aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2013-11-29 03:32:37 +0800
committerMilan Crha <mcrha@redhat.com>2013-11-29 03:32:37 +0800
commitc12a958aba0bac2b665cc8a5a3cae2f10d16dd71 (patch)
tree03a851eb53b7e2395573224a84e0fcf814b879e6 /e-util
parentc8322a6c391cbbdc886e41f5c3a7cf5e7be272c9 (diff)
downloadgsoc2013-evolution-c12a958aba0bac2b665cc8a5a3cae2f10d16dd71.tar
gsoc2013-evolution-c12a958aba0bac2b665cc8a5a3cae2f10d16dd71.tar.gz
gsoc2013-evolution-c12a958aba0bac2b665cc8a5a3cae2f10d16dd71.tar.bz2
gsoc2013-evolution-c12a958aba0bac2b665cc8a5a3cae2f10d16dd71.tar.lz
gsoc2013-evolution-c12a958aba0bac2b665cc8a5a3cae2f10d16dd71.tar.xz
gsoc2013-evolution-c12a958aba0bac2b665cc8a5a3cae2f10d16dd71.tar.zst
gsoc2013-evolution-c12a958aba0bac2b665cc8a5a3cae2f10d16dd71.zip
Extend test-source-selector test program
Added features: - show all four selectors (for Calendars/Memos/Tasks/Books) - be able to open/close selected source Especially the later can be used for testing the factories easily, without running evolution or other client. There can be added more actions on an opened EClient descendant in the future, if it'll be found useful.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/test-source-selector.c285
1 files changed, 226 insertions, 59 deletions
diff --git a/e-util/test-source-selector.c b/e-util/test-source-selector.c
index f89c480520..f8f7031d02 100644
--- a/e-util/test-source-selector.c
+++ b/e-util/test-source-selector.c
@@ -1,6 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* test-source-list-selector.c - Test program for the ESourceListSelector
- * widget.
+/* test-source-selector.c - Test program for the ESourceSelector widget.
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
@@ -17,22 +16,23 @@
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
- *
- * Author: Ettore Perazzoli <ettore@ximian.com>
*/
#include <e-util/e-util.h>
-static const gchar *extension_name;
+#define OPENED_KEY "sources-opened-key"
+#define SOURCE_TYPE_KEY "sources-source-type-key"
+#define EXTENSION_NAME_KEY "sources-extension-name-key"
static void
-dump_selection (ESourceSelector *selector)
+dump_selection (ESourceSelector *selector,
+ const gchar *extension_name)
{
GList *list, *link;
list = e_source_selector_get_selection (selector);
- g_print ("Current selection:\n");
+ g_print ("Current selection at %s:\n", extension_name);
if (list == NULL)
g_print ("\t(None)\n");
@@ -56,81 +56,251 @@ static void
selection_changed_callback (ESourceSelector *selector)
{
g_print ("Selection changed!\n");
- dump_selection (selector);
+ dump_selection (selector, g_object_get_data (G_OBJECT (selector), EXTENSION_NAME_KEY));
}
-static gint
-on_idle_create_widget (ESourceRegistry *registry)
+static void
+enable_widget_if_opened_cb (ESourceSelector *selector,
+ GtkWidget *widget)
{
- GtkWidget *window;
- GtkWidget *vgrid;
- GtkWidget *selector;
- GtkWidget *scrolled_window;
- GtkWidget *check;
+ GHashTable *opened_sources;
+ ESource *source;
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
+ opened_sources = g_object_get_data (G_OBJECT (selector), OPENED_KEY);
+ g_return_if_fail (opened_sources != NULL);
- g_signal_connect (
- window, "delete-event",
- G_CALLBACK (gtk_main_quit), NULL);
+ source = e_source_selector_ref_primary_selection (selector);
+ gtk_widget_set_sensitive (widget, source && g_hash_table_lookup (opened_sources, source) != NULL);
+ if (source)
+ g_object_unref (source);
+}
+
+static void
+disable_widget_if_opened_cb (ESourceSelector *selector,
+ GtkWidget *widget)
+{
+ GHashTable *opened_sources;
+ ESource *source;
- vgrid = g_object_new (
- GTK_TYPE_GRID,
- "orientation", GTK_ORIENTATION_VERTICAL,
- "column-homogeneous", FALSE,
- "row-spacing", 6,
+ opened_sources = g_object_get_data (G_OBJECT (selector), OPENED_KEY);
+ g_return_if_fail (opened_sources != NULL);
+
+ source = e_source_selector_ref_primary_selection (selector);
+ gtk_widget_set_sensitive (widget, source && g_hash_table_lookup (opened_sources, source) == NULL);
+ if (source)
+ g_object_unref (source);
+}
+
+static void
+open_selected_clicked_cb (GtkWidget *button,
+ ESourceSelector *selector)
+{
+ GHashTable *opened_sources;
+ ESource *source;
+
+ opened_sources = g_object_get_data (G_OBJECT (selector), OPENED_KEY);
+ g_return_if_fail (opened_sources != NULL);
+
+ source = e_source_selector_ref_primary_selection (selector);
+ if (!source)
+ return;
+
+ if (!g_hash_table_lookup (opened_sources, source)) {
+ EClient *client;
+ GError *error = NULL;
+ ECalClientSourceType source_type;
+
+ source_type = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (selector), SOURCE_TYPE_KEY));
+ if (source_type == E_CAL_CLIENT_SOURCE_TYPE_LAST)
+ client = e_book_client_connect_sync (source, NULL, &error);
+ else
+ client = e_cal_client_connect_sync (source, source_type, NULL, &error);
+ if (error) {
+ g_warning ("Failed to open '%s': %s", e_source_get_display_name (source), error->message);
+ } else {
+ g_hash_table_insert (opened_sources, g_object_ref (source), client);
+ g_signal_emit_by_name (selector, "primary-selection-changed", 0);
+ }
+ }
+
+ g_object_unref (source);
+}
+
+static void
+close_selected_clicked_cb (GtkWidget *button,
+ ESourceSelector *selector)
+{
+ GHashTable *opened_sources;
+ ESource *source;
+
+ opened_sources = g_object_get_data (G_OBJECT (selector), OPENED_KEY);
+ g_return_if_fail (opened_sources != NULL);
+
+ source = e_source_selector_ref_primary_selection (selector);
+ if (!source)
+ return;
+
+ if (g_hash_table_remove (opened_sources, source))
+ g_signal_emit_by_name (selector, "primary-selection-changed", 0);
+
+ g_object_unref (source);
+}
+
+static GtkWidget *
+create_page (ESourceRegistry *registry,
+ const gchar *extension_name,
+ ECalClientSourceType source_type)
+{
+ GtkWidget *widget, *subwindow, *selector, *button_box;
+ GtkGrid *grid;
+ GHashTable *opened_sources;
+
+ grid = GTK_GRID (gtk_grid_new ());
+
+ subwindow = gtk_scrolled_window_new (NULL, NULL);
+ g_object_set (G_OBJECT (subwindow),
+ "halign", GTK_ALIGN_FILL,
+ "hexpand", TRUE,
+ "valign", GTK_ALIGN_FILL,
+ "vexpand", TRUE,
NULL);
- gtk_container_add (GTK_CONTAINER (window), vgrid);
selector = e_source_selector_new (registry, extension_name);
- g_signal_connect (
- selector, "selection_changed",
- G_CALLBACK (selection_changed_callback), NULL);
+ g_object_set (G_OBJECT (selector),
+ "halign", GTK_ALIGN_FILL,
+ "hexpand", TRUE,
+ "valign", GTK_ALIGN_FILL,
+ "vexpand", TRUE,
+ "show-toggles", FALSE,
+ "show-colors", source_type != E_CAL_CLIENT_SOURCE_TYPE_LAST,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (subwindow), selector);
+
+ gtk_grid_attach (grid, subwindow, 0, 0, 1, 5);
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (
- GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (
- GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (scrolled_window), selector);
- gtk_widget_set_hexpand (scrolled_window, TRUE);
- gtk_widget_set_halign (scrolled_window, GTK_ALIGN_FILL);
- gtk_widget_set_vexpand (scrolled_window, TRUE);
- gtk_widget_set_valign (scrolled_window, GTK_ALIGN_FILL);
- gtk_container_add (GTK_CONTAINER (vgrid), scrolled_window);
-
- check = gtk_check_button_new_with_label ("Show colors");
- gtk_widget_set_halign (check, GTK_ALIGN_FILL);
- gtk_container_add (GTK_CONTAINER (vgrid), check);
+ button_box = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
+ g_object_set (G_OBJECT (button_box),
+ "halign", GTK_ALIGN_START,
+ "hexpand", FALSE,
+ "valign", GTK_ALIGN_START,
+ "vexpand", FALSE,
+ NULL);
+ gtk_grid_attach (grid, button_box, 1, 0, 1, 1);
+
+ widget = gtk_button_new_with_label ("Open selected");
+ gtk_container_add (GTK_CONTAINER (button_box), widget);
+ g_signal_connect (widget, "clicked", G_CALLBACK (open_selected_clicked_cb), selector);
+ g_signal_connect (selector, "primary-selection-changed", G_CALLBACK (disable_widget_if_opened_cb), widget);
+
+ widget = gtk_button_new_with_label ("Close selected");
+ gtk_container_add (GTK_CONTAINER (button_box), widget);
+ g_signal_connect (widget, "clicked", G_CALLBACK (close_selected_clicked_cb), selector);
+ g_signal_connect (selector, "primary-selection-changed", G_CALLBACK (enable_widget_if_opened_cb), widget);
+
+ widget = gtk_label_new ("");
+ g_object_set (G_OBJECT (widget),
+ "halign", GTK_ALIGN_FILL,
+ "hexpand", FALSE,
+ "valign", GTK_ALIGN_FILL,
+ "vexpand", TRUE,
+ NULL);
+ gtk_grid_attach (grid, widget, 1, 1, 1, 1);
+
+ widget = gtk_check_button_new_with_label ("Show colors");
+ g_object_set (G_OBJECT (widget),
+ "halign", GTK_ALIGN_START,
+ "hexpand", FALSE,
+ "valign", GTK_ALIGN_END,
+ "vexpand", FALSE,
+ NULL);
+ gtk_grid_attach (grid, widget, 1, 2, 1, 1);
g_object_bind_property (
selector, "show-colors",
- check, "active",
+ widget, "active",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
- check = gtk_check_button_new_with_label ("Show icons");
- gtk_widget_set_halign (check, GTK_ALIGN_FILL);
- gtk_container_add (GTK_CONTAINER (vgrid), check);
+ widget = gtk_check_button_new_with_label ("Show icons");
+ g_object_set (G_OBJECT (widget),
+ "halign", GTK_ALIGN_START,
+ "hexpand", FALSE,
+ "valign", GTK_ALIGN_END,
+ "vexpand", FALSE,
+ NULL);
+ gtk_grid_attach (grid, widget, 1, 3, 1, 1);
g_object_bind_property (
selector, "show-icons",
- check, "active",
+ widget, "active",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
- check = gtk_check_button_new_with_label ("Show toggles");
- gtk_widget_set_halign (check, GTK_ALIGN_FILL);
- gtk_container_add (GTK_CONTAINER (vgrid), check);
+ widget = gtk_check_button_new_with_label ("Show toggles");
+ g_object_set (G_OBJECT (widget),
+ "halign", GTK_ALIGN_START,
+ "hexpand", FALSE,
+ "valign", GTK_ALIGN_END,
+ "vexpand", FALSE,
+ NULL);
+ gtk_grid_attach (grid, widget, 1, 4, 1, 1);
g_object_bind_property (
selector, "show-toggles",
- check, "active",
+ widget, "active",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
+ opened_sources = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, g_object_unref);
+ g_object_set_data_full (G_OBJECT (selector), OPENED_KEY, opened_sources, (GDestroyNotify) g_hash_table_unref);
+ g_object_set_data (G_OBJECT (selector), SOURCE_TYPE_KEY, GUINT_TO_POINTER (source_type));
+ g_object_set_data_full (G_OBJECT (selector), EXTENSION_NAME_KEY, g_strdup (extension_name), g_free);
+
+ /* update buttons */
+ g_signal_emit_by_name (selector, "primary-selection-changed", 0);
+
+ g_signal_connect (
+ selector, "selection-changed",
+ G_CALLBACK (selection_changed_callback), NULL);
+
+ return GTK_WIDGET (grid);
+}
+
+static gint
+on_idle_create_widget (ESourceRegistry *registry)
+{
+ GtkWidget *window, *notebook;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
+
+ g_signal_connect (
+ window, "delete-event",
+ G_CALLBACK (gtk_main_quit), NULL);
+
+ notebook = gtk_notebook_new ();
+ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (notebook));
+
+ gtk_notebook_append_page (
+ GTK_NOTEBOOK (notebook),
+ create_page (registry, E_SOURCE_EXTENSION_CALENDAR, E_CAL_CLIENT_SOURCE_TYPE_EVENTS),
+ gtk_label_new ("Calendars"));
+
+ gtk_notebook_append_page (
+ GTK_NOTEBOOK (notebook),
+ create_page (registry, E_SOURCE_EXTENSION_MEMO_LIST, E_CAL_CLIENT_SOURCE_TYPE_MEMOS),
+ gtk_label_new ("Memos"));
+
+ gtk_notebook_append_page (
+ GTK_NOTEBOOK (notebook),
+ create_page (registry, E_SOURCE_EXTENSION_TASK_LIST, E_CAL_CLIENT_SOURCE_TYPE_TASKS),
+ gtk_label_new ("Tasks"));
+
+ gtk_notebook_append_page (
+ GTK_NOTEBOOK (notebook),
+ create_page (registry, E_SOURCE_EXTENSION_ADDRESS_BOOK, E_CAL_CLIENT_SOURCE_TYPE_LAST),
+ gtk_label_new ("Books"));
+
gtk_widget_show_all (window);
return FALSE;
@@ -145,11 +315,6 @@ main (gint argc,
gtk_init (&argc, &argv);
- if (argc < 2)
- extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
- else
- extension_name = argv[1];
-
registry = e_source_registry_new_sync (NULL, &error);
if (error != NULL) {
@@ -163,5 +328,7 @@ main (gint argc,
gtk_main ();
+ g_object_unref (registry);
+
return 0;
}