Merge lp:~elementary-pantheon/switchboard-plug-security-privacy/rewrite-app-chooser into lp:~elementary-apps/switchboard-plug-security-privacy/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: David Hewitt
Approved revision: 294
Merged at revision: 293
Proposed branch: lp:~elementary-pantheon/switchboard-plug-security-privacy/rewrite-app-chooser
Merge into: lp:~elementary-apps/switchboard-plug-security-privacy/trunk
Diff against target: 250 lines (+116/-73)
3 files modified
src/CMakeLists.txt (+1/-0)
src/Widgets/AppChooser.vala (+33/-73)
src/Widgets/AppRow.vala (+82/-0)
To merge this branch: bzr merge lp:~elementary-pantheon/switchboard-plug-security-privacy/rewrite-app-chooser
Reviewer Review Type Date Requested Status
David Hewitt code, function Approve
Review via email: mp+318011@code.launchpad.net

Commit message

AppChooser.vala:
* Update copyright header
* GObject-style construction
* Adjust alignment and spacing
* Make search grab focus

Move AppRow class to its own file and rewrite based around AppRow from the applications plug

To post a comment you must log in.
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Perhaps get_app_comment, get_app_name and get_icon_name can be static since they don't access anything from the class itself?

294. By Danielle Foré

don't pass global var

Revision history for this message
David Hewitt (davidmhewitt) wrote :

Much improved. LGTM.

review: Approve (code, function)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2017-02-19 21:27:25 +0000
3+++ src/CMakeLists.txt 2017-02-22 18:16:51 +0000
4@@ -23,6 +23,7 @@
5 Views/TrackPanel.vala
6
7 Widgets/AppChooser.vala
8+ Widgets/AppRow.vala
9
10 ${CMAKE_CURRENT_BINARY_DIR}/config.vala
11 PACKAGES
12
13=== modified file 'src/Widgets/AppChooser.vala'
14--- src/Widgets/AppChooser.vala 2017-02-19 21:27:25 +0000
15+++ src/Widgets/AppChooser.vala 2017-02-22 18:16:51 +0000
16@@ -1,64 +1,28 @@
17 // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
18 /*-
19- * Copyright (c) 2014 Security & Privacy Plug (http://launchpad.net/switchboard-plug-security-privacy)
20- *
21- * This library is free software; you can redistribute it and/or
22- * modify it under the terms of the GNU Library General Public
23- * License as published by the Free Software Foundation; either
24- * version 3 of the License, or (at your option) any later version.
25- *
26- * This library is distributed in the hope that it will be useful,
27- * but WITHOUT ANY WARRANTY; without even the implied warranty of
28- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29- * Library General Public License for more details.
30- *
31- * You should have received a copy of the GNU Library General Public
32- * License along with this library; if not, write to the
33- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
34- * Boston, MA 02111-1307, USA.
35- *
36- * Authored by: Julien Spautz <spautz.julien@gmail.com>
37- * Corentin Noël <corentin@elementaryos.org>
38- */
39+* Copyright (c) 2014-2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
40+*
41+* This program is free software; you can redistribute it and/or
42+* modify it under the terms of the GNU Lesser General Public
43+* License as published by the Free Software Foundation; either
44+* version 3 of the License, or (at your option) any later version.
45+*
46+* This program is distributed in the hope that it will be useful,
47+* but WITHOUT ANY WARRANTY; without even the implied warranty of
48+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
49+* Lesser General Public License for more details.
50+*
51+* You should have received a copy of the GNU Lesser General Public
52+* License along with this program; if not, write to the
53+* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
54+* Boston, MA 02110-1301 USA
55+*
56+* Authored by: Julien Spautz <spautz.julien@gmail.com>
57+* Corentin Noël <corentin@elementaryos.org>
58+*/
59
60 public class SecurityPrivacy.Dialogs.AppChooser : Gtk.Popover {
61
62- const string FALLBACK_ICON = "application-default-icon";
63- public class AppRow : Gtk.Box {
64- public DesktopAppInfo app_info { get; construct; }
65-
66- public AppRow (DesktopAppInfo app_info) {
67- Object (app_info: app_info);
68- orientation = Gtk.Orientation.HORIZONTAL;
69-
70- var name = app_info.get_display_name ();
71- if (name == null)
72- name = app_info.get_name ();
73- var escaped_name = Markup.escape_text (name);
74- var comment = app_info.get_description ();
75- if (comment == null)
76- comment = "";
77- var escaped_comment = Markup.escape_text (comment);
78-
79- margin = 6;
80- spacing = 12;
81-
82- var icon_theme = Gtk.IconTheme.get_default ();
83- if (icon_theme.has_icon (app_info.get_icon ().to_string ()))
84- add (new Gtk.Image.from_gicon (app_info.get_icon (), Gtk.IconSize.DND));
85- else
86- add (new Gtk.Image.from_icon_name (FALLBACK_ICON, Gtk.IconSize.DND));
87-
88- var label = new Gtk.Label ("<span font_weight=\"bold\" size=\"large\">%s</span>\n%s".printf (escaped_name, escaped_comment));
89- label.use_markup = true;
90- label.halign = Gtk.Align.START;
91- label.ellipsize = Pango.EllipsizeMode.END;
92- add (label);
93-
94- show_all ();
95- }
96- }
97-
98 public signal void app_chosen (DesktopAppInfo app_info);
99
100 private Gtk.ListBox list;
101@@ -66,37 +30,38 @@
102
103 public AppChooser (Gtk.Widget widget) {
104 Object (relative_to: widget);
105- setup_gui ();
106- connect_signals ();
107- init_list ();
108 }
109
110- void setup_gui () {
111- var grid = new Gtk.Grid ();
112- grid.margin = 12;
113- grid.row_spacing = 6;
114-
115+ construct {
116 search_entry = new Gtk.SearchEntry ();
117+ search_entry.margin_end = 12;
118+ search_entry.margin_start = 12;
119 search_entry.placeholder_text = _("Search Application");
120
121 var scrolled = new Gtk.ScrolledWindow (null, null);
122 scrolled.height_request = 200;
123 scrolled.width_request = 250;
124- scrolled.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
125- scrolled.shadow_type = Gtk.ShadowType.IN;
126+ scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;
127
128 list = new Gtk.ListBox ();
129 list.expand = true;
130- list.height_request = 250;
131- list.width_request = 200;
132 list.set_sort_func (sort_function);
133 list.set_filter_func (filter_function);
134 scrolled.add (list);
135
136+ var grid = new Gtk.Grid ();
137+ grid.margin_top = 12;
138+ grid.row_spacing = 6;
139 grid.attach (search_entry, 0, 0, 1, 1);
140 grid.attach (scrolled, 0, 1, 1, 1);
141
142 add (grid);
143+
144+ search_entry.grab_focus ();
145+ list.row_activated.connect (on_app_selected);
146+ search_entry.search_changed.connect (apply_filter);
147+
148+ init_list ();
149 }
150
151 public void init_list () {
152@@ -135,11 +100,6 @@
153 || search in description.down ();
154 }
155
156- void connect_signals () {
157- list.row_activated.connect (on_app_selected);
158- search_entry.search_changed.connect (apply_filter);
159- }
160-
161 void on_app_selected (Gtk.ListBoxRow list_box_row) {
162 var app_row = list_box_row.get_child () as AppRow;
163 app_chosen (app_row.app_info);
164
165=== added file 'src/Widgets/AppRow.vala'
166--- src/Widgets/AppRow.vala 1970-01-01 00:00:00 +0000
167+++ src/Widgets/AppRow.vala 2017-02-22 18:16:51 +0000
168@@ -0,0 +1,82 @@
169+/*-
170+* Copyright (c) 2014-2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
171+*
172+* This program is free software; you can redistribute it and/or
173+* modify it under the terms of the GNU Lesser General Public
174+* License as published by the Free Software Foundation; either
175+* version 3 of the License, or (at your option) any later version.
176+*
177+* This program is distributed in the hope that it will be useful,
178+* but WITHOUT ANY WARRANTY; without even the implied warranty of
179+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
180+* Lesser General Public License for more details.
181+*
182+* You should have received a copy of the GNU Lesser General Public
183+* License along with this program; if not, write to the
184+* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
185+* Boston, MA 02110-1301 USA
186+*
187+* Authored by: Julien Spautz <spautz.julien@gmail.com>
188+* Corentin Noël <corentin@elementaryos.org>
189+*/
190+
191+public class AppRow : Gtk.Grid {
192+ public DesktopAppInfo app_info { get; construct; }
193+
194+ public AppRow (DesktopAppInfo app_info) {
195+ Object (app_info: app_info);
196+ }
197+
198+ construct {
199+ var image = new Gtk.Image.from_icon_name (get_icon_name (), Gtk.IconSize.DND);
200+ image.pixel_size = 32;
201+
202+ var app_name = new Gtk.Label (get_app_name ());
203+ app_name.get_style_context ().add_class ("h3");
204+ app_name.xalign = 0;
205+
206+ var app_comment = new Gtk.Label ("<span font_size='small'>" + get_app_comment () + "</span>");
207+ app_comment.xalign = 0;
208+ app_comment.use_markup = true;
209+
210+ margin = 6;
211+ margin_end = 12;
212+ margin_start = 10; // Account for icon position on the canvas
213+ column_spacing = 12;
214+ attach (image, 0, 0, 1, 2);
215+ attach (app_name, 1, 0, 1, 1);
216+ attach (app_comment, 1, 1, 1, 1);
217+
218+ show_all ();
219+ }
220+
221+ private string get_app_comment () {
222+ var comment = app_info.get_description ();
223+
224+ if (comment == null) {
225+ comment = "";
226+ }
227+
228+ return Markup.escape_text (comment);
229+ }
230+
231+ private string get_app_name () {
232+ var name = app_info.get_display_name ();
233+
234+ if (name == null) {
235+ name = app_info.get_name ();
236+ }
237+
238+ return Markup.escape_text (name);
239+ }
240+
241+ private string get_icon_name () {
242+ var icon_theme = Gtk.IconTheme.get_default ();
243+
244+ if (icon_theme.has_icon (app_info.get_icon ().to_string ())) {
245+ return app_info.get_icon ().to_string ();
246+ } else {
247+ return "application-default-icon";
248+ }
249+ }
250+}

Subscribers

People subscribed via source and target branches