~elementary-apps/switchboard-plug-security-privacy/trunk

« back to all changes in this revision

Viewing changes to src/Widgets/AppRow.vala

  • Committer: RabbitBot
  • Author(s): Daniel Foré
  • Date: 2017-02-26 11:50:53 UTC
  • mfrom: (292.1.2 rewrite-app-chooser)
  • Revision ID: rabbitbot-20170226115053-xpeqxdcfpus58lvg
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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
23
public 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
}