/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-02-08 17:53:39 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140208175339-yxn38uceduzzvswx
Initial code.

Non of the code is actualy functional.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
9
 
const _ = imports.gettext.gettext;
10
 
const Lang = imports.lang;
11
 
 
12
 
const SettingsData = imports.settings_data;
13
 
 
14
 
/** @class
15
 
 * PreferencesUI.
16
 
 */
17
 
const PreferencesUI = Lang.Class ({
18
 
  Name: "PrefrencesUI",
19
 
  Extends: Gtk.Dialog,
20
 
  
21
 
  _init: function () {
22
 
    this.parent ({
23
 
      use_header_bar: true,
24
 
      modal: true,
25
 
      title: _("GPump preferences"),
26
 
      width_request: 550,
27
 
      height_request: 300
28
 
    });
29
 
    
30
 
    this._prepare_header_bar ();
31
 
    this._prepare_list_box ();
32
 
    
33
 
    this.set_property ('resizable', false);
34
 
    
35
 
    this.show_all ();
36
 
  },
37
 
  
38
 
  _prepare_header_bar: function () {
39
 
    
40
 
    this.headerbar = this.get_header_bar ();
41
 
    this.headerbar.set_show_close_button (false);
42
 
    this.headerbar.pack_end ((this.close_btn = new Gtk.Button ({
43
 
      label: _("close")
44
 
    })));
45
 
    
46
 
    /* Install a custom style */
47
 
    let special_btn_style_ctx = this.close_btn.get_style_context ();
48
 
    special_btn_style_ctx.add_class ("suggested-action");
49
 
    
50
 
    this.close_btn.connect ('clicked', Lang.bind (this, function () {
51
 
      SettingsData.get_settings ().commit_to_file ();
52
 
      this.destroy ();
53
 
    }));
54
 
    
55
 
  },
56
 
  
57
 
  _prepare_list_box: function () {
58
 
    /*this.get_content_area ().pack_start ()),
59
 
                                         true, true, 25);*/
60
 
    this.get_content_area ().set_center_widget (
61
 
      (this.layout = new Gtk.Box ({
62
 
        orientation: Gtk.Orientation.VERTICAL,
63
 
        spacing: 8,
64
 
        border_width: 8,
65
 
        margin: 50
66
 
      }))
67
 
    );
68
 
    
69
 
    
70
 
    this.layout.pack_start (
71
 
      new Gtk.Frame ({child:
72
 
        (this.list_box = new Gtk.ListBox ({
73
 
          width_request: 400,
74
 
          selection_mode: Gtk.SelectionMode.NONE,
75
 
          expand: false
76
 
        })),
77
 
        expand: false
78
 
      }),
79
 
      true,
80
 
      true,
81
 
      null
82
 
    );
83
 
    
84
 
    let settings_object = SettingsData.get_settings ();
85
 
    
86
 
    /*************************** Use dark setting *****************************/
87
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
88
 
    
89
 
    this.use_dark_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
90
 
    
91
 
    this.list_box.add (this.use_dark_hbox);
92
 
    
93
 
    this.use_dark_hbox.pack_start ((new Gtk.Label ({
94
 
      label: _("Use dark theme")
95
 
    })),false, false, 3);
96
 
    
97
 
    this.use_dark_hbox.pack_end ((this.use_dark_reset = new Gtk.Button ({
98
 
      image: edit_clear_icon
99
 
    })),false, false, 3);
100
 
    
101
 
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
102
 
                                 false, false, 3);
103
 
    
104
 
    this.use_dark_switch.set_active (
105
 
      settings_object.get_setting("main.use_dark").data
106
 
    );
107
 
    
108
 
    this.use_dark_switch.connect("notify::active",
109
 
                                                  Lang.bind (this, function () {
110
 
      let settings = Gtk.Settings.get_default ();
111
 
      let app_settings = SettingsData.get_settings ();
112
 
      if ( this.use_dark_switch.get_active () ) {
113
 
        settings["gtk_application_prefer_dark_theme"] = true;
114
 
        app_settings.set_setting ("main.use_dark", true);
115
 
      } else {
116
 
        settings["gtk_application_prefer_dark_theme"] = false;
117
 
        app_settings.set_setting ("main.use_dark", false);
118
 
      }
119
 
    }));
120
 
    
121
 
    this.use_dark_reset.connect ("clicked", Lang.bind (this,
122
 
                                                   this._reset_use_dark_theme));
123
 
    
124
 
    /*************************** Privacy settings *****************************/
125
 
    this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
126
 
    
127
 
    /************************ show full name setting **************************/
128
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
129
 
    
130
 
    this.show_full_name_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
131
 
    
132
 
    this.list_box.add (this.show_full_name_hbox);
133
 
    
134
 
    this.show_full_name_hbox.pack_start ((new Gtk.Label ({
135
 
      label: _("Show full name")
136
 
    })),false, false, 3);
137
 
    
138
 
    this.show_full_name_hbox.pack_end ((this.show_full_name_reset =
139
 
      new Gtk.Button ({
140
 
        image: edit_clear_icon
141
 
      })), false, false, 3);
142
 
    
143
 
    this.show_full_name_hbox.pack_end (
144
 
      (this.show_full_name_switch = new Gtk.Switch ()), false, false, 3);
145
 
    
146
 
    this.show_full_name_switch.set_active (
147
 
      settings_object.get_setting ("main.privacy.show_full_name").data
148
 
    );
149
 
    
150
 
    this.show_full_name_switch.connect ("notify::active",
151
 
                                        Lang.bind (this, function () {
152
 
      let app_settings = SettingsData.get_settings ();
153
 
      if (this.show_full_name_switch.get_active ()) {
154
 
        app_settings.set_setting ("main.privacy.show_full_name", true);
155
 
      } else {
156
 
        app_settings.set_setting ("main.privacy.show_full_name", false);
157
 
      }
158
 
    }));
159
 
    
160
 
    this.show_full_name_reset.connect ("clicked", Lang.bind (this,
161
 
                                                  this._reset_show_full_name));
162
 
    
163
 
    /*********************** only show avatar setting **************************/
164
 
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
165
 
    
166
 
    this.only_show_avatar_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
167
 
    
168
 
    this.list_box.add (this.only_show_avatar_hbox);
169
 
    
170
 
    this.only_show_avatar_hbox.pack_start ((new Gtk.Label ({
171
 
      label: _("Only show avatar")
172
 
    })), false, false, 3);
173
 
    
174
 
    this.only_show_avatar_hbox.pack_end ((this.only_show_avatar_reset = 
175
 
                                          new Gtk.Button ({
176
 
      image: edit_clear_icon
177
 
    })), false, false, 3);
178
 
    
179
 
    this.only_show_avatar_hbox.pack_end (
180
 
                             (this.only_show_avatar_switch = new Gtk.Switch ()),
181
 
                                 false, false, 3);
182
 
    this.only_show_avatar_switch.set_active (
183
 
      settings_object.get_setting ("main.privacy.only_show_avatar").data
184
 
    );
185
 
    
186
 
    this.only_show_avatar_switch.connect ("notify::active",
187
 
                                          Lang.bind (this, function () {
188
 
      let app_settings = SettingsData.get_settings ();
189
 
      if (this.only_show_avatar_switch.get_active ()) {
190
 
        app_settings.set_setting ("main.privacy.only_show_avatar", true);
191
 
      } else {
192
 
        app_settings.set_setting ("main.privacy.only_show_avatar", false);
193
 
      }
194
 
    }));
195
 
    
196
 
    /* Reset all settings */
197
 
    this.layout.pack_end (
198
 
      (this.reset_all_btn = new Gtk.Button ({
199
 
        label: _("Reset all settings")
200
 
      })),
201
 
      false,
202
 
      false,
203
 
      null
204
 
    );
205
 
    
206
 
    this.reset_all_btn.connect ("clicked", Lang.bind(this, this._reset_all));
207
 
  },
208
 
  
209
 
  _reset_all: function () {
210
 
    this._reset_use_dark_theme ();
211
 
    this._reset_show_full_name ();
212
 
    this._reset_only_show_avatar_reset ();
213
 
  },
214
 
  
215
 
  _reset_use_dark_theme: function () {
216
 
    /* If the switch is active */
217
 
    if ((this.use_dark_switch.get_active ())) {
218
 
      this.use_dark_switch.set_active (false);
219
 
    }
220
 
  },
221
 
  
222
 
  _reset_show_full_name: function () {
223
 
    if (!(this.show_full_name_switch.get_active ())) {
224
 
      this.show_full_name_switch.set_active (true);
225
 
    }
226
 
  },
227
 
  
228
 
  _reset_only_show_avatar_reset: function () {
229
 
    if ((this.only_show_avatar_switch.get_active ())) {
230
 
      this.only_show_avatar_switch.set_active (false);
231
 
    }
232
 
  }
233
 
  
234
 
});