1
/* This file is part of GPump, a Pump.io client.
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.
8
const Gtk = imports.gi.Gtk;
9
const _ = imports.gettext.gettext;
10
const Lang = imports.lang;
12
const SettingsData = imports.settings_data;
17
const PreferencesUI = Lang.Class ({
25
title: _("GPump preferences"),
30
this._prepare_header_bar ();
31
this._prepare_list_box ();
33
this.set_property ('resizable', false);
38
_prepare_header_bar: function () {
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 ({
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");
50
this.close_btn.connect ('clicked', Lang.bind (this, function () {
51
SettingsData.get_settings ().commit_to_file ();
57
_prepare_list_box: function () {
58
/*this.get_content_area ().pack_start ()),
60
this.get_content_area ().set_center_widget (
61
(this.layout = new Gtk.Box ({
62
orientation: Gtk.Orientation.VERTICAL,
70
this.layout.pack_start (
71
new Gtk.Frame ({child:
72
(this.list_box = new Gtk.ListBox ({
74
selection_mode: Gtk.SelectionMode.NONE,
84
let settings_object = SettingsData.get_settings ();
86
/*************************** Use dark setting *****************************/
87
let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
89
this.use_dark_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
91
this.list_box.add (this.use_dark_hbox);
93
this.use_dark_hbox.pack_start ((new Gtk.Label ({
94
label: _("Use dark theme")
97
this.use_dark_hbox.pack_end ((this.use_dark_reset = new Gtk.Button ({
98
image: edit_clear_icon
101
this.use_dark_hbox.pack_end ((this.use_dark_switch = new Gtk.Switch ()),
104
this.use_dark_switch.set_active (
105
settings_object.get_setting("main.use_dark").data
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);
116
settings["gtk_application_prefer_dark_theme"] = false;
117
app_settings.set_setting ("main.use_dark", false);
121
this.use_dark_reset.connect ("clicked", Lang.bind (this,
122
this._reset_use_dark_theme));
124
/*************************** Privacy settings *****************************/
125
this.list_box.add ((new Gtk.Label ({label: _("Privacy settings")})));
127
/************************ show full name setting **************************/
128
let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
130
this.show_full_name_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
132
this.list_box.add (this.show_full_name_hbox);
134
this.show_full_name_hbox.pack_start ((new Gtk.Label ({
135
label: _("Show full name")
136
})),false, false, 3);
138
this.show_full_name_hbox.pack_end ((this.show_full_name_reset =
140
image: edit_clear_icon
141
})), false, false, 3);
143
this.show_full_name_hbox.pack_end (
144
(this.show_full_name_switch = new Gtk.Switch ()), false, false, 3);
146
this.show_full_name_switch.set_active (
147
settings_object.get_setting ("main.privacy.show_full_name").data
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);
156
app_settings.set_setting ("main.privacy.show_full_name", false);
160
this.show_full_name_reset.connect ("clicked", Lang.bind (this,
161
this._reset_show_full_name));
163
/*********************** only show avatar setting **************************/
164
let edit_clear_icon = new Gtk.Image ({icon_name: 'edit-clear'});
166
this.only_show_avatar_hbox = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 5);
168
this.list_box.add (this.only_show_avatar_hbox);
170
this.only_show_avatar_hbox.pack_start ((new Gtk.Label ({
171
label: _("Only show avatar")
172
})), false, false, 3);
174
this.only_show_avatar_hbox.pack_end ((this.only_show_avatar_reset =
176
image: edit_clear_icon
177
})), false, false, 3);
179
this.only_show_avatar_hbox.pack_end (
180
(this.only_show_avatar_switch = new Gtk.Switch ()),
182
this.only_show_avatar_switch.set_active (
183
settings_object.get_setting ("main.privacy.only_show_avatar").data
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);
192
app_settings.set_setting ("main.privacy.only_show_avatar", false);
196
/* Reset all settings */
197
this.layout.pack_end (
198
(this.reset_all_btn = new Gtk.Button ({
199
label: _("Reset all settings")
206
this.reset_all_btn.connect ("clicked", Lang.bind(this, this._reset_all));
209
_reset_all: function () {
210
this._reset_use_dark_theme ();
211
this._reset_show_full_name ();
212
this._reset_only_show_avatar_reset ();
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);
222
_reset_show_full_name: function () {
223
if (!(this.show_full_name_switch.get_active ())) {
224
this.show_full_name_switch.set_active (true);
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);