[ekiga] Notifications: Added support for actions.



commit 48adb01705cd5b01685e07c6236977490552e2c3
Author: Damien Sandras <dsandras beip be>
Date:   Sun May 6 15:43:14 2012 +0200

    Notifications: Added support for actions.
    
    All notifications can now have one action associated to them.

 lib/engine/components/libnotify/libnotify-main.cpp |   23 +++++++++++++++----
 lib/engine/notification/notification-core.h        |   14 ++++++++++-
 2 files changed, 30 insertions(+), 7 deletions(-)
---
diff --git a/lib/engine/components/libnotify/libnotify-main.cpp b/lib/engine/components/libnotify/libnotify-main.cpp
index ad75362..46944d6 100644
--- a/lib/engine/components/libnotify/libnotify-main.cpp
+++ b/lib/engine/components/libnotify/libnotify-main.cpp
@@ -80,9 +80,9 @@ private:
 };
 
 static void
-notify_action_cb (NotifyNotification *notification,
-                  gchar *action,
-                  gpointer data)
+call_notification_action_cb (NotifyNotification *notification,
+                             gchar *action,
+                             gpointer data)
 {
   Ekiga::Call *call = (Ekiga::Call *) data;
 
@@ -93,6 +93,16 @@ notify_action_cb (NotifyNotification *notification,
     call->hangup ();
 }
 
+static void
+notify_action_cb (NotifyNotification *notification,
+                  gchar * /*action*/,
+                  gpointer data)
+{
+  Ekiga::Notification *notif = (Ekiga::Notification *) data;
+  notify_notification_close (notification, NULL);
+
+  notif->action_trigger ();
+}
 
 struct LIBNOTIFYSpark: public Ekiga::Spark
 {
@@ -177,6 +187,9 @@ LibNotify::on_notification_added (boost::shared_ptr<Ekiga::Notification> notific
 
   if (notification->get_level () == Ekiga::Notification::Error)
     notify_notification_set_urgency (notif, NOTIFY_URGENCY_CRITICAL);
+  if (!notification->get_action_name ().empty ())
+    notify_notification_add_action (notif, "action", notification->get_action_name ().c_str (),
+                                    notify_action_cb, notification.get (), NULL);
 
   g_signal_connect (notif, "closed", G_CALLBACK (on_notif_closed), notification.get ());
   boost::signals::connection conn = notification->removed.connect (boost::bind (&LibNotify::on_notification_removed,
@@ -226,8 +239,8 @@ LibNotify::on_call_notification (boost::shared_ptr<Ekiga::CallManager> manager,
 #endif
 #endif
                                     );
-  notify_notification_add_action (notify, "reject", _("Reject"), notify_action_cb, call.get (), NULL);
-  notify_notification_add_action (notify, "accept", _("Accept"), notify_action_cb, call.get (), NULL);
+  notify_notification_add_action (notify, "reject", _("Reject"), call_notification_action_cb, call.get (), NULL);
+  notify_notification_add_action (notify, "accept", _("Accept"), call_notification_action_cb, call.get (), NULL);
   notify_notification_set_app_name (notify, "Ekiga");
   notify_notification_set_hint (notify, "transient", g_variant_new_boolean (TRUE));
   notify_notification_set_timeout (notify, NOTIFY_EXPIRES_NEVER);
diff --git a/lib/engine/notification/notification-core.h b/lib/engine/notification/notification-core.h
index 05a1db5..cff2cb3 100644
--- a/lib/engine/notification/notification-core.h
+++ b/lib/engine/notification/notification-core.h
@@ -54,8 +54,10 @@ namespace Ekiga
 
     Notification (NotificationLevel level_,
 		  const std::string title_,
-		  const std::string body_)
-      : level(level_), title(title_), body(body_)
+		  const std::string body_,
+                  const std::string action_name_ = "",
+                  boost::function0<void> action_callback_ = NULL)
+      : level(level_), title(title_), body(body_), action_name(action_name_), action_callback(action_callback_)
     {}
 
     ~Notification () {}
@@ -69,6 +71,12 @@ namespace Ekiga
     const std::string get_body () const
     { return body; }
 
+    const std::string get_action_name () const
+    { return action_name; }
+
+    void action_trigger ()
+    { if (action_callback) action_callback (); }
+
     boost::signal0<void> removed;
 
   private:
@@ -76,6 +84,8 @@ namespace Ekiga
     NotificationLevel level;
     std::string title;
     std::string body;
+    std::string action_name;
+    boost::function0<void> action_callback;
   };
 
   class NotificationCore: public Service



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]