diff options
author | Rodrigo Moya <rodrigo@gnome-db.org> | 2010-10-08 17:51:10 +0200 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2010-10-11 10:04:58 +0200 |
commit | 03a2ddc15876c46cae6e063845b464d418141c46 (patch) | |
tree | 883645456142979bc09218299c8a1b344e616533 /libgnome-control-center | |
parent | b7972bc1cbb49a212556ae4c1b18e9a9a113e081 (diff) |
Convert CcSettingEditor object to a widget, to simplify a lot of the code in the panels
Diffstat (limited to 'libgnome-control-center')
-rw-r--r-- | libgnome-control-center/Makefile.am | 1 | ||||
-rw-r--r-- | libgnome-control-center/cc-setting-editor.c | 96 | ||||
-rw-r--r-- | libgnome-control-center/cc-setting-editor.h | 15 | ||||
-rw-r--r-- | libgnome-control-center/test-setting-editor.c | 9 |
4 files changed, 101 insertions, 20 deletions
diff --git a/libgnome-control-center/Makefile.am b/libgnome-control-center/Makefile.am index d0c372024..d43db550c 100644 --- a/libgnome-control-center/Makefile.am +++ b/libgnome-control-center/Makefile.am @@ -13,7 +13,6 @@ libgnome_control_center_include_HEADERS = \ cc-setting-editor.h \ cc-shell.h \ gconf-property-editor.h \ - gconf-property-editor-marshal.h \ $(NULL) libgnome_control_center_la_SOURCES = \ diff --git a/libgnome-control-center/cc-setting-editor.c b/libgnome-control-center/cc-setting-editor.c index db15cf797..f9c549044 100644 --- a/libgnome-control-center/cc-setting-editor.c +++ b/libgnome-control-center/cc-setting-editor.c @@ -51,7 +51,7 @@ struct _CcSettingEditorPrivate static guint seditor_signals[LAST_SIGNAL] = { 0, }; -G_DEFINE_TYPE(CcSettingEditor, cc_setting_editor, G_TYPE_OBJECT) +G_DEFINE_TYPE(CcSettingEditor, cc_setting_editor, GTK_TYPE_VBOX) static void cc_setting_editor_finalize (GObject *object) @@ -114,6 +114,9 @@ cc_setting_editor_new (SettingType s_type, seditor->priv->settings_prefix = g_strdup (settings_prefix); } + /* Add the ui control to the box */ + gtk_box_pack_start (GTK_BOX (seditor), ui_control, TRUE, FALSE, 3); + return seditor; } @@ -140,33 +143,49 @@ application_selection_changed_cb (GtkComboBox *combobox, CcSettingEditor *sedito } } +static gboolean +is_separator (GtkTreeModel *model, GtkTreeIter *iter, gpointer sep_index) +{ + GtkTreePath *path; + gboolean result; + + path = gtk_tree_model_get_path (model, iter); + result = gtk_tree_path_get_indices (path)[0] == GPOINTER_TO_INT (sep_index); + gtk_tree_path_free (path); + + return result; +} + /** * cc_setting_editor_new_application: * @mime_type: The MIME type to configure application for. - * @combobox: The combo box widget used to display the list of applications for the given type. * * Create a new #CCSettingEditor object to configure the default application * for the given MIME type. * * Return value: A newly created #CCSettingEditor object. */ -GObject * -cc_setting_editor_new_application (const gchar *mime_type, GtkWidget *combobox) +GtkWidget * +cc_setting_editor_new_application (const gchar *mime_type) { CcSettingEditor *seditor; GList *app_list; GtkListStore *model; GtkCellRenderer *renderer; GAppInfo *default_app; + GtkWidget *combobox; + /* Setup the combo box */ + model = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER); + combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model)); + gtk_widget_show (combobox); + + /* Create the CcSettingEditor widget */ seditor = cc_setting_editor_new (SETTING_TYPE_APPLICATION, NULL, mime_type, combobox); - /* Setup the combo box */ - model = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER); - renderer = gtk_cell_renderer_pixbuf_new (); /* not all cells have a pixbuf, this prevents the combo box to shrink */ gtk_cell_renderer_set_fixed_size (renderer, -1, 22); @@ -187,6 +206,9 @@ cc_setting_editor_new_application (const gchar *mime_type, GtkWidget *combobox) default_app = g_app_info_get_default_for_type (mime_type, FALSE); app_list = g_app_info_get_all_for_type (mime_type); + gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, + GINT_TO_POINTER (g_list_length (app_list)), NULL); + while (app_list != NULL) { GtkTreeIter new_row; GAppInfo *app_info = (GAppInfo *) app_list->data; @@ -212,7 +234,65 @@ cc_setting_editor_new_application (const gchar *mime_type, GtkWidget *combobox) g_signal_connect (combobox, "changed", G_CALLBACK (application_selection_changed_cb), seditor); - return (GObject *) seditor; + return (GtkWidget *) seditor; +} + +static void +boolean_value_changed_cb (GtkToggleButton *toggle_button, CcSettingEditor *seditor) +{ + g_settings_set_boolean (seditor->priv->settings, + seditor->priv->key, + gtk_toggle_button_get_active (toggle_button)); +} + +/** + * cc_setting_editor_new_boolean: + * @settings_prefix: The settings prefix for the key. + * @key: The settings key to associate with. + * + * Create a new #CCSettingEditor object to configure a boolean setting. + * + * Return value: A newly created #CCSettingEditor object. + */ +GtkWidget * +cc_setting_editor_new_boolean (const gchar *label, + const gchar *settings_prefix, + const gchar *key) +{ + GtkWidget *checkbox; + CcSettingEditor *seditor; + + checkbox = gtk_check_button_new_with_label (label); + gtk_widget_show (checkbox); + + /* Create the CcSettingEditor widget */ + seditor = cc_setting_editor_new (SETTING_TYPE_GSETTINGS, + settings_prefix, + key, + checkbox); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), + g_settings_get_boolean (seditor->priv->settings, seditor->priv->key)); + g_signal_connect (checkbox, "toggled", + G_CALLBACK (boolean_value_changed_cb), seditor); + + return (GtkWidget *) seditor; +} + +/** + * cc_setting_editor_get_key: + * @seditor: a #CCSettingEditor object. + * + * Get the settings key associated with the given #CCSettingEditor object. + * + * Return value: The settings key associated with the given #CCSettingEditor object. + */ +const gchar * +cc_setting_editor_get_key (CcSettingEditor *seditor) +{ + g_return_val_if_fail (CC_IS_SETTING_EDITOR (seditor), NULL); + + return seditor->priv->key; } /** diff --git a/libgnome-control-center/cc-setting-editor.h b/libgnome-control-center/cc-setting-editor.h index 9e08151c1..743dd11ec 100644 --- a/libgnome-control-center/cc-setting-editor.h +++ b/libgnome-control-center/cc-setting-editor.h @@ -22,7 +22,6 @@ #ifndef __CC_SETTING_EDITOR_H #define __CC_SETTING_EDITOR_H -#include <glib-object.h> #include <gio/gio.h> #include <gtk/gtk.h> @@ -47,7 +46,7 @@ typedef struct _CcSettingEditorClass CcSettingEditorClass; struct _CcSettingEditor { /*< private >*/ - GObject parent; + GtkVBox parent; CcSettingEditorPrivate *priv; }; @@ -59,16 +58,20 @@ struct _CcSettingEditor struct _CcSettingEditorClass { /*< private >*/ - GObjectClass parent_class; + GtkVBoxClass parent_class; void (* value_changed) (CcSettingEditor *seditor, const gchar *key, GVariant *value); }; -GType cc_setting_editor_get_type (void); +GType cc_setting_editor_get_type (void); -GObject *cc_setting_editor_new_application (const gchar *mime_type, GtkWidget *combobox); +GtkWidget *cc_setting_editor_new_application (const gchar *mime_type); +GtkWidget *cc_setting_editor_new_boolean (const gchar *label, + const gchar *settings_prefix, + const gchar *key); -GtkWidget *cc_setting_editor_get_ui_control (CcSettingEditor *seditor); +const gchar *cc_setting_editor_get_key (CcSettingEditor *editor); +GtkWidget *cc_setting_editor_get_ui_control (CcSettingEditor *seditor); G_END_DECLS diff --git a/libgnome-control-center/test-setting-editor.c b/libgnome-control-center/test-setting-editor.c index 6620f1b90..6709e4eaa 100644 --- a/libgnome-control-center/test-setting-editor.c +++ b/libgnome-control-center/test-setting-editor.c @@ -24,8 +24,8 @@ int main (int argc, char *argv[]) { - GtkWidget *dialog, *w; - GObject *seditor; + GtkWidget *dialog; + GtkWidget *seditor; gtk_init (&argc, &argv); @@ -35,10 +35,9 @@ main (int argc, char *argv[]) g_signal_connect (dialog, "response", G_CALLBACK (gtk_main_quit), NULL); /* Create a default application selector */ - w = gtk_combo_box_new (); //seditor = cc_setting_editor_new_application ("x-scheme-handler/http", w); - seditor = cc_setting_editor_new_application ("text/plain", w); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), w, TRUE, FALSE, 3); + seditor = cc_setting_editor_new_application ("text/plain"); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), seditor, TRUE, FALSE, 3); /* Run the dialog */ gtk_widget_show_all (dialog); |