gcr: Remove stock icon code, add gcr_icon_for_token_info()
authorStef Walter <stefw@collabora.co.uk>
Tue, 27 Sep 2011 07:19:49 +0000 (09:19 +0200)
committerStef Walter <stefw@collabora.co.uk>
Tue, 27 Sep 2011 07:19:49 +0000 (09:19 +0200)
 * gcr-icons.h is public
 * Remove old stock icon code, and use themed icons properly
 * Add gcr_icon_for_token_info() function which looks up an
   appropriate icon for a token.

gcr/Makefile.am
gcr/gcr-base.h
gcr/gcr-certificate-renderer.c
gcr/gcr-failure-renderer.c
gcr/gcr-icons.c
gcr/gcr-icons.h
gcr/gcr-key-renderer.c
gcr/gcr-unlock-renderer.c

index 4c747a7..3f88bde 100644 (file)
@@ -20,6 +20,7 @@ HEADER_BASE_FILES = \
        gcr-collection.h \
        gcr-comparable.h \
        gcr-deprecated-base.h \
+       gcr-icons.h \
        gcr-library.h \
        gcr-parser.h \
        gcr-pkcs11-certificate.h \
index 218030a..f70720b 100644 (file)
@@ -38,6 +38,7 @@
 #include "gcr-certificate-chain.h"
 #include "gcr-deprecated-base.h"
 #include "gcr-enum-types-base.h"
+#include "gcr-icons.h"
 #include "gcr-library.h"
 #include "gcr-parser.h"
 #include "gcr-pkcs11-certificate.h"
index 6c8535d..4516199 100644 (file)
@@ -549,7 +549,6 @@ gcr_certificate_renderer_class_init (GcrCertificateRendererClass *klass)
                   g_param_spec_string ("label", "Label", "Certificate Label",
                                        "", G_PARAM_READWRITE));
 
-       _gcr_icons_register ();
        gcr_certificate_mixin_class_init (gobject_class);
 
        /* Register this as a renderer which can be loaded */
index 8f75956..b6f829f 100644 (file)
@@ -126,8 +126,6 @@ _gcr_failure_renderer_class_init (GcrFailureRendererClass *klass)
        g_object_class_install_property (gobject_class, PROP_ATTRIBUTES,
                   g_param_spec_boxed ("attributes", "Attributes", "Certificate pkcs11 attributes",
                                       GCK_TYPE_ATTRIBUTES, G_PARAM_READWRITE));
-
-       _gcr_icons_register ();
 }
 
 static void
index 9f2994e..ba946f7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * gnome-keyring
  *
- * Copyright (C) 2010 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as
  * License along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  * 02111-1307, USA.
+ *
+ * Author: Stef Walter <stefw@collabora.co.uk>
  */
 
 #include "config.h"
 
-#include "gcr.h"
-#include "gcr-types.h"
+#include "gcr-base.h"
 #include "gcr-icons.h"
-#include "gcr-internal.h"
-
-static gboolean registered_icons = FALSE;
-static const gchar *themed_icons[] = {
-       GCR_ICON_CERTIFICATE,
-       GCR_ICON_KEY,
-       GCR_ICON_KEY_PAIR,
-       NULL,
-};
 
-static void
-add_theme_source (GtkIconSet *iconset, const gchar *icon, GtkIconSize size)
+GIcon *
+gcr_icon_for_token_info (GckTokenInfo *token_info)
 {
-       GtkIconSource *source;
-
-       source = gtk_icon_source_new ();
-       gtk_icon_source_set_icon_name (source, icon);
-       gtk_icon_source_set_direction_wildcarded (source, TRUE);
-       gtk_icon_source_set_state_wildcarded (source, TRUE);
-
-       if (size == -1) {
-               gtk_icon_source_set_size_wildcarded (source, TRUE);
-       } else {
-               gtk_icon_source_set_size_wildcarded (source, FALSE);
-               gtk_icon_source_set_size (source, size);
-       }
-
-       gtk_icon_set_add_source (iconset, source);
-       gtk_icon_source_free (source);
-}
-
-void
-_gcr_icons_register (void)
-{
-       GtkIconFactory *factory;
-       GtkIconSet *iconset;
-       const gchar **name;
-
-       if (registered_icons)
-               return;
+       GIcon *icon;
 
-       /* Setup the icon factory. */
-       factory = gtk_icon_factory_new ();
-       gtk_icon_factory_add_default (factory);
+       g_return_val_if_fail (token_info != NULL, NULL);
 
-       for (name = themed_icons; name && *name; name++) {
-               iconset = gtk_icon_set_new ();
-               add_theme_source (iconset, *name, GTK_ICON_SIZE_BUTTON);
-               add_theme_source (iconset, *name, GTK_ICON_SIZE_MENU);
-               add_theme_source (iconset, *name, GTK_ICON_SIZE_LARGE_TOOLBAR);
-               add_theme_source (iconset, *name, GTK_ICON_SIZE_SMALL_TOOLBAR);
-               add_theme_source (iconset, *name, GTK_ICON_SIZE_DIALOG);
-               add_theme_source (iconset, *name, -1);
-               gtk_icon_factory_add (factory, *name, iconset);
-               gtk_icon_set_unref (iconset);
-       }
+       if (g_strcmp0 (token_info->manufacturer_id, "Gnome Keyring") == 0)
+               icon = g_themed_icon_new (GCR_ICON_HOME_DIRECTORY);
+       else
+               icon = g_themed_icon_new (GCR_ICON_SMART_CARD);
 
-       g_object_unref (factory);
-       registered_icons = TRUE;
+       return icon;
 }
index 2974ae3..f0e8b69 100644 (file)
@@ -2,6 +2,7 @@
  * gnome-keyring
  *
  * Copyright (C) 2010 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as
@@ -29,9 +30,11 @@ G_BEGIN_DECLS
 #define GCR_ICON_CERTIFICATE    "application-certificate"
 #define GCR_ICON_KEY            "gcr-key"
 #define GCR_ICON_KEY_PAIR       "gcr-key-pair"
+#define GCR_ICON_SMART_CARD     "gcr-smart-card"
+#define GCR_ICON_HOME_DIRECTORY "user-home"
 
-void         _gcr_icons_register         (void);
+GIcon *          gcr_icon_for_token_info                (GckTokenInfo *token_info);
 
 G_END_DECLS
 
-#endif /* __GCR_TOKEN_MANAGER_H__ */
+#endif /* __GCR_SMART_CARD_H__ */
index 242d842..b9248fd 100644 (file)
@@ -225,8 +225,6 @@ gcr_key_renderer_class_init (GcrKeyRendererClass *klass)
        g_object_class_override_property (gobject_class, PROP_LABEL, "label");
        g_object_class_override_property (gobject_class, PROP_ATTRIBUTES, "attributes");
 
-       _gcr_icons_register ();
-
        /* Register this as a view which can be loaded */
        registered = gck_attributes_new ();
        gck_attributes_add_ulong (registered, CKA_CLASS, CKO_PRIVATE_KEY);
index 106c2bc..9d15678 100644 (file)
@@ -265,8 +265,6 @@ _gcr_unlock_renderer_class_init (GcrUnlockRendererClass *klass)
        g_object_class_install_property (gobject_class, PROP_ATTRIBUTES,
                   g_param_spec_boxed ("attributes", "Attributes", "Certificate pkcs11 attributes",
                                       GCK_TYPE_ATTRIBUTES, G_PARAM_READWRITE));
-
-       _gcr_icons_register ();
 }
 
 static void