* don't try to open file:-uri's, and don't add them to CSMs
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 30 Nov 2007 14:44:53 +0000 (14:44 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 30 Nov 2007 14:44:53 +0000 (14:44 +0000)
pmo-trunk-r3843

src/maemo/modest-platform.c

index 8ee6646..e16317a 100644 (file)
@@ -234,14 +234,15 @@ modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
        gchar *icon_name  = NULL;
        gchar **icons, **cursor;
        
        gchar *icon_name  = NULL;
        gchar **icons, **cursor;
        
-       if (!mime_type || !g_ascii_strcasecmp (mime_type, "application/octet-stream")) 
+       if (!mime_type || g_ascii_strcasecmp (mime_type, "application/octet-stream") == 0) 
                mime_str = g_string_new (gnome_vfs_get_mime_type_for_name (name));
        else {
                mime_str = g_string_new (mime_type);
                g_string_ascii_down (mime_str);
        }
                mime_str = g_string_new (gnome_vfs_get_mime_type_for_name (name));
        else {
                mime_str = g_string_new (mime_type);
                g_string_ascii_down (mime_str);
        }
-
+       
        icons = hildon_mime_get_icon_names (mime_str->str, NULL);
        icons = hildon_mime_get_icon_names (mime_str->str, NULL);
+       
        for (cursor = icons; cursor; ++cursor) {
                if (!g_ascii_strcasecmp (*cursor, "gnome-mime-message") ||
                    !g_ascii_strcasecmp (*cursor, "gnome-mime-message-rfc822")) {
        for (cursor = icons; cursor; ++cursor) {
                if (!g_ascii_strcasecmp (*cursor, "gnome-mime-message") ||
                    !g_ascii_strcasecmp (*cursor, "gnome-mime-message-rfc822")) {
@@ -258,7 +259,7 @@ modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
                *effective_mime_type = g_string_free (mime_str, FALSE);
        else
                g_string_free (mime_str, TRUE);
                *effective_mime_type = g_string_free (mime_str, FALSE);
        else
                g_string_free (mime_str, TRUE);
-
+       
        return icon_name;
 }
 
        return icon_name;
 }
 
@@ -293,28 +294,34 @@ modest_platform_activate_uri (const gchar *uri)
        g_return_val_if_fail (uri, FALSE);
        if (!uri)
                return FALSE;
        g_return_val_if_fail (uri, FALSE);
        if (!uri)
                return FALSE;
-       
-       actions = hildon_uri_get_actions_by_uri (uri, -1, NULL);
-       
-       for (iter = actions; iter; iter = g_slist_next (iter)) {
-               action = (HildonURIAction*) iter->data;
-               if (action && strcmp (hildon_uri_action_get_service (action),
-                                     "com.nokia.modest") == 0) {
-                       result = checked_hildon_uri_open (uri, action);
-                       break;
+
+       /* don't try to activate file: uri's -- they might confuse the user,
+        * and/or might have security implications */
+       if (!g_str_has_prefix (uri, "file:")) {
+               
+               actions = hildon_uri_get_actions_by_uri (uri, -1, NULL);
+               
+               for (iter = actions; iter; iter = g_slist_next (iter)) {
+                       action = (HildonURIAction*) iter->data;
+                       if (action && strcmp (hildon_uri_action_get_service (action),
+                                             "com.nokia.modest") == 0) {
+                               result = checked_hildon_uri_open (uri, action);
+                               break;
+                       }
                }
                }
-       }
+               
+               /* if we could not open it with email, try something else */
+               if (!result)
+                       result = checked_hildon_uri_open (uri, NULL);   
+       } 
        
        
-       /* if we could not open it with email, try something else */
-       if (!result)
-               result = checked_hildon_uri_open (uri, NULL);   
-
        if (!result) {
                ModestWindow *parent =
                        modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE);
                hildon_banner_show_information (parent ? GTK_WIDGET(parent): NULL, NULL,
                                                _("mcen_ib_unsupported_link"));
        if (!result) {
                ModestWindow *parent =
                        modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), FALSE);
                hildon_banner_show_information (parent ? GTK_WIDGET(parent): NULL, NULL,
                                                _("mcen_ib_unsupported_link"));
-       }
+               g_warning ("%s: cannot open uri '%s'", __FUNCTION__,uri);
+       } 
        
        return result;
 }
        
        return result;
 }
@@ -325,7 +332,7 @@ modest_platform_activate_file (const gchar *path, const gchar *mime_type)
        gint result = 0;
        DBusConnection *con;
        gchar *uri_path = NULL;
        gint result = 0;
        DBusConnection *con;
        gchar *uri_path = NULL;
-
+       
        uri_path = g_strconcat ("file://", path, NULL); 
        con = osso_get_dbus_connection (modest_maemo_utils_get_osso_context());
        
        uri_path = g_strconcat ("file://", path, NULL); 
        con = osso_get_dbus_connection (modest_maemo_utils_get_osso_context());
        
@@ -406,38 +413,47 @@ modest_platform_show_uri_popup (const gchar *uri)
 
        if (uri == NULL)
                return FALSE;
 
        if (uri == NULL)
                return FALSE;
-
+       
        actions_list = hildon_uri_get_actions_by_uri (uri, -1, NULL);
        actions_list = hildon_uri_get_actions_by_uri (uri, -1, NULL);
-       if (actions_list != NULL) {
-               GSList *node;
+       if (actions_list) {
+
                GtkWidget *menu = gtk_menu_new ();
                ModestPlatformPopupInfo *popup_info = g_new0 (ModestPlatformPopupInfo, 1);
 
                GtkWidget *menu = gtk_menu_new ();
                ModestPlatformPopupInfo *popup_info = g_new0 (ModestPlatformPopupInfo, 1);
 
-               popup_info->actions = actions_list;
-               popup_info->uri = g_strdup (uri);
-             
-               for (node = actions_list; node != NULL; node = g_slist_next (node)) {
-                       GtkWidget *menu_item;
-                       const gchar *action_name;
-                       const gchar *translation_domain;
-                       HildonURIAction *action = (HildonURIAction *) node->data;
-                       action_name = hildon_uri_action_get_name (action);
-                       translation_domain = hildon_uri_action_get_translation_domain (action);
-                       menu_item = gtk_menu_item_new_with_label (dgettext(translation_domain, 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);
+               /* don't add actions for file: uri's -- they might confuse the user,
+                * and/or might have security implications
+                * we still allow to copy the url though
+                */
+               if (!g_str_has_prefix (uri, "file:")) {                 
+               
+                       GSList *node;                   
+                       popup_info->actions = actions_list;
+                       popup_info->uri = g_strdup (uri);
+                       
+                       for (node = actions_list; node != NULL; node = g_slist_next (node)) {
+                               GtkWidget *menu_item;
+                               const gchar *action_name;
+                               const gchar *translation_domain;
+                               HildonURIAction *action = (HildonURIAction *) node->data;
+                               action_name = hildon_uri_action_get_name (action);
+                               translation_domain = hildon_uri_action_get_translation_domain (action);
+                               menu_item = gtk_menu_item_new_with_label (dgettext(translation_domain, 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);
+                               }
+                               gtk_widget_show (menu_item);
                        }
                        }
-                       gtk_widget_show (menu_item);
                }
 
                /* always add the copy item */
                }
 
                /* always add the copy item */
-               GtkWidget* menu_item = gtk_menu_item_new_with_label (dgettext("osso-uri", "uri_link_copy_link_location"));
+               GtkWidget* menu_item = gtk_menu_item_new_with_label (dgettext("osso-uri",
+                                                                             "uri_link_copy_link_location"));
                g_object_set_data_full (G_OBJECT(menu_item), HILDON_OSSO_URI_ACTION,
                                        g_strconcat (URI_ACTION_COPY, uri, NULL),
                                        g_free);
                g_object_set_data_full (G_OBJECT(menu_item), HILDON_OSSO_URI_ACTION,
                                        g_strconcat (URI_ACTION_COPY, uri, NULL),
                                        g_free);
@@ -453,7 +469,7 @@ modest_platform_show_uri_popup (const gchar *uri)
        } else {
                hildon_banner_show_information (NULL, NULL, _("mcen_ib_unsupported_link"));
        }
        } else {
                hildon_banner_show_information (NULL, NULL, _("mcen_ib_unsupported_link"));
        }
-
+       
        return TRUE;
 }
 
        return TRUE;
 }