~elementary-apps/switchboard-plug-pantheon-shell/trunk

« back to all changes in this revision

Viewing changes to src/desktop-plug.vala

  • Committer: Corentin Noël
  • Date: 2012-10-26 15:43:50 UTC
  • Revision ID: tintou@mailoo.org-20121026154350-1uxj0378lwh7tqjn
Fixed translation, switch the wallpaper to the 1st tab and reorganize some widgets

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
class LLabel : Gtk.Label
19
19
{
20
 
        public LLabel (string label)
21
 
        {
22
 
                this.set_halign (Gtk.Align.START);
23
 
                this.label = label;
24
 
        }
25
 
        public LLabel.indent (string label) 
26
 
        {
27
 
                this (label);
28
 
                this.margin_left = 10;
29
 
        }
30
 
        public LLabel.markup (string label) 
31
 
        {
32
 
                this (label);
33
 
                this.use_markup = true;
34
 
        }
35
 
        public LLabel.right (string label) 
36
 
        {
37
 
                this.set_halign (Gtk.Align.END);
38
 
                this.label = label;
39
 
        }
40
 
        public LLabel.right_with_markup (string label)
41
 
        {
42
 
                this.set_halign (Gtk.Align.END);
43
 
                this.use_markup = true;
44
 
                this.label = label;
45
 
        }
 
20
    public LLabel (string label)
 
21
    {
 
22
        this.set_halign (Gtk.Align.START);
 
23
        this.label = label;
 
24
    }
 
25
    public LLabel.indent (string label) 
 
26
    {
 
27
        this (label);
 
28
        this.margin_left = 10;
 
29
    }
 
30
    public LLabel.markup (string label) 
 
31
    {
 
32
        this (label);
 
33
        this.use_markup = true;
 
34
    }
 
35
    public LLabel.right (string label) 
 
36
    {
 
37
        this.set_halign (Gtk.Align.END);
 
38
        this.label = label;
 
39
    }
 
40
    public LLabel.right_with_markup (string label)
 
41
    {
 
42
        this.set_halign (Gtk.Align.END);
 
43
        this.use_markup = true;
 
44
        this.label = label;
 
45
    }
46
46
}
47
47
 
48
48
public class GalaPlug : Pantheon.Switchboard.Plug
49
49
{
50
 
        
51
 
        public GalaPlug ()
52
 
        {
53
 
                
54
 
                var notebook = new Granite.Widgets.StaticNotebook (false);
55
 
                notebook.margin = 12;
56
 
                
57
 
                /*dock*/
58
 
                var dock_grid = new Gtk.Grid ();
59
 
                
60
 
                var icon_size_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
61
 
                
62
 
                Gtk.Scale icon_size_range = null;
63
 
                var icon_size = new Gtk.SpinButton.with_range (32, 96, 1);
64
 
                icon_size.set_value (PlankSettings.get_default ().icon_size);
65
 
                icon_size.value_changed.connect (() => {
66
 
                        PlankSettings.get_default ().icon_size = (int)icon_size.get_value ();
67
 
                        icon_size_range.set_value (icon_size.get_value ());
68
 
                });
69
 
                icon_size.halign = Gtk.Align.START;
70
 
                
71
 
                icon_size_range = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 32, 96, 1);
72
 
                icon_size_range.set_value (PlankSettings.get_default ().icon_size);
73
 
                icon_size_range.button_release_event.connect (() => {icon_size.value = icon_size_range.get_value (); return false;});
74
 
                icon_size_range.draw_value = false;
75
 
                
76
 
                icon_size_box.pack_start (icon_size_range, true);
77
 
                icon_size_box.pack_start (icon_size, false);
78
 
                
79
 
                var hide_mode = new Gtk.ComboBoxText ();
80
 
                hide_mode.append ("0", _("Don't hide"));
81
 
                hide_mode.append ("1", _("Intelligent hide"));
82
 
                hide_mode.append ("2", _("Auto hide"));
83
 
                hide_mode.append ("3", _("Hide on maximize"));
84
 
                hide_mode.active_id = PlankSettings.get_default ().hide_mode.to_string ();
85
 
                hide_mode.changed.connect (() => PlankSettings.get_default ().hide_mode = int.parse (hide_mode.active_id));
86
 
                hide_mode.halign = Gtk.Align.START;
87
 
                hide_mode.width_request = 164;
88
 
                
89
 
                var monitor = new Gtk.ComboBoxText ();
90
 
                int i;
91
 
                for (i=0;i<Gdk.Screen.get_default ().get_n_monitors ();i ++)
92
 
                        monitor.append ((i+1).to_string (), _("Monitor")+" "+(i+1).to_string ());
93
 
                monitor.active_id = (PlankSettings.get_default ().monitor+1).to_string ();
94
 
                monitor.changed.connect (() => PlankSettings.get_default ().monitor = int.parse (monitor.active_id));
95
 
                monitor.halign = Gtk.Align.START;
96
 
                monitor.width_request = 164;
97
 
                
98
 
                dock_grid.column_homogeneous = true;
99
 
                dock_grid.column_spacing = 12;
100
 
                dock_grid.row_spacing = 6;
101
 
                dock_grid.margin = 64;
102
 
                dock_grid.margin_top = 24;
103
 
                
104
 
                dock_grid.attach (new LLabel.right (_("Icon Size:")), 0, 0, 1, 1);
105
 
                dock_grid.attach (icon_size_box, 1, 0, 1, 1);
106
 
                dock_grid.attach (new LLabel.right (_("Hide Mode:")), 0, 1, 1, 1);
107
 
                dock_grid.attach (hide_mode, 1, 1, 1, 1);
108
 
                if (i < 1) {
109
 
                        dock_grid.attach (new LLabel.right (_("Monitor")+":"), 0, 2, 1, 1);
110
 
                        dock_grid.attach (monitor, 1, 2, 1, 1);
111
 
                }
112
 
                
113
 
                notebook.append_page (dock_grid, new Gtk.Label (_("Dock")));
114
 
                
115
 
                /*wallpaper*/
116
 
                var wallpaper = new Wallpaper (this);
117
 
                notebook.append_page (wallpaper, new Gtk.Label (_("Wallpaper")));
118
 
                
119
 
                /*hot corners*/
120
 
                var hotc_grid = new Gtk.Grid ();
121
 
                hotc_grid.column_spacing = 12;
122
 
                hotc_grid.margin = 32;
123
 
                hotc_grid.margin_top = 50;
124
 
                
125
 
                var expl = new LLabel (_("When the cursor enters the corner of the display:"));
126
 
                expl.margin_bottom = 10;
127
 
                
128
 
                var topleft = create_hotcorner ();
129
 
                topleft.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topleft").to_string ();
130
 
                topleft.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-topleft", int.parse (topleft.active_id)));
131
 
                topleft.valign = Gtk.Align.START;
132
 
                var topright = create_hotcorner ();
133
 
                topright.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topright").to_string ();
134
 
                topright.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-topright", int.parse (topright.active_id)));
135
 
                topright.valign = Gtk.Align.START;
136
 
                var bottomleft = create_hotcorner ();
137
 
                bottomleft.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomleft").to_string ();
138
 
                bottomleft.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-bottomleft", int.parse (bottomleft.active_id)));
139
 
                bottomleft.valign = Gtk.Align.END;
140
 
                var bottomright = create_hotcorner ();
141
 
                bottomright.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomright").to_string ();
142
 
                bottomright.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-bottomright", int.parse (bottomright.active_id)));
143
 
                bottomright.valign = Gtk.Align.END;
144
 
                
145
 
                var icon = new Gtk.Image.from_file (Constants.PKGDATADIR + "/hotcornerdisplay.png");
146
 
                var custom_command = new Gtk.Entry ();
147
 
                custom_command.text = BehaviorSettings.get_default ().hotcorner_custom_command;
148
 
                custom_command.changed.connect (() => BehaviorSettings.get_default ().hotcorner_custom_command = custom_command.text );
149
 
                
150
 
                var cc_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
151
 
                cc_box.margin_top = 24;
152
 
                cc_box.pack_start (new LLabel (_("Custom Command:")), false);
153
 
                cc_box.pack_start (custom_command, false);
154
 
                
155
 
                hotc_grid.attach (expl, 0, 0, 3, 1);
156
 
                hotc_grid.attach (icon, 1, 1, 1, 3);
157
 
                hotc_grid.attach (topleft, 0, 1, 1, 1);
158
 
                hotc_grid.attach (topright, 2, 1, 1, 1);
159
 
                hotc_grid.attach (bottomleft, 0, 3, 1, 1);
160
 
                hotc_grid.attach (bottomright, 2, 3, 1, 1);
161
 
                hotc_grid.attach (cc_box, 0, 4, 2, 1);
162
 
                
163
 
                notebook.append_page (hotc_grid, new Gtk.Label (_("Hot Corners")));
164
 
                
165
 
                
166
 
                add (notebook);
167
 
                
168
 
                notebook.page_changed.connect ((page) => {
169
 
                        if (page == 1 && !wallpaper.finished) {
170
 
                                switchboard_controller.progress_bar_set_visible (true);
171
 
                        } else {
172
 
                                switchboard_controller.progress_bar_set_visible (false);
173
 
                        }
174
 
                });
175
 
        }
176
 
        
177
 
        Gtk.ComboBoxText create_hotcorner ()
178
 
        {
179
 
                var box = new Gtk.ComboBoxText ();
180
 
                box.append ("0", _("Do Nothing"));
181
 
                box.append ("1", _("Show Workspace View"));
182
 
                box.append ("2", _("Maximize Current Window"));
183
 
                box.append ("3", _("Minimize Current Window"));
184
 
                box.append ("4", _("Open Launcher"));
185
 
                box.append ("6", _("Expose All Windows"));
186
 
                box.append ("5", _("Execute Custom Command"));
187
 
                
188
 
                return box;
189
 
        }
190
 
}
191
 
 
192
 
public static int main (string[] args)
193
 
{
194
 
        Gtk.init (ref args);
195
 
        
196
 
        var plug = new GalaPlug ();
197
 
        plug.register ("Effects");
198
 
        plug.show_all ();
199
 
        
200
 
        Gtk.main ();
201
 
        return 0;
 
50
    
 
51
    public GalaPlug ()
 
52
    {
 
53
        
 
54
        var notebook = new Granite.Widgets.StaticNotebook (false);
 
55
        notebook.set_margin_top (12);
 
56
        
 
57
        /*wallpaper*/
 
58
        var wallpaper = new Wallpaper (this);
 
59
        notebook.append_page (wallpaper, new Gtk.Label (_("Wallpaper")));
 
60
        switchboard_controller.progress_bar_set_visible (true);
 
61
        
 
62
        /*dock*/
 
63
        var dock_grid = new Gtk.Grid ();
 
64
        dock_grid.set_column_spacing (12);
 
65
        dock_grid.set_row_spacing (6);
 
66
        dock_grid.margin = 12;
 
67
        
 
68
        var icon_size_range = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 32, 96, 1);
 
69
        var icon_size = new Gtk.SpinButton.with_range (32, 96, 1);
 
70
        icon_size.set_value (PlankSettings.get_default ().icon_size);
 
71
        icon_size.value_changed.connect (() => {
 
72
            PlankSettings.get_default ().icon_size = (int)icon_size.get_value ();
 
73
            icon_size_range.set_value (icon_size.get_value ());
 
74
        });
 
75
        icon_size.halign = Gtk.Align.START;
 
76
        
 
77
        icon_size_range.set_value (PlankSettings.get_default ().icon_size);
 
78
        icon_size_range.button_release_event.connect (() => {icon_size.value = icon_size_range.get_value (); return false;});
 
79
        icon_size_range.draw_value = false;
 
80
        icon_size_range.set_hexpand (true);
 
81
        
 
82
        var hide_mode = new Gtk.ComboBoxText ();
 
83
        hide_mode.append ("0", _("Don't hide"));
 
84
        hide_mode.append ("1", _("Intelligent hide"));
 
85
        hide_mode.append ("2", _("Auto hide"));
 
86
        hide_mode.append ("3", _("Hide on maximize"));
 
87
        hide_mode.active_id = PlankSettings.get_default ().hide_mode.to_string ();
 
88
        hide_mode.changed.connect (() => PlankSettings.get_default ().hide_mode = int.parse (hide_mode.active_id));
 
89
        hide_mode.halign = Gtk.Align.START;
 
90
        hide_mode.width_request = 164;
 
91
        
 
92
        var monitor = new Gtk.ComboBoxText ();
 
93
        int i = 0;
 
94
        for (i = 0; i < Gdk.Screen.get_default ().get_n_monitors () ; i ++) {
 
95
            monitor.append ( (i+1).to_string (), _("Monitor %d").printf (i+1) );
 
96
        }
 
97
        monitor.active_id = ( PlankSettings.get_default ().monitor +1 ).to_string ();
 
98
        monitor.changed.connect (() => PlankSettings.get_default ().monitor = int.parse (monitor.active_id));
 
99
        monitor.halign = Gtk.Align.START;
 
100
        monitor.width_request = 164;
 
101
        
 
102
        dock_grid.attach (new LLabel.right (_("Icon Size:")), 0, 0, 2, 1);
 
103
        dock_grid.attach (icon_size_range,2, 0, 1, 1);
 
104
        dock_grid.attach (icon_size, 3, 0, 1, 1);
 
105
        dock_grid.attach (new LLabel.right (_("Hide Mode:")), 0, 1, 2, 1);
 
106
        dock_grid.attach (hide_mode, 2, 1, 2, 1);
 
107
        if (i < 1) {
 
108
            dock_grid.attach (new LLabel.right (_("Monitor:")), 0, 2, 2, 1);
 
109
            dock_grid.attach (monitor, 2, 2, 2, 1);
 
110
        }
 
111
        
 
112
        var fake_label = new Gtk.Label ("");
 
113
        fake_label.set_hexpand (true);
 
114
        dock_grid.attach (fake_label, 0, 0, 1, 1);
 
115
        
 
116
        notebook.append_page (dock_grid, new Gtk.Label (_("Dock")));
 
117
        
 
118
        /*hot corners*/
 
119
        var hotc_grid = new Gtk.Grid ();
 
120
        hotc_grid.column_spacing = 12;
 
121
        hotc_grid.margin = 32;
 
122
        hotc_grid.margin_top = 50;
 
123
        
 
124
        var expl = new LLabel (_("When the cursor enters the corner of the display:"));
 
125
        expl.margin_bottom = 10;
 
126
        expl.set_hexpand (true);
 
127
        
 
128
        var topleft = create_hotcorner ();
 
129
        topleft.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topleft").to_string ();
 
130
        topleft.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-topleft", int.parse (topleft.active_id)));
 
131
        topleft.valign = Gtk.Align.START;
 
132
        var topright = create_hotcorner ();
 
133
        topright.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-topright").to_string ();
 
134
        topright.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-topright", int.parse (topright.active_id)));
 
135
        topright.valign = Gtk.Align.START;
 
136
        var bottomleft = create_hotcorner ();
 
137
        bottomleft.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomleft").to_string ();
 
138
        bottomleft.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-bottomleft", int.parse (bottomleft.active_id)));
 
139
        bottomleft.valign = Gtk.Align.END;
 
140
        var bottomright = create_hotcorner ();
 
141
        bottomright.active_id = BehaviorSettings.get_default ().schema.get_enum ("hotcorner-bottomright").to_string ();
 
142
        bottomright.changed.connect (() => BehaviorSettings.get_default ().schema.set_enum ("hotcorner-bottomright", int.parse (bottomright.active_id)));
 
143
        bottomright.valign = Gtk.Align.END;
 
144
        
 
145
        var icon = new Gtk.Image.from_file (Constants.PKGDATADIR + "/hotcornerdisplay.png");
 
146
        var custom_command = new Gtk.Entry ();
 
147
        custom_command.text = BehaviorSettings.get_default ().hotcorner_custom_command;
 
148
        custom_command.changed.connect (() => BehaviorSettings.get_default ().hotcorner_custom_command = custom_command.text );
 
149
        
 
150
        var cc_grid = new Gtk.Grid ();
 
151
        cc_grid.set_column_spacing (12);
 
152
        cc_grid.set_margin_top (6);
 
153
        cc_grid.attach (new LLabel (_("Custom Command:")), 0, 0, 1, 1);
 
154
        cc_grid.attach (custom_command, 1, 0, 1, 1);
 
155
        
 
156
        
 
157
        hotc_grid.attach (expl, 0, 0, 3, 1);
 
158
        hotc_grid.attach (icon, 1, 1, 1, 3);
 
159
        hotc_grid.attach (topleft, 0, 1, 1, 1);
 
160
        hotc_grid.attach (topright, 2, 1, 1, 1);
 
161
        hotc_grid.attach (bottomleft, 0, 3, 1, 1);
 
162
        hotc_grid.attach (bottomright, 2, 3, 1, 1);
 
163
        hotc_grid.attach (cc_grid, 0, 4, 2, 1);
 
164
        
 
165
        notebook.append_page (hotc_grid, new Gtk.Label (_("Hot Corners")));
 
166
        
 
167
        
 
168
        add (notebook);
 
169
        
 
170
        notebook.page_changed.connect ((page) => {
 
171
            if (page == 0 && !wallpaper.finished) {
 
172
                switchboard_controller.progress_bar_set_visible (true);
 
173
            } else {
 
174
                switchboard_controller.progress_bar_set_visible (false);
 
175
            }
 
176
        });
 
177
    }
 
178
    
 
179
    Gtk.ComboBoxText create_hotcorner ()
 
180
    {
 
181
        var box = new Gtk.ComboBoxText ();
 
182
        box.append ("0", _("Do Nothing"));
 
183
        box.append ("1", _("Show Workspace View"));
 
184
        box.append ("2", _("Maximize Current Window"));
 
185
        box.append ("3", _("Minimize Current Window"));
 
186
        box.append ("4", _("Open Launcher"));
 
187
        box.append ("6", _("Expose All Windows"));
 
188
        box.append ("5", _("Execute Custom Command"));
 
189
        
 
190
        return box;
 
191
    }
 
192
}
 
193
 
 
194
public static int main (string[] args) {
 
195
 
 
196
    Gtk.init (ref args);
 
197
    
 
198
    var plug = new GalaPlug ();
 
199
    plug.register ("Effects");
 
200
    plug.show_all ();
 
201
    
 
202
    Gtk.main ();
 
203
    return 0;
 
204
}
 
205
 
 
206
public static void translations () {
 
207
    string desktop_name = _("Desktop");
202
208
}