diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/em-folder-tree.c | 129 | ||||
-rw-r--r-- | mail/mail.error.xml | 18 |
2 files changed, 102 insertions, 45 deletions
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c index 2d1e28ea58..4dbbb36224 100644 --- a/mail/em-folder-tree.c +++ b/mail/em-folder-tree.c @@ -1899,48 +1899,6 @@ tree_drag_begin (GtkWidget *widget, } static void -tree_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - EMFolderTree *folder_tree) -{ - EMFolderTreePrivate *priv = folder_tree->priv; - gchar *full_name = NULL; - GtkTreeModel *model; - GtkTreePath *src_path; - gboolean is_store; - CamelStore *store; - GtkTreeIter iter; - - if (!priv->drag_row) - return; - - src_path = gtk_tree_row_reference_get_path (priv->drag_row); - if (src_path == NULL) - return; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_tree)); - - if (!gtk_tree_model_get_iter (model, &iter, src_path)) - goto fail; - - gtk_tree_model_get ( - model, &iter, - COL_POINTER_CAMEL_STORE, &store, - COL_STRING_FULL_NAME, &full_name, - COL_BOOL_IS_STORE, &is_store, -1); - - if (is_store) - goto fail; - - /* FIXME camel_store_delete_folder_sync() may block. */ - camel_store_delete_folder_sync (store, full_name, NULL, NULL); - -fail: - gtk_tree_path_free (src_path); - g_free (full_name); -} - -static void tree_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection, @@ -2005,6 +1963,80 @@ fail: g_free (uri); } +static gboolean +ask_drop_folder (EMFolderTree *folder_tree, + const gchar *src_folder_uri, + const gchar *des_full_name, + CamelStore *des_store, + gboolean is_move) +{ + const gchar *key = is_move ? "prompt-on-folder-drop-move" : "prompt-on-folder-drop-copy"; + EMailSession *session; + GSettings *settings; + gchar *set_value, *src_folder_name = NULL; + GError *error = NULL; + GtkWidget *widget; + GtkWindow *parent; + gint response; + + g_return_val_if_fail (folder_tree != NULL, FALSE); + g_return_val_if_fail (src_folder_uri != NULL, FALSE); + g_return_val_if_fail (des_full_name != NULL || des_store != NULL, FALSE); + + settings = g_settings_new ("org.gnome.evolution.mail"); + set_value = g_settings_get_string (settings, key); + + if (g_strcmp0 (set_value, "never") == 0) { + g_object_unref (settings); + g_free (set_value); + + return FALSE; + } else if (g_strcmp0 (set_value, "always") == 0) { + g_object_unref (settings); + g_free (set_value); + + return TRUE; + } + + g_free (set_value); + + session = em_folder_tree_get_session (folder_tree); + if (!e_mail_folder_uri_parse (CAMEL_SESSION (session), + src_folder_uri, NULL, &src_folder_name, &error)) { + g_debug ("%s: Failed to convert '%s' to folder name: %s", + G_STRFUNC, src_folder_uri, error ? error->message : "Unknown error"); + g_clear_error (&error); + g_object_unref (settings); + + return FALSE; + } + + parent = NULL; + widget = gtk_widget_get_toplevel (GTK_WIDGET (folder_tree)); + if (widget && gtk_widget_is_toplevel (widget) && GTK_IS_WINDOW (widget)) + parent = GTK_WINDOW (widget); + + widget = e_alert_dialog_new_for_args ( + parent, + is_move ? "mail:ask-folder-drop-move" : "mail:ask-folder-drop-copy", + src_folder_name, + des_full_name && *des_full_name ? des_full_name : + camel_service_get_display_name (CAMEL_SERVICE (des_store)), + NULL); + response = gtk_dialog_run (GTK_DIALOG (widget)); + gtk_widget_destroy (widget); + + if (response == GTK_RESPONSE_OK) + g_settings_set_string (settings, key, "always"); + else if (response == GTK_RESPONSE_CANCEL) + g_settings_set_string (settings, key, "never"); + + g_free (src_folder_name); + g_object_unref (settings); + + return response == GTK_RESPONSE_YES || response == GTK_RESPONSE_OK; +} + /* Drop handling */ struct _DragDataReceivedAsync { MailMsg base; @@ -2250,6 +2282,16 @@ tree_drag_data_received (GtkWidget *widget, return; } + if (info == DND_DROP_TYPE_FOLDER && + !ask_drop_folder (folder_tree, + (const gchar *) gtk_selection_data_get_data (selection), + full_name, store, + gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE)) { + gtk_drag_finish (context, FALSE, FALSE, GDK_CURRENT_TIME); + gtk_tree_path_free (dest_path); + return; + } + m = mail_msg_new (&folder_tree_drop_async_info); m->folder_tree = g_object_ref (folder_tree); m->session = g_object_ref (session); @@ -2781,9 +2823,6 @@ em_folder_tree_enable_drag_and_drop (EMFolderTree *folder_tree) tree_view, "drag-begin", G_CALLBACK (tree_drag_begin), folder_tree); g_signal_connect ( - tree_view, "drag-data-delete", - G_CALLBACK (tree_drag_data_delete), folder_tree); - g_signal_connect ( tree_view, "drag-data-get", G_CALLBACK (tree_drag_data_get), folder_tree); g_signal_connect ( diff --git a/mail/mail.error.xml b/mail/mail.error.xml index 3a9dab56bf..158a26440b 100644 --- a/mail/mail.error.xml +++ b/mail/mail.error.xml @@ -426,6 +426,24 @@ An mbox account will be created to preserve the old mbox folders. You can delete <button _label="N_ever" response="GTK_RESPONSE_CANCEL"/> </error> + <error id="ask-folder-drop-copy" type="question" default="GTK_RESPONSE_YES"> + <_primary>Copy folder in folder tree.</_primary> + <_secondary xml:space="preserve">Are you sure to copy folder '{0}' to folder '{1}'?</_secondary> + <button _label="_Yes" response="GTK_RESPONSE_YES"/> + <button _label="_No" response="GTK_RESPONSE_NO"/> + <button _label="_Always" response="GTK_RESPONSE_OK"/> + <button _label="N_ever" response="GTK_RESPONSE_CANCEL"/> + </error> + + <error id="ask-folder-drop-move" type="question" default="GTK_RESPONSE_YES"> + <_primary>Move folder in folder tree.</_primary> + <_secondary xml:space="preserve">Are you sure to move folder '{0}' to folder '{1}'?</_secondary> + <button _label="_Yes" response="GTK_RESPONSE_YES"/> + <button _label="_No" response="GTK_RESPONSE_NO"/> + <button _label="_Always" response="GTK_RESPONSE_OK"/> + <button _label="N_ever" response="GTK_RESPONSE_CANCEL"/> + </error> + <error id="signature-already-exists" type="error" modal="true"> <_primary>Signature Already Exists</_primary> <_secondary>A signature already exists with the name "{0}". Please specify a different name. </_secondary> |