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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2017-02-19 21:27:25 +0000
+++ src/CMakeLists.txt 2017-02-22 18:16:51 +0000
@@ -23,6 +23,7 @@
23 Views/TrackPanel.vala23 Views/TrackPanel.vala
2424
25 Widgets/AppChooser.vala25 Widgets/AppChooser.vala
26 Widgets/AppRow.vala
2627
27 ${CMAKE_CURRENT_BINARY_DIR}/config.vala28 ${CMAKE_CURRENT_BINARY_DIR}/config.vala
28PACKAGES29PACKAGES
2930
=== modified file 'src/Widgets/AppChooser.vala'
--- src/Widgets/AppChooser.vala 2017-02-19 21:27:25 +0000
+++ src/Widgets/AppChooser.vala 2017-02-22 18:16:51 +0000
@@ -1,64 +1,28 @@
1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2/*-2/*-
3 * Copyright (c) 2014 Security & Privacy Plug (http://launchpad.net/switchboard-plug-security-privacy)3* Copyright (c) 2014-2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
4 *4*
5 * This library is free software; you can redistribute it and/or5* This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public6* modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either7* License as published by the Free Software Foundation; either
8 * version 3 of the License, or (at your option) any later version.8* version 3 of the License, or (at your option) any later version.
9 *9*
10 * This library is distributed in the hope that it will be useful,10* This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.13* Lesser General Public License for more details.
14 *14*
15 * You should have received a copy of the GNU Library General Public15* You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the16* License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,17* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02111-1307, USA.18* Boston, MA 02110-1301 USA
19 *19*
20 * Authored by: Julien Spautz <spautz.julien@gmail.com>20* Authored by: Julien Spautz <spautz.julien@gmail.com>
21 * Corentin Noël <corentin@elementaryos.org>21* Corentin Noël <corentin@elementaryos.org>
22 */22*/
2323
24public class SecurityPrivacy.Dialogs.AppChooser : Gtk.Popover {24public class SecurityPrivacy.Dialogs.AppChooser : Gtk.Popover {
2525
26 const string FALLBACK_ICON = "application-default-icon";
27 public class AppRow : Gtk.Box {
28 public DesktopAppInfo app_info { get; construct; }
29
30 public AppRow (DesktopAppInfo app_info) {
31 Object (app_info: app_info);
32 orientation = Gtk.Orientation.HORIZONTAL;
33
34 var name = app_info.get_display_name ();
35 if (name == null)
36 name = app_info.get_name ();
37 var escaped_name = Markup.escape_text (name);
38 var comment = app_info.get_description ();
39 if (comment == null)
40 comment = "";
41 var escaped_comment = Markup.escape_text (comment);
42
43 margin = 6;
44 spacing = 12;
45
46 var icon_theme = Gtk.IconTheme.get_default ();
47 if (icon_theme.has_icon (app_info.get_icon ().to_string ()))
48 add (new Gtk.Image.from_gicon (app_info.get_icon (), Gtk.IconSize.DND));
49 else
50 add (new Gtk.Image.from_icon_name (FALLBACK_ICON, Gtk.IconSize.DND));
51
52 var label = new Gtk.Label ("<span font_weight=\"bold\" size=\"large\">%s</span>\n%s".printf (escaped_name, escaped_comment));
53 label.use_markup = true;
54 label.halign = Gtk.Align.START;
55 label.ellipsize = Pango.EllipsizeMode.END;
56 add (label);
57
58 show_all ();
59 }
60 }
61
62 public signal void app_chosen (DesktopAppInfo app_info);26 public signal void app_chosen (DesktopAppInfo app_info);
6327
64 private Gtk.ListBox list;28 private Gtk.ListBox list;
@@ -66,37 +30,38 @@
6630
67 public AppChooser (Gtk.Widget widget) {31 public AppChooser (Gtk.Widget widget) {
68 Object (relative_to: widget);32 Object (relative_to: widget);
69 setup_gui ();
70 connect_signals ();
71 init_list ();
72 }33 }
7334
74 void setup_gui () {35 construct {
75 var grid = new Gtk.Grid ();
76 grid.margin = 12;
77 grid.row_spacing = 6;
78
79 search_entry = new Gtk.SearchEntry ();36 search_entry = new Gtk.SearchEntry ();
37 search_entry.margin_end = 12;
38 search_entry.margin_start = 12;
80 search_entry.placeholder_text = _("Search Application");39 search_entry.placeholder_text = _("Search Application");
8140
82 var scrolled = new Gtk.ScrolledWindow (null, null);41 var scrolled = new Gtk.ScrolledWindow (null, null);
83 scrolled.height_request = 200;42 scrolled.height_request = 200;
84 scrolled.width_request = 250;43 scrolled.width_request = 250;
85 scrolled.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;44 scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;
86 scrolled.shadow_type = Gtk.ShadowType.IN;
8745
88 list = new Gtk.ListBox ();46 list = new Gtk.ListBox ();
89 list.expand = true;47 list.expand = true;
90 list.height_request = 250;
91 list.width_request = 200;
92 list.set_sort_func (sort_function);48 list.set_sort_func (sort_function);
93 list.set_filter_func (filter_function);49 list.set_filter_func (filter_function);
94 scrolled.add (list);50 scrolled.add (list);
9551
52 var grid = new Gtk.Grid ();
53 grid.margin_top = 12;
54 grid.row_spacing = 6;
96 grid.attach (search_entry, 0, 0, 1, 1);55 grid.attach (search_entry, 0, 0, 1, 1);
97 grid.attach (scrolled, 0, 1, 1, 1);56 grid.attach (scrolled, 0, 1, 1, 1);
9857
99 add (grid);58 add (grid);
59
60 search_entry.grab_focus ();
61 list.row_activated.connect (on_app_selected);
62 search_entry.search_changed.connect (apply_filter);
63
64 init_list ();
100 }65 }
10166
102 public void init_list () {67 public void init_list () {
@@ -135,11 +100,6 @@
135 || search in description.down ();100 || search in description.down ();
136 }101 }
137102
138 void connect_signals () {
139 list.row_activated.connect (on_app_selected);
140 search_entry.search_changed.connect (apply_filter);
141 }
142
143 void on_app_selected (Gtk.ListBoxRow list_box_row) {103 void on_app_selected (Gtk.ListBoxRow list_box_row) {
144 var app_row = list_box_row.get_child () as AppRow;104 var app_row = list_box_row.get_child () as AppRow;
145 app_chosen (app_row.app_info);105 app_chosen (app_row.app_info);
146106
=== added file 'src/Widgets/AppRow.vala'
--- src/Widgets/AppRow.vala 1970-01-01 00:00:00 +0000
+++ src/Widgets/AppRow.vala 2017-02-22 18:16:51 +0000
@@ -0,0 +1,82 @@
1/*-
2* Copyright (c) 2014-2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
3*
4* This program is free software; you can redistribute it and/or
5* modify it under the terms of the GNU Lesser General Public
6* License as published by the Free Software Foundation; either
7* version 3 of the License, or (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12* Lesser General Public License for more details.
13*
14* You should have received a copy of the GNU Lesser General Public
15* License along with this program; if not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17* Boston, MA 02110-1301 USA
18*
19* Authored by: Julien Spautz <spautz.julien@gmail.com>
20* Corentin Noël <corentin@elementaryos.org>
21*/
22
23public class AppRow : Gtk.Grid {
24 public DesktopAppInfo app_info { get; construct; }
25
26 public AppRow (DesktopAppInfo app_info) {
27 Object (app_info: app_info);
28 }
29
30 construct {
31 var image = new Gtk.Image.from_icon_name (get_icon_name (), Gtk.IconSize.DND);
32 image.pixel_size = 32;
33
34 var app_name = new Gtk.Label (get_app_name ());
35 app_name.get_style_context ().add_class ("h3");
36 app_name.xalign = 0;
37
38 var app_comment = new Gtk.Label ("<span font_size='small'>" + get_app_comment () + "</span>");
39 app_comment.xalign = 0;
40 app_comment.use_markup = true;
41
42 margin = 6;
43 margin_end = 12;
44 margin_start = 10; // Account for icon position on the canvas
45 column_spacing = 12;
46 attach (image, 0, 0, 1, 2);
47 attach (app_name, 1, 0, 1, 1);
48 attach (app_comment, 1, 1, 1, 1);
49
50 show_all ();
51 }
52
53 private string get_app_comment () {
54 var comment = app_info.get_description ();
55
56 if (comment == null) {
57 comment = "";
58 }
59
60 return Markup.escape_text (comment);
61 }
62
63 private string get_app_name () {
64 var name = app_info.get_display_name ();
65
66 if (name == null) {
67 name = app_info.get_name ();
68 }
69
70 return Markup.escape_text (name);
71 }
72
73 private string get_icon_name () {
74 var icon_theme = Gtk.IconTheme.get_default ();
75
76 if (icon_theme.has_icon (app_info.get_icon ().to_string ())) {
77 return app_info.get_icon ().to_string ();
78 } else {
79 return "application-default-icon";
80 }
81 }
82}

Subscribers

People subscribed via source and target branches