~jaapz-b/switchboard/fix-1088451

« back to all changes in this revision

Viewing changes to CategoryView.vala

  • Committer: Avi Romanoff
  • Date: 2011-06-23 05:26:15 UTC
  • Revision ID: avi@elementaryos.org-20110623052615-vd2nmnbcitrjrnml
Make consts all caps, move source into it's own directory, utilize constants more, bump version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***
2
 
BEGIN LICENSE
3
 
Copyright (C) 2011 Avi Romanoff <aviromanoff@gmail.com>
4
 
This program is free software: you can redistribute it and/or modify it
5
 
under the terms of the GNU Lesser General Public License version 2.1, as published
6
 
by the Free Software Foundation.
7
 
 
8
 
This program is distributed in the hope that it will be useful, but
9
 
WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
 
PURPOSE.  See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along
14
 
with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
END LICENSE
16
 
***/
17
 
 
18
 
using Gtk;
19
 
 
20
 
namespace SwitchBoard {
21
 
 
22
 
    public class CategoryView : Gtk.VBox {
23
 
        private Gee.HashMap<string, Gtk.VBox> category_labels = new Gee.HashMap<string, Gtk.VBox>();
24
 
        private Gee.HashMap<string, ListStore> category_store = new Gee.HashMap<string, ListStore>();
25
 
        private Gtk.IconTheme theme = Gtk.IconTheme.get_default();
26
 
        private static Gee.HashMap<string, string> category_titles = new Gee.HashMap<string, string>();
27
 
 
28
 
        public signal void plug_selected(IconView view, ListStore message);
29
 
 
30
 
        public CategoryView () {
31
 
            category_titles["personal"] = _("Personal");
32
 
            category_titles["hardware"] = _("Hardware");
33
 
            category_titles["network"] = _("Network and Wireless");
34
 
            category_titles["system"] = _("System");
35
 
            foreach (var entry in this.category_titles.entries) {
36
 
                var store = new ListStore (3, typeof (string), typeof (Gdk.Pixbuf), typeof(string));
37
 
                var label = new Gtk.Label("<big><b>"+entry.value+"</b></big>");
38
 
                var category_plugs = new Gtk.IconView.with_model (store);
39
 
                category_plugs.set_text_column (0);
40
 
                category_plugs.set_pixbuf_column (1);
41
 
                category_plugs.selection_changed.connect(() => this.plug_selected(category_plugs, store));
42
 
                var color = Gdk.Color ();
43
 
                Gdk.Color.parse ("#dedede", out color);
44
 
                category_plugs.modify_base (Gtk.StateType.NORMAL, color);
45
 
                label.xalign = (float) 0.02;
46
 
                var vbox = new Gtk.VBox(false, 0); // not homogeneous, 0 spacing
47
 
                var headbox = new Gtk.HBox(false, 5);
48
 
                label.use_markup = true;
49
 
                // Always add a Seperator
50
 
                var hsep = new Gtk.HSeparator();
51
 
                headbox.pack_end(hsep, true, true); // expand, fill, padding´
52
 
                headbox.pack_start(label, false, false, 10);
53
 
                vbox.pack_start(headbox, false, true, 5);
54
 
                vbox.pack_end(category_plugs, true, true);
55
 
                this.category_labels[entry.key] = vbox;
56
 
                this.category_store[entry.key] = store;
57
 
                this.pack_start(vbox);
58
 
                vbox.show_all();
59
 
                vbox.hide();
60
 
            }
61
 
        }
62
 
 
63
 
        public void add_plug (Gee.HashMap<string, string> plug) {
64
 
            Gtk.TreeIter root;
65
 
            this.category_store[plug["category"].down()].append (out root);
66
 
            try {
67
 
                var icon_pixbuf = this.theme.load_icon (plug["icon"], 48, Gtk.IconLookupFlags.GENERIC_FALLBACK);
68
 
                this.category_store[plug["category"].down()].set (root, 1, icon_pixbuf, -1);
69
 
            } catch {
70
 
                GLib.log(SwitchBoard.errdomain, LogLevelFlags.LEVEL_DEBUG,
71
 
                "Unable to load plug %s's icon: %s", plug["title"], plug["icon"]);
72
 
            }
73
 
            this.category_store[plug["category"].down()].set (root, 0, plug["title"], -1);
74
 
            this.category_store[plug["category"].down()].set (root, 2, plug["exec"], -1);
75
 
            this.category_labels[plug["category"].down()].show();
76
 
        }
77
 
    }
78
 
}
79