22
const Clutter = imports.gi.Clutter;
23
22
const Gd = imports.gi.Gd;
23
const Gio = imports.gi.Gio;
24
24
const GLib = imports.gi.GLib;
25
25
const Gtk = imports.gi.Gtk;
26
const GtkClutter = imports.gi.GtkClutter;
27
26
const TrackerMiner = imports.gi.TrackerMiner;
28
27
const _ = imports.gettext.gettext;
30
const Global = imports.global;
29
const Application = imports.application;
31
30
const Utils = imports.utils;
31
const WindowMode = imports.windowMode;
33
33
const Lang = imports.lang;
34
const Mainloop = imports.mainloop;
34
35
const Signals = imports.signals;
36
37
const PrintNotification = new Lang.Class({
83
84
let status = this._printOp.get_status();
84
85
let fraction = this._printOp.get_progress();
85
86
let name = this._printOp.get_job_name();
86
status = _("Printing \"%s\": %s").format(this._doc.name, status);
87
status = _("Printing “%s”: %s").format(this._doc.name, status);
88
89
this._statusLabel.set_text(status);
89
90
this._progressBar.fraction = fraction;
97
const REMOTE_MINER_TIMEOUT = 10; // seconds
98
const TRACKER_MINER_FILES_NAME = 'org.freedesktop.Tracker1.Miner.Files';
96
100
const IndexingNotification = new Lang.Class({
97
101
Name: 'IndexingNotification',
99
103
_init: function() {
104
this._closed = false;
101
108
this._manager = TrackerMiner.MinerManager.new_full(false);
109
this._manager.connect('miner-progress', Lang.bind(this, this._checkNotification));
103
111
log('Unable to create a TrackerMinerManager, indexing progress ' +
104
112
'notification won\'t work: ' + e.message);
108
this._minerFiles = 'org.freedesktop.Tracker1.Miner.Files';
110
this._manuallyClosed = false;
112
this._manager.connect('miner-progress', Lang.bind(this, this._checkNotification));
113
this._checkNotification();
116
Application.application.connectJS('miners-changed', Lang.bind(this, this._checkNotification));
117
Application.modeController.connect('window-mode-changed', Lang.bind(this, this._checkNotification));
116
120
_checkNotification: function() {
117
let running = this._manager.get_running();
119
if (running.indexOf(this._minerFiles) != -1) {
120
let [res, status, progress, time] = this._manager.get_status(this._minerFiles);
123
this._displayNotification();
125
this._manuallyClosed = false;
126
this._destroyNotification();
121
if (Application.modeController.getWindowMode() == WindowMode.WindowMode.PREVIEW) {
122
this._destroy(false);
126
let isIndexingLocal = false;
127
let isIndexingRemote = false;
130
let running = this._manager.get_running();
131
if (running.indexOf(TRACKER_MINER_FILES_NAME) != -1) {
132
let [res, status, progress, time] = this._manager.get_status(TRACKER_MINER_FILES_NAME);
135
isIndexingLocal = true;
131
_displayNotification: function() {
135
if (this._manuallyClosed)
139
if (Application.application.minersRunning.length > 0)
140
isIndexingRemote = true;
142
if (isIndexingLocal) {
143
this._display(_("Your documents are being indexed"),
144
_("Some documents might not be available during this process"));
145
} else if (isIndexingRemote) {
146
this._removeTimeout();
147
this._timeoutId = Mainloop.timeout_add_seconds(REMOTE_MINER_TIMEOUT, Lang.bind(this, this._onTimeoutExpired));
149
this._destroy(false);
153
_onTimeoutExpired: function() {
159
if (Application.application.minersRunning.length == 1) {
160
miner = Application.application.minersRunning[0];
163
if (miner && miner.DisplayName) {
164
primary = _("Fetching documents from %s").format(miner.DisplayName);
166
primary = _("Fetching documents from online accounts");
169
this._display(primary, null);
174
_removeTimeout: function() {
175
if (this._timeoutId != 0) {
176
Mainloop.source_remove(this._timeoutId);
181
_buildWidget: function() {
138
182
this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
140
184
margin_right: 12,
149
193
row_spacing: 3 });
150
194
this.widget.add(labels);
152
let primary = new Gtk.Label({ label: _("Your documents are being indexed"),
153
halign: Gtk.Align.START });
196
this._primaryLabel = new Gtk.Label({ halign: Gtk.Align.START });
197
labels.add(this._primaryLabel);
156
let secondary = new Gtk.Label({ label: _("Some documents might not be available during this process"),
157
halign: Gtk.Align.START });
158
secondary.get_style_context().add_class('dim-label');
159
labels.add(secondary);
199
this._secondaryLabel = new Gtk.Label({ halign: Gtk.Align.START });
200
this._secondaryLabel.get_style_context().add_class('dim-label');
201
labels.add(this._secondaryLabel);
161
203
let close = new Gtk.Button({ child: new Gtk.Image({ icon_name: 'window-close-symbolic',
165
207
valign: Gtk.Align.CENTER });
166
208
close.connect('clicked', Lang.bind(this,
168
this._manuallyClosed = true;
169
this._destroyNotification();
171
212
this.widget.add(close);
173
Global.notificationManager.addNotification(this);
176
_destroyNotification: function() {
214
Application.notificationManager.addNotification(this);
217
_update: function(primaryText, secondaryText) {
218
this._primaryLabel.label = primaryText;
219
this._secondaryLabel.label = secondaryText;
222
this._primaryLabel.vexpand = false;
223
this._secondaryLabel.show();
225
this._primaryLabel.vexpand = true;
226
this._secondaryLabel.hide();
230
_display: function(primaryText, secondaryText) {
238
this._update(primaryText, secondaryText);
241
_destroy: function(closed) {
242
this._removeTimeout();
177
244
if (this.widget) {
178
245
this.widget.destroy();
179
246
this.widget = null;
249
this._closed = closed;
187
256
_init: function() {
188
257
this.widget = new Gd.Notification({ timeout: -1,
189
show_close_button: false });
258
show_close_button: false,
259
halign: Gtk.Align.CENTER,
260
valign: Gtk.Align.START });
190
261
this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
191
262
row_spacing: 6 });
193
this.actor = new GtkClutter.Actor({ contents: this.widget,
195
x_align: Clutter.ActorAlign.CENTER,
196
y_align: Clutter.ActorAlign.START,
198
Utils.alphaGtkWidget(this.actor.get_widget());
200
264
this.widget.add(this._grid);
266
// add indexing monitor notification
267
this._indexingNotification = new IndexingNotification();
204
270
addNotification: function(notification) {
205
this._activeNotification = notification;
206
271
this._grid.add(notification.widget);
208
notification.widget.show_all();
210
this.actor.opacity = 255;
212
272
notification.widget.connect('destroy', Lang.bind(this, this._onWidgetDestroy));
274
this.widget.show_all();
215
277
_onWidgetDestroy: function() {