* Added a first implementation for new messages notifications
[modest] / src / maemo / modest-platform.c
index 455e12b..5afd73e 100644 (file)
@@ -47,7 +47,9 @@
 #include <gtk/gtkmenuitem.h>
 #include <gtk/gtkmain.h>
 #include <string.h>
+#include <hildon/hildon-notification.h>
 
+#define HILDON_OSSO_URI_ACTION "uri-action"
 
 static osso_context_t *osso_context = NULL;
        
@@ -295,20 +297,24 @@ activate_uri_popup_item (GtkMenuItem *menu_item,
 {
        GSList *node;
        ModestPlatformPopupInfo *popup_info = (ModestPlatformPopupInfo *) userdata;
-       GtkWidget *label;
-
-       label = gtk_bin_get_child (GTK_BIN (menu_item));
+       const gchar* action_name;
 
+       action_name = g_object_get_data (G_OBJECT(menu_item), HILDON_OSSO_URI_ACTION);
+       if (!action_name) {
+               g_printerr ("modest: no action name defined\n");
+               return;
+       }
+       
        for (node = popup_info->actions; node != NULL; node = g_slist_next (node)) {
 #ifdef MODEST_HILDON_VERSION_0
                OssoURIAction *action = (OssoURIAction *) node->data;
-               if (strcmp (gtk_label_get_text (GTK_LABEL(label)), osso_uri_action_get_name (action))==0) {
+               if (strcmp (action_name, osso_uri_action_get_name (action))==0) {
                        osso_uri_open (popup_info->uri, action, NULL);
                        break;
                }
 #else
                HildonURIAction *action = (HildonURIAction *) node->data;
-               if (strcmp (gtk_label_get_text (GTK_LABEL(label)), hildon_uri_action_get_name (action))==0) {
+               if (strcmp (action_name, hildon_uri_action_get_name (action))==0) {
                        hildon_uri_open (popup_info->uri, action, NULL);
                        break;
                }
@@ -341,13 +347,15 @@ modest_platform_show_uri_popup (const gchar *uri)
              
                for (node = actions_list; node != NULL; node = g_slist_next (node)) {
                        GtkWidget *menu_item;
-
+                       const gchar* action_name;
 #ifdef MODEST_HILDON_VERSION_0
-                       OssoURIAction *action;
-
-                       action = (OssoURIAction *) node->data;
-                       menu_item = gtk_menu_item_new_with_label (osso_uri_action_get_name (action));
-                       g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (activate_uri_popup_item), popup_info);
+                       OssoURIAction *action = (OssoURIAction *) node->data;
+                       action_name = osso_uri_action_get_name (action);                
+                       menu_item = gtk_menu_item_new_with_label (dgettext("osso-uri",action_name));
+                       g_object_set_data (G_OBJECT(menu_item), HILDON_OSSO_URI_ACTION, (gpointer)action_name);
+                       /* hack, we add it as a gobject property*/
+                       g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (activate_uri_popup_item),
+                                         popup_info);
                        
                        if (osso_uri_is_default_action (action, NULL)) {
                                gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
@@ -355,28 +363,29 @@ modest_platform_show_uri_popup (const gchar *uri)
                                gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
                        }
 #else
-                       HildonURIAction *action;
-
-                       action = (HildonURIAction *) node->data;
-                       menu_item = gtk_menu_item_new_with_label (hildon_uri_action_get_name (action));
-                       g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (activate_uri_popup_item), popup_info);
-                       
+                       HildonURIAction *action = (HildonURIAction *) node->data;
+                       action_name = hildon_uri_action_get_name (action);
+                       menu_item = gtk_menu_item_new_with_label (dgettext("osso-uri", action_name));
+                       g_object_set_data (G_OBJECT(menu_item), HILDON_OSSO_URI_ACTION, (gpointer)action_name);  /* hack */
+                       g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (activate_uri_popup_item),
+                                         popup_info);
+                                                                 
                        if (hildon_uri_is_default_action (action, NULL)) {
                                gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
                        } else {
                                gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
                        }
-#endif
-
+#endif 
                        gtk_widget_show (menu_item);
                }
+               
                g_signal_connect (G_OBJECT (menu), "delete-event", G_CALLBACK (delete_uri_popup), popup_info);
                gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time ());
                                                  
        } else {
                hildon_banner_show_information (NULL, NULL, _("mcen_ib_unsupported_link"));
        }
-               
+       
        g_free (scheme);
        return TRUE;
 }
@@ -796,10 +805,27 @@ modest_platform_get_global_settings_dialog ()
 void 
 modest_platform_on_new_msg (void)
 {
-       /* TODO: play sound SR-SND-18 */
-       /* TODO: LED lightning pattern */
-       /* TODO: update the application icon in the task navigator */ 
-       g_print ("--------------- NEW MESSAGE ARRIVED ---------------\n");
+       HildonNotification *not;
+
+       /* Create a new notification. FIXME put the right values, need
+          some more specs */
+       not = hildon_notification_new ("Summary",
+                                      "Description",
+                                      "qgn_contact_group_chat_invitation",
+                                      "system.note.dialog");
+
+       /* Play sound SR-SND-18. TODO: play the right file */
+/*     hildon_notification_set_sound (not, "/usr/share/sounds/ui-battery_low.wav"); */
+
+       /* Set the led pattern */
+       notify_notification_set_hint_int32 (NOTIFY_NOTIFICATION (not), "led-pattern", 3);
+
+       /* Notify. We need to do this in an idle because this function
+          could be called from a thread */
+       if (!notify_notification_show (NOTIFY_NOTIFICATION (not), NULL))
+               g_error ("Failed to send notification");
+
+       g_object_unref (not);
 }
 
 
@@ -828,3 +854,27 @@ modest_platform_show_help (GtkWindow *parent_window,
                g_free (error_msg);
        }
 }
+
+void 
+modest_platform_show_search_messages (GtkWindow *parent_window)
+{
+       osso_return_t result = OSSO_ERROR;
+       
+       result = osso_rpc_run_with_defaults (osso_context, "osso_global_search", "search_email", NULL, DBUS_TYPE_INVALID);
+
+       if (result != OSSO_OK) {
+               /* TODO: warning about error showing dialog */
+       }
+}
+
+void 
+modest_platform_show_addressbook (GtkWindow *parent_window)
+{
+       osso_return_t result = OSSO_ERROR;
+       
+       result = osso_rpc_run_with_defaults (osso_context, "osso_addressbook", "top_application", NULL, DBUS_TYPE_INVALID);
+
+       if (result != OSSO_OK) {
+               /* TODO: warning about error showing dialog */
+       }
+}