Fixed several TnyIterator leaks
[modest] / src / modest-ui-actions.c
index afb7736..f6f7892 100644 (file)
@@ -184,7 +184,7 @@ remote_folder_is_pop (const TnyFolderStore *folder)
                 account = tny_folder_get_account(TNY_FOLDER(folder));
         }
 
-       if (!account && !TNY_IS_ACCOUNT(account)) {
+       if (!TNY_IS_ACCOUNT(account)) {
                g_warning ("%s: could not get account", __FUNCTION__);
                return FALSE;
        }
@@ -598,8 +598,6 @@ modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *
        modest_ui_actions_on_delete_message (action, win);
 }
 
-
-
 void
 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
 {      
@@ -814,25 +812,6 @@ modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
        modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
 }
 
-void
-modest_ui_actions_on_new_msg_or_folder (GtkAction *action, ModestWindow *win)
-{
-       g_return_if_fail (MODEST_IS_WINDOW (win));
-
-       /* Check first if the folder view has the focus */
-       if (MODEST_IS_MAIN_WINDOW (win)) {
-               GtkWidget *w;
-               w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
-                                                        MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
-               if (gtk_widget_is_focus (w)) {
-                       modest_ui_actions_on_new_folder (action, MODEST_MAIN_WINDOW(win));
-                       return;
-               }
-       }
-
-       modest_ui_actions_on_new_msg (action, win);
-}
-
 
 gboolean 
 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
@@ -1021,14 +1000,21 @@ modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
 {
        const GError *error;
        GObject *win = NULL;
-       const gchar *err_msg = (const gchar *) user_data;
 
        win = modest_mail_operation_get_source (mail_op);
        error = modest_mail_operation_get_error (mail_op);
 
        /* Show error */
-       if (err_msg)
-               modest_platform_run_information_dialog ((GtkWindow *) win, err_msg);
+       if (error->code == TNY_SYSTEM_ERROR_MEMORY ||
+           error->code == TNY_IO_ERROR_WRITE ||
+           error->code == TNY_IO_ERROR_READ) {
+               modest_platform_information_banner ((GtkWidget *) win, 
+                                                   NULL, dgettext("ke-recv", 
+                                                                  "cerm_device_memory_full"));
+       } else if (user_data) {
+               modest_platform_information_banner ((GtkWidget *) win, 
+                                                   NULL, user_data);
+       }
 
        if (win)
                g_object_unref (win);
@@ -4484,6 +4470,7 @@ open_msg_for_purge_cb (ModestMailOperation *mail_op,
 
                                tny_iterator_next (iter);
                        }
+                       g_object_unref (iter);
                        
                        tny_msg_rewrite_cache (msg);
                }
@@ -4491,7 +4478,6 @@ open_msg_for_purge_cb (ModestMailOperation *mail_op,
                /* This string no longer exists, refer to NB#75415 for more info */
                /* modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged")); */
        }
-       g_object_unref (iter);
 
        modest_window_mgr_unregister_header (mgr, header);
 
@@ -4504,7 +4490,6 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
 {
        GtkWidget *header_view;
        TnyList *header_list;
-       TnyIterator *iter;
        TnyHeader *header;
        TnyHeaderFlags flags;
        ModestWindow *msg_view_window =  NULL;
@@ -4522,7 +4507,7 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
        }
        
        if (tny_list_get_length (header_list) == 1) {
-               iter = tny_list_create_iterator (header_list);
+               TnyIterator *iter = tny_list_create_iterator (header_list);
                header = TNY_HEADER (tny_iterator_get_current (iter));
                g_object_unref (iter);
        } else
@@ -5449,3 +5434,54 @@ modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
                g_free (error_note);
        }
 }
+
+gchar *
+modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
+{
+       gchar *msg = NULL;
+       TnyFolderStore *folder = NULL;
+       TnyAccount *account = NULL;
+       ModestTransportStoreProtocol proto;
+       TnyHeader *header = NULL;
+
+       if (MODEST_IS_MAIN_WINDOW (win)) {
+               GtkWidget *header_view;
+               TnyList* headers = NULL;
+               TnyIterator *iter;
+               header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                                  MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+               headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
+               if (!headers || tny_list_get_length (headers) == 0) {
+                       if (headers)
+                               g_object_unref (headers);
+                       return NULL;
+               }
+               iter = tny_list_create_iterator (headers);
+               header = TNY_HEADER (tny_iterator_get_current (iter));
+               folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
+               g_object_unref (iter);
+               g_object_unref (headers);
+       } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+               header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
+               folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
+       }
+
+       /* Get the account type */
+       account = tny_folder_get_account (TNY_FOLDER (folder));
+       proto = modest_protocol_info_get_transport_store_protocol (tny_account_get_proto (account));
+       if (proto == MODEST_PROTOCOL_STORE_POP) {
+               msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
+       } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
+               msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"), 
+                                      tny_header_get_subject (header));
+       } else {
+               msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
+       }
+
+       /* Frees */
+       g_object_unref (account);
+       g_object_unref (folder);
+       g_object_unref (header);
+
+       return msg;
+}