X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-ui-actions.c;h=b0a44084b3462e0fc7074ef83239709d6711473e;hp=019df84dd5128a9caba3f2b540d870680f1fb4fb;hb=67789b8955031c322e59cad5492b300724420d8f;hpb=af3e3bf14a866a495c483bb3e57826c8e0b764e4 diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 019df84..b0a4408 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -1163,20 +1164,39 @@ cleanup: } static gboolean -is_memory_full_error (GError *error) +is_memory_full_error (GError *error, ModestMailOperation *mail_op) { gboolean enough_free_space = TRUE; GnomeVFSURI *cache_dir_uri; - const gchar *cache_dir; + const gchar *cache_dir = NULL; GnomeVFSFileSize free_space; + TnyAccountStore *acc_store; + + acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()); + + /* Cache dir is different in case we're using an external storage (like MMC account) */ + if (mail_op) { + TnyAccount *account = modest_mail_operation_get_account (mail_op); + if (account) { + if (modest_tny_account_is_memory_card_account (account)) { + cache_dir = g_getenv (MODEST_MMC1_VOLUMEPATH_ENV); + } + g_object_unref (account); + } + } + + /* Get the default local cache dir */ + if (!cache_dir) + cache_dir = tny_account_store_get_cache_dir (acc_store); - cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ())); cache_dir_uri = gnome_vfs_uri_new (cache_dir); - if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) { - if (free_space < MIN_FREE_SPACE) - enough_free_space = FALSE; + if (cache_dir_uri) { + if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) { + if (free_space < MIN_FREE_SPACE) + enough_free_space = FALSE; + } + gnome_vfs_uri_unref (cache_dir_uri); } - gnome_vfs_uri_unref (cache_dir_uri); if ((error->code == TNY_SYSTEM_ERROR_MEMORY || /* When asking for a mail and no space left on device @@ -1199,7 +1219,7 @@ check_memory_full_error (GtkWidget *parent_window, GError *err) if (err == NULL) return FALSE; - if (is_memory_full_error (err)) + if (is_memory_full_error (err, NULL)) modest_platform_information_banner (parent_window, NULL, _KR("cerm_device_memory_full")); else if (err->code == TNY_SYSTEM_ERROR_MEMORY) @@ -1229,7 +1249,7 @@ modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op, /* If the mail op has been cancelled then it's not an error: don't show any message */ if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) { - if (is_memory_full_error ((GError *) error)) { + if (is_memory_full_error ((GError *) error, mail_op)) { modest_platform_information_banner ((GtkWidget *) win, NULL, _KR("cerm_device_memory_full")); } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) { @@ -1338,7 +1358,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; @@ -1463,6 +1483,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); @@ -2068,12 +2090,12 @@ modest_ui_actions_on_sort (GtkAction *action, if (!header_view) { modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort")); - + return; } /* Show sorting dialog */ - modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS); + modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS); } static void @@ -3229,38 +3251,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, @@ -3269,8 +3259,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 @@ -3282,24 +3274,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? */ @@ -3382,7 +3360,7 @@ do_create_folder (GtkWindow *parent_window, &parent_folder); if (result == GTK_RESPONSE_ACCEPT && parent_folder) { - CreateFolderConnect *helper = (CreateFolderConnect *) g_slice_new0 (CreateFolderHelper); + CreateFolderConnect *helper = (CreateFolderConnect *) g_slice_new0 (CreateFolderConnect); helper->folder_name = g_strdup (folder_name); helper->parent = g_object_ref (parent_folder); @@ -3416,8 +3394,10 @@ modest_ui_actions_create_folder(GtkWidget *parent_window, parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view)); #endif - if (parent_folder) + if (parent_folder) { do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL); + g_object_unref (parent_folder); + } } void @@ -4900,41 +4880,58 @@ on_move_to_dialog_response (GtkDialog *dialog, gint response, gpointer user_data) { - GtkWidget *parent_win, *folder_view; + GtkWidget *parent_win; MoveToInfo *helper = NULL; + ModestFolderView *folder_view; helper = (MoveToInfo *) user_data; parent_win = (GtkWidget *) helper->win; - folder_view = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), - MODEST_MOVE_TO_DIALOG_FOLDER_VIEW)); + folder_view = MODEST_FOLDER_VIEW (g_object_get_data (G_OBJECT (dialog), + MODEST_MOVE_TO_DIALOG_FOLDER_VIEW)); switch (response) { TnyFolderStore *dst_folder; case MODEST_GTK_RESPONSE_NEW_FOLDER: - modest_ui_actions_create_folder (GTK_WIDGET (dialog), folder_view); + modest_ui_actions_create_folder (GTK_WIDGET (dialog), GTK_WIDGET (folder_view)); return; case GTK_RESPONSE_NONE: case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: break; case GTK_RESPONSE_OK: - dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)); - /* Do window specific stuff */ + dst_folder = modest_folder_view_get_selected (folder_view); + if (MODEST_IS_MAIN_WINDOW (parent_win)) { + /* Clean list to move used for filtering */ + modest_folder_view_set_list_to_move (folder_view, NULL); + modest_ui_actions_on_main_window_move_to (NULL, - folder_view, + GTK_WIDGET (folder_view), dst_folder, MODEST_MAIN_WINDOW (parent_win)); #ifdef MODEST_TOOLKIT_HILDON2 } else if (MODEST_IS_FOLDER_WINDOW (parent_win)) { - modest_ui_actions_on_folder_window_move_to (folder_view, + /* Clean list to move used for filtering */ + modest_folder_view_set_list_to_move (folder_view, NULL); + + modest_ui_actions_on_folder_window_move_to (GTK_WIDGET (folder_view), dst_folder, helper->list, GTK_WINDOW (parent_win)); #endif } else { + /* if the user selected a root folder + (account) then do not perform any action */ + if (TNY_IS_ACCOUNT (dst_folder)) { + g_signal_stop_emission_by_name (dialog, "response"); + return; + } + + /* Clean list to move used for filtering */ + modest_folder_view_set_list_to_move (folder_view, NULL); + /* Moving from headers window in edit mode */ modest_ui_actions_on_window_move_to (NULL, helper->list, dst_folder, @@ -4958,7 +4955,8 @@ on_move_to_dialog_response (GtkDialog *dialog, static GtkWidget* create_move_to_dialog (GtkWindow *win, - GtkWidget *folder_view) + GtkWidget *folder_view, + TnyList *list_to_move) { GtkWidget *dialog, *tree_view = NULL; @@ -5027,6 +5025,8 @@ create_move_to_dialog (GtkWindow *win, /* Hide special folders */ modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE); + if (list_to_move) + modest_folder_view_set_list_to_move (MODEST_FOLDER_VIEW (tree_view), list_to_move); #ifndef MODEST_TOOLKIT_HILDON2 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view)); #endif @@ -5454,7 +5454,7 @@ xfer_messages_error_handler (ModestMailOperation *mail_op, win = modest_mail_operation_get_source (mail_op); error = modest_mail_operation_get_error (mail_op); - if (error && is_memory_full_error ((GError *) error)) + if (error && is_memory_full_error ((GError *) error, mail_op)) modest_platform_information_banner ((GtkWidget *) win, NULL, _KR("cerm_device_memory_full")); else @@ -5888,7 +5888,7 @@ modest_ui_actions_on_edit_mode_move_to (ModestWindow *win) } /* Create and run the dialog */ - dialog = create_move_to_dialog (GTK_WINDOW (win), NULL); + dialog = create_move_to_dialog (GTK_WINDOW (win), NULL, list_to_move); modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), (GtkWindow *) win); @@ -6355,8 +6355,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 @@ -6368,24 +6369,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", @@ -6396,7 +6424,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 @@ -6430,7 +6457,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;