/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-11-18 20:53:37 UTC
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: gustav.hartvigsson@gmail.com-20141118205337-j6opehfighclrkqc
* added 'make gettext' for generating gettext information
* updated 'messages.po' to fit the resent changes

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
const PreferencesUI = Lang.Class ({
 
15
  Name: "PrefrencesUI",
 
16
  Extends: Gtk.Dialog,
 
17
  
 
18
  _init: function () {
 
19
    this.parent ({
 
20
      use_header_bar: true,
 
21
      modal: true,
 
22
      title: _("GPump preferences"),
 
23
      width_request: 550,
 
24
      height_request: 300
 
25
    });
 
26
    
 
27
    this._prepare_header_bar ();
 
28
    this._prepare_list_box ();
 
29
    
 
30
    this.set_property ('resizable', false);
 
31
    
 
32
    this.show_all ();
 
33
  },
 
34
  
 
35
  _prepare_header_bar: function () {
 
36
    
 
37
    this.headerbar = this.get_header_bar ();
 
38
    this.headerbar.set_show_close_button (false);
 
39
    this.headerbar.pack_end ((this.close_btn = new Gtk.Button ({
 
40
      label: _("close")
 
41
    })));
 
42
    
 
43
    /* Install a custom style */
 
44
    let special_btn_style_ctx = this.close_btn.get_style_context ();
 
45
    special_btn_style_ctx.add_class ("suggested-action");
 
46
    
 
47
    this.close_btn.connect ('clicked', Lang.bind (this, function () {
 
48
      this.destroy ();
 
49
    }));
 
50
    
 
51
  },
 
52
  
 
53
  _prepare_list_box: function () {
 
54
    /*this.get_content_area ().pack_start ()),
 
55
                                         true, true, 25);*/
 
56
    this.get_content_area ().set_center_widget (
 
57
      (this.layout = new Gtk.Box ({
 
58
        orientation: Gtk.Orientation.VERTICAL,
 
59
        spacing: 8,
 
60
        border_width: 8,
 
61
        margin: 50
 
62
      }))
 
63
    );
 
64
    
 
65
    
 
66
    this.layout.pack_start (
 
67
      new Gtk.Frame ({child:
 
68
        (this.list_box = new Gtk.ListBox ({
 
69
          width_request: 400,
 
70
          selection_mode: Gtk.SelectionMode.NONE,
 
71
          expand: false
 
72
        })),
 
73
        expand: false
 
74
      }),
 
75
      true,
 
76
      true,
 
77
      null
 
78
    );
 
79
    
 
80
    let settings_object = SettingsData.get_settings ();
 
81
    
 
82
    /*************************** Use dark setting *****************************/
 
83
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
 
84
    
 
85
    this.use_dark_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
86
    
 
87
    this.list_box.add (this.use_dark_hbox);
 
88
    
 
89
    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);
 
97
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
 
98
                                 false, false, 3);
 
99
    
 
100
    this.use_dark_switch.set_active (
 
101
      settings_object.get_setting("main.use_dark").data
 
102
    );
 
103
    
 
104
    this.use_dark_switch.connect("notify::active",
 
105
                                                  Lang.bind (this, function () {
 
106
      var settings = Gtk.Settings.get_default ();
 
107
      var app_settings = SettingsData.get_settings ();
 
108
      if ( this.use_dark_switch.get_active () ) {
 
109
        settings["gtk_application_prefer_dark_theme"] = true;
 
110
        app_settings.set_setting ("main.use_dark", true);
 
111
      } else {
 
112
        settings["gtk_application_prefer_dark_theme"] = false;
 
113
        app_settings.set_setting ("main.use_dark", false);
 
114
      }
 
115
    }));
 
116
    
 
117
    this.use_dark_reset.connect ("clicked", Lang.bind (this,
 
118
                                                   this._reset_use_dark_theme));
 
119
    
 
120
    /*************************** Privacy settings *****************************/
 
121
    this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
 
122
    
 
123
    /************************ show full name setting **************************/
 
124
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
 
125
    
 
126
    this.show_full_name_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
127
    
 
128
    this.list_box.add (this.show_full_name_hbox);
 
129
    
 
130
    this.show_full_name_hbox.pack_start ((new Gtk.Label ({
 
131
                                                     label: _("Show full name")
 
132
                                                   })),
 
133
                                   false, false, 3);
 
134
    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);
 
138
    this.show_full_name_hbox.pack_end (
 
139
                               (this.show_full_name_switch = new Gtk.Switch ()),
 
140
                                 false, false, 3);
 
141
    this.show_full_name_switch.set_active (
 
142
      settings_object.get_setting ("main.privacy.show_full_name").data
 
143
    );
 
144
    
 
145
    /*********************** only show avatar setting **************************/
 
146
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
 
147
    
 
148
    this.only_show_avatar_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
149
    
 
150
    this.list_box.add (this.only_show_avatar_hbox);
 
151
    
 
152
    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);
 
160
    this.only_show_avatar_hbox.pack_end (
 
161
                             (this.only_show_avatar_switch = new Gtk.Switch ()),
 
162
                                 false, false, 3);
 
163
    this.only_show_avatar_switch.set_active (
 
164
      settings_object.get_setting ("main.privacy.only_show_avatar").data
 
165
    );
 
166
    
 
167
    /* Spacer */
 
168
    //this.list_box.add ((new Gtk.Label ()));
 
169
    
 
170
    /* Reset all settings */
 
171
    this.layout.pack_end (
 
172
      (this.reset_all_btn = new Gtk.Button ({
 
173
        label: _("Reset all settings")
 
174
      })),
 
175
      false,
 
176
      false,
 
177
      null
 
178
    );
 
179
    
 
180
    this.reset_all_btn.connect ("clicked", Lang.bind(this, this._reset_all));
 
181
  },
 
182
  
 
183
  _reset_all: function () {
 
184
    this._reset_use_dark_theme ();
 
185
  },
 
186
  
 
187
  _reset_use_dark_theme: function () {
 
188
    /* If the switch is active */
 
189
    if ((this.use_dark_switch.get_active ())) {
 
190
      this.use_dark_switch.set_active (false);
 
191
    }
 
192
    /* else we do nothing */
 
193
  }
 
194
  
 
195
});