forked from omid/Hijri-Calendar-for-Gnome-Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs.js
190 lines (154 loc) · 5.91 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
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const Gdk = imports.gi.Gdk;
const Lang = imports.lang;
const SETTINGS_SCHEMA = 'hijri-calendar';
const Gettext = imports.gettext.domain('hijri-calendar');
const _ = Gettext.gettext;
let extension = imports.misc.extensionUtils.getCurrentExtension();
let convenience = extension.imports.convenience;
let Schema = convenience.getSettings(extension, SETTINGS_SCHEMA);
function init()
{
}
const App = new Lang.Class({
Name: 'HijriCalendar.App',
_init: function ()
{
this.main_hbox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 20,
border_width: 10
});
this.vbox1 = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 10,
border_width: 10
});
this.vbox2 = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 10,
border_width: 10
});
this.vbox3 = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 10,
border_width: 10
});
this.main_hbox.pack_start(this.vbox1, false, false, 0);
this.main_hbox.pack_start(this.vbox2, false, false, 0);
this.main_hbox.pack_start(this.vbox3, false, false, 0);
// DATES FORMAT
this.vbox1.add(new Gtk.Label({label: _('Date Conversions:')}));
let item = new Gtk.CheckButton({label: _('Gregorian')});
this.vbox1.add(item);
Schema.bind('gregorian-display', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let label = new Gtk.Label({label: ' Format: '});
let format = new Gtk.Entry();
let hbox = new Gtk.HBox();
hbox.add(label);
hbox.add(format);
this.vbox1.add(hbox);
format.set_text(Schema.get_string('gregorian-display-format'));
format.connect('changed', function (format) {
Schema.set_string('gregorian-display-format', format.text);
});
item = new Gtk.CheckButton({label: _('Hijri')});
this.vbox1.add(item);
Schema.bind('hijri-display', item, 'active', Gio.SettingsBindFlags.DEFAULT);
label = new Gtk.Label({label: ' Format: '});
format = new Gtk.Entry();
hbox = new Gtk.HBox();
hbox.add(label);
hbox.add(format);
this.vbox1.add(hbox);
format.set_text(Schema.get_string('hijri-display-format'));
format.connect('changed', function (format) {
Schema.set_string('hijri-display-format', format.text);
});
let comment = new Gtk.Label({
label: _('<span size="x-small">Formatting possible values:\n%Y: 4-digit year\n%y: 2-digit year\n%M: 2-digit month\n%m: 1 or 2-digit month\n%MM: Full month name\n%mm: Abbreviated month name\n%D: 2-digit day\n%d: 1 or 2-digit day</span>'),
use_markup: true
});
this.vbox1.add(comment);
// EVENTS
this.vbox2.add(new Gtk.Label({
label: _('Events:'),
use_markup: true
}));
item = new Gtk.CheckButton({label: _('International')});
this.vbox2.add(item);
Schema.bind('event-world', item, 'active', Gio.SettingsBindFlags.DEFAULT);
// COLOR
this.vbox3.add(new Gtk.Label({label: _('Widget Properties:')}));
item = new Gtk.CheckButton({label: _('Use custom color')});
this.vbox3.add(item);
Schema.bind('custom-color', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let color = new Gtk.ColorButton();
this.vbox3.add(color);
let _color = this.getColorByHexadecimal(Schema.get_string('color'));
color.set_color(_color);
color.connect('color-set', (function (color) {
Schema.set_string('color', this.getHexadecimalByColor(color.get_color()));
}).bind(this));
item = new Gtk.CheckButton({label: _('Startup Notification')});
this.vbox3.add(item);
Schema.bind('startup-notification', item, 'active', Gio.SettingsBindFlags.DEFAULT);
label = new Gtk.Label({label: 'Format: '});
format = new Gtk.Entry();
hbox = new Gtk.HBox();
hbox.add(label);
hbox.add(format);
this.vbox3.add(hbox);
format.set_text(Schema.get_string('widget-format'));
format.connect('changed', function (format) {
Schema.set_string('widget-format', format.text);
});
comment = new Gtk.Label({
label: _('<span size="x-small">Formatting possible values:\n%Y: 4-digit year\n%y: 2-digit year\n%M: 2-digit month\n%m: 1 or 2-digit month\n%MM: Full month name\n%mm: Abbreviated month name\n%D: 2-digit day\n%d: 1 or 2-digit day</span>'),
use_markup: true
});
this.vbox3.add(comment);
this.main_hbox.show_all();
},
_scaleRound: function(value)
{
// Based on gtk/gtkcoloreditor.c
value = Math.floor((value / 255) + 0.5);
value = Math.max(value, 0);
value = Math.min(value, 255);
return value;
},
_dec2Hex: function(value)
{
value = value.toString(16);
while (value.length < 2) {
value = '0' + value;
}
return value;
},
getColorByHexadecimal: function(hex)
{
let colorArray = Gdk.Color.parse(hex);
let color = null;
if (colorArray[0]) {
color = colorArray[1];
} else {
// On any error, default to red
color = new Gdk.Color({red: 65535});
}
return color;
},
getHexadecimalByColor: function(color)
{
let red = this._scaleRound(color.red);
let green = this._scaleRound(color.green);
let blue = this._scaleRound(color.blue);
return '#' + this._dec2Hex(red) + this._dec2Hex(green) + this._dec2Hex(blue);
}
});
function buildPrefsWidget()
{
let widget = new App();
return widget.main_hbox;
}