Fixes RefNULL 4/14
[modest] / src / modest-ui-actions.c
index a1f80f4..736eeb0 100644 (file)
@@ -974,13 +974,12 @@ open_msg_banner_idle (gpointer userdata)
        gdk_threads_enter ();
        banner_info->idle_handler = 0;
        banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
-       if (banner_info)
+       if (banner_info->banner)
                g_object_ref (banner_info->banner);
-       
+
        gdk_threads_leave ();
 
        return FALSE;
-       
 }
 
 static GtkWidget *
@@ -1358,7 +1357,7 @@ open_msg_performer(gboolean canceled,
                    gpointer user_data)
 {
        ModestMailOperation *mail_op = NULL;
-       gchar *error_msg;
+       gchar *error_msg = NULL;
        ModestProtocolType proto;
        TnyConnectionStatus status;
        OpenMsgHelper *helper = NULL;
@@ -1455,7 +1454,7 @@ open_msg_performer(gboolean canceled,
        mail_op = 
                modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
                                                               modest_ui_actions_disk_operations_error_handler,
-                                                              error_msg, g_free);
+                                                              g_strdup (error_msg), g_free);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
 
@@ -1483,6 +1482,8 @@ open_msg_performer(gboolean canceled,
 
        /* Frees */
  clean:
+       if (error_msg)
+               g_free (error_msg);
        if (mail_op)
                g_object_unref (mail_op);
        g_object_unref (account);
@@ -3249,38 +3250,6 @@ modest_ui_actions_on_remove_attachments (GtkAction *action,
        modest_msg_edit_window_remove_attachments (window, NULL);
 }
 
-
-#ifndef MODEST_TOOLKIT_GTK
-typedef struct {
-       guint handler;
-       gchar *name;
-       GtkWindow *win;
-       TnyFolderStore *folder;
-} CreateFolderHelper;
-
-static gboolean
-show_create_folder_in_timeout (gpointer data)
-{
-       CreateFolderHelper *helper = (CreateFolderHelper *) data;
-
-       /* Remove the timeout ASAP, we can not wait until the dialog
-          is shown because it could take a lot of time and so the
-          timeout could be called twice or more times */
-       g_source_remove (helper->handler);
-
-       gdk_threads_enter ();
-       do_create_folder (helper->win, helper->folder, helper->name);
-       gdk_threads_leave ();
-
-       g_object_unref (helper->win);
-       g_object_unref (helper->folder);
-       g_free (helper->name);
-       g_slice_free (CreateFolderHelper, helper);
-
-       return FALSE;
-}
-#endif
-
 static void
 do_create_folder_cb (ModestMailOperation *mail_op,
                     TnyFolderStore *parent_folder, 
@@ -3289,8 +3258,10 @@ do_create_folder_cb (ModestMailOperation *mail_op,
 {
        gchar *suggested_name = (gchar *) user_data;
        GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
+       const GError *error;
 
-       if (modest_mail_operation_get_error (mail_op)) {
+       error = modest_mail_operation_get_error (mail_op);
+       if (error) {
 
                /* Show an error. If there was some problem writing to
                   disk, show it, otherwise show the generic folder
@@ -3302,24 +3273,10 @@ do_create_folder_cb (ModestMailOperation *mail_op,
                modest_ui_actions_disk_operations_error_handler (mail_op,
                                                                 _("mail_in_ui_folder_create_error"));
 
-               /* Try again. Do *NOT* show any error because the mail
-                  operations system will do it for us because we
-                  created the mail_op with new_with_error_handler */
-#ifndef MODEST_TOOLKIT_GTK
-               CreateFolderHelper *helper;
-               helper = g_slice_new0 (CreateFolderHelper);
-               helper->name = g_strdup (suggested_name);
-               helper->folder = g_object_ref (parent_folder);
-               helper->win = g_object_ref (source_win);
-
-               /* Ugly but neccesary stuff. The problem is that the
-                  dialog when is shown calls a function that destroys
-                  all the temporary windows, so the banner is
-                  destroyed */
-               helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
-#else
-               do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
-#endif
+               if (!is_memory_full_error ((GError *) error, mail_op)) {
+                       /* Try again if there is no full memory condition */
+                       do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
+               }
        } else {
                /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
                 * FIXME: any other? */
@@ -6397,8 +6354,9 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
                                                gpointer user_data)
 {
        const gchar* server_name = NULL;
-       TnyTransportAccount *server_account;
+       TnyTransportAccount *transport;
        gchar *message = NULL;
+       ModestProtocol *protocol;
 
        /* Don't show anything if the user cancelled something or the
         * send receive request is not interactive. Authentication
@@ -6410,24 +6368,51 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
                return;
 
 
-       /* Get the server name: */
-       server_account =
-               TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
-       if (server_account)
-               server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
-       else
-               g_return_if_reached ();
+       /* Get the server name. Note that we could be using a
+          connection specific transport account */
+       transport = (TnyTransportAccount *)
+               tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self));
+       if (transport) {
+               ModestTnyAccountStore *acc_store;
+               const gchar *acc_name;
+               TnyTransportAccount *conn_specific;
+
+               acc_store = modest_runtime_get_account_store();
+               acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT (transport));
+               conn_specific = (TnyTransportAccount *)
+                       modest_tny_account_store_get_transport_account_for_open_connection (acc_store, acc_name);
+               if (conn_specific) {
+                       server_name = tny_account_get_hostname (TNY_ACCOUNT (conn_specific));
+                       g_object_unref (conn_specific);
+               } else {
+                       server_name = tny_account_get_hostname (TNY_ACCOUNT (transport));
+               }
+               g_object_unref (transport);
+       }
+
+       /* Get protocol */
+       protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
+                                                                 MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
+                                                                 tny_account_get_proto (TNY_ACCOUNT (transport)));
+       if (!protocol) {
+               g_warning ("%s: Account with no proto", __FUNCTION__);
+               return;
+       }
 
        /* Show the appropriate message text for the GError: */
        switch (err->code) {
        case TNY_SERVICE_ERROR_CONNECT:
-               message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
+               message = modest_protocol_get_translation (protocol,
+                                                          MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, 
+                                                          server_name);
                break;
        case TNY_SERVICE_ERROR_SEND:
                message = g_strdup (_CS("sfil_ib_unable_to_send"));
                break;
        case TNY_SERVICE_ERROR_UNAVAILABLE:
-               message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
+               message = modest_protocol_get_translation (protocol,
+                                                          MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR, 
+                                                          server_name);
                break;
        default:
                g_warning ("%s: unexpected ERROR %d",
@@ -6438,7 +6423,6 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
 
        modest_platform_run_information_dialog (NULL, message, FALSE);
        g_free (message);
-       g_object_unref (server_account);
 }
 
 void
@@ -6472,7 +6456,8 @@ modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
 #endif
 
        /* Get selected folder */
-       selected_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
+       if (header_view)
+               selected_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
        if (!selected_folder)
                return;
 
@@ -6575,6 +6560,9 @@ modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
                folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
        }
 
+       if (!header || !folder)
+               goto frees;
+
        /* Get the account type */
        account = tny_folder_get_account (TNY_FOLDER (folder));
        proto = modest_tny_account_get_protocol_type (account);
@@ -6589,10 +6577,14 @@ modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
                msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
        }
 
+ frees:
        /* Frees */
-       g_object_unref (account);
-       g_object_unref (folder);
-       g_object_unref (header);
+       if (account)
+               g_object_unref (account);
+       if (folder)
+               g_object_unref (folder);
+       if (header)
+               g_object_unref (header);
 
        return msg;
 }