From: Christian Dywan Date: Sun, 18 Oct 2009 20:06:24 +0000 (+0200) Subject: Refactor MidoriPreferences into KatzePreferences base class X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cef65324296160a6ef5c401f58a4bde263201fc9;p=midori Refactor MidoriPreferences into KatzePreferences base class The goal is to get rid of detailed table setups in favour of automatic alignment with few hints as well as abstracting away the exact layout to allow reimplementing it in a different form. --- diff --git a/katze/katze-preferences.c b/katze/katze-preferences.c new file mode 100644 index 00000000..4518731f --- /dev/null +++ b/katze/katze-preferences.c @@ -0,0 +1,360 @@ +/* + Copyright (C) 2007-2009 Christian Dywan + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#include "katze-preferences.h" + +#if HAVE_CONFIG_H + #include +#endif + +#define HAVE_HILDON 0 /* FIXME: Implement Hildonized version */ + +#include +#include + +struct _KatzePreferencesPrivate +{ + #if HAVE_HILDON + + #else + GtkWidget* notebook; + GtkWidget* toolbar; + GtkWidget* toolbutton; + GtkSizeGroup* sizegroup; + GtkSizeGroup* sizegroup2; + GtkWidget* page; + GtkWidget* frame; + GtkWidget* box; + GtkWidget* hbox; + #endif +}; + +G_DEFINE_TYPE (KatzePreferences, katze_preferences, GTK_TYPE_DIALOG); + +static void +katze_preferences_finalize (GObject* object); + +static void +katze_preferences_class_init (KatzePreferencesClass* class) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS (class); + gobject_class->finalize = katze_preferences_finalize; + + g_type_class_add_private (class, sizeof (KatzePreferencesPrivate)); +} + +static void +katze_preferences_response_cb (KatzePreferences* preferences, + gint response) +{ + if (response == GTK_RESPONSE_CLOSE) + gtk_widget_destroy (GTK_WIDGET (preferences)); +} + +static void +katze_preferences_init (KatzePreferences* preferences) +{ + KatzePreferencesPrivate* priv; + gchar* dialog_title; + + preferences->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE ((preferences), + KATZE_TYPE_PREFERENCES, KatzePreferencesPrivate); + + dialog_title = g_strdup_printf (_("Preferences for %s"), + g_get_application_name ()); + g_object_set (preferences, + "icon-name", GTK_STOCK_PREFERENCES, + "title", dialog_title, + "has-separator", FALSE, + NULL); + g_free (dialog_title); + + #if HAVE_HILDON + + #else + priv->notebook = gtk_notebook_new (); + gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 6); + + #if HAVE_OSX + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (preferences->notebook), FALSE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (preferences->notebook), FALSE); + priv->toolbar = gtk_toolbar_new (); + gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_BOTH); + gtk_toolbar_set_show_arrow (GTK_TOOLBAR (priv->toolbar), FALSE); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox), + priv->toolbar, FALSE, FALSE, 0); + #else + priv->toolbar = NULL; + #endif + priv->toolbutton = NULL; + gtk_box_pack_end (GTK_BOX (GTK_DIALOG (preferences)->vbox), + priv->notebook, FALSE, FALSE, 4); + + priv->sizegroup = NULL; + priv->sizegroup2 = NULL; + priv->page = NULL; + priv->frame = NULL; + priv->box = NULL; + priv->hbox = NULL; + #endif + + #if HAVE_OSX + GtkWidget* icon; + hbox = gtk_hbox_new (FALSE, 0); + button = gtk_button_new (); + icon = gtk_image_new_from_stock (GTK_STOCK_HELP, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button), icon); + g_signal_connect (button, "clicked", + G_CALLBACK (katze_preferences_help_clicked_cb), preferences); + gtk_box_pack_end (GTK_BOX (hbox), + button, FALSE, FALSE, 4); + gtk_box_pack_end (GTK_BOX (GTK_DIALOG (preferences)->vbox), + hbox, FALSE, FALSE, 0); + #endif + gtk_widget_show_all (GTK_DIALOG (preferences)->vbox); + + #if !HAVE_OSX + gtk_dialog_add_buttons (GTK_DIALOG (preferences), + GTK_STOCK_HELP, GTK_RESPONSE_HELP, + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + NULL); + #endif + g_object_connect (preferences, + "signal::response", katze_preferences_response_cb, NULL, + NULL); +} + +static void +katze_preferences_finalize (GObject* object) +{ + G_OBJECT_CLASS (katze_preferences_parent_class)->finalize (object); +} + +/** + * katze_preferences_new: + * @parent: the parent window, or %NULL + * + * Creates a new preferences dialog. + * + * Return value: a new #KatzePreferences + * + * Since: 0.2.1 + **/ +GtkWidget* +katze_preferences_new (GtkWindow* parent) +{ + KatzePreferences* preferences; + + g_return_val_if_fail (!parent || GTK_IS_WINDOW (parent), NULL); + + preferences = g_object_new (KATZE_TYPE_PREFERENCES, + "transient-for", parent, + NULL); + + return GTK_WIDGET (preferences); +} + +#if HAVE_OSX +static void +katze_preferences_help_clicked_cb (GtkWidget* button, + GtkDialog* dialog) +{ + gtk_dialog_response (dialog, GTK_RESPONSE_HELP); +} + +static void +katze_preferences_toolbutton_clicked_cb (GtkWidget* toolbutton, + GtkWidget* page) +{ + gpointer notebook = g_object_get_data (G_OBJECT (toolbutton), "notebook"); + guint n = gtk_notebook_page_num (notebook, page); + gtk_notebook_set_current_page (notebook, n); +} +#endif + +/** + * katze_preferences_add_category: + * @preferences: a #KatzePreferences instance + * @label: a category label + * @icon: an icon name + * + * Adds a new category with the specified label to the dialog. + * + * Since: 0.2.1 + **/ +void +katze_preferences_add_category (KatzePreferences* preferences, + const gchar* label, + const gchar* icon) +{ + KatzePreferencesPrivate* priv = preferences->priv; + + priv->page = gtk_vbox_new (FALSE, 0); + gtk_widget_show (priv->page); + #if HAVE_OSX + priv->toolbutton = GTK_WIDGET (priv->toolbutton ? + gtk_radio_tool_button_new_from_widget ( + GTK_RADIO_TOOL_BUTTON (priv->toolbutton)) + : gtk_radio_tool_button_new (NULL)); + gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->toolbutton), label); + gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (priv->toolbutton), icon); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (priv->toolbutton), -1); + g_signal_connect (priv->toolbutton, "clicked", + G_CALLBACK (katze_preferences_toolbutton_clicked_cb), page); + if (priv->toolbutton) + g_object_set_data (G_OBJECT (priv->toolbutton), "notebook", priv->notebook); + #endif + gtk_container_set_border_width (GTK_CONTAINER (priv->page), 4); + gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), + priv->page, gtk_label_new (label)); +} + +static GtkWidget* +katze_hig_frame_new (const gchar* title) +{ + /* Create a frame with no actual frame but a bold label and indentation */ + GtkWidget* frame = gtk_frame_new (NULL); + #ifdef G_OS_WIN32 + gtk_frame_set_label (GTK_FRAME (frame), title); + #else + gchar* title_bold = g_strdup_printf ("%s", title); + GtkWidget* label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), title_bold); + g_free (title_bold); + gtk_frame_set_label_widget (GTK_FRAME (frame), label); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + #endif + return frame; +} + +/** + * katze_preferences_add_group: + * @preferences: a #KatzePreferences instance + * @label: a group label + * + * Adds a new group with the specified label to the dialog. + * + * Since: 0.2.1 + **/ +void +katze_preferences_add_group (KatzePreferences* preferences, + const gchar* label) +{ + KatzePreferencesPrivate* priv = preferences->priv; + + priv->sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + 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); + gtk_box_pack_start (GTK_BOX (priv->page), priv->frame, FALSE, FALSE, 0); + priv->box = gtk_vbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (priv->box), 4); + gtk_container_add (GTK_CONTAINER (priv->frame), priv->box); + gtk_widget_show_all (priv->frame); +} + +/** + * katze_preferences_add_widget: + * @preferences: a #KatzePreferences instance + * @widget: a widget representing an option + * @type: "filled", "indented", or "spanned" + * + * Adds a widget to the dialog. + * + * Since: 0.2.1 + **/ +void +katze_preferences_add_widget (KatzePreferences* preferences, + GtkWidget* widget, + const gchar* type) +{ + KatzePreferencesPrivate* priv; + const gchar* _type; + + g_return_if_fail (KATZE_IS_PREFERENCES (preferences)); + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (type != NULL); + + priv = preferences->priv; + _type = g_intern_string (type); + + /* Showing implicitly widget and children is not the best idea, + but lots of repeated function calls aren't either. */ + gtk_widget_show_all (widget); + + if (_type != g_intern_static_string ("spanned")) + { + priv->hbox = gtk_hbox_new (FALSE, 4); + gtk_widget_show (priv->hbox); + gtk_box_pack_start (GTK_BOX (priv->hbox), widget, TRUE, FALSE, 0); + } + + if (_type == g_intern_static_string ("filled")) + gtk_box_pack_start (GTK_BOX (priv->box), priv->hbox, TRUE, FALSE, 0); + else if (_type == g_intern_static_string ("indented")) + { + GtkWidget* align = gtk_alignment_new (0, 0.5, 0, 0); + gtk_widget_show (align); + gtk_container_add (GTK_CONTAINER (align), priv->hbox); + if (!GTK_IS_SPIN_BUTTON (widget)) + gtk_size_group_add_widget (priv->sizegroup, widget); + gtk_box_pack_start (GTK_BOX (priv->box), align, TRUE, FALSE, 0); + } + else if (_type == g_intern_static_string ("spanned")) + { + GtkWidget* align = gtk_alignment_new (0, 0.5, 0, 0); + gtk_widget_show (align); + gtk_container_add (GTK_CONTAINER (align), widget); + if (!GTK_IS_LABEL (widget) && !GTK_IS_SPIN_BUTTON (widget) + && !(GTK_IS_BUTTON (widget) && !GTK_IS_TOGGLE_BUTTON (widget))) + gtk_size_group_add_widget (priv->sizegroup2, widget); + gtk_box_pack_start (GTK_BOX (priv->hbox), align, TRUE, FALSE, 0); + } +} + +/** + * katze_preferences_add_option: + * @preferences: a #KatzePreferences instance + * @object: the object to proxy + * @property: the property to proxy + * @label: a label, or %NULL + * @widget: a widget representing an option + * @type: "filled", "indented", or "spanned" + * + * Adds an option to the dialog, with a label. + * + * If @label is %NULL, it will be filled in from the property. + * + * Since: 0.2.1 + **/ +void +katze_preferences_add_option (KatzePreferences* preferences, + gpointer object, + const gchar* property, + const gchar* label, + GtkWidget* widget, + const gchar* type) +{ + g_return_if_fail (KATZE_IS_PREFERENCES (preferences)); + g_return_if_fail (G_IS_OBJECT (object)); + g_return_if_fail (property != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (type != NULL); + + if (label) + katze_preferences_add_widget (preferences, + gtk_label_new_with_mnemonic (label), "indented"); + else + katze_preferences_add_widget (preferences, + katze_property_label (object, property), "indented"); + katze_preferences_add_widget (preferences, widget, type); +} diff --git a/katze/katze-preferences.h b/katze/katze-preferences.h new file mode 100644 index 00000000..39e46d41 --- /dev/null +++ b/katze/katze-preferences.h @@ -0,0 +1,78 @@ +/* + Copyright (C) 2008-2009 Christian Dywan + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See the file COPYING for the full license text. +*/ + +#ifndef __KATZE_PREFERENCES_H__ +#define __KATZE_PREFERENCES_H__ + +#include "katze-utils.h" + +G_BEGIN_DECLS + +#define KATZE_TYPE_PREFERENCES \ + (katze_preferences_get_type ()) +#define KATZE_PREFERENCES(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), KATZE_TYPE_PREFERENCES, KatzePreferences)) +#define KATZE_PREFERENCES_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), KATZE_TYPE_PREFERENCES, KatzePreferencesClass)) +#define KATZE_IS_PREFERENCES(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KATZE_TYPE_PREFERENCES)) +#define KATZE_IS_PREFERENCES_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), KATZE_TYPE_PREFERENCES)) +#define KATZE_PREFERENCES_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), KATZE_TYPE_PREFERENCES, KatzePreferencesClass)) + +typedef struct _KatzePreferences KatzePreferences; +typedef struct _KatzePreferencesClass KatzePreferencesClass; +typedef struct _KatzePreferencesPrivate KatzePreferencesPrivate; + +struct _KatzePreferences +{ + GtkDialog parent_instance; + + KatzePreferencesPrivate* priv; +}; + +struct _KatzePreferencesClass +{ + GtkDialogClass parent_class; +}; + +GType +katze_preferences_get_type (void); + +GtkWidget* +katze_preferences_new (GtkWindow* parent); + +void +katze_preferences_add_category (KatzePreferences* preferences, + const gchar* label, + const gchar* icon); + +void +katze_preferences_add_group (KatzePreferences* preferences, + const gchar* label); + +void +katze_preferences_add_widget (KatzePreferences* preferences, + GtkWidget* widget, + const gchar* type); + +void +katze_preferences_add_option (KatzePreferences* preferences, + gpointer object, + const gchar* property, + const gchar* label, + GtkWidget* widget, + const gchar* type); + +G_END_DECLS + +#endif /* __KATZE_PREFERENCES_H__ */ diff --git a/katze/katze-utils.c b/katze/katze-utils.c index 1ac9ad48..d5b55aea 100644 --- a/katze/katze-utils.c +++ b/katze/katze-utils.c @@ -553,6 +553,7 @@ katze_property_label (gpointer object, } nick = g_param_spec_get_nick (pspec); widget = gtk_label_new (nick); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); return widget; } diff --git a/katze/katze.h b/katze/katze.h index ab85d27b..367fd447 100644 --- a/katze/katze.h +++ b/katze/katze.h @@ -22,5 +22,6 @@ #include "katze-separatoraction.h" #include "katze-net.h" #include "katze-scrolled.h" +#include "katze-preferences.h" #endif /* __KATZE_H__ */ diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c index 36009286..f39d8406 100644 --- a/midori/midori-preferences.c +++ b/midori/midori-preferences.c @@ -24,13 +24,10 @@ struct _MidoriPreferences { - GtkDialog parent_instance; - - MidoriWebSettings* settings; - GtkWidget* notebook; + KatzePreferences parent_instance; }; -G_DEFINE_TYPE (MidoriPreferences, midori_preferences, GTK_TYPE_DIALOG) +G_DEFINE_TYPE (MidoriPreferences, midori_preferences, KATZE_TYPE_PREFERENCES); enum { @@ -62,6 +59,13 @@ midori_preferences_class_init (MidoriPreferencesClass* class) gobject_class->set_property = midori_preferences_set_property; gobject_class->get_property = midori_preferences_get_property; + /** + * MidoriPreferences:settings: + * + * The settings to proxy properties from. + * + * Since 0.2.1 the property is only writable. + */ g_object_class_install_property (gobject_class, PROP_SETTINGS, g_param_spec_object ( @@ -69,7 +73,7 @@ midori_preferences_class_init (MidoriPreferencesClass* class) "Settings", "Settings instance to provide properties", MIDORI_TYPE_WEB_SETTINGS, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)); } static void @@ -83,27 +87,7 @@ midori_preferences_response_cb (MidoriPreferences* preferences, static void midori_preferences_init (MidoriPreferences* preferences) { - gchar* dialog_title; - - preferences->settings = NULL; - preferences->notebook = NULL; - - dialog_title = g_strdup_printf (_("Preferences for %s"), - g_get_application_name ()); - g_object_set (preferences, - "icon-name", GTK_STOCK_PREFERENCES, - "title", dialog_title, - "has-separator", FALSE, - NULL); - g_free (dialog_title); - #if !HAVE_OSX - gtk_dialog_add_buttons (GTK_DIALOG (preferences), - GTK_STOCK_HELP, GTK_RESPONSE_HELP, - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); - #endif - g_signal_connect (preferences, "response", - G_CALLBACK (midori_preferences_response_cb), NULL); + /* Nothing to do */ } static void @@ -142,9 +126,6 @@ midori_preferences_get_property (GObject* object, switch (prop_id) { - case PROP_SETTINGS: - g_value_set_object (value, preferences->settings); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -307,112 +288,72 @@ midori_preferences_add_toolbutton (GtkWidget* toolbar, * Note: This must not be called more than once. * * Since 0.1.2 this is equal to setting #MidoriPreferences:settings:. + * + * Since 0.2.1 this can be called multiple times. **/ void midori_preferences_set_settings (MidoriPreferences* preferences, MidoriWebSettings* settings) { + GList* children; + GtkWidget* notebook; GtkWidget* header; GtkWindow* parent; const gchar* icon_name; #if WEBKIT_CHECK_VERSION (1, 1, 15) GtkSettings* gtk_settings; #endif - GtkSizeGroup* sizegroup; - GtkWidget* toolbar; - GtkWidget* toolbutton; - GtkWidget* page; - GtkWidget* frame; - GtkWidget* table; - GtkWidget* align; + KatzePreferences* _preferences; GtkWidget* label; GtkWidget* button; GtkWidget* entry; - GtkWidget* hbox; gint icon_width, icon_height; g_return_if_fail (MIDORI_IS_PREFERENCES (preferences)); g_return_if_fail (MIDORI_IS_WEB_SETTINGS (settings)); - g_return_if_fail (!preferences->notebook); - - katze_assign (preferences->settings, g_object_ref (settings)); + children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (preferences)->vbox)); + notebook = g_list_nth_data (children, 0); + g_list_free (children); + gtk_container_foreach (GTK_CONTAINER (notebook), + (GtkCallback)gtk_widget_destroy, NULL); g_object_get (preferences, "transient-for", &parent, NULL); icon_name = parent ? gtk_window_get_icon_name (parent) : NULL; if ((header = sokoke_xfce_header_new (icon_name, gtk_window_get_title (GTK_WINDOW (preferences))))) + { gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox), header, FALSE, FALSE, 0); + gtk_widget_show_all (header); + } #if WEBKIT_CHECK_VERSION (1, 1, 15) - gtk_settings = parent ? gtk_widget_get_settings (GTK_WIDGET (parent)) : NULL; + gtk_settings = parent ? + gtk_widget_get_settings (GTK_WIDGET (parent)) : gtk_settings_get_default (); #endif + _preferences = KATZE_PREFERENCES (preferences); - preferences->notebook = gtk_notebook_new (); - gtk_container_set_border_width (GTK_CONTAINER (preferences->notebook), 6); - - #if HAVE_OSX - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (preferences->notebook), FALSE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (preferences->notebook), FALSE); - toolbar = gtk_toolbar_new (); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH); - gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox), - toolbar, FALSE, FALSE, 0); - #else - toolbar = NULL; - #endif - toolbutton = NULL; - - sizegroup = NULL; #define PAGE_NEW(__icon, __label) \ - page = gtk_vbox_new (FALSE, 0); \ - midori_preferences_add_toolbutton (toolbar, &toolbutton, \ - __icon, __label, page); \ - if (toolbutton) g_object_set_data (G_OBJECT (toolbutton), \ - "notebook", preferences->notebook); \ - if (sizegroup) g_object_unref (sizegroup); \ - sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); \ - gtk_container_set_border_width (GTK_CONTAINER (page), 4); \ - gtk_notebook_append_page (GTK_NOTEBOOK (preferences->notebook), page, \ - gtk_label_new (__label)) - #define FRAME_NEW(__label) frame = sokoke_hig_frame_new (__label); \ - gtk_container_set_border_width (GTK_CONTAINER (frame), 4); \ - gtk_box_pack_start (GTK_BOX (page), frame, FALSE, FALSE, 0); - #define TABLE_NEW(__rows, __cols) table = gtk_table_new ( \ - __rows, __cols, FALSE); \ - gtk_container_set_border_width (GTK_CONTAINER (table), 4); \ - gtk_container_add (GTK_CONTAINER (frame), table); - #define WIDGET_ADD(__widget, __left, __right, __top, __bottom) \ - gtk_table_attach (GTK_TABLE (table), __widget \ - , __left, __right, __top, __bottom \ - , GTK_FILL, GTK_FILL, 8, 2) - #define FILLED_ADD(__widget, __left, __right, __top, __bottom) \ - gtk_table_attach (GTK_TABLE (table), __widget \ - , __left, __right, __top, __bottom\ - , GTK_EXPAND | GTK_FILL, GTK_FILL, 8, 2) - #define INDENTED_ADD(__widget, __left, __right, __top, __bottom) \ - align = gtk_alignment_new (0, 0.5, 0, 0); \ - gtk_container_add (GTK_CONTAINER (align), __widget); \ - gtk_size_group_add_widget (sizegroup, align); \ - WIDGET_ADD (align, __left, __right, __top, __bottom) - #define SPANNED_ADD(__widget, __left, __right, __top, __bottom) \ - align = gtk_alignment_new (0, 0.5, 0, 0); \ - gtk_container_add (GTK_CONTAINER (align), __widget); \ - FILLED_ADD (align, __left, __right, __top, __bottom) + katze_preferences_add_category (_preferences, __label, __icon) + #define FRAME_NEW(__label) \ + katze_preferences_add_group (_preferences, __label) + #define FILLED_ADD(__widget) \ + katze_preferences_add_widget (_preferences, __widget, "filled") + #define INDENTED_ADD(__widget) \ + katze_preferences_add_widget (_preferences, __widget, "indented") + #define SPANNED_ADD(__widget) \ + katze_preferences_add_widget (_preferences, __widget, "spanned") /* Page "General" */ PAGE_NEW (GTK_STOCK_HOME, _("General")); FRAME_NEW (_("Startup")); - TABLE_NEW (3, 2); label = katze_property_label (settings, "load-on-startup"); - INDENTED_ADD (label, 0, 1, 0, 1); + INDENTED_ADD (label); button = katze_property_proxy (settings, "load-on-startup", NULL); - FILLED_ADD (button, 1, 2, 0, 1); + SPANNED_ADD (button); label = katze_property_label (settings, "homepage"); - INDENTED_ADD (label, 0, 1, 1, 2); - hbox = gtk_hbox_new (FALSE, 4); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "homepage", NULL); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + SPANNED_ADD (entry); if (parent && katze_object_has_property (parent, "uri")) { button = gtk_button_new (); @@ -421,77 +362,66 @@ midori_preferences_set_settings (MidoriPreferences* preferences, gtk_widget_set_tooltip_text (button, _("Use current page as homepage")); g_signal_connect (button, "clicked", G_CALLBACK (midori_preferences_homepage_current_clicked_cb), settings); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + SPANNED_ADD (button); } - FILLED_ADD (hbox, 1, 2, 1, 2); button = katze_property_proxy (settings, "show-crash-dialog", NULL); - INDENTED_ADD (button, 0, 1, 2, 3); + INDENTED_ADD (button); button = katze_property_proxy (settings, "speed-dial-in-new-tabs", NULL); - FILLED_ADD (button, 1, 2, 2, 3); + SPANNED_ADD (button); FRAME_NEW (_("Transfers")); - TABLE_NEW (2, 2); label = katze_property_label (settings, "download-folder"); - INDENTED_ADD (label, 0, 1, 0, 1); + INDENTED_ADD (label); button = katze_property_proxy (settings, "download-folder", "folder"); - FILLED_ADD (button, 1, 2, 0, 1); + SPANNED_ADD (button); label = katze_property_proxy (settings, "ask-for-destination-folder", NULL); - INDENTED_ADD (label, 0, 1, 1, 2); + INDENTED_ADD (label); button = katze_property_proxy (settings, "notify-transfer-completed", NULL); /* FIXME: Disable the option if notifications presumably cannot be sent gtk_widget_set_sensitive (button, FALSE); */ - SPANNED_ADD (button, 1, 2, 1, 2); + SPANNED_ADD (button); /* Page "Appearance" */ PAGE_NEW (GTK_STOCK_SELECT_FONT, _("Appearance")); FRAME_NEW (_("Font settings")); - TABLE_NEW (7, 2); label = gtk_label_new (_("Default Font Family")); - INDENTED_ADD (label, 0, 1, 0, 1); - hbox = gtk_hbox_new (FALSE, 4); + INDENTED_ADD (label); button = katze_property_proxy (settings, "default-font-family", "font"); gtk_widget_set_tooltip_text (button, _("The default font family used to display text")); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + SPANNED_ADD (button); entry = katze_property_proxy (settings, "default-font-size", NULL); gtk_widget_set_tooltip_text (entry, _("The default font size used to display text")); - gtk_box_pack_end (GTK_BOX (hbox), entry, FALSE, FALSE, 4); - FILLED_ADD (hbox, 1, 2, 0, 1); + SPANNED_ADD (entry); label = gtk_label_new (_("Fixed-width Font Family")); - INDENTED_ADD (label, 0, 1, 1, 2); - hbox = gtk_hbox_new (FALSE, 4); + INDENTED_ADD (label); button = katze_property_proxy (settings, "monospace-font-family", "font-monospace"); gtk_widget_set_tooltip_text (button, _("The font family used to display fixed-width text")); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + SPANNED_ADD (button); entry = katze_property_proxy (settings, "default-monospace-font-size", NULL); gtk_widget_set_tooltip_text (entry, _("The font size used to display fixed-width text")); - gtk_box_pack_end (GTK_BOX (hbox), entry, FALSE, FALSE, 4); - INDENTED_ADD (hbox, 1, 2, 1, 2); + SPANNED_ADD (entry); label = gtk_label_new (_("Minimum Font Size")); - INDENTED_ADD (label, 0, 1, 2, 3); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "minimum-font-size", NULL); gtk_widget_set_tooltip_text (entry, _("The minimum font size used to display text")); - INDENTED_ADD (entry, 1, 2, 2, 3); + SPANNED_ADD (entry); label = katze_property_label (settings, "preferred-encoding"); - INDENTED_ADD (label, 0, 1, 3, 4); + INDENTED_ADD (label); button = katze_property_proxy (settings, "preferred-encoding", NULL); - FILLED_ADD (button, 1, 2, 3, 4); - label = katze_property_label (settings, "default-encoding"); - gtk_label_set_label (GTK_LABEL (label), _("Encoding")); - INDENTED_ADD (label, 0, 1, 4, 5); + SPANNED_ADD (button); entry = katze_property_proxy (settings, "default-encoding", NULL); gtk_widget_set_tooltip_text (entry, _("The character encoding to use by default")); g_signal_connect (settings, "notify::preferred-encoding", G_CALLBACK (midori_preferences_notify_preferred_encoding_cb), entry); midori_preferences_notify_preferred_encoding_cb (settings, NULL, entry); - FILLED_ADD (entry, 1, 2, 4, 5); + SPANNED_ADD (entry); /* Page "Behavior" */ PAGE_NEW (GTK_STOCK_SELECT_COLOR, _("Behavior")); FRAME_NEW (_("Features")); - TABLE_NEW (6, 2); button = katze_property_proxy (settings, "auto-load-images", NULL); gtk_button_set_label (GTK_BUTTON (button), _("Load images automatically")); gtk_widget_set_tooltip_text (button, _("Load and display images automatically")); - INDENTED_ADD (button, 0, 1, 0, 1); + INDENTED_ADD (button); #if WEBKIT_CHECK_VERSION (1, 1, 15) if (katze_object_get_boolean (gtk_settings, "gtk-touchscreen-mode")) button = katze_property_proxy (settings, "kinetic-scrolling", NULL); @@ -504,195 +434,137 @@ midori_preferences_set_settings (MidoriPreferences* preferences, #else button = katze_property_proxy (settings, "middle-click-opens-selection", NULL); #endif - SPANNED_ADD (button, 1, 2, 0, 1); + SPANNED_ADD (button); button = katze_property_proxy (settings, "enable-scripts", NULL); gtk_button_set_label (GTK_BUTTON (button), _("Enable scripts")); gtk_widget_set_tooltip_text (button, _("Enable embedded scripting languages")); - INDENTED_ADD (button, 0, 1, 2, 3); + INDENTED_ADD (button); button = katze_property_proxy (settings, "enable-plugins", NULL); gtk_button_set_label (GTK_BUTTON (button), _("Enable Netscape plugins")); gtk_widget_set_tooltip_text (button, _("Enable embedded Netscape plugin objects")); - SPANNED_ADD (button, 1, 2, 2, 3); + SPANNED_ADD (button); button = katze_property_proxy (settings, "enforce-96-dpi", NULL); gtk_button_set_label (GTK_BUTTON (button), _("Enforce 96 dots per inch")); gtk_widget_set_tooltip_text (button, _("Enforce a video dot density of 96 DPI")); - SPANNED_ADD (button, 0, 1, 3, 4); + INDENTED_ADD (button); button = katze_property_proxy (settings, "enable-developer-extras", NULL); gtk_button_set_label (GTK_BUTTON (button), _("Enable developer tools")); gtk_widget_set_tooltip_text (button, _("Enable special extensions for developers")); - SPANNED_ADD (button, 1, 2, 3, 4); + SPANNED_ADD (button); button = katze_property_proxy (settings, "zoom-text-and-images", NULL); - SPANNED_ADD (button, 0, 1, 4, 5); + INDENTED_ADD (button); button = katze_property_proxy (settings, "find-while-typing", NULL); - SPANNED_ADD (button, 1, 2, 4, 5); + SPANNED_ADD (button); #if WEBKIT_CHECK_VERSION (1, 1, 6) FRAME_NEW (_("Spell Checking")); - TABLE_NEW (1, 2); button = katze_property_proxy (settings, "enable-spell-checking", NULL); gtk_button_set_label (GTK_BUTTON (button), _("Enable Spell Checking")); gtk_widget_set_tooltip_text (button, _("Enable spell checking while typing")); - INDENTED_ADD (button, 0, 1, 0, 1); + INDENTED_ADD (button); entry = katze_property_proxy (settings, "spell-checking-languages", NULL); /* i18n: The example should be adjusted to contain a good local default */ gtk_widget_set_tooltip_text (entry, _("A comma separated list of languages to be used for spell checking, for example \"en_GB,de_DE\"")); - FILLED_ADD (entry, 1, 2, 0, 1); + SPANNED_ADD (entry); #endif /* Page "Interface" */ PAGE_NEW (GTK_STOCK_CONVERT, _("Interface")); FRAME_NEW (_("Navigationbar")); - TABLE_NEW (2, 2); #if !HAVE_HILDON - INDENTED_ADD (katze_property_label (settings, "toolbar-style"), 0, 1, 0, 1); + INDENTED_ADD (katze_property_label (settings, "toolbar-style")); button = katze_property_proxy (settings, "toolbar-style", NULL); - FILLED_ADD (button, 1, 2, 0, 1); + SPANNED_ADD (button); #endif button = katze_property_proxy (settings, "progress-in-location", NULL); - FILLED_ADD (button, 0, 1, 1, 2); + INDENTED_ADD (button); button = katze_property_proxy (settings, "search-engines-in-completion", NULL); - FILLED_ADD (button, 1, 2, 1, 2); + SPANNED_ADD (button); FRAME_NEW (_("Browsing")); - TABLE_NEW (5, 2); - hbox = gtk_hbox_new (FALSE, 4); label = katze_property_label (settings, "open-new-pages-in"); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4); + INDENTED_ADD (label); button = katze_property_proxy (settings, "open-new-pages-in", NULL); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4); - INDENTED_ADD (hbox, 0, 1, 0, 1); - hbox = gtk_hbox_new (FALSE, 4); + SPANNED_ADD (button); label = katze_property_label (settings, "open-external-pages-in"); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4); + INDENTED_ADD (label); button = katze_property_proxy (settings, "open-external-pages-in", NULL); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4); - FILLED_ADD (hbox, 1, 2, 0, 1); + SPANNED_ADD (button); button = katze_property_proxy (settings, "always-show-tabbar", NULL); - INDENTED_ADD (button, 0, 1, 2, 3); + INDENTED_ADD (button); button = katze_property_proxy (settings, "open-tabs-in-the-background", NULL); - INDENTED_ADD (button, 1, 2, 2, 3); + SPANNED_ADD (button); button = katze_property_proxy (settings, "open-tabs-next-to-current", NULL); - WIDGET_ADD (button, 0, 1, 5, 6); + INDENTED_ADD (button); button = katze_property_proxy (settings, "close-buttons-on-tabs", NULL); - WIDGET_ADD (button, 1, 2, 5, 6); + SPANNED_ADD (button); /* Page "Applications" */ PAGE_NEW (GTK_STOCK_CONVERT, _("Applications")); FRAME_NEW (_("External applications")); - TABLE_NEW (3, 2); label = katze_property_label (settings, "text-editor"); - INDENTED_ADD (label, 0, 1, 0, 1); - hbox = gtk_hbox_new (FALSE, 4); - button = gtk_image_new (); - gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button), - GTK_ICON_SIZE_MENU, &icon_width, &icon_height); - gtk_widget_set_size_request (button, icon_width, icon_height); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "text-editor", "application-text/plain"); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - FILLED_ADD (hbox, 1, 2, 0, 1); + SPANNED_ADD (entry); label = katze_property_label (settings, "download-manager"); - INDENTED_ADD (label, 0, 1, 1, 2); - hbox = gtk_hbox_new (FALSE, 4); - button = gtk_image_new (); - gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button), - GTK_ICON_SIZE_MENU, &icon_width, &icon_height); - gtk_widget_set_size_request (button, icon_width, icon_height); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "download-manager", "application-Network"); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - FILLED_ADD (hbox, 1, 2, 1, 2); + SPANNED_ADD (entry); label = katze_property_label (settings, "news-aggregator"); - INDENTED_ADD (label, 0, 1, 2, 3); - hbox = gtk_hbox_new (FALSE, 4); - button = gtk_image_new (); - gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button), - GTK_ICON_SIZE_MENU, &icon_width, &icon_height); - gtk_widget_set_size_request (button, icon_width, icon_height); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "news-aggregator", "application-Network"); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - FILLED_ADD (hbox, 1, 2, 2, 3); + SPANNED_ADD (entry); /* Page "Network" */ PAGE_NEW (GTK_STOCK_NETWORK, _("Network")); FRAME_NEW (_("Network")); - TABLE_NEW (5, 2); label = katze_property_label (settings, "http-proxy"); - INDENTED_ADD (label, 0, 1, 0, 1); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "http-proxy", NULL); - FILLED_ADD (entry, 1, 2, 0, 1); + SPANNED_ADD (entry); button = katze_property_proxy (settings, "auto-detect-proxy", NULL); - FILLED_ADD (button, 1, 2, 1, 2); + FILLED_ADD (button); g_signal_connect (settings, "notify::auto-detect-proxy", G_CALLBACK (midori_preferences_notify_auto_detect_proxy_cb), entry); midori_preferences_notify_auto_detect_proxy_cb (settings, NULL, entry); label = katze_property_label (settings, "identify-as"); - INDENTED_ADD (label, 0, 1, 2, 3); + INDENTED_ADD (label); button = katze_property_proxy (settings, "identify-as", NULL); - FILLED_ADD (button, 1, 2, 2, 3); - label = katze_property_label (settings, "ident-string"); - INDENTED_ADD (label, 0, 1, 3, 4); + SPANNED_ADD (button); entry = katze_property_proxy (settings, "ident-string", NULL); g_signal_connect (settings, "notify::identify-as", G_CALLBACK (midori_preferences_notify_identify_as_cb), entry); midori_preferences_notify_identify_as_cb (settings, NULL, entry); - FILLED_ADD (entry, 1, 2, 3, 4); + SPANNED_ADD (entry); label = katze_property_label (settings, "cache-size"); - INDENTED_ADD (label, 0, 1, 4, 5); - hbox = gtk_hbox_new (FALSE, 4); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "cache-size", NULL); - gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("MB")), - FALSE, FALSE, 0); - FILLED_ADD (hbox, 1, 2, 4, 5); + SPANNED_ADD (entry); + label = gtk_label_new (_("MB")); + SPANNED_ADD (label); /* Page "Privacy" */ PAGE_NEW (GTK_STOCK_INDEX, _("Privacy")); FRAME_NEW (_("Web Cookies")); - TABLE_NEW (3, 2); label = katze_property_label (settings, "accept-cookies"); - INDENTED_ADD (label, 0, 1, 0, 1); + INDENTED_ADD (label); button = katze_property_proxy (settings, "accept-cookies", NULL); - FILLED_ADD (button, 1, 2, 0, 1); + SPANNED_ADD (button); button = katze_property_proxy (settings, "original-cookies-only", NULL); - SPANNED_ADD (button, 0, 1, 1, 2); - hbox = gtk_hbox_new (FALSE, 4); + INDENTED_ADD (button); label = katze_property_label (settings, "maximum-cookie-age"); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + INDENTED_ADD (label); entry = katze_property_proxy (settings, "maximum-cookie-age", NULL); - gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("days")), - FALSE, FALSE, 0); - FILLED_ADD (hbox, 1, 2, 1, 2); + SPANNED_ADD (entry); + label = gtk_label_new (_("days")); + SPANNED_ADD (label); FRAME_NEW (_("History")); - TABLE_NEW (3, 2); button = katze_property_proxy (settings, "remember-last-visited-pages", NULL); - SPANNED_ADD (button, 0, 1, 0, 1); - hbox = gtk_hbox_new (FALSE, 4); + INDENTED_ADD (button); button = katze_property_proxy (settings, "maximum-history-age", NULL); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("days")), - FALSE, FALSE, 0); - SPANNED_ADD (hbox, 1, 2, 0, 1); + SPANNED_ADD (button); + label = gtk_label_new (_("days")); + SPANNED_ADD (label); button = katze_property_proxy (settings, "remember-last-form-inputs", NULL); - SPANNED_ADD (button, 0, 2, 1, 2); + INDENTED_ADD (button); button = katze_property_proxy (settings, "remember-last-downloaded-files", NULL); - SPANNED_ADD (button, 0, 2, 2, 3); - - g_object_unref (sizegroup); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (preferences)->vbox), - preferences->notebook, FALSE, FALSE, 4); - #if HAVE_OSX - GtkWidget* icon; - hbox = gtk_hbox_new (FALSE, 0); - button = gtk_button_new (); - icon = gtk_image_new_from_stock (GTK_STOCK_HELP, GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (button), icon); - g_signal_connect (button, "clicked", - G_CALLBACK (midori_preferences_help_clicked_cb), preferences); - gtk_box_pack_end (GTK_BOX (hbox), - button, FALSE, FALSE, 4); - gtk_box_pack_end (GTK_BOX (GTK_DIALOG (preferences)->vbox), - hbox, FALSE, FALSE, 0); - #endif - gtk_widget_show_all (GTK_DIALOG (preferences)->vbox); + INDENTED_ADD (button); } diff --git a/midori/midori-preferences.h b/midori/midori-preferences.h index 9015d952..3b4ca2ed 100644 --- a/midori/midori-preferences.h +++ b/midori/midori-preferences.h @@ -14,8 +14,6 @@ #include "midori-websettings.h" -#include - #include G_BEGIN_DECLS @@ -38,7 +36,7 @@ typedef struct _MidoriPreferencesClass MidoriPreferencesClass; struct _MidoriPreferencesClass { - GtkDialogClass parent_class; + KatzePreferencesClass parent_class; }; GType diff --git a/midori/sokoke.c b/midori/sokoke.c index b2f4b59a..0a1268d9 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -608,24 +608,6 @@ sokoke_xfce_header_new (const gchar* icon, return NULL; } -GtkWidget* -sokoke_hig_frame_new (const gchar* title) -{ - /* Create a frame with no actual frame but a bold label and indentation */ - GtkWidget* frame = gtk_frame_new (NULL); - #ifdef G_OS_WIN32 - gtk_frame_set_label (GTK_FRAME (frame), title); - #else - gchar* title_bold = g_strdup_printf ("%s", title); - GtkWidget* label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), title_bold); - g_free (title_bold); - gtk_frame_set_label_widget (GTK_FRAME (frame), label); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - #endif - return frame; -} - void sokoke_widget_set_pango_font_style (GtkWidget* widget, PangoStyle style) diff --git a/midori/sokoke.h b/midori/sokoke.h index f01de6cc..5074d74a 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -83,9 +83,6 @@ GtkWidget* sokoke_xfce_header_new (const gchar* icon, const gchar* title); -GtkWidget* -sokoke_hig_frame_new (const gchar* title); - void sokoke_widget_set_pango_font_style (GtkWidget* widget, PangoStyle style); diff --git a/po/POTFILES.in b/po/POTFILES.in index 42792b86..2cdeb7ee 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -26,6 +26,7 @@ katze/katze-utils.c katze/katze-item.c katze/katze-array.c katze/katze-arrayaction.c +katze/katze-preferences.c extensions/adblock.c extensions/colorful-tabs.c extensions/cookie-manager/cookie-manager.c diff --git a/tests/properties.c b/tests/properties.c index 6d9ecffb..239717ca 100644 --- a/tests/properties.c +++ b/tests/properties.c @@ -78,6 +78,9 @@ properties_object_get_set (GObject* object) g_param_spec_get_name (pspec), g_param_spec_get_name (pspecs[j])); + if (!(pspec->flags & G_PARAM_READABLE)) + continue; + g_object_get (object, property, &value, NULL); if (type == G_TYPE_PARAM_BOOLEAN) {