forked from omid/Persian-Calendar-for-Gnome-Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs.js
176 lines (139 loc) · 5.4 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
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const Gdk = imports.gi.Gdk;
const Lang = imports.lang;
const SETTINGS_SCHEMA = 'persian-calendar';
const Gettext = imports.gettext.domain('persian-calendar');
const _ = Gettext.gettext;
const N_ = function (e) {
return e;
};
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: 'PersianCalendar.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);
this.vbox1.add(new Gtk.Label({label: _('Dates to display:')}));
this.vbox2.add(new Gtk.Label({
label: _('Events to display:\n<span size="x-small">("Official" events are needed to find holidays)</span>'),
use_markup: true
}));
let item = new Gtk.CheckButton({label: _('Persian')});
this.vbox1.add(item);
Schema.bind('persian-display', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let item = new Gtk.CheckButton({label: _('Gregorian')});
this.vbox1.add(item);
Schema.bind('gregorian-display', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let item = new Gtk.CheckButton({label: _('Hijri')});
this.vbox1.add(item);
Schema.bind('hijri-display', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let item = new Gtk.CheckButton({label: _('Official Iranian lunar')});
this.vbox2.add(item);
Schema.bind('event-iran-lunar', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let item = new Gtk.CheckButton({label: _('Official Iranian solar')});
this.vbox2.add(item);
Schema.bind('event-iran-solar', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let item = new Gtk.CheckButton({label: _('Old Persian')});
this.vbox2.add(item);
Schema.bind('event-persian', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let item = new Gtk.CheckButton({label: _('Persian personages')});
this.vbox2.add(item);
Schema.bind('event-persian-personage', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let item = new Gtk.CheckButton({label: _('International')});
this.vbox2.add(item);
Schema.bind('event-world', item, 'active', Gio.SettingsBindFlags.DEFAULT);
// COLOR
let item = new Gtk.CheckButton({label: _('Use custom color')});
this.vbox3.add(item);
Schema.bind('custom-color', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let label = new Gtk.Label({label: "Color: "});
let color = new Gtk.ColorButton();
let _actor = new Gtk.HBox();
_actor.add(label);
_actor.add(color);
let _color = getColorByHexadecimal(Schema.get_string('color'));
color.set_color(_color);
this.vbox3.add(_actor);
color.connect('color-set', function (color) {
Schema.set_string('color', getHexadecimalByColor(color.get_color()));
});
// FONT
/*let item = new Gtk.CheckButton({label: _('Use custom font')})
this.vbox3.add(item)
Schema.bind('custom-font', item, 'active', Gio.SettingsBindFlags.DEFAULT);
let label = new Gtk.Label({label: "Font: "});
let font = new Gtk.FontButton();
font.set_show_size(false);
//font.set_show_style(false);
let _actor = new Gtk.HBox();
_actor.add(label);
_actor.add(font);
font.set_font_name(Schema.get_string('font'));
this.vbox3.add(_actor);
font.connect('font-set', function(font){
Schema.set_string('font', font.get_font_name());
});*/
this.main_hbox.show_all();
}
});
function buildPrefsWidget() {
let widget = new App();
return widget.main_hbox;
}
function _scaleRound(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;
}
function _dec2Hex(value) {
value = value.toString(16);
while (value.length < 2) {
value = '0' + value;
}
return value;
}
function getColorByHexadecimal(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;
}
function getHexadecimalByColor(color) {
let red = _scaleRound(color.red);
let green = _scaleRound(color.green);
let blue = _scaleRound(color.blue);
return "#" + _dec2Hex(red) + _dec2Hex(green) + _dec2Hex(blue);
}