/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/preferences_ui.js

  • Committer: Gustav Hartvigsson
  • Date: 2015-06-05 19:06:14 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150605190614-s410mh65n2jdxtcv
* Cleaded up a lille code
* Fixed a nasty segfault that could occur if the conig folder did not exist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
const SettingsData = imports.settings_data;
13
13
 
 
14
/** @class
 
15
 * PreferencesUI.
 
16
 */
14
17
const PreferencesUI = Lang.Class ({
15
18
  Name: "PrefrencesUI",
16
19
  Extends: Gtk.Dialog,
17
20
  
18
 
  _init: function () {
 
21
  _init: function (params) {
19
22
    this.parent ({
20
23
      use_header_bar: true,
21
24
      modal: true,
24
27
      height_request: 300
25
28
    });
26
29
    
 
30
    if (params != undefined) {
 
31
      for (let k in params) {
 
32
        this[k] = params[k];
 
33
      }
 
34
    }
 
35
    
27
36
    this._prepare_header_bar ();
28
37
    this._prepare_list_box ();
29
38
    
45
54
    special_btn_style_ctx.add_class ("suggested-action");
46
55
    
47
56
    this.close_btn.connect ('clicked', Lang.bind (this, function () {
 
57
      SettingsData.get_settings ().commit_to_file ();
48
58
      this.destroy ();
49
59
    }));
50
60
    
80
90
    let settings_object = SettingsData.get_settings ();
81
91
    
82
92
    /*************************** Use dark setting *****************************/
83
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
84
93
    
85
 
    this.use_dark_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
94
    this.use_dark_hbox = new Gtk.Box ({orientation: Gtk.Orientation.HORIZONTAL,
 
95
                                       spacing: 5});
86
96
    
87
97
    this.list_box.add (this.use_dark_hbox);
88
98
    
89
99
    this.use_dark_hbox.pack_start ((new Gtk.Label ({
90
 
                                                     label: _("Use dark theme")
91
 
                                                   })),
92
 
                                   false, false, 3);
93
 
    this.use_dark_hbox.pack_end ((this.use_dark_reset =
94
 
                                 new Gtk.Button ({
95
 
                                   image: edit_clear_icon})),
96
 
                                 false, false, 3);
 
100
      label: _("Use dark theme")
 
101
    })),false, false, 3);
 
102
    
 
103
    this.use_dark_hbox.pack_end ((this.use_dark_reset = new Gtk.Button ({
 
104
      image: (new Gtk.Image ({icon_name: "edit-clear"}))
 
105
    })),false, false, 3);
 
106
    
97
107
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
98
108
                                 false, false, 3);
99
109
    
103
113
    
104
114
    this.use_dark_switch.connect("notify::active",
105
115
                                                  Lang.bind (this, function () {
106
 
      var settings = Gtk.Settings.get_default ();
107
 
      var app_settings = SettingsData.get_settings ();
 
116
      let settings = Gtk.Settings.get_default ();
 
117
      let app_settings = SettingsData.get_settings ();
108
118
      if ( this.use_dark_switch.get_active () ) {
109
119
        settings["gtk_application_prefer_dark_theme"] = true;
110
120
        app_settings.set_setting ("main.use_dark", true);
115
125
    }));
116
126
    
117
127
    this.use_dark_reset.connect ("clicked", Lang.bind (this,
118
 
                                                   this._reset_use_dark_theme));
 
128
                                 this._reset_use_dark_theme));
 
129
    
 
130
    /*********************** Quit on close ************************************/
 
131
    this.quit_on_close_hbox = new Gtk.Box ({
 
132
      orientation: Gtk.Orientation.HORIZONTAL,
 
133
      spacing: 5
 
134
    });
 
135
    
 
136
    this.list_box.add (this.quit_on_close_hbox);
 
137
    
 
138
    this.quit_on_close_hbox.pack_start ((new Gtk.Label ({
 
139
      label: _("Quit on close")
 
140
    })), false, false, 3);
 
141
    
 
142
    this.quit_on_close_hbox.pack_end ((this.quit_on_close_reset =
 
143
                                       new Gtk.Button ({
 
144
      image: (new Gtk.Image ({icon_name: "edit-clear"}))
 
145
    })), false, false, 3);
 
146
    
 
147
    this.quit_on_close_hbox.pack_end ((this.quit_on_close_switch =
 
148
                                       new Gtk.Switch), false, false, 3);
 
149
    
 
150
    if (settings_object.get_setting ("main.quit_on_close").data !=
 
151
                                       SettingsData.QUIT_ON_CLOSE.UNKNOWN) {
 
152
      this.quit_on_close_switch.set_active (Boolean (
 
153
        settings_object.get_setting ("main.quit_on_close")));
 
154
      print ("Herro!")
 
155
    } else {
 
156
      this.quit_on_close_switch.set_active (false);
 
157
    }
 
158
    
 
159
    this.quit_on_close_switch.connect ("notify::active",
 
160
                                       Lang.bind (this, function () {
 
161
      let v = settings_object.get_setting ("main.quit_on_close").data;
 
162
      
 
163
      switch (v) {
 
164
        case (SettingsData.QUIT_ON_CLOSE.YES):
 
165
        case (SettingsData.QUIT_ON_CLOSE.NO):
 
166
          if (this.quit_on_close_switch.get_active ()) {
 
167
            settings_object.set_setting ("main.quit_on_close", SettingsData.QUIT_ON_CLOSE.YES);
 
168
          } else {
 
169
            settings_object.set_setting ("main.quit_on_close", SettingsData.QUIT_ON_CLOSE.NO);
 
170
          }
 
171
          break;
 
172
          break;
 
173
        case (SettingsData.QUIT_ON_CLOSE.UNKNOWN):
 
174
          let popover = new Gtk.Popover ({relative_to: this.quit_on_close_switch, modal: true});
 
175
          let popover_layout1 = new Gtk.Box ({parent: popover, orientation: Gtk.Orientation.VERTICAL});
 
176
          popover_layout1.pack_start ((new Gtk.Label ({
 
177
            label: _("This has not been set yet, if you like to set it to a " +
 
178
            "value, click \"yes\" or \"no\", dismiss this to not set a value"),
 
179
            max_width_chars: 25,
 
180
            wrap: true
 
181
          })),false,false,0);
 
182
          let popover_layout2 = new Gtk.Box ({orientation: Gtk.Orientation.HORIZONTAL});
 
183
          popover_layout2.get_style_context().add_class ("linked");
 
184
          let btn_yes = new Gtk.Button ({label: _("Yes")});
 
185
          let btn_no = new Gtk.Button ({label: _("No")});
 
186
          popover_layout2.pack_end (btn_yes, true, true, 0);
 
187
          popover_layout2.pack_start (btn_no, true, true, 0);
 
188
          popover_layout1.pack_end (popover_layout2, false, false, 0);
 
189
          btn_no.get_style_context ().add_class("suggested-action");
 
190
          
 
191
          popover.connect_after ("hide", Lang.bind (popover, function () {
 
192
            popover.destroy ();
 
193
          }));
 
194
          
 
195
          btn_no.connect ("clicked", Lang.bind ((popover, this), function () {
 
196
            SettingsData.get_settings ().set_setting ("main.quit_on_close",
 
197
            SettingsData.QUIT_ON_CLOSE.NO);
 
198
            this.quit_on_close_switch.set_active (false);
 
199
            popover.hide ();
 
200
          }));
 
201
          
 
202
          btn_yes.connect ("clicked", Lang.bind ((popover, this), function () {
 
203
            SettingsData.get_settings ().set_setting ("main.quit_on_close",
 
204
            SettingsData.QUIT_ON_CLOSE.YES);
 
205
            this.quit_on_close_switch.set_active (true);
 
206
            popover.hide ();
 
207
          }));
 
208
          
 
209
          popover.show_all ();
 
210
          break;
 
211
        default:
 
212
          print ("WOW! Something went wrong!");
 
213
          print (JSON.stringify(v).toString ());
 
214
      }
 
215
    }));
 
216
    
119
217
    
120
218
    /*************************** Privacy settings *****************************/
121
219
    this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
122
220
    
123
221
    /************************ show full name setting **************************/
124
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
125
222
    
126
 
    this.show_full_name_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
223
    this.show_full_name_hbox = new Gtk.Box ({
 
224
      orientation: Gtk.Orientation.HORIZONTAL,
 
225
      spacing: 5
 
226
    });
127
227
    
128
228
    this.list_box.add (this.show_full_name_hbox);
129
229
    
130
230
    this.show_full_name_hbox.pack_start ((new Gtk.Label ({
131
 
                                                     label: _("Show full name")
132
 
                                                   })),
133
 
                                   false, false, 3);
 
231
      label: _("Show full name")
 
232
    })),false, false, 3);
 
233
    
134
234
    this.show_full_name_hbox.pack_end ((this.show_full_name_reset =
135
 
                                 new Gtk.Button ({
136
 
                                   image: edit_clear_icon})),
137
 
                                 false, false, 3);
 
235
      new Gtk.Button ({
 
236
        image: (new Gtk.Image ({icon_name: "edit-clear"}))
 
237
      })), false, false, 3);
 
238
    
138
239
    this.show_full_name_hbox.pack_end (
139
 
                               (this.show_full_name_switch = new Gtk.Switch ()),
140
 
                                 false, false, 3);
 
240
      (this.show_full_name_switch = new Gtk.Switch ()), false, false, 3);
 
241
    
141
242
    this.show_full_name_switch.set_active (
142
243
      settings_object.get_setting ("main.privacy.show_full_name").data
143
244
    );
144
245
    
 
246
    this.show_full_name_switch.connect ("notify::active",
 
247
                                        Lang.bind (this, function () {
 
248
      let app_settings = SettingsData.get_settings ();
 
249
      if (this.show_full_name_switch.get_active ()) {
 
250
        app_settings.set_setting ("main.privacy.show_full_name", true);
 
251
      } else {
 
252
        app_settings.set_setting ("main.privacy.show_full_name", false);
 
253
      }
 
254
    }));
 
255
    
 
256
    this.show_full_name_reset.connect ("clicked", Lang.bind (this,
 
257
                                                  this._reset_show_full_name));
 
258
    
145
259
    /*********************** only show avatar setting **************************/
146
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
147
260
    
148
 
    this.only_show_avatar_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
261
    this.only_show_avatar_hbox = new Gtk.Box ({orientation: Gtk.Orientation.HORIZONTAL,
 
262
                                       spacing: 5});
149
263
    
150
264
    this.list_box.add (this.only_show_avatar_hbox);
151
265
    
152
266
    this.only_show_avatar_hbox.pack_start ((new Gtk.Label ({
153
 
                                                    label: _("Only show avatar")
154
 
                                                   })),
155
 
                                   false, false, 3);
156
 
    this.only_show_avatar_hbox.pack_end ((this.only_show_avatar_reset =
157
 
                                 new Gtk.Button ({
158
 
                                   image: edit_clear_icon})),
159
 
                                 false, false, 3);
 
267
      label: _("Only show avatar")
 
268
    })), false, false, 3);
 
269
    
 
270
    this.only_show_avatar_hbox.pack_end ((this.only_show_avatar_reset = 
 
271
                                          new Gtk.Button ({
 
272
      image: (new Gtk.Image ({icon_name: "edit-clear"}))
 
273
    })), false, false, 3);
 
274
    
160
275
    this.only_show_avatar_hbox.pack_end (
161
276
                             (this.only_show_avatar_switch = new Gtk.Switch ()),
162
277
                                 false, false, 3);
164
279
      settings_object.get_setting ("main.privacy.only_show_avatar").data
165
280
    );
166
281
    
167
 
    /* Spacer */
168
 
    //this.list_box.add ((new Gtk.Label ()));
 
282
    this.only_show_avatar_switch.connect ("notify::active",
 
283
                                          Lang.bind (this, function () {
 
284
      let app_settings = SettingsData.get_settings ();
 
285
      if (this.only_show_avatar_switch.get_active ()) {
 
286
        app_settings.set_setting ("main.privacy.only_show_avatar", true);
 
287
      } else {
 
288
        app_settings.set_setting ("main.privacy.only_show_avatar", false);
 
289
      }
 
290
    }));
169
291
    
170
292
    /* Reset all settings */
171
293
    this.layout.pack_end (
182
304
  
183
305
  _reset_all: function () {
184
306
    this._reset_use_dark_theme ();
 
307
    this._reset_show_full_name ();
 
308
    this._reset_only_show_avatar ();
 
309
    this._reset_quit_on_close
185
310
  },
186
311
  
187
312
  _reset_use_dark_theme: function () {
189
314
    if ((this.use_dark_switch.get_active ())) {
190
315
      this.use_dark_switch.set_active (false);
191
316
    }
192
 
    /* else we do nothing */
 
317
  },
 
318
  
 
319
  _reset_show_full_name: function () {
 
320
    if (!(this.show_full_name_switch.get_active ())) {
 
321
      this.show_full_name_switch.set_active (true);
 
322
    }
 
323
  },
 
324
  
 
325
  _reset_only_show_avatar: function () {
 
326
    if ((this.only_show_avatar_switch.get_active ())) {
 
327
      this.only_show_avatar_switch.set_active (false);
 
328
    }
 
329
  },
 
330
  
 
331
  _reset_quit_on_close: function () {
 
332
    if ((this.quit_on_close_switch.get_active())) {
 
333
      this.quit_on_close_switch.set_active (false);
 
334
    }
193
335
  }
194
336
  
195
337
});