[epiphany] Don't use stock ids for the security state of a page



commit 3bf0f7dbb2c8dea3ac7b66d2ca62ed6779e66077
Author: William Jon McCann <william jon mccann gmail com>
Date:   Tue Dec 31 12:17:34 2013 -0500

    Don't use stock ids for the security state of a page
    
    Use an enum instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721285

 lib/widgets/Makefile.am           |    3 +-
 lib/widgets/ephy-location-entry.c |   40 +++++++++++++++++++-----------------
 lib/widgets/ephy-location-entry.h |   13 +++++++----
 src/ephy-location-controller.c    |   36 ++++++++++++++++----------------
 src/ephy-window.c                 |   14 ++++++------
 5 files changed, 56 insertions(+), 50 deletions(-)
---
diff --git a/lib/widgets/Makefile.am b/lib/widgets/Makefile.am
index a507ada..819717d 100644
--- a/lib/widgets/Makefile.am
+++ b/lib/widgets/Makefile.am
@@ -5,7 +5,8 @@ BUILT_SOURCES = \
        ephy-widgets-type-builtins.h
 
 TYPES_H_FILES = \
-       ephy-removable-pixbuf-renderer.h
+       ephy-removable-pixbuf-renderer.h \
+       ephy-location-entry.h
 
 CLEANFILES = $(stamp_files) $(BUILT_SOURCES)
 DISTCLEANFILES = $(stamp_files) $(BUILT_SOURCES)
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 3e5a1d4..f09457c 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -24,6 +24,7 @@
 #include "config.h"
 #include "ephy-location-entry.h"
 
+#include "ephy-widgets-type-builtins.h"
 #include "ephy-about-handler.h"
 #include "ephy-debug.h"
 #include "ephy-dnd.h"
@@ -109,7 +110,7 @@ enum
        PROP_0,
        PROP_LOCATION,
        PROP_FAVICON,
-       PROP_LOCK_STOCK,
+       PROP_LOCK_STATE,
        PROP_SHOW_LOCK,
        PROP_SHOW_FAVICON
 };
@@ -144,9 +145,9 @@ ephy_location_entry_set_property (GObject *object,
                ephy_location_entry_set_favicon (entry,
                                                 g_value_get_object (value));
                break;
-       case PROP_LOCK_STOCK:
-               ephy_location_entry_set_lock_stock (entry,
-                                                   g_value_get_string (value));
+       case PROP_LOCK_STATE:
+               ephy_location_entry_set_lock_state (entry,
+                                                   g_value_get_enum (value));
                break;
        case PROP_SHOW_LOCK:
                ephy_location_entry_set_show_lock (entry,
@@ -255,17 +256,18 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
                                                              G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
        /**
-       * EphyLocationEntry:lock-stock-id:
+       * EphyLocationEntry:lock-state:
        *
-       * Stock id of the security icon.
+       * State of the security icon.
        */
        g_object_class_install_property (object_class,
-                                        PROP_LOCK_STOCK,
-                                        g_param_spec_string  ("lock-stock-id",
-                                                              "Lock Stock ID",
-                                                              "Stock id of the security icon",
-                                                              NULL,
-                                                              G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+                                        PROP_LOCK_STATE,
+                                        g_param_spec_enum  ("lock-state",
+                                                            "Lock state",
+                                                            "State of the security icon",
+                                                            EPHY_TYPE_LOCATION_LOCK_STATE,
+                                                            EPHY_LOCATION_LOCK_STATE_UNKNOWN,
+                                                            G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
        /**
        * EphyLocationEntry:show-lock:
@@ -1610,17 +1612,17 @@ ephy_location_entry_set_show_lock (EphyLocationEntry *entry,
 }
 
 /**
- * ephy_location_entry_set_lock_stock:
+ * ephy_location_entry_set_lock_state:
  * @entry: an #EphyLocationEntry widget
- * @stock_id: a stock_id from GTK+ stock icons
+ * @state: the #EphyLocationLockState
  *
  * Set the lock icon to be displayed, to actually show the icon see 
  * ephy_location_entry_set_show_lock.
  *
  **/
 void
-ephy_location_entry_set_lock_stock (EphyLocationEntry *entry,
-                                   const char *stock_id)
+ephy_location_entry_set_lock_state (EphyLocationEntry *entry,
+                                   EphyLocationLockState state)
 
 {
        EphyLocationEntryPrivate *priv;
@@ -1638,10 +1640,10 @@ ephy_location_entry_set_lock_stock (EphyLocationEntry *entry,
         * their security infrastructure (broken cert, etc). For
         * everything else, nothing is shown.
         */
-       if (!stock_id || g_str_equal (stock_id, STOCK_LOCK_BROKEN))
-               priv->lock_gicon = g_themed_icon_new_with_default_fallbacks ("channel-insecure-symbolic");
-       else
+       if (state == EPHY_LOCATION_LOCK_STATE_SECURE)
                priv->lock_gicon = g_themed_icon_new_with_default_fallbacks ("channel-secure-symbolic");
+       else
+               priv->lock_gicon = g_themed_icon_new_with_default_fallbacks ("channel-insecure-symbolic");
 
        if (priv->show_lock)
                gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry),
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index 307a45e..014b910 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -61,9 +61,12 @@ struct _EphyLocationEntry
        EphyLocationEntryPrivate *priv;
 };
 
-#define STOCK_LOCK_INSECURE        "lock-insecure"
-#define STOCK_LOCK_SECURE          "lock-secure"
-#define STOCK_LOCK_BROKEN          "lock-broken"
+typedef enum {
+  EPHY_LOCATION_LOCK_STATE_UNKNOWN = 0,
+  EPHY_LOCATION_LOCK_STATE_BROKEN,
+  EPHY_LOCATION_LOCK_STATE_INSECURE,
+  EPHY_LOCATION_LOCK_STATE_SECURE
+} EphyLocationLockState;
 
 GType          ephy_location_entry_get_type            (void);
 
@@ -110,8 +113,8 @@ void            ephy_location_entry_set_show_favicon    (EphyLocationEntry *entr
 void           ephy_location_entry_set_show_lock       (EphyLocationEntry *entry,
                                                         gboolean show_lock);
 
-void           ephy_location_entry_set_lock_stock      (EphyLocationEntry *entry,
-                                                        const char *stock_id);
+void           ephy_location_entry_set_lock_state      (EphyLocationEntry *entry,
+                                                        EphyLocationLockState state);
 
 void           ephy_location_entry_set_lock_tooltip    (EphyLocationEntry *entry,
                                                         const char *tooltip);
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index 7ac778d..eaf7868 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -22,6 +22,7 @@
 #include "config.h"
 #include "ephy-location-controller.h"
 
+#include "ephy-widgets-type-builtins.h"
 #include "ephy-completion-model.h"
 #include "ephy-debug.h"
 #include "ephy-embed-container.h"
@@ -53,7 +54,7 @@ struct _EphyLocationControllerPrivate
        EphyNode *smart_bmks;
        EphyBookmarks *bookmarks;
        GdkPixbuf *icon;
-       char *lock_stock_id;
+       EphyLocationLockState lock_state;
        guint editable : 1;
        guint show_icon : 1;
        guint show_lock : 1;
@@ -76,7 +77,7 @@ enum
        PROP_EDITABLE,
        PROP_ICON,
        PROP_SHOW_ICON,
-       PROP_LOCK_STOCK,
+       PROP_LOCK_STATE,
        PROP_SHOW_LOCK,
        PROP_WINDOW,
        PROP_LOCATION_ENTRY
@@ -439,8 +440,8 @@ ephy_location_controller_constructed (GObject *object)
                                priv->location_entry, "show-favicon",
                                G_BINDING_SYNC_CREATE);
 
-       g_object_bind_property (controller, "lock-stock-id",
-                               priv->location_entry, "lock-stock-id",
+       g_object_bind_property (controller, "lock-state",
+                               priv->location_entry, "lock-state",
                                G_BINDING_SYNC_CREATE);
 
        g_object_bind_property (controller, "show-lock",
@@ -494,9 +495,8 @@ ephy_location_controller_set_property (GObject *object,
                case PROP_SHOW_ICON:
                        priv->show_icon = g_value_get_boolean (value);
                        break;
-               case PROP_LOCK_STOCK:
-                       g_free (priv->lock_stock_id);
-                       priv->lock_stock_id = g_value_dup_string (value);
+               case PROP_LOCK_STATE:
+                       priv->lock_state = g_value_get_enum (value);
                        break;
                case PROP_SHOW_LOCK:
                        priv->show_lock = g_value_get_boolean (value);
@@ -535,8 +535,8 @@ ephy_location_controller_get_property (GObject *object,
                case PROP_SHOW_ICON:
                        g_value_set_boolean (value, priv->show_icon);
                        break;
-               case PROP_LOCK_STOCK:
-                       g_value_set_string (value, priv->lock_stock_id);
+               case PROP_LOCK_STATE:
+                       g_value_set_enum (value, priv->lock_state);
                        break;
                case PROP_SHOW_LOCK:
                        g_value_set_boolean (value, priv->show_lock);
@@ -652,17 +652,18 @@ ephy_location_controller_class_init (EphyLocationControllerClass *class)
                                                               G_PARAM_CONSTRUCT | G_PARAM_READWRITE | 
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
        /**
-       * EphyLocationController:lock-stock-id:
+       * EphyLocationController:lock-state:
        *
-       * Stock id of the security icon.
+       * State of the security icon.
        */
        g_object_class_install_property (object_class,
-                                        PROP_LOCK_STOCK,
-                                        g_param_spec_string  ("lock-stock-id",
-                                                              "Lock Stock ID",
-                                                              "Stock id of the security icon",
-                                                              NULL,
-                                                              G_PARAM_READWRITE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+                                        PROP_LOCK_STATE,
+                                        g_param_spec_enum  ("lock-state",
+                                                            "Lock State",
+                                                            "State of the security icon",
+                                                            EPHY_TYPE_LOCATION_LOCK_STATE,
+                                                            EPHY_LOCATION_LOCK_STATE_UNKNOWN,
+                                                            G_PARAM_READWRITE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
        /**
        * EphyLocationController:show-lock:
@@ -846,7 +847,6 @@ ephy_location_controller_finalize (GObject *object)
 
        g_list_free (priv->actions);
        g_free (priv->address);
-       g_free (priv->lock_stock_id);
 
        G_OBJECT_CLASS (ephy_location_controller_parent_class)->finalize (object);
 }
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 8f0f30c..03e5a98 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -738,14 +738,14 @@ sync_tab_load_status (EphyWebView *view,
 static void
 _ephy_window_set_security_state (EphyWindow *window,
                                 gboolean show_lock,
-                                const char *stock_id)
+                                EphyLocationLockState state)
 {
        EphyWindowPrivate *priv = window->priv;
 
        priv->show_lock = show_lock != FALSE;
 
        g_object_set (priv->location_controller,
-                     "lock-stock-id", stock_id,
+                     "lock-state", state,
                      "show-lock", priv->show_lock,
                      NULL);
 }
@@ -757,7 +757,7 @@ sync_tab_security (EphyWebView *view,
 {
        EphyWindowPrivate *priv = window->priv;
        EphyWebViewSecurityLevel level;
-       const char *stock_id = STOCK_LOCK_INSECURE;
+       EphyLocationLockState state = EPHY_LOCATION_LOCK_STATE_INSECURE;
        gboolean show_lock = FALSE;
 
        if (priv->closing) return;
@@ -771,7 +771,7 @@ sync_tab_security (EphyWebView *view,
                        /* Nothing to do. */
                        break;
                case EPHY_WEB_VIEW_STATE_IS_BROKEN:
-                       stock_id = STOCK_LOCK_BROKEN;
+                       state = EPHY_LOCATION_LOCK_STATE_INSECURE;
                         show_lock = TRUE;
                         break;
                case EPHY_WEB_VIEW_STATE_IS_SECURE_LOW:
@@ -779,10 +779,10 @@ sync_tab_security (EphyWebView *view,
                        /* We deliberately don't show the 'secure' icon
                         * for low & medium secure sites; see bug #151709.
                         */
-                       stock_id = STOCK_LOCK_INSECURE;
+                       state = EPHY_LOCATION_LOCK_STATE_INSECURE;
                        break;
                case EPHY_WEB_VIEW_STATE_IS_SECURE_HIGH:
-                       stock_id = STOCK_LOCK_SECURE;
+                       state = EPHY_LOCATION_LOCK_STATE_SECURE;
                        show_lock = TRUE;
                        break;
                default:
@@ -790,7 +790,7 @@ sync_tab_security (EphyWebView *view,
                        break;
        }
 
-       _ephy_window_set_security_state (window, show_lock, stock_id);
+       _ephy_window_set_security_state (window, show_lock, state);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]