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.
This commit is contained in:
Christian Dywan 2011-04-14 03:29:50 +02:00
parent f01c4a472a
commit ed6ed71239
6 changed files with 83 additions and 8 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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",

View file

@ -16,6 +16,7 @@
#endif
#include "sokoke.h"
#include "midori-stock.h"
#include <string.h>
#include <glib/gi18n.h>

View file

@ -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);