]> spindle.queued.net Git - midori/commitdiff
Change extension API to split initialization and activation
authorChristian Dywan <christian@twotoasts.de>
Thu, 20 Nov 2008 00:22:25 +0000 (01:22 +0100)
committerChristian Dywan <christian@twotoasts.de>
Thu, 20 Nov 2008 00:22:25 +0000 (01:22 +0100)
We want to be able to keep extensions in a state where
they don't actually do anything but merely provide
context information. Therefore don't pass the MidoriApp.

As soon as we want to use extensions, we activate them.

Extensions are now saved in an array in MidoriApp.

extensions/statusbar-features.c
extensions/tab-panel/main.c
midori/main.c
midori/midori-app.c
midori/midori-app.h
midori/midori-extension.c

index 26e2876e7e712b878ab2cc1f338e9168b574d971..c1a37e3afded9dbb3461537aebd981aefcaa7b90 100644 (file)
@@ -12,8 +12,8 @@
 #include <midori/midori.h>
 
 void
-realign_tabs_app_add_browser_cb (MidoriApp*     app,
-                                 MidoriBrowser* browser)
+statusbar_features_app_add_browser_cb (MidoriApp*     app,
+                                       MidoriBrowser* browser)
 {
     GtkWidget* statusbar;
     GtkWidget* bbox;
@@ -36,7 +36,16 @@ realign_tabs_app_add_browser_cb (MidoriApp*     app,
     gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
 }
 
-MidoriExtension* extension_main (MidoriApp* app)
+static void
+statusbar_features_activate_cb (MidoriExtension* extension,
+                                MidoriApp*       app)
+{
+    g_signal_connect (app, "add-browser",
+        G_CALLBACK (statusbar_features_app_add_browser_cb), NULL);
+}
+
+MidoriExtension*
+extension_init (void)
 {
     MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
         "name", "Statusbar Features",
@@ -45,8 +54,8 @@ MidoriExtension* extension_main (MidoriApp* app)
         "authors", "Christian Dywan <christian@twotoasts.de>",
         NULL);
 
-    g_signal_connect (app, "add-browser",
-        G_CALLBACK (realign_tabs_app_add_browser_cb), NULL);
+    g_signal_connect (extension, "activate",
+        G_CALLBACK (statusbar_features_activate_cb), NULL);
 
     return extension;
 }
index 83664ba833bb416d6de2f70b2466af51a218b59f..60cb316b9804a5682e405c5671d028fcdf6c8289 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <midori/midori.h>
 
-void
+static void
 tab_panel_app_add_browser_cb (MidoriApp*     app,
                               MidoriBrowser* browser)
 {
@@ -29,7 +29,16 @@ tab_panel_app_add_browser_cb (MidoriApp*     app,
                               NULL, GTK_STOCK_INDEX, "Tab Panel");
 }
 
-MidoriExtension* extension_main (MidoriApp* app)
+static void
+tab_panel_activate_cb (MidoriExtension* extension,
+                       MidoriApp*       app)
+{
+    g_signal_connect (app, "add-browser",
+        G_CALLBACK (tab_panel_app_add_browser_cb), NULL);
+}
+
+MidoriExtension*
+extension_init (void)
 {
     MidoriExtension* extension = g_object_new (TAB_PANEL_TYPE_EXTENSION,
         "name", "Tab Panel",
@@ -38,8 +47,8 @@ MidoriExtension* extension_main (MidoriApp* app)
         "authors", "Christian Dywan <christian@twotoasts.de>",
         NULL);
 
-    g_signal_connect (app, "add-browser",
-        G_CALLBACK (tab_panel_app_add_browser_cb), extension);
+    g_signal_connect (extension, "activate",
+        G_CALLBACK (tab_panel_activate_cb), NULL);
 
     return extension;
 }
index 2b6b2cf2ed972643e82f2143ae7bccc0829df271..c4bd900ca1f9e592477e5e605421517cbe685473 100644 (file)
@@ -1291,18 +1291,14 @@ main (int    argc,
         G_CALLBACK (midori_history_clear_cb), db);
     #endif
 
-    g_object_set (app, "settings", settings,
-                       "bookmarks", bookmarks,
-                       "trash", trash,
-                       "search-engines", search_engines,
-                       "history", history,
-                       NULL);
-
     /* Load extensions */
+    KatzeArray* extensions;
     gchar* extension_path;
     GDir* extension_dir;
     const gchar* filename;
+    MidoriExtension* extension;
 
+    extensions = katze_array_new (MIDORI_TYPE_EXTENSION);
     extension_path = g_build_filename (LIBDIR, PACKAGE_NAME, NULL);
     if (g_module_supported ())
         extension_dir = g_dir_open (extension_path, 0, NULL);
@@ -1314,8 +1310,8 @@ main (int    argc,
         {
             gchar* fullname;
             GModule* module;
-            typedef MidoriExtension* (*extension_main_func)(MidoriApp* app);
-            extension_main_func extension_main;
+            typedef MidoriExtension* (*extension_init_func)(void);
+            extension_init_func extension_init;
 
             fullname = g_build_filename (extension_path, filename, NULL);
             module = g_module_open (fullname, G_MODULE_BIND_LOCAL);
@@ -1326,17 +1322,33 @@ main (int    argc,
                 continue;
             }
             ;
-            if (!g_module_symbol (module, "extension_main",
-                             (gpointer) &extension_main))
+            if (!g_module_symbol (module, "extension_init",
+                             (gpointer) &extension_init))
             {
                 g_warning ("%s", g_module_error ());
                 continue;
             }
-            extension_main (app);
+            extension = extension_init ();
+            katze_array_add_item (extensions, extension);
         }
         g_dir_close (extension_dir);
     }
 
+    g_object_set (app, "settings", settings,
+                       "bookmarks", bookmarks,
+                       "trash", trash,
+                       "search-engines", search_engines,
+                       "history", history,
+                       "extensions", extensions,
+                       NULL);
+
+    n = katze_array_get_length (extensions);
+    for (i = 0; i < n; i++)
+    {
+        extension = katze_array_get_nth_item (extensions, i);
+        g_signal_emit_by_name (extension, "activate", app);
+    }
+
     browser = g_object_new (MIDORI_TYPE_BROWSER,
                             "settings", settings,
                             "bookmarks", bookmarks,
index b7966835e3d2232bb9e58bf36c8e23f758e3d013..5e754e1ed20af0510a300c2a16cdfb692e001a3d 100644 (file)
@@ -36,6 +36,7 @@ struct _MidoriApp
     KatzeArray* trash;
     KatzeArray* search_engines;
     KatzeArray* history;
+    KatzeArray* extensions;
 
     gpointer instance;
 };
@@ -52,8 +53,9 @@ enum
     PROP_BOOKMARKS,
     PROP_TRASH,
     PROP_SEARCH_ENGINES,
-    PROP_BROWSER,
     PROP_HISTORY,
+    PROP_EXTENSIONS,
+    PROP_BROWSER,
     PROP_BROWSER_COUNT
 };
 
@@ -235,6 +237,24 @@ midori_app_class_init (MidoriAppClass* class)
                                      KATZE_TYPE_ARRAY,
                                      G_PARAM_READWRITE));
 
+    g_object_class_install_property (gobject_class,
+                                     PROP_HISTORY,
+                                     g_param_spec_object (
+                                     "history",
+                                     "History",
+                                     "The list of history items",
+                                     KATZE_TYPE_ARRAY,
+                                     G_PARAM_READWRITE));
+
+    g_object_class_install_property (gobject_class,
+                                     PROP_EXTENSIONS,
+                                     g_param_spec_object (
+                                     "extensions",
+                                     "Extensions",
+                                     "The list of extensions",
+                                     KATZE_TYPE_ARRAY,
+                                     G_PARAM_READWRITE));
+
     g_object_class_install_property (gobject_class,
                                      PROP_BROWSER,
                                      g_param_spec_object (
@@ -252,15 +272,6 @@ midori_app_class_init (MidoriAppClass* class)
                                      "The current number of browsers",
                                      0, G_MAXUINT, 0,
                                      G_PARAM_READABLE));
-
-    g_object_class_install_property (gobject_class,
-                                     PROP_HISTORY,
-                                     g_param_spec_object (
-                                     "history",
-                                     "History",
-                                     "The list of history items",
-                                     KATZE_TYPE_ARRAY,
-                                     G_PARAM_READWRITE));
 }
 
 static GObject*
@@ -387,6 +398,7 @@ midori_app_init (MidoriApp* app)
     app->trash = NULL;
     app->search_engines = NULL;
     app->history = NULL;
+    app->extensions = NULL;
 
     #if HAVE_UNIQUE
     display_name = g_strdup (gdk_display_get_name (gdk_display_get_default ()));
@@ -418,6 +430,7 @@ midori_app_finalize (GObject* object)
     katze_object_assign (app->trash, NULL);
     katze_object_assign (app->search_engines, NULL);
     katze_object_assign (app->history, NULL);
+    katze_object_assign (app->extensions, NULL);
 
     katze_object_assign (app->instance, NULL);
 
@@ -454,6 +467,9 @@ midori_app_set_property (GObject*      object,
         katze_object_assign (app->history, g_value_dup_object (value));
         /* FIXME: Propagate history to all browsers */
         break;
+    case PROP_EXTENSIONS:
+        katze_object_assign (app->extensions, g_value_dup_object (value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -485,6 +501,9 @@ midori_app_get_property (GObject*    object,
     case PROP_HISTORY:
         g_value_set_object (value, app->history);
         break;
+    case PROP_EXTENSIONS:
+        g_value_set_object (value, app->extensions);
+        break;
     case PROP_BROWSER:
         g_value_set_object (value, app->browser);
         break;
@@ -654,55 +673,6 @@ midori_app_add_browser (MidoriApp*     app,
     g_signal_emit (app, signals[ADD_BROWSER], 0, browser);
 }
 
-/**
- * midori_app_get_settings:
- * @app: a #MidoriApp
- *
- * Retrieves the #MidoriWebSettings of the app.
- *
- * Return value: the assigned #MidoriWebSettings
- **/
-MidoriWebSettings*
-midori_app_get_settings (MidoriApp* app)
-{
-    g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
-
-    return app->settings;
-}
-
-/**
- * midori_app_set_settings:
- * @app: a #MidoriApp
- *
- * Assigns the #MidoriWebSettings to the app.
- *
- * Return value: the assigned #MidoriWebSettings
- **/
-void
-midori_app_set_settings (MidoriApp*         app,
-                         MidoriWebSettings* settings)
-{
-    g_return_if_fail (MIDORI_IS_APP (app));
-
-    g_object_set (app, "settings", settings, NULL);
-}
-
-/**
- * midori_app_get_trash:
- * @app: a #MidoriApp
- *
- * Retrieves the trash of the app.
- *
- * Return value: the assigned #MidoriTrash
- **/
-KatzeArray*
-midori_app_get_trash (MidoriApp* app)
-{
-    g_return_val_if_fail (MIDORI_IS_APP (app), NULL);
-
-    return app->trash;
-}
-
 /**
  * midori_app_quit:
  * @app: a #MidoriApp
index 361b9d66cf1293d61a91ad05b2a37135645fc68a..98aff04c64d0e403c000e58585a4ba4122d85dcd 100644 (file)
@@ -70,16 +70,6 @@ void
 midori_app_add_browser            (MidoriApp*         app,
                                    MidoriBrowser*     browser);
 
-MidoriWebSettings*
-midori_app_get_settings           (MidoriApp*         app);
-
-void
-midori_app_set_settings           (MidoriApp*         app,
-                                   MidoriWebSettings* settings);
-
-KatzeArray*
-midori_app_get_trash              (MidoriApp*         app);
-
 void
 midori_app_quit                   (MidoriApp*         app);
 
index b97f8eda4486987858189fac4c3198872a5da274..553292bd6c9e5816c79f5adbeb0b0800c7f8f137 100644 (file)
@@ -11,6 +11,8 @@
 
 #include "midori-extension.h"
 
+#include "midori-app.h"
+
 #include <katze/katze.h>
 
 G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT);
@@ -33,6 +35,14 @@ enum
     PROP_AUTHORS
 };
 
+enum {
+    ACTIVATE,
+
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
 static void
 midori_extension_finalize (GObject* object);
 
@@ -54,6 +64,17 @@ midori_extension_class_init (MidoriExtensionClass* class)
     GObjectClass* gobject_class;
     GParamFlags flags;
 
+    signals[ACTIVATE] = g_signal_new (
+        "activate",
+        G_TYPE_FROM_CLASS (class),
+        (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+        0,
+        0,
+        NULL,
+        g_cclosure_marshal_VOID__OBJECT,
+        G_TYPE_NONE, 1,
+        MIDORI_TYPE_APP);
+
     gobject_class = G_OBJECT_CLASS (class);
     gobject_class->finalize = midori_extension_finalize;
     gobject_class->set_property = midori_extension_set_property;