]> spindle.queued.net Git - midori/commitdiff
GIcon for MIME icons, findbar and security
authorChristian Dywan <christian@twotoasts.de>
Sun, 15 Jul 2012 14:55:52 +0000 (16:55 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 15 Jul 2012 15:25:07 +0000 (17:25 +0200)
midori/midori-locationaction.c
midori/midori-view.c
toolbars/midori-findbar.c

index 1d44a22e2b2d3982791b2ee94a5524d93432a160..6f35e27e8ebbb791152f1677bf90154d6ce07f37 100644 (file)
@@ -1692,53 +1692,39 @@ midori_location_action_set_security_hint (MidoriLocationAction* location_action,
     if (GTK_IS_TOOL_ITEM (proxies->data))
     {
         GtkWidget* entry = midori_location_action_entry_for_proxy (proxies->data);
-        GdkScreen* screen = gtk_widget_get_screen (entry);
-        GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
 
         if (hint == MIDORI_SECURITY_UNKNOWN)
         {
-            #if !GTK_CHECK_VERSION (3, 0, 0)
+            #if GTK_CHECK_VERSION (2, 16, 0)
+            gchar* icon_names[] = { "channel-insecure-symbolic", "lock-insecure", "dialog-information", NULL };
+            gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY,
+                g_themed_icon_new_from_names (icon_names, -1));
+            #else
+            gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_INFO);
             #endif
-            #if !HAVE_HILDON
-            if (gtk_icon_theme_has_icon (icon_theme, "channel-insecure-symbolic"))
-                gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, "channel-insecure-symbolic");
-            else if (gtk_icon_theme_has_icon (icon_theme, "lock-insecure"))
-                gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, "lock-insecure");
-            else
-                gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_INFO);
             gtk_icon_entry_set_tooltip (GTK_ICON_ENTRY (entry),
                 GTK_ICON_ENTRY_PRIMARY, _("Not verified"));
-            #endif
         }
         else if (hint == MIDORI_SECURITY_TRUSTED)
         {
-            #if !GTK_CHECK_VERSION (3, 0, 0)
+            #if GTK_CHECK_VERSION (2, 16, 0)
+            gchar* icon_names[] = { "channel-secure-symbolic", "lock-secure", "locked", NULL };
+            gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY,
+                g_themed_icon_new_from_names (icon_names, -1));
+            #else
+            gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_DIALOG_AUTHENTICATION);
             #endif
-            #if !HAVE_HILDON
-            if (gtk_icon_theme_has_icon (icon_theme, "channel-secure-symbolic"))
-                gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, "channel-secure-symbolic");
-            else if (gtk_icon_theme_has_icon (icon_theme, "lock-secure"))
-                gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, "lock-secure");
-            else
-                gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_DIALOG_AUTHENTICATION);
             gtk_icon_entry_set_tooltip (GTK_ICON_ENTRY (entry),
                 GTK_ICON_ENTRY_PRIMARY, _("Verified and encrypted connection"));
-            #endif
         }
         else if (hint == MIDORI_SECURITY_NONE)
         {
-            if (gtk_icon_theme_has_icon (icon_theme, "text-html-symbolic"))
-                gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, "text-html-symbolic");
-            else
-                gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
-                    GTK_ICON_ENTRY_PRIMARY, STOCK_URL);
+            #if GTK_CHECK_VERSION (2, 16, 0)
+            gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY,
+                g_themed_icon_new_with_default_fallbacks ("text-html-symbolic"));
+            #else
+            gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY, STOCK_URL);
+            #endif
             gtk_icon_entry_set_tooltip (GTK_ICON_ENTRY (entry),
                 GTK_ICON_ENTRY_PRIMARY, _("Open, unencrypted connection"));
         }
index f1c0b766dd5bf76c9196f782e643f30d280aab24..c10ca98bf528849454fe5b38e6772fd777281206 100644 (file)
@@ -718,67 +718,39 @@ midori_view_apply_icon (MidoriView*  view,
     }
 }
 
-static gboolean
-midori_view_mime_icon (MidoriView*   view,
-                       GtkIconTheme* icon_theme,
-                       const gchar*  format,
-                       const gchar*  part1,
-                       const gchar*  part2)
-{
-    gchar* icon_name;
-    GdkPixbuf* icon;
-
-    icon_name = part2 ? g_strdup_printf (format, part1, part2)
-        : g_strdup_printf (format, part1);
-    if (!(icon = gtk_icon_theme_load_icon (icon_theme, icon_name, 16, 0, NULL)))
-    {
-        g_free (icon_name);
-        return FALSE;
-    }
-
-    g_object_ref (icon);
-    midori_view_apply_icon (view, icon, icon_name);
-    g_free (icon_name);
-    return TRUE;
-}
-
 static void
 midori_view_unset_icon (MidoriView* view)
 {
     GdkScreen* screen;
-    GtkIconTheme* theme;
-    gchar** parts = NULL;
-    GdkPixbuf* icon;
+    GtkIconTheme* icon_theme;
+    GIcon* icon;
+    gchar** icon_names;
+    GdkPixbuf* pixbuf = NULL;
 
     if (!((screen = gtk_widget_get_screen (view->web_view))
-        && (theme = gtk_icon_theme_get_for_screen (screen))))
+        && (icon_theme = gtk_icon_theme_get_for_screen (screen))))
         return;
 
-    if (!(view->mime_type
-       && (parts = g_strsplit (view->mime_type, "/", 2))
-       && (*parts && parts[1])))
+    if (view->mime_type != NULL)
     {
-        icon = gtk_widget_render_icon (view->web_view,
-            GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
-        midori_view_apply_icon (view, icon, GTK_STOCK_FILE);
-        goto free_parts;
+        gchar* content_type = g_content_type_from_mime_type (view->mime_type);
+        icon = g_content_type_get_icon (content_type);
+        g_free (content_type);
+        g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html");
     }
+    else
+        icon = g_themed_icon_new ("text-html");
 
-    if (midori_view_mime_icon (view, theme, "%s-%s", *parts, parts[1]))
-        goto free_parts;
-    if (midori_view_mime_icon (view, theme, "gnome-mime-%s-%s", *parts, parts[1]))
-        goto free_parts;
-    if (midori_view_mime_icon (view, theme, "%s-x-generic", *parts, NULL))
-        goto free_parts;
-    if (midori_view_mime_icon (view, theme, "gnome-mime-%s-x-generic", *parts, NULL))
-        goto free_parts;
-
-    icon = gtk_widget_render_icon (view->web_view,
-        GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
-    midori_view_apply_icon (view, icon, GTK_STOCK_FILE);
+    if ((icon_names = (gchar**)g_themed_icon_get_names (G_THEMED_ICON (icon))))
+    while (*icon_names)
+    {
+        if ((pixbuf = gtk_icon_theme_load_icon (icon_theme, *icon_names, 16, 0, NULL)))
+            break;
+        icon_names++;
+    }
+    g_object_unref (icon);
 
-free_parts:
-    g_strfreev (parts);
+    midori_view_apply_icon (view, pixbuf, GTK_STOCK_FILE);
 }
 
 #if !WEBKIT_CHECK_VERSION (1, 8, 0)
@@ -3012,7 +2984,7 @@ webkit_web_view_download_requested_cb (GtkWidget*      web_view,
     description = g_content_type_get_description (content_type);
     #if GTK_CHECK_VERSION (2, 14, 0)
     icon = g_content_type_get_icon (content_type);
-    g_themed_icon_append_name (G_THEMED_ICON (icon), "document-x-generic");
+    g_themed_icon_append_name (G_THEMED_ICON (icon), "text-html");
     image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
     g_object_unref (icon);
     gtk_widget_show (image);
index c5a12f8ab2d3f2f7be4dff8d11d253d34c93674f..89a5d342225e0e759518fb8b8dac8c082835c7e8 100644 (file)
@@ -50,27 +50,21 @@ midori_findbar_set_icon (MidoriFindbar*       findbar,
                          GtkIconEntryPosition icon_pos,
                          const gchar*         icon_name)
 {
-    #if !HAVE_HILDON
-    GdkScreen* screen = gtk_widget_get_screen (findbar->find_text);
-    GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
-    gchar* symbolic_icon_name;
-
-    if (icon_name == NULL)
+    if (icon_name != NULL)
     {
+        #if GTK_CHECK_VERSION (2, 16, 0)
+        gchar* symbolic_icon_name = g_strconcat (icon_name, "-symbolic", NULL);
+        gtk_entry_set_icon_from_gicon (GTK_ENTRY (findbar->find_text), icon_pos,
+            g_themed_icon_new_with_default_fallbacks (symbolic_icon_name));
+        g_free (symbolic_icon_name);
+        #else
         gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (findbar->find_text),
-                                                icon_pos, NULL);
-        return;
+                                                icon_pos, icon_name);
+        #endif
     }
-
-    symbolic_icon_name = g_strconcat (icon_name, "-symbolic", NULL);
-    if (gtk_icon_theme_has_icon (icon_theme, symbolic_icon_name))
-        gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (findbar->find_text),
-                                                icon_pos, symbolic_icon_name);
     else
         gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (findbar->find_text),
-                                                icon_pos, icon_name);
-    g_free (symbolic_icon_name);
-    #endif
+                                                icon_pos, NULL);
 }
 
 static void