/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:11:21 UTC
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: gustav.hartvigsson@gmail.com-20141118201121-o0rwh33ra0lmldxp
* Made the Pref. dialoug look waaaay better

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
    
 
67
    this.layout.pack_start (
 
68
      new Gtk.Frame ({child:
 
69
        (this.list_box = new Gtk.ListBox ({
 
70
          width_request: 400,
 
71
          selection_mode: Gtk.SelectionMode.NONE,
 
72
          expand: false
 
73
        })),
 
74
        expand: false
 
75
      }),
 
76
      true,
 
77
      true,
 
78
      null
 
79
    );
 
80
    
 
81
    let settings_object = SettingsData.get_settings ();
 
82
    
 
83
    /*************************** Use dark setting *****************************/
 
84
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
 
85
    
 
86
    this.use_dark_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
87
    
 
88
    this.list_box.add (this.use_dark_hbox);
 
89
    
 
90
    this.use_dark_hbox.pack_start ((new Gtk.Label ({
 
91
                                                     label: _("Use dark theme")
 
92
                                                   })),
 
93
                                   false, false, 3);
 
94
    this.use_dark_hbox.pack_end ((this.use_dark_reset =
 
95
                                 new Gtk.Button ({
 
96
                                   image: edit_clear_icon})),
 
97
                                 false, false, 3);
 
98
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
 
99
                                 false, false, 3);
 
100
    
 
101
    this.use_dark_switch.set_active (
 
102
      settings_object.get_setting("main.use_dark").data
 
103
    );
 
104
    
 
105
    this.use_dark_switch.connect("notify::active",
 
106
                                                  Lang.bind (this, function () {
 
107
      var settings = Gtk.Settings.get_default ();
 
108
      var app_settings = SettingsData.get_settings ();
 
109
      if ( this.use_dark_switch.get_active () ) {
 
110
        settings["gtk_application_prefer_dark_theme"] = true;
 
111
        app_settings.set_setting ("main.use_dark", true);
 
112
      } else {
 
113
        settings["gtk_application_prefer_dark_theme"] = false;
 
114
        app_settings.set_setting ("main.use_dark", false);
 
115
      }
 
116
    }));
 
117
    
 
118
    this.use_dark_reset.connect ("clicked", Lang.bind (this,
 
119
                                                   this._reset_use_dark_theme));
 
120
    
 
121
    /*************************** Privacy settings *****************************/
 
122
    this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
 
123
    
 
124
    /************************ show full name setting **************************/
 
125
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
 
126
    
 
127
    this.show_full_name_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
128
    
 
129
    this.list_box.add (this.show_full_name_hbox);
 
130
    
 
131
    this.show_full_name_hbox.pack_start ((new Gtk.Label ({
 
132
                                                     label: _("Show full name")
 
133
                                                   })),
 
134
                                   false, false, 3);
 
135
    this.show_full_name_hbox.pack_end ((this.show_full_name_reset =
 
136
                                 new Gtk.Button ({
 
137
                                   image: edit_clear_icon})),
 
138
                                 false, false, 3);
 
139
    this.show_full_name_hbox.pack_end (
 
140
                               (this.show_full_name_switch = new Gtk.Switch ()),
 
141
                                 false, false, 3);
 
142
    this.show_full_name_switch.set_active (
 
143
      settings_object.get_setting ("main.privacy.show_full_name").data
 
144
    );
 
145
    
 
146
    /*********************** only show avatar setting **************************/
 
147
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
 
148
    
 
149
    this.only_show_avatar_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
 
150
    
 
151
    this.list_box.add (this.only_show_avatar_hbox);
 
152
    
 
153
    this.only_show_avatar_hbox.pack_start ((new Gtk.Label ({
 
154
                                                    label: _("Only show avatar")
 
155
                                                   })),
 
156
                                   false, false, 3);
 
157
    this.only_show_avatar_hbox.pack_end ((this.only_show_avatar_reset =
 
158
                                 new Gtk.Button ({
 
159
                                   image: edit_clear_icon})),
 
160
                                 false, false, 3);
 
161
    this.only_show_avatar_hbox.pack_end (
 
162
                             (this.only_show_avatar_switch = new Gtk.Switch ()),
 
163
                                 false, false, 3);
 
164
    this.only_show_avatar_switch.set_active (
 
165
      settings_object.get_setting ("main.privacy.only_show_avatar").data
 
166
    );
 
167
    
 
168
    /* Spacer */
 
169
    //this.list_box.add ((new Gtk.Label ()));
 
170
    
 
171
    /* Reset all settings */
 
172
    this.layout.pack_end (
 
173
      (this.reset_all_btn = new Gtk.Button ({
 
174
        label: _("Reset all settings")
 
175
      })),
 
176
      false,
 
177
      false,
 
178
      null
 
179
    );
 
180
    
 
181
    this.reset_all_btn.connect ("clicked", Lang.bind(this, this._reset_all));
 
182
  },
 
183
  
 
184
  _reset_all: function () {
 
185
    this._reset_use_dark_theme ();
 
186
  },
 
187
  
 
188
  _reset_use_dark_theme: function () {
 
189
    /* If the switch is active */
 
190
    if ((this.use_dark_switch.get_active ())) {
 
191
      this.use_dark_switch.set_active (false);
 
192
    }
 
193
    /* else we do nothing */
 
194
  }
 
195
  
 
196
});