Link with C++ linker
[oweals/cde.git] / cde / programs / dtfile / OverWrite.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: OverWrite.c /main/8 1998/10/26 12:40:12 mgreess $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  *
27  *   FILE:           OverWrite.c
28  *
29  *   COMPONENT_NAME: Desktop File Manager (dtfile)
30  *
31  *   Description:    Contains routines for collision dialog during
32  *                   move/copy/link operations.
33  *
34  *   FUNCTIONS: Create_Action_Area
35  *              buffer_multicollide_ok_callback
36  *              buffer_replace_rename_ok_callback
37  *              create_multicollide_dialog
38  *              create_replace_merge_dialog
39  *              create_replace_rename_dialog
40  *              getVariableMessage
41  *              multiRenameError_ok_callback
42  *              multiReplaceError_ok_callback
43  *              multicollide_cancel_callback
44  *              multicollide_ok_callback
45  *              renameError_ok_callback
46  *              replaceError_ok_callback
47  *              replace_merge_cancel_callback
48  *              replace_merge_ok_callback
49  *              replace_rename_cancel_callback
50  *              replace_rename_ok_callback
51  *              replace_rename_radio_callback
52  *
53  *   (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
54  *   (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
55  *   (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
56  *   (c) Copyright 1993, 1994, 1995 Novell, Inc.
57  *
58  ****************************************************************************
59  ************************************<+>*************************************/
60
61 /* includes */
62 #include <errno.h>
63
64 #include <Xm/DialogS.h>
65 #include <Xm/Frame.h>
66 #include <Xm/Form.h>
67 #include <Xm/Label.h>
68 #include <Xm/PushB.h>
69 #include <Xm/RowColumn.h>
70 #include <Xm/ToggleB.h>
71 #include <Xm/TextF.h>
72 #include <Xm/Separator.h>
73
74
75 #include <Dt/DtNlUtils.h>
76
77 #include "Encaps.h"
78 #include "FileMgr.h"
79 #include "Desktop.h"
80 #include "Main.h"
81 #include "SharedProcs.h"
82 #include "Help.h"
83
84 #include "sharedFuncs.h"
85 #include "fsrtns.h"
86
87
88 /* defines */
89 #define VERTICAL_SPACING  5
90 #define HORIZONTAL_SPACING  10
91 #define TOP_SPACING  (VERTICAL_SPACING + 3)
92
93 /* types of messages sent through the pipe */
94 /* these messages are also defined & used in FileOp.c */
95 #define PIPEMSG_CANCEL      101
96 #define PIPEMSG_PROCEED     102
97 #define PIPEMSG_MERGE       103
98 #define PIPEMSG_REPLACE_BUFFER  104
99 #define PIPEMSG_RENAME_BUFFER   105
100 #define PIPEMSG_MULTI_PROCEED   106
101
102 #define RADIO_REPLACE 0
103 #define RADIO_RENAME  1
104
105
106 /* global variables */
107 Boolean G_initImages          = True;
108 int     G_filop_confirm_fd    = -1;
109 char    G_directory[MAX_PATH];
110 char    G_file[MAX_PATH];
111 String  *G_fileList           = NULL;
112 int     G_nCollisions         = 0;
113 Widget  G_dialogShell         = NULL;
114 Widget  G_rename_text         = NULL;
115 Widget  G_rename_toggle       = NULL;
116 Widget  G_merge_toggle        = NULL;
117 Widget  G_multi_rename_toggle = NULL;
118 int     G_mode;
119
120 /* types */
121 typedef enum {
122   vm_replaceCannotDeleteFolder,         /* 80 81 */
123   vm_replaceCannotDeleteFile,           /* 82 */
124   vm_multiCannotRenameMany,             /* 83 84 */
125   vm_multiCannotRenameOne,              /* 85 84 */
126   vm_multiCannotDeleteFolderMany,       /* 86 */
127   vm_multiCannotDeleteFolderOne,        /* 87 */
128   vm_multiCannotDeleteFileMany,         /* 88 */
129   vm_multiCannotDeleteFileOne          /* 89 */
130 } VariableMessage;
131
132 /* local functions */
133 static void      replaceError_ok_callback(
134                                     Widget w,
135                                     XtPointer client_data,
136                                     XtPointer call_data);
137 static void      renameError_ok_callback(
138                                     Widget w,
139                                     XtPointer client_data,
140                                     XtPointer call_data);
141 static void      multiReplaceError_ok_callback(
142                                     Widget w,
143                                     XtPointer client_data,
144                                     XtPointer call_data);
145 static void      multiRenameError_ok_callback(
146                                     Widget w,
147                                     XtPointer client_data,
148                                     XtPointer call_data);
149 static char *    getVariableMessage(
150                                     VariableMessage message,
151                                     int             mode);
152 static Boolean   IsReplaceable(
153                                     char *name);
154
155
156 /*--------------------------------------------------------------------
157  * Callback routines
158  *------------------------------------------------------------------*/
159
160
161 void
162 replace_rename_ok_callback(
163         Widget w,
164         XtPointer client_data,
165         XtPointer call_data)
166 {
167    const int    rc = PIPEMSG_PROCEED;
168    String       newFile, renameNewName, destinationName;
169    struct stat  buf;
170    int          saveError = 0;
171    static char  msg[30+(3*MAX_PATH)];
172    String       title;
173    char         *newFileDir = NULL;
174    char         *newFileName = NULL;
175    int          newFileDirLen;
176    int          rename_rc;
177    Boolean      same = (Boolean)client_data;
178
179    /* if same is true, then the object is tring to be copied into the same
180     * folder as itself.  So the existing files stay the same and the new files
181     * being created take on the new names.
182     */
183
184    /* Rename was selected */
185    if (XmToggleButtonGetState(G_rename_toggle))
186    {
187       newFile         = XmTextFieldGetString(G_rename_text);
188       renameNewName   = build_path(G_directory,newFile);
189       destinationName = build_path(G_directory,G_file);
190       XtFree(newFile);
191       /* make sure renameNewName does not exist */
192       if ( (lstat(renameNewName, &buf)) == 0)
193       {
194          sprintf(msg,
195                  GETMESSAGE(9, 38, "%s\nalready exists: choose another name."),
196                  renameNewName);
197          title = XtNewString(GETMESSAGE(9, 37, "Object Rename - Error"));
198          _DtMessageDialog (G_dialogShell, title, msg, 0, FALSE, NULL,
199                            renameError_ok_callback, NULL, NULL, False, ERROR_DIALOG);
200          XtFree(title);
201          XtFree(renameNewName);
202          XtFree(destinationName);
203          return;
204
205       }
206       if(!same)
207       {
208           /* attempt the rename ... since rename function is being used, this*/
209           /* only allows renames within the same filesystem */
210
211           DirectoryFileModified(home_host_name, G_directory, G_file);
212           if (DtStrchr(newFile, '/') == NULL)
213               DirectoryFileModified(home_host_name, G_directory, newFile);
214           else
215           {
216               newFileName = strrchr(renameNewName, '/');
217               newFileDirLen = newFileName - renameNewName;
218               newFileName++;
219
220               newFileDir = XtMalloc(newFileDirLen + 1);
221               strncpy(newFileDir, renameNewName, newFileDirLen);
222               newFileDir[newFileDirLen] = '\0';
223
224               DirectoryBeginModify(home_host_name, newFileDir);
225               DirectoryFileModified(home_host_name, newFileDir, newFileName);
226           }
227
228           errno = 0;
229           rename_rc = rename(destinationName, renameNewName);
230
231           if (newFileDir != NULL)
232           {
233               DirectoryEndModify(home_host_name, newFileDir);
234               XtFree(newFileDir);
235           }
236
237           if (rename_rc != 0)
238           {
239               saveError = errno;
240               sprintf(msg,
241                       GETMESSAGE(9, 39, "%s\ncannot be renamed to\n%s\n%s"),
242                       destinationName, renameNewName, strerror(saveError));
243               title = XtNewString(GETMESSAGE(9, 37, "Object Rename - Error"));
244               _DtMessageDialog (G_dialogShell, title, msg, 0, FALSE, NULL,
245                                 renameError_ok_callback, NULL, NULL, False, ERROR_DIALOG);
246               XtFree(title);
247               XtFree(renameNewName);
248               XtFree(destinationName);
249               return;
250           }
251       }
252       XtFree(renameNewName);
253       XtFree(destinationName);
254    }
255
256    /* Replace was selected ... remove the offending target */
257    else
258    {
259       destinationName = build_path(G_directory,G_file);
260       DirectoryFileModified(home_host_name, G_directory, G_file);
261       if(IsReplaceable(destinationName))
262         fsErase(destinationName,&saveError,False);
263       else
264         saveError = 1;
265       if ( saveError == 0 )
266       {
267          /* removal succeeded */
268          XtFree(destinationName);
269       }
270       else
271       {
272          /* removal failed */
273
274          stat(destinationName,&buf);
275          title = XtNewString(GETMESSAGE(9, 40, "Object Replace - Error"));
276
277          if (S_ISDIR(buf.st_mode))
278          {
279             strcpy(msg,getVariableMessage(vm_replaceCannotDeleteFolder, G_mode));
280          }
281          else
282          {
283             sprintf(msg,
284                     getVariableMessage(vm_replaceCannotDeleteFile, G_mode),
285                     destinationName);
286          }
287
288          _DtMessageDialog (G_dialogShell, title, msg, 0, FALSE, NULL,
289                            replaceError_ok_callback, NULL, NULL, False, ERROR_DIALOG);
290          XtFree(title);
291          XtFree(destinationName);
292          return;
293       }
294    }
295
296    /* close the dialog */
297    XtDestroyWidget(G_dialogShell);
298    G_dialogShell = NULL;
299
300    /* send return code through the pipe to the background proc */
301    write(G_filop_confirm_fd, &rc, sizeof(int));
302    G_filop_confirm_fd = -1;
303
304 }  /*  end replace_rename_ok_callback */
305
306
307 void
308 buffer_replace_rename_ok_callback(
309         Widget w,
310         XtPointer client_data,
311         XtPointer call_data)
312 {
313    int          rc = 0;
314    String       newFile, renameNewName, destinationName;
315    struct stat  buf;
316    int          saveError = 0;
317    static char  msg[38+MAX_PATH];
318    String       title;
319
320
321    /* Rename was selected */
322    if (XmToggleButtonGetState(G_rename_toggle))
323    {
324       newFile         = XmTextFieldGetString(G_rename_text);
325       renameNewName   = build_path(G_directory,newFile);
326       destinationName = build_path(G_directory,G_file);
327
328       /* make sure renameNewName does not exist */
329       if ( (lstat(renameNewName, &buf)) == 0)
330       {
331          sprintf(msg,
332                  GETMESSAGE(9, 38, "%s\nalready exists: choose another name."),
333                  renameNewName);
334          title = XtNewString(GETMESSAGE(9, 37, "Object Rename - Error"));
335          _DtMessageDialog (G_dialogShell, title, msg, 0, FALSE, NULL,
336                            renameError_ok_callback, NULL, NULL, False, ERROR_DIALOG);
337          XtFree(title);
338          XtFree(renameNewName);
339          XtFree(destinationName);
340          return;
341
342       }
343
344       /* Perform the actual rename in the child process */
345       /* set up pipe message */
346       rc = PIPEMSG_RENAME_BUFFER;
347
348
349       XtFree(renameNewName);
350       XtFree(destinationName);
351    }
352    /* Replace was selected ... remove the offending target */
353    else
354    {
355       destinationName = build_path(G_directory,G_file);
356       if(IsReplaceable(destinationName))
357         fsErase(destinationName,&saveError,False);
358       else
359         saveError = 1;
360       if ( saveError == 0 )
361       {
362
363          rc = PIPEMSG_REPLACE_BUFFER;
364          /* removal succeeded */
365          XtFree(destinationName);
366
367       }
368       else
369       {
370          /* removal failed */
371
372          stat(destinationName,&buf);
373          title = XtNewString(GETMESSAGE(9, 40, "Object Replace - Error"));
374
375          if (S_ISDIR(buf.st_mode))
376          {
377             strcpy(msg,getVariableMessage(vm_replaceCannotDeleteFolder, COPY_FILE));
378          }
379          else
380          {
381             sprintf(msg,
382                     getVariableMessage(vm_replaceCannotDeleteFile, COPY_FILE),
383                     destinationName);
384          }
385
386
387          _DtMessageDialog (G_dialogShell, title, msg, 0, FALSE, NULL,
388                            replaceError_ok_callback, NULL, NULL, False, ERROR_DIALOG);
389          XtFree(title);
390          XtFree(destinationName);
391          return;
392       }
393    }
394
395    /* close the dialog */
396    XtDestroyWidget(G_dialogShell);
397    G_dialogShell = NULL;
398
399    /* send return code through the pipe to the background proc */
400    write(G_filop_confirm_fd, &rc, sizeof(int));
401
402    /* write the the new name on the pipe if rename is selected */
403    if (XmToggleButtonGetState(G_rename_toggle))
404    {
405      DPRINTF(("Writing %s to %d\n", newFile ,G_filop_confirm_fd));
406      PipeWriteString(G_filop_confirm_fd, newFile);
407      XtFree(newFile);
408    }
409    G_filop_confirm_fd = -1;
410
411 }  /*  end buffer_replace_rename_ok_callback */
412
413
414 void
415 replace_rename_cancel_callback(
416         Widget w,
417         XtPointer client_data,
418         XtPointer call_data)
419 {
420    const int rc = PIPEMSG_CANCEL;
421
422    /* close the dialog */
423    XtDestroyWidget(G_dialogShell);
424    G_dialogShell = NULL;
425
426    /* send negative return code through the pipe to the background proc */
427    write(G_filop_confirm_fd, &rc, sizeof(int));
428    G_filop_confirm_fd = -1;
429
430 }  /*  end replace_rename_cancel_callback */
431
432
433 static void
434 replace_rename_radio_callback(
435         Widget w,
436         XtPointer client_data,
437         XtPointer call_data)
438 {
439    XmToggleButtonCallbackStruct *state = (XmToggleButtonCallbackStruct *)call_data;
440
441
442    if (state->set)
443       switch ((int) client_data)
444       {
445         case RADIO_REPLACE:
446            XtVaSetValues (G_rename_text,
447                           XmNsensitive, FALSE,
448                           NULL);
449         break;
450
451         case RADIO_RENAME:
452            XtVaSetValues (G_rename_text,
453                           XmNsensitive, TRUE,
454                           NULL);
455            XmProcessTraversal(G_rename_text, XmTRAVERSE_CURRENT);
456         break;
457
458
459       }   /* end switch */
460
461   return;
462
463 }  /* end replace_rename_radio_callback */
464
465
466
467 static void
468 renameError_ok_callback(
469         Widget w,
470         XtPointer client_data,
471         XtPointer call_data)
472 {
473   XtDestroyWidget((Widget)client_data);
474   XmProcessTraversal(G_rename_text, XmTRAVERSE_CURRENT);
475
476   return;
477 }  /* end renameError_ok_callback */
478
479
480 void
481 replace_merge_ok_callback(
482         Widget w,
483         XtPointer client_data,
484         XtPointer call_data)
485 {
486    int          rc;
487    String       newFile=NULL, renameNewName, renameOldName;
488    struct stat  buf;
489    int          saveError = 0;
490    char         msg[128];
491    String       title;
492    char         *destinationPath =  build_path(G_directory,G_file);
493
494    if (XmToggleButtonGetState(G_merge_toggle))
495       rc = PIPEMSG_MERGE;
496    else
497    {
498       rc = PIPEMSG_PROCEED;
499       if(DirectoryBusy(destinationPath))
500       {
501          char *msg,*errmsg;
502
503          msg = GETMESSAGE(11,30, "Cannot move or rename the folder %s.\n\
504 All File Manager views displayed for a folder or its sub-folders\n\
505 must be closed before a folder can be moved or renamed.");
506
507          errmsg = XtMalloc(strlen(msg)+strlen(destinationPath)+1);
508          sprintf(errmsg,msg,destinationPath);
509          title = XtNewString(GETMESSAGE(9, 40, "Object Replace - Error"));
510          _DtMessage(toplevel, title, errmsg, NULL, HelpRequestCB);
511          XtFree(errmsg);
512          XtFree(title);
513          XtFree(destinationPath);
514          rc = PIPEMSG_CANCEL;
515       }
516    }
517
518    /* close the dialog */
519    XtDestroyWidget(G_dialogShell);
520    G_dialogShell = NULL;
521
522    /* send return code through the pipe to the background proc */
523    write(G_filop_confirm_fd, &rc, sizeof(int));
524    G_filop_confirm_fd = -1;
525
526 }  /*  end replace_merge_ok_callback */
527
528
529
530 void
531 replace_merge_cancel_callback(
532         Widget w,
533         XtPointer client_data,
534         XtPointer call_data)
535 {
536    const int rc = PIPEMSG_CANCEL;
537
538    /* close the dialog */
539    XtDestroyWidget(G_dialogShell);
540    G_dialogShell = NULL;
541
542    /* send negative return code through the pipe to the background proc */
543    write(G_filop_confirm_fd, &rc, sizeof(int));
544    G_filop_confirm_fd = -1;
545
546 }  /*  end replace_merge_cancel_callback */
547
548
549
550 void
551 multicollide_cancel_callback(
552         Widget w,
553         XtPointer client_data,
554         XtPointer call_data)
555 {
556    const int rc = PIPEMSG_CANCEL;
557    int       i;
558
559    /* close the dialog */
560    XtDestroyWidget(G_dialogShell);
561    G_dialogShell = NULL;
562
563    /* de-allocate the file list */
564    for ( i = 0; i < G_nCollisions; i++)
565       XtFree((char *)G_fileList[i]);
566    XtFree((char *)G_fileList);
567    G_fileList = NULL;
568
569    /* send return code through the pipe to the background proc */
570    write(G_filop_confirm_fd, &rc, sizeof(int));
571    G_filop_confirm_fd = -1;
572
573 }  /*  end multicollide_cancel_callback */
574
575
576 void
577 multicollide_ok_callback(
578         Widget w,
579         XtPointer client_data,
580         XtPointer call_data)
581 {
582    const int    rc = PIPEMSG_MULTI_PROCEED;
583    int          i;
584    int          saveError;
585    String       destinationPath;
586    String       title;
587    static char  msg[1024];
588    struct stat  buf;
589
590
591    Boolean      same = (Boolean)client_data;
592
593    /* if same is true, then the object is tring to be copied into the same
594     * folder as itself.  So the existing files stay the same and the new files
595     * being created take on the new names.
596     */
597
598    if (XmToggleButtonGetState(G_multi_rename_toggle))
599    {
600       char *names = NULL;
601       title = XtNewString(GETMESSAGE(9, 37, "Object Rename - Error"));
602
603       write(G_filop_confirm_fd, &rc, sizeof(int));
604       /* Auto rename was selected */
605       for ( i = 0; i < G_nCollisions; i++)
606       {
607           if(!same)
608           {
609
610          destinationPath = build_path(G_directory,G_fileList[i]);
611          DirectoryFileModified(home_host_name, G_directory, G_fileList[i]);
612          if ( auto_rename(destinationPath) != 0)
613          {
614            saveError = -1;
615            if(!names)
616              names = (char *) XtNewString(destinationPath);
617            else
618            {
619              names = (char *)XtRealloc(names,strlen(names)+
620                               strlen(destinationPath)+2);
621              strcat(names,"\n");
622              strcat(names,destinationPath);
623            }
624          }
625          else
626            saveError = 0;
627          write(G_filop_confirm_fd, &saveError, sizeof(int));
628          XtFree(destinationPath);
629       }
630
631           else
632           {
633               saveError = 0;
634               write(G_filop_confirm_fd, &saveError, sizeof(int));
635           }
636       }
637
638       if(!same)
639       {
640           if ( names )
641           {
642               char *buf;
643               int bufsize;
644               buf = XtMalloc(strlen(GETMESSAGE(9,138, "Failed to rename the following object(s)\n\n%s\n\nThe most likely cause is that you do not have\npermission to rename these objects(s)"))+strlen(names)+10);
645               sprintf(buf,GETMESSAGE(9,138, "Failed to rename the following object(s)\n\n%s\n\nThe most likely cause is that you do not have\npermission to rename these object(s)"),names);
646               _DtMessage(toplevel, title, buf, NULL, HelpRequestCB);
647               XtFree(buf);
648           }
649           XtFree(names);
650       }
651       XtFree(title);
652    }
653    else
654    {
655       char *names = NULL;
656
657       title = XtNewString(GETMESSAGE(9, 40, "Object Replace - Error"));
658       write(G_filop_confirm_fd, &rc, sizeof(int));
659
660       /* Replace was selected ... remove the offending targets */
661       for ( i = 0; i < G_nCollisions; i++)
662       {
663          destinationPath = build_path(G_directory,G_fileList[i]);
664          if(IsReplaceable(destinationPath))
665          {
666            if(DirectoryBusy(destinationPath))
667            {
668              char *msg,*errmsg;
669
670              msg = GETMESSAGE(11,30, "Cannot move or rename the folder%s.\nAll File Manager views displayed for a folder or its sub-folders\nmust be closed before a folder can be moved or renamed.");
671
672              errmsg = XtMalloc(strlen(msg)+strlen(destinationPath)+1);
673              sprintf(errmsg,msg,destinationPath);
674              _DtMessage(toplevel, title, errmsg, NULL, HelpRequestCB);
675              XtFree(errmsg);
676              XtFree(destinationPath);
677              continue;
678            }
679            else
680              fsErase(destinationPath,&saveError,False);
681          }
682          else
683            saveError = -1;
684          write(G_filop_confirm_fd, &saveError, sizeof(int));
685          if(saveError != 0)
686          {
687            if(!names)
688              names = (char *) XtNewString(destinationPath);
689            else
690            {
691              names = (char *)XtRealloc(names,strlen(names)+
692                               strlen(destinationPath)+2);
693              strcat(names,"\n");
694              strcat(names,destinationPath);
695            }
696          }
697          XtFree(destinationPath);
698       }
699       if ( names )
700       {
701         char *buf;
702         int bufsize;
703         buf = XtMalloc(strlen(GETMESSAGE(9,139, "Failed to replace the following object(s)\n\n%s\n\nThe most likely cause is that you do not have\npermission to replace these object(s)"))+strlen(names)+10);
704         sprintf(buf,GETMESSAGE(9,139, "Failed to replace the following object(s)\n\n%s\n\nThe most likely cause is that you do not have\npermission to replace these object(s)"),names);
705         _DtMessage(toplevel, title, buf, NULL, HelpRequestCB);
706         XtFree(buf);
707       }
708       XtFree(names);
709       XtFree(title);
710    }
711
712
713    /* close the dialog */
714    XtDestroyWidget(G_dialogShell);
715    G_dialogShell = NULL;
716
717    /* de-allocate the file list */
718    for ( i = 0; i < G_nCollisions; i++)
719       XtFree((char *)G_fileList[i]);
720    XtFree((char *)G_fileList);
721    G_fileList = NULL;
722
723    /* send return code through the pipe to the background proc */
724 /*
725    write(G_filop_confirm_fd, &rc, sizeof(int));
726 */
727    G_filop_confirm_fd = -1;
728 }  /*  end multicollide_ok_callback */
729
730
731 void
732 buffer_multicollide_ok_callback(
733         Widget w,
734         XtPointer client_data,
735         XtPointer call_data)
736 {
737    int          rc = 0;
738    int          i;
739    int          saveError;
740    String       destinationPath;
741    String       title;
742    char         newPath[MAX_PATH];
743    char         *newFile;
744    static char  msg[1024];
745    struct stat  buf;
746
747
748    if (XmToggleButtonGetState(G_multi_rename_toggle))
749    {
750      /* send return code through the pipe to the background proc */
751       rc = PIPEMSG_RENAME_BUFFER;
752       write(G_filop_confirm_fd, &rc, sizeof(int));
753
754       /* Auto rename was selected */
755       for ( i = 0; i < G_nCollisions; i++)
756       {
757          /* automatically generated new name */
758          destinationPath = build_path(G_directory,G_fileList[i]);
759          generate_NewPath(newPath, destinationPath);
760          newFile= strrchr(newPath,'/') + 1 ;
761
762          DPRINTF (("buffer_multicollide_ok_callback: new file is %s\n", newFile));
763
764          /* write new name on the pipe */
765
766          PipeWriteString(G_filop_confirm_fd, newFile);
767
768          XtFree(destinationPath);
769       }
770    } /* endif multi auto-rename */
771    else
772    {
773       title = XtNewString(GETMESSAGE(9, 40, "Object Replace - Error"));
774
775       /* Replace was selected ... remove the offending targets */
776       for ( i = 0; i < G_nCollisions; i++)
777       {
778          /* set the pipe msg */
779          rc = PIPEMSG_REPLACE_BUFFER;
780
781          destinationPath = build_path(G_directory,G_fileList[i]);
782          fsErase(destinationPath,&saveError,False);
783          if ( saveError != 0 )
784          {
785             /* removal failed */
786             stat(destinationPath,&buf);
787
788             if ( S_ISDIR(buf.st_mode) && i != 1 )
789             {
790                sprintf(msg,
791                        getVariableMessage(vm_multiCannotDeleteFolderMany, COPY_FILE),
792                        destinationPath, i);
793             }
794             else if ( S_ISDIR(buf.st_mode) && i == 1)
795             {
796                sprintf(msg,
797                        getVariableMessage(vm_multiCannotDeleteFolderOne, COPY_FILE),
798                        destinationPath);
799             }
800             else if ( ! S_ISDIR(buf.st_mode) && i != 1 )
801             {
802                sprintf(msg,
803                        getVariableMessage(vm_multiCannotDeleteFileMany, COPY_FILE),
804                        destinationPath, i);
805             }
806             else  /*  ! S_ISDIR(buf.st_mode) && i == 1 ) */
807             {
808                sprintf(msg,
809                        getVariableMessage(vm_multiCannotDeleteFileOne, COPY_FILE),
810                        destinationPath);
811             }
812             _DtMessageDialog (G_dialogShell, title, msg, 0, FALSE, NULL,
813                               multiReplaceError_ok_callback, NULL, NULL, False, ERROR_DIALOG);
814             XtFree(destinationPath);
815             return;
816          }
817
818
819          /* send return code through the pipe to the background proc */
820          rc = PIPEMSG_REPLACE_BUFFER;
821          write(G_filop_confirm_fd, &rc, sizeof(int));
822
823          XtFree(destinationPath);
824       }
825       XtFree(title);
826    } /* end else */
827
828
829    /* close the dialog */
830    XtDestroyWidget(G_dialogShell);
831    G_dialogShell = NULL;
832
833    /* de-allocate the file list */
834    for ( i = 0; i < G_nCollisions; i++)
835       XtFree((char *)G_fileList[i]);
836    XtFree((char *)G_fileList);
837    G_fileList = NULL;
838
839    G_filop_confirm_fd = -1;
840
841 }  /*  end multicollide_ok_callback */
842
843
844
845 static void
846 replaceError_ok_callback(
847         Widget w,
848         XtPointer client_data,
849         XtPointer call_data)
850 {
851   XtDestroyWidget((Widget)client_data);
852
853   return;
854 }  /* end replaceError_ok_callback */
855
856
857
858 static void
859 multiReplaceError_ok_callback(
860         Widget w,
861         XtPointer client_data,
862         XtPointer call_data)
863 {
864   XtDestroyWidget((Widget)client_data);
865
866   return;
867 }  /* end multiReplaceError_ok_callback */
868
869
870
871 static void
872 multiRenameError_ok_callback(
873         Widget w,
874         XtPointer client_data,
875         XtPointer call_data)
876 {
877   XtDestroyWidget((Widget)client_data);
878
879   return;
880 }  /* end multiRenameError_ok_callback */
881
882
883
884 /*--------------------------------------------------------------------
885  * create replace/rename dialog
886  *------------------------------------------------------------------*/
887
888 void
889 create_replace_rename_dialog(Widget         parent_widget,
890                              int            mode,
891                              String         directory,
892                              String         file,
893                              int            filop_confirm_fd,
894                              ActionAreaDefn actions,
895                              Boolean        Same)
896 {
897   Arg args[10];
898   int n;
899   Widget form;
900   Widget icon;
901   Widget action_label;
902   Widget msg_label;
903   Widget radio;
904   Widget radioButton1;
905   Widget actionArea;
906   Widget separator;
907   Pixmap px;
908   Pixel background, foreground;
909   char     path[MAX_PATH], newDir[MAX_PATH], newFile[MAX_PATH];
910   String   s;
911   XmString xs;
912   char *title;
913   char *orig_label;
914   int orig_msg_num;
915   Boolean set;
916
917   if( G_dialogShell )
918   {
919      XBell( XtDisplay( G_dialogShell ), 100 );
920      return;
921   }
922
923   /* make args available to callback functions */
924   G_filop_confirm_fd = filop_confirm_fd;
925   G_mode             = mode;
926   strcpy(G_directory,directory);
927   strcpy(G_file,file);
928
929   /* Initialize images for error, warning, ... icons */
930   if (G_initImages)
931   {
932      ImageInitialize(XtDisplay(toplevel));
933      G_initImages = False;
934   }
935
936   /* Initialize mode-dependent things */
937   n = 0;
938   orig_label = actions.actionList[1].label;
939   orig_msg_num = actions.actionList[1].msg_num;
940   switch (mode) {
941      case MOVE_FILE:
942         title = XtNewString(GETMESSAGE(9, 34, "File Manager - Move Warning"));
943         XtSetArg (args[n], XmNtitle, title);
944         n++;
945         actions.actionList[1].label   = XtNewString(GETMESSAGE(9, 30, "Cancel Move"));
946         actions.actionList[1].msg_num = 30;
947         break;
948      case COPY_FILE:
949         title = XtNewString(GETMESSAGE(9, 35, "File Manager - Copy Warning"));
950         XtSetArg (args[n], XmNtitle, title);
951         n++;
952         actions.actionList[1].label   = XtNewString(GETMESSAGE(9, 31, "Cancel Copy"));
953         actions.actionList[1].msg_num = 31;
954         break;
955      case LINK_FILE:
956         title = XtNewString(GETMESSAGE(9, 36, "File Manager - Link Warning"));
957         XtSetArg (args[n], XmNtitle, title);
958         n++;
959         actions.actionList[1].label   = XtNewString(GETMESSAGE(9, 32, "Cancel Link"));
960         actions.actionList[1].msg_num = 32;
961         break;
962      default:
963         title = XtNewString(GETMESSAGE(9, 33, "File Manager - Move/Copy/Link Warning"));
964         XtSetArg (args[n], XmNtitle, title);
965         n++;
966         break;
967   }
968
969
970   /* Create the dialog shell for the dialog */
971   G_dialogShell = XmCreateDialogShell (parent_widget, "replace/rename dialog", args, n);
972
973
974   /* Create the Manager Widget, form, for the copy dialog */
975   form  = XtVaCreateWidget ("dialog_form",
976                              xmFormWidgetClass,  G_dialogShell,
977                              XmNverticalSpacing,   VERTICAL_SPACING,
978                              XmNhorizontalSpacing, HORIZONTAL_SPACING,
979                              XmNdialogStyle,       XmDIALOG_FULL_APPLICATION_MODAL,
980                              NULL);
981
982   /* Create a question dialog icon */
983   n = 0;
984   XtSetArg (args[n], XmNbackground, &background); n++;
985   XtSetArg (args[n], XmNforeground, &foreground); n++;
986   XtGetValues (form, args, n);
987
988   px = XmGetPixmapByDepth(XtScreen(form), "xm_question",
989                           foreground, background, form->core.depth);
990   if (px == XmUNSPECIFIED_PIXMAP)
991     px = XmGetPixmapByDepth(XtScreen(form), "default_xm_question",
992                      foreground, background, form->core.depth);
993
994   icon = XtVaCreateManagedWidget("question_icon",
995                              xmLabelWidgetClass, form,
996                              XmNlabelType,        XmPIXMAP,
997                              XmNlabelPixmap,      px,
998                              XmNtopAttachment,    XmATTACH_FORM,
999                              XmNleftAttachment,   XmATTACH_FORM,
1000                              NULL);
1001
1002   /* Create the message label */
1003   s = XtMalloc( 1
1004                 + strlen( GETMESSAGE(9, 16, "An object named\n%s\nalready exists inside the folder\n%s") )
1005                 + strlen( file )
1006                 + strlen( directory ) );
1007   sprintf( s,
1008            GETMESSAGE(9, 16, "An object named\n%s\nalready exists inside the folder\n%s"),
1009            file,
1010            directory );
1011
1012   xs = XmStringCreateLocalized(s);
1013   msg_label = XtVaCreateManagedWidget("msg_header",
1014                              xmLabelWidgetClass, form,
1015                              XmNlabelString,      xs,
1016                              XmNalignment,        XmALIGNMENT_BEGINNING,
1017                              XmNtopAttachment,    XmATTACH_FORM,
1018                              XmNleftAttachment,   XmATTACH_WIDGET,
1019                              XmNleftWidget,       icon,
1020                              XmNleftOffset,       HORIZONTAL_SPACING,
1021                              XmNrightAttachment,  XmATTACH_FORM,
1022                              NULL);
1023   XmStringFree(xs);
1024   XtFree(s);
1025
1026
1027   /* create the action-question */
1028   xs = XmStringCreateLocalized(GETMESSAGE(9, 20, "What do you want to do?"));
1029   action_label = XtVaCreateManagedWidget("action-question",
1030                              xmLabelWidgetClass, form,
1031                              XmNlabelString,      xs,
1032                              XmNalignment,        XmALIGNMENT_BEGINNING,
1033                              XmNtopAttachment,    XmATTACH_WIDGET,
1034                              XmNtopWidget,        msg_label,
1035                              XmNtopOffset,        3*VERTICAL_SPACING,
1036                              XmNleftAttachment,   XmATTACH_OPPOSITE_WIDGET,
1037                              XmNleftWidget,       msg_label,
1038                              XmNleftOffset,       0,
1039                              NULL);
1040   XmStringFree(xs);
1041
1042   /* create radio box */
1043
1044   n = 0;
1045   XtSetArg (args[n], XmNorientation,      XmVERTICAL);               n++;
1046   XtSetArg (args[n], XmNtopAttachment,    XmATTACH_WIDGET);          n++;
1047   XtSetArg (args[n], XmNtopWidget,        action_label);             n++;
1048   XtSetArg (args[n], XmNleftAttachment,   XmATTACH_OPPOSITE_WIDGET); n++;
1049   XtSetArg (args[n], XmNleftWidget,       action_label);             n++;
1050   XtSetArg (args[n], XmNleftOffset,       2*HORIZONTAL_SPACING);     n++;
1051   radio = (Widget) XmCreateRadioBox(form, "radio_box", args, n);
1052
1053   if( mode == MAKE_BUFFER )
1054     set = FALSE;
1055   else
1056   {
1057       /* if the object is have the operation done to the same folder (i.e.
1058          being done to itself, we want the default to be to create a new name
1059          for the new object.
1060          */
1061       if(Same)
1062           set = FALSE;
1063       else
1064     set = TRUE;
1065   }
1066
1067   /* create the radio buttons ... default button is replace */
1068   xs = XmStringCreateLocalized(GETMESSAGE(9, 21, "Replace existing object"));
1069   radioButton1 = XtVaCreateManagedWidget("radio_toggle1",
1070                                          xmToggleButtonWidgetClass, radio,
1071                                          XmNalignment,   XmALIGNMENT_BEGINNING,
1072                                          XmNlabelString, xs,
1073                                          XmNset,         set,
1074                                          NULL);
1075   XmStringFree(xs);
1076   if(!Same)
1077   {
1078       XtSetSensitive(radioButton1, True);
1079       XtAddCallback(radioButton1, XmNvalueChangedCallback, replace_rename_radio_callback, (XtPointer) RADIO_REPLACE);
1080   }
1081   else
1082       XtSetSensitive(radioButton1, False);
1083
1084   if( mode == MAKE_BUFFER )
1085   {
1086     xs = XmStringCreateLocalized(GETMESSAGE(10,48, "New Object Name:"));
1087     set = TRUE;
1088   }
1089   else
1090   {
1091       if(Same)
1092       {
1093           xs = XmStringCreateLocalized(GETMESSAGE(9, 140, "Rename new object to:"));
1094           set = TRUE;
1095       }
1096       else
1097       {
1098           xs = XmStringCreateLocalized(GETMESSAGE(9, 22, "Rename existing object to:"));
1099           set = FALSE;
1100       }
1101   }
1102   G_rename_toggle = XtVaCreateManagedWidget("radio_toggle2",
1103                                             xmToggleButtonWidgetClass, radio,
1104                                             XmNalignment,   XmALIGNMENT_BEGINNING,
1105                                             XmNlabelString, xs,
1106                                             XmNset,         set,
1107                                             NULL);
1108   XmStringFree(xs);
1109   XtAddCallback(G_rename_toggle, XmNvalueChangedCallback, replace_rename_radio_callback, (XtPointer) RADIO_RENAME);
1110
1111   XtManageChild(radio);
1112
1113
1114   /* create text field for entering a new file name */
1115   /* a name is generated to use as the default */
1116   _DtBuildPath(path,directory,file);
1117   generate_NewPath(path,path);
1118   split_path(path, newDir, newFile);
1119   G_rename_text = XtVaCreateManagedWidget("rename_text",
1120                                        xmTextFieldWidgetClass, form,
1121                                        XmNrightAttachment,  XmATTACH_FORM,
1122                                        XmNleftAttachment,   XmATTACH_WIDGET,
1123                                        XmNleftWidget,       radio,
1124                                        XmNleftOffset,       HORIZONTAL_SPACING,
1125                                        XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
1126                                        XmNbottomWidget,     radio,
1127                                        XmNsensitive,        set,
1128                                        XmNvalue,            newFile,
1129                                        XmNcursorPosition,   strlen(newFile),
1130                                        NULL);
1131
1132   /* create the action area  */
1133   actionArea = Create_Action_Area(form, actions,  NULL);
1134   separator  =  XtVaCreateManagedWidget("separator",
1135                                         xmSeparatorWidgetClass, form,
1136                                         XmNtopAttachment,     XmATTACH_WIDGET,
1137                                         XmNtopWidget,         radio,
1138                                         XmNbottomAttachment,  XmATTACH_WIDGET,
1139                                         XmNbottomWidget,      actionArea,
1140                                         XmNleftAttachment,    XmATTACH_FORM,
1141                                         XmNrightAttachment,   XmATTACH_FORM,
1142                                         NULL);
1143
1144
1145   /* set initial keyborad focus to the action button area */
1146   XtVaSetValues(form,
1147                 XmNinitialFocus, actionArea,
1148                 NULL);
1149
1150   /* Manage the dialog */
1151   XtManageChild(form);
1152
1153
1154   XtFree(title);
1155   XtFree(actions.actionList[1].label);
1156   actions.actionList[1].label = orig_label;
1157   actions.actionList[1].msg_num = orig_msg_num;
1158   return;
1159
1160 }  /* end create_replace_rename_dialog */
1161
1162
1163
1164 /*--------------------------------------------------------------------
1165  * create replace/merge dialog
1166  *------------------------------------------------------------------*/
1167
1168 void
1169 create_replace_merge_dialog(Widget parent_widget,
1170                              int            mode,
1171                              String         directory,
1172                              String         file,
1173                              int            filop_confirm_fd,
1174                              ActionAreaDefn actions)
1175 {
1176   Arg args[10];
1177   int n;
1178   Widget form;
1179   Widget icon;
1180   Widget action_label;
1181   Widget msg_label;
1182   Widget radio;
1183   Widget radioButton1;
1184   Widget actionArea;
1185   Widget separator;
1186   Pixmap px;
1187   Pixel background, foreground;
1188   char     path[MAX_PATH], newDir[MAX_PATH], newFile[MAX_PATH];
1189   String   s;
1190   XmString xs;
1191   char *title;
1192   char *orig_label;
1193   int orig_msg_num;
1194
1195   if( G_dialogShell )
1196   {
1197      XBell( XtDisplay( G_dialogShell ), 100 );
1198      return;
1199   }
1200
1201   /* make args available to callback functions */
1202   G_filop_confirm_fd = filop_confirm_fd;
1203   G_mode             = mode;
1204   strcpy(G_directory,directory);
1205   strcpy(G_file,file);
1206
1207   /* Initialize images for error, warning, ... icons */
1208   if (G_initImages)
1209   {
1210      ImageInitialize(XtDisplay(toplevel));
1211      G_initImages = False;
1212   }
1213
1214   /* Initialize mode-dependent things */
1215   n = 0;
1216   orig_label = actions.actionList[1].label;
1217   orig_msg_num = actions.actionList[1].msg_num;
1218   switch (mode) {
1219      case MOVE_FILE:
1220         title = XtNewString(GETMESSAGE(9, 34, "File Manager - Move Warning"));
1221         XtSetArg (args[n], XmNtitle, title);
1222         n++;
1223         actions.actionList[1].label   = XtNewString(GETMESSAGE(9, 30, "Cancel Move"));
1224         actions.actionList[1].msg_num = 30;
1225         break;
1226      case COPY_FILE:
1227         title = XtNewString(GETMESSAGE(9, 35, "File Manager - Copy Warning"));
1228         XtSetArg (args[n], XmNtitle, title);
1229         n++;
1230         actions.actionList[1].label   = XtNewString(GETMESSAGE(9, 31, "Cancel Copy"));
1231         actions.actionList[1].msg_num = 31;
1232         break;
1233      case LINK_FILE:
1234         title = XtNewString(GETMESSAGE(9, 36, "File Manager - Link Warning"));
1235         XtSetArg (args[n], XmNtitle, title);
1236         n++;
1237         actions.actionList[1].label   = XtNewString(GETMESSAGE(9, 32, "Cancel Link"));
1238         actions.actionList[1].msg_num = 32;
1239         break;
1240      default:
1241         title = XtNewString(GETMESSAGE(9, 33, "File Manager - Move/Copy/Link Warning"));
1242         XtSetArg (args[n], XmNtitle, title);
1243         n++;
1244         break;
1245   }
1246
1247
1248   /* Create the dialog shell for the dialog */
1249   G_dialogShell = XmCreateDialogShell (parent_widget, "replace/merge dialog", args, n);
1250
1251
1252   /* Create the Manager Widget, form, for the copy dialog */
1253   form  = XtVaCreateWidget ("dialog_form",
1254                              xmFormWidgetClass,  G_dialogShell,
1255                              XmNverticalSpacing,   VERTICAL_SPACING,
1256                              XmNhorizontalSpacing, HORIZONTAL_SPACING,
1257                              XmNdialogStyle,       XmDIALOG_FULL_APPLICATION_MODAL,
1258                              NULL);
1259
1260   /* Create a question dialog icon */
1261   n = 0;
1262   XtSetArg (args[n], XmNbackground, &background); n++;
1263   XtSetArg (args[n], XmNforeground, &foreground); n++;
1264   XtGetValues (form, args, n);
1265
1266   px = XmGetPixmapByDepth(XtScreen(form), "xm_question",
1267                           foreground, background, form->core.depth);
1268   if (px == XmUNSPECIFIED_PIXMAP)
1269     px = XmGetPixmapByDepth(XtScreen(form), "default_xm_question",
1270                      foreground, background, form->core.depth);
1271
1272   icon = XtVaCreateManagedWidget("question_icon",
1273                              xmLabelWidgetClass, form,
1274                              XmNlabelType,        XmPIXMAP,
1275                              XmNlabelPixmap,      px,
1276                              XmNtopAttachment,    XmATTACH_FORM,
1277                              XmNleftAttachment,   XmATTACH_FORM,
1278                              NULL);
1279
1280   /* Create the message label */
1281   s = XtMalloc( 1
1282                 + strlen( GETMESSAGE(9, 17, "A folder named\n%s\nalready exists inside the folder\n%s") )
1283                 + strlen( file )
1284                 + strlen( directory ) );
1285
1286   sprintf(s, GETMESSAGE(9, 17, "A folder named\n%s\nalready exists inside the folder\n%s"), file, directory);
1287
1288   xs = XmStringCreateLocalized(s);
1289   msg_label = XtVaCreateManagedWidget("msg_header",
1290                              xmLabelWidgetClass, form,
1291                              XmNlabelString,      xs,
1292                              XmNalignment,        XmALIGNMENT_BEGINNING,
1293                              XmNtopAttachment,    XmATTACH_FORM,
1294                              XmNleftAttachment,   XmATTACH_WIDGET,
1295                              XmNleftWidget,       icon,
1296                              XmNleftOffset,       HORIZONTAL_SPACING,
1297                              XmNrightAttachment,  XmATTACH_FORM,
1298                              NULL);
1299   XmStringFree(xs);
1300   XtFree(s);
1301
1302
1303   /* create the action-question */
1304   xs = XmStringCreateLocalized(GETMESSAGE(9, 20, "What do you want to do?"));
1305   action_label = XtVaCreateManagedWidget("action-question",
1306                              xmLabelWidgetClass, form,
1307                              XmNlabelString,      xs,
1308                              XmNalignment,        XmALIGNMENT_BEGINNING,
1309                              XmNtopAttachment,    XmATTACH_WIDGET,
1310                              XmNtopWidget,        msg_label,
1311                              XmNtopOffset,        3*VERTICAL_SPACING,
1312                              XmNleftAttachment,   XmATTACH_OPPOSITE_WIDGET,
1313                              XmNleftWidget,       msg_label,
1314                              XmNleftOffset,       0,
1315                              NULL);
1316   XmStringFree(xs);
1317
1318   /* create radio box */
1319
1320   n = 0;
1321   XtSetArg (args[n], XmNorientation,      XmVERTICAL);               n++;
1322   XtSetArg (args[n], XmNtopAttachment,    XmATTACH_WIDGET);          n++;
1323   XtSetArg (args[n], XmNtopWidget,        action_label);             n++;
1324   XtSetArg (args[n], XmNleftAttachment,   XmATTACH_OPPOSITE_WIDGET); n++;
1325   XtSetArg (args[n], XmNleftWidget,       action_label);             n++;
1326   XtSetArg (args[n], XmNleftOffset,       2*HORIZONTAL_SPACING);     n++;
1327   radio = (Widget) XmCreateRadioBox(form, "radio_box", args, n);
1328
1329   /* create the radio buttons ... default button is replace */
1330   xs = XmStringCreateLocalized(GETMESSAGE(9, 25, "Replace existing folder"));
1331   radioButton1 = XtVaCreateManagedWidget("radio_toggle1",
1332                                          xmToggleButtonWidgetClass, radio,
1333                                          XmNalignment,   XmALIGNMENT_BEGINNING,
1334                                          XmNlabelString, xs,
1335                                          XmNset,         TRUE,
1336                                          NULL);
1337   XmStringFree(xs);
1338
1339   xs = XmStringCreateLocalized(GETMESSAGE(9, 24, "Merge contents of the two folders"));
1340   G_merge_toggle = XtVaCreateManagedWidget("radio_toggle2",
1341                                             xmToggleButtonWidgetClass, radio,
1342                                             XmNalignment,   XmALIGNMENT_BEGINNING,
1343                                             XmNlabelString, xs,
1344                                             NULL);
1345   XmStringFree(xs);
1346
1347   XtManageChild(radio);
1348
1349
1350   /* create the action area  */
1351   actionArea = Create_Action_Area(form, actions, NULL);
1352   separator  =  XtVaCreateManagedWidget("separator",
1353                                         xmSeparatorWidgetClass, form,
1354                                         XmNtopAttachment,     XmATTACH_WIDGET,
1355                                         XmNtopWidget,         radio,
1356                                         XmNbottomAttachment,  XmATTACH_WIDGET,
1357                                         XmNbottomWidget,      actionArea,
1358                                         XmNleftAttachment,    XmATTACH_FORM,
1359                                         XmNrightAttachment,   XmATTACH_FORM,
1360                                         NULL);
1361
1362
1363   /* set initial keyborad focus to the action button area */
1364   XtVaSetValues(form,
1365                 XmNinitialFocus, actionArea,
1366                 NULL);
1367
1368   /* Manage the dialog */
1369   XtManageChild(form);
1370
1371
1372   XtFree(title);
1373   XtFree(actions.actionList[1].label);
1374   actions.actionList[1].label = orig_label;
1375   actions.actionList[1].msg_num = orig_msg_num;
1376   return;
1377
1378 }  /* end create_replace_merge_dialog */
1379
1380
1381
1382
1383 /*--------------------------------------------------------------------
1384  * create multicollide dialog
1385  *------------------------------------------------------------------*/
1386
1387 void
1388 create_multicollide_dialog(Widget           parent_widget,
1389                            int              mode,
1390                            int              nSelected,
1391                            int              nCollisions,
1392                            String           destination,
1393                            String         * fileList,
1394                            int              filop_confirm_fd,
1395                            ActionAreaDefn   actions,
1396                            Boolean          Same)
1397 {
1398   Arg args[10];
1399   int n;
1400   Widget form;
1401   Widget icon;
1402   Widget action_label;
1403   Widget msg_label;
1404   Widget radio;
1405   Widget radioButton1;
1406   Widget actionArea;
1407   Widget separator;
1408   Pixmap px;
1409   Pixel background, foreground;
1410   String   s, s1, eMsgOne, eMsgMany;
1411   int nChanged;
1412   XmString xs;
1413   char *title;
1414   char *orig_label;
1415   int orig_msg_num;
1416   Boolean set;
1417
1418   if( G_dialogShell )
1419   {
1420      XBell( XtDisplay( G_dialogShell ), 100 );
1421      return;
1422   }
1423
1424   /* make args available to callback functions */
1425   G_filop_confirm_fd = filop_confirm_fd;
1426   strcpy(G_directory,destination);
1427   G_fileList    = fileList;
1428   G_nCollisions = nCollisions;
1429   G_mode        = mode;
1430
1431   /* Initialize images for error, warning, ... icons */
1432   if (G_initImages)
1433   {
1434      ImageInitialize(XtDisplay(toplevel));
1435      G_initImages = False;
1436   }
1437
1438   /* Initialize mode-dependent things */
1439   n = 0;
1440   orig_label = actions.actionList[1].label;
1441   orig_msg_num = actions.actionList[1].msg_num;
1442   switch (mode) {
1443      case MOVE_FILE:
1444         title = XtNewString(GETMESSAGE(9, 34, "File Manager - Move Warning"));
1445         XtSetArg (args[n], XmNtitle, title);
1446         n++;
1447         actions.actionList[1].label   =
1448            XtNewString(GETMESSAGE(9, 30, "Cancel Move"));
1449         actions.actionList[1].msg_num = 30;
1450         eMsgOne  = XtNewString(GETMESSAGE(9, 127, "1 object moved."));
1451         eMsgMany = XtNewString(GETMESSAGE(9, 128, "%d objects moved."));
1452         break;
1453      case COPY_FILE:
1454         title = XtNewString(GETMESSAGE(9, 35, "File Manager - Copy Warning"));
1455         XtSetArg (args[n], XmNtitle, title);
1456         n++;
1457         actions.actionList[1].label   =
1458            XtNewString(GETMESSAGE(9, 31, "Cancel Copy"));
1459         actions.actionList[1].msg_num = 31;
1460         eMsgOne  = XtNewString(GETMESSAGE(9, 129, "1 object copied."));
1461         eMsgMany = XtNewString(GETMESSAGE(9, 130, "%d objects copied."));
1462         break;
1463      case LINK_FILE:
1464         title = XtNewString(GETMESSAGE(9, 36, "File Manager - Link Warning"));
1465         XtSetArg (args[n], XmNtitle, title);
1466         n++;
1467         actions.actionList[1].label   =
1468            XtNewString(GETMESSAGE(9, 32, "Cancel Link"));
1469         actions.actionList[1].msg_num = 32;
1470         eMsgOne  = XtNewString(GETMESSAGE(9, 131, "1 object linked."));
1471         eMsgMany = XtNewString(GETMESSAGE(9, 132, "%d objects linked."));
1472         break;
1473      default:
1474         title = XtNewString(GETMESSAGE(9, 33, "File Manager - Move/Copy/Link Warning"));
1475         XtSetArg (args[n], XmNtitle, title);
1476         n++;
1477         eMsgOne  = XtNewString(GETMESSAGE(9, 133, "1 object changed."));
1478         eMsgMany = XtNewString(GETMESSAGE(9, 134, "%d objects changed."));
1479         break;
1480   }
1481
1482
1483   /* Create the dialog shell for the dialog */
1484   G_dialogShell = XmCreateDialogShell (parent_widget, "multicollide dialog", args, n);
1485
1486
1487   /* Create the Manager Widget, form, for the copy dialog */
1488   form  = XtVaCreateWidget ("dialog_form",
1489                              xmFormWidgetClass,  G_dialogShell,
1490                              XmNverticalSpacing,   VERTICAL_SPACING,
1491                              XmNhorizontalSpacing, HORIZONTAL_SPACING,
1492                              XmNdialogStyle,       XmDIALOG_FULL_APPLICATION_MODAL,
1493                              NULL);
1494
1495   /* Create a question dialog icon */
1496   n = 0;
1497   XtSetArg (args[n], XmNbackground, &background); n++;
1498   XtSetArg (args[n], XmNforeground, &foreground); n++;
1499   XtGetValues (form, args, n);
1500
1501   px = XmGetPixmapByDepth(XtScreen(form), "xm_question",
1502                           foreground, background, form->core.depth);
1503   if (px == XmUNSPECIFIED_PIXMAP)
1504     px = XmGetPixmapByDepth(XtScreen(form), "default_xm_question",
1505                      foreground, background, form->core.depth);
1506
1507   icon = XtVaCreateManagedWidget("question_icon",
1508                              xmLabelWidgetClass, form,
1509                              XmNlabelType,        XmPIXMAP,
1510                              XmNlabelPixmap,      px,
1511                              XmNtopAttachment,    XmATTACH_FORM,
1512                              XmNleftAttachment,   XmATTACH_FORM,
1513                              NULL);
1514
1515   /* Create the message label */
1516
1517   nChanged = (nSelected - nCollisions);
1518   if ( nChanged == 0 )
1519     /* This is really stupid but Sun requires it
1520        For now just get it work.
1521      */
1522     s1 = (char *)XtCalloc( 1, 1 );
1523   else if ( nChanged == 1 )
1524   {
1525     s1 = eMsgOne;
1526   }
1527   else
1528   {
1529     s1 = (char *)XtMalloc( 20 + strlen(eMsgMany) );
1530
1531     sprintf(s1, eMsgMany, nChanged);
1532   }
1533
1534   if (nCollisions > 1)
1535   {
1536     int tmp_len = (s1)?strlen(s1):0;
1537     char *tmpmsg,*filemsg=NULL;
1538     int i;
1539
1540     filemsg = XtMalloc(strlen(destination)+3);
1541     sprintf(filemsg,"%s\n",destination);
1542     for(i = 0;i < nCollisions; i++)
1543     {
1544        if(i > 7)
1545        {
1546          char *addmsg;
1547          tmpmsg = GETMESSAGE(27,98, "(Plus %d additional object(s))");
1548          addmsg = XtMalloc(strlen(tmpmsg)+10);
1549          sprintf(addmsg,tmpmsg,nCollisions-8);
1550          filemsg = XtRealloc(filemsg,strlen(filemsg)+strlen(addmsg)+4);
1551          strcat(filemsg,"\n\n");
1552          strcat(filemsg,addmsg);
1553          XtFree(addmsg);
1554          break;
1555        }
1556        filemsg = XtRealloc(filemsg,strlen(filemsg)+strlen(destination)+
1557                       strlen(fileList[i])+3);
1558        strcat(filemsg,"\n");
1559        strcat(filemsg,destination);
1560        strcat(filemsg,"/");
1561        strcat(filemsg,fileList[i]);
1562     }
1563     filemsg = XtRealloc(filemsg,strlen(filemsg)+2);
1564
1565     tmpmsg = GETMESSAGE(9, 70,
1566               "%s\n%d objects have the same name as objects in the folder\n%s");
1567     s = (char *)XtMalloc( tmp_len + strlen(tmpmsg) + strlen(filemsg) + 10);
1568     sprintf(s,tmpmsg,s1, nCollisions, filemsg);
1569     XtFree(filemsg);
1570   }
1571   else
1572   {
1573     int tmp_len = (s1)?strlen(s1):0;
1574     s = (char *)XtMalloc( tmp_len + 10
1575                           + strlen( GETMESSAGE(9, 71, "%s\n1 object has the same name as an object in the folder\n%s") )
1576                           + strlen( destination ) );
1577     sprintf(s, GETMESSAGE(9, 71, "%s\n1 object has the same name as an object in the folder\n%s"), s1, destination);
1578   }
1579
1580   xs = XmStringCreateLocalized(s);
1581   msg_label = XtVaCreateManagedWidget("msg_header",
1582                              xmLabelWidgetClass, form,
1583                              XmNlabelString,      xs,
1584                              XmNalignment,        XmALIGNMENT_BEGINNING,
1585                              XmNtopAttachment,    XmATTACH_FORM,
1586                              XmNleftAttachment,   XmATTACH_WIDGET,
1587                              XmNleftWidget,       icon,
1588                              XmNleftOffset,       HORIZONTAL_SPACING,
1589                              XmNrightAttachment,  XmATTACH_FORM,
1590                              NULL);
1591   XmStringFree(xs);
1592   XtFree(s);
1593   XtFree(s1);
1594   XtFree(eMsgOne);
1595   XtFree(eMsgMany);
1596
1597
1598   /* create the action-question */
1599   xs = XmStringCreateLocalized(GETMESSAGE(9, 20, "What do you want to do?"));
1600   action_label = XtVaCreateManagedWidget("action-question",
1601                              xmLabelWidgetClass, form,
1602                              XmNlabelString,      xs,
1603                              XmNalignment,        XmALIGNMENT_BEGINNING,
1604                              XmNtopAttachment,    XmATTACH_WIDGET,
1605                              XmNtopWidget,        msg_label,
1606                              XmNtopOffset,        3*VERTICAL_SPACING,
1607                              XmNleftAttachment,   XmATTACH_OPPOSITE_WIDGET,
1608                              XmNleftWidget,       msg_label,
1609                              XmNleftOffset,       0,
1610                              NULL);
1611   XmStringFree(xs);
1612
1613   /* create radio box */
1614
1615   n = 0;
1616   XtSetArg (args[n], XmNorientation,      XmVERTICAL);               n++;
1617   XtSetArg (args[n], XmNtopAttachment,    XmATTACH_WIDGET);          n++;
1618   XtSetArg (args[n], XmNtopWidget,        action_label);             n++;
1619   XtSetArg (args[n], XmNleftAttachment,   XmATTACH_OPPOSITE_WIDGET); n++;
1620   XtSetArg (args[n], XmNleftWidget,       action_label);             n++;
1621   XtSetArg (args[n], XmNleftOffset,       2*HORIZONTAL_SPACING);     n++;
1622   radio = (Widget) XmCreateRadioBox(form, "radio_box", args, n);
1623
1624   /* create the radio buttons ... default button is replace */
1625   xs = XmStringCreateLocalized(GETMESSAGE(9, 56, "Replace existing objects"));
1626
1627   if(Same)
1628       set = FALSE;
1629   else
1630       set = TRUE;
1631
1632   radioButton1 = XtVaCreateManagedWidget("radio_toggle1",
1633                                          xmToggleButtonWidgetClass, radio,
1634                                          XmNalignment,   XmALIGNMENT_BEGINNING,
1635                                          XmNlabelString, xs,
1636                                          XmNset,         set,
1637                                          NULL);
1638   XmStringFree(xs);
1639   if(Same)
1640   {
1641       XtSetSensitive(radioButton1, False);
1642       set = TRUE;
1643       xs = XmStringCreateLocalized(GETMESSAGE(9, 141, "Rename new objects by appending a number"));
1644   }
1645   else
1646   {
1647       XtSetSensitive(radioButton1, True);
1648       set = FALSE;
1649       xs = XmStringCreateLocalized(GETMESSAGE(9, 57, "Rename existing objects by appending a number"));
1650   }
1651
1652   G_multi_rename_toggle = XtVaCreateManagedWidget("radio_toggle2",
1653                                                   xmToggleButtonWidgetClass, radio,
1654                                                   XmNalignment,   XmALIGNMENT_BEGINNING,
1655                                                   XmNset,         set,
1656                                                   XmNlabelString, xs,
1657                                                   NULL);
1658   XmStringFree(xs);
1659
1660   XtManageChild(radio);
1661
1662
1663   /* create the action area  */
1664   actionArea = Create_Action_Area(form, actions, NULL);
1665   separator  =  XtVaCreateManagedWidget("separator",
1666                                         xmSeparatorWidgetClass, form,
1667                                         XmNtopAttachment,     XmATTACH_WIDGET,
1668                                         XmNtopWidget,         radio,
1669                                         XmNbottomAttachment,  XmATTACH_WIDGET,
1670                                         XmNbottomWidget,      actionArea,
1671                                         XmNleftAttachment,    XmATTACH_FORM,
1672                                         XmNrightAttachment,   XmATTACH_FORM,
1673                                         NULL);
1674
1675
1676   /* set initial keyborad focus to the action button area */
1677   XtVaSetValues(form,
1678                 XmNinitialFocus, actionArea,
1679                 NULL);
1680
1681   /* Manage the dialog */
1682   XtManageChild(form);
1683
1684
1685   XtFree(title);
1686   XtFree(actions.actionList[1].label);
1687   actions.actionList[1].label = orig_label;
1688   actions.actionList[1].msg_num = orig_msg_num;
1689   return;
1690
1691 }  /* end create_multicollide_dialog */
1692
1693
1694
1695 /*--------------------------------------------------------------------
1696  *
1697  * Create Action Area
1698  *
1699  * Use of this function requires #include "sharedFuncs.h"
1700  * The source for Create_Action_Area is in dtfile/OverWrite.c and
1701  * dtfile/dtcopy/utils.c. Because it uses GETMESSAGE, it could not
1702  * be placed in dtcopy/sharedFunc.c.
1703  *
1704  *------------------------------------------------------------------*/
1705
1706 Widget
1707 Create_Action_Area(
1708         Widget parent_widget,
1709         ActionAreaDefn actions,
1710         Widget *pushbutton_array)
1711 {
1712   Widget action_area, widget;
1713   int i;
1714   int fractbase_value;
1715   XmString xm_string;
1716
1717
1718   if (actions.defaultAction < 0  ||  actions.defaultAction > actions.numActions-1)
1719      actions.defaultAction = 0;
1720
1721   fractbase_value = (TIGHTNESS * actions.numActions) - 1;
1722   action_area = XtVaCreateWidget("action_area", xmFormWidgetClass ,parent_widget,
1723                                 XmNfractionBase, fractbase_value,
1724                                 XmNleftAttachment, XmATTACH_FORM,
1725                                 XmNrightAttachment, XmATTACH_FORM,
1726                                 XmNbottomAttachment, XmATTACH_FORM,
1727                                 NULL);
1728
1729   for (i=0; i < actions.numActions ;i++ )
1730     {
1731       xm_string = XmStringCreateLocalized(GETMESSAGE(actions.actionList[i].msg_set,
1732                                                 actions.actionList[i].msg_num,
1733                                                 actions.actionList[i].label));
1734       widget = XtVaCreateManagedWidget(actions.actionList[i].label,
1735                xmPushButtonWidgetClass, action_area,
1736                XmNleftAttachment,     (i ? XmATTACH_POSITION: XmATTACH_FORM),
1737                XmNleftPosition,       (TIGHTNESS * i),
1738                XmNtopAttachment,      XmATTACH_FORM,
1739                XmNbottomAttachment,   XmATTACH_FORM,
1740                XmNrightAttachment,
1741                         ((i != (actions.numActions - 1)) ? XmATTACH_POSITION: XmATTACH_FORM),
1742                XmNrightPosition,      ((TIGHTNESS*i) + (TIGHTNESS - 1)),
1743                XmNshowAsDefault,      (i == actions.defaultAction),
1744                XmNdefaultButtonShadowThickness, 1,
1745                XmNlabelString,         xm_string,
1746                NULL);
1747       XmStringFree(xm_string);
1748
1749
1750
1751        if (actions.actionList[i].callback)
1752          {
1753            XtAddCallback(widget, XmNactivateCallback,
1754                          actions.actionList[i].callback, actions.actionList[i].data);
1755          }
1756
1757        if (i == actions.defaultAction)
1758          {
1759             Dimension height, h;
1760             XtVaGetValues (action_area, XmNmarginHeight, &h, NULL);
1761             XtVaGetValues (widget, XmNheight, &height, NULL);
1762
1763             height +=2 * h;
1764             XtVaSetValues (action_area,
1765                            XmNdefaultButton, widget,
1766                            XmNpaneMaximum,   height,
1767                            XmNpaneMinimum,   height,
1768                            NULL);
1769
1770          }
1771
1772        if (pushbutton_array != NULL)
1773            pushbutton_array[i] = widget;
1774
1775     } /* endfor */
1776
1777    XtManageChild(action_area);
1778    return action_area;
1779
1780 }  /* end Create_Action_Area */
1781
1782
1783
1784 /*--------------------------------------------------------------------
1785  *
1786  * Get Variable Message
1787  *
1788  * Return the appropriate message for the current mode (move, copy,
1789  * link, or other).
1790  *
1791  *------------------------------------------------------------------*/
1792
1793 static char *
1794 getVariableMessage(
1795         VariableMessage message,
1796         int             mode)
1797 {
1798    switch (message)
1799    {
1800       case vm_replaceCannotDeleteFolder:
1801            switch (mode)
1802            {
1803               case MOVE_FILE:
1804                    return GETMESSAGE(9, 95, "Move Canceled - the folder was not moved.\n\n\
1805 The folder you want to replace could not be deleted\n\
1806 because an object inside that folder could not be deleted.\n\
1807 Some other objects inside that folder may have already been\n\
1808 deleted before the move process was halted.\n\n\
1809 The most probable cause of this problem is that you do not\n\
1810 have Write permission for the object that could not be removed.\n\
1811 Change Write permission or manually rename the folder you\n\
1812 are moving so it no longer has the same name.");
1813                    break;
1814               case COPY_FILE:
1815                    return GETMESSAGE(9, 96, "Copy Canceled - the folder was not copied.\n\n\
1816 The folder you want to replace could not be deleted\n\
1817 because an object inside that folder could not be deleted.\n\
1818 Some other objects inside that folder may have already been\n\
1819 deleted before the copy process was halted.\n\n\
1820 The most probable cause of this problem is that you do not\n\
1821 have Write permission for the object that could not be removed.\n\
1822 Change Write permission or manually rename the folder you\n\
1823 are copying so it no longer has the same name.");
1824                    break;
1825               case LINK_FILE:
1826                    return GETMESSAGE(9, 97, "Link Canceled - the folder was not linked.\n\n\
1827 The folder you want to replace could not be deleted\n\
1828 because an object inside that folder could not be deleted.\n\
1829 Some other objects inside that folder may have already been\n\
1830 deleted before the link process was halted.\n\n\
1831 The most probable cause of this problem is that you do not\n\
1832 have Write permission for the object that could not be removed.\n\
1833 Change Write permission or manually rename the folder you\n\
1834 are linking so it no longer has the same name.");
1835                    break;
1836               default:
1837                    return GETMESSAGE(9, 98, "Operation Canceled - the folder was not changed.\n\n\
1838 The folder you want to replace could not be deleted\n\
1839 because an object inside that folder could not be deleted.\n\
1840 Some other objects inside that folder may have already been\n\
1841 deleted before the process was halted.\n\n\
1842 The most probable cause of this problem is that you do not\n\
1843 have Write permission for the object that could not be removed.\n\
1844 Change Write permission or manually rename the folder you\n\
1845 are changing so it no longer has the same name.");
1846                    break;
1847            }  /* end switch (mode) */
1848
1849       case vm_replaceCannotDeleteFile:
1850            switch (mode)
1851            {
1852               case MOVE_FILE:
1853                    return  GETMESSAGE(9, 99, "Move Canceled\n\n\
1854 %s\n\
1855 cannot be removed.\n\n\
1856 The most probable cause of this problem is that\n\
1857 you do not have Write permission for the file.\n\
1858 Change Write permission or manually rename the\n\
1859 file you are moving so it no longer has the same name.");
1860                    break;
1861               case COPY_FILE:
1862                    return  GETMESSAGE(9, 100, "Copy Canceled\n\n\
1863 %s\n\
1864 cannot be removed.\n\n\
1865 The most probable cause of this problem is that\n\
1866 you do not have Write permission for the file.\n\
1867 Change Write permission or manually rename the\n\
1868 file you are copying so it no longer has the same name.");
1869                    break;
1870               case LINK_FILE:
1871                    return  GETMESSAGE(9, 101, "Link Canceled\n\n\
1872 %s\n\
1873 cannot be removed.\n\n\
1874 The most probable cause of this problem is that\n\
1875 you do not have Write permission for the file.\n\
1876 Change Write permission or manually rename the\n\
1877 file you are linking so it no longer has the same name.");
1878                    break;
1879               default:
1880                    return  GETMESSAGE(9, 102, "Operation Canceled\n\n\
1881 %s\n\
1882 cannot be removed.\n\n\
1883 The most probable cause of this problem is that\n\
1884 you do not have Write permission for the file.\n\
1885 Change Write permission or manually rename the\n\
1886 file you are changing so it no longer has the same name.");
1887                    break;
1888            }  /* end switch (mode) */
1889
1890       case vm_multiCannotRenameMany:
1891            switch (mode)
1892            {
1893               case MOVE_FILE:
1894                    return GETMESSAGE(9, 103, "Move Canceled - None of the objects were moved.\n\n\
1895  The following object could not be automatically renamed\n\
1896 %s\n\n\
1897 %d objects were renamed before the move process was halted.\n\n\
1898 The most probable cause of this problem is that you do not have Write\n\
1899 permission for the above object. Change Write permission or manually\n\
1900 rename the object you are moving so it no longer has the same name.");
1901                    break;
1902               case COPY_FILE:
1903                    return GETMESSAGE(9, 104, "Copy Canceled - None of the objects were copied.\n\n\
1904  The following object could not be automatically renamed\n\
1905 %s\n\n\
1906 %d objects were renamed before the copy process was halted.\n\n\
1907 The most probable cause of this problem is that you do not have Write\n\
1908 permission for the above object. Change Write permission or manually\n\
1909 rename the object you are copying so it no longer has the same name.");
1910                    break;
1911               case LINK_FILE:
1912                    return GETMESSAGE(9, 105, "Link Canceled - None of the objects were linked.\n\n\
1913  The following object could not be automatically renamed\n\
1914 %s\n\n\
1915 %d objects were renamed before the link process was halted.\n\n\
1916 The most probable cause of this problem is that you do not have Write\n\
1917 permission for the above object. Change Write permission or manually\n\
1918 rename the object you are linking so it no longer has the same name.");
1919                    break;
1920               default:
1921                    return GETMESSAGE(9, 106, "Operation Canceled - None of the objects were changed.\n\n\
1922  The following object could not be automatically renamed\n\
1923 %s\n\n\
1924 %d objects were renamed before the process was halted.\n\n\
1925 The most probable cause of this problem is that you do not have Write\n\
1926 permission for the above object. Change Write permission or manually\n\
1927 rename the object you are changing so it no longer has the same name.");
1928                    break;
1929            }  /* end switch (mode) */
1930
1931       case vm_multiCannotRenameOne:
1932            switch (mode)
1933            {
1934               case MOVE_FILE:
1935                    return GETMESSAGE(9, 107, "Move Canceled - None of the objects were moved.\n\n\
1936  The following object could not be automatically renamed\n\
1937 %s\n\n\
1938 1 object was renamed before the move process was halted.\n\n\
1939 The most probable cause of this problem is that you do not have Write\n\
1940 permission for the above object. Change Write permission or manually\n\
1941 rename the object you are moving so it no longer has the same name.");
1942                    break;
1943               case COPY_FILE:
1944                    return GETMESSAGE(9, 108, "Copy Canceled - None of the objects were copied.\n\n\
1945  The following object could not be automatically renamed\n\
1946 %s\n\n\
1947 1 object was renamed before the copy process was halted.\n\n\
1948 The most probable cause of this problem is that you do not have Write\n\
1949 permission for the above object. Change Write permission or manually\n\
1950 rename the object you are copying so it no longer has the same name.");
1951                    break;
1952               case LINK_FILE:
1953                    return GETMESSAGE(9, 109, "Link Canceled - None of the objects were linked.\n\n\
1954  The following object could not be automatically renamed\n\
1955 %s\n\n\
1956 1 object was renamed before the link process was halted.\n\n\
1957 The most probable cause of this problem is that you do not have Write\n\
1958 permission for the above object. Change Write permission or manually\n\
1959 rename the object you are linking so it no longer has the same name.");
1960                    break;
1961               default:
1962                    return GETMESSAGE(9, 110, "Operation Canceled - None of the objects were changed.\n\n\
1963  The following object could not be automatically renamed\n\
1964 %s\n\n\
1965 1 object was renamed before the process was halted.\n\n\
1966 The most probable cause of this problem is that you do not have Write\n\
1967 permission for the above object. Change Write permission or manually\n\
1968 rename the object you are changing so it no longer has the same name.");
1969                    break;
1970            }  /* end switch (mode) */
1971
1972       case vm_multiCannotDeleteFolderMany:
1973            switch (mode)
1974            {
1975               case MOVE_FILE:
1976                    return GETMESSAGE(9, 111, "Move Canceled - none of the objects were moved.\n\n\
1977 A folder that you want to replace could not be deleted.\n\
1978    Folder: %s\n\n\
1979 Some objects inside this folder may have been deleted\n\
1980 before the move process was halted.\n\n\
1981 %d other objects have been deleted.\n\n\
1982 The most probable cause of this problem is that you do not have Write\n\
1983 permission for the above folder. Change Write permission or manually\n\
1984 rename the folder you are moving so it no longer has the same name.");
1985                    break;
1986               case COPY_FILE:
1987                    return GETMESSAGE(9, 112, "Copy Canceled - none of the objects were copied.\n\n\
1988 A folder that you want to replace could not be deleted.\n\
1989    Folder: %s\n\n\
1990 Some objects inside this folder may have been deleted\n\
1991 before the copy process was halted.\n\n\
1992 %d other objects have been deleted.\n\n\
1993 The most probable cause of this problem is that you do not have Write\n\
1994 permission for the above folder. Change Write permission or manually\n\
1995 rename the folder you are copying so it no longer has the same name.");
1996                    break;
1997               case LINK_FILE:
1998                    return GETMESSAGE(9, 113, "Link Canceled - none of the objects were linked.\n\n\
1999 A folder that you want to replace could not be deleted.\n\
2000    Folder: %s\n\n\
2001 Some objects inside this folder may have been deleted\n\
2002 before the link process was halted.\n\n\
2003 %d other objects have been deleted.\n\n\
2004 The most probable cause of this problem is that you do not have Write\n\
2005 permission for the above folder. Change Write permission or manually\n\
2006 rename the folder you are linking so it no longer has the same name.");
2007                    break;
2008               default:
2009                    return GETMESSAGE(9, 114, "Operation Canceled - none of the objects were changed.\n\n\
2010 A folder that you want to replace could not be deleted.\n\
2011    Folder: %s\n\n\
2012 Some objects inside this folder may have been deleted\n\
2013 before the process was halted.\n\n\
2014 %d other objects have been deleted.\n\n\
2015 The most probable cause of this problem is that you do not have Write\n\
2016 permission for the above folder. Change Write permission or manually\n\
2017 rename the folder you are changing so it no longer has the same name.");
2018                    break;
2019            }  /* end switch (mode) */
2020
2021       case vm_multiCannotDeleteFolderOne:
2022            switch (mode)
2023            {
2024               case MOVE_FILE:
2025                    return GETMESSAGE(9, 115, "Move Canceled - none of the objects were moved.\n\n\
2026 A folder that you want to replace could not be deleted.\n\
2027    Folder: %s\n\n\
2028 Some objects inside this folder may have been deleted\n\
2029 before the move process was halted.\n\n\
2030 1 other object has been deleted.\n\n\
2031 The most probable cause of this problem is that you do not have Write\n\
2032 permission for the above folder. Change Write permission or manually\n\
2033 rename the folder you are moving so it no longer has the same name.");
2034                    break;
2035               case COPY_FILE:
2036                    return GETMESSAGE(9, 116, "Copy Canceled - none of the objects were copied.\n\n\
2037 A folder that you want to replace could not be deleted.\n\
2038    Folder: %s\n\n\
2039 Some objects inside this folder may have been deleted\n\
2040 before the copy process was halted.\n\n\
2041 1 other object has been deleted.\n\n\
2042 The most probable cause of this problem is that you do not have Write\n\
2043 permission for the above folder. Change Write permission or manually\n\
2044 rename the folder you are copying so it no longer has the same name.");
2045                    break;
2046               case LINK_FILE:
2047                    return GETMESSAGE(9, 117, "Link Canceled - none of the objects were linked.\n\n\
2048 A folder that you want to replace could not be deleted.\n\
2049    Folder: %s\n\n\
2050 Some objects inside this folder may have been deleted\n\
2051 before the link process was halted.\n\n\
2052 1 other object has been deleted.\n\n\
2053 The most probable cause of this problem is that you do not have Write\n\
2054 permission for the above folder. Change Write permission or manually\n\
2055 rename the folder you are linking so it no longer has the same name.");
2056                    break;
2057               default:
2058                    return GETMESSAGE(9, 118, "Operation Canceled - none of the objects were changed.\n\n\
2059 A folder that you want to replace could not be deleted.\n\
2060    Folder: %s\n\n\
2061 Some objects inside this folder may have been deleted\n\
2062 before the process was halted.\n\n\
2063 1 other object has been deleted.\n\n\
2064 The most probable cause of this problem is that you do not have Write\n\
2065 permission for the above folder. Change Write permission or manually\n\
2066 rename the folder you are changing so it no longer has the same name.");
2067                    break;
2068            }  /* end switch (mode) */
2069
2070       case vm_multiCannotDeleteFileMany:
2071            switch (mode)
2072            {
2073               case MOVE_FILE:
2074                    return GETMESSAGE(9, 119, "Move Canceled - none of the objects were moved.\n\n\
2075 A file that you want to replace could not be deleted.\n\
2076     File: %s\n\n\
2077 %d other objects have been deleted.\n\n\
2078 The most probable cause of this problem is that you do not have Write\n\
2079 permission for the above file. Change Write permission or manually\n\
2080 rename the file you are moving so it no longer has the same name.");
2081                    break;
2082               case COPY_FILE:
2083                    return GETMESSAGE(9, 120, "Copy Canceled - none of the objects were copied.\n\n\
2084 A file that you want to replace could not be deleted.\n\
2085     File: %s\n\n\
2086 %d other objects have been deleted.\n\n\
2087 The most probable cause of this problem is that you do not have Write\n\
2088 permission for the above file. Change Write permission or manually\n\
2089 rename the file you are copying so it no longer has the same name.");
2090                    break;
2091               case LINK_FILE:
2092                    return GETMESSAGE(9, 121, "Link Canceled - none of the objects were linked.\n\n\
2093 A file that you want to replace could not be deleted.\n\
2094     File: %s\n\n\
2095 %d other objects have been deleted.\n\n\
2096 The most probable cause of this problem is that you do not have Write\n\
2097 permission for the above file. Change Write permission or manually\n\
2098 rename the file you are linking so it no longer has the same name.");
2099                    break;
2100               default:
2101                    return GETMESSAGE(9, 122, "Operation Canceled - none of the objects were changed.\n\n\
2102 A file that you want to replace could not be deleted.\n\
2103     File: %s\n\n\
2104 %d other objects have been deleted.\n\n\
2105 The most probable cause of this problem is that you do not have Write\n\
2106 permission for the above file. Change Write permission or manually\n\
2107 rename the file you are changing so it no longer has the same name.");
2108                    break;
2109            }  /* end switch (mode) */
2110
2111       case vm_multiCannotDeleteFileOne:
2112            switch (mode)
2113            {
2114               case MOVE_FILE:
2115                    return GETMESSAGE(9, 123, "Move Canceled - none of the objects were moved.\n\n\
2116 A file that you want to replace could not be deleted.\n\
2117     File: %s\n\n\
2118 1 other object has been deleted.\n\n\
2119 The most probable cause of this problem is that you do not have Write\n\
2120 permission for the above file. Change Write permission or manually\n\
2121 rename the file you are moving so it no longer has the same name.");
2122                    break;
2123               case COPY_FILE:
2124                    return GETMESSAGE(9, 124, "Copy Canceled - none of the objects were copied.\n\n\
2125 A file that you want to replace could not be deleted.\n\
2126     File: %s\n\n\
2127 1 other object has been deleted.\n\n\
2128 The most probable cause of this problem is that you do not have Write\n\
2129 permission for the above file. Change Write permission or manually\n\
2130 rename the file you are copying so it no longer has the same name.");
2131                    break;
2132               case LINK_FILE:
2133                    return GETMESSAGE(9, 125, "Link Canceled - none of the objects were linked.\n\n\
2134 A file that you want to replace could not be deleted.\n\
2135     File: %s\n\n\
2136 1 other object has been deleted.\n\n\
2137 The most probable cause of this problem is that you do not have Write\n\
2138 permission for the above file. Change Write permission or manually\n\
2139 rename the file you are linking so it no longer has the same name.");
2140                    break;
2141               default:
2142                    return GETMESSAGE(9, 126, "Operation Canceled - none of the objects were changed.\n\n\
2143 A file that you want to replace could not be deleted.\n\
2144     File: %s\n\n\
2145 1 other object has been deleted.\n\n\
2146 The most probable cause of this problem is that you do not have Write\n\
2147 permission for the above file. Change Write permission or manually\n\
2148 rename the file you are changing so it no longer has the same name.");
2149                    break;
2150            }  /* end switch (mode) */
2151
2152    }  /* end switch (message) */
2153
2154 }  /* end getVariableMessage */
2155
2156 static Boolean
2157 IsReplaceable(
2158    char *name)
2159 {
2160   struct stat s1;
2161
2162   if(lstat(name,&s1) < 0)
2163     return False;
2164   if (S_ISDIR(s1.st_mode))
2165   {
2166     if(!access(name,02|01))
2167       return True;
2168     return False;
2169   }
2170   else
2171   {
2172     if(!access(name,02))
2173       return True;
2174     return False;
2175   }
2176 }