/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
14
const PreferencesUI = Lang.Class ({
15
  Name: "PrefrencesUI",
16
  Extends: Gtk.Dialog,
17
  
18
  _init: function () {
19
    this.parent ({
20
      use_header_bar: true,
47 by Gustav Hartvigsson
* Fixed the preferences dialoug. For some reasons
21
      modal: true,
45 by Gustav Hartvigsson
* forgot the bloody file...
22
      title: _("GPump preferences")
23
    });
24
    
25
    this._prepare_header_bar ();
26
    this._prepare_list_box ();
27
    
28
    this.set_property ('resizable', false);
29
    
30
    this.show_all ();
31
  },
32
  
33
  _prepare_header_bar: function () {
34
    
35
    this.headerbar = this.get_header_bar ();
36
    this.headerbar.set_show_close_button (false);
37
    this.headerbar.pack_end ((this.close_btn = new Gtk.Button ({
38
      label: _("close")
39
    })));
40
    
49 by Gustav Hartvigsson
* Changes a thing in the about dialoug.
41
    /* Install a custom style */
42
    let special_btn_style_ctx = this.close_btn.get_style_context ();
43
    special_btn_style_ctx.add_class ("suggested-action");
44
    
45 by Gustav Hartvigsson
* forgot the bloody file...
45
    this.close_btn.connect ('clicked', Lang.bind (this, function () {
46
      this.destroy ();
47
    }));
48
    
49
  },
50
  
51
  _prepare_list_box: function () {
52
    /*this.get_content_area ().pack_start ()),
53
                                         true, true, 25);*/
54
    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
    })));
60
    
61
    let settings_object = SettingsData.get_settings ();
62
    
63
    /*************************** Use dark setting *****************************/
64
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
65
    
66
    this.use_dark_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
67
    
68
    this.list_box.add (this.use_dark_hbox);
69
    
70
    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);
78
    this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
79
                                 false, false, 3);
80
    
81
    this.use_dark_switch.set_active (
82
      settings_object.get_setting("main.use_dark").data
83
    );
84
    
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
85
    this.use_dark_switch.connect("notify::active",
86
                                                  Lang.bind (this, function () {
87
      var settings = Gtk.Settings.get_default ();
88
      var app_settings = SettingsData.get_settings ();
89
      if ( this.use_dark_switch.get_active () ) {
90
        settings["gtk_application_prefer_dark_theme"] = true;
91
        app_settings.set_setting ("main.use_dark", true);
92
      } else {
93
        settings["gtk_application_prefer_dark_theme"] = false;
94
        app_settings.set_setting ("main.use_dark", false);
95
      }
96
    }));
97
    
98
    this.use_dark_reset.connect ("clicked", Lang.bind (this,
99
                                                   this._reset_use_dark_theme));
100
    
45 by Gustav Hartvigsson
* forgot the bloody file...
101
    /*************************** Privacy settings *****************************/
102
    this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
103
    
104
    /************************ show full name setting **************************/
105
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
106
    
107
    this.show_full_name_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
108
    
109
    this.list_box.add (this.show_full_name_hbox);
110
    
111
    this.show_full_name_hbox.pack_start ((new Gtk.Label ({
112
                                                     label: _("Show full name")
113
                                                   })),
114
                                   false, false, 3);
115
    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);
119
    this.show_full_name_hbox.pack_end (
120
                               (this.show_full_name_switch = new Gtk.Switch ()),
121
                                 false, false, 3);
122
    this.show_full_name_switch.set_active (
123
      settings_object.get_setting ("main.privacy.show_full_name").data
124
    );
125
    
126
    /*********************** only show avatar setting **************************/
127
    let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
128
    
129
    this.only_show_avatar_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
130
    
131
    this.list_box.add (this.only_show_avatar_hbox);
132
    
133
    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);
141
    this.only_show_avatar_hbox.pack_end (
142
                             (this.only_show_avatar_switch = new Gtk.Switch ()),
143
                                 false, false, 3);
144
    this.only_show_avatar_switch.set_active (
145
      settings_object.get_setting ("main.privacy.only_show_avatar").data
146
    );
147
    
148
    /* Spacer */
149
    //this.list_box.add ((new Gtk.Label ()));
150
    
151
    /* 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
    })));
50 by Gustav Hartvigsson
* bound the GtkSwitch for "use dark theme"
158
    
159
    this.reset_all_btn.connect ("clicked", Lang.bind(this, this._reset_all));
160
  },
161
  
162
  _reset_all: function () {
163
    this._reset_use_dark_theme ();
164
  },
165
  
166
  _reset_use_dark_theme: function () {
167
    /* If the switch is active */
168
    if ((this.use_dark_switch.get_active ())) {
169
      this.use_dark_switch.set_active (false);
170
    }
171
    /* else we do nothing */
45 by Gustav Hartvigsson
* forgot the bloody file...
172
  }
173
  
174
});