diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-12-09 23:34:55 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2011-12-11 10:34:19 +0800 |
commit | 7c0c40f83317228e0a725bfb5ca8854339d25588 (patch) | |
tree | db1197dd9f336e175c590c3a41201dfa78ee303e /widgets | |
parent | 2f32e1cc68cd416f4530ecc3d2ff08b0e6498d45 (diff) | |
download | gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.gz gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.bz2 gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.lz gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.xz gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.tar.zst gsoc2013-evolution-7c0c40f83317228e0a725bfb5ca8854339d25588.zip |
Reorder accounts by drag-and-drop.
This implements https://bugzilla.gnome.org/show_bug.cgi?id=663527#c3.
Account reordering is now done by drag-and-drop instead of up/down
buttons.
Turned out to be a wee bit more complicated than I initially thought.
This scraps EAccountManager and EAccountTreeView and replaces them with
new classes centered around EMailAccountStore, which EMailSession owns.
EMailAccountStore is the model behind the account list in Preferences.
The folder tree model now uses it to sort its own top-level rows using
gtk_tree_path_compare(). It also broadcasts account operations through
signals so we don't have to rely so heavily on EAccountList signals,
since EAccountList is going away soon.
Also as part of this work, the e-mail-local.h and e-mail-store.h APIs
have been merged into EMailSession and MailFolderCache.
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/misc/Makefile.am | 4 | ||||
-rw-r--r-- | widgets/misc/e-account-manager.c | 536 | ||||
-rw-r--r-- | widgets/misc/e-account-manager.h | 83 | ||||
-rw-r--r-- | widgets/misc/e-account-tree-view.c | 1401 | ||||
-rw-r--r-- | widgets/misc/e-account-tree-view.h | 132 |
5 files changed, 0 insertions, 2156 deletions
diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 5235c1ca54..71194d17ad 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -6,8 +6,6 @@ ui_DATA = e-send-options.ui widgetsinclude_HEADERS = \ e-account-combo-box.h \ - e-account-manager.h \ - e-account-tree-view.h \ e-action-combo-box.h \ e-activity-bar.h \ e-activity-proxy.h \ @@ -91,8 +89,6 @@ libemiscwidgets_la_CPPFLAGS = \ libemiscwidgets_la_SOURCES = \ $(widgetsinclude_HEADERS) \ e-account-combo-box.c \ - e-account-manager.c \ - e-account-tree-view.c \ e-action-combo-box.c \ e-activity-bar.c \ e-activity-proxy.c \ diff --git a/widgets/misc/e-account-manager.c b/widgets/misc/e-account-manager.c deleted file mode 100644 index b2c0583b8b..0000000000 --- a/widgets/misc/e-account-manager.c +++ /dev/null @@ -1,536 +0,0 @@ -/* - * e-account-manager.c - * - * This program 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 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-account-manager.h" - -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include "e-account-tree-view.h" - -struct _EAccountManagerPrivate { - EAccountList *account_list; - - GtkWidget *tree_view; - GtkWidget *add_button; - GtkWidget *edit_button; - GtkWidget *delete_button; - GtkWidget *default_button; - GtkWidget *sort_toggle; - GtkWidget *sort_up_button; - GtkWidget *sort_down_button; -}; - -enum { - PROP_0, - PROP_ACCOUNT_LIST -}; - -enum { - ADD_ACCOUNT, - EDIT_ACCOUNT, - DELETE_ACCOUNT, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -G_DEFINE_TYPE ( - EAccountManager, - e_account_manager, - GTK_TYPE_TABLE) - -static void -account_manager_default_clicked_cb (EAccountManager *manager) -{ - EAccountTreeView *tree_view; - EAccountList *account_list; - EAccount *account; - - tree_view = e_account_manager_get_tree_view (manager); - account_list = e_account_manager_get_account_list (manager); - account = e_account_tree_view_get_selected (tree_view); - g_return_if_fail (account != NULL); - - e_account_list_set_default (account_list, account); - - /* This signals the tree view to refresh. */ - e_account_list_change (account_list, account); -} - -static gboolean -account_manager_key_press_event_cb (EAccountManager *manager, - GdkEventKey *event) -{ - if (event->keyval == GDK_KEY_Delete) { - e_account_manager_delete_account (manager); - return TRUE; - } - - return FALSE; -} - -static void -account_manager_selection_changed_cb (EAccountManager *manager, - GtkTreeSelection *selection) -{ - EAccountTreeView *tree_view; - EAccountList *account_list; - EAccount *default_account; - EAccount *account; - GtkTreeModel *model = NULL; - GtkTreeIter iter1, iter2; - GtkWidget *add_button; - GtkWidget *edit_button; - GtkWidget *delete_button; - GtkWidget *default_button; - GtkWidget *sort_up_button; - GtkWidget *sort_down_button; - gboolean sensitive; - - add_button = manager->priv->add_button; - edit_button = manager->priv->edit_button; - delete_button = manager->priv->delete_button; - default_button = manager->priv->default_button; - sort_up_button = manager->priv->sort_up_button; - sort_down_button = manager->priv->sort_down_button; - - tree_view = e_account_manager_get_tree_view (manager); - account = e_account_tree_view_get_selected (tree_view); - account_list = e_account_tree_view_get_account_list (tree_view); - - if (account == NULL) - gtk_widget_grab_focus (add_button); - - /* XXX EAccountList misuses const */ - default_account = (EAccount *) - e_account_list_get_default (account_list); - - sensitive = (account != NULL); - gtk_widget_set_sensitive (edit_button, sensitive); - - sensitive = (account != NULL); - gtk_widget_set_sensitive (delete_button, sensitive); - - sensitive = (account != NULL && account != default_account); - gtk_widget_set_sensitive (default_button, sensitive); - - sensitive = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (manager->priv->sort_toggle)) && - gtk_tree_selection_get_selected (selection, &model, &iter1); - iter2 = iter1; - gtk_widget_set_sensitive (sort_up_button, sensitive && gtk_tree_model_iter_previous (model, &iter1)); - gtk_widget_set_sensitive (sort_down_button, sensitive && gtk_tree_model_iter_next (model, &iter2)); -} - -static void -account_manager_sort_toggled_cb (EAccountManager *manager) -{ - GtkTreeView *tree_view; - GtkTreeSelection *selection; - - tree_view = GTK_TREE_VIEW (e_account_manager_get_tree_view (manager)); - selection = gtk_tree_view_get_selection (tree_view); - - account_manager_selection_changed_cb (manager, selection); -} - -static void -account_manager_sort_up_cb (EAccountManager *manager) -{ - GtkTreeView *tree_view; - GtkTreeSelection *selection; - - tree_view = GTK_TREE_VIEW (e_account_manager_get_tree_view (manager)); - selection = gtk_tree_view_get_selection (tree_view); - - e_account_tree_view_move_up (e_account_manager_get_tree_view (manager)); - account_manager_selection_changed_cb (manager, selection); -} - -static void -account_manager_sort_down_cb (EAccountManager *manager) -{ - GtkTreeView *tree_view; - GtkTreeSelection *selection; - - tree_view = GTK_TREE_VIEW (e_account_manager_get_tree_view (manager)); - selection = gtk_tree_view_get_selection (tree_view); - - e_account_tree_view_move_down (e_account_manager_get_tree_view (manager)); - account_manager_selection_changed_cb (manager, selection); -} - -static void -account_manager_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ACCOUNT_LIST: - e_account_manager_set_account_list ( - E_ACCOUNT_MANAGER (object), - g_value_get_object (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -account_manager_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ACCOUNT_LIST: - g_value_set_object ( - value, - e_account_manager_get_account_list ( - E_ACCOUNT_MANAGER (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -account_manager_dispose (GObject *object) -{ - EAccountManagerPrivate *priv; - - priv = E_ACCOUNT_MANAGER (object)->priv; - - if (priv->account_list != NULL) { - g_object_unref (priv->account_list); - priv->account_list = NULL; - } - - if (priv->tree_view != NULL) { - g_object_unref (priv->tree_view); - priv->tree_view = NULL; - } - - if (priv->add_button != NULL) { - g_object_unref (priv->add_button); - priv->add_button = NULL; - } - - if (priv->edit_button != NULL) { - g_object_unref (priv->edit_button); - priv->edit_button = NULL; - } - - if (priv->delete_button != NULL) { - g_object_unref (priv->delete_button); - priv->delete_button = NULL; - } - - if (priv->sort_toggle != NULL) { - g_object_unref (priv->sort_toggle); - priv->sort_toggle = NULL; - } - - if (priv->sort_up_button != NULL) { - g_object_unref (priv->sort_up_button); - priv->sort_up_button = NULL; - } - - if (priv->sort_down_button != NULL) { - g_object_unref (priv->sort_down_button); - priv->sort_down_button = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_account_manager_parent_class)->dispose (object); -} - -static void -e_account_manager_class_init (EAccountManagerClass *class) -{ - GObjectClass *object_class; - - g_type_class_add_private (class, sizeof (EAccountManagerPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = account_manager_set_property; - object_class->get_property = account_manager_get_property; - object_class->dispose = account_manager_dispose; - - /* XXX If we moved the account editor to /widgets/misc we - * could handle adding and editing accounts directly. */ - - g_object_class_install_property ( - object_class, - PROP_ACCOUNT_LIST, - g_param_spec_object ( - "account-list", - "Account List", - NULL, - E_TYPE_ACCOUNT_LIST, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - signals[ADD_ACCOUNT] = g_signal_new ( - "add-account", - G_OBJECT_CLASS_TYPE (class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EAccountManagerClass, add_account), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[EDIT_ACCOUNT] = g_signal_new ( - "edit-account", - G_OBJECT_CLASS_TYPE (class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EAccountManagerClass, edit_account), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[DELETE_ACCOUNT] = g_signal_new ( - "delete-account", - G_OBJECT_CLASS_TYPE (class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EAccountManagerClass, delete_account), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -e_account_manager_init (EAccountManager *manager) -{ - GtkTreeSelection *selection; - GtkWidget *container; - GtkWidget *widget; - - manager->priv = G_TYPE_INSTANCE_GET_PRIVATE ( - manager, E_TYPE_ACCOUNT_MANAGER, EAccountManagerPrivate); - - gtk_table_resize (GTK_TABLE (manager), 1, 2); - gtk_table_set_col_spacings (GTK_TABLE (manager), 6); - gtk_table_set_row_spacings (GTK_TABLE (manager), 12); - - container = GTK_WIDGET (manager); - - widget = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy ( - GTK_SCROLLED_WINDOW (widget), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type ( - GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); - gtk_table_attach ( - GTK_TABLE (container), widget, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (widget); - - container = widget; - - widget = e_account_tree_view_new (); - gtk_container_add (GTK_CONTAINER (container), widget); - manager->priv->tree_view = g_object_ref (widget); - gtk_widget_show (widget); - - g_object_bind_property ( - manager, "account-list", - widget, "account-list", - G_BINDING_BIDIRECTIONAL | - G_BINDING_SYNC_CREATE); - - g_signal_connect_swapped ( - widget, "key-press-event", - G_CALLBACK (account_manager_key_press_event_cb), - manager); - - g_signal_connect_swapped ( - widget, "row-activated", - G_CALLBACK (e_account_manager_edit_account), - manager); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); - - g_signal_connect_swapped ( - selection, "changed", - G_CALLBACK (account_manager_selection_changed_cb), - manager); - - container = GTK_WIDGET (manager); - - widget = gtk_check_button_new_with_mnemonic (_("Use default Evolution _sort order for accounts")); - manager->priv->sort_toggle = g_object_ref (widget); - gtk_widget_show (widget); - gtk_table_attach ( - GTK_TABLE (container), widget, 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, 0, 4, 0); - - g_object_bind_property ( - manager->priv->tree_view, "sort-alpha", - widget, "active", - G_BINDING_BIDIRECTIONAL | - G_BINDING_SYNC_CREATE); - - g_signal_connect_swapped ( - widget, "toggled", - G_CALLBACK (account_manager_sort_toggled_cb), manager); - - widget = gtk_vbutton_box_new (); - gtk_button_box_set_layout ( - GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_START); - gtk_box_set_spacing (GTK_BOX (widget), 6); - gtk_table_attach ( - GTK_TABLE (container), widget, - 1, 2, 0, 2, 0, GTK_FILL, 0, 0); - gtk_widget_show (widget); - - container = widget; - - widget = gtk_button_new_from_stock (GTK_STOCK_ADD); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - manager->priv->add_button = g_object_ref (widget); - gtk_widget_show (widget); - - g_signal_connect_swapped ( - widget, "clicked", - G_CALLBACK (e_account_manager_add_account), manager); - - widget = gtk_button_new_from_stock (GTK_STOCK_EDIT); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - manager->priv->edit_button = g_object_ref (widget); - gtk_widget_show (widget); - - g_signal_connect_swapped ( - widget, "clicked", - G_CALLBACK (e_account_manager_edit_account), manager); - - widget = gtk_button_new_from_stock (GTK_STOCK_DELETE); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - manager->priv->delete_button = g_object_ref (widget); - gtk_widget_show (widget); - - g_signal_connect_swapped ( - widget, "clicked", - G_CALLBACK (e_account_manager_delete_account), manager); - - widget = gtk_button_new_with_mnemonic (_("De_fault")); - gtk_button_set_image ( - GTK_BUTTON (widget), gtk_image_new_from_icon_name ( - "emblem-default", GTK_ICON_SIZE_BUTTON)); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - manager->priv->default_button = g_object_ref (widget); - gtk_widget_show (widget); - - g_signal_connect_swapped ( - widget, "clicked", - G_CALLBACK (account_manager_default_clicked_cb), manager); - - widget = gtk_button_new_from_stock (GTK_STOCK_GO_UP); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - manager->priv->sort_up_button = g_object_ref (widget); - gtk_widget_show (widget); - - g_signal_connect_swapped ( - widget, "clicked", - G_CALLBACK (account_manager_sort_up_cb), manager); - - widget = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - manager->priv->sort_down_button = g_object_ref (widget); - gtk_widget_show (widget); - - g_signal_connect_swapped ( - widget, "clicked", - G_CALLBACK (account_manager_sort_down_cb), manager); -} - -GtkWidget * -e_account_manager_new (EAccountList *account_list) -{ - g_return_val_if_fail (E_IS_ACCOUNT_LIST (account_list), NULL); - - return g_object_new ( - E_TYPE_ACCOUNT_MANAGER, - "account-list", account_list, NULL); -} - -void -e_account_manager_add_account (EAccountManager *manager) -{ - g_return_if_fail (E_IS_ACCOUNT_MANAGER (manager)); - - g_signal_emit (manager, signals[ADD_ACCOUNT], 0); -} - -void -e_account_manager_edit_account (EAccountManager *manager) -{ - g_return_if_fail (E_IS_ACCOUNT_MANAGER (manager)); - - g_signal_emit (manager, signals[EDIT_ACCOUNT], 0); -} - -void -e_account_manager_delete_account (EAccountManager *manager) -{ - g_return_if_fail (E_IS_ACCOUNT_MANAGER (manager)); - - g_signal_emit (manager, signals[DELETE_ACCOUNT], 0); -} - -EAccountList * -e_account_manager_get_account_list (EAccountManager *manager) -{ - g_return_val_if_fail (E_IS_ACCOUNT_MANAGER (manager), NULL); - - return manager->priv->account_list; -} - -void -e_account_manager_set_account_list (EAccountManager *manager, - EAccountList *account_list) -{ - g_return_if_fail (E_IS_ACCOUNT_MANAGER (manager)); - - if (account_list != NULL) { - g_return_if_fail (E_IS_ACCOUNT_LIST (account_list)); - g_object_ref (account_list); - } - - if (manager->priv->account_list != NULL) - g_object_unref (manager->priv->account_list); - - manager->priv->account_list = account_list; - - g_object_notify (G_OBJECT (manager), "account-list"); -} - -EAccountTreeView * -e_account_manager_get_tree_view (EAccountManager *manager) -{ - g_return_val_if_fail (E_IS_ACCOUNT_MANAGER (manager), NULL); - - return E_ACCOUNT_TREE_VIEW (manager->priv->tree_view); -} diff --git a/widgets/misc/e-account-manager.h b/widgets/misc/e-account-manager.h deleted file mode 100644 index 0dc5892b2e..0000000000 --- a/widgets/misc/e-account-manager.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * e-account-manager.h - * - * This program 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 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_ACCOUNT_MANAGER_H -#define E_ACCOUNT_MANAGER_H - -#include <gtk/gtk.h> -#include <libedataserver/e-account-list.h> -#include <misc/e-account-tree-view.h> - -/* Standard GObject macros */ -#define E_TYPE_ACCOUNT_MANAGER \ - (e_account_manager_get_type ()) -#define E_ACCOUNT_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_ACCOUNT_MANAGER, EAccountManager)) -#define E_ACCOUNT_MANAGER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_ACCOUNT_MANAGER, EAccountManagerClass)) -#define E_IS_ACCOUNT_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_ACCOUNT_MANAGER)) -#define E_IS_ACCOUNT_MANAGER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_ACCOUNT_MANAGER)) -#define E_ACCOUNT_MANAGER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_ACCOUNT_MANAGER, EAccountManagerClass)) - -G_BEGIN_DECLS - -typedef struct _EAccountManager EAccountManager; -typedef struct _EAccountManagerClass EAccountManagerClass; -typedef struct _EAccountManagerPrivate EAccountManagerPrivate; - -struct _EAccountManager { - GtkTable parent; - EAccountManagerPrivate *priv; -}; - -struct _EAccountManagerClass { - GtkTableClass parent_class; - - void (*add_account) (EAccountManager *manager); - void (*edit_account) (EAccountManager *manager); - void (*delete_account) (EAccountManager *manager); -}; - -GType e_account_manager_get_type (void); -GtkWidget * e_account_manager_new (EAccountList *account_list); -void e_account_manager_add_account (EAccountManager *manager); -void e_account_manager_edit_account (EAccountManager *manager); -void e_account_manager_delete_account - (EAccountManager *manager); -EAccountList * e_account_manager_get_account_list - (EAccountManager *manager); -void e_account_manager_set_account_list - (EAccountManager *manager, - EAccountList *account_list); -EAccountTreeView * - e_account_manager_get_tree_view (EAccountManager *manager); - -G_END_DECLS - -#endif /* E_ACCOUNT_MANAGER_H */ diff --git a/widgets/misc/e-account-tree-view.c b/widgets/misc/e-account-tree-view.c deleted file mode 100644 index bd21668e2f..0000000000 --- a/widgets/misc/e-account-tree-view.c +++ /dev/null @@ -1,1401 +0,0 @@ -/* - * e-account-tree-view.c - * - * This program 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 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-account-tree-view.h" - -#include <glib/gi18n.h> -#include <camel/camel.h> - -enum { - COLUMN_ACCOUNT, - COLUMN_DEFAULT, - COLUMN_ENABLED, - COLUMN_NAME, - COLUMN_PROTOCOL, - COLUMN_SORTORDER -}; - -enum { - PROP_0, - PROP_ACCOUNT_LIST, - PROP_SELECTED, - PROP_SORT_ALPHA, - PROP_EXPRESS_MODE, - PROP_ENABLE_LOCAL_FOLDERS, - PROP_ENABLE_SEARCH_FOLDERS -}; - -enum { - ENABLE_ACCOUNT, - DISABLE_ACCOUNT, - REFRESHED, - SORT_ORDER_CHANGED, - LAST_SIGNAL -}; - -struct _EAccountTreeViewPrivate { - EAccountList *account_list; - GHashTable *index; - gboolean sort_alpha; - gboolean express_mode; - gboolean enable_local_folders; - gboolean enable_search_folders; -}; - -static guint signals[LAST_SIGNAL]; - -G_DEFINE_TYPE ( - EAccountTreeView, - e_account_tree_view, - GTK_TYPE_TREE_VIEW) - -static gint -account_tree_view_sort (GtkTreeModel *model, - GtkTreeIter *a, - GtkTreeIter *b, - gpointer user_data) -{ - gint rv = -2; - gchar *aname = NULL, *bname = NULL; - EAccount *aaccount = NULL, *baccount = NULL; - guint asortorder = 0, bsortorder = 0; - - gtk_tree_model_get (model, a, - COLUMN_ACCOUNT, &aaccount, - COLUMN_NAME, &aname, - COLUMN_SORTORDER, &asortorder, - -1); - - gtk_tree_model_get (model, b, - COLUMN_ACCOUNT, &baccount, - COLUMN_NAME, &bname, - COLUMN_SORTORDER, &bsortorder, - -1); - - if ((!aaccount || !baccount || !e_account_tree_view_get_sort_alpha (user_data)) && aname && bname) { - if (e_account_tree_view_get_sort_alpha (user_data)) { - const gchar *on_this_computer = _("On This Computer"); - const gchar *search_folders = _("Search Folders"); - - if (e_account_tree_view_get_express_mode (user_data)) { - if (g_str_equal (aname, on_this_computer) && - g_str_equal (bname, search_folders)) - rv = -1; - else if (g_str_equal (bname, on_this_computer) && - g_str_equal (aname, search_folders)) - rv = 1; - else if (g_str_equal (aname, on_this_computer)) - rv = 1; - else if (g_str_equal (bname, on_this_computer)) - rv = -1; - else if (g_str_equal (aname, search_folders)) - rv = 1; - else if (g_str_equal (bname, search_folders)) - rv = -1; - } else { - if (g_str_equal (aname, on_this_computer)) - rv = -1; - else if (g_str_equal (bname, on_this_computer)) - rv = 1; - else if (g_str_equal (aname, search_folders)) - rv = 1; - else if (g_str_equal (bname, search_folders)) - rv = -1; - } - } else { - if (asortorder < bsortorder) - rv = -1; - else if (asortorder > bsortorder) - rv = 1; - else - rv = 0; - } - } - - if (rv == -2) { - if (aname == NULL) { - if (bname == NULL) - rv = 0; - else - rv = -1; - } else if (bname == NULL) - rv = 1; - - if (rv == -2) - rv = g_utf8_collate (aname, bname); - } - - g_free (aname); - g_free (bname); - - if (aaccount) - g_object_unref (aaccount); - if (baccount) - g_object_unref (baccount); - - return rv; -} - -static void -account_tree_view_normalize_sortorder_column (EAccountTreeView *tree_view) -{ - GtkListStore *list_store; - GtkTreeModel *model; - GtkTreeIter iter; - guint index; - - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - if (!model || !gtk_tree_model_get_iter_first (model, &iter)) - return; - - list_store = GTK_LIST_STORE (model); - g_return_if_fail (list_store != NULL); - - index = 1; - do { - gtk_list_store_set (list_store, &iter, COLUMN_SORTORDER, index, -1); - - index++; - } while (gtk_tree_model_iter_next (model, &iter)); -} - -static gboolean -account_tree_view_refresh_timeout_cb (gpointer ptree_view) -{ - EAccountTreeView *tree_view; - EAccountTreeViewSelectedType selected; - EAccountList *account_list; - EAccount *account; - GtkListStore *store; - GtkTreeModel *model; - GtkTreeIter tree_iter; - EIterator *account_iter; - EAccount *default_account; - GHashTable *index; - GSList *sort_order; - GList *list = NULL; - GList *iter; - - tree_view = ptree_view; - account_list = e_account_tree_view_get_account_list (tree_view); - sort_order = e_account_tree_view_get_sort_order (tree_view); - - store = gtk_list_store_new ( - 6, E_TYPE_ACCOUNT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT); - model = GTK_TREE_MODEL (store); - index = tree_view->priv->index; - - gtk_tree_sortable_set_default_sort_func ( - GTK_TREE_SORTABLE (model), - account_tree_view_sort, tree_view, NULL); - gtk_tree_sortable_set_sort_column_id ( - GTK_TREE_SORTABLE (model), - GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, - GTK_SORT_ASCENDING); - - g_hash_table_remove_all (index); - - if (account_list == NULL) - goto skip; - - /* XXX EAccountList misuses const. */ - default_account = (EAccount *) - e_account_list_get_default (account_list); - - /* Build a list of EAccounts to display. */ - account_iter = e_list_get_iterator (E_LIST (account_list)); - while (e_iterator_is_valid (account_iter)) { - /* XXX EIterator misuses const. */ - account = (EAccount *) e_iterator_get (account_iter); - list = g_list_prepend (list, account); - e_iterator_next (account_iter); - } - g_object_unref (account_iter); - - list = g_list_reverse (list); - - /* Populate the list store and index. */ - for (iter = list; iter != NULL; iter = iter->next) { - GtkTreeRowReference *reference; - GtkTreePath *path; - CamelURL *url = NULL; - gboolean is_default; - const gchar *protocol; - - account = iter->data; - - /* Skip proxy accounts. */ - if (account->parent_uid != NULL) - continue; - - is_default = (account == default_account); - - if (account->source != NULL && account->source->url != NULL) - url = camel_url_new (account->source->url, NULL); - - if (url != NULL && url->protocol != NULL) - protocol = url->protocol; - else - protocol = C_("mail-receiving", "None"); - - gtk_list_store_append (store, &tree_iter); - gtk_list_store_set ( - store, &tree_iter, - COLUMN_ACCOUNT, account, - COLUMN_DEFAULT, is_default, - COLUMN_ENABLED, account->enabled, - COLUMN_NAME, account->name, - COLUMN_PROTOCOL, protocol, -1); - - path = gtk_tree_model_get_path (model, &tree_iter); - reference = gtk_tree_row_reference_new (model, path); - g_hash_table_insert (index, account, reference); - gtk_tree_path_free (path); - - if (url != NULL) - camel_url_free (url); - } - - gtk_list_store_append (store, &tree_iter); - gtk_list_store_set ( - store, &tree_iter, - COLUMN_ACCOUNT, NULL, - COLUMN_DEFAULT, FALSE, - COLUMN_ENABLED, tree_view->priv->enable_local_folders, - COLUMN_NAME, _("On This Computer"), - COLUMN_PROTOCOL, NULL, - -1); - - gtk_list_store_append (store, &tree_iter); - gtk_list_store_set ( - store, &tree_iter, - COLUMN_ACCOUNT, NULL, - COLUMN_DEFAULT, FALSE, - COLUMN_ENABLED, tree_view->priv->enable_search_folders, - COLUMN_NAME, _("Search Folders"), - COLUMN_PROTOCOL, NULL, - -1); - - g_list_free (list); - - skip: - /* Restore the previously selected account. */ - selected = e_account_tree_view_get_selected_type (tree_view); - account = e_account_tree_view_get_selected (tree_view); - if (account != NULL) - g_object_ref (account); - gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model); - e_account_tree_view_set_selected (tree_view, account); - if (account != NULL) - g_object_unref (account); - else if (selected == E_ACCOUNT_TREE_VIEW_SELECTED_LOCAL || - selected == E_ACCOUNT_TREE_VIEW_SELECTED_VFOLDER) - e_account_tree_view_set_selected_type (tree_view, selected); - - e_account_tree_view_set_sort_order (tree_view, sort_order); - g_slist_foreach (sort_order, (GFunc) g_free, NULL); - g_slist_free (sort_order); - - g_signal_emit (tree_view, signals[REFRESHED], 0); - - return FALSE; -} - -static void -account_tree_view_refresh_cb (EAccountList *account_list, - EAccount *account, - EAccountTreeView *tree_view) -{ - g_timeout_add (10, account_tree_view_refresh_timeout_cb, tree_view); -} - -static void -account_tree_view_enabled_toggled_cb (EAccountTreeView *tree_view, - gchar *path_string, - GtkCellRendererToggle *renderer) -{ - GtkTreeSelection *selection; - GtkTreePath *path; - - /* Change the selection first so we enable or disable the - * correct account. */ - path = gtk_tree_path_new_from_string (path_string); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - gtk_tree_selection_select_path (selection, path); - gtk_tree_path_free (path); - - if (gtk_cell_renderer_toggle_get_active (renderer)) - e_account_tree_view_disable_account (tree_view); - else - e_account_tree_view_enable_account (tree_view); -} - -static void -account_tree_view_selection_changed_cb (EAccountTreeView *tree_view) -{ - g_object_notify (G_OBJECT (tree_view), "selected"); -} - -static GObject * -account_tree_view_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *object; - GObjectClass *parent_class; - GtkTreeView *tree_view; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - - /* Chain up to parent's constructor() method. */ - parent_class = G_OBJECT_CLASS (e_account_tree_view_parent_class); - object = parent_class->constructor ( - type, n_construct_properties, construct_properties); - - tree_view = GTK_TREE_VIEW (object); - gtk_tree_view_set_headers_visible (tree_view, TRUE); - - /* Column: Enabled */ - - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_expand (column, FALSE); - gtk_tree_view_column_set_title (column, _("Enabled")); - - renderer = gtk_cell_renderer_toggle_new (); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - - g_signal_connect_swapped ( - renderer, "toggled", - G_CALLBACK (account_tree_view_enabled_toggled_cb), - tree_view); - - gtk_tree_view_column_add_attribute ( - column, renderer, "active", COLUMN_ENABLED); - - gtk_tree_view_append_column (tree_view, column); - - /* Column: Account Name */ - - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_expand (column, TRUE); - gtk_tree_view_column_set_title (column, _("Account Name")); - - renderer = gtk_cell_renderer_text_new (); - g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - - gtk_tree_view_column_add_attribute ( - column, renderer, "text", COLUMN_NAME); - - renderer = gtk_cell_renderer_text_new (); - g_object_set (renderer, "text", _("Default"), NULL); - gtk_tree_view_column_pack_end (column, renderer, FALSE); - - gtk_tree_view_column_add_attribute ( - column, renderer, "visible", COLUMN_DEFAULT); - - renderer = gtk_cell_renderer_pixbuf_new (); - g_object_set ( - renderer, "icon-name", "emblem-default", - "stock-size", GTK_ICON_SIZE_MENU, NULL); - gtk_tree_view_column_pack_end (column, renderer, FALSE); - - gtk_tree_view_column_add_attribute ( - column, renderer, "visible", COLUMN_DEFAULT); - - gtk_tree_view_append_column (tree_view, column); - - /* Column: Protocol */ - - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_expand (column, FALSE); - gtk_tree_view_column_set_title (column, _("Protocol")); - - renderer = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - - gtk_tree_view_column_add_attribute ( - column, renderer, "text", COLUMN_PROTOCOL); - - gtk_tree_view_append_column (tree_view, column); - - return object; -} - -static void -account_tree_view_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ACCOUNT_LIST: - e_account_tree_view_set_account_list ( - E_ACCOUNT_TREE_VIEW (object), - g_value_get_object (value)); - return; - - case PROP_SELECTED: - e_account_tree_view_set_selected ( - E_ACCOUNT_TREE_VIEW (object), - g_value_get_object (value)); - return; - case PROP_SORT_ALPHA: - e_account_tree_view_set_sort_alpha ( - E_ACCOUNT_TREE_VIEW (object), - g_value_get_boolean (value)); - return; - case PROP_EXPRESS_MODE: - e_account_tree_view_set_express_mode ( - E_ACCOUNT_TREE_VIEW (object), - g_value_get_boolean (value)); - return; - case PROP_ENABLE_LOCAL_FOLDERS: - e_account_tree_view_set_enable_local_folders ( - E_ACCOUNT_TREE_VIEW (object), - g_value_get_boolean (value)); - return; - case PROP_ENABLE_SEARCH_FOLDERS: - e_account_tree_view_set_enable_search_folders ( - E_ACCOUNT_TREE_VIEW (object), - g_value_get_boolean (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -account_tree_view_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ACCOUNT_LIST: - g_value_set_object ( - value, - e_account_tree_view_get_account_list ( - E_ACCOUNT_TREE_VIEW (object))); - return; - - case PROP_SELECTED: - g_value_set_object ( - value, - e_account_tree_view_get_selected ( - E_ACCOUNT_TREE_VIEW (object))); - return; - case PROP_SORT_ALPHA: - g_value_set_boolean ( - value, - e_account_tree_view_get_sort_alpha ( - E_ACCOUNT_TREE_VIEW (object))); - return; - case PROP_EXPRESS_MODE: - g_value_set_boolean ( - value, - e_account_tree_view_get_express_mode ( - E_ACCOUNT_TREE_VIEW (object))); - return; - case PROP_ENABLE_LOCAL_FOLDERS: - g_value_set_boolean ( - value, - e_account_tree_view_get_enable_local_folders ( - E_ACCOUNT_TREE_VIEW (object))); - return; - case PROP_ENABLE_SEARCH_FOLDERS: - g_value_set_boolean ( - value, - e_account_tree_view_get_enable_search_folders ( - E_ACCOUNT_TREE_VIEW (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -account_tree_view_dispose (GObject *object) -{ - EAccountTreeViewPrivate *priv; - - priv = E_ACCOUNT_TREE_VIEW (object)->priv; - - if (priv->account_list != NULL) { - g_signal_handlers_disconnect_by_func ( - priv->account_list, - account_tree_view_refresh_cb, object); - g_object_unref (priv->account_list); - priv->account_list = NULL; - } - - g_hash_table_remove_all (priv->index); - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_account_tree_view_parent_class)->dispose (object); -} - -static void -account_tree_view_finalize (GObject *object) -{ - EAccountTreeViewPrivate *priv; - - priv = E_ACCOUNT_TREE_VIEW (object)->priv; - - g_hash_table_destroy (priv->index); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_account_tree_view_parent_class)->finalize (object); -} - -static void -account_tree_view_enable_account (EAccountTreeView *tree_view) -{ - EAccountList *account_list; - EAccount *account; - - account = e_account_tree_view_get_selected (tree_view); - if (account == NULL || account->enabled) - return; - - account_list = e_account_tree_view_get_account_list (tree_view); - g_return_if_fail (account_list != NULL); - - account->enabled = TRUE; - e_account_list_change (account_list, account); - - e_account_list_save (account_list); -} - -static void -account_tree_view_disable_account (EAccountTreeView *tree_view) -{ - EAccountList *account_list; - EAccount *account; - - account = e_account_tree_view_get_selected (tree_view); - if (account == NULL || !account->enabled) - return; - - account_list = e_account_tree_view_get_account_list (tree_view); - g_return_if_fail (account_list != NULL); - - account->enabled = FALSE; - e_account_list_change (account_list, account); - - e_account_list_save (account_list); -} - -static void -e_account_tree_view_class_init (EAccountTreeViewClass *class) -{ - GObjectClass *object_class; - - g_type_class_add_private (class, sizeof (EAccountTreeViewPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->constructor = account_tree_view_constructor; - object_class->set_property = account_tree_view_set_property; - object_class->get_property = account_tree_view_get_property; - object_class->dispose = account_tree_view_dispose; - object_class->finalize = account_tree_view_finalize; - - class->enable_account = account_tree_view_enable_account; - class->disable_account = account_tree_view_disable_account; - - g_object_class_install_property ( - object_class, - PROP_SELECTED, - g_param_spec_object ( - "selected", - "Selected Account", - NULL, - E_TYPE_ACCOUNT, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_ACCOUNT_LIST, - g_param_spec_object ( - "account-list", - "Account List", - NULL, - E_TYPE_ACCOUNT_LIST, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_SORT_ALPHA, - g_param_spec_boolean ( - "sort-alpha", - "Sort alphabetically", - NULL, - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_EXPRESS_MODE, - g_param_spec_boolean ( - "express-mode", - "Express Mode sorting", - NULL, - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_ENABLE_LOCAL_FOLDERS, - g_param_spec_boolean ( - "enable-local-folders", - "Enable Local Folders", - NULL, - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_ENABLE_SEARCH_FOLDERS, - g_param_spec_boolean ( - "enable-search-folders", - "Enable Search Folders", - NULL, - TRUE, - G_PARAM_READWRITE)); - - signals[ENABLE_ACCOUNT] = g_signal_new ( - "enable-account", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EAccountTreeViewClass, enable_account), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[DISABLE_ACCOUNT] = g_signal_new ( - "disable-account", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EAccountTreeViewClass, disable_account), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[REFRESHED] = g_signal_new ( - "refreshed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EAccountTreeViewClass, refreshed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[SORT_ORDER_CHANGED] = g_signal_new ( - "sort-order-changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EAccountTreeViewClass, sort_order_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -e_account_tree_view_init (EAccountTreeView *tree_view) -{ - GHashTable *index; - GtkTreeSelection *selection; - - /* Reverse-lookup index */ - index = g_hash_table_new_full ( - g_direct_hash, g_direct_equal, - (GDestroyNotify) g_object_unref, - (GDestroyNotify) gtk_tree_row_reference_free); - - tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE ( - tree_view, E_TYPE_ACCOUNT_TREE_VIEW, EAccountTreeViewPrivate); - tree_view->priv->index = index; - tree_view->priv->sort_alpha = TRUE; - tree_view->priv->express_mode = FALSE; - tree_view->priv->enable_local_folders = TRUE; - tree_view->priv->enable_search_folders = TRUE; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - - g_signal_connect_swapped ( - selection, "changed", - G_CALLBACK (account_tree_view_selection_changed_cb), - tree_view); -} - -GtkWidget * -e_account_tree_view_new (void) -{ - return g_object_new (E_TYPE_ACCOUNT_TREE_VIEW, NULL); -} - -void -e_account_tree_view_enable_account (EAccountTreeView *tree_view) -{ - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - g_signal_emit (tree_view, signals[ENABLE_ACCOUNT], 0); -} - -void -e_account_tree_view_disable_account (EAccountTreeView *tree_view) -{ - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - g_signal_emit (tree_view, signals[DISABLE_ACCOUNT], 0); -} - -EAccountList * -e_account_tree_view_get_account_list (EAccountTreeView *tree_view) -{ - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), NULL); - - return tree_view->priv->account_list; -} - -void -e_account_tree_view_set_account_list (EAccountTreeView *tree_view, - EAccountList *account_list) -{ - EAccountTreeViewPrivate *priv; - - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - if (account_list != NULL) - g_return_if_fail (E_IS_ACCOUNT_LIST (account_list)); - - priv = tree_view->priv; - - if (priv->account_list != NULL) { - g_signal_handlers_disconnect_by_func ( - priv->account_list, - account_tree_view_refresh_cb, tree_view); - g_object_unref (priv->account_list); - priv->account_list = NULL; - } - - if (account_list != NULL) { - priv->account_list = g_object_ref (account_list); - - /* Listen for changes to the account list. */ - g_signal_connect ( - priv->account_list, "account-added", - G_CALLBACK (account_tree_view_refresh_cb), - tree_view); - g_signal_connect ( - priv->account_list, "account-changed", - G_CALLBACK (account_tree_view_refresh_cb), - tree_view); - g_signal_connect ( - priv->account_list, "account-removed", - G_CALLBACK (account_tree_view_refresh_cb), - tree_view); - } - - account_tree_view_refresh_timeout_cb (tree_view); - - g_object_notify (G_OBJECT (tree_view), "account-list"); -} - -EAccount * -e_account_tree_view_get_selected (EAccountTreeView *tree_view) -{ - EAccount *account; - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), NULL); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return NULL; - - gtk_tree_model_get (model, &iter, COLUMN_ACCOUNT, &account, -1); - - return account; -} - -gboolean -e_account_tree_view_set_selected (EAccountTreeView *tree_view, - EAccount *account) -{ - GtkTreeRowReference *reference; - GtkTreeSelection *selection; - GtkTreePath *path; - - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), FALSE); - - if (account != NULL) - g_return_val_if_fail (E_IS_ACCOUNT (account), FALSE); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - - /* NULL means clear the selection. */ - if (account == NULL) { - gtk_tree_selection_unselect_all (selection); - return TRUE; - } - - /* Lookup the tree row reference for the account. */ - reference = g_hash_table_lookup (tree_view->priv->index, account); - if (reference == NULL) - return FALSE; - - /* Select the referenced path. */ - path = gtk_tree_row_reference_get_path (reference); - gtk_tree_selection_select_path (selection, path); - gtk_tree_path_free (path); - - g_object_notify (G_OBJECT (tree_view), "selected"); - - return TRUE; -} - -/** - * e_account_tree_view_get_selected_type: - * @tree_view: an #EAccountTreeView - * - * Returns: What node type is selected. This is useful for virtual - * nodes "On This Computer" and "Search Folders", which doesn't have - * their #EAccount representations. if the function returns - * #E_ACCOUNT_TREE_VIEW_SELECTED_ACCOUNT, then the selected account - * can be obtained with e_account_tree_view_get_selected(). - * - * Since: 3.4 - **/ -EAccountTreeViewSelectedType -e_account_tree_view_get_selected_type (EAccountTreeView *tree_view) -{ - EAccountTreeViewSelectedType res = E_ACCOUNT_TREE_VIEW_SELECTED_NONE; - EAccount *account = NULL; - gchar *name = NULL; - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - - g_return_val_if_fail (tree_view != NULL, E_ACCOUNT_TREE_VIEW_SELECTED_NONE); - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), E_ACCOUNT_TREE_VIEW_SELECTED_NONE); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return E_ACCOUNT_TREE_VIEW_SELECTED_NONE; - - gtk_tree_model_get (model, &iter, - COLUMN_ACCOUNT, &account, - COLUMN_NAME, &name, - -1); - - if (account) { - res = E_ACCOUNT_TREE_VIEW_SELECTED_ACCOUNT; - g_object_unref (account); - } else if (name) { - if (g_str_equal (name, _("On This Computer"))) - res = E_ACCOUNT_TREE_VIEW_SELECTED_LOCAL; - else if (g_str_equal (name, _("Search Folders"))) - res = E_ACCOUNT_TREE_VIEW_SELECTED_VFOLDER; - } - - g_free (name); - - return res; -} - -/** - * e_account_tree_view_set_selected_type: - * @tree_view: an #EAccountTreeView - * @select: what to select; see below what can be used here - * - * Selects special nodes in a view. Can be only either #E_ACCOUNT_TREE_VIEW_SELECTED_LOCAL - * or #E_ACCOUNT_TREE_VIEW_SELECTED_VFOLDER. - * - * Since: 3.4 - **/ -void -e_account_tree_view_set_selected_type (EAccountTreeView *tree_view, - EAccountTreeViewSelectedType select) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - gboolean found; - - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - - if (!model || !gtk_tree_model_get_iter_first (model, &iter)) - return; - - if (select != E_ACCOUNT_TREE_VIEW_SELECTED_LOCAL && - select != E_ACCOUNT_TREE_VIEW_SELECTED_VFOLDER) - return; - - found = FALSE; - do { - gchar *name = NULL; - EAccount *account = NULL; - - gtk_tree_model_get (model, &iter, - COLUMN_ACCOUNT, &account, - COLUMN_NAME, &name, - -1); - - if (account) { - g_object_unref (account); - } else { - switch (select) { - case E_ACCOUNT_TREE_VIEW_SELECTED_LOCAL: - found = g_strcmp0 (name, _("On This Computer")) == 0; - break; - case E_ACCOUNT_TREE_VIEW_SELECTED_VFOLDER: - found = g_strcmp0 (name, _("Search Folders")) == 0; - break; - default: - break; - } - } - - g_free (name); - } while (!found && gtk_tree_model_iter_next (model, &iter)); - - if (found) - gtk_tree_selection_select_iter (selection, &iter); -} - -static guint -account_tree_view_get_slist_index (const GSList *account_uids, - const gchar *uid) -{ - guint res = 0; - - while (account_uids) { - if (g_strcmp0 (uid, account_uids->data) == 0) - return res; - - account_uids = account_uids->next; - res++; - } - - return -1; -} - -/** - * e_account_tree_view_set_sort_order: - * @tree_view: an #EAccountTreeView - * @account_uids: a #GSList of account uids as string - * - * Sets user sort order for accounts based on the order - * in @account_uids. This is used only when sort - * alphabetically is set to #FALSE. - * - * Since: 3.4 - **/ -void -e_account_tree_view_set_sort_order (EAccountTreeView *tree_view, - const GSList *account_uids) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - - if (!model || !gtk_tree_model_get_iter_first (model, &iter)) - return; - - do { - gchar *name = NULL; - EAccount *account = NULL; - guint sort_order = 0; - - gtk_tree_model_get (model, &iter, - COLUMN_ACCOUNT, &account, - COLUMN_NAME, &name, - -1); - - if (account) { - sort_order = account_tree_view_get_slist_index (account_uids, account->uid) + 1; - g_object_unref (account); - } else if (g_strcmp0 (name, _("On This Computer")) == 0) { - sort_order = account_tree_view_get_slist_index (account_uids, "local") + 1; - } else if (g_strcmp0 (name, _("Search Folders")) == 0) { - sort_order = account_tree_view_get_slist_index (account_uids, "vfolder") + 1; - } else { - g_warn_if_reached (); - } - - gtk_list_store_set (GTK_LIST_STORE (model), &iter, COLUMN_SORTORDER, sort_order, -1); - g_free (name); - } while (gtk_tree_model_iter_next (model, &iter)); - - account_tree_view_normalize_sortorder_column (tree_view); - e_account_tree_view_sort_changed (tree_view); -} - -static gint -eval_order_by_sort_hash_cb (gconstpointer a, - gconstpointer b, - gpointer user_data) -{ - guint asortorder = GPOINTER_TO_UINT (g_hash_table_lookup (user_data, a)); - guint bsortorder = GPOINTER_TO_UINT (g_hash_table_lookup (user_data, b)); - - if (asortorder < bsortorder) - return -1; - if (asortorder > bsortorder) - return 1; - - return 0; -} - -/** - * e_account_tree_view_get_sort_order: - * @tree_view: an #EAccountTreeView - * - * Returns: Newly allocated #GSList of newly allocated strings - * containing account UIDs in order as user wish to see them. - * Each item of the returned list should be freed with g_free() - * and the list itself should be freed with g_slist_free(), when - * no longer needed. - * - * Since: 3.4 - **/ -GSList * -e_account_tree_view_get_sort_order (EAccountTreeView *tree_view) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GHashTable *hash; - GSList *res = NULL; - - g_return_val_if_fail (tree_view != NULL, NULL); - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), NULL); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - - if (!model || !gtk_tree_model_get_iter_first (model, &iter)) - return NULL; - - hash = g_hash_table_new (g_direct_hash, g_direct_equal); - - do { - gchar *toadd = NULL; - gchar *name = NULL; - EAccount *account = NULL; - guint sort_order = 0; - - gtk_tree_model_get (model, &iter, - COLUMN_ACCOUNT, &account, - COLUMN_NAME, &name, - COLUMN_SORTORDER, &sort_order, - -1); - - if (account) { - toadd = g_strdup (account->uid); - g_object_unref (account); - } else if (g_strcmp0 (name, _("On This Computer")) == 0) { - toadd = g_strdup ("local"); - } else if (g_strcmp0 (name, _("Search Folders")) == 0) { - toadd = g_strdup ("vfolder"); - } else { - g_warn_if_reached (); - } - - if (toadd) { - g_hash_table_insert (hash, toadd, GUINT_TO_POINTER (sort_order)); - res = g_slist_prepend (res, toadd); - } - - g_free (name); - } while (gtk_tree_model_iter_next (model, &iter)); - - res = g_slist_sort_with_data (res, eval_order_by_sort_hash_cb, hash); - - g_hash_table_destroy (hash); - - return res; -} - -/** - * e_account_tree_view_sort_changed: - * @tree_view: an #EAccountTreeView - * - * Notifies @tree_view about sort order change, thus it resorts - * items in a view. - * - * Since: 3.4 - **/ -void -e_account_tree_view_sort_changed (EAccountTreeView *tree_view) -{ - GtkTreeModel *model; - - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - if (!model) - return; - - /* this invokes also sort on a GtkListStore */ - gtk_tree_sortable_set_default_sort_func ( - GTK_TREE_SORTABLE (model), - account_tree_view_sort, tree_view, NULL); -} - -static void -account_tree_view_swap_sort_order (EAccountTreeView *tree_view, - gint direction) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter1, iter2; - guint sortorder1, sortorder2; - - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - g_return_if_fail (direction != 0); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - if (!gtk_tree_selection_get_selected (selection, &model, &iter1)) - return; - - iter2 = iter1; - if ((direction < 0 && !gtk_tree_model_iter_previous (model, &iter2)) || - (direction > 0 && !gtk_tree_model_iter_next (model, &iter2))) - return; - - gtk_tree_model_get (model, &iter1, COLUMN_SORTORDER, &sortorder1, -1); - gtk_tree_model_get (model, &iter2, COLUMN_SORTORDER, &sortorder2, -1); - - gtk_list_store_set (GTK_LIST_STORE (model), &iter1, COLUMN_SORTORDER, sortorder2, -1); - gtk_list_store_set (GTK_LIST_STORE (model), &iter2, COLUMN_SORTORDER, sortorder1, -1); - - e_account_tree_view_sort_changed (tree_view); - - g_signal_emit (tree_view, signals[SORT_ORDER_CHANGED], 0); -} - -/** - * e_account_tree_view_move_up: - * @tree_view: an #EAccountTreeView - * - * Moves currently selected node up within user's sort order. - * - * Since: 3.4 - **/ -void -e_account_tree_view_move_up (EAccountTreeView *tree_view) -{ - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - account_tree_view_swap_sort_order (tree_view, -1); -} - -/** - * e_account_tree_view_move_down: - * @tree_view: an #EAccountTreeView - * - * Moves currently selected node down within user's sort order. - * - * Since: 3.4 - **/ -void -e_account_tree_view_move_down (EAccountTreeView *tree_view) -{ - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - - account_tree_view_swap_sort_order (tree_view, +1); -} - -void -e_account_tree_view_set_sort_alpha (EAccountTreeView *tree_view, - gboolean sort_alpha) -{ - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - g_return_if_fail (tree_view->priv != NULL); - - if ((tree_view->priv->sort_alpha ? 1 : 0) == (sort_alpha ? 1 : 0)) - return; - - tree_view->priv->sort_alpha = sort_alpha; - - g_object_notify (G_OBJECT (tree_view), "sort-alpha"); - e_account_tree_view_sort_changed (tree_view); -} - -gboolean -e_account_tree_view_get_sort_alpha (EAccountTreeView *tree_view) -{ - g_return_val_if_fail (tree_view != NULL, FALSE); - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), FALSE); - g_return_val_if_fail (tree_view->priv != NULL, FALSE); - - return tree_view->priv->sort_alpha; -} - -void -e_account_tree_view_set_express_mode (EAccountTreeView *tree_view, - gboolean express_mode) -{ - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - g_return_if_fail (tree_view->priv != NULL); - - if ((tree_view->priv->express_mode ? 1 : 0) == (express_mode ? 1 : 0)) - return; - - tree_view->priv->express_mode = express_mode; - - g_object_notify (G_OBJECT (tree_view), "express-mode"); - e_account_tree_view_sort_changed (tree_view); -} - -gboolean -e_account_tree_view_get_express_mode (EAccountTreeView *tree_view) -{ - g_return_val_if_fail (tree_view != NULL, FALSE); - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), FALSE); - g_return_val_if_fail (tree_view->priv != NULL, FALSE); - - return tree_view->priv->express_mode; -} - -static void -update_special_enable_state (EAccountTreeView *tree_view, - const gchar *display_name, - gboolean enabled) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkListStore *list_store; - - g_return_if_fail (tree_view != NULL); - g_return_if_fail (display_name != NULL); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - if (!model) - return; - - list_store = GTK_LIST_STORE (model); - g_return_if_fail (list_store != NULL); - - if (!gtk_tree_model_get_iter_first (model, &iter)) - return; - - do { - gchar *name = NULL; - EAccount *account = NULL; - - gtk_tree_model_get (model, &iter, - COLUMN_ACCOUNT, &account, - COLUMN_NAME, &name, - -1); - - if (account) { - g_object_unref (account); - } else if (g_strcmp0 (name, display_name) == 0) { - gtk_list_store_set (list_store, &iter, COLUMN_ENABLED, enabled, -1); - g_free (name); - break; - } - - g_free (name); - } while (gtk_tree_model_iter_next (model, &iter)); -} - -void -e_account_tree_view_set_enable_local_folders (EAccountTreeView *tree_view, - gboolean enabled) -{ - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - g_return_if_fail (tree_view->priv != NULL); - - if ((tree_view->priv->enable_local_folders ? 1 : 0) == (enabled ? 1 : 0)) - return; - - tree_view->priv->enable_local_folders = enabled; - - g_object_notify (G_OBJECT (tree_view), "enable-local-folders"); - - update_special_enable_state (tree_view, _("On This Computer"), enabled); -} - -gboolean -e_account_tree_view_get_enable_local_folders (EAccountTreeView *tree_view) -{ - g_return_val_if_fail (tree_view != NULL, FALSE); - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), FALSE); - g_return_val_if_fail (tree_view->priv != NULL, FALSE); - - return tree_view->priv->enable_local_folders; -} - -void -e_account_tree_view_set_enable_search_folders (EAccountTreeView *tree_view, - gboolean enabled) -{ - g_return_if_fail (tree_view != NULL); - g_return_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view)); - g_return_if_fail (tree_view->priv != NULL); - - if ((tree_view->priv->enable_search_folders ? 1 : 0) == (enabled ? 1 : 0)) - return; - - tree_view->priv->enable_search_folders = enabled; - - g_object_notify (G_OBJECT (tree_view), "enable-search-folders"); - - update_special_enable_state (tree_view, _("Search Folders"), enabled); -} - -gboolean -e_account_tree_view_get_enable_search_folders (EAccountTreeView *tree_view) -{ - g_return_val_if_fail (tree_view != NULL, FALSE); - g_return_val_if_fail (E_IS_ACCOUNT_TREE_VIEW (tree_view), FALSE); - g_return_val_if_fail (tree_view->priv != NULL, FALSE); - - return tree_view->priv->enable_search_folders; -} diff --git a/widgets/misc/e-account-tree-view.h b/widgets/misc/e-account-tree-view.h deleted file mode 100644 index d62d040bbd..0000000000 --- a/widgets/misc/e-account-tree-view.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * e-account-tree-view.h - * - * This program 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 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_ACCOUNT_TREE_VIEW_H -#define E_ACCOUNT_TREE_VIEW_H - -#include <gtk/gtk.h> -#include <libedataserver/e-account.h> -#include <libedataserver/e-account-list.h> - -/* Standard GObject macros */ -#define E_TYPE_ACCOUNT_TREE_VIEW \ - (e_account_tree_view_get_type ()) -#define E_ACCOUNT_TREE_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_ACCOUNT_TREE_VIEW, EAccountTreeView)) -#define E_ACCOUNT_TREE_VIEW_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_ACCOUNT_TREE_VIEW, EAccountTreeViewClass)) -#define E_IS_ACCOUNT_TREE_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_ACCOUNT_TREE_VIEW)) -#define E_IS_ACCOUNT_TREE_VIEW_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_ACCOUNT_TREE_VIEW)) -#define E_ACCOUNT_TREE_VIEW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_ACCOUNT_TREE_VIEW, EAccountTreeViewClass)) - -G_BEGIN_DECLS - -typedef enum -{ - E_ACCOUNT_TREE_VIEW_SELECTED_NONE, - E_ACCOUNT_TREE_VIEW_SELECTED_ACCOUNT, - E_ACCOUNT_TREE_VIEW_SELECTED_LOCAL, - E_ACCOUNT_TREE_VIEW_SELECTED_VFOLDER -} EAccountTreeViewSelectedType; - -typedef struct _EAccountTreeView EAccountTreeView; -typedef struct _EAccountTreeViewClass EAccountTreeViewClass; -typedef struct _EAccountTreeViewPrivate EAccountTreeViewPrivate; - -struct _EAccountTreeView { - GtkTreeView parent; - EAccountTreeViewPrivate *priv; -}; - -struct _EAccountTreeViewClass { - GtkTreeViewClass parent_class; - - void (*enable_account) (EAccountTreeView *tree_view); - void (*disable_account) (EAccountTreeView *tree_view); - void (*refreshed) (EAccountTreeView *tree_view); - void (*sort_order_changed) (EAccountTreeView *tree_view); -}; - -GType e_account_tree_view_get_type (void); -GtkWidget * e_account_tree_view_new (void); -void e_account_tree_view_enable_account - (EAccountTreeView *tree_view); -void e_account_tree_view_disable_account - (EAccountTreeView *tree_view); -EAccountList * e_account_tree_view_get_account_list - (EAccountTreeView *tree_view); -void e_account_tree_view_set_account_list - (EAccountTreeView *tree_view, - EAccountList *account_list); -EAccount * e_account_tree_view_get_selected - (EAccountTreeView *tree_view); -gboolean e_account_tree_view_set_selected - (EAccountTreeView *tree_view, - EAccount *account); -EAccountTreeViewSelectedType - e_account_tree_view_get_selected_type - (EAccountTreeView *tree_view); -void e_account_tree_view_set_selected_type - (EAccountTreeView *tree_view, - EAccountTreeViewSelectedType select); - -void e_account_tree_view_set_sort_order - (EAccountTreeView *tree_view, - const GSList *account_uids); - -GSList * e_account_tree_view_get_sort_order - (EAccountTreeView *tree_view); - -void e_account_tree_view_sort_changed - (EAccountTreeView *tree_view); -void e_account_tree_view_move_up (EAccountTreeView *tree_view); -void e_account_tree_view_move_down (EAccountTreeView *tree_view); - -void e_account_tree_view_set_sort_alpha - (EAccountTreeView *tree_view, - gboolean sort_alpha); -gboolean e_account_tree_view_get_sort_alpha - (EAccountTreeView *tree_view); -void e_account_tree_view_set_express_mode - (EAccountTreeView *tree_view, - gboolean express_mode); -gboolean e_account_tree_view_get_express_mode - (EAccountTreeView *tree_view); -void e_account_tree_view_set_enable_local_folders - (EAccountTreeView *tree_view, gboolean enabled); -gboolean e_account_tree_view_get_enable_local_folders - (EAccountTreeView *tree_view); -void e_account_tree_view_set_enable_search_folders - (EAccountTreeView *tree_view, gboolean enabled); -gboolean e_account_tree_view_get_enable_search_folders - (EAccountTreeView *tree_view); - -G_END_DECLS - -#endif /* E_ACCOUNT_TREE_VIEW_H */ |