[gnome-documents/wip/ui-changes: 25/25] notifications: add a NotificationManager class



commit 8beac358242fc0bd6d52657804175b4bdc90ce45
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Mar 2 19:21:10 2012 -0500

    notifications: add a NotificationManager class
    
    And use it to implement an app notification for the print operation.

 src/Makefile-js.am   |    1 +
 src/application.js   |    2 +
 src/embed.js         |    4 ++
 src/global.js        |    1 +
 src/notifications.js |  136 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/selections.js    |    3 +
 6 files changed, 147 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 1f5c0a9..2bab431 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -13,6 +13,7 @@ dist_js_DATA = \
     mainToolbar.js \
     mainWindow.js \
     manager.js \
+    notifications.js \
     offsetController.js \
     preview.js \
     query.js \
diff --git a/src/application.js b/src/application.js
index acf5d47..1e85850 100644
--- a/src/application.js
+++ b/src/application.js
@@ -40,6 +40,7 @@ const Global = imports.global;
 const Main = imports.main;
 const MainWindow = imports.mainWindow;
 const Manager = imports.manager;
+const Notifications = imports.notifications;
 const OffsetController = imports.offsetController;
 const Path = imports.path;
 const Query = imports.query;
@@ -175,6 +176,7 @@ Application.prototype = {
         Global.trackerController = new TrackerController.TrackerController();
         Global.selectionController = new Selections.SelectionController();
         Global.modeController = new WindowMode.ModeController();
+        Global.notificationManager = new Notifications.NotificationManager();
 
         this._initMenus();
         this._mainWindow = new MainWindow.MainWindow(this.application);
diff --git a/src/embed.js b/src/embed.js
index f1f3cd1..7f035c1 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -138,6 +138,10 @@ ViewEmbed.prototype  = {
         this._overlayLayout.add(this._selectionToolbar.actor,
             Clutter.BinAlignment.FIXED, Clutter.BinAlignment.FIXED);
 
+        // pack the OSD notification actor
+        this._viewLayout.add(Global.notificationManager.actor,
+            Clutter.BinAlignment.CENTER, Clutter.BinAlignment.START);
+
         Global.errorHandler.connect('load-error',
                                     Lang.bind(this, this._onLoadError));
 
diff --git a/src/global.js b/src/global.js
index fdc301f..5234795 100644
--- a/src/global.js
+++ b/src/global.js
@@ -27,6 +27,7 @@ let documentManager = null;
 let errorHandler = null;
 let goaClient = null;
 let modeController = null;
+let notificationManager = null;
 let offsetController = null;
 let queryBuilder = null;
 let searchCategoryManager = null;
diff --git a/src/notifications.js b/src/notifications.js
new file mode 100644
index 0000000..0607a05
--- /dev/null
+++ b/src/notifications.js
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+const Gd = imports.gi.Gd;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const GtkClutter = imports.gi.GtkClutter;
+const _ = imports.gettext.gettext;
+
+const Global = imports.global;
+
+const Lang = imports.lang;
+const Signals = imports.signals;
+
+function PrintNotification(printOp, doc) {
+    this._init(printOp, doc);
+}
+
+PrintNotification.prototype = {
+    _init: function(printOp, doc) {
+        this.widget = null;
+        this._printOp = printOp;
+        this._doc = doc;
+
+        this._printOp.connect('begin-print',
+                              Lang.bind(this, this._onPrintBegin));
+        this._printOp.connect('status-changed',
+                              Lang.bind(this, this._onPrintStatus));
+    },
+
+    _onPrintBegin: function() {
+        this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
+                                     row_spacing: 6,
+                                     margin_left: 12,
+                                     margin_right: 12});
+
+        this._statusLabel = new Gtk.Label();
+        this.widget.add(this._statusLabel);
+        this._progressBar = new Gtk.ProgressBar();
+        this.widget.add(this._progressBar);
+
+        this._stopButton = new Gtk.Button({ child: new Gtk.Image({ icon_name: 'process-stop-symbolic',
+                                                                   pixel_size: 16,
+                                                                   margin_top: 2,
+                                                                   margin_bottom: 2 }),
+                                            margin_left: 12,
+                                            valign: Gtk.Align.CENTER
+                                            });
+        this.widget.attach_next_to(this._stopButton, this._statusLabel,
+                                   Gtk.PositionType.RIGHT, 1, 2);
+        this._stopButton.connect('clicked', Lang.bind(this,
+            function() {
+                this._printOp.cancel();
+                this.widget.destroy();
+            }));
+
+        Global.notificationManager.addNotification(this);
+    },
+
+    _onPrintStatus: function() {
+        if (!this.widget)
+            return;
+
+        let status = this._printOp.get_status();
+        let fraction = this._printOp.get_progress();
+	let name = this._printOp.get_job_name();
+	status = _("Printing \"%s\": %s").format(this._doc.name, status);
+
+        this._statusLabel.set_text(status);
+        this._progressBar.fraction = fraction;
+
+        if (fraction == 1)
+            this.widget.destroy();
+    }
+};
+
+function NotificationManager() {
+    this._init();
+}
+
+NotificationManager.prototype = {
+    _init: function() {
+        this.widget = new Gd.Notification({ timeout: -1,
+                                            show_close_button: false });
+        this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
+                                    row_spacing: 6 });
+
+        this.actor = new GtkClutter.Actor({ contents: this.widget,
+                                            opacity: 0 });
+        this.actor.get_widget().get_style_context().add_class('documents-osd');
+        this.actor.get_widget().reset_style();
+
+        this.widget.add(this._grid);
+        this._grid.show();
+    },
+
+    addNotification: function(notification) {
+        this._activeNotification = notification;
+        this._grid.add(notification.widget);
+
+        notification.widget.show_all();
+        this.widget.show();
+        this.actor.opacity = 255;
+
+        notification.widget.connect('destroy', Lang.bind(this, this._onWidgetDestroy));
+    },
+
+    _onWidgetDestroy: function() {
+        let children = this._grid.get_children();
+
+        if (children.length == 0)
+            this.widget.hide();
+    },
+
+    _onNotificationDismissed: function() {
+    }
+};
+Signals.addSignalMethods(NotificationManager.prototype);
diff --git a/src/selections.js b/src/selections.js
index c0d6099..aa49177 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -30,6 +30,7 @@ const _ = imports.gettext.gettext;
 const Documents = imports.documents;
 const Global = imports.global;
 const Manager = imports.manager;
+const Notifications = imports.notifications;
 const Query = imports.query;
 const Tweener = imports.util.tweener;
 const Utils = imports.utils;
@@ -890,6 +891,8 @@ SelectionToolbar.prototype = {
                 }
 
                 let printOp = EvView.PrintOperation.new(evDoc);
+                let printNotification = new Notifications.PrintNotification(printOp, doc);
+
                 let toplevel = this.widget.get_toplevel();
                 printOp.run(toplevel);
             }));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]