[epiphany] Use an enum for the global mode of the application



commit f594ec68442049ad9b6ecce598f2623e0ece9049
Author: Xan Lopez <xlopez igalia com>
Date:   Thu Jun 30 16:31:01 2011 +0200

    Use an enum for the global mode of the application
    
    In preparation to add a new mode for WebApps.

 embed/ephy-embed-shell.c  |   40 +++++++++++++++++++++-------------------
 embed/ephy-embed-shell.h  |    8 +++++++-
 embed/ephy-embed-single.c |    2 +-
 embed/ephy-web-view.c     |    2 +-
 src/ephy-main.c           |    3 ++-
 src/ephy-shell.c          |    8 ++++----
 src/ephy-shell.h          |    2 +-
 src/pdm-dialog.c          |    3 ++-
 8 files changed, 39 insertions(+), 29 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 73ab927..30de7dd 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -32,6 +32,7 @@
 #include "ephy-download.h"
 #include "ephy-embed-shell.h"
 #include "ephy-embed-single.h"
+#include "ephy-embed-type-builtins.h"
 #include "ephy-encodings.h"
 #include "ephy-favicon-cache.h"
 #include "ephy-file-helpers.h"
@@ -58,7 +59,7 @@ struct _EphyEmbedShellPrivate
 	EphyAdBlockManager *adblock_manager;
 	GtkPageSetup *page_setup;
 	GtkPrintSettings *print_settings;
-	gboolean private_instance;
+	EphyEmbedShellMode mode;
 	guint single_initialised : 1;
 };
 
@@ -75,7 +76,7 @@ static guint signals[LAST_SIGNAL];
 enum
 {
 	PROP_0,
-	PROP_PRIVATE_INSTANCE,
+	PROP_MODE,
 	N_PROPERTIES
 };
 
@@ -291,8 +292,8 @@ ephy_embed_shell_set_property (GObject *object,
 
   switch (prop_id)
   {
-  case PROP_PRIVATE_INSTANCE:
-	  embed_shell->priv->private_instance = g_value_get_boolean (value);
+  case PROP_MODE:
+	  embed_shell->priv->mode = g_value_get_enum (value);
 	  break;
   default:
 	  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -309,8 +310,8 @@ ephy_embed_shell_get_property (GObject *object,
 
   switch (prop_id)
   {
-  case PROP_PRIVATE_INSTANCE:
-	  g_value_set_boolean (value, embed_shell->priv->private_instance);
+  case PROP_MODE:
+	  g_value_set_enum (value, embed_shell->priv->mode);
 	  break;
   default:
 	  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -341,13 +342,14 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
 
 	klass->get_embed_single = impl_get_embed_single;
 
-	object_properties[PROP_PRIVATE_INSTANCE] =
-		g_param_spec_boolean ("private-instance",
-				      "Private instance",
-				      "Whether this Epiphany instance is private.",
-				      FALSE,
-				      G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
-				      G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY);
+	object_properties[PROP_MODE] =
+		g_param_spec_enum ("mode",
+				   "Mode",
+				   "The	 global mode for this instance of Epiphany .",
+				   EPHY_TYPE_EMBED_SHELL_MODE,
+				   EPHY_EMBED_SHELL_MODE_BROWSER,
+				   G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
+				   G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY);
 	
 	g_object_class_install_properties (object_class,
 					   N_PROPERTIES,
@@ -646,15 +648,15 @@ ephy_embed_shell_remove_download (EphyEmbedShell *shell, EphyDownload *download)
 }
 
 /**
- * ephy_embed_shell_is_private_instance:
+ * ephy_embed_shell_get_mode:
  * @shell: an #EphyEmbedShell
  * 
- * Returns: whether @shell is a private instance
+ * Returns: the global mode of the @shell
  **/
-gboolean
-ephy_embed_shell_is_private_instance (EphyEmbedShell *shell)
+EphyEmbedShellMode
+ephy_embed_shell_get_mode (EphyEmbedShell *shell)
 {
-	g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), FALSE);
+	g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), EPHY_EMBED_SHELL_MODE_BROWSER);
 	
-	return shell->priv->private_instance;
+	return shell->priv->mode;
 }
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index 02eaf43..d89aafe 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -47,6 +47,12 @@ typedef struct _EphyEmbedShellPrivate	EphyEmbedShellPrivate;
 
 extern EphyEmbedShell *embed_shell;
 
+typedef enum
+{
+	EPHY_EMBED_SHELL_MODE_BROWSER,
+	EPHY_EMBED_SHELL_MODE_PRIVATE
+} EphyEmbedShellMode;
+
 struct _EphyEmbedShell
 {
 	GtkApplication parent;
@@ -101,7 +107,7 @@ void		   ephy_embed_shell_add_download	(EphyEmbedShell *shell,
 void		   ephy_embed_shell_remove_download	(EphyEmbedShell *shell,
 							 EphyDownload *download);
 
-gboolean           ephy_embed_shell_is_private_instance (EphyEmbedShell *shell);
+EphyEmbedShellMode ephy_embed_shell_get_mode            (EphyEmbedShell *shell);
 
 G_END_DECLS
 
diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c
index a41d0b2..547f492 100644
--- a/embed/ephy-embed-single.c
+++ b/embed/ephy-embed-single.c
@@ -528,7 +528,7 @@ ephy_embed_single_initialize (EphyEmbedSingle *single)
      are not using a private session, otherwise we want any new
      password to expire when we exit *and* we don't want to use any
      existing password in the keyring */
-  if (ephy_embed_shell_is_private_instance (ephy_embed_shell_get_default ()) == FALSE)
+  if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) != EPHY_EMBED_SHELL_MODE_PRIVATE)
     soup_session_add_feature_by_type (session, SOUP_TYPE_PASSWORD_MANAGER_GNOME);
 #endif
 
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 719db10..19ff7d4 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1873,7 +1873,7 @@ load_status_cb (WebKitWebView *web_view,
     if (ephy_web_view_get_is_blank (view))
       g_object_notify (object, "embed-title");
 
-    if (ephy_embed_shell_is_private_instance (embed_shell) == FALSE &&
+    if (ephy_embed_shell_get_mode (embed_shell) != EPHY_EMBED_SHELL_MODE_PRIVATE &&
         g_settings_get_boolean (EPHY_SETTINGS_MAIN,
                                 EPHY_PREFS_REMEMBER_PASSWORDS))
       _ephy_web_view_hook_into_forms (view);
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 2b5f102..e8e5fb1 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -415,7 +415,8 @@ main (int argc,
   g_setenv ("XLIB_SKIP_ARGB_VISUALS", "1", FALSE);
 
   /* Now create the shell */
-  _ephy_shell_create_instance (private_instance);
+  _ephy_shell_create_instance (private_instance ?
+                               EPHY_EMBED_SHELL_MODE_PRIVATE : EPHY_EMBED_SHELL_MODE_BROWSER);
 
   startup_flags = get_startup_flags ();
   ctx = ephy_shell_startup_context_new (startup_flags,
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index bba5741..594301e 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -179,7 +179,7 @@ ephy_shell_startup (GApplication* application)
 {
   /* We're not remoting; start our services */
   /* Migrate profile if we are not running a private instance */
-  if (!ephy_embed_shell_is_private_instance (EPHY_EMBED_SHELL (application)) &&
+  if (ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (application)) != EPHY_EMBED_SHELL_MODE_PRIVATE &&
       ephy_profile_utils_get_migration_version () < EPHY_PROFILE_MIGRATION_VERSION)
   {
 	  GError *error = NULL;
@@ -365,7 +365,7 @@ ephy_shell_before_emit (GApplication *application,
 static void
 ephy_shell_constructed (GObject *object)
 {
-	if (ephy_embed_shell_is_private_instance (EPHY_EMBED_SHELL (object)))
+	if (ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (object)) == EPHY_EMBED_SHELL_MODE_PRIVATE)
 	{
 		GApplicationFlags flags;
 
@@ -1088,13 +1088,13 @@ ephy_shell_get_prefs_dialog (EphyShell *shell)
 }
 
 void
-_ephy_shell_create_instance (gboolean private_instance)
+_ephy_shell_create_instance (EphyEmbedShellMode mode)
 {
 	g_assert (ephy_shell == NULL);
 
 	ephy_shell = EPHY_SHELL (g_object_new (EPHY_TYPE_SHELL,
 					       "application-id", "org.gnome.Epiphany",
-					       "private-instance", private_instance,
+					       "mode", mode,
 					       NULL));
 	/* FIXME weak ref */
 	g_assert (ephy_shell != NULL);
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index bd49a0f..b3d19d7 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -160,7 +160,7 @@ EphyShellStartupContext *ephy_shell_startup_context_new (EphyStartupFlags startu
 							 guint32          user_time);
 
 /* private API */
-void	       _ephy_shell_create_instance		(gboolean private_instance);
+void	       _ephy_shell_create_instance		(EphyEmbedShellMode mode);
 
 G_END_DECLS
 
diff --git a/src/pdm-dialog.c b/src/pdm-dialog.c
index f5ce73f..c243c16 100644
--- a/src/pdm-dialog.c
+++ b/src/pdm-dialog.c
@@ -1518,7 +1518,8 @@ pdm_dialog_init (PdmDialog *dialog)
 	PdmDialogPrivate *priv;
 	PdmActionInfo *cookies, *passwords;
 	GtkWidget *window;
-	gboolean has_private_profile = ephy_embed_shell_is_private_instance (embed_shell);
+	gboolean has_private_profile = 
+		ephy_embed_shell_get_mode (embed_shell) == EPHY_EMBED_SHELL_MODE_PRIVATE;
 
 
 	priv = dialog->priv = EPHY_PDM_DIALOG_GET_PRIVATE (dialog);



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