/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: 2014-12-15 21:45:36 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20141215214536-ty17fg5rq06clphg
* Code cleanup
* fixed a Gtk warning (by hooking up the parameters thingy)
* Hooked up "quit on exit" in the references UI.
  * added a popover to set it for the first time...
    This way of doing it is not so good, I think I will have
    to re-do how "quit on exit" is handled.
* Switched the order of the fealds in the return map in the
  SettingsData.get_setting.
  This should, hypothetically, make it posible to use the the ret
  data as is.
  This shoold probably be be redone to just return undefined.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  Name: "PrefrencesUI",
19
19
  Extends: Gtk.Dialog,
20
20
  
21
 
  _init: function () {
 
21
  _init: function (params) {
22
22
    this.parent ({
23
23
      use_header_bar: true,
24
24
      modal: true,
27
27
      height_request: 300
28
28
    });
29
29
    
 
30
    if (params != undefined) {
 
31
      for (let k in params) {
 
32
        this[k] = params[k];
 
33
      }
 
34
    }
 
35
    
30
36
    this._prepare_header_bar ();
31
37
    this._prepare_list_box ();
32
38
    
84
90
    let settings_object = SettingsData.get_settings ();
85
91
    
86
92
    /*************************** Use dark setting *****************************/
87
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
88
93
    
89
 
    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});
90
96
    
91
97
    this.list_box.add (this.use_dark_hbox);
92
98
    
95
101
    })),false, false, 3);
96
102
    
97
103
    this.use_dark_hbox.pack_end ((this.use_dark_reset = new Gtk.Button ({
98
 
      image: edit_clear_icon
 
104
      image: (new Gtk.Image ({icon_name: "edit-clear"}))
99
105
    })),false, false, 3);
100
106
    
101
107
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
119
125
    }));
120
126
    
121
127
    this.use_dark_reset.connect ("clicked", Lang.bind (this,
122
 
                                                   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
    
123
217
    
124
218
    /*************************** Privacy settings *****************************/
125
219
    this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
126
220
    
127
221
    /************************ show full name setting **************************/
128
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
129
222
    
130
 
    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
    });
131
227
    
132
228
    this.list_box.add (this.show_full_name_hbox);
133
229
    
137
233
    
138
234
    this.show_full_name_hbox.pack_end ((this.show_full_name_reset =
139
235
      new Gtk.Button ({
140
 
        image: edit_clear_icon
 
236
        image: (new Gtk.Image ({icon_name: "edit-clear"}))
141
237
      })), false, false, 3);
142
238
    
143
239
    this.show_full_name_hbox.pack_end (
161
257
                                                  this._reset_show_full_name));
162
258
    
163
259
    /*********************** only show avatar setting **************************/
164
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
165
260
    
166
 
    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});
167
263
    
168
264
    this.list_box.add (this.only_show_avatar_hbox);
169
265
    
173
269
    
174
270
    this.only_show_avatar_hbox.pack_end ((this.only_show_avatar_reset = 
175
271
                                          new Gtk.Button ({
176
 
      image: edit_clear_icon
 
272
      image: (new Gtk.Image ({icon_name: "edit-clear"}))
177
273
    })), false, false, 3);
178
274
    
179
275
    this.only_show_avatar_hbox.pack_end (
209
305
  _reset_all: function () {
210
306
    this._reset_use_dark_theme ();
211
307
    this._reset_show_full_name ();
212
 
    this._reset_only_show_avatar_reset ();
 
308
    this._reset_only_show_avatar ();
 
309
    this._reset_quit_on_close
213
310
  },
214
311
  
215
312
  _reset_use_dark_theme: function () {
225
322
    }
226
323
  },
227
324
  
228
 
  _reset_only_show_avatar_reset: function () {
 
325
  _reset_only_show_avatar: function () {
229
326
    if ((this.only_show_avatar_switch.get_active ())) {
230
327
      this.only_show_avatar_switch.set_active (false);
231
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
    }
232
335
  }
233
336
  
234
337
});