[gnome-maps/wip/notifications-jonas: 1/4] Add in app notifications



commit 28a11f4de054b65dfd9ee095a998205d91186b97
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                |    3 +
 src/gnome-maps.data.gresource.xml |    1 +
 src/gnome-maps.js.gresource.xml   |    1 +
 src/mainWindow.js                 |    2 +-
 src/notification.js               |  100 +++++++++++++++++++++++++++++++++++++
 src/notification.ui               |   43 ++++++++++++++++
 7 files changed, 153 insertions(+), 1 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..ae0cc0e 100644
--- a/src/application.js
+++ b/src/application.js
@@ -35,6 +35,7 @@ const GLib = imports.gi.GLib;
 const Main = imports.main;
 const Format = imports.format;
 const MainWindow = imports.mainWindow;
+const Notification = imports.notification;
 const Utils = imports.utils;
 const Path = imports.path;
 const Settings = imports.settings;
@@ -42,6 +43,7 @@ const Settings = imports.settings;
 // used globally
 let application = null;
 let settings = null;
+let notificationManager = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -97,6 +99,7 @@ const Application = new Lang.Class({
     },
 
     vfunc_activate: function() {
+        notificationManager = new Notification.Manager();
         this._createWindow();
         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..bdb54c0 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -9,6 +9,7 @@
     <file>mainWindow.js</file>
     <file>mapLocation.js</file>
     <file>mapView.js</file>
+    <file>notification.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..6fdc1f3 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -81,8 +81,8 @@ const MainWindow = new Lang.Class({
         this._initSignals();
         this._restoreWindowGeometry();
 
+        ui.windowContent.add_overlay(Application.notificationManager);
         ui.windowContent.add_overlay(new ZoomControl.ZoomControl(this.mapView));
-
         ui.windowContent.show_all();
     },
 
diff --git a/src/notification.js b/src/notification.js
new file mode 100644
index 0000000..9a87c05
--- /dev/null
+++ b/src/notification.js
@@ -0,0 +1,100 @@
+/* -*- 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.Bin,
+    Abstract: true,
+
+    _init: function() {
+        this.parent({ visible: true });
+
+        this._ui = Utils.getUIObject('notification', [ 'frame',
+                                                       'body',
+                                                       'dismiss-button']);
+
+        this._ui.dismissButton.connect('clicked', (function() {
+            this.emit('dismiss');
+        }).bind(this));
+        this.add(this._ui.frame);
+    }
+});
+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);
+    }
+});
+
+const Manager = new Lang.Class({
+    Name: 'Manager',
+    Extends: Gtk.Revealer,
+
+    _init: function(overlay) {
+        this._cache = {};
+        this._stack = new Gtk.Stack({ visible: true });
+
+        this.parent({ visible: true,
+                      halign: Gtk.Align.CENTER,
+                      valign: Gtk.Align.START });
+        this.add(this._stack);
+    },
+
+    showMessage: function (msg) {
+        let notification = new Plain(msg);
+        this._revealNotification(notification);
+    },
+
+    _revealNotification: function(notification) {
+        // only conceal the notification when it's the last one
+        notification.connect('dismiss', (function() {
+            if (this._stack.get_children().length > 1) {
+                this._stack.remove(notification);
+            } else {
+                this.set_reveal_child(false);
+                Mainloop.timeout_add(this.transition_duration, (function() {
+                    this._stack.remove(notification);
+                }).bind(this));
+            }
+        }).bind(this));
+
+        this._stack.add(notification);
+        this._stack.child_set_property(notification, 'position', 0);
+        this._stack.set_visible_child(notification);
+        this.set_reveal_child(true);
+    }
+});
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>


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