]> spindle.queued.net Git - midori/commitdiff
Embed extensions into preferences dialogue
authorChristian Dywan <christian@twotoasts.de>
Thu, 14 Apr 2011 01:29:50 +0000 (03:29 +0200)
committerChristian Dywan <christian@twotoasts.de>
Thu, 14 Apr 2011 01:29:50 +0000 (03:29 +0200)
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.

katze/katze-preferences.c
katze/katze-preferences.h
midori/main.c
midori/midori-browser.c
midori/midori-preferences.c
panels/midori-extensions.c

index d8d513f9904891f225f63e394f276be593ff42e8..e45d9f62bb9bb5105d17f643d6eb6b5e5a27ffb5 100644 (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);
index e957ebcab2d29edda0ebbd68dd381caee560983c..1424ac61ae76c3214ddfd740b888c98783130eeb 100644 (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);
index 540871449b33324fdf14a3e8bfc562c7d9b3e398..be99b4b871097fd18be7101c6c2480b136be48cb 100644 (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);
 }
index e4863ebb297e8c81f2a34520ca4f38458db1c134..f51b96789fd15ce911d108a881ac8f43ceef7f27 100644 (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",
index 0a68de200fdb545198ff2717726f4c0df699f593..04e44769df276a2c683b4956112081c8870a6048 100644 (file)
@@ -16,6 +16,7 @@
 #endif
 
 #include "sokoke.h"
+#include "midori-stock.h"
 
 #include <string.h>
 #include <glib/gi18n.h>
index e25d1c5cf29371d00170bcebc809d6df33f9a234..834fd08c3ac655b64da64952964ac0d23354b7d6 100644 (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);