-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
172 lines (142 loc) · 5.37 KB
/
extension.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
/*
* Simple CTParental extension for gnome-shell
* Copyright (c) 2017-2018 Thibaut Madelaine <[email protected]>
*
* Portions originate from the gnome-shell source code, Copyright (c)
* its respectives authors.
* Portions originate from the gnome-shell project-hamster-extension source
* code, Copyright (c) its respectives authors.
* This project is released under the GNU GPL License.
*/
const Clutter = imports.gi.Clutter;
const Config = imports.misc.config;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const St = imports.gi.St;
const Shell = imports.gi.Shell;
const Meta = imports.gi.Meta;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;
const Gio = imports.gi.Gio;
const PopupMenu = imports.ui.popupMenu;
const PanelMenu = imports.ui.panelMenu;
const Util = imports.misc.util;
const Gettext = imports.gettext.domain("ctparental-time-displayer");
const _ = Gettext.gettext;
const N_ = function(x) { return x; };
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Stuff = Me.imports.stuff;
const CTParentalMenu = new Lang.Class({
Name: 'CTParentalMenu.CTParentalMenu',
Extends: PanelMenu.Button,
_init: function() {
this.parent(0.0, _("CTParental"));
this.panelContainer = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
this.statusLabel = new St.Label({ text: _("CTParental"),
y_expand: true,
y_align: Clutter.ActorAlign.CENTER });
this.panelContainer.add_child(this.statusLabel);
this.panelContainer.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
this.actor.add_actor(this.panelContainer);
// panel icon
this._symbolicIcon = Gio.icon_new_for_string(Me.path + "/images/ctparental_symbolic.svg");
this.icon = new St.Icon({gicon: this._symbolicIcon,
icon_size: 16,
style_class: "panel-icon"});
this.panelContainer.add(this.icon);
this.menuSection = new PopupMenu.PopupMenuSection();
this.menu.addMenuItem(this.menuSection);
this._updatePanelDisplay();
},
_updateMenu: function() {
this._settings = Convenience.getSettings();
let confDir = this._settings.get_strv("ctparental-configuration-file");
this.menu.removeAll();
// get the remaining time
let timeLeft = Stuff.getRemainingTime(confDir);
this.remainingTimeItem = new PopupMenu.PopupMenuItem(_("Remaining time: ")+Stuff.formatDurationHuman(timeLeft));
this.menu.addMenuItem(this.remainingTimeItem);
// get the day timetable
this.todayScheduleItem = new PopupMenu.PopupMenuItem(_("Today's schedule: "));
this.menu.addMenuItem(this.todayScheduleItem);
let todayTimetable = Stuff.getTodayTimetable(confDir);
for (let i=0; i<todayTimetable.length-1; i+=2) {
if (todayTimetable[i] != '' && todayTimetable[i+1] != '' ) {
let labelText = "\t"+todayTimetable[i]+_(" to ")+todayTimetable[i+1];
let todayPeriodItem = new PopupMenu.PopupMenuItem(labelText);
this.menu.addMenuItem(todayPeriodItem);
}
}
},
_updatePanelLabel: function(fact) {
this._settings = Convenience.getSettings();
let confDir = this._settings.get_strv("ctparental-configuration-file");
// 0 = show label, 1 = show icon + warning, 2 = show icon + label
let appearance = this._settings.get_int("ctparental-panel-appearance");
let logoutTime = Stuff.getLogoutTime(confDir);
if (logoutTime < 10) {
this.statusLabel.text = _("Logout in ")+logoutTime+_(" minutes");
this.panelContainer.add_style_class_name('ctparental-notification');
} else {
this.statusLabel.text = _("CTParental"+logoutTime);
this.panelContainer.remove_style_class_name('ctparental-notification');
}
if (appearance === 0) {
this.panelContainer.show();
this.icon.hide();
} else {
this.icon.show();
if (appearance === 1) {
if (logoutTime >= 10) {
this.statusLabel.hide();
}
}
else {
this.statusLabel.show();
}
}
},
_updatePanelDisplay: function(){
let refreshTime = 60; // in seconds
if (this._timeout) {
Mainloop.source_remove(this._timeout);
this._timeout = null;
}
this._timeout = Mainloop.timeout_add_seconds(refreshTime, Lang.bind(this, this._updatePanelDisplay));
this._updatePanelLabel();
this._updateMenu();
return true;
},
destroy: function() {
this.parent();
},
});
function init(extensionMeta) {
Convenience.initTranslations("ctparental-time-displayer");
}
let _indicator;
function enable() {
_indicator = new CTParentalMenu;
let pos = 1;
if ('apps-menu' in Main.panel.statusArea)
pos = 2;
let panelIntPosition = Convenience.getSettings().get_int("ctparental-panel-position");
let panelPosition = 'left'; // pref = 0 (default)
if (panelIntPosition == 1) {
panelPosition = 'center';
}
else if (panelIntPosition == 2) {
panelPosition = 'right';
}
else if (panelIntPosition == 3) {
panelPosition = 'system menu';
}
Main.panel.addToStatusArea('ctparental-menu', _indicator, pos, panelPosition);
}
function disable() {
Mainloop.source_remove(this._timeout);
_indicator.destroy();
}