[gnome-maps/wip/notifications2: 4/7] Add in app notifications



commit 26151e8c94d20a7cf6509e3fc0afdb702a84feb8
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Sat Feb 15 06:28:35 2014 +0100

    Add in app notifications
    
    This patch adds in-app notifications. The code is derived from
    gtk-widget-factory.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723996

 data/gnome-maps.css               |    4 ++
 src/application.js                |    5 ++
 src/gnome-maps.data.gresource.xml |    1 +
 src/gnome-maps.js.gresource.xml   |    2 +
 src/mainWindow.js                 |   11 ++++-
 src/notification.js               |   81 +++++++++++++++++++++++++++++++++++++
 src/notification.ui               |   43 +++++++++++++++++++
 src/notificationManager.js        |   43 +++++++++++++++++++
 8 files changed, 187 insertions(+), 3 deletions(-)
---
diff --git a/data/gnome-maps.css b/data/gnome-maps.css
index 22e8739..42972ec 100644
--- a/data/gnome-maps.css
+++ b/data/gnome-maps.css
@@ -12,6 +12,10 @@
        border-radius: 0px;
 }
 
+.maps-notification {
+    border-radius: 0px 0px 0px 0px;
+}
+
 .zoom-control {
     background-color: transparent;
 }
diff --git a/src/application.js b/src/application.js
index de4cdfc..f185339 100644
--- a/src/application.js
+++ b/src/application.js
@@ -35,6 +35,9 @@ const GLib = imports.gi.GLib;
 const Main = imports.main;
 const Format = imports.format;
 const MainWindow = imports.mainWindow;
+const Notification = imports.notification;
+const NotificationManager = imports.notificationManager;
+
 const Utils = imports.utils;
 const Path = imports.path;
 const Settings = imports.settings;
@@ -42,6 +45,7 @@ const Settings = imports.settings;
 // used globally
 let application = null;
 let settings = null;
+let notificationManager = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -98,6 +102,7 @@ const Application = new Lang.Class({
 
     vfunc_activate: function() {
         this._createWindow();
+        notificationManager = new NotificationManager.NotificationManager(this._mainWindow.getOverlay());
         this._mainWindow.window.present();
     },
 
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 6250d60..347efe2 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -6,6 +6,7 @@
     <file preprocess="xml-stripblanks">zoom-control.ui</file>
     <file preprocess="xml-stripblanks">search-popup.ui</file>
     <file preprocess="xml-stripblanks">context-menu.ui</file>
+    <file preprocess="xml-stripblanks">notification.ui</file>
     <file alias="application.css">../data/gnome-maps.css</file>
     <file alias="zoom-in.png">../data/media/zoom-in.png</file>
     <file alias="zoom-out.png">../data/media/zoom-out.png</file>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index cb9a57c..9e7b4c1 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -9,6 +9,8 @@
     <file>mainWindow.js</file>
     <file>mapLocation.js</file>
     <file>mapView.js</file>
+    <file>notification.js</file>
+    <file>notificationManager.js</file>
     <file>path.js</file>
     <file>placeStore.js</file>
     <file>searchPopup.js</file>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 3f9fc96..0d53751 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -65,11 +65,12 @@ const MainWindow = new Lang.Class({
                                                     'search-completion']);
         this._searchEntry = ui.searchEntry;
         this._searchCompletion = ui.searchCompletion;
+        this._windowContent = ui.windowContent;
         this.window = ui.appWindow;
         this.window.application = app;
 
         this.mapView = new MapView.MapView();
-        ui.windowContent.add(this.mapView);
+        this._windowContent.add(this.mapView);
 
         this.mapView.gotoUserLocation(false);
 
@@ -81,9 +82,13 @@ const MainWindow = new Lang.Class({
         this._initSignals();
         this._restoreWindowGeometry();
 
-        ui.windowContent.add_overlay(new ZoomControl.ZoomControl(this.mapView));
+        this._windowContent.add_overlay(new ZoomControl.ZoomControl(this.mapView));
 
-        ui.windowContent.show_all();
+        this._windowContent.show_all();
+    },
+
+    getOverlay: function() {
+        return this._windowContent;
     },
 
     _initPlaces: function() {
diff --git a/src/notification.js b/src/notification.js
new file mode 100644
index 0000000..ee21cd1
--- /dev/null
+++ b/src/notification.js
@@ -0,0 +1,81 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2014 Mattias Bengtsson
+ *
+ * GNOME Maps 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 Maps 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 Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Gtk = imports.gi.Gtk;
+
+const Mainloop = imports.mainloop;
+const Lang = imports.lang;
+const Utils = imports.utils;
+
+const Notification = new Lang.Class({
+    Name: 'Notification',
+    Extends: Gtk.Revealer,
+    Abstract: true,
+
+    _init: function() {
+        this.parent({ visible: true,
+                      halign: Gtk.Align.CENTER,
+                      valign: Gtk.Align.START });
+
+        this._ui = Utils.getUIObject('notification', [ 'frame',
+                                                       'body',
+                                                       'dismiss-button']);
+
+        this._ui.dismissButton.connect('clicked', this.dismiss.bind(this));
+        this.add(this._ui.frame);
+    },
+
+    reveal: function() {
+        this._setRevealAndEmit(true, 'revealed');
+    },
+
+    dismiss: function() {
+        this._setRevealAndEmit(false, 'dismissed');
+    },
+
+    _setRevealAndEmit: function(state, signal) {
+        // We only want to send a dismissed / shown -signal
+        // if there is an actual change in revealed state.
+        if(state !== this.child_revealed) {
+            this.set_reveal_child(state);
+            Mainloop.timeout_add(this.transition_duration, (function() {
+                this.emit(signal);
+                return false;
+            }).bind(this));
+        }
+    }
+});
+Utils.addSignalMethods(Notification.prototype);
+
+const Plain = new Lang.Class({
+    Name: 'Plain',
+    Extends: Notification,
+
+    _init: function(msg) {
+        this.parent();
+        let label = new Gtk.Label({ visible : true,
+                                    hexpand : true,
+                                    halign  : Gtk.Align.START,
+                                    label   : msg });
+        this._ui.body.add(label);
+    }
+});
diff --git a/src/notification.ui b/src/notification.ui
new file mode 100644
index 0000000..1a96559
--- /dev/null
+++ b/src/notification.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkFrame" id="frame">
+    <property name="visible">True</property>
+    <style>
+      <class name="app-notification"/>
+      <class name="maps-notification"/>
+    </style>
+    <child>
+      <object class="GtkGrid">
+        <property name="visible">True</property>
+        <property name="margin-start">10</property>
+        <property name="margin-end">10</property>
+        <property name="width_request">600</property>
+        <property name="height_request">33</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <child>
+          <object class="GtkGrid" id="body">
+            <property name="visible">True</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="valign">center</property>
+            <property name="margin-end">20</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="dismiss-button">
+            <property name="visible">True</property>
+            <property name="relief">none</property>
+            <child>
+              <object class="GtkImage" id="dismiss-image">
+                <property name="visible">True</property>
+                <property name="icon-name">window-close-symbolic</property>
+                <property name="icon-size">0</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/notificationManager.js b/src/notificationManager.js
new file mode 100644
index 0000000..9edef21
--- /dev/null
+++ b/src/notificationManager.js
@@ -0,0 +1,43 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2014 Mattias Bengtsson
+ *
+ * GNOME Maps 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 Maps 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 Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Mainloop = imports.mainloop;
+const Lang = imports.lang;
+const Utils = imports.utils;
+
+const Notification = imports.notification;
+
+const NotificationManager = new Lang.Class({
+    Name: 'NotificationManager',
+
+    _init: function(overlay) {
+        this._overlay = overlay;
+    },
+
+    showMessage: function (msg) {
+        let notification = new Notification.Plain(msg);
+        notification.connect('dismissed',
+                             notification.destroy.bind(notification));
+        this._overlay.add_overlay(notification);
+        notification.reveal();
+    }
+});


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