aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-05-25 05:36:21 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-05-25 07:41:59 +0800
commita9dff2f33a06879403277a422fc579854aa99885 (patch)
tree36d8ccdaf876cc6ca36db80069dcbef8a26a60bf
parentb6fecfcd53bc5a733a7aaf3684cda077bfdd2e5e (diff)
downloadgsoc2013-evolution-a9dff2f33a06879403277a422fc579854aa99885.tar
gsoc2013-evolution-a9dff2f33a06879403277a422fc579854aa99885.tar.gz
gsoc2013-evolution-a9dff2f33a06879403277a422fc579854aa99885.tar.bz2
gsoc2013-evolution-a9dff2f33a06879403277a422fc579854aa99885.tar.lz
gsoc2013-evolution-a9dff2f33a06879403277a422fc579854aa99885.tar.xz
gsoc2013-evolution-a9dff2f33a06879403277a422fc579854aa99885.tar.zst
gsoc2013-evolution-a9dff2f33a06879403277a422fc579854aa99885.zip
Use em_folder_tree_get_selected() in places to simplify code.
There were a few places where we were accessing the folder tree model directly to get the selected store + folder name, or were asking for the selected URI only to parse back into its store + folder name components.
-rw-r--r--mail/e-mail-sidebar.c5
-rw-r--r--mail/em-folder-properties.c40
-rw-r--r--mail/em-folder-properties.h3
-rw-r--r--mail/em-folder-tree.c52
-rw-r--r--modules/mail/e-mail-shell-backend.c31
-rw-r--r--modules/mail/e-mail-shell-view-actions.c20
-rw-r--r--modules/mail/e-mail-shell-view.c21
-rw-r--r--plugins/mark-all-read/mark-all-read.c39
8 files changed, 72 insertions, 139 deletions
diff --git a/mail/e-mail-sidebar.c b/mail/e-mail-sidebar.c
index 45d16a8be1..5f6285112d 100644
--- a/mail/e-mail-sidebar.c
+++ b/mail/e-mail-sidebar.c
@@ -300,7 +300,6 @@ mail_sidebar_check_state (EMailSidebar *sidebar)
GtkTreeIter iter;
CamelStore *store;
gchar *full_name;
- gchar *uri;
gboolean allows_children = TRUE;
gboolean can_delete = TRUE;
gboolean is_junk = FALSE;
@@ -321,8 +320,7 @@ mail_sidebar_check_state (EMailSidebar *sidebar)
COL_POINTER_CAMEL_STORE, &store,
COL_STRING_FULL_NAME, &full_name,
COL_BOOL_IS_STORE, &is_store,
- COL_UINT_FLAGS, &folder_flags,
- COL_STRING_URI, &uri, -1);
+ COL_UINT_FLAGS, &folder_flags, -1);
if (!is_store && full_name != NULL) {
CamelStore *local_store;
@@ -372,7 +370,6 @@ mail_sidebar_check_state (EMailSidebar *sidebar)
state |= E_MAIL_SIDEBAR_STORE_SUPPORTS_SUBSCRIPTIONS;
g_free (full_name);
- g_free (uri);
return state;
}
diff --git a/mail/em-folder-properties.c b/mail/em-folder-properties.c
index 090dcd75c4..4f5b4f6710 100644
--- a/mail/em-folder-properties.c
+++ b/mail/em-folder-properties.c
@@ -444,48 +444,32 @@ emfp_dialog_got_folder (CamelStore *store,
/**
* em_folder_properties_show:
* @shell_view: an #EShellView
- * @folder_uri: a folder URI
+ * @store: a #CamelStore
+ * @folder_name: a folder name
*
- * Show folder properties for @folder_uri.
+ * Show folder properties for @folder_name.
**/
void
em_folder_properties_show (EShellView *shell_view,
- const gchar *folder_uri)
+ CamelStore *store,
+ const gchar *folder_name)
{
EShellBackend *shell_backend;
EShellContent *shell_content;
EMailBackend *backend;
- EMailSession *session;
EAlertSink *alert_sink;
GCancellable *cancellable;
AsyncContext *context;
- CamelStore *store = NULL;
- gchar *folder_name = NULL;
const gchar *uid;
- GError *error = NULL;
g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
- g_return_if_fail (folder_uri != NULL);
+ g_return_if_fail (CAMEL_IS_STORE (store));
+ g_return_if_fail (folder_name != NULL);
shell_backend = e_shell_view_get_shell_backend (shell_view);
shell_content = e_shell_view_get_shell_content (shell_view);
backend = E_MAIL_BACKEND (shell_backend);
- session = e_mail_backend_get_session (backend);
-
- e_mail_folder_uri_parse (
- CAMEL_SESSION (session), folder_uri,
- &store, &folder_name, &error);
-
- /* XXX This is unlikely to fail since the URI comes straight from
- * EMFolderTreeModel, but leave a breadcrumb if it does fail. */
- if (error != NULL) {
- g_warn_if_fail (store == NULL);
- g_warn_if_fail (folder_name == NULL);
- g_warning ("%s", error->message);
- g_error_free (error);
- return;
- }
uid = camel_service_get_uid (CAMEL_SERVICE (store));
@@ -493,9 +477,12 @@ em_folder_properties_show (EShellView *shell_view,
* "Unmatched" is a special Search Folder which can't be modified. */
if (g_strcmp0 (uid, "vfolder") == 0) {
if (g_strcmp0 (folder_name, CAMEL_UNMATCHED_NAME) != 0) {
+ gchar *folder_uri;
+
+ folder_uri = e_mail_folder_uri_build (
+ store, folder_name);
vfolder_edit_rule (backend, folder_uri);
- g_object_unref (store);
- g_free (folder_name);
+ g_free (folder_uri);
return;
}
}
@@ -519,7 +506,4 @@ em_folder_properties_show (EShellView *shell_view,
(GAsyncReadyCallback) emfp_dialog_got_folder, context);
g_object_unref (cancellable);
-
- g_object_unref (store);
- g_free (folder_name);
}
diff --git a/mail/em-folder-properties.h b/mail/em-folder-properties.h
index 8ceda89ca4..fbb8dadac9 100644
--- a/mail/em-folder-properties.h
+++ b/mail/em-folder-properties.h
@@ -30,7 +30,8 @@
G_BEGIN_DECLS
void em_folder_properties_show (EShellView *shell_view,
- const gchar *folder_uri);
+ CamelStore *store,
+ const gchar *folder_name);
G_END_DECLS
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c
index 3b16f62fa3..9ad9d32989 100644
--- a/mail/em-folder-tree.c
+++ b/mail/em-folder-tree.c
@@ -552,18 +552,16 @@ folder_tree_maybe_expand_row (EMFolderTreeModel *model,
{
EMFolderTreePrivate *priv = folder_tree->priv;
struct _EMFolderTreeModelStoreInfo *si;
- gboolean is_store;
CamelStore *store;
EAccount *account;
gchar *full_name;
gchar *key;
struct _selected_uri *u;
- gtk_tree_model_get ((GtkTreeModel *) model, iter,
- COL_STRING_FULL_NAME, &full_name,
- COL_POINTER_CAMEL_STORE, &store,
- COL_BOOL_IS_STORE, &is_store,
- -1);
+ gtk_tree_model_get (
+ GTK_TREE_MODEL (model), iter,
+ COL_STRING_FULL_NAME, &full_name,
+ COL_POINTER_CAMEL_STORE, &store, -1);
si = em_folder_tree_model_lookup_store_info (model, store);
if ((account = e_get_account_by_name (si->display_name))) {
@@ -3174,6 +3172,18 @@ em_folder_tree_get_selected (EMFolderTree *folder_tree,
COL_POINTER_CAMEL_STORE, &store,
COL_STRING_FULL_NAME, &folder_name, -1);
+ /* We should always get a valid store. */
+ g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
+
+ /* If a store is selected, the folder name will be NULL.
+ * Treat this as though nothing is selected, so that callers
+ * can assume a TRUE return value means a folder is selected. */
+ if (folder_name == NULL)
+ return FALSE;
+
+ /* FIXME We really should be storing the CamelStore as a GObject
+ * so it gets referenced. The pointer type is a relic of
+ * days before Camel used GObject. */
if (out_store != NULL)
*out_store = g_object_ref (store);
@@ -3210,31 +3220,20 @@ em_folder_tree_get_selected_uri (EMFolderTree *folder_tree)
CamelFolder *
em_folder_tree_get_selected_folder (EMFolderTree *folder_tree)
{
- GtkTreeView *tree_view;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- gchar *full_name = NULL;
- CamelStore *store = NULL;
- CamelFolder *folder = NULL;
+ CamelFolder *folder;
+ CamelStore *store;
+ gchar *full_name;
g_return_val_if_fail (EM_IS_FOLDER_TREE (folder_tree), NULL);
- tree_view = GTK_TREE_VIEW (folder_tree);
- selection = gtk_tree_view_get_selection (tree_view);
-
- if (gtk_tree_selection_get_selected (selection, &model, &iter))
- gtk_tree_model_get (
- model, &iter,
- COL_POINTER_CAMEL_STORE, &store,
- COL_STRING_FULL_NAME, &full_name, -1);
+ if (!em_folder_tree_get_selected (folder_tree, &store, &full_name))
+ return NULL;
/* FIXME camel_store_get_folder_sync() may block. */
- if (store && full_name)
- folder = camel_store_get_folder_sync (
- store, full_name,
- CAMEL_STORE_FOLDER_INFO_FAST, NULL, NULL);
+ folder = camel_store_get_folder_sync (
+ store, full_name, CAMEL_STORE_FOLDER_INFO_FAST, NULL, NULL);
+ g_object_unref (store);
g_free (full_name);
return folder;
@@ -3252,6 +3251,9 @@ em_folder_tree_get_selected_account (EMFolderTree *folder_tree)
g_return_val_if_fail (EM_IS_FOLDER_TREE (folder_tree), NULL);
+ /* Don't use em_folder_tree_get_selected() here because we
+ * want this to work whether a folder or store is selected. */
+
tree_view = GTK_TREE_VIEW (folder_tree);
selection = gtk_tree_view_get_selection (tree_view);
diff --git a/modules/mail/e-mail-shell-backend.c b/modules/mail/e-mail-shell-backend.c
index f7e9b81ae1..b95ce9db54 100644
--- a/modules/mail/e-mail-shell-backend.c
+++ b/modules/mail/e-mail-shell-backend.c
@@ -145,14 +145,14 @@ action_mail_message_new_cb (GtkAction *action,
EShellWindow *shell_window)
{
EMailShellSidebar *mail_shell_sidebar;
- EShellBackend *shell_backend;
EShellSidebar *shell_sidebar;
EShellView *shell_view;
EShell *shell;
EMFolderTree *folder_tree;
CamelFolder *folder = NULL;
+ CamelStore *store;
const gchar *view_name;
- gchar *folder_uri = NULL;
+ gchar *folder_name;
shell = e_shell_window_get_shell (shell_window);
@@ -165,36 +165,19 @@ action_mail_message_new_cb (GtkAction *action,
goto exit;
shell_view = e_shell_window_get_shell_view (shell_window, view_name);
- shell_backend = e_shell_view_get_shell_backend (shell_view);
shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar);
folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
- folder_uri = em_folder_tree_get_selected_uri (folder_tree);
-
- if (folder_uri != NULL) {
- EMailBackend *backend;
- EMailSession *session;
- CamelStore *store;
- gchar *folder_name;
- gboolean success;
- backend = E_MAIL_BACKEND (shell_backend);
- session = e_mail_backend_get_session (backend);
-
- success = e_mail_folder_uri_parse (
- CAMEL_SESSION (session), folder_uri,
- &store, &folder_name, NULL);
+ if (em_folder_tree_get_selected (folder_tree, &store, &folder_name)) {
/* FIXME This blocks and is not cancellable. */
- if (success) {
- folder = camel_store_get_folder_sync (
- store, folder_name, 0, NULL, NULL);
- g_object_unref (store);
- g_free (folder_name);
- }
+ folder = camel_store_get_folder_sync (
+ store, folder_name, 0, NULL, NULL);
- g_free (folder_uri);
+ g_object_unref (store);
+ g_free (folder_name);
}
exit:
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index 7c55908b31..c5f155de15 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -451,24 +451,20 @@ action_mail_folder_properties_cb (GtkAction *action,
EMailShellSidebar *mail_shell_sidebar;
EMFolderTree *folder_tree;
EShellView *shell_view;
- GtkTreeSelection *selection;
- GtkTreeView *tree_view;
- GtkTreeModel *model;
- GtkTreeIter iter;
- gchar *uri;
+ CamelStore *store;
+ gchar *folder_name;
shell_view = E_SHELL_VIEW (mail_shell_view);
mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
- tree_view = GTK_TREE_VIEW (folder_tree);
- selection = gtk_tree_view_get_selection (tree_view);
- if (!gtk_tree_selection_get_selected (selection, &model, &iter))
- return;
+ if (!em_folder_tree_get_selected (folder_tree, &store, &folder_name))
+ g_return_if_reached ();
- gtk_tree_model_get (model, &iter, COL_STRING_URI, &uri, -1);
- em_folder_properties_show (shell_view, uri);
- g_free (uri);
+ em_folder_properties_show (shell_view, store, folder_name);
+
+ g_object_unref (store);
+ g_free (folder_name);
}
static void
diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c
index f0a89e3a37..04c9d4d034 100644
--- a/modules/mail/e-mail-shell-view.c
+++ b/modules/mail/e-mail-shell-view.c
@@ -660,27 +660,18 @@ current_account:
/* Create a new search folder. */
- if (folder) {
+ if (folder != NULL) {
store = camel_folder_get_parent_store (folder);
+ if (store != NULL)
+ g_object_ref (store);
} else {
- GtkTreeView *tree_view;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
-
store = NULL;
- tree_view = GTK_TREE_VIEW (folder_tree);
- selection = gtk_tree_view_get_selection (tree_view);
-
- if (gtk_tree_selection_get_selected (selection, &model, &iter))
- gtk_tree_model_get (
- model, &iter,
- COL_POINTER_CAMEL_STORE, &store, -1);
+ em_folder_tree_get_selected (folder_tree, &store, NULL);
}
list = NULL; /* list of CamelFolders */
- if (store) {
+ if (store != NULL) {
CamelFolderInfo *root, *fi;
/* FIXME This call blocks the main loop. */
@@ -722,6 +713,8 @@ current_account:
if (root)
camel_store_free_folder_info_full (store, root);
+
+ g_object_unref (store);
}
list = g_list_reverse (list);
diff --git a/plugins/mark-all-read/mark-all-read.c b/plugins/mark-all-read/mark-all-read.c
index 7a5c79e95f..10ea043fee 100644
--- a/plugins/mark-all-read/mark-all-read.c
+++ b/plugins/mark-all-read/mark-all-read.c
@@ -515,14 +515,9 @@ action_mail_mark_read_recursive_cb (GtkAction *action,
EShellContent *shell_content;
EShellSidebar *shell_sidebar;
EMFolderTree *folder_tree;
- EMailBackend *backend;
- EMailSession *session;
AsyncContext *context;
- CamelStore *store = NULL;
- CamelStoreGetFolderInfoFlags flags;
- gchar *folder_name = NULL;
- gchar *folder_uri;
- GError *error = NULL;
+ CamelStore *store;
+ gchar *folder_name;
shell_backend = e_shell_view_get_shell_backend (shell_view);
shell_content = e_shell_view_get_shell_content (shell_view);
@@ -530,28 +525,11 @@ action_mail_mark_read_recursive_cb (GtkAction *action,
g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
- backend = em_folder_tree_get_backend (folder_tree);
- session = e_mail_backend_get_session (backend);
-
- folder_uri = em_folder_tree_get_selected_uri (folder_tree);
- g_return_if_fail (folder_uri != NULL);
-
- e_mail_folder_uri_parse (
- CAMEL_SESSION (session), folder_uri,
- &store, &folder_name, &error);
+ /* This action should only be activatable if a folder is selected. */
+ if (!em_folder_tree_get_selected (folder_tree, &store, &folder_name))
+ g_return_if_reached ();
g_object_unref (folder_tree);
- g_free (folder_uri);
-
- /* Failure here is unlikely enough that we don't need an
- * EAlert for it, but we should still leave a breadcrumb. */
- if (error != NULL) {
- g_warning ("%s", error->message);
- return;
- }
-
- g_return_if_fail (CAMEL_IS_STORE (store));
- g_return_if_fail (folder_name != NULL);
/* Open the selected folder asynchronously. */
@@ -567,11 +545,10 @@ action_mail_mark_read_recursive_cb (GtkAction *action,
e_shell_backend_add_activity (shell_backend, context->activity);
- flags = CAMEL_STORE_FOLDER_INFO_RECURSIVE |
- CAMEL_STORE_FOLDER_INFO_FAST;
-
camel_store_get_folder_info (
- store, folder_name, flags,
+ store, folder_name,
+ CAMEL_STORE_FOLDER_INFO_FAST |
+ CAMEL_STORE_FOLDER_INFO_RECURSIVE,
G_PRIORITY_DEFAULT, cancellable,
(GAsyncReadyCallback) mar_got_folder_info, context);