From a9dff2f33a06879403277a422fc579854aa99885 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 24 May 2011 17:36:21 -0400 Subject: 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. --- modules/mail/e-mail-shell-backend.c | 31 +++++++------------------------ modules/mail/e-mail-shell-view-actions.c | 20 ++++++++------------ modules/mail/e-mail-shell-view.c | 21 +++++++-------------- 3 files changed, 22 insertions(+), 50 deletions(-) (limited to 'modules/mail') 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); -- cgit