aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-05-25 05:36:21 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-06-30 00:42:20 +0800
commit6e6da8a4080c4606529603ad9a90489509bea105 (patch)
treeba6161fc5b5abc0c514004ea5fafa6424a46f224 /mail
parent851a872865769d1d53e495fd1d0b82f0452594c4 (diff)
downloadgsoc2013-evolution-6e6da8a4080c4606529603ad9a90489509bea105.tar
gsoc2013-evolution-6e6da8a4080c4606529603ad9a90489509bea105.tar.gz
gsoc2013-evolution-6e6da8a4080c4606529603ad9a90489509bea105.tar.bz2
gsoc2013-evolution-6e6da8a4080c4606529603ad9a90489509bea105.tar.lz
gsoc2013-evolution-6e6da8a4080c4606529603ad9a90489509bea105.tar.xz
gsoc2013-evolution-6e6da8a4080c4606529603ad9a90489509bea105.tar.zst
gsoc2013-evolution-6e6da8a4080c4606529603ad9a90489509bea105.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.
Diffstat (limited to 'mail')
-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
4 files changed, 42 insertions, 58 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);