/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-02 21:00:08 UTC
  • mfrom: (52.1.12 GPump_test)
  • Revision ID: gustav.hartvigsson@gmail.com-20141202210008-v9ma32lgz57i0ikb
* Made the window behave when it is shown

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 */
7
7
 
8
8
const Gtk = imports.gi.Gtk;
 
9
const _ = imports.gettext.gettext;
9
10
const Lang = imports.lang;
10
 
const _ = imports.gettext.gettext;
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,
19
22
    this.parent ({
20
23
      use_header_bar: true,
21
24
      modal: true,
22
 
      title: _("GPump preferences")
 
25
      title: _("GPump preferences"),
 
26
      width_request: 550,
 
27
      height_request: 300
23
28
    });
24
29
    
25
30
    this._prepare_header_bar ();
43
48
    special_btn_style_ctx.add_class ("suggested-action");
44
49
    
45
50
    this.close_btn.connect ('clicked', Lang.bind (this, function () {
 
51
      SettingsData.get_settings ().commit_to_file ();
46
52
      this.destroy ();
47
53
    }));
48
54
    
52
58
    /*this.get_content_area ().pack_start ()),
53
59
                                         true, true, 25);*/
54
60
    this.get_content_area ().set_center_widget (
55
 
                                          (this.list_box = new Gtk.ListBox ({
56
 
      width_request: 400,
57
 
      margin: 50,
58
 
      selection_mode: Gtk.SelectionMode.NONE
59
 
    })));
 
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
    );
60
83
    
61
84
    let settings_object = SettingsData.get_settings ();
62
85
    
68
91
    this.list_box.add (this.use_dark_hbox);
69
92
    
70
93
    this.use_dark_hbox.pack_start ((new Gtk.Label ({
71
 
                                                     label: _("Use dark theme")
72
 
                                                   })),
73
 
                                   false, false, 3);
74
 
    this.use_dark_hbox.pack_end ((this.use_dark_reset =
75
 
                                 new Gtk.Button ({
76
 
                                   image: edit_clear_icon})),
77
 
                                 false, false, 3);
 
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
    
78
101
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
79
102
                                 false, false, 3);
80
103
    
84
107
    
85
108
    this.use_dark_switch.connect("notify::active",
86
109
                                                  Lang.bind (this, function () {
87
 
      var settings = Gtk.Settings.get_default ();
88
 
      var app_settings = SettingsData.get_settings ();
 
110
      let settings = Gtk.Settings.get_default ();
 
111
      let app_settings = SettingsData.get_settings ();
89
112
      if ( this.use_dark_switch.get_active () ) {
90
113
        settings["gtk_application_prefer_dark_theme"] = true;
91
114
        app_settings.set_setting ("main.use_dark", true);
109
132
    this.list_box.add (this.show_full_name_hbox);
110
133
    
111
134
    this.show_full_name_hbox.pack_start ((new Gtk.Label ({
112
 
                                                     label: _("Show full name")
113
 
                                                   })),
114
 
                                   false, false, 3);
 
135
      label: _("Show full name")
 
136
    })),false, false, 3);
 
137
    
115
138
    this.show_full_name_hbox.pack_end ((this.show_full_name_reset =
116
 
                                 new Gtk.Button ({
117
 
                                   image: edit_clear_icon})),
118
 
                                 false, false, 3);
 
139
      new Gtk.Button ({
 
140
        image: edit_clear_icon
 
141
      })), false, false, 3);
 
142
    
119
143
    this.show_full_name_hbox.pack_end (
120
 
                               (this.show_full_name_switch = new Gtk.Switch ()),
121
 
                                 false, false, 3);
 
144
      (this.show_full_name_switch = new Gtk.Switch ()), false, false, 3);
 
145
    
122
146
    this.show_full_name_switch.set_active (
123
147
      settings_object.get_setting ("main.privacy.show_full_name").data
124
148
    );
125
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
    
126
163
    /*********************** only show avatar setting **************************/
127
164
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
128
165
    
131
168
    this.list_box.add (this.only_show_avatar_hbox);
132
169
    
133
170
    this.only_show_avatar_hbox.pack_start ((new Gtk.Label ({
134
 
                                                    label: _("Only show avatar")
135
 
                                                   })),
136
 
                                   false, false, 3);
137
 
    this.only_show_avatar_hbox.pack_end ((this.only_show_avatar_reset =
138
 
                                 new Gtk.Button ({
139
 
                                   image: edit_clear_icon})),
140
 
                                 false, false, 3);
 
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
    
141
179
    this.only_show_avatar_hbox.pack_end (
142
180
                             (this.only_show_avatar_switch = new Gtk.Switch ()),
143
181
                                 false, false, 3);
145
183
      settings_object.get_setting ("main.privacy.only_show_avatar").data
146
184
    );
147
185
    
148
 
    /* Spacer */
149
 
    //this.list_box.add ((new Gtk.Label ()));
 
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
    }));
150
195
    
151
196
    /* Reset all settings */
152
 
    this.list_box.add ((this.reset_all_btn = new Gtk.Button ({
153
 
      label: _("Reset all settings"),
154
 
      margin_left: 50,
155
 
      margin_right: 50,
156
 
      margin_top: 20
157
 
    })));
 
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
    );
158
205
    
159
206
    this.reset_all_btn.connect ("clicked", Lang.bind(this, this._reset_all));
160
207
  },
161
208
  
162
209
  _reset_all: function () {
163
210
    this._reset_use_dark_theme ();
 
211
    this._reset_show_full_name ();
 
212
    this._reset_only_show_avatar_reset ();
164
213
  },
165
214
  
166
215
  _reset_use_dark_theme: function () {
168
217
    if ((this.use_dark_switch.get_active ())) {
169
218
      this.use_dark_switch.set_active (false);
170
219
    }
171
 
    /* else we do nothing */
 
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
    }
172
232
  }
173
233
  
174
234
});