aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/misc/e-preferences-window.c80
-rw-r--r--widgets/misc/e-preferences-window.h8
-rw-r--r--widgets/misc/test-preferences-window.c60
3 files changed, 120 insertions, 28 deletions
diff --git a/widgets/misc/e-preferences-window.c b/widgets/misc/e-preferences-window.c
index 9203855937..493727c6ae 100644
--- a/widgets/misc/e-preferences-window.c
+++ b/widgets/misc/e-preferences-window.c
@@ -32,6 +32,9 @@
((obj), E_TYPE_PREFERENCES_WINDOW, EPreferencesWindowPrivate))
struct _EPreferencesWindowPrivate {
+ gboolean setup;
+ gpointer shell;
+
GtkWidget *icon_view;
GtkWidget *scroll;
GtkWidget *notebook;
@@ -138,6 +141,11 @@ preferences_window_dispose (GObject *object)
priv->notebook = NULL;
}
+ if (priv->shell) {
+ g_object_remove_weak_pointer (priv->shell, &priv->shell);
+ priv->shell = NULL;
+ }
+
g_hash_table_remove_all (priv->index);
/* Chain up to parent's dispose() method. */
@@ -165,6 +173,8 @@ preferences_window_show (GtkWidget *widget)
GtkTreePath *path;
priv = E_PREFERENCES_WINDOW_GET_PRIVATE (widget);
+ if (!priv->setup)
+ g_warning ("Error - preferences window has not been setup correctly");
icon_view = GTK_ICON_VIEW (priv->icon_view);
@@ -375,9 +385,27 @@ e_preferences_window_get_type (void)
}
GtkWidget *
-e_preferences_window_new (void)
+e_preferences_window_new (gpointer shell)
+{
+ EPreferencesWindow *window;
+
+ window = g_object_new (E_TYPE_PREFERENCES_WINDOW, NULL);
+
+ /* ideally should be an object property */
+ window->priv->shell = shell;
+ if (shell)
+ g_object_add_weak_pointer (shell, &window->priv->shell);
+
+ return GTK_WIDGET (window);
+}
+
+gpointer
+e_preferences_window_get_shell (EPreferencesWindow *window)
{
- return g_object_new (E_TYPE_PREFERENCES_WINDOW, NULL);
+ g_return_val_if_fail (E_IS_PREFERENCES_WINDOW (window), NULL);
+ g_return_val_if_fail (window->priv != NULL, NULL);
+
+ return window->priv->shell;
}
void
@@ -385,7 +413,7 @@ e_preferences_window_add_page (EPreferencesWindow *window,
const gchar *page_name,
const gchar *icon_name,
const gchar *caption,
- GtkWidget *widget,
+ EPreferencesWindowCreatePageFn create_fn,
gint sort_order)
{
GtkTreeRowReference *reference;
@@ -396,13 +424,14 @@ e_preferences_window_add_page (EPreferencesWindow *window,
GHashTable *index;
GdkPixbuf *pixbuf;
GtkTreeIter iter;
+ GtkWidget *align;
gint page;
g_return_if_fail (E_IS_PREFERENCES_WINDOW (window));
+ g_return_if_fail (create_fn != NULL);
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 (window->priv->icon_view);
notebook = GTK_NOTEBOOK (window->priv->notebook);
@@ -425,8 +454,10 @@ e_preferences_window_add_page (EPreferencesWindow *window,
g_hash_table_insert (index, g_strdup (page_name), reference);
gtk_tree_path_free (path);
- gtk_widget_show (widget);
- gtk_notebook_append_page (notebook, widget, NULL);
+ align = g_object_new (GTK_TYPE_ALIGNMENT, NULL);
+ gtk_widget_show (GTK_WIDGET (align));
+ g_object_set_data (G_OBJECT (align), "create_fn", create_fn);
+ gtk_notebook_append_page (notebook, align, NULL);
/* Force GtkIconView to recalculate the text wrap width,
* otherwise we get a really narrow icon list on the left
@@ -445,6 +476,7 @@ e_preferences_window_show_page (EPreferencesWindow *window,
g_return_if_fail (E_IS_PREFERENCES_WINDOW (window));
g_return_if_fail (page_name != NULL);
+ g_return_if_fail (window->priv->setup);
icon_view = GTK_ICON_VIEW (window->priv->icon_view);
reference = g_hash_table_lookup (window->priv->index, page_name);
@@ -466,6 +498,7 @@ e_preferences_window_filter_page (EPreferencesWindow *window,
g_return_if_fail (E_IS_PREFERENCES_WINDOW (window));
g_return_if_fail (page_name != NULL);
+ g_return_if_fail (window->priv->setup);
icon_view = GTK_ICON_VIEW (window->priv->icon_view);
reference = g_hash_table_lookup (window->priv->index, page_name);
@@ -487,3 +520,38 @@ e_preferences_window_filter_page (EPreferencesWindow *window,
gtk_widget_show (window->priv->scroll);
}
+/*
+ * Create all the deferred configuration pages.
+ */
+void
+e_preferences_window_setup (EPreferencesWindow *window)
+{
+ gint i, num;
+ GtkNotebook *notebook;
+ EPreferencesWindowPrivate *priv;
+
+ priv = E_PREFERENCES_WINDOW_GET_PRIVATE (window);
+ notebook = GTK_NOTEBOOK (priv->notebook);
+ num = gtk_notebook_get_n_pages (notebook);
+
+ for (i = 0; i < num; i++) {
+ GtkBin *align;
+ GtkWidget *content;
+ EPreferencesWindowCreatePageFn create_fn;
+
+ align = GTK_BIN (gtk_notebook_get_nth_page (notebook, i));
+ create_fn = g_object_get_data (G_OBJECT (align), "create_fn");
+
+ if (!create_fn || gtk_bin_get_child (align))
+ continue;
+
+
+ content = create_fn (window);
+ if (content) {
+ gtk_widget_show (content);
+ gtk_container_add (GTK_CONTAINER (align), content);
+ }
+ }
+
+ priv->setup = TRUE;
+}
diff --git a/widgets/misc/e-preferences-window.h b/widgets/misc/e-preferences-window.h
index 00b51b85e1..3606d6e629 100644
--- a/widgets/misc/e-preferences-window.h
+++ b/widgets/misc/e-preferences-window.h
@@ -58,13 +58,17 @@ struct _EPreferencesWindowClass {
GtkWindowClass parent_class;
};
+typedef GtkWidget *(*EPreferencesWindowCreatePageFn) (EPreferencesWindow *window);
+
GType e_preferences_window_get_type (void);
-GtkWidget * e_preferences_window_new (void);
+GtkWidget * e_preferences_window_new (gpointer shell);
+gpointer e_preferences_window_get_shell (EPreferencesWindow *window);
+void e_preferences_window_setup (EPreferencesWindow *window);
void e_preferences_window_add_page (EPreferencesWindow *window,
const gchar *page_name,
const gchar *icon_name,
const gchar *caption,
- GtkWidget *widget,
+ EPreferencesWindowCreatePageFn create_fn,
gint sort_order);
void e_preferences_window_show_page (EPreferencesWindow *window,
const gchar *page_name);
diff --git a/widgets/misc/test-preferences-window.c b/widgets/misc/test-preferences-window.c
index dec6b85cb5..c737964518 100644
--- a/widgets/misc/test-preferences-window.c
+++ b/widgets/misc/test-preferences-window.c
@@ -23,31 +23,50 @@
#include <gtk/gtk.h>
-#define NUM_PAGES 10
-
-static void
-add_pages (EPreferencesWindow *preferences_window)
+static GtkWidget *
+create_page_number (gint i)
{
- gint i;
+ gchar *caption;
+ GtkWidget *widget;
+
+ caption = g_strdup_printf ("Title of page %d", i);
- for (i = 0; i < NUM_PAGES; i++) {
- GtkWidget *widget;
- gchar *caption;
- gchar *page_name;
+ widget = gtk_label_new (caption);
+ gtk_widget_show (widget);
- caption = g_strdup_printf ("Title of page %d", i);
- page_name = g_strdup_printf ("page-%d", i);
+ g_free (caption);
- widget = gtk_label_new (caption);
- gtk_widget_show (widget);
+ return widget;
+}
- e_preferences_window_add_page (
- preferences_window, page_name,
- "gtk-properties", caption, widget, i);
+static GtkWidget *
+create_page_zero (EPreferencesWindow *preferences_window)
+{
+ return create_page_number (0);
+}
+static GtkWidget *
+create_page_one (EPreferencesWindow *preferences_window)
+{
+ return create_page_number (1);
+}
+static GtkWidget *
+create_page_two (EPreferencesWindow *preferences_window)
+{
+ return create_page_number (2);
+}
- g_free (caption);
- g_free (page_name);
- }
+static void
+add_pages (EPreferencesWindow *preferences_window)
+{
+ e_preferences_window_add_page (preferences_window, "page-0",
+ "gtk-properties", "title 0",
+ create_page_zero, 0);
+ e_preferences_window_add_page (preferences_window, "page-1",
+ "gtk-properties", "title 1",
+ create_page_one, 1);
+ e_preferences_window_add_page (preferences_window, "page-2",
+ "gtk-properties", "title 2",
+ create_page_two, 2);
}
static gint
@@ -67,7 +86,7 @@ main (gint argc, gchar **argv)
gtk_init (&argc, &argv);
- window = e_preferences_window_new ();
+ window = e_preferences_window_new (NULL);
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect(
@@ -75,6 +94,7 @@ main (gint argc, gchar **argv)
G_CALLBACK (delete_event_callback), NULL);
add_pages (E_PREFERENCES_WINDOW (window));
+ e_preferences_window_setup (E_PREFERENCES_WINDOW (window));
gtk_widget_show (window);