Change extension API to split initialization and activation
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.
This commit is contained in:
parent
dc59d66eb9
commit
72f39b0f82
6 changed files with 101 additions and 90 deletions
|
@ -12,7 +12,7 @@
|
||||||
#include <midori/midori.h>
|
#include <midori/midori.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
realign_tabs_app_add_browser_cb (MidoriApp* app,
|
statusbar_features_app_add_browser_cb (MidoriApp* app,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
GtkWidget* statusbar;
|
GtkWidget* statusbar;
|
||||||
|
@ -36,7 +36,16 @@ realign_tabs_app_add_browser_cb (MidoriApp* app,
|
||||||
gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
|
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,
|
MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
|
||||||
"name", "Statusbar Features",
|
"name", "Statusbar Features",
|
||||||
|
@ -45,8 +54,8 @@ MidoriExtension* extension_main (MidoriApp* app)
|
||||||
"authors", "Christian Dywan <christian@twotoasts.de>",
|
"authors", "Christian Dywan <christian@twotoasts.de>",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_signal_connect (app, "add-browser",
|
g_signal_connect (extension, "activate",
|
||||||
G_CALLBACK (realign_tabs_app_add_browser_cb), NULL);
|
G_CALLBACK (statusbar_features_activate_cb), NULL);
|
||||||
|
|
||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include <midori/midori.h>
|
#include <midori/midori.h>
|
||||||
|
|
||||||
void
|
static void
|
||||||
tab_panel_app_add_browser_cb (MidoriApp* app,
|
tab_panel_app_add_browser_cb (MidoriApp* app,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,16 @@ tab_panel_app_add_browser_cb (MidoriApp* app,
|
||||||
NULL, GTK_STOCK_INDEX, "Tab Panel");
|
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,
|
MidoriExtension* extension = g_object_new (TAB_PANEL_TYPE_EXTENSION,
|
||||||
"name", "Tab Panel",
|
"name", "Tab Panel",
|
||||||
|
@ -38,8 +47,8 @@ MidoriExtension* extension_main (MidoriApp* app)
|
||||||
"authors", "Christian Dywan <christian@twotoasts.de>",
|
"authors", "Christian Dywan <christian@twotoasts.de>",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_signal_connect (app, "add-browser",
|
g_signal_connect (extension, "activate",
|
||||||
G_CALLBACK (tab_panel_app_add_browser_cb), extension);
|
G_CALLBACK (tab_panel_activate_cb), NULL);
|
||||||
|
|
||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1291,18 +1291,14 @@ main (int argc,
|
||||||
G_CALLBACK (midori_history_clear_cb), db);
|
G_CALLBACK (midori_history_clear_cb), db);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_object_set (app, "settings", settings,
|
|
||||||
"bookmarks", bookmarks,
|
|
||||||
"trash", trash,
|
|
||||||
"search-engines", search_engines,
|
|
||||||
"history", history,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* Load extensions */
|
/* Load extensions */
|
||||||
|
KatzeArray* extensions;
|
||||||
gchar* extension_path;
|
gchar* extension_path;
|
||||||
GDir* extension_dir;
|
GDir* extension_dir;
|
||||||
const gchar* filename;
|
const gchar* filename;
|
||||||
|
MidoriExtension* extension;
|
||||||
|
|
||||||
|
extensions = katze_array_new (MIDORI_TYPE_EXTENSION);
|
||||||
extension_path = g_build_filename (LIBDIR, PACKAGE_NAME, NULL);
|
extension_path = g_build_filename (LIBDIR, PACKAGE_NAME, NULL);
|
||||||
if (g_module_supported ())
|
if (g_module_supported ())
|
||||||
extension_dir = g_dir_open (extension_path, 0, NULL);
|
extension_dir = g_dir_open (extension_path, 0, NULL);
|
||||||
|
@ -1314,8 +1310,8 @@ main (int argc,
|
||||||
{
|
{
|
||||||
gchar* fullname;
|
gchar* fullname;
|
||||||
GModule* module;
|
GModule* module;
|
||||||
typedef MidoriExtension* (*extension_main_func)(MidoriApp* app);
|
typedef MidoriExtension* (*extension_init_func)(void);
|
||||||
extension_main_func extension_main;
|
extension_init_func extension_init;
|
||||||
|
|
||||||
fullname = g_build_filename (extension_path, filename, NULL);
|
fullname = g_build_filename (extension_path, filename, NULL);
|
||||||
module = g_module_open (fullname, G_MODULE_BIND_LOCAL);
|
module = g_module_open (fullname, G_MODULE_BIND_LOCAL);
|
||||||
|
@ -1326,17 +1322,33 @@ main (int argc,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
if (!g_module_symbol (module, "extension_main",
|
if (!g_module_symbol (module, "extension_init",
|
||||||
(gpointer) &extension_main))
|
(gpointer) &extension_init))
|
||||||
{
|
{
|
||||||
g_warning ("%s", g_module_error ());
|
g_warning ("%s", g_module_error ());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
extension_main (app);
|
extension = extension_init ();
|
||||||
|
katze_array_add_item (extensions, extension);
|
||||||
}
|
}
|
||||||
g_dir_close (extension_dir);
|
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,
|
browser = g_object_new (MIDORI_TYPE_BROWSER,
|
||||||
"settings", settings,
|
"settings", settings,
|
||||||
"bookmarks", bookmarks,
|
"bookmarks", bookmarks,
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct _MidoriApp
|
||||||
KatzeArray* trash;
|
KatzeArray* trash;
|
||||||
KatzeArray* search_engines;
|
KatzeArray* search_engines;
|
||||||
KatzeArray* history;
|
KatzeArray* history;
|
||||||
|
KatzeArray* extensions;
|
||||||
|
|
||||||
gpointer instance;
|
gpointer instance;
|
||||||
};
|
};
|
||||||
|
@ -52,8 +53,9 @@ enum
|
||||||
PROP_BOOKMARKS,
|
PROP_BOOKMARKS,
|
||||||
PROP_TRASH,
|
PROP_TRASH,
|
||||||
PROP_SEARCH_ENGINES,
|
PROP_SEARCH_ENGINES,
|
||||||
PROP_BROWSER,
|
|
||||||
PROP_HISTORY,
|
PROP_HISTORY,
|
||||||
|
PROP_EXTENSIONS,
|
||||||
|
PROP_BROWSER,
|
||||||
PROP_BROWSER_COUNT
|
PROP_BROWSER_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -235,6 +237,24 @@ midori_app_class_init (MidoriAppClass* class)
|
||||||
KATZE_TYPE_ARRAY,
|
KATZE_TYPE_ARRAY,
|
||||||
G_PARAM_READWRITE));
|
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,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_BROWSER,
|
PROP_BROWSER,
|
||||||
g_param_spec_object (
|
g_param_spec_object (
|
||||||
|
@ -252,15 +272,6 @@ midori_app_class_init (MidoriAppClass* class)
|
||||||
"The current number of browsers",
|
"The current number of browsers",
|
||||||
0, G_MAXUINT, 0,
|
0, G_MAXUINT, 0,
|
||||||
G_PARAM_READABLE));
|
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*
|
static GObject*
|
||||||
|
@ -387,6 +398,7 @@ midori_app_init (MidoriApp* app)
|
||||||
app->trash = NULL;
|
app->trash = NULL;
|
||||||
app->search_engines = NULL;
|
app->search_engines = NULL;
|
||||||
app->history = NULL;
|
app->history = NULL;
|
||||||
|
app->extensions = NULL;
|
||||||
|
|
||||||
#if HAVE_UNIQUE
|
#if HAVE_UNIQUE
|
||||||
display_name = g_strdup (gdk_display_get_name (gdk_display_get_default ()));
|
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->trash, NULL);
|
||||||
katze_object_assign (app->search_engines, NULL);
|
katze_object_assign (app->search_engines, NULL);
|
||||||
katze_object_assign (app->history, NULL);
|
katze_object_assign (app->history, NULL);
|
||||||
|
katze_object_assign (app->extensions, NULL);
|
||||||
|
|
||||||
katze_object_assign (app->instance, 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));
|
katze_object_assign (app->history, g_value_dup_object (value));
|
||||||
/* FIXME: Propagate history to all browsers */
|
/* FIXME: Propagate history to all browsers */
|
||||||
break;
|
break;
|
||||||
|
case PROP_EXTENSIONS:
|
||||||
|
katze_object_assign (app->extensions, g_value_dup_object (value));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -485,6 +501,9 @@ midori_app_get_property (GObject* object,
|
||||||
case PROP_HISTORY:
|
case PROP_HISTORY:
|
||||||
g_value_set_object (value, app->history);
|
g_value_set_object (value, app->history);
|
||||||
break;
|
break;
|
||||||
|
case PROP_EXTENSIONS:
|
||||||
|
g_value_set_object (value, app->extensions);
|
||||||
|
break;
|
||||||
case PROP_BROWSER:
|
case PROP_BROWSER:
|
||||||
g_value_set_object (value, app->browser);
|
g_value_set_object (value, app->browser);
|
||||||
break;
|
break;
|
||||||
|
@ -654,55 +673,6 @@ midori_app_add_browser (MidoriApp* app,
|
||||||
g_signal_emit (app, signals[ADD_BROWSER], 0, browser);
|
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:
|
* midori_app_quit:
|
||||||
* @app: a #MidoriApp
|
* @app: a #MidoriApp
|
||||||
|
|
|
@ -70,16 +70,6 @@ void
|
||||||
midori_app_add_browser (MidoriApp* app,
|
midori_app_add_browser (MidoriApp* app,
|
||||||
MidoriBrowser* browser);
|
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
|
void
|
||||||
midori_app_quit (MidoriApp* app);
|
midori_app_quit (MidoriApp* app);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include "midori-extension.h"
|
#include "midori-extension.h"
|
||||||
|
|
||||||
|
#include "midori-app.h"
|
||||||
|
|
||||||
#include <katze/katze.h>
|
#include <katze/katze.h>
|
||||||
|
|
||||||
G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT);
|
G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT);
|
||||||
|
@ -33,6 +35,14 @@ enum
|
||||||
PROP_AUTHORS
|
PROP_AUTHORS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ACTIVATE,
|
||||||
|
|
||||||
|
LAST_SIGNAL
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[LAST_SIGNAL];
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_extension_finalize (GObject* object);
|
midori_extension_finalize (GObject* object);
|
||||||
|
|
||||||
|
@ -54,6 +64,17 @@ midori_extension_class_init (MidoriExtensionClass* class)
|
||||||
GObjectClass* gobject_class;
|
GObjectClass* gobject_class;
|
||||||
GParamFlags flags;
|
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 = G_OBJECT_CLASS (class);
|
||||||
gobject_class->finalize = midori_extension_finalize;
|
gobject_class->finalize = midori_extension_finalize;
|
||||||
gobject_class->set_property = midori_extension_set_property;
|
gobject_class->set_property = midori_extension_set_property;
|
||||||
|
|
Loading…
Reference in a new issue