fix error handling in folder dnd (thanks to Alfons)
authorColin Leroy <colin@colino.net>
Fri, 15 Nov 2002 19:51:25 +0000 (19:51 +0000)
committerColin Leroy <colin@colino.net>
Fri, 15 Nov 2002 19:51:25 +0000 (19:51 +0000)
ChangeLog.claws
configure.in
src/folder.c
src/folder.h
src/folderview.c

index bb1b205..7c353b9 100644 (file)
@@ -1,3 +1,10 @@
+2002-11-14 [colin]     0.8.5claws155
+
+       * src/folder.[ch]
+         src/folderview.c
+               Fix error handling of folder_item_move_to()
+               (thanks to Alfons!)
+
 2002-11-14 [colin]     0.8.5claws154
 
        * src/folder.[ch]
index dc54ccd..1181928 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws154
+EXTRA_VERSION=claws155
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 4f09911..c9cba06 100644 (file)
@@ -1559,7 +1559,7 @@ FolderItem *folder_item_move_recursive (FolderItem *src, FolderItem *dest)
        return new_item;
 }
 
-FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest, char *error)
+gint folder_item_move_to(FolderItem *src, FolderItem *dest, FolderItem **new_item)
 {
        FolderItem *tmp = dest->parent;
        char * src_identifier, * dst_identifier, * new_identifier;
@@ -1568,8 +1568,7 @@ FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest, char *error)
        
        while (tmp) {
                if (tmp == src) {
-                       error = g_strdup(_("Can't move a folder to one of its children."));
-                       return NULL;
+                       return F_MOVE_FAILED_DEST_IS_CHILD;
                }
                tmp = tmp->parent;
        }
@@ -1585,24 +1584,22 @@ FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest, char *error)
        }
        if (src_identifier == NULL || dst_identifier == NULL) {
                printf("Can't get identifiers\n");
-               return NULL;
+               return F_MOVE_FAILED;
        }
 
        phys_srcpath = folder_item_get_path(src);
        phys_dstpath = g_strconcat(folder_item_get_path(dest),G_DIR_SEPARATOR_S,g_basename(phys_srcpath),NULL);
 
        if (src->parent == dest) {
-               error = g_strdup(_("Source and destination are the same."));
                g_free(src_identifier);
                g_free(dst_identifier);
                g_free(phys_srcpath);
                g_free(phys_dstpath);
-               return NULL;
+               return F_MOVE_FAILED_DEST_IS_PARENT;
        }
        debug_print("moving \"%s\" to \"%s\"\n", phys_srcpath, phys_dstpath);
        if ((tmp = folder_item_move_recursive(src, dest)) == NULL) {
-               error = g_strdup(_("Move failed!"));
-               return NULL;
+               return F_MOVE_FAILED;
        }
        
        /* update rules */
@@ -1626,7 +1623,9 @@ FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest, char *error)
        g_free(phys_srcpath);
        g_free(phys_dstpath);
 
-       return tmp;
+       *new_item = tmp;
+
+       return F_MOVE_OK;
 }
 
 gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
index 67961ea..8d8a8eb 100644 (file)
@@ -96,6 +96,14 @@ typedef enum
        SORT_DESCENDING
 } FolderSortType;
 
+typedef enum
+{
+       F_MOVE_OK,
+       F_MOVE_FAILED_DEST_IS_PARENT,
+       F_MOVE_FAILED_DEST_IS_CHILD,
+       F_MOVE_FAILED
+} FolderMoveStatus;
+
 typedef void (*FolderUIFunc)           (Folder         *folder,
                                         FolderItem     *item,
                                         gpointer        data);
@@ -357,9 +365,9 @@ gchar *folder_item_fetch_msg                (FolderItem     *item,
 gint   folder_item_add_msg             (FolderItem     *dest,
                                         const gchar    *file,
                                         gboolean        remove_source);
-FolderItem   *folder_item_move_to      (FolderItem     *src,
+gint   folder_item_move_to             (FolderItem     *src,
                                         FolderItem     *dest,
-                                        char           *error);
+                                        FolderItem    **new_item);
 gint   folder_item_move_msg            (FolderItem     *dest,
                                         MsgInfo        *msginfo);
 gint   folder_item_move_msgs_with_dest (FolderItem     *dest,
index 0170858..8dd2d1c 100644 (file)
@@ -2620,7 +2620,7 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                /* comes from folderview */
                char *source;
                char *buf;
-               char *error_msg = NULL;
+               gint status;
                GtkCTreeNode *src_node;
                FolderItem *new_item, *src_parent;
                
@@ -2651,7 +2651,7 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                gtk_widget_set_sensitive(folderview->ctree, FALSE);
                inc_lock();
                main_window_cursor_wait(folderview->mainwin);
-               if ((new_item = folder_item_move_to(src_item, item, &error_msg)) != NULL) {
+               if ((status = folder_item_move_to(src_item, item, &new_item)) == F_MOVE_OK) {
                        main_window_cursor_normal(folderview->mainwin);
                        gtk_drag_finish(drag_context, TRUE, TRUE, time);
                
@@ -2672,9 +2672,16 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                        main_window_cursor_normal(folderview->mainwin);
                        gtk_drag_finish(drag_context, FALSE, FALSE, time);
                        STATUSBAR_POP(folderview->mainwin);
-                       if (error_msg != NULL) {
-                               alertpanel_error(error_msg);
-                               g_free(error_msg);
+                       switch (status) {
+                       case F_MOVE_FAILED_DEST_IS_PARENT:
+                               alertpanel_error(_("Source and destination are the same."));
+                               break;
+                       case F_MOVE_FAILED_DEST_IS_CHILD:
+                               alertpanel_error(_("Can't move a folder to one of its children."));
+                               break;
+                       default:
+                               alertpanel_error(_("Move failed!"));
+                               break;
                        }
                }       
                inc_unlock();