[maemo-commits] [maemo-commits] r11127 - in projects/haf/trunk/hildon-desktop: . libhildondesktop

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Apr 18 16:13:52 EEST 2007
Author: lucasr
Date: 2007-04-18 16:13:51 +0300 (Wed, 18 Apr 2007)
New Revision: 11127

Modified:
   projects/haf/trunk/hildon-desktop/ChangeLog
   projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.c
   projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.h
   projects/haf/trunk/hildon-desktop/libhildondesktop/notification-manager.xml
Log:
2007-04-18  Lucas Rocha  <lucas.rocha at nokia.com>

	* libhildondesktop/hildon-desktop-notification-manager.[ch]:
	implemented notification action and close support in the notification
	manager. Changed public API to make it saner for direct use.


Modified: projects/haf/trunk/hildon-desktop/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-desktop/ChangeLog	2007-04-18 13:09:13 UTC (rev 11126)
+++ projects/haf/trunk/hildon-desktop/ChangeLog	2007-04-18 13:13:51 UTC (rev 11127)
@@ -1,3 +1,9 @@
+2007-04-18  Lucas Rocha  <lucas.rocha at nokia.com>
+
+	* libhildondesktop/hildon-desktop-notification-manager.[ch]:
+	implemented notification action and close support in the notification
+	manager. Changed public API to make it saner for direct use.
+
 2007-04-18  Moises Martinez  <moises.martinez at nokia.com>
 
 	* libhildonwm/hd-wm.c:

Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.c
===================================================================
--- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.c	2007-04-18 13:09:13 UTC (rev 11126)
+++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.c	2007-04-18 13:13:51 UTC (rev 11127)
@@ -44,13 +44,13 @@
 
 struct _HildonDesktopNotificationManagerPrivate
 {
-  guint current_id;
+  DBusGConnection *connection;
+  guint            current_id;
 };
 
 static void
 hildon_desktop_notification_manager_init (HildonDesktopNotificationManager *nm)
 {
-  DBusGConnection *connection;
   DBusGProxy *bus_proxy;
   GError *error = NULL;
   guint request_name_result;
@@ -65,7 +65,8 @@
     G_TYPE_POINTER,
     G_TYPE_POINTER,
     G_TYPE_INT,
-    G_TYPE_BOOLEAN
+    G_TYPE_BOOLEAN,
+    G_TYPE_STRING
   };
 
   nm->priv = HILDON_DESKTOP_NOTIFICATION_MANAGER_GET_PRIVATE (nm);
@@ -75,9 +76,8 @@
   gtk_list_store_set_column_types (GTK_LIST_STORE (nm),
 		  		   HD_NM_N_COLS,
 		  		   _types);
-		  		   
 
-  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  nm->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
   if (error != NULL)
   {
@@ -89,7 +89,7 @@
     return;
   }
 
-  bus_proxy = dbus_g_proxy_new_for_name (connection,
+  bus_proxy = dbus_g_proxy_new_for_name (nm->priv->connection,
   					 DBUS_SERVICE_DBUS,
   					 DBUS_PATH_DBUS,
   					 DBUS_INTERFACE_DBUS);
@@ -114,9 +114,10 @@
   dbus_g_object_type_install_info (HILDON_DESKTOP_TYPE_NOTIFICATION_MANAGER,
                                    &dbus_glib_hildon_desktop_notification_service_object_info);
  
-  dbus_g_connection_register_g_object (connection,
+  dbus_g_connection_register_g_object (nm->priv->connection,
                                        HILDON_DESKTOP_NOTIFICATION_MANAGER_DBUS_PATH,
                                        G_OBJECT (nm));
+
 }
 
 static void
@@ -126,19 +127,6 @@
 }
 
 static gboolean 
-hildon_desktop_notification_manager_timeout (GtkTreeIter *iter)
-{
- GtkListStore *nm = 
-   hildon_desktop_notification_manager_get_singleton ();	
-
-  gtk_list_store_remove (nm, iter);
-
-  g_free (iter);
-
-  return FALSE;
-}
-
-static gboolean 
 hildon_desktop_notification_manager_find_by_id (HildonDesktopNotificationManager *nm,
 						guint id, 
 					        GtkTreeIter *return_iter)
@@ -153,8 +141,7 @@
   {
     gtk_tree_model_get (GTK_TREE_MODEL (nm),
 	  		&iter,
-			HD_NM_COL_ID,
-			&iter_id,
+			HD_NM_COL_ID, &iter_id,
 			-1);
     if (iter_id == id)
     {	    
@@ -167,6 +154,84 @@
   return FALSE;
 }
 
+static DBusMessage *
+hildon_desktop_notification_manager_create_signal (HildonDesktopNotificationManager *nm, 
+		                                   guint                             id, 
+						   const char                       *signal_name)
+{
+  DBusMessage *message;
+  GtkTreeIter iter;
+  gchar *dest;
+
+  if (hildon_desktop_notification_manager_find_by_id (nm, id, &iter))
+  {
+    gtk_tree_model_get (GTK_TREE_MODEL (nm),
+		        &iter,
+			HD_NM_COL_SENDER, &dest,
+			-1);
+  }
+  else
+  {
+    return NULL;
+  }
+
+  g_assert(dest != NULL);
+
+  message = dbus_message_new_signal ("/org/freedesktop/Notifications",
+                                     "org.freedesktop.Notifications",
+                                     signal_name);
+
+  dbus_message_set_destination (message, dest);
+
+  dbus_message_append_args (message,
+                            DBUS_TYPE_UINT32, &id,
+                            DBUS_TYPE_INVALID);
+
+  g_free (dest);
+  
+  return message;
+}
+
+static void
+hildon_desktop_notification_manager_notification_closed (HildonDesktopNotificationManager *nm,
+		                                         GtkTreeIter *iter)
+{
+  DBusMessage *message;
+  gint id;
+  
+  gtk_tree_model_get (GTK_TREE_MODEL (nm), 
+                      iter,
+                      HD_NM_COL_ID, &id,
+                      -1);
+
+  message = hildon_desktop_notification_manager_create_signal (nm, id, "NotificationClosed");
+
+  g_assert (message != NULL); 
+
+  dbus_connection_send (dbus_g_connection_get_connection (nm->priv->connection), 
+		        message, 
+			NULL);
+
+  dbus_message_unref (message);
+}
+
+static gboolean 
+hildon_desktop_notification_manager_timeout (GtkTreeIter *iter)
+{
+  GtkListStore *nm = 
+     hildon_desktop_notification_manager_get_singleton ();	
+
+  /* Notify the client */
+  hildon_desktop_notification_manager_notification_closed (HILDON_DESKTOP_NOTIFICATION_MANAGER (nm), 
+		  					   iter);
+ 
+  gtk_list_store_remove (nm, iter);
+
+  g_free (iter);
+
+  return FALSE;
+}
+
 GtkListStore *
 hildon_desktop_notification_manager_get_singleton (void)
 {
@@ -179,16 +244,16 @@
 }
 
 gboolean
-hildon_desktop_notification_manager_notify_handler (HildonDesktopNotificationManager *nm,
-                                        	    const gchar           *app_name,
-                                        	    guint                  id,
-                                        	    const gchar           *icon,
-                                        	    const gchar           *summary,
-                                        	    const gchar           *body,
-                                        	    gchar                **actions,
-                                        	    GHashTable            *hints,
-                                        	    gint                   timeout, 
-                                        	    DBusGMethodInvocation *context)
+hildon_desktop_notification_manager_add_notification (HildonDesktopNotificationManager *nm,
+                                        	      const gchar           *app_name,
+                                        	      guint                  id,
+                                        	      const gchar           *icon,
+                                        	      const gchar           *summary,
+                                        	      const gchar           *body,
+                                        	      gchar                **actions,
+                                        	      GHashTable            *hints,
+                                        	      gint                   timeout, 
+                                        	      DBusGMethodInvocation *context)
 {
   GtkTreeIter iter,*iter_timeout;
   GError *error = NULL;
@@ -203,7 +268,7 @@
 
       if (error)
       {
-        pixbuf = NULL; /* Tt'd be already NULL */
+        pixbuf = NULL; /* It'd be already NULL */
 	g_warning ("Notification Manager %s:",error->message);
         g_error_free (error);
       }
@@ -219,7 +284,7 @@
 
       if (error)
       {
-	pixbuf = NULL; /* Tt'd be already NULL */
+	pixbuf = NULL; /* It'd be already NULL */
 	g_warning ("Notification Manager %s:",error->message);
         g_error_free (error);
       }
@@ -250,6 +315,7 @@
 		        HD_NM_COL_HINTS, hints,
 		        HD_NM_COL_TIMEOUT, timeout,
 			HD_NM_COL_REMOVABLE, TRUE,
+			HD_NM_COL_SENDER, g_strdup (dbus_g_method_get_sender (context)),
 		        -1);
   }
   else 
@@ -263,7 +329,7 @@
 			HD_NM_COL_REMOVABLE, FALSE,
 			-1);
   }
-    
+
   if (timeout > 0)
   {
     iter_timeout = g_new0 (GtkTreeIter, 1);
@@ -271,7 +337,7 @@
     *iter_timeout = iter;  
     
     g_timeout_add (timeout,
-		   (GSourceFunc)hildon_desktop_notification_manager_timeout,
+		   (GSourceFunc) hildon_desktop_notification_manager_timeout,
 		   iter_timeout);
   }
 		      
@@ -309,34 +375,62 @@
 }
 
 gboolean
-hildon_desktop_notification_manager_close_notification_handler (HildonDesktopNotificationManager *nm,
-                                                    	        guint                  id, 
-                                                    	        GError               **error)
+hildon_desktop_notification_manager_close_notification (HildonDesktopNotificationManager *nm,
+                                                    	guint                  id, 
+                                                    	GError               **error)
 {
 
   GtkTreeIter iter;
   gboolean removable = TRUE;
 
-  if (hildon_desktop_notification_manager_find_by_id (nm,id,&iter))
+  if (hildon_desktop_notification_manager_find_by_id (nm, id, &iter))
   {
     gtk_tree_model_get (GTK_TREE_MODEL (nm),
 		        &iter,
 			HD_NM_COL_REMOVABLE, &removable,
 			-1);
-	  
-    if (!removable)  /*libnotify call close_notification_handler when updating a row 
-		       that we happend to not want removed
-		      */
+
+    /* libnotify call close_notification_handler when updating a row 
+       that we happend to not want removed */
+    if (!removable)
+    {
       gtk_list_store_set (GTK_LIST_STORE (nm),
-		          &iter,
-			  HD_NM_COL_REMOVABLE, TRUE,
-			  -1);
+                          &iter,
+                          HD_NM_COL_REMOVABLE, TRUE,
+                          -1);
+    }
     else
+    {
+      /* Notify the client */
+      hildon_desktop_notification_manager_notification_closed (nm, &iter);
+
       gtk_list_store_remove (GTK_LIST_STORE (nm), &iter);
-    
+    }
+      
     return TRUE;    
   }
   else
     return FALSE;
+}
 
+void
+hildon_desktop_notification_manager_call_action (HildonDesktopNotificationManager *nm,
+                                                 guint                             id,
+				                 const gchar                      *action_id)
+{
+  DBusMessage *message;
+
+  message = hildon_desktop_notification_manager_create_signal (nm, id, "ActionInvoked");
+
+  g_assert (message != NULL);
+
+  dbus_message_append_args (message,
+                            DBUS_TYPE_STRING, &action_id,
+                            DBUS_TYPE_INVALID);
+
+  dbus_connection_send (dbus_g_connection_get_connection (nm->priv->connection), 
+		        message, 
+			NULL);
+  
+  dbus_message_unref (message);
 }

Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.h
===================================================================
--- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.h	2007-04-18 13:09:13 UTC (rev 11126)
+++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-notification-manager.h	2007-04-18 13:13:51 UTC (rev 11127)
@@ -30,6 +30,8 @@
 #include <gtk/gtkliststore.h>
 #include <glib.h>
 #include <glib-object.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
 #include <dbus/dbus-glib-bindings.h>
 
 G_BEGIN_DECLS
@@ -46,6 +48,7 @@
   HD_NM_COL_HINTS,
   HD_NM_COL_TIMEOUT,
   HD_NM_COL_REMOVABLE,
+  HD_NM_COL_SENDER,
   HD_NM_N_COLS
 };
 
@@ -72,33 +75,38 @@
   GtkListStoreClass parent_class;
 };
 
-GType      hildon_desktop_notification_manager_get_type          (void);
+GType      hildon_desktop_notification_manager_get_type           (void);
 
-GtkListStore *hildon_desktop_notification_manager_get_singleton     (void);
+GtkListStore *hildon_desktop_notification_manager_get_singleton   (void);
 
-gboolean   hildon_desktop_notification_manager_notify_handler    (HildonDesktopNotificationManager *nm,
-                                                      		  const gchar           *app_name,
-                                                      		  guint                  id,
-                                                      		  const gchar           *icon,
-                                                      		  const gchar           *summary,
-                                                      		  const gchar           *body,
-                                                      		  gchar                **actions,
-                                                      		  GHashTable            *hints,
-                                                      		  gint                   timeout, 
-                                                      		  DBusGMethodInvocation *context);
+gboolean   hildon_desktop_notification_manager_add_notification   (HildonDesktopNotificationManager *nm,
+                                                      		   const gchar           *app_name,
+                                                      		   guint                  id,
+                                                      		   const gchar           *icon,
+                                                      		   const gchar           *summary,
+                                                      		   const gchar           *body,
+                                                      		   gchar                **actions,
+                                                      		   GHashTable            *hints,
+                                                      		   gint                   timeout, 
+                                                      		   DBusGMethodInvocation *context);
 
-gboolean   hildon_desktop_notification_manager_get_capabilities  (HildonDesktopNotificationManager *nm, 
-                                                      		  gchar               ***caps);
+gboolean   hildon_desktop_notification_manager_get_capabilities   (HildonDesktopNotificationManager *nm, 
+                                                      		   gchar               ***caps);
 
-gboolean   hildon_desktop_notification_manager_get_server_info   (HildonDesktopNotificationManager *nm,
-                                                      		  gchar                **out_name,
-                                                      		  gchar                **out_vendor,
-                                                      		  gchar                **out_version,
-                                                      		  gchar                **out_spec_ver);
+gboolean   hildon_desktop_notification_manager_get_server_info    (HildonDesktopNotificationManager *nm,
+                                                      		   gchar                **out_name,
+                                                      		   gchar                **out_vendor,
+                                                      		   gchar                **out_version,
+                                                      		   gchar                **out_spec_ver);
 
-gboolean   hildon_desktop_notification_manager_close_notification_handler (HildonDesktopNotificationManager *nm,
-                                                               guint id, GError **error);
+gboolean   hildon_desktop_notification_manager_close_notification (HildonDesktopNotificationManager *nm,
+                                                                   guint id, 
+								   GError **error);
 
+void       hildon_desktop_notification_manager_call_action        (HildonDesktopNotificationManager *nm,
+                                                                   guint                  id,
+								   const gchar           *action_id);
+
 G_END_DECLS
 
 #endif /* __HILDON_DESKTOP_NOTIFICATION_MANAGER_H__ */

Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/notification-manager.xml
===================================================================
--- projects/haf/trunk/hildon-desktop/libhildondesktop/notification-manager.xml	2007-04-18 13:09:13 UTC (rev 11126)
+++ projects/haf/trunk/hildon-desktop/libhildondesktop/notification-manager.xml	2007-04-18 13:13:51 UTC (rev 11127)
@@ -4,10 +4,10 @@
 
   <interface name="org.freedesktop.Notifications">
                 
-    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="HDNotificationManager"/>
+    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="HildonDesktopNotificationManager"/>
 
     <method name="Notify">
-      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="hildon_desktop_notification_manager_notify_handler"/>
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="hildon_desktop_notification_manager_add_notification"/>
 
       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  
@@ -23,7 +23,7 @@
     </method>
 
     <method name="CloseNotification">
-      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="hildon_desktop_notification_manager_close_notification_handler"/>
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="hildon_desktop_notification_manager_close_notification"/>
 
       <arg type="u" name="id" direction="in" />
     </method>


More information about the maemo-commits mailing list