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



commit 42445ec19225ccfaf96ef744da1cfff9d51ad003
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Wed Feb 5 19:26:24 2014 +0100

    Add in app notifications
    
    This patch adds in app notifications. The code is derived from
    gtk-widget-factory.
    The Notification widget inherits from GtkRevealer and has a
    showNotification()- and a dismiss() method.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723996

 src/gnome-maps.data.gresource.xml |    1 +
 src/gnome-maps.js.gresource.xml   |    1 +
 src/mainWindow.js                 |   22 ++++++++++--
 src/notification.js               |   67 +++++++++++++++++++++++++++++++++++++
 src/notification.ui               |   43 +++++++++++++++++++++++
 5 files changed, 130 insertions(+), 4 deletions(-)
---
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 857bcef..04006d6 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -39,6 +39,7 @@ const PlaceStore = imports.placeStore;
 const Utils = imports.utils;
 const Config = imports.config;
 const ZoomControl = imports.zoomControl;
+const Notification = imports.notification;
 
 const _ = imports.gettext.gettext;
 
@@ -65,11 +66,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,10 +83,22 @@ const MainWindow = new Lang.Class({
         this._initSignals();
         this._restoreWindowGeometry();
 
-        ui.windowContent.add_overlay(this._searchPopup);
-        ui.windowContent.add_overlay(new ZoomControl.ZoomControl(this.mapView));
+        this._windowContent.add_overlay(this._searchPopup);
+        this._windowContent.add_overlay(new ZoomControl.ZoomControl(this.mapView));
 
-        ui.windowContent.show_all();
+        this._windowContent.show_all();
+    },
+
+    showNotification: function(msg, buttonLabel, callback) {
+        let notification = new Notification.Notification(msg, buttonLabel),
+            id;
+
+        if(callback) {
+            notification.connect('button-clicked', callback);
+        }
+
+        this._windowContent.add_overlay(notification);
+        notification.reveal();
     },
 
     _initPlaces: function() {
diff --git a/src/notification.js b/src/notification.js
new file mode 100644
index 0000000..d580280
--- /dev/null
+++ b/src/notification.js
@@ -0,0 +1,67 @@
+/* -*- 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 SECOND = 1000;
+
+const Notification = new Lang.Class({
+    Name: 'Notification',
+    Extends: Gtk.Revealer,
+
+    _init: function(msg, buttonLabel) {
+        this.parent({ visible: true,
+                      halign: Gtk.Align.CENTER,
+                      valign: Gtk.Align.START });
+        let ui = Utils.getUIObject('notification', [ 'frame',
+                                                     'button',
+                                                     'notification',
+                                                     'dismiss-button']);
+        ui.notification.label = msg;
+        if(buttonLabel) {
+            ui.button.show();
+            ui.button.label = buttonLabel;
+            ui.button.connect('clicked', (function() {
+                this.emit('button-clicked');
+            }).bind(this));
+        }
+        ui.dismissButton.connect('clicked', this.dismiss.bind(this));
+        this.add(ui.frame);
+    },
+
+    reveal: function() {
+        this.set_reveal_child(true);
+    },
+
+    dismiss: function() {
+        this.set_reveal_child(false);
+        Mainloop.timeout_add(this.transition_duration, (function() {
+            this.destroy();
+            return false;
+        }).bind(this));
+    }
+});
+Utils.addSignalMethods(Notification.prototype);
diff --git a/src/notification.ui b/src/notification.ui
new file mode 100644
index 0000000..5e31e47
--- /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"/>
+    </style>
+    <child>
+      <object class="GtkBox" id="box">
+        <property name="visible">True</property>
+        <property name="margin-start">10</property>
+        <property name="margin-end">10</property>
+        <property name="spacing">20</property>
+        <property name="width_request">600</property>
+        <child>
+          <object class="GtkLabel" id="notification">
+            <property name="visible">True</property>
+            <property name="hexpand">True</property>
+            <property name="halign">start</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="button">
+            <property name="visible">False</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]