-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathprefs.js
293 lines (278 loc) · 8.77 KB
/
prefs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
* Copyright (c) 2012-2017 Gmail Message Tray contributors
*
* Gmail Message Tray Extension is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* Gmail Message Tray Extension is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Gnome Documents; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
* Adam Jabłoński <jablona123@gmail.com>
* Shuming Chan <shuming0207@gmail.com>
*
*/
"use strict";
const { GObject, Gtk } = imports.gi;
const Gettext = imports.gettext;
const _ = Gettext.domain('gmail_notify').gettext;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Conf = Me.imports.Conf.Conf;
/*
Gmail system label definitions taken from
https://developers.google.com/gmail/android/com/google/android/gm/contentprovider/GmailContract.Labels.LabelCanonicalNames
Linked to by https://stackoverflow.com/questions/24959370/list-of-gmail-atom-available-labels
Only those marked as "include" are available to choose from, but the
whole list is documented here anyway.
*/
const GMAIL_SYSTEM_LABELS = {
CANONICAL_NAME_ALL_MAIL: {
display: "All Mail label",
value: "^all",
include: false,
order: 0
},
CANONICAL_NAME_DRAFTS: {
display: "Drafts label",
value: "^r",
include: false,
order: 0
},
CANONICAL_NAME_INBOX: {
display: "Whole inbox (the 'inbox' label)",
value: "^i",
include: true,
order: 1
},
CANONICAL_NAME_INBOX_CATEGORY_FORUMS: {
display: "Forums inbox category",
value: "^sq_ig_i_group",
include: false,
order: 0
},
CANONICAL_NAME_INBOX_CATEGORY_PRIMARY: {
display: "Priority Inbox: Primary category only",
value: "^sq_ig_i_personal",
include: true,
order: 3
},
CANONICAL_NAME_INBOX_CATEGORY_PROMOTIONS: {
display: "Promotions inbox category",
value: "^sq_ig_i_promo",
include: false,
order: 0
},
CANONICAL_NAME_INBOX_CATEGORY_SOCIAL: {
display: "Social inbox category",
value: "^sq_ig_i_social",
include: false,
order: 0
},
CANONICAL_NAME_INBOX_CATEGORY_UPDATES: {
display: "Updates inbox category",
value: "^sq_ig_i_notification",
include: false,
order: 0
},
CANONICAL_NAME_PRIORITY_INBOX: {
display: "Priority Inbox",
value: "^iim",
include: true,
order: 2
},
CANONICAL_NAME_SENT: {
display: "Sent label",
value: "^f",
include: false,
order: 0
},
CANONICAL_NAME_SPAM: {
display: "Spam label",
value: "^s",
include: false,
order: 0
},
CANONICAL_NAME_STARRED: {
display: "Starred label",
value: "^t",
include: false,
order: 0
},
CANONICAL_NAME_TRASH: {
display: "Trash label",
value: "^k",
include: false,
order: 0
}
}
/**
* Initializes settings
*/
function init() {
Conf.setupTranslations();
}
/**
* Creates the setting GUI
*/
function buildPrefsWidget() {
const prefs = new Prefs();
return prefs;
}
/**
* Creates a preference widget for extension settings
* @private
*/
var Prefs = GObject.registerClass(class extends Gtk.Box {
_init(params) {
super._init(params);
this.margin_start = 24;
this.margin_end = 24;
this.margin_top = 16;
this.margin_bottom = 16;
this.orientation = Gtk.Orientation.VERTICAL;
this._conf = new Conf();
const useMailLabel = _("Use default email client instead of browser");
const timeoutLabel = _("Check every {0} sec: ");
const gmailSystemLabelLabel = _("Select mailbox (for Gmail accounts only)");
this._addSwitchSetting(useMailLabel, useMailLabel);
this._addSliderSetting(timeoutLabel, timeoutLabel);
const gmailSystemLabelToggleDefinitions = [];
for (let key in GMAIL_SYSTEM_LABELS) {
if (GMAIL_SYSTEM_LABELS[key].include) {
gmailSystemLabelToggleDefinitions.push(Object.assign({}, GMAIL_SYSTEM_LABELS[key]))
}
}
gmailSystemLabelToggleDefinitions.sort((a, b) => a.order - b.order)
this._addToggleSetting(
gmailSystemLabelLabel,
gmailSystemLabelLabel,
gmailSystemLabelToggleDefinitions
);
}
/**
* Creates a set of radio buttons
* @param {string} label - label for setting
* @param {string} help - help information for setting
* @param {array of objects} definitions - Each radio button, with "display" and "value" entries
* @private
*/
_addToggleSetting(label, help, definitions) {
const vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
const setting_label = new Gtk.Label({
label: label,
xalign: 0,
margin_top: 2,
margin_bottom: 2,
use_markup: true
});
setting_label.set_tooltip_text(help);
vbox.append(setting_label);
let previous_radio_button = null;
definitions.forEach(d => {
const setting_radio_button = new Gtk.ToggleButton({
group: previous_radio_button,
label: d.display,
margin_top: 2,
margin_bottom: 2,
margin_start: 20,
margin_end: 20,
active: this._conf.getGmailSystemLabel() === d.value
})
previous_radio_button = setting_radio_button
setting_radio_button.connect('toggled', button => {
if (button.active) {
this._conf.setGmailSystemLabel(d.value)
}
})
vbox.append(setting_radio_button)
})
this.append(vbox);
}
/**
* Creates a single switch setting
* @param {string} label - label for setting
* @param {string} help - help information for setting
* @private
*/
_addSwitchSetting(label, help) {
const hbox = this._createHBox();
const setting_switch = new Gtk.CheckButton({
margin_start: 2,
active: this._conf.getReader() === 1
});
setting_switch.connect('toggled', button => {
this._conf.setReader(button.active ? 1 : 0);
});
this._addLabel(hbox, label, help);
hbox.append(setting_switch);
this.append(hbox);
}
/**
* Creates a horizontal Box
* @returns {Gtk.Box}
* @private
*/
_createHBox() {
return new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
margin_top: 2,
margin_bottom: 2
});
}
/**
* Creates a single slider setting
* @param {string} label - label for setting
* @param {string} help - help information for setting
* @private
*/
_addSliderSetting(label, help) {
const hbox = this._createHBox();
const new_label = label.replace('{0}', this._conf.getTimeout());
const setting_label = this._addLabel(hbox, new_label, help);
const adjustment = new Gtk.Adjustment({
lower: 60,
upper: 1800,
step_increment: 1
});
const setting_slider = new Gtk.Scale({
hexpand: true,
digits: 0,
adjustment: adjustment,
value_pos: Gtk.PositionType.RIGHT
});
setting_slider.set_value(this._conf.getTimeout());
setting_slider.connect('value-changed', button => {
let i = Math.round(button.get_value());
setting_label.label = label.replace('{0}', i.toString());
this._conf.setTimeout(i);
});
hbox.append(setting_slider);
this.append(hbox);
}
/**
* Creates a label for an hbox
* @param {Gtk.Box} hbox - the GUI element to add the label to
* @param {string} label - label for setting
* @param {string} help - help information for setting
* @returns {Gtk.Label}
* @private
*/
_addLabel(hbox, label, help) {
const setting_label = new Gtk.Label({
label: label,
xalign: 0,
use_markup: true
});
setting_label.set_tooltip_text(help);
hbox.prepend(setting_label);
return setting_label;
}
});