From: Christian Dywan Date: Thu, 14 Apr 2011 01:29:50 +0000 (+0200) Subject: Embed extensions into preferences dialogue X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed6ed712399a66b50197064ca5f5a68566f43f14;p=midori Embed extensions into preferences dialogue MidoriBrowser gains the show-preferences signal which gives API users a chance to add preferences. katze_preferences_add_category now returns a box to allow freely packing a widget into the page. The extension panel is packed into the preferences now rather than being appended as a proper panel. Motivation is consistency here, such as with Gedit or Emerillon and also the aspect that extensions often really do tweak behaviour like preferences do. Spacing and icons are added for visual consistency. --- diff --git a/katze/katze-preferences.c b/katze/katze-preferences.c index d8d513f9..e45d9f62 100644 --- a/katze/katze-preferences.c +++ b/katze/katze-preferences.c @@ -249,13 +249,21 @@ katze_preferences_prepare (KatzePreferences* preferences) * Adds a new category with the specified label to the dialog. * * Since: 0.2.1 + * + * Since 0.3.4 a #GtkBox is returned that can be packed into. **/ -void +GtkWidget* katze_preferences_add_category (KatzePreferences* preferences, const gchar* label, const gchar* icon) { - KatzePreferencesPrivate* priv = preferences->priv; + KatzePreferencesPrivate* priv; + + g_return_val_if_fail (KATZE_IS_PREFERENCES (preferences), NULL); + g_return_val_if_fail (label != NULL, NULL); + g_return_val_if_fail (icon != NULL, NULL); + + priv = preferences->priv; #if HAVE_HILDON GtkWidget* widget; @@ -300,6 +308,8 @@ katze_preferences_add_category (KatzePreferences* preferences, g_object_set_data (G_OBJECT (priv->toolbutton), "notebook", priv->notebook); #endif #endif + + return priv->page; } #if !HAVE_HILDON @@ -336,8 +346,12 @@ katze_preferences_add_group (KatzePreferences* preferences, const gchar* label) { #if !HAVE_HILDON - KatzePreferencesPrivate* priv = preferences->priv; + KatzePreferencesPrivate* priv; + g_return_if_fail (KATZE_IS_PREFERENCES (preferences)); + g_return_if_fail (label != NULL); + + priv = preferences->priv; priv->sizegroup2 = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); priv->frame = katze_hig_frame_new (label); gtk_container_set_border_width (GTK_CONTAINER (priv->frame), 4); diff --git a/katze/katze-preferences.h b/katze/katze-preferences.h index e957ebca..1424ac61 100644 --- a/katze/katze-preferences.h +++ b/katze/katze-preferences.h @@ -51,7 +51,7 @@ katze_preferences_get_type (void) G_GNUC_CONST; GtkWidget* katze_preferences_new (GtkWindow* parent); -void +GtkWidget* katze_preferences_add_category (KatzePreferences* preferences, const gchar* label, const gchar* icon); diff --git a/midori/main.c b/midori/main.c index 54087144..be99b4b8 100644 --- a/midori/main.c +++ b/midori/main.c @@ -694,6 +694,24 @@ midori_trash_remove_item_cb (KatzeArray* trash, g_free (config_file); } +static void +midori_browser_show_preferences_cb (MidoriBrowser* browser, + KatzePreferences* preferences, + MidoriApp* app) +{ + GtkWidget* scrolled = katze_scrolled_new (NULL, NULL); + GtkWidget* addon = g_object_new (MIDORI_TYPE_EXTENSIONS, NULL); + GList* children = gtk_container_get_children (GTK_CONTAINER (addon)); + GtkWidget* page; + gtk_widget_reparent (g_list_nth_data (children, 0), scrolled); + g_list_free (children); + g_object_set (addon, "app", app, NULL); + gtk_widget_show (scrolled); + page = katze_preferences_add_category (preferences, + _("Extensions"), STOCK_EXTENSIONS); + gtk_box_pack_start (GTK_BOX (page), scrolled, TRUE, TRUE, 4); +} + static void midori_app_add_browser_cb (MidoriApp* app, MidoriBrowser* browser, @@ -722,10 +740,8 @@ midori_app_add_browser_cb (MidoriApp* app, #endif /* Extensions */ - addon = g_object_new (MIDORI_TYPE_EXTENSIONS, NULL); - gtk_widget_show (addon); - g_object_set (addon, "app", app, NULL); - midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon)); + g_signal_connect (browser, "show-preferences", + G_CALLBACK (midori_browser_show_preferences_cb), app); g_object_unref (panel); } diff --git a/midori/midori-browser.c b/midori/midori-browser.c index e4863ebb..f51b9678 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -144,6 +144,7 @@ enum SEND_NOTIFICATION, POPULATE_TOOL_MENU, QUIT, + SHOW_PREFERENCES, LAST_SIGNAL }; @@ -1862,6 +1863,27 @@ midori_browser_class_init (MidoriBrowserClass* class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + /** + * MidoriBrowser::show-preferences: + * @browser: the object on which the signal is emitted + * @preferences: the #KatzePreferences to populate + * + * Emitted when a preference dialogue displayed, to allow + * adding of a new page, to be used sparingly. + * + * Since: 0.3.4 + */ + signals[SHOW_PREFERENCES] = g_signal_new ( + "show-preferences", + G_TYPE_FROM_CLASS (class), + (GSignalFlags)(G_SIGNAL_RUN_LAST), + 0, + 0, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + KATZE_TYPE_PREFERENCES); + class->add_tab = _midori_browser_add_tab; class->remove_tab = _midori_browser_remove_tab; class->activate_action = _midori_browser_activate_action; @@ -3056,6 +3078,7 @@ _action_preferences_activate (GtkAction* action, if (!dialog) { dialog = midori_preferences_new (GTK_WINDOW (browser), browser->settings); + g_signal_emit (browser, signals[SHOW_PREFERENCES], 0, dialog); g_signal_connect (dialog, "response", G_CALLBACK (midori_preferences_response_help_cb), browser); g_signal_connect (dialog, "destroy", diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c index 0a68de20..04e44769 100644 --- a/midori/midori-preferences.c +++ b/midori/midori-preferences.c @@ -16,6 +16,7 @@ #endif #include "sokoke.h" +#include "midori-stock.h" #include #include diff --git a/panels/midori-extensions.c b/panels/midori-extensions.c index e25d1c5c..834fd08c 100644 --- a/panels/midori-extensions.c +++ b/panels/midori-extensions.c @@ -221,11 +221,24 @@ midori_extensions_treeview_render_tick_cb (GtkTreeViewColumn* column, g_object_set (renderer, "activatable", midori_extension_is_prepared (extension), "active", midori_extension_is_active (extension) || g_object_get_data (G_OBJECT (extension), "static"), + "xpad", 4, NULL); g_object_unref (extension); } +static void +midori_extensions_treeview_render_icon_cb (GtkTreeViewColumn* column, + GtkCellRenderer* renderer, + GtkTreeModel* model, + GtkTreeIter* iter, + GtkWidget* treeview) +{ + g_object_set (renderer, "stock-id", STOCK_EXTENSION, + "stock-size", GTK_ICON_SIZE_BUTTON, + "xpad", 4, NULL); +} + static void midori_extensions_treeview_render_text_cb (GtkTreeViewColumn* column, GtkCellRenderer* renderer, @@ -338,6 +351,7 @@ midori_extensions_init (MidoriExtensions* extensions) { /* Create the treeview */ GtkTreeViewColumn* column; + GtkCellRenderer* renderer_icon; GtkCellRenderer* renderer_text; GtkCellRenderer* renderer_toggle; GtkListStore* liststore = gtk_list_store_new (1, G_TYPE_OBJECT); @@ -357,6 +371,13 @@ midori_extensions_init (MidoriExtensions* extensions) G_CALLBACK (midori_extensions_cell_renderer_toggled_cb), extensions); gtk_tree_view_append_column (GTK_TREE_VIEW (extensions->treeview), column); column = gtk_tree_view_column_new (); + renderer_icon = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (column, renderer_icon, FALSE); + gtk_tree_view_column_set_cell_data_func (column, renderer_icon, + (GtkTreeCellDataFunc)midori_extensions_treeview_render_icon_cb, + extensions->treeview, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (extensions->treeview), column); + column = gtk_tree_view_column_new (); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); renderer_text = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, renderer_text, FALSE);