From 558de407c4afe0d3d42a6a67687f78d31404ade8 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 9 Aug 2008 02:24:46 +0000 Subject: Kill EShellSettingsDialog. Rename EMultiConfigDialog to EPreferencesWindow and improve the API. svn path=/branches/kill-bonobo/; revision=35944 --- widgets/misc/Makefile.am | 14 +- widgets/misc/e-multi-config-dialog.c | 383 -------------------------------- widgets/misc/e-multi-config-dialog.h | 78 ------- widgets/misc/e-preferences-window.c | 377 +++++++++++++++++++++++++++++++ widgets/misc/e-preferences-window.h | 73 ++++++ widgets/misc/test-multi-config-dialog.c | 96 -------- widgets/misc/test-preferences-window.c | 86 +++++++ 7 files changed, 543 insertions(+), 564 deletions(-) delete mode 100644 widgets/misc/e-multi-config-dialog.c delete mode 100644 widgets/misc/e-multi-config-dialog.h create mode 100644 widgets/misc/e-preferences-window.c create mode 100644 widgets/misc/e-preferences-window.h delete mode 100644 widgets/misc/test-multi-config-dialog.c create mode 100644 widgets/misc/test-preferences-window.c (limited to 'widgets/misc') diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 95acd8b929..c7258e14a5 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -56,7 +56,7 @@ widgetsinclude_HEADERS = \ e-image-chooser.h \ e-info-label.h \ e-map.h \ - e-multi-config-dialog.h \ + e-preferences-window.h \ e-online-button.h \ e-search-bar.h \ e-task-bar.h \ @@ -104,7 +104,7 @@ libemiscwidgets_la_SOURCES = \ e-image-chooser.c \ e-info-label.c \ e-map.c \ - e-multi-config-dialog.c \ + e-preferences-window.c \ e-online-button.c \ e-search-bar.c \ e-task-bar.c \ @@ -158,7 +158,7 @@ noinst_PROGRAMS = \ test-calendar \ test-dateedit \ test-dropdown-button \ - test-multi-config-dialog \ + test-preferences-window \ test-info-label # test-calendar @@ -191,12 +191,12 @@ test_dropdown_button_LDADD = \ $(top_builddir)/e-util/libeutil.la \ $(E_WIDGETS_LIBS) -# test-multi-config-dialog +# test-preferences-window -test_multi_config_dialog_SOURCES = \ - test-multi-config-dialog.c +test_preferences_window_SOURCES = \ + test-preferences-window.c -test_multi_config_dialog_LDADD = \ +test_preferences_window_LDADD = \ libemiscwidgets.la \ $(top_builddir)/e-util/libeutil.la \ $(E_WIDGETS_LIBS) diff --git a/widgets/misc/e-multi-config-dialog.c b/widgets/misc/e-multi-config-dialog.c deleted file mode 100644 index bb9c0e6f79..0000000000 --- a/widgets/misc/e-multi-config-dialog.c +++ /dev/null @@ -1,383 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-multi-config-dialog.c - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "e-multi-config-dialog.h" - -#include - -#define SWITCH_PAGE_INTERVAL 250 - -#define E_MULTI_CONFIG_DIALOG_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_MULTI_CONFIG_DIALOG, EMultiConfigDialogPrivate)) - -struct _EMultiConfigDialogPrivate { - GtkWidget *icon_view; - GtkWidget *notebook; - guint timeout_id; -}; - -enum { - COLUMN_TEXT, /* G_TYPE_STRING */ - COLUMN_PIXBUF /* GDK_TYPE_PIXBUF */ -}; - -static gpointer parent_class; - -static GtkWidget * -create_page_container (GtkWidget *widget) -{ - GtkWidget *vbox; - - vbox = gtk_vbox_new (FALSE, 0); - - gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0); - - gtk_widget_show (widget); - gtk_widget_show (vbox); - - return vbox; -} - -static GdkPixbuf * -multi_config_dialog_load_pixbuf (const gchar *icon_name) -{ - GtkIconTheme *icon_theme; - GtkIconInfo *icon_info; - GdkPixbuf *pixbuf; - const gchar *filename; - gint size; - GError *error = NULL; - - icon_theme = gtk_icon_theme_get_default (); - - if (!gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, 0)) - return NULL; - - icon_info = gtk_icon_theme_lookup_icon ( - icon_theme, icon_name, size, 0); - - if (icon_info == NULL) - return NULL; - - filename = gtk_icon_info_get_filename (icon_info); - - pixbuf = gdk_pixbuf_new_from_file (filename, &error); - - gtk_icon_info_free (icon_info); - - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } - - return pixbuf; -} - -static gboolean -multi_config_dialog_timeout_cb (EMultiConfigDialog *dialog) -{ - GtkIconView *icon_view; - GtkNotebook *notebook; - GList *list; - - icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); - notebook = GTK_NOTEBOOK (dialog->priv->notebook); - - list = gtk_icon_view_get_selected_items (icon_view); - - if (list != NULL) { - GtkTreePath *path = list->data; - gint page; - - page = gtk_tree_path_get_indices (path)[0]; - gtk_notebook_set_current_page (notebook, page); - } - - g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL); - g_list_free (list); - - dialog->priv->timeout_id = 0; - gtk_widget_grab_focus (GTK_WIDGET (icon_view)); - - return FALSE; -} - -static void -multi_config_dialog_selection_changed_cb (EMultiConfigDialog *dialog) -{ - if (dialog->priv->timeout_id == 0) - dialog->priv->timeout_id = g_timeout_add ( - SWITCH_PAGE_INTERVAL, (GSourceFunc) - multi_config_dialog_timeout_cb, dialog); -} - -static void -multi_config_dialog_dispose (GObject *object) -{ - EMultiConfigDialogPrivate *priv; - - priv = E_MULTI_CONFIG_DIALOG_GET_PRIVATE (object); - - if (priv->icon_view != NULL) { - g_object_unref (priv->icon_view); - priv->icon_view = NULL; - } - - if (priv->notebook != NULL) { - g_object_unref (priv->notebook); - priv->notebook = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static void -multi_config_dialog_finalize (GObject *object) -{ - EMultiConfigDialogPrivate *priv; - - priv = E_MULTI_CONFIG_DIALOG_GET_PRIVATE (object); - - if (priv->timeout_id != 0) - g_source_remove (priv->timeout_id); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -multi_config_dialog_map (GtkWidget *widget) -{ - GtkDialog *dialog; - - /* Chain up to parent's map() method. */ - GTK_WIDGET_CLASS (parent_class)->map (widget); - - /* Override those stubborn style properties. */ - dialog = GTK_DIALOG (widget); - gtk_box_set_spacing (GTK_BOX (dialog->vbox), 12); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 0); - gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 0); -} - -static void -multi_config_dialog_response (GtkDialog *dialog, - gint response_id) -{ - GError *error = NULL; - - switch (response_id) { - case GTK_RESPONSE_HELP: - gnome_help_display ( - "evolution.xml", "config-prefs", &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } - break; - - case GTK_RESPONSE_CLOSE: - default: - gtk_widget_destroy (GTK_WIDGET (dialog)); - break; - } -} - -static void -multi_config_dialog_class_init (EMultiConfigDialogClass *class) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkDialogClass *dialog_class; - - parent_class = g_type_class_peek_parent (class); - g_type_class_add_private (class, sizeof (EMultiConfigDialogPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = multi_config_dialog_dispose; - object_class->finalize = multi_config_dialog_finalize; - - widget_class = GTK_WIDGET_CLASS (class); - widget_class->map = multi_config_dialog_map; - - dialog_class = GTK_DIALOG_CLASS (class); - dialog_class->response = multi_config_dialog_response; -} - -static void -multi_config_dialog_init (EMultiConfigDialog *dialog) -{ - GtkListStore *store; - GtkWidget *container; - GtkWidget *hbox; - GtkWidget *widget; - - dialog->priv = E_MULTI_CONFIG_DIALOG_GET_PRIVATE (dialog); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); - - /* XXX Remove this once we kill Bonobo. */ - gtk_widget_realize (GTK_WIDGET (dialog)); - - container = GTK_DIALOG (dialog)->vbox; - - hbox = gtk_hbox_new (FALSE, 12); - gtk_container_add (GTK_CONTAINER (container), hbox); - gtk_widget_show (hbox); - - widget = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy ( - GTK_SCROLLED_WINDOW (widget), - GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type ( - GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); - gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, TRUE, 0); - gtk_widget_show (widget); - - container = widget; - - store = gtk_list_store_new (2, G_TYPE_STRING, GDK_TYPE_PIXBUF); - widget = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store)); - gtk_icon_view_set_columns (GTK_ICON_VIEW (widget), 1); - gtk_icon_view_set_text_column (GTK_ICON_VIEW (widget), COLUMN_TEXT); - gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (widget), COLUMN_PIXBUF); - g_signal_connect_swapped ( - widget, "selection-changed", - G_CALLBACK (multi_config_dialog_selection_changed_cb), dialog); - gtk_container_add (GTK_CONTAINER (container), widget); - dialog->priv->icon_view = g_object_ref (widget); - gtk_widget_show (widget); - g_object_unref (store); - - widget = gtk_notebook_new (); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (widget), FALSE); - gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0); - dialog->priv->notebook = g_object_ref (widget); - gtk_widget_show (widget); - - gtk_dialog_add_buttons ( - GTK_DIALOG (dialog), - GTK_STOCK_HELP, GTK_RESPONSE_HELP, - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); - - gtk_dialog_set_default_response ( - GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); -} - -GType -e_multi_config_dialog_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - const GTypeInfo type_info = { - sizeof (EMultiConfigDialogClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) multi_config_dialog_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EMultiConfigDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) multi_config_dialog_init, - NULL /* value_table */ - }; - - type = g_type_register_static ( - GTK_TYPE_DIALOG, "EMultiConfigDialog", &type_info, 0); - } - - return type; -} - -GtkWidget * -e_multi_config_dialog_new (void) -{ - return g_object_new (e_multi_config_dialog_get_type (), NULL); -} - -void -e_multi_config_dialog_add_page (EMultiConfigDialog *dialog, - const gchar *caption, - const gchar *icon_name, - EConfigPage *page_widget) -{ - GtkIconView *icon_view; - GtkNotebook *notebook; - GtkTreeModel *model; - GdkPixbuf *pixbuf; - GtkTreeIter iter; - - g_return_if_fail (E_IS_MULTI_CONFIG_DIALOG (dialog)); - g_return_if_fail (caption != NULL); - g_return_if_fail (icon_name != NULL); - g_return_if_fail (E_IS_CONFIG_PAGE (page_widget)); - - icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); - notebook = GTK_NOTEBOOK (dialog->priv->notebook); - - model = gtk_icon_view_get_model (icon_view); - pixbuf = multi_config_dialog_load_pixbuf (icon_name); - - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - - gtk_list_store_set ( - GTK_LIST_STORE (model), &iter, - COLUMN_TEXT, caption, COLUMN_PIXBUF, pixbuf, -1); - - if (gtk_tree_model_iter_n_children (model, NULL) == 1) { - GtkTreePath *path; - - path = gtk_tree_path_new_first (); - gtk_icon_view_select_path (icon_view, path); - gtk_tree_path_free (path); - } - - gtk_notebook_append_page ( - notebook, create_page_container ( - GTK_WIDGET (page_widget)), NULL); -} - -void -e_multi_config_dialog_show_page (EMultiConfigDialog *dialog, - gint page) -{ - GtkIconView *icon_view; - GtkNotebook *notebook; - GtkTreePath *path; - - g_return_if_fail (E_IS_MULTI_CONFIG_DIALOG (dialog)); - - icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); - notebook = GTK_NOTEBOOK (dialog->priv->notebook); - - path = gtk_tree_path_new_from_indices (page, -1); - gtk_icon_view_select_path (icon_view, path); - gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0); - gtk_tree_path_free (path); - - gtk_notebook_set_current_page (notebook, page); -} diff --git a/widgets/misc/e-multi-config-dialog.h b/widgets/misc/e-multi-config-dialog.h deleted file mode 100644 index f636f0d37d..0000000000 --- a/widgets/misc/e-multi-config-dialog.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-multi-config-dialog.h - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef E_MULTI_CONFIG_DIALOG_H -#define E_MULTI_CONFIG_DIALOG_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "e-config-page.h" - -#include - -G_BEGIN_DECLS - -/* Standard GObject macros */ -#define E_TYPE_MULTI_CONFIG_DIALOG \ - (e_multi_config_dialog_get_type ()) -#define E_MULTI_CONFIG_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_MULTI_CONFIG_DIALOG, EMultiConfigDialog)) -#define E_MULTI_CONFIG_DIALOG_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_MULTI_CONFIG_DIALOG, EMultiConfigDialogClass)) -#define E_IS_MULTI_CONFIG_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_MULTI_CONFIG_DIALOG)) -#define E_IS_MULTI_CONFIG_DIALOG_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((obj), E_TYPE_MULTI_CONFIG_DIALOG)) -#define E_MULTI_CONFIG_DIALOG_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_TYPE \ - ((obj), E_TYPE_MULTI_CONFIG_DIALOG, EMultiConfigDialogClass)) - -typedef struct _EMultiConfigDialog EMultiConfigDialog; -typedef struct _EMultiConfigDialogClass EMultiConfigDialogClass; -typedef struct _EMultiConfigDialogPrivate EMultiConfigDialogPrivate; - -struct _EMultiConfigDialog { - GtkDialog parent; - EMultiConfigDialogPrivate *priv; -}; - -struct _EMultiConfigDialogClass { - GtkDialogClass parent_class; -}; - -GType e_multi_config_dialog_get_type (void); -GtkWidget * e_multi_config_dialog_new (void); - -void e_multi_config_dialog_add_page (EMultiConfigDialog *dialog, - const gchar *caption, - const gchar *icon_name, - EConfigPage *page); -void e_multi_config_dialog_show_page (EMultiConfigDialog *dialog, - gint page); - -G_END_DECLS - -#endif /* E_MULTI_CONFIG_DIALOG_H */ diff --git a/widgets/misc/e-preferences-window.c b/widgets/misc/e-preferences-window.c new file mode 100644 index 0000000000..1f2d38345f --- /dev/null +++ b/widgets/misc/e-preferences-window.c @@ -0,0 +1,377 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-preferences-window.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-preferences-window.h" + +#include + +#define SWITCH_PAGE_INTERVAL 250 + +#define E_PREFERENCES_WINDOW_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_PREFERENCES_WINDOW, EPreferencesWindowPrivate)) + +struct _EPreferencesWindowPrivate { + GtkWidget *icon_view; + GtkWidget *notebook; + GHashTable *index; +}; + +enum { + COLUMN_TEXT, /* G_TYPE_STRING */ + COLUMN_PIXBUF, /* GDK_TYPE_PIXBUF */ + COLUMN_PAGE, /* G_TYPE_INT */ + COLUMN_SORT /* G_TYPE_INT */ +}; + +static gpointer parent_class; + +static GdkPixbuf * +preferences_window_load_pixbuf (const gchar *icon_name) +{ + GtkIconTheme *icon_theme; + GtkIconInfo *icon_info; + GdkPixbuf *pixbuf; + const gchar *filename; + gint size; + GError *error = NULL; + + icon_theme = gtk_icon_theme_get_default (); + + if (!gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, 0)) + return NULL; + + icon_info = gtk_icon_theme_lookup_icon ( + icon_theme, icon_name, size, 0); + + if (icon_info == NULL) + return NULL; + + filename = gtk_icon_info_get_filename (icon_info); + + pixbuf = gdk_pixbuf_new_from_file (filename, &error); + + gtk_icon_info_free (icon_info); + + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + + return pixbuf; +} + +static void +preferences_window_selection_changed_cb (EPreferencesWindow *dialog) +{ + GtkIconView *icon_view; + GtkNotebook *notebook; + GtkTreeModel *model; + GtkTreeIter iter; + GList *list; + gint page; + + icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); + list = gtk_icon_view_get_selected_items (icon_view); + if (list == NULL) + return; + + model = gtk_icon_view_get_model (icon_view); + gtk_tree_model_get_iter (model, &iter, list->data); + gtk_tree_model_get (model, &iter, COLUMN_PAGE, &page, -1); + + notebook = GTK_NOTEBOOK (dialog->priv->notebook); + gtk_notebook_set_current_page (notebook, page); + + g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL); + g_list_free (list); + + gtk_widget_grab_focus (GTK_WIDGET (icon_view)); +} + +static void +preferences_window_dispose (GObject *object) +{ + EPreferencesWindowPrivate *priv; + + priv = E_PREFERENCES_WINDOW_GET_PRIVATE (object); + + if (priv->icon_view != NULL) { + g_object_unref (priv->icon_view); + priv->icon_view = NULL; + } + + if (priv->notebook != NULL) { + g_object_unref (priv->notebook); + priv->notebook = NULL; + } + + g_hash_table_remove_all (priv->index); + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +preferences_window_finalize (GObject *object) +{ + EPreferencesWindowPrivate *priv; + + priv = E_PREFERENCES_WINDOW_GET_PRIVATE (object); + + g_hash_table_destroy (priv->index); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +preferences_window_map (GtkWidget *widget) +{ + GtkDialog *dialog; + + /* Chain up to parent's map() method. */ + GTK_WIDGET_CLASS (parent_class)->map (widget); + + /* Override those stubborn style properties. */ + dialog = GTK_DIALOG (widget); + gtk_box_set_spacing (GTK_BOX (dialog->vbox), 12); + gtk_container_set_border_width (GTK_CONTAINER (widget), 12); + gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 0); + gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 0); +} + +static void +preferences_window_response (GtkDialog *dialog, + gint response_id) +{ + GError *error = NULL; + + switch (response_id) { + case GTK_RESPONSE_HELP: + gnome_help_display ( + "evolution.xml", "config-prefs", &error); + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + break; + + case GTK_RESPONSE_CLOSE: + default: + gtk_widget_destroy (GTK_WIDGET (dialog)); + break; + } +} + +static void +preferences_window_class_init (EPreferencesWindowClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkDialogClass *dialog_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EPreferencesWindowPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->dispose = preferences_window_dispose; + object_class->finalize = preferences_window_finalize; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->map = preferences_window_map; + + dialog_class = GTK_DIALOG_CLASS (class); + dialog_class->response = preferences_window_response; +} + +static void +preferences_window_init (EPreferencesWindow *dialog) +{ + GtkListStore *store; + GtkWidget *container; + GtkWidget *hbox; + GtkWidget *widget; + GHashTable *index; + + index = g_hash_table_new_full ( + g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) gtk_tree_row_reference_free); + + dialog->priv = E_PREFERENCES_WINDOW_GET_PRIVATE (dialog); + dialog->priv->index = index; + + store = gtk_list_store_new ( + 4, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT, G_TYPE_INT); + gtk_tree_sortable_set_sort_column_id ( + GTK_TREE_SORTABLE (store), COLUMN_SORT, GTK_SORT_ASCENDING); + + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); + + container = GTK_DIALOG (dialog)->vbox; + + hbox = gtk_hbox_new (FALSE, 12); + gtk_container_add (GTK_CONTAINER (container), hbox); + gtk_widget_show (hbox); + + widget = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy ( + GTK_SCROLLED_WINDOW (widget), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type ( + GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); + gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, TRUE, 0); + gtk_widget_show (widget); + + container = widget; + + widget = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store)); + gtk_icon_view_set_columns (GTK_ICON_VIEW (widget), 1); + gtk_icon_view_set_text_column (GTK_ICON_VIEW (widget), COLUMN_TEXT); + gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (widget), COLUMN_PIXBUF); + g_signal_connect_swapped ( + widget, "selection-changed", + G_CALLBACK (preferences_window_selection_changed_cb), dialog); + gtk_container_add (GTK_CONTAINER (container), widget); + dialog->priv->icon_view = g_object_ref (widget); + gtk_widget_show (widget); + g_object_unref (store); + + widget = gtk_notebook_new (); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (widget), FALSE); + gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0); + dialog->priv->notebook = g_object_ref (widget); + gtk_widget_show (widget); + + gtk_dialog_add_buttons ( + GTK_DIALOG (dialog), + GTK_STOCK_HELP, GTK_RESPONSE_HELP, + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + NULL); + + gtk_dialog_set_default_response ( + GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); +} + +GType +e_preferences_window_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EPreferencesWindowClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) preferences_window_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EPreferencesWindow), + 0, /* n_preallocs */ + (GInstanceInitFunc) preferences_window_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_DIALOG, "EPreferencesWindow", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_preferences_window_new (void) +{ + return g_object_new (E_TYPE_PREFERENCES_WINDOW, NULL); +} + +void +e_preferences_window_add_page (EPreferencesWindow *dialog, + const gchar *page_name, + const gchar *icon_name, + const gchar *caption, + gint sort_order, + GtkWidget *widget) +{ + GtkTreeRowReference *reference; + GtkIconView *icon_view; + GtkNotebook *notebook; + GtkTreeModel *model; + GtkTreePath *path; + GHashTable *index; + GdkPixbuf *pixbuf; + GtkTreeIter iter; + gint page; + + g_return_if_fail (E_IS_MULTI_CONFIG_DIALOG (dialog)); + g_return_if_fail (page_name != NULL); + g_return_if_fail (icon_name != NULL); + g_return_if_fail (caption != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); + notebook = GTK_NOTEBOOK (dialog->priv->notebook); + + page = gtk_notebook_get_n_pages (notebook); + model = gtk_icon_view_get_model (icon_view); + pixbuf = preferences_window_load_pixbuf (icon_name); + + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + gtk_list_store_set ( + GTK_LIST_STORE (model), &iter, + COLUMN_TEXT, caption, COLUMN_PIXBUF, pixbuf, + COLUMN_PAGE, page, COLUMN_SORT, sort_order, -1); + + index = dialog->priv->index; + path = gtk_tree_model_get_path (model, &iter); + reference = gtk_tree_row_reference_new (model, path); + g_hash_table_insert (index, g_strdup (page_name), reference); + gtk_tree_path_free (path); + + gtk_notebook_append_page (notebook, widget, NULL); + + if (page == 0) + e_preferences_window_show_page (dialog, page_name); +} + +void +e_preferences_window_show_page (EPreferencesWindow *dialog, + const gchar *page_name) +{ + GtkTreeRowReference *reference; + GtkIconView *icon_view; + GtkTreePath *path; + + g_return_if_fail (E_IS_MULTI_CONFIG_DIALOG (dialog)); + g_return_if_fail (page_name != NULL); + + icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); + reference = g_hash_table_lookup (dialog->priv->index, page_name); + g_return_if_fail (reference != NULL); + + path = gtk_tree_row_reference_get_path (reference); + gtk_icon_view_select_path (icon_view, path); + gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0); + gtk_tree_path_free (path); +} diff --git a/widgets/misc/e-preferences-window.h b/widgets/misc/e-preferences-window.h new file mode 100644 index 0000000000..133bf8cdb3 --- /dev/null +++ b/widgets/misc/e-preferences-window.h @@ -0,0 +1,73 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-preferences-window.h + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef E_PREFERENCES_WINDOW_H +#define E_PREFERENCES_WINDOW_H + +#include + +/* Standard GObject macros */ +#define E_TYPE_PREFERENCES_WINDOW \ + (e_preferences_window_get_type ()) +#define E_PREFERENCES_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_PREFERENCES_WINDOW, EPreferencesWindow)) +#define E_PREFERENCES_WINDOW_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_PREFERENCES_WINDOW, EPreferencesWindowClass)) +#define E_IS_MULTI_CONFIG_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_PREFERENCES_WINDOW)) +#define E_IS_MULTI_CONFIG_DIALOG_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((obj), E_TYPE_PREFERENCES_WINDOW)) +#define E_PREFERENCES_WINDOW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_TYPE \ + ((obj), E_TYPE_PREFERENCES_WINDOW, EPreferencesWindowClass)) + +G_BEGIN_DECLS + +typedef struct _EPreferencesWindow EPreferencesWindow; +typedef struct _EPreferencesWindowClass EPreferencesWindowClass; +typedef struct _EPreferencesWindowPrivate EPreferencesWindowPrivate; + +struct _EPreferencesWindow { + GtkDialog parent; + EPreferencesWindowPrivate *priv; +}; + +struct _EPreferencesWindowClass { + GtkDialogClass parent_class; +}; + +GType e_preferences_window_get_type (void); +GtkWidget * e_preferences_window_new (void); +void e_preferences_window_add_page (EPreferencesWindow *window, + const gchar *page_name, + const gchar *icon_name, + const gchar *caption, + gint sort_order, + GtkWidget *widget); +void e_preferences_window_show_page (EPreferencesWindow *window, + const gchar *page_name); + +G_END_DECLS + +#endif /* E_PREFERENCES_WINDOW_H */ diff --git a/widgets/misc/test-multi-config-dialog.c b/widgets/misc/test-multi-config-dialog.c deleted file mode 100644 index b9439722e9..0000000000 --- a/widgets/misc/test-multi-config-dialog.c +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* test-multi-config-dialog.c - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Authors: - * Ettore Perazzoli - */ - -#include "e-multi-config-dialog.c" - -#include -#include -#include - - -#define NUM_PAGES 10 - - -static void -add_pages (EMultiConfigDialog *multi_config_dialog) -{ - int i; - - for (i = 0; i < NUM_PAGES; i ++) { - GtkWidget *widget; - GtkWidget *page; - char *string; - char *title; - - string = g_strdup_printf ("This is page %d", i); - title = g_strdup_printf ("Title of page %d", i); - - widget = gtk_label_new (string); - gtk_widget_show (widget); - - page = e_config_page_new (); - gtk_container_add (GTK_CONTAINER (page), widget); - - e_multi_config_dialog_add_page ( - multi_config_dialog, title, "gtk-properties", - E_CONFIG_PAGE (page)); - - g_free (string); - g_free (title); - } -} - -static int -delete_event_callback (GtkWidget *widget, - GdkEventAny *event, - void *data) -{ - gtk_main_quit (); - - return TRUE; -} - - -int -main (int argc, char **argv) -{ - GtkWidget *dialog; - - gnome_program_init ( - "test-multi-config-dialog", "0.0", LIBGNOMEUI_MODULE, - argc, argv, GNOME_PARAM_NONE); - - dialog = e_multi_config_dialog_new (); - - gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300); - g_signal_connect((dialog), "delete_event", - G_CALLBACK (delete_event_callback), NULL); - - add_pages (E_MULTI_CONFIG_DIALOG (dialog)); - - gtk_widget_show (dialog); - - gtk_main (); - - return 0; -} diff --git a/widgets/misc/test-preferences-window.c b/widgets/misc/test-preferences-window.c new file mode 100644 index 0000000000..ddc99ff3ba --- /dev/null +++ b/widgets/misc/test-preferences-window.c @@ -0,0 +1,86 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* test-preferences-window.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-preferences-window.c" + +#include +#include +#include + +#define NUM_PAGES 10 + +static void +add_pages (EPreferencesWindow *preferences_window) +{ + int i; + + for (i = 0; i < NUM_PAGES; i ++) { + GtkWidget *widget; + char *caption; + char *page_name; + + caption = g_strdup_printf ("Title of page %d", i); + page_name = g_strdup_printf ("page-%d", i); + + widget = gtk_label_new (caption); + gtk_widget_show (widget); + + e_preferences_window_add_page ( + preferences_window, page_name, + "gtk-properties", caption, i, widget); + + g_free (caption); + g_free (page_name); + } +} + +static int +delete_event_callback (GtkWidget *widget, + GdkEventAny *event, + void *data) +{ + gtk_main_quit (); + + return TRUE; +} + +int +main (int argc, char **argv) +{ + GtkWidget *dialog; + + gnome_program_init ( + "test-preferences-window", "0.0", LIBGNOMEUI_MODULE, + argc, argv, GNOME_PARAM_NONE); + + dialog = e_preferences_window_new (); + + gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300); + g_signal_connect((dialog), "delete_event", + G_CALLBACK (delete_event_callback), NULL); + + add_pages (E_PREFERENCES_WINDOW (dialog)); + + gtk_widget_show (dialog); + + gtk_main (); + + return 0; +} -- cgit