summaryrefslogtreecommitdiff
path: root/src/gui/themeList.vala
blob: 7eadcdbe7cc63ff5a4a2c36c98042ad1fe66ecc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* 
Copyright (c) 2011 by Simon Schneegans

This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public License along with
this program.  If not, see <http://www.gnu.org/licenses/>. 
*/

namespace GnomePie {

/////////////////////////////////////////////////////////////////////////    
/// A widget displaying all available themes of Gnome-Pie.
/////////////////////////////////////////////////////////////////////////

class ThemeList : Gtk.TreeView {

    /////////////////////////////////////////////////////////////////////
    /// The currently selected row.
    /////////////////////////////////////////////////////////////////////

    private Gtk.TreeIter active { private get; private set; }

    /////////////////////////////////////////////////////////////////////
    /// C'tor, constructs the Widget.
    /////////////////////////////////////////////////////////////////////

    public ThemeList() {
        GLib.Object();
        
        var data = new Gtk.ListStore(2, typeof(bool),    // selected
                                        typeof(string)); // description
        base.set_model(data);
        base.set_headers_visible(false);
        base.set_rules_hint(true);
        base.set_grid_lines(Gtk.TreeViewGridLines.NONE);
        
        var main_column = new Gtk.TreeViewColumn();
            var check_render = new Gtk.CellRendererToggle();
                check_render.set_radio(true);
                check_render.set_activatable(true);
                main_column.pack_start(check_render, false);
                
                // switch the theme if the entry has been toggled
                check_render.toggled.connect((r, path) => {
                    Gtk.TreeIter toggled;
                    data.get_iter(out toggled, new Gtk.TreePath.from_string(path));
                    
                    if (toggled != this.active) {
                        Timeout.add(10, () => {
                            int index = int.parse(path);
                            Config.global.theme = Config.global.themes[index];
                            Config.global.theme.load();
                            Config.global.theme.load_images();
                            return false;
                        });
                        
                        data.set(this.active, 0, false); 
                        data.set(toggled, 0, true);
                        
                        this.active = toggled;
                    }
                });
        
            var theme_render = new Gtk.CellRendererText();
                main_column.pack_start(theme_render, true);
        
        base.append_column(main_column);
        
        main_column.add_attribute(check_render, "active", 0);
        main_column.add_attribute(theme_render, "markup", 1);
        
        // load all themes into the list
        var themes = Config.global.themes;
        foreach(var theme in themes) {
            Gtk.TreeIter current;
            data.append(out current);
            data.set(current, 0, theme == Config.global.theme); 
            data.set(current, 1, "<b>" + theme.name + "</b>\n" + theme.description
                                 + "  <small> - " + _("by") + " " + theme.author + "</small>"); 
            if(theme == Config.global.theme)
                this.active = current;
        }  
    }
}

}