[Xfce4-commits] <postler:master> Refactor notifications and mockup unread notification
Christian Dywan
noreply at xfce.org
Tue Aug 16 04:32:04 CEST 2011
Updating branch refs/heads/master
to 4cab780af66d7fe6c66ff3d3937db2ab5795003d (commit)
from 3b330fa77b47566d565203c29b718d2a530dfb4d (commit)
commit 4cab780af66d7fe6c66ff3d3937db2ab5795003d
Author: Christian Dywan <christian at twotoasts.de>
Date: Mon Aug 15 23:18:40 2011 +0200
Refactor notifications and mockup unread notification
Define POSTLER_PERSISTENCE to enable an icon with a badge on
a system with persistent notifications. The result appears to
be unreadably small by default and is not used in the tray.
postler/postler-app.vala | 32 +++++++++++++++++++++++++++++---
postler/postler-bureau.vala | 3 ++-
postler/postler-service.vala | 5 +----
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/postler/postler-app.vala b/postler/postler-app.vala
index e37f44b..7c221c9 100644
--- a/postler/postler-app.vala
+++ b/postler/postler-app.vala
@@ -219,7 +219,8 @@ public class Postler.App : Unique.App {
}
static Notify.Notification? notification = null;
- public static void send_notification (string message) {
+ static bool persistence = false;
+ public static void send_notification (string message, int count, string sound) {
try {
if (!Notify.is_initted ()) {
if (!Notify.init ("Postler"))
@@ -229,8 +230,7 @@ public class Postler.App : Unique.App {
notification = (Notify.Notification)GLib.Object.new (
typeof (Notify.Notification),
"summary", GLib.Environment.get_application_name (),
- "body", message,
- "icon-name", STOCK_INTERNET_MAIL);
+ "body", message);
unowned List<string> caps = Notify.get_server_caps ();
foreach (string cap in caps) {
@@ -241,16 +241,42 @@ public class Postler.App : Unique.App {
}
else if (cap == "sound")
notification.set_hint_uint32 ("suppress-sound", 1);
+ else if (cap == "persistence") {
+ if (Environment.get_variable ("POSTLER_PERSISTENCE") != null)
+ persistence = true;
+ }
}
+ if (!persistence)
+ notification.set ("icon-name", STOCK_INTERNET_MAIL);
}
else
notification.set ("body", message);
+ if (persistence) {
+#if HAVE_GTK3
+ var icon = new Gtk.NumerableIcon (new GLib.ThemedIcon (STOCK_INTERNET_MAIL));
+ icon.count = count;
+ var icon_theme = Gtk.IconTheme.get_default ();
+ var icon_info = icon_theme.lookup_by_gicon (icon, 48, 0);
+ var pixbuf = icon_info.load_icon ();
+ notification.set_image_from_pixbuf (pixbuf);
+#else
+ notification.set ("icon-name", STOCK_INTERNET_MAIL);
+#endif
+ }
notification.show ();
+ Postler.App.play_sound (sound);
} catch (Error error) {
GLib.warning (_("Failed to send notification: %s"), error.message);
}
}
+ public static void send_unread_notification (int count) {
+ send_notification (ngettext ("You have %d new message",
+ "You have %d new messages", count).printf (count),
+ count,
+ "message-new-email");
+ }
+
static Canberra.Context sound_context = null;
public static void play_sound (string sound) {
if (sound_context == null)
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index b42475f..daeb3c9 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -957,7 +957,7 @@ public class Postler.Bureau : Gtk.Window {
if (Environment.get_variable ("POSTLER_MOCKUP") != null) {
progressbar.fraction = 0.7;
- statuslabel.label = "Receiving 4 of 7 - Inbox";
+ statuslabel.label = _("Receiving %d of %d in %s").printf (4, 7, _("Inbox"));
statusitem.get_child ().show ();
search.set_text ("elementary");
search_apply ();
@@ -987,6 +987,7 @@ public class Postler.Bureau : Gtk.Window {
content.display (message);
}
catch (GLib.Error error) { GLib.error ("Failed to render mockup"); }
+ Postler.App.send_unread_notification (4);
});
}
}
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index dd0b325..bcc9e2c 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -475,10 +475,7 @@ namespace Postler {
try {
if ((unread = unread_messages ("%/INBOX/%")[0]) > 0) {
GLib.debug ("Done: %d new messages", (int)unread);
- Postler.App.send_notification (
- ngettext ("You have %d new message",
- "You have %d new messages", (int)unread).printf ((int)unread));
- Postler.App.play_sound ("message-new-email");
+ Postler.App.send_unread_notification ((int)unread);
}
}
catch (GLib.Error error) {
More information about the Xfce4-commits
mailing list