[polari] app: Add overlaid widget for in-app notifications
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] app: Add overlaid widget for in-app notifications
- Date: Thu, 8 Aug 2013 13:07:01 +0000 (UTC)
commit d3de401336f7f7f544bfe77735a19123893a5974
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Jul 25 02:41:14 2013 +0200
app: Add overlaid widget for in-app notifications
GdNotification does not really handle multiple (stacked) notifications
visible at a time, so we roll our own. It should be pretty close to
the implementation in Gd, except for the nice drop shadows.
We want to add app notifications from more places than the main
window, so it's easier to handle as a public property on the
application object.
src/Makefile.am | 1 +
src/appNotifications.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++
src/application.js | 3 ++
src/mainWindow.js | 5 ++++
4 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4cf1935..262a744 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,7 @@ polari: polari.in
jsdir = $(pkgdatadir)/js/
dist_js_DATA = \
application.js \
+ appNotifications.js \
chatroomManager.js \
chatView.js \
connections.js \
diff --git a/src/appNotifications.js b/src/appNotifications.js
new file mode 100644
index 0000000..775c186
--- /dev/null
+++ b/src/appNotifications.js
@@ -0,0 +1,53 @@
+const Gtk = imports.gi.Gtk;
+
+const Lang = imports.lang;
+
+const AppNotification = new Lang.Class({
+ Name: 'AppNotification',
+ Abstract: true,
+
+ _init: function() {
+ this.widget = new Gtk.Revealer({ reveal_child: true });
+ this.widget.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
+
+ this.widget.connect('notify::child-revealed',
+ Lang.bind(this, this._onChildRevealed));
+ },
+
+ close: function() {
+ this.widget.reveal_child = false;
+ },
+
+ _onChildRevealed: function() {
+ if (!this.widget.child_revealed)
+ this.widget.destroy();
+ }
+});
+
+const NotificationQueue = new Lang.Class({
+ Name: 'NotificationQueue',
+
+ _init: function() {
+ this.widget = new Gtk.Frame({ valign: Gtk.Align.START,
+ halign: Gtk.Align.CENTER,
+ no_show_all: true });
+ this.widget.get_style_context().add_class('app-notification');
+
+ this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
+ row_spacing: 6, visible: true });
+ this.widget.add(this._grid);
+ },
+
+ addNotification: function(notification) {
+ this._grid.add(notification.widget);
+
+ notification.widget.connect('destroy',
+ Lang.bind(this, this._onChildDestroy));
+ this.widget.show();
+ },
+
+ _onChildDestroy: function() {
+ if (this._grid.get_children().length == 0)
+ this.widget.hide();
+ }
+});
diff --git a/src/application.js b/src/application.js
index a510493..539778b 100644
--- a/src/application.js
+++ b/src/application.js
@@ -3,6 +3,7 @@ const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Tp = imports.gi.TelepathyGLib;
+const AppNotifications = imports.appNotifications;
const ChatroomManager = imports.chatroomManager;
const Config = imports.config;
const Connections = imports.connections;
@@ -38,6 +39,8 @@ const Application = new Lang.Class({
this._chatroomManager = ChatroomManager.getDefault();
this._accountManager = Tp.AccountManager.dup();
+ this.notificationQueue = new AppNotifications.NotificationQueue();
+
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/polari/app-menu.ui');
this.set_app_menu(builder.get_object('app-menu'));
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 5075531..46cc489 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -1,6 +1,7 @@
const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
+const AppNotifications = imports.appNotifications;
const ChatroomManager = imports.chatroomManager;
const ChatView = imports.chatView;
const Lang = imports.lang;
@@ -24,6 +25,10 @@ const MainWindow = new Lang.Class({
this._tpClient = new TelepathyClient.TelepathyClient(); // should be in app
+ let overlay = builder.get_object('overlay');
+
+ overlay.add_overlay(app.notificationQueue.widget);
+
this._roomManager = new ChatroomManager.getDefault();
this._roomManager.connect('room-added',
Lang.bind(this, this._roomAdded));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]