~noskcaj/ubuntu/trusty/gnome-documents/3.10.2

« back to all changes in this revision

Viewing changes to src/notifications.js

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson, Thomas Bechtold
  • Date: 2013-04-04 13:32:08 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130404133208-n19gqczi05z31ogb
Tags: 3.8.0-1
[ Thomas Bechtold ]
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 *
20
20
 */
21
21
 
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;
29
28
 
30
 
const Global = imports.global;
 
29
const Application = imports.application;
31
30
const Utils = imports.utils;
 
31
const WindowMode = imports.windowMode;
32
32
 
33
33
const Lang = imports.lang;
 
34
const Mainloop = imports.mainloop;
34
35
const Signals = imports.signals;
35
36
 
36
37
const PrintNotification = new Lang.Class({
73
74
                this.widget.destroy();
74
75
            }));
75
76
 
76
 
        Global.notificationManager.addNotification(this);
 
77
        Application.notificationManager.addNotification(this);
77
78
    },
78
79
 
79
80
    _onPrintStatus: function() {
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);
87
88
 
88
89
        this._statusLabel.set_text(status);
89
90
        this._progressBar.fraction = fraction;
93
94
    }
94
95
});
95
96
 
 
97
const REMOTE_MINER_TIMEOUT = 10; // seconds
 
98
const TRACKER_MINER_FILES_NAME = 'org.freedesktop.Tracker1.Miner.Files';
 
99
 
96
100
const IndexingNotification = new Lang.Class({
97
101
    Name: 'IndexingNotification',
98
102
 
99
103
    _init: function() {
 
104
        this._closed = false;
 
105
        this._timeoutId = 0;
 
106
 
100
107
        try {
101
108
            this._manager = TrackerMiner.MinerManager.new_full(false);
 
109
            this._manager.connect('miner-progress', Lang.bind(this, this._checkNotification));
102
110
        } catch(e) {
103
111
            log('Unable to create a TrackerMinerManager, indexing progress ' +
104
112
                'notification won\'t work: ' + e.message);
105
113
            return;
106
114
        }
107
115
 
108
 
        this._minerFiles = 'org.freedesktop.Tracker1.Miner.Files';
109
 
        this.widget = null;
110
 
        this._manuallyClosed = false;
111
 
 
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));
114
118
    },
115
119
 
116
120
    _checkNotification: function() {
117
 
        let running = this._manager.get_running();
118
 
 
119
 
        if (running.indexOf(this._minerFiles) != -1) {
120
 
            let [res, status, progress, time] = this._manager.get_status(this._minerFiles);
121
 
 
122
 
            if (progress < 1) {
123
 
                this._displayNotification();
124
 
            } else {
125
 
                this._manuallyClosed = false;
126
 
                this._destroyNotification();
 
121
        if (Application.modeController.getWindowMode() == WindowMode.WindowMode.PREVIEW) {
 
122
            this._destroy(false);
 
123
            return;
 
124
        }
 
125
 
 
126
        let isIndexingLocal = false;
 
127
        let isIndexingRemote = false;
 
128
 
 
129
        if (this._manager) {
 
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);
 
133
 
 
134
                if (progress < 1)
 
135
                    isIndexingLocal = true;
127
136
            }
128
137
        }
129
 
    },
130
 
 
131
 
    _displayNotification: function() {
132
 
        if (this.widget)
133
 
            return;
134
 
 
135
 
        if (this._manuallyClosed)
136
 
            return;
137
 
 
 
138
 
 
139
        if (Application.application.minersRunning.length > 0)
 
140
            isIndexingRemote = true;
 
141
 
 
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));
 
148
        } else {
 
149
            this._destroy(false);
 
150
        }
 
151
    },
 
152
 
 
153
    _onTimeoutExpired: function() {
 
154
        this._timeoutId = 0;
 
155
 
 
156
        let primary = null;
 
157
        let miner = null;
 
158
 
 
159
        if (Application.application.minersRunning.length == 1) {
 
160
            miner = Application.application.minersRunning[0];
 
161
        }
 
162
 
 
163
        if (miner && miner.DisplayName) {
 
164
            primary = _("Fetching documents from %s").format(miner.DisplayName);
 
165
        } else {
 
166
            primary = _("Fetching documents from online accounts");
 
167
        }
 
168
 
 
169
        this._display(primary, null);
 
170
 
 
171
        return false;
 
172
    },
 
173
 
 
174
    _removeTimeout: function() {
 
175
        if (this._timeoutId != 0) {
 
176
            Mainloop.source_remove(this._timeoutId);
 
177
            this._timeoutId = 0;
 
178
        }
 
179
    },
 
180
 
 
181
    _buildWidget: function() {
138
182
        this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
139
183
                                     margin_left: 12,
140
184
                                     margin_right: 12,
149
193
                                    row_spacing: 3 });
150
194
        this.widget.add(labels);
151
195
 
152
 
        let primary = new Gtk.Label({ label: _("Your documents are being indexed"),
153
 
                                      halign: Gtk.Align.START });
154
 
        labels.add(primary);
 
196
        this._primaryLabel = new Gtk.Label({ halign: Gtk.Align.START });
 
197
        labels.add(this._primaryLabel);
155
198
 
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);
160
202
 
161
203
        let close = new Gtk.Button({ child: new Gtk.Image({ icon_name: 'window-close-symbolic',
162
204
                                                            pixel_size: 16,
165
207
                                     valign: Gtk.Align.CENTER });
166
208
        close.connect('clicked', Lang.bind(this,
167
209
            function() {
168
 
                this._manuallyClosed = true;
169
 
                this._destroyNotification();
 
210
                this._destroy(true);
170
211
            }));
171
212
        this.widget.add(close);
172
213
 
173
 
        Global.notificationManager.addNotification(this);
174
 
    },
175
 
 
176
 
    _destroyNotification: function() {
 
214
        Application.notificationManager.addNotification(this);
 
215
    },
 
216
 
 
217
    _update: function(primaryText, secondaryText) {
 
218
        this._primaryLabel.label = primaryText;
 
219
        this._secondaryLabel.label = secondaryText;
 
220
 
 
221
        if (secondaryText) {
 
222
            this._primaryLabel.vexpand = false;
 
223
            this._secondaryLabel.show();
 
224
        } else {
 
225
            this._primaryLabel.vexpand = true;
 
226
            this._secondaryLabel.hide();
 
227
        }
 
228
    },
 
229
 
 
230
    _display: function(primaryText, secondaryText) {
 
231
        if (this._closed) {
 
232
            return;
 
233
        }
 
234
 
 
235
        if (!this.widget)
 
236
            this._buildWidget();
 
237
 
 
238
        this._update(primaryText, secondaryText);
 
239
    },
 
240
 
 
241
    _destroy: function(closed) {
 
242
        this._removeTimeout();
 
243
 
177
244
        if (this.widget) {
178
245
            this.widget.destroy();
179
246
            this.widget = null;
180
247
        }
 
248
 
 
249
        this._closed = closed;
181
250
    }
182
251
});
183
252
 
186
255
 
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 });
192
263
 
193
 
        this.actor = new GtkClutter.Actor({ contents: this.widget,
194
 
                                            opacity: 0,
195
 
                                            x_align: Clutter.ActorAlign.CENTER,
196
 
                                            y_align: Clutter.ActorAlign.START,
197
 
                                            y_expand: true });
198
 
        Utils.alphaGtkWidget(this.actor.get_widget());
199
 
 
200
264
        this.widget.add(this._grid);
201
 
        this._grid.show();
 
265
 
 
266
        // add indexing monitor notification
 
267
        this._indexingNotification = new IndexingNotification();
202
268
    },
203
269
 
204
270
    addNotification: function(notification) {
205
 
        this._activeNotification = notification;
206
271
        this._grid.add(notification.widget);
207
 
 
208
 
        notification.widget.show_all();
209
 
        this.widget.show();
210
 
        this.actor.opacity = 255;
211
 
 
212
272
        notification.widget.connect('destroy', Lang.bind(this, this._onWidgetDestroy));
 
273
 
 
274
        this.widget.show_all();
213
275
    },
214
276
 
215
277
    _onWidgetDestroy: function() {