/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk
45 by Gustav Hartvigsson
* forgot the bloody file...
1
/* This file is part of GPump, a Pump.io client.
2
 *
3
 * GPump (THE SOFTWARE) is made available under the terms and conditions of the
4
 * GNU Lesser General Public Licence 3.0. A copy of the licence can be read
5
 * in the file lgpl-3.0.txt in the root of this project.
6
 */
7
8
const Gtk = imports.gi.Gtk;
52.1.1 by Gustav Hartvigsson
Button still not worknig, saving for prosparitny
9
const _ = imports.gettext.gettext;
45 by Gustav Hartvigsson
* forgot the bloody file...
10
const Lang = imports.lang;
11
12
const SettingsData = imports.settings_data;
13
52.1.8 by Gustav Hartvigsson
* Strted work on changing how the SettingsData class works,
14
/** @class
15
 * PreferencesUI.
16
 */
45 by Gustav Hartvigsson
* forgot the bloody file...
17
const PreferencesUI = Lang.Class ({
18
  Name: "PrefrencesUI",
19
  Extends: Gtk.Dialog,
20
  
55 by Gustav Hartvigsson
* Code cleanup
21
  _init: function (params) {
45 by Gustav Hartvigsson
* forgot the bloody file...
22
    this.parent ({
23
      use_header_bar: true,
47 by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons
24
      modal: true,
52.1.2 by Gustav Hartvigsson
* Fixed a few style errors...
25
      title: _("GPump preferences"),
26
      width_request: 550,
27
      height_request: 300
45 by Gustav Hartvigsson
* forgot the bloody file...
28
    });
29
    
55 by Gustav Hartvigsson
* Code cleanup
30
    if (params != undefined) {
31
      for (let k in params) {
32
        this[k] = params[k];
33
      }
34
    }
35
    
45 by Gustav Hartvigsson
* forgot the bloody file...
36
    this._prepare_header_bar ();
37
    this._prepare_list_box ();
38
    
39
    this.set_property ('resizable', false);
40
    
41
    this.show_all ();
42
  },
43
  
44
  _prepare_header_bar: function () {
45
    
46
    this.headerbar = this.get_header_bar ();
47
    this.headerbar.set_show_close_button (false);
48
    this.headerbar.pack_end ((this.close_btn = new Gtk.Button ({
49
      label: _("close")
50
    })));
51
    
49 by Gustav Hartvigsson
* Changes a thing in the about dialoug.
52
    /* Install a custom style */
53
    let special_btn_style_ctx = this.close_btn.get_style_context ();
54
    special_btn_style_ctx.add_class ("suggested-action");
55
    
45 by Gustav Hartvigsson
* forgot the bloody file...
56
    this.close_btn.connect ('clicked', Lang.bind (this, function () {
52.1.10 by Gustav Hartvigsson
* made the UserButton work in tests.
57
      SettingsData.get_settings ().commit_to_file ();
45 by Gustav Hartvigsson
* forgot the bloody file...
58
      this.destroy ();
59
    }));
60
    
61
  },
62
  
63
  _prepare_list_box: function () {
64
    /*this.get_content_area ().pack_start ()),
65
                                         true, true, 25);*/
66
    this.get_content_area ().set_center_widget (
52.1.4 by Gustav Hartvigsson
* Made the Pref. dialoug look waaaay better
67
      (this.layout = new Gtk.Box ({
68
        orientation: Gtk.Orientation.VERTICAL,
69
        spacing: 8,
70
        border_width: 8,
71
        margin: 50
72
      }))
73
    );
74
    
75
    
76
    this.layout.pack_start (
52.1.2 by Gustav Hartvigsson
* Fixed a few style errors...
77
      new Gtk.Frame ({child:
78
        (this.list_box = new Gtk.ListBox ({
79
          width_request: 400,
80
          selection_mode: Gtk.SelectionMode.NONE,
81
          expand: false
82
        })),
52.1.4 by Gustav Hartvigsson
* Made the Pref. dialoug look waaaay better
83
        expand: false
84
      }),
85
      true,
86
      true,
87
      null
52.1.2 by Gustav Hartvigsson
* Fixed a few style errors...
88
    );
45 by Gustav Hartvigsson
* forgot the bloody file...
89
    
90
    let settings_object = SettingsData.get_settings ();
91
    
92
    /*************************** Use dark setting *****************************/
93
    
55 by Gustav Hartvigsson
* Code cleanup
94
    this.use_dark_hbox = new Gtk.Box ({orientation: Gtk.Orientation.HORIZONTAL,
95
                                       spacing: 5});
45 by Gustav Hartvigsson
* forgot the bloody file...
96
    
97
    this.list_box.add (this.use_dark_hbox);
98
    
99
    this.use_dark_hbox.pack_start ((new Gtk.Label ({
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
100
      label: _("Use dark theme")
101
    })),false, false, 3);
102
    
103
    this.use_dark_hbox.pack_end ((this.use_dark_reset = new Gtk.Button ({
55 by Gustav Hartvigsson
* Code cleanup
104
      image: (new Gtk.Image ({icon_name: "edit-clear"}))
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
105
    })),false, false, 3);
106
    
45 by Gustav Hartvigsson
* forgot the bloody file...
107
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
108
                                 false, false, 3);
109
    
110
    this.use_dark_switch.set_active (
111
      settings_object.get_setting("main.use_dark").data
112
    );
113
    
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
114
    this.use_dark_switch.connect("notify::active",
115
                                                  Lang.bind (this, function () {
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
116
      let settings = Gtk.Settings.get_default ();
117
      let app_settings = SettingsData.get_settings ();
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
118
      if ( this.use_dark_switch.get_active () ) {
119
        settings["gtk_application_prefer_dark_theme"] = true;
120
        app_settings.set_setting ("main.use_dark", true);
121
      } else {
122
        settings["gtk_application_prefer_dark_theme"] = false;
123
        app_settings.set_setting ("main.use_dark", false);
124
      }
125
    }));
126
    
127
    this.use_dark_reset.connect ("clicked", Lang.bind (this,
55 by Gustav Hartvigsson
* Code cleanup
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
    
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
217
    
45 by Gustav Hartvigsson
* forgot the bloody file...
218
    /*************************** Privacy settings *****************************/
219
    this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
220
    
221
    /************************ show full name setting **************************/
222
    
55 by Gustav Hartvigsson
* Code cleanup
223
    this.show_full_name_hbox = new Gtk.Box ({
224
      orientation: Gtk.Orientation.HORIZONTAL,
225
      spacing: 5
226
    });
45 by Gustav Hartvigsson
* forgot the bloody file...
227
    
228
    this.list_box.add (this.show_full_name_hbox);
229
    
230
    this.show_full_name_hbox.pack_start ((new Gtk.Label ({
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
231
      label: _("Show full name")
232
    })),false, false, 3);
233
    
45 by Gustav Hartvigsson
* forgot the bloody file...
234
    this.show_full_name_hbox.pack_end ((this.show_full_name_reset =
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
235
      new Gtk.Button ({
55 by Gustav Hartvigsson
* Code cleanup
236
        image: (new Gtk.Image ({icon_name: "edit-clear"}))
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
237
      })), false, false, 3);
238
    
45 by Gustav Hartvigsson
* forgot the bloody file...
239
    this.show_full_name_hbox.pack_end (
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
240
      (this.show_full_name_switch = new Gtk.Switch ()), false, false, 3);
241
    
45 by Gustav Hartvigsson
* forgot the bloody file...
242
    this.show_full_name_switch.set_active (
243
      settings_object.get_setting ("main.privacy.show_full_name").data
244
    );
245
    
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
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
    
45 by Gustav Hartvigsson
* forgot the bloody file...
259
    /*********************** only show avatar setting **************************/
260
    
55 by Gustav Hartvigsson
* Code cleanup
261
    this.only_show_avatar_hbox = new Gtk.Box ({orientation: Gtk.Orientation.HORIZONTAL,
262
                                       spacing: 5});
45 by Gustav Hartvigsson
* forgot the bloody file...
263
    
264
    this.list_box.add (this.only_show_avatar_hbox);
265
    
266
    this.only_show_avatar_hbox.pack_start ((new Gtk.Label ({
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
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 ({
55 by Gustav Hartvigsson
* Code cleanup
272
      image: (new Gtk.Image ({icon_name: "edit-clear"}))
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
273
    })), false, false, 3);
274
    
45 by Gustav Hartvigsson
* forgot the bloody file...
275
    this.only_show_avatar_hbox.pack_end (
276
                             (this.only_show_avatar_switch = new Gtk.Switch ()),
277
                                 false, false, 3);
278
    this.only_show_avatar_switch.set_active (
279
      settings_object.get_setting ("main.privacy.only_show_avatar").data
280
    );
281
    
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
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
    }));
45 by Gustav Hartvigsson
* forgot the bloody file...
291
    
292
    /* Reset all settings */
52.1.4 by Gustav Hartvigsson
* Made the Pref. dialoug look waaaay better
293
    this.layout.pack_end (
294
      (this.reset_all_btn = new Gtk.Button ({
295
        label: _("Reset all settings")
296
      })),
297
      false,
298
      false,
299
      null
300
    );
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
301
    
302
    this.reset_all_btn.connect ("clicked", Lang.bind(this, this._reset_all));
303
  },
304
  
305
  _reset_all: function () {
306
    this._reset_use_dark_theme ();
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
307
    this._reset_show_full_name ();
55 by Gustav Hartvigsson
* Code cleanup
308
    this._reset_only_show_avatar ();
309
    this._reset_quit_on_close
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
310
  },
311
  
312
  _reset_use_dark_theme: function () {
313
    /* If the switch is active */
314
    if ((this.use_dark_switch.get_active ())) {
315
      this.use_dark_switch.set_active (false);
316
    }
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
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
  
55 by Gustav Hartvigsson
* Code cleanup
325
  _reset_only_show_avatar: function () {
52.1.7 by Gustav Hartvigsson
* changed the 'user icon' temporarely, until I get the
326
    if ((this.only_show_avatar_switch.get_active ())) {
327
      this.only_show_avatar_switch.set_active (false);
328
    }
55 by Gustav Hartvigsson
* Code cleanup
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
    }
45 by Gustav Hartvigsson
* forgot the bloody file...
335
  }
336
  
337
});