[gnome-maps] Add in app notifications
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Add in app notifications
- Date: Tue, 1 Apr 2014 20:39:13 +0000 (UTC)
commit 531c44191e20610c53cbdf526cad4d7d2ba4690f
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 | 8 ---
src/mainWindow.js | 18 ++++----
src/notification.js | 97 +++++++++++++++++++++++++++++++++++++
src/notification.ui | 43 ++++++++++++++++
8 files changed, 160 insertions(+), 18 deletions(-)
---
diff --git a/data/gnome-maps.css b/data/gnome-maps.css
index 6891aec..48bdc5c 100644
--- a/data/gnome-maps.css
+++ b/data/gnome-maps.css
@@ -27,6 +27,10 @@
border: 2px solid @suggested_action_button_a;
}
+.maps-notification {
+ border-radius: 0px 0px 0px 0px;
+}
+
.zoom-control {
background-color: transparent;
}
diff --git a/src/application.js b/src/application.js
index ced3bd3..ae00dda 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;
@@ -44,6 +45,7 @@ const PlaceStore = imports.placeStore;
let application = null;
let settings = null;
let placeStore = null;
+let notificationManager = null;
const Application = new Lang.Class({
Name: 'Application',
@@ -105,7 +107,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 51cbf61..d9265a9 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -7,6 +7,7 @@
<file preprocess="xml-stripblanks">search-popup.ui</file>
<file preprocess="xml-stripblanks">context-menu.ui</file>
<file preprocess="xml-stripblanks">layers-popover.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 6c729c3..cc8ada0 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -10,6 +10,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 aa7accb..4a3deba 100644
--- a/src/main-window.ui
+++ b/src/main-window.ui
@@ -81,13 +81,5 @@
</child>
</object>
</child>
- <child>
- <object class="GtkOverlay" id="window-content">
- <property name="visible">True</property>
- <property name="can-focus">True</property>
- <child>
- </child>
- </object>
- </child>
</object>
</interface>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index a157195..01d37b5 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -48,10 +48,9 @@ const _WINDOW_MIN_HEIGHT = 500;
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',
'layers-button']);
@@ -59,11 +58,13 @@ const MainWindow = new Lang.Class({
this._searchCompletion = ui.searchCompletion;
this.window = ui.appWindow;
this.window.application = app;
- this._windowContent = ui.windowContent;
this._placeStore = Application.placeStore;
+ this._overlay = overlay;
+
+ ui.appWindow.add(this._overlay);
this.mapView = new MapView.MapView();
- ui.windowContent.add(this.mapView);
+ overlay.add(this.mapView);
this.mapView.gotoUserLocation(false);
@@ -76,9 +77,8 @@ const MainWindow = new Lang.Class({
this._initSignals();
this._restoreWindowGeometry();
- this._windowContent.add_overlay(new ZoomControl.ZoomControl(this.mapView));
-
- this._windowContent.show_all();
+ this._overlay.add_overlay(new ZoomControl.ZoomControl(this.mapView));
+ this._overlay.show_all();
},
_initSearchWidgets: function() {
@@ -87,11 +87,11 @@ const MainWindow = new Lang.Class({
this._searchPopup.connect('selected',
this._onSearchPopupSelected.bind(this));
this._searchPopup.connect('selected',
- this._windowContent.grab_focus.bind(this._windowContent));
+ this._overlay.grab_focus.bind(this._overlay));
this.mapView.view.connect('button-press-event',
this._searchPopup.hide.bind(this._searchPopup));
this.mapView.view.connect('button-press-event',
- this._windowContent.grab_focus.bind(this._windowContent));
+ this._overlay.grab_focus.bind(this._overlay));
this._searchEntry.connect('changed',
this._searchPopup.hide.bind(this._searchPopup));
diff --git a/src/notification.js b/src/notification.js
new file mode 100644
index 0000000..c9d8406
--- /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]