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



commit 14ecc52e6365cca287384a6ccc52b6f7b527d725
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                |    6 ++-
 src/gnome-maps.data.gresource.xml |    1 +
 src/gnome-maps.js.gresource.xml   |    1 +
 src/main-window.ui                |    7 ---
 src/mainWindow.js                 |   12 ++--
 src/notification.js               |   97 +++++++++++++++++++++++++++++++++++++
 src/notification.ui               |   43 ++++++++++++++++
 8 files changed, 157 insertions(+), 14 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..4c06bb2 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',
@@ -92,7 +94,9 @@ const Application = new Lang.Class({
         if (this._mainWindow)
             return;
 
-        this._mainWindow = new MainWindow.MainWindow(this);
+        let overlay = new Gtk.Overlay({ visible: true });
+        notificationManager = new Notification.Manager(overlay);
+        this._mainWindow = new MainWindow.MainWindow(this, overlay);
         this._mainWindow.window.connect('destroy', this._onWindowDestroy.bind(this));
     },
 
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/main-window.ui b/src/main-window.ui
index 5d6afc4..168bc84 100644
--- a/src/main-window.ui
+++ b/src/main-window.ui
@@ -100,12 +100,5 @@
         </child>
       </object>
     </child>
-    <child>
-      <object class="GtkOverlay" id="window-content">
-        <property name="visible">True</property>
-        <child>
-        </child>
-      </object>
-    </child>
   </object>
 </interface>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 3f9fc96..8e784b5 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -57,10 +57,9 @@ const SearchResults = {
 const MainWindow = new Lang.Class({
     Name: 'MainWindow',
 
-    _init: function(app) {
+    _init: function(app, overlay) {
         this._configureId = 0;
         let ui = Utils.getUIObject('main-window', [ 'app-window',
-                                                    'window-content',
                                                     'search-entry',
                                                     'search-completion']);
         this._searchEntry = ui.searchEntry;
@@ -68,8 +67,10 @@ const MainWindow = new Lang.Class({
         this.window = ui.appWindow;
         this.window.application = app;
 
+        ui.appWindow.add(overlay);
+
         this.mapView = new MapView.MapView();
-        ui.windowContent.add(this.mapView);
+        overlay.add(this.mapView);
 
         this.mapView.gotoUserLocation(false);
 
@@ -81,9 +82,8 @@ const MainWindow = new Lang.Class({
         this._initSignals();
         this._restoreWindowGeometry();
 
-        ui.windowContent.add_overlay(new ZoomControl.ZoomControl(this.mapView));
-
-        ui.windowContent.show_all();
+        overlay.add_overlay(new ZoomControl.ZoomControl(this.mapView));
+        overlay.show_all();
     },
 
     _initPlaces: function() {
diff --git a/src/notification.js b/src/notification.js
new file mode 100644
index 0000000..cf61dd9
--- /dev/null
+++ b/src/notification.js
@@ -0,0 +1,97 @@
+/* -*- 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);
+    }
+});
+
+const Manager = new Lang.Class({
+    Name: 'Manager',
+
+    _init: function(overlay) {
+        this._overlay = overlay;
+    },
+
+    showMessage: function (msg) {
+        let notification = new Plain(msg);
+        notification.connect('dismissed',
+                             notification.destroy.bind(notification));
+        this._overlay.add_overlay(notification);
+        notification.reveal();
+    }
+});
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]