From c78f775142d8b615556ce5da6d0434859dc09787 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 3 Dec 2008 23:57:37 +0100 Subject: [PATCH] Implement MidoriViewable in MidoriAddons --- midori/midori-addons.c | 58 ++++++++++++++++++++++++++++++++++++------ midori/midori-addons.h | 9 +++---- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/midori/midori-addons.c b/midori/midori-addons.c index b0d2c415..f73ff580 100644 --- a/midori/midori-addons.c +++ b/midori/midori-addons.c @@ -40,6 +40,11 @@ struct _MidoriAddons GSList* elements; }; +struct _MidoriAddonsClass +{ + GtkVBoxClass parent_class; +}; + struct AddonElement { gchar *fullpath; @@ -52,7 +57,12 @@ struct AddonElement GSList* excludes; }; -G_DEFINE_TYPE (MidoriAddons, midori_addons, GTK_TYPE_VBOX) +static void +midori_addons_viewable_iface_init (MidoriViewableIface* iface); + +G_DEFINE_TYPE_WITH_CODE (MidoriAddons, midori_addons, GTK_TYPE_VBOX, + G_IMPLEMENT_INTERFACE (MIDORI_TYPE_VIEWABLE, + midori_addons_viewable_iface_init)); enum { @@ -127,6 +137,36 @@ midori_addons_class_init (MidoriAddonsClass* class) G_PARAM_READWRITE)); } +static const gchar* +midori_addons_get_label (MidoriViewable* viewable) +{ + if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_SCRIPTS) + return _("Userscripts"); + else if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_SCRIPTS) + return _("Userstyles"); + else + return NULL; +} + +static const gchar* +midori_addons_get_stock_id (MidoriViewable* viewable) +{ + if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_SCRIPTS) + return STOCK_SCRIPTS; + else if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_STYLES) + return STOCK_STYLES; + else + return NULL; +} + +static void +midori_addons_viewable_iface_init (MidoriViewableIface* iface) +{ + iface->get_stock_id = midori_addons_get_stock_id; + iface->get_label = midori_addons_get_label; + iface->get_toolbar = midori_addons_get_toolbar; +} + static void midori_addons_set_property (GObject* object, guint prop_id, @@ -941,16 +981,18 @@ midori_addons_new (MidoriAddonKind kind, * is created on the first call of this function. * * Return value: a toolbar widget + * + * Deprecated: 0.1.2: Use midori_viewable_get_toolbar() instead. **/ GtkWidget* -midori_addons_get_toolbar (MidoriAddons* addons) +midori_addons_get_toolbar (MidoriViewable* addons) { GtkWidget* toolbar; GtkToolItem* toolitem; g_return_val_if_fail (MIDORI_IS_ADDONS (addons), NULL); - if (!addons->toolbar) + if (!MIDORI_ADDONS (addons)->toolbar) { toolbar = gtk_toolbar_new (); gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ); @@ -992,18 +1034,18 @@ midori_addons_get_toolbar (MidoriAddons* addons) G_CALLBACK (midori_addons_button_add_clicked_cb), addons); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); gtk_widget_show (GTK_WIDGET (toolitem)); - addons->toolbar = toolbar; + MIDORI_ADDONS (addons)->toolbar = toolbar; - g_signal_connect (addons->treeview, "cursor-changed", + g_signal_connect (MIDORI_ADDONS (addons)->treeview, "cursor-changed", G_CALLBACK (midori_addons_treeview_cursor_changed), addons); - g_signal_connect (addons->toolbar, "destroy", + g_signal_connect (toolbar, "destroy", G_CALLBACK (gtk_widget_destroyed), - &addons->toolbar); + &MIDORI_ADDONS (addons)->toolbar); } - return addons->toolbar; + return MIDORI_ADDONS (addons)->toolbar; } /** diff --git a/midori/midori-addons.h b/midori/midori-addons.h index 4503562b..662745ab 100644 --- a/midori/midori-addons.h +++ b/midori/midori-addons.h @@ -16,6 +16,8 @@ #include +#include "midori-viewable.h" + G_BEGIN_DECLS #define MIDORI_TYPE_ADDONS \ @@ -34,11 +36,6 @@ G_BEGIN_DECLS typedef struct _MidoriAddons MidoriAddons; typedef struct _MidoriAddonsClass MidoriAddonsClass; -struct _MidoriAddonsClass -{ - GtkVBoxClass parent_class; -}; - typedef enum { MIDORI_ADDON_NONE, @@ -60,7 +57,7 @@ midori_addons_new (MidoriAddonKind kind, GtkWidget* web_widget); GtkWidget* -midori_addons_get_toolbar (MidoriAddons* addons); +midori_addons_get_toolbar (MidoriViewable* addons); void midori_addons_update_elements (MidoriAddons* addons); -- 2.39.5