]> spindle.queued.net Git - midori/commitdiff
Propagate mime icons from views to proxy items
authorChristian Dywan <christian@twotoasts.de>
Tue, 6 Jan 2009 01:09:35 +0000 (02:09 +0100)
committerChristian Dywan <christian@twotoasts.de>
Tue, 6 Jan 2009 01:09:35 +0000 (02:09 +0100)
katze/katze-arrayaction.c
midori/midori-view.c

index 5ab26c0926b25af66d63e0a868776029315d79fc..fe3657d272535f9f1f27abb79c5074670ce79926 100644 (file)
@@ -226,6 +226,7 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
     guint n, i;
     KatzeItem* item;
     GtkWidget* menuitem;
+    const gchar* icon_name;
     GdkPixbuf* icon;
     GtkWidget* image;
     GtkWidget* submenu;
@@ -245,14 +246,19 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
         }
         menuitem = katze_image_menu_item_new_ellipsized (
             katze_item_get_name (item));
-        if (KATZE_IS_ARRAY (item))
-            icon = gtk_widget_render_icon (menuitem,
-                GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
+        if ((icon_name = katze_item_get_icon (item)) && *icon_name)
+            image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
         else
-            icon = katze_net_load_icon (array_action->net,
-                katze_item_get_uri (item), NULL, proxy, NULL);
-        image = gtk_image_new_from_pixbuf (icon);
-        g_object_unref (icon);
+        {
+            if (KATZE_IS_ARRAY (item))
+                icon = gtk_widget_render_icon (menuitem,
+                    GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
+            else
+                icon = katze_net_load_icon (array_action->net,
+                    katze_item_get_uri (item), NULL, proxy, NULL);
+            image = gtk_image_new_from_pixbuf (icon);
+            g_object_unref (icon);
+        }
         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
         gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
         g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
@@ -405,6 +411,13 @@ katze_array_action_item_notify_cb (KatzeItem*   item,
         gtk_widget_show (image);
         gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
     }
+    else if (!strcmp (property, "icon"))
+    {
+        image = gtk_image_new_from_icon_name (katze_item_get_icon (item),
+                                              GTK_ICON_SIZE_MENU);
+        gtk_widget_show (image);
+        gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
+    }
 }
 
 /**
index 0ee351195ca3231d58e56b8e810ff2829b47f5f3..89b5e600e5a662ff4c664d4bfa5e056e48fbda40 100644 (file)
@@ -526,15 +526,15 @@ static GdkPixbuf*
 midori_view_mime_icon (GtkIconTheme* icon_theme,
                        const gchar*  format,
                        const gchar*  part1,
-                       const gchar*  part2)
+                       const gchar*  part2,
+                       gchar**       name)
 {
-    gchar* name;
     GdkPixbuf* icon;
 
-    name = part2 ? g_strdup_printf (format, part1, part2)
+    *name = part2 ? g_strdup_printf (format, part1, part2)
         : g_strdup_printf (format, part1);
-    icon = gtk_icon_theme_load_icon (icon_theme, name, 16, 0, NULL);
-    g_free (name);
+    if (!(icon = gtk_icon_theme_load_icon (icon_theme, *name, 16, 0, NULL)))
+        g_free (*name);
     return icon ? g_object_ref (icon) : NULL;
 }
 
@@ -547,31 +547,36 @@ midori_view_update_icon (MidoriView* view,
         GdkScreen* screen;
         GtkIconTheme* icon_theme;
         gchar** parts;
+        gchar* icon_name;
 
         if ((screen = gtk_widget_get_screen (GTK_WIDGET (view))))
         {
             icon_theme = gtk_icon_theme_get_for_screen (screen);
-            parts = g_strsplit (view->mime_type, "/", 2);
+            if ((parts = g_strsplit (view->mime_type, "/", 2)))
+                parts = (parts[0] && parts[1]) ? parts : NULL;
         }
         else
             parts = NULL;
 
-        if (parts && parts[0] && parts[1])
+        if (parts)
             icon = midori_view_mime_icon (icon_theme, "%s-%s",
-                                          parts[0], parts[1]);
-        if (!icon && parts && parts[0] && parts[1])
+                                          parts[0], parts[1], &icon_name);
+        if (!icon && parts)
             icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-%s",
-                                          parts[0], parts[1]);
-        if (!icon && parts && parts[0])
+                                          parts[0], parts[1], &icon_name);
+        if (!icon && parts)
             icon = midori_view_mime_icon (icon_theme, "%s-x-generic",
-                                          parts[0], NULL);
-        if (!icon && parts && parts[0])
+                                          parts[0], NULL, &icon_name);
+        if (!icon && parts)
             icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-x-generic",
-                                          parts[0], NULL);
+                                          parts[0], NULL, &icon_name);
+        katze_item_set_icon (view->item, icon && view->item ? icon_name : NULL);
         if (!icon)
             icon = gtk_widget_render_icon (GTK_WIDGET (view),
                 GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
     }
+    else
+        katze_item_set_icon (view->item, NULL);
     katze_object_assign (view->icon, icon);
     g_object_notify (G_OBJECT (view), "icon");