-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathprefs.js
More file actions
142 lines (119 loc) · 5 KB
/
prefs.js
File metadata and controls
142 lines (119 loc) · 5 KB
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
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Config = imports.misc.config;
const Gio = imports.gi.Gio;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Gettext = imports.gettext.domain('clock-override');
const _ = Gettext.gettext;
function init() {
Convenience.initTranslations("clock-override");
}
const ClockOverrideSettings = new GObject.Class({
Name: 'ClockOverridePrefs',
Extends: Gtk.Grid,
update_textbox_value: function(value) {
let sval = this._settings.get_string('override-string');
if (sval != value) {
this._settings.set_string('override-string', value);
// If requested time has seconds in it, so the clock needs to be updated every second, else can be updated every minute
var set_clock_seconds = (value.indexOf("%S") !== -1) ||
(value.indexOf("%-S") !== -1) ||
(value.indexOf("%r") !== -1) ||
(value.indexOf("%T") !== -1) ||
(value.indexOf("%;@") !== -1);
Gio.Settings.new("org.gnome.desktop.interface").set_boolean("clock-show-seconds", set_clock_seconds);
}
},
_init: function(params) {
this.parent(params);
this.margin = 24;
this.column_spacing = 30;
this.row_spacing = 10;
this._settings = Convenience.getSettings();
let label = null;
let widget = null;
let value = null;
label = new Gtk.Label({
label: _("Text to display instead of the clock"),
hexpand: true,
halign: Gtk.Align.START
});
widget = new Gtk.Entry({halign: Gtk.Align.END, text: this._settings.get_string('override-string')});
widget.set_sensitive(true);
widget.connect('changed', Lang.bind(this, function(w) {
this.update_textbox_value(w.get_text());
}));
this.attach(label, 0, 0, 2, 1);
this.attach(widget, 2, 0, 1, 1);
let label2 = new Gtk.Label({
label: _("Some examples:"),
use_markup: true,
hexpand: true,
halign: Gtk.Align.START
});
this.attach(label2, 0, 1, 3, 1);
var css = new Gtk.CssProvider();
css.load_from_data("GtkLabel { text-decoration: underline rgba(128, 128, 128, 0.3); }");
var grid = this;
var rownumber = 2;
[
[_("The time in 24-hour notation (14:50)"), "%H:%M"],
[_("The time in 12-hour notation with seconds (2:50:10 pm)"), "%r"],
[_("A bell"), "🔔"],
[_("An emoji clock face"), "%;cf"],
[_("Slow time (quarters as fractions)"), "%H %;vf"],
[_("ISO date and time (2014-01-30T14:50:10)"), "%FT%T"],
[_("Local and Internet time"), "%H:%M @%;@."],
[_("Something sillier"), _("It is %M minutes past hour %H")]
].forEach(function(eg) {
let l = new Gtk.Label({
label: '<b>' + eg[0] + '</b>:',
use_markup: true,
hexpand: true,
halign: Gtk.Align.START
});
/* It would be nicer to use just a Label with a hyperlink in it here, for accessibility
reasons, but god alone knows how to remove the underline on a label, thanks to the
lack of Gtk CSS examples. And a Button would be ugly. So an EventBox it is for now. */
let eb = new Gtk.EventBox({
hexpand: true,
halign: Gtk.Align.START
});
let r = new Gtk.Label({
label: '<tt>' + eg[1] + '</tt>',
use_markup: true,
hexpand: true,
halign: Gtk.Align.START
});
eb.add(r);
eb.connect("button-press-event", Lang.bind(grid, function(w) {
this.update_textbox_value(eg[1]);
grid._settings.set_string('override-string', eg[1]);
return true;
}));
r.get_style_context().add_provider(css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
grid.attach(l, 0, rownumber, 1, 1);
grid.attach(eb, 1, rownumber, 2, 1);
rownumber += 1;
});
let label3 = new Gtk.Label({
label: '<a href="https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format">' + _("What do all these %x codes mean?") + '</a>',
use_markup: true,
hexpand: true,
halign: Gtk.Align.END
});
this.attach(label3, 0, rownumber, 3, 1);
this._settings.connect('changed::override-string', Lang.bind(this, function() {
let sval = this._settings.get_string('override-string');
if (widget.get_text() != sval) widget.set_text(sval);
}));
},
});
function buildPrefsWidget() {
let widget = new ClockOverrideSettings();
widget.show_all();
return widget;
}