Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtfile / Main.c
1 /* $TOG: Main.c /main/29 1999/09/17 13:35:04 mgreess $ */
2 /************************************<+>*************************************
3  ****************************************************************************
4  *
5  *   FILE:           Main.c
6  *
7  *   COMPONENT_NAME: Desktop File Manager (dtfile)
8  *
9  *   Description:    This file contains the main program for dtfile.
10  *                   It also contains functions for session management and
11  *                   directory view control.
12  *
13  *   FUNCTIONS: BlackPixelOfScreen
14  *              BuildAndShowIconName
15  *              CheckForOpenDirectory
16  *              CheckOpenDir
17  *              CleanUp
18  *              CloseView
19  *              DirectoryChanged
20  *              DisplayHeight
21  *              DisplayWidth
22  *              DtfileCvtStringToDTIcon
23  *              DtfileCvtStringToDirection
24  *              DtfileCvtStringToGrid
25  *              DtfileCvtStringToObjPlace
26  *              DtfileCvtStringToOpenDir
27  *              DtfileCvtStringToOrder
28  *              DtfileCvtStringToTree
29  *              DtfileCvtStringToTreeFiles
30  *              DtfileCvtStringToView
31  *              DtfileStringToDirection
32  *              DtfileStringToGrid
33  *              DtfileStringToOrder
34  *              DtfileStringToTree
35  *              DtfileStringToTreeFiles
36  *              DtfileStringToView
37  *              ErrorHandler
38  *              ExitApp
39  *              ExitHandler
40  *              ForceMyIconClosed
41  *              ForceMyIconOpen
42  *              GetNewView
43  *              GetPWD
44  *              GetRestrictedDirectory
45  *              HandleTtRequest
46  *              LoadViews
47  *              MarqueeSelect
48  *              MoveDefaultSettings
49  *              ObserveTtNotice
50  *              OpenDirectories
51  *              ReloadDatabases
52  *              RemoveTextFields
53  *              RestoreSession
54  *              RestoreSettingsFile
55  *              RestrictModeUsage
56  *              ReturnDesktopPtr
57  *              RootWindowOfScreen
58  *              SaveDefaultCancelCB
59  *              SaveDefaultOkCB
60  *              SaveSession
61  *              SaveSessionCallback
62  *              SaveSettingsCB
63  *              SetupSendRequestArgs
64  *              Stop
65  *              ToolkitErrorHandler
66  *              Usage
67  *              ViewAccept
68  *              ViewDirectoryHandler
69  *              ViewDirectoryProc
70  *              ViewHomeDirectoryHandler
71  *              ViewSessionHandler
72  *              ViewToolsDirectoryHandler
73  *              WaitForResponseAndExit
74  *              WhitePixelOfScreen
75  *              XtMalloc
76  *              _DtNextToken
77  *              _DtWsmAddMarqueeSelectionCallback
78  *              if
79  *              main
80  *              strcmp
81  *              strlen
82  *
83  *   (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
84  *   (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
85  *   (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
86  *   (c) Copyright 1993, 1994, 1995 Novell, Inc.
87  *
88  ****************************************************************************
89  ************************************<+>*************************************/
90
91 #include <sys/types.h>
92 #include <stdio.h>
93 #include <sys/stat.h>
94 #include <signal.h>
95
96 #ifdef __osf__
97 #include <sys/wait.h>
98 #endif /* __osf__ */
99
100 #include <errno.h>
101 #include <pwd.h>
102 #include <malloc.h>
103 #include <ctype.h>
104
105 #ifndef sun /* don't need the nl_types.h file */
106 #include <nl_types.h>
107 #endif /* !sun */
108
109 #include <locale.h>
110
111 #include <Xm/XmP.h>
112 #include <Xm/DrawingA.h>
113 #include <Xm/DrawingAP.h>
114 #include <Xm/MessageB.h>
115 #include <Xm/RowColumn.h>
116 #include <Xm/MwmUtil.h>
117
118 #include <Dt/Icon.h>
119 #include <Dt/IconP.h>
120 #include <Dt/IconFile.h>
121
122 #include <Dt/HelpDialog.h>
123
124 #ifdef SHAPE
125 #include <X11/extensions/shape.h>
126 #endif
127
128 #include <X11/Shell.h>
129 #include <X11/Xatom.h>
130 #include <Xm/Protocols.h>
131 #include <X11/keysymdef.h>
132 #ifdef HAVE_EDITRES
133 #include <X11/Xmu/Editres.h>
134 #endif
135 #include <Dt/Session.h>
136 #include <Dt/DtP.h>
137 #include <Dt/Connect.h>
138 #include <Dt/FileM.h>
139 #include <Dt/Indicator.h>
140 #include <Dt/Lock.h>
141 #include <Dt/UserMsg.h>
142 #include <Dt/Wsm.h>
143 #include <Dt/WsmP.h>
144 #include <Dt/DtNlUtils.h>
145 #include <Dt/CommandM.h>
146 #include <Dt/EnvControlP.h>
147 #include <Dt/Dts.h>
148
149 #include "Encaps.h"
150 #include "SharedProcs.h"
151
152 #include <Tt/tttk.h>
153
154 #include "Help.h"
155 #include "FileMgr.h"
156 #include "Desktop.h"
157 #include "Main.h"
158 #include "ChangeDir.h"
159 #include "Prefs.h"
160 #include "Common.h"
161 #include "Filter.h"
162 #include "Find.h"
163 #include "ModAttr.h"
164
165 /* When openDir resource is set to NEW
166    File Manager will use this prefix to find for a different icon
167    to display.
168 */
169 #define ICON_OPEN_PREFIX "OPEN_"
170
171 /* THESE ARE ONLY STRINGS WHICH DO NOT NEED TO BE LOCALIZED */
172 /* Don't use '#define' since you end up with multiple copies */
173 char DTFILE_CLASS_NAME[] = "Dtfile";
174 char DTFILE_HELP_NAME[] = "Filemgr";
175 char DESKTOP_DIR[] = ".dt/Desktop";
176
177 static char WS_RES_HEADER[] = ".Workspace.";
178 static char SEC_HELP_RES_HEADER[] = ".secondaryHelpDialogCount: ";
179 static char WS_LOAD_RES_HEADER[] = "Workspace";
180 static char SEC_LOAD_HELP_RES_HEADER[] = "secondaryHelpDialogCount";
181 static char RESTRICTED_HEADER[] = "-restricted";
182 static char VIEW_HEADER[] = "-view";
183
184
185 /*  Structure, resource definitions, for View's optional parameters.  */
186
187 typedef struct
188 {
189    char * no_view;
190    char * session;
191    char * directories;
192    int tree_view;
193    int tree_files;
194    int view;
195    int order;
196    int direction;
197    int grid;
198    int instanceIconWidth;
199    int instanceIconHeight;
200    XmFontList user_font;
201    Dimension tool_width;
202    Dimension tool_height;
203    Dimension dir_width;
204    Dimension dir_height;
205    Boolean prompt_user;
206    char * root_title;
207    char * title;
208    char * help_volume;
209    char * restricted;
210    int dragThreshold;
211    int rereadTime;
212    int checkBrokenLink;
213    int maxDirectoryProcesses;
214    int maxRereadProcesses;
215    int maxRereadProcsPerTick;
216    int trashWait;
217    int desktopIconType;
218    Boolean showFilesystem;
219    Boolean showDropZone;
220    Boolean showEmptySet;
221    Boolean showEmptyMsg;
222    int openDirType;
223    Boolean restrictMode;
224    int desktopPlacement;
225    Boolean freezeOnConfig;
226 #if defined(__hpux) || defined(sun)
227    Boolean follow_links;
228 #endif
229    char * fileMgrIcon;
230    char * appMgrIcon;
231    char * trashIcon;
232    int retryLoadDesktop;
233    int smallIconWidth;
234    int smallIconHeight;
235    int largeIconWidth;
236    int largeIconHeight;
237    Boolean emptyTrashOnExit;
238 } ApplicationArgs, *ApplicationArgsPtr;
239
240 static ApplicationArgs application_args;
241
242 /********    Static Function Declarations    ********/
243
244 static void ErrorHandler(
245                         Display *disp,
246                         XErrorEvent *event) ;
247 static void ToolkitErrorHandler(
248                         char *message) ;
249 static void Usage(
250                         char **argv) ;
251 static void RestrictModeUsage(
252                         char **argv) ;
253 static void Stop( void ) ;
254 static void RestoreSettingsFile( void ) ;
255 static void MoveDefaultSettings(
256                         int mode) ;
257 static void SaveDefaultCancelCB(
258                         Widget w,
259                         XtPointer client_data,
260                         XtPointer call_data) ;
261 static void SaveDefaultOkCB(
262                         Widget w,
263                         XtPointer client_data,
264                         XtPointer call_data) ;
265 static void SaveSession(
266                         char *path) ;
267 static int RestoreSession(
268                         char *path,
269                         int type_of_restore,
270                         char *directory) ;
271 static void GetPWD(
272                         char current_directory[]) ;
273 static void OpenDirectories(
274                         char *directory_set,
275                         char *type) ;
276 static Tt_callback_action ObserveTtNotice(
277                         Tt_message msg,
278                         Tt_pattern pat) ;
279 static void ViewSessionHandler(
280                         Tt_message msg);
281 static void ViewDirectoryHandler(
282                         Tt_message msg);
283 static void ViewHomeDirectoryHandler(
284                         Tt_message msg);
285 static void ViewToolsDirectoryHandler(
286                         Tt_message msg);
287 static void ExitHandler(
288                         Tt_message msg,
289                         XtPointer clientData,
290                         String * messageFields,
291                         int numFields);
292 static void ReloadDatabases( void );
293 static void ViewAccept(
294                         View *view,
295                         Tt_message msg);
296 static void LoadViews (
297                         int num_views,
298                         XrmDatabase db,
299                         char *host_name,
300                         char *directory_name,
301                         char *type,
302                         Tt_message msg);
303 static void RemoveTextFields (
304                         XtPointer client_data,
305                         DialogData * old_dialog_data,
306                         DialogData * new_dialog_data) ;
307 static void DtfileCvtStringToObjPlace (
308                         XrmValue *args,
309                         Cardinal numArgs,
310                         XrmValue *fromVal,
311                         XrmValue *toVal) ;
312 static unsigned char *_DtNextToken (
313                         unsigned char *pchIn,
314                         int *pLen,
315                         unsigned char **ppchNext) ;
316 static void DtfileCvtStringToOpenDir (
317                         XrmValue *args,
318                         Cardinal numArgs,
319                         XrmValue *fromVal,
320                         XrmValue *toVal) ;
321 static void DtfileCvtStringToDTIcon (
322                         XrmValue *args,
323                         Cardinal numArgs,
324                         XrmValue *fromVal,
325                         XrmValue *toVal) ;
326 static void DtfileCvtStringToTree (
327                         XrmValue *args,
328                         Cardinal numArgs,
329                         XrmValue *fromVal,
330                         XrmValue *toVal) ;
331 static void DtfileCvtStringToTreeFiles (
332                         XrmValue *args,
333                         Cardinal numArgs,
334                         XrmValue *fromVal,
335                         XrmValue *toVal) ;
336 static void DtfileCvtStringToView (
337                         XrmValue *args,
338                         Cardinal numArgs,
339                         XrmValue *fromVal,
340                         XrmValue *toVal) ;
341 static void DtfileCvtStringToOrder (
342                         XrmValue *args,
343                         Cardinal numArgs,
344                         XrmValue *fromVal,
345                         XrmValue *toVal) ;
346 static void DtfileCvtStringToDirection (
347                         XrmValue *args,
348                         Cardinal numArgs,
349                         XrmValue *fromVal,
350                         XrmValue *toVal) ;
351 static void DtfileCvtStringToGrid (
352                         XrmValue *args,
353                         Cardinal numArgs,
354                         XrmValue *fromVal,
355                         XrmValue *toVal) ;
356 static void DtfileStringToTree(
357                         char *str,
358                         int *type) ;
359 static void DtfileStringToTreeFiles(
360                         char *str,
361                         int *type) ;
362 static void DtfileStringToView(
363                         char *str,
364                         int *type) ;
365 static void DtfileStringToOrder(
366                         char *str,
367                         int *type) ;
368 static void DtfileStringToDirection(
369                         char *str,
370                         int *type) ;
371 static void DtfileStringToGrid(
372                         char *str,
373                         int *type) ;
374 static void SetupSendRequestArgs(
375                         ApplicationArgs application_args,
376                         Tt_message msg) ;
377 static void BuildAndShowIconName(
378                         char *file_type_name,
379                         unsigned char view,
380                         unsigned char show_type,
381                         Widget widget) ;
382 static void MarqueeSelect (
383                         Widget w,
384                         int type,
385                         Position x,
386                         Position y,
387                         Dimension width,
388                         Dimension height,
389                         XtPointer client_data);
390 static void WaitForResponseAndExit( void ) ;
391 static void ExitApp(
392                         XtPointer clientData,
393                         String *words,
394                         int num_fields) ;
395 static Widget post_dialog(
396                         Widget parent,
397                         char *title,
398                         char *msg,
399                         void (*callback)());
400 static void DtErrExitCB(
401                         Widget widget,
402                         XtPointer client_data,
403                         XtPointer call_data);
404
405 /********    End Static Function Declarations    ********/
406
407 /*  debugging flag  */
408 #ifdef DEBUG
409 int debug = 0;
410 #endif
411
412 /*  performance flag  */
413 #ifdef DT_PERFORMANCE
414 int perform = 0;
415 #endif
416
417 /*  The id's of the dialogs registered by main  */
418
419 int file_mgr_dialog;
420 int change_dir_dialog;
421 int preferences_dialog;
422 int filter_dialog;
423 int find_dialog;
424 int mod_attr_dialog;
425 int help_dialog;
426
427 /* The shared menu button and pane Id's */
428
429 Widget * create_dataBtn;
430 Widget * renameBtn;
431 Widget * moveBtn;
432 Widget * duplicateBtn;
433 Widget * linkBtn;
434 Widget * findBtn;
435 Widget * create_directoryBtn;
436 Widget * change_directoryBtn;
437 Widget * showHiddenMenu;
438 Widget * preferencesBtn;
439 Widget * filterBtn;
440 Widget * defaultEnvBtn;
441 Widget * homeBarBtn;
442 Widget * upBarBtn;
443 Widget * newViewBtn;
444 Widget * cleanUpBtn;
445 Widget * separator1;
446 Widget * separator2;
447 Widget * terminalBtn;
448 Widget * usingHelp = NULL;
449 Widget * fileManagerHelp = NULL;
450 Widget * applicationManagerHelp = NULL;
451 Widget * usingHelpTrash = NULL;
452
453
454 /* Bitmask used to indicate the current sensitivity state of shared menu btns */
455
456 unsigned int currentMenuStates = ( RENAME | MOVE | DUPLICATE | LINK | TRASH |
457                                  MODIFY | CHANGEDIR | PREFERENCES | FILTER |
458                                  FIND | CREATE_DIR | CREATE_FILE |
459                                  PUT_ON_DESKTOP | PUTBACK |
460                                  CLEAN_UP | MOVE_UP |
461                                  HOME | CHANGE_DIR | TERMINAL);
462
463 /* Drag manager globals */
464 Boolean b1Drag;
465 Boolean dragActive = False;
466
467 /* Desktop Globals */
468 int numColumns;
469 int numRows;
470
471 /*  Globally referenced application name.  Set to argv[0] in main  */
472
473 char * application_name = NULL;
474
475
476 /*  uid for root user; used when we are checking access permissions  */
477
478 long root_user = -1;
479
480
481 /*  Home host name  */
482
483 char home_host_name[MAX_PATH];
484 char users_home_dir[MAX_PATH];
485
486
487 /*  Toolbox directory  */
488
489 char * desktop_dir = NULL;
490 char * trash_dir = NULL;
491 char * remote_sys_dir = NULL;
492
493 /* Restor type */
494
495 int restoreType = NORMAL_RESTORE;
496
497
498 /*  Black and White pixels  */
499
500 Pixel black_pixel;
501 Pixel white_pixel;
502
503
504 /*  File manager view set before a new view is created and   */
505 /*  used to propagate visual attributes from the initiating  */
506 /*  view to the new view.                                    */
507
508 XtPointer initiating_view = NULL;
509 Boolean special_view = False;
510 Boolean TrashView = False;
511
512
513 /*  system wide user font  */
514
515 XmFontList user_font;
516
517
518 /* Global localizable strings */
519
520 String openInPlace;
521 String openNewView;
522
523
524 /* Global dialog button labels, as XmStrings */
525
526 XmString okXmString;
527 XmString cancelXmString;
528 XmString helpXmString;
529 XmString applyXmString;
530 XmString closeXmString;
531
532
533 /* Global top level widget  */
534
535 Widget toplevel;
536
537 /* Global Application resources */
538 Boolean showFilesystem;
539 Boolean showDropZone;
540 Boolean showEmptySet;
541 Boolean showEmptyMsg;
542 Boolean restrictMode;
543 int openDirType;
544 char *root_title;
545 char *fileMgrTitle;
546 char *fileMgrHelpVol;
547 int desktopIconType;
548 int rereadTime;
549 int checkBrokenLink;
550 int trashWait;
551 int desktopPlacement;
552 Boolean freezeOnConfig;
553 #if defined(__hpux) || defined(sun)
554 Boolean follow_links;
555 #endif
556 int treeType;
557 int treeFiles;
558 int viewType;
559 int orderType;
560 int directionType;
561 int randomType;
562 int instanceWidth;
563 int instanceHeight;
564 unsigned char keybdFocusPolicy;
565 int special_treeType;
566 int special_treeFiles;
567 int special_viewType;
568 int special_orderType;
569 int special_directionType;
570 int special_randomType;
571 char *special_restricted;
572 char *special_title;
573 char *special_helpVol;
574 char *fileMgrIcon;
575 char *appMgrIcon;
576 char *trashIcon;
577 int retryLoadDesktopInfo;
578
579 int smallIconWidth;
580 int smallIconHeight;
581 int largeIconWidth;
582 int largeIconHeight;
583
584 Boolean emptyTrashOnExit;
585
586 #ifdef SHAPE
587 Boolean shapeExtension;
588 #endif
589
590 /* Drag state variables */
591 Boolean B1DragPossible = False;
592 Boolean B2DragPossible = False;
593 Boolean ProcessBtnUp = False;
594 Boolean ProcessBtnUpCD = True;
595 int initialDragX;
596 int initialDragY;
597 int dragThreshold;
598 int xErrorDetected = False;
599
600 /* BMenu button binding */
601 int bMenuButton;
602
603 View ** view_set = NULL;
604 int view_count = 0;
605 int view_set_size = 0;
606
607 /*  Globals used within this file.  */
608
609 static Display * display;
610 char * dt_path = NULL;
611 static Boolean message_display_enabled = True;
612
613
614 static Atom save_yourself_atom;
615 static Atom command_atom;
616 static Atom wm_state_atom;
617 static Atom save_mode;
618
619 /*  Structure used on a save session to see if a dt is iconic  */
620
621 typedef struct
622 {
623    int state;
624    Window icon;
625 } WM_STATE;
626
627
628 /*  Application resource list definition  */
629
630 static XrmOptionDescRec option_list[] =
631 {
632    {  "-noview",            "noView",          XrmoptionIsArg,   NULL  },
633    {  "-session",           "session",         XrmoptionSepArg,  NULL  },
634    {  "-dir",               "folder",          XrmoptionSepArg,  NULL  },
635    {  "-folder",            "folder",          XrmoptionSepArg,  NULL  },
636    {  "-tree",              "treeView",        XrmoptionSepArg,  NULL  },
637    {  "-tree_files",        "treeFiles",       XrmoptionSepArg,  NULL  },
638    {  VIEW_HEADER,          "view",            XrmoptionSepArg,  NULL  },
639    {  "-order",             "order",           XrmoptionSepArg,  NULL  },
640    {  "-direction",         "direction",       XrmoptionSepArg,  NULL  },
641    {  "-grid",              "grid",            XrmoptionSepArg,  NULL  },
642    {  RESTRICTED_HEADER,    "restricted",      XrmoptionIsArg,   NULL  },
643    {  "-title",             "title",           XrmoptionSepArg,  NULL  },
644    {  "-help_volume",       "help_volume",     XrmoptionSepArg,  NULL  },
645    {  "-noprompt",          "promptUser",      XrmoptionNoArg,  "False"  },
646    {  "-small_icon_width",  "smallIconWidth",  XrmoptionSepArg,  NULL  },
647    {  "-small_icon_height", "smallIconHeight", XrmoptionSepArg,  NULL  },
648    {  "-large_icon_width",  "largeIconWidth",  XrmoptionSepArg,  NULL  },
649    {  "-large_icon_height", "largeIconHeight", XrmoptionSepArg,  NULL  },
650 };
651
652
653 static XtResource resources[] =
654 {
655    {
656      "noView", "NoView", XmRString, sizeof (char *),
657      XtOffset (ApplicationArgsPtr, no_view), XmRImmediate, (XtPointer) NULL,
658    },
659
660    {
661      "session", "Session", XmRString, sizeof (char *),
662      XtOffset (ApplicationArgsPtr, session), XmRImmediate, (XtPointer) NULL,
663    },
664
665    {
666      "folder", "Folder", XmRString, sizeof (char *),
667      XtOffset (ApplicationArgsPtr, directories), XmRImmediate, (XtPointer) NULL,
668    },
669
670    {
671      "treeView", "TreeView", "Tree", sizeof (int),
672      XtOffset (ApplicationArgsPtr, tree_view), XmRImmediate,
673      (XtPointer) UNSET_VALUE,
674    },
675
676    {
677      "treeFiles", "TreeFiles", "TreeFiles", sizeof (int),
678      XtOffset (ApplicationArgsPtr, tree_files), XmRImmediate,
679      (XtPointer) UNSET_VALUE,
680    },
681
682    {
683      "view", "View", "View", sizeof (int),
684      XtOffset (ApplicationArgsPtr, view), XmRImmediate, (XtPointer) UNSET_VALUE,
685    },
686
687    {
688      "order", "Order", "Order", sizeof (int),
689      XtOffset (ApplicationArgsPtr, order), XmRImmediate, (XtPointer) UNSET_VALUE,
690    },
691
692    {
693      "direction", "Direction", "Direction", sizeof (int),
694      XtOffset (ApplicationArgsPtr, direction), XmRImmediate,
695      (XtPointer) UNSET_VALUE,
696    },
697
698    {
699      "grid", "Grid", "Grid", sizeof (int),
700      XtOffset (ApplicationArgsPtr, grid), XmRImmediate, (XtPointer) UNSET_VALUE,
701    },
702
703    {
704      "instanceIconWidth", "InstanceIconWidth", XmRInt, sizeof (int),
705      XtOffset (ApplicationArgsPtr, instanceIconWidth), XmRImmediate,
706      (XtPointer) 256,
707    },
708
709    {
710      "instanceIconHeight", "InstanceIconHeight", XmRInt, sizeof (int),
711      XtOffset (ApplicationArgsPtr, instanceIconHeight), XmRImmediate,
712      (XtPointer) 256,
713    },
714
715    {
716      "restricted", "Restricted", XmRString, sizeof (char *),
717      XtOffset (ApplicationArgsPtr, restricted), XmRImmediate, (XtPointer) NULL,
718    },
719
720    {
721      "title", "Title", XmRString, sizeof (char *),
722      XtOffset (ApplicationArgsPtr, title), XmRImmediate, (XtPointer)NULL,
723    },
724
725    {
726      "help_volume", "Help_volume", XmRString, sizeof (char *),
727      XtOffset (ApplicationArgsPtr, help_volume), XmRImmediate, (XtPointer)NULL,
728    },
729
730    {
731      "userFont", "XmCFontList", XmRFontList, sizeof (XmFontList),
732      XtOffset (ApplicationArgsPtr, user_font), XmRString, (XtPointer) "Fixed",
733    },
734
735    {
736      "toolWidth", "ToolWidth", XmRHorizontalDimension, sizeof (Dimension),
737      XtOffset (ApplicationArgsPtr, tool_width), XmRImmediate, (XtPointer) 700,
738    },
739
740    {
741      "toolHeight", "ToolHeight", XmRVerticalDimension, sizeof (Dimension),
742      XtOffset (ApplicationArgsPtr, tool_height), XmRImmediate, (XtPointer) 250,
743    },
744
745    {
746      "dirWidth", "DirWidth", XmRHorizontalDimension, sizeof (Dimension),
747      XtOffset (ApplicationArgsPtr, dir_width), XmRImmediate, (XtPointer) 555,
748    },
749
750    {
751      "dirHeight", "DirHeight", XmRVerticalDimension, sizeof (Dimension),
752      XtOffset (ApplicationArgsPtr, dir_height), XmRImmediate, (XtPointer) 400,
753    },
754
755    {
756      "promptUser", "PromptUser", XmRBoolean, sizeof (Boolean),
757      XtOffset (ApplicationArgsPtr, prompt_user), XmRImmediate, (XtPointer) True,
758    },
759
760    {
761      "rootTitle", "RootTitle", XmRString, sizeof (char *),
762      XtOffset (ApplicationArgsPtr, root_title), XmRImmediate, (XtPointer)"ROOT",
763    },
764
765    {
766      "moveThreshold", "MoveThreshold", XmRInt, sizeof (int),
767      XtOffset (ApplicationArgsPtr, dragThreshold), XmRImmediate, (XtPointer) 4,
768    },
769
770    {
771      "rereadTime", "RereadTime", XmRInt, sizeof (int),
772      XtOffset (ApplicationArgsPtr, rereadTime), XmRImmediate, (XtPointer) 3,
773    },
774
775    {
776      "checkBrokenLink", "CheckBrokenLink", XmRInt, sizeof (int),
777      XtOffset (ApplicationArgsPtr, checkBrokenLink), XmRImmediate,
778      (XtPointer) 180,
779    },
780
781    {
782      "maxDirectoryProcesses", "MaxDirectoryProcesses", XmRInt, sizeof (int),
783      XtOffset (ApplicationArgsPtr, maxDirectoryProcesses), XmRImmediate,
784      (XtPointer) 10,
785    },
786
787    {
788      "maxRereadProcesses", "MaxRereadProcesses", XmRInt, sizeof (int),
789      XtOffset (ApplicationArgsPtr, maxRereadProcesses), XmRImmediate,
790      (XtPointer) 5,
791    },
792
793    {
794      "maxRereadProcsPerTick", "MaxRereadProcsPerTick", XmRInt, sizeof (int),
795      XtOffset (ApplicationArgsPtr, maxRereadProcsPerTick), XmRImmediate,
796      (XtPointer) 1,
797    },
798
799    {
800      "trashWait", "TrashWait", XmRInt, sizeof (int),
801      XtOffset (ApplicationArgsPtr, trashWait), XmRImmediate, (XtPointer) 1,
802    },
803
804    {
805      "desktopIcon", "DesktopIcon", "DesktopIcon", sizeof (int),
806      XtOffset (ApplicationArgsPtr, desktopIconType), XmRImmediate,
807      (XtPointer)LARGE,
808    },
809
810    {
811      "showFilesystem", "ShowFilesystem", XmRBoolean, sizeof (Boolean),
812      XtOffset (ApplicationArgsPtr, showFilesystem), XmRImmediate,
813      (XtPointer)True,
814    },
815
816    {
817      "showDropZone", "ShowDropZone", XmRBoolean, sizeof (Boolean),
818      XtOffset (ApplicationArgsPtr, showDropZone), XmRImmediate,
819      (XtPointer)False,
820    },
821
822    {
823      "showEmptySet", "ShowEmptySet", XmRBoolean, sizeof (Boolean),
824      XtOffset (ApplicationArgsPtr, showEmptySet), XmRImmediate,
825      (XtPointer)False,
826    },
827
828    {
829      "showEmptyMsg", "ShowEmptyMsg", XmRBoolean, sizeof (Boolean),
830      XtOffset (ApplicationArgsPtr, showEmptyMsg), XmRImmediate,
831      (XtPointer)False,
832    },
833
834    {
835      "openFolder", "OpenFolder", "OpenFolder", sizeof (int),
836      XtOffset (ApplicationArgsPtr, openDirType), XmRImmediate,
837      (XtPointer)CURRENT,
838    },
839
840    {
841      "restrictMode", "RestrictMode", XmRBoolean, sizeof (Boolean),
842      XtOffset (ApplicationArgsPtr, restrictMode), XmRImmediate,
843      (XtPointer)False,
844    },
845
846    {
847      "objectPlacement", "ObjectPlacement", "ObjectPlacement", sizeof (int),
848      XtOffset (ApplicationArgsPtr, desktopPlacement), XmRImmediate,
849      (XtPointer)(OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_RIGHT_SECONDARY),
850    },
851
852    {
853      "freezeOnConfig", "FreezeOnConfig", XmRBoolean, sizeof (Boolean),
854      XtOffset (ApplicationArgsPtr, freezeOnConfig), XmRImmediate,
855      (XtPointer)True,
856    },
857
858    {
859      "fileManagerIcon", "FileManagerIcon", XmRString, sizeof (char *),
860      XtOffset (ApplicationArgsPtr, fileMgrIcon), XmRImmediate,
861      (XtPointer) HOME_ICON_NAME,
862    },
863
864    {
865      "appManagerIcon", "AppManagerIcon", XmRString, sizeof (char *),
866      XtOffset (ApplicationArgsPtr, appMgrIcon), XmRImmediate,
867      (XtPointer) TOOL_ICON_NAME,
868    },
869
870    {
871      "trashIcon", "TrashIcon", XmRString, sizeof (char *),
872      XtOffset (ApplicationArgsPtr, trashIcon), XmRImmediate,
873      (XtPointer) TRASH_ICON_NAME,
874    },
875
876    {
877      "retryLoadDesktop", "RetryLoadDesktop", XmRInt, sizeof (int),
878      XtOffset (ApplicationArgsPtr, retryLoadDesktop), XmRImmediate,
879      (XtPointer) 10,
880    },
881
882    {
883      "smallIconWidth", "SmallIconWidth", XmRInt, sizeof (int),
884      XtOffset (ApplicationArgsPtr, smallIconWidth), XmRImmediate,
885      (XtPointer) 24,
886    },
887
888    {
889      "smallIconHeight", "SmallIconHeight", XmRInt, sizeof (int),
890      XtOffset (ApplicationArgsPtr, smallIconHeight), XmRImmediate,
891      (XtPointer) 24,
892    },
893
894    {
895      "largeIconWidth", "LargeIconWidth", XmRInt, sizeof (int),
896      XtOffset (ApplicationArgsPtr, largeIconWidth), XmRImmediate,
897      (XtPointer) 38,
898    },
899
900    {
901      "largeIconHeight", "LargeIconHeight", XmRInt, sizeof (int),
902      XtOffset (ApplicationArgsPtr, largeIconHeight), XmRImmediate,
903      (XtPointer) 38,
904    },
905
906    {
907      "emptyTrashOnExit", "EmptyTrashOnExit", XmRBoolean, sizeof (Boolean),
908      XtOffset (ApplicationArgsPtr, emptyTrashOnExit), XmRImmediate,
909      (XtPointer)False,
910    },
911
912 #if defined(__hpux) || defined(sun)
913    { "followLinks", "FollowLinks", XmRBoolean, sizeof(Boolean),
914      XtOffset(ApplicationArgsPtr, follow_links), XmRImmediate,
915      (XtPointer) False,
916    },
917 #endif
918
919 };
920
921 XtActionsRec actionTable[] = {
922    {"Space", (XtActionProc)VFTextChangeSpace},
923    {"EscapeFM", (XtActionProc)CancelOut},
924 };
925
926 /************************************************************************
927  *
928  *  DT File
929  *      The main program for the file manager.
930  *
931  ************************************************************************/
932
933 extern XtInputId ProcessToolTalkInputId;
934
935 #ifdef __osf__
936 extern void sigchld_handler(int);
937 #endif /* __osf__ */
938
939 void
940 main(
941         unsigned int argc,
942         char **argv )
943 {
944 #ifdef DT_PERFORMANCE
945    struct timeval update_time_s;
946    struct timeval update_time_f;
947    struct timeval update_time_ss;
948    struct timeval update_time_fs;
949 #endif
950    struct passwd * pw;
951    char current_directory[MAX_PATH];
952    struct passwd * pwInfo;
953    char * homeDir;
954    XEvent event;
955    XtInputMask pending;
956    Boolean eventDebugging;
957    int offset;
958    KeySym keysym;
959    int displayHeight;
960    int displayWidth;
961    Arg args[10];
962    int n;
963    char * tmpStr;
964    XSetWindowAttributes sAttributes;
965    Window root;
966 #ifdef SHAPE
967    int base1, base2;
968 #endif
969    XrmValue resource_value;
970    XrmDatabase db;
971    char *rep_type;
972    char *string, *str;
973    int i;
974    int ttFd;    /* ToolTalk file descriptor */
975    char *sessId;
976    Tt_pattern events2Watch;
977    Tt_pattern requests2Handle;
978    Tt_message msg;
979    Tt_status status;
980 #ifdef __osf__
981    struct sigaction sa, osa;
982 #endif /* __osf__ */
983    int session_flag = 0;
984
985 #ifdef DT_PERFORMANCE
986    printf("  Start\n");
987    gettimeofday(&update_time_ss, NULL);
988 #endif
989    (void) signal (SIGINT, (void (*)())Stop);
990
991    /* We don't want any zombie children, do we? */
992 #ifdef __osf__
993     sa.sa_handler = sigchld_handler;
994     sigemptyset(&sa.sa_mask);
995     sa.sa_flags   =  0;
996
997     if (sigaction(SIGCHLD, &sa, &osa) < 0)
998     /* error handling follows, none for now */
999         ;
1000 #else
1001    (void) signal (SIGCLD, SIG_IGN);
1002 #endif /* __osf__ */
1003    XtSetLanguageProc( NULL, NULL, NULL );
1004
1005 #ifdef DT_PERFORMANCE
1006 { /* Initialize the checkpoint protocol  - Aloke Gupta */
1007 Display *display;
1008 display = XOpenDisplay("");
1009 _DtPerfChkpntInit(display, RootWindow(display, DefaultScreen(display)),
1010                     argv[0], True);
1011 }
1012 #endif
1013
1014
1015    _DtEnvControl(DT_ENV_SET);
1016
1017 #ifdef DT_PERFORMANCE
1018    printf("  XtInitalize\n");
1019    gettimeofday(&update_time_s, NULL);
1020
1021    /* Added by Aloke Gupta */
1022 _DtPerfChkpntMsgSend("Begin XtInitialize");
1023 #endif
1024
1025    /*  Initialize the toolkit and open the display  */
1026    toplevel = XtInitialize (argv[0], DTFILE_CLASS_NAME,
1027                             option_list, XtNumber(option_list),
1028                             (int *)&argc, argv);
1029
1030 /* MERGE START: May not need
1031 #ifdef __osf__
1032    _XmColorObjCreate ( toplevel, NULL, NULL );
1033 #endif
1034 */
1035
1036 #ifdef DT_PERFORMANCE
1037    gettimeofday(&update_time_f, NULL);
1038    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1039       update_time_f.tv_usec += 1000000;
1040       update_time_f.tv_sec--;
1041    }
1042    printf("    done XtInitialize, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1043
1044    /* Added by Aloke Gupta */
1045    _DtPerfChkpntMsgSend("Done  XtInitialize");
1046 #endif
1047
1048    /* Initialize the function ptr for alphabetic sorting */
1049    FMStrcoll = GetStrcollProc();
1050
1051    /* Open the message catalog - DO NOT PERFORM until after XtInitialize! */
1052    {
1053       char * foo = ((char *)GETMESSAGE(18, 1, ""));
1054    }
1055
1056    /* set application name for later */
1057    str = strrchr(argv[0], '/');
1058    if(str != NULL)
1059       application_name = XtNewString (str + 1);
1060    else
1061       application_name = XtNewString (argv[0]);
1062
1063    n = 0;
1064    XtSetArg(args[n], XmNallowShellResize, True); n++;
1065    XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
1066    XtSetArg(args[n], XmNheight, 1); n++;
1067    XtSetArg(args[n], XmNwidth, 1); n++;
1068    XtSetValues(toplevel, args, n);
1069    XtRealizeWidget(toplevel);
1070    display = XtDisplay (toplevel);
1071 #ifdef HAVE_EDITRES
1072     XtAddEventHandler(toplevel, 0, True,
1073                       (XtEventHandler) _XEditResCheckMessages,
1074                       (XtPointer) NULL);
1075 #endif
1076
1077    /* Initialize BMenu button binding */
1078    {
1079         int numMouseButtons = XGetPointerMapping(display,
1080                                         (unsigned char *)NULL, 0);
1081         bMenuButton = (numMouseButtons < 3) ? Button2 : Button3;
1082    }
1083
1084    /* initialize debugging flag */
1085 #ifdef DEBUG
1086    if ((tmpStr = getenv("DTFILE_DEBUG")) != NULL)
1087    {
1088       debug = atoi(tmpStr);
1089       if (debug <= 0)
1090          debug = 1;
1091    }
1092    if (getenv("DTFILE_XSYNC") != NULL)
1093    {
1094       XSynchronize(display, True);
1095    }
1096 #endif
1097
1098    /* initialize performance flag */
1099 #ifdef DT_PERFORMANCE
1100    if ((tmpStr = getenv("DTFILE_PERFORM")) != NULL)
1101    {
1102       perform = atoi(tmpStr);
1103       if (perform <= 0)
1104          perform = 1;
1105    }
1106    if (getenv("DTFILE_XSYNC") != NULL)
1107    {
1108       XSynchronize(display, True);
1109    }
1110 #endif
1111
1112    /*  Create the atom set used by save and restore session  */
1113    save_yourself_atom = XmInternAtom (display, "WM_SAVE_YOURSELF", False);
1114    wm_state_atom = XmInternAtom (display, "WM_STATE", False);
1115    command_atom = XA_WM_COMMAND;
1116    save_mode = XmInternAtom (display, _XA_DT_RESTORE_MODE, False);
1117
1118    root = RootWindowOfScreen(XtScreen(toplevel));
1119
1120    /* Set session property on the top level window */
1121    XmAddWMProtocols(toplevel, &save_yourself_atom, 1);
1122    XmAddWMProtocolCallback(toplevel, save_yourself_atom, SaveSessionCallback,
1123                            NULL);
1124
1125    XSetErrorHandler ((int (*)())ErrorHandler);
1126    XtAppSetErrorHandler (XtWidgetToApplicationContext(toplevel),
1127                          ToolkitErrorHandler);
1128
1129    /* get the keyboard focus policy so we know how we want to set up the */
1130    /*  Icon gadgets */
1131    XtSetArg(args[0], XmNkeyboardFocusPolicy, &keybdFocusPolicy);
1132    XtGetValues(toplevel, args, 1);
1133
1134    /*  If all of the command line parameters were not processed  */
1135    /*  out, print out a usage message set and exit.              */
1136
1137    if (argc != 1) Usage (argv);
1138
1139    displayWidth = DisplayWidth(display, DefaultScreen(display));
1140    displayHeight = DisplayHeight(display, DefaultScreen(display));
1141
1142    /*  Get Dt initialized  */
1143
1144    if (DtInitialize (display, toplevel, argv[0], FILE_MANAGER_TOOL_CLASS) == False)
1145    {
1146       /* Fatal Error: could not connect to the messaging system. */
1147       /* DtInitialize() has already logged an appropriate error msg */
1148       exit(-1);
1149    }
1150
1151 #ifdef DT_PERFORMANCE
1152    printf("  Setup Converters and get resources\n");
1153    gettimeofday(&update_time_s, NULL);
1154
1155    /* Added by Aloke Gupta */
1156    _DtPerfChkpntMsgSend("Begin Setup Converters");
1157
1158 #endif
1159
1160    /* First lets add the resource converters needed */
1161    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1162                        XtRString, "ObjectPlacement",
1163                        (XtConverter)DtfileCvtStringToObjPlace, NULL, 0);
1164    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1165                        XtRString, "OpenFolder",
1166                        (XtConverter)DtfileCvtStringToOpenDir, NULL, 0);
1167    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1168                        XtRString, "DesktopIcon",
1169                        (XtConverter)DtfileCvtStringToDTIcon, NULL, 0);
1170    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1171                        XtRString, "Tree",
1172                        (XtConverter)DtfileCvtStringToTree, NULL, 0);
1173    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1174                        XtRString, "TreeFiles",
1175                        (XtConverter)DtfileCvtStringToTreeFiles, NULL, 0);
1176    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1177                        XtRString, "View",
1178                        (XtConverter)DtfileCvtStringToView, NULL, 0);
1179    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1180                        XtRString, "Order",
1181                        (XtConverter)DtfileCvtStringToOrder, NULL, 0);
1182    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1183                        XtRString, "Direction",
1184                        (XtConverter)DtfileCvtStringToDirection, NULL, 0);
1185    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1186                        XtRString, "Grid",
1187                        (XtConverter)DtfileCvtStringToGrid, NULL, 0);
1188
1189    /*  Get the application defined resources of session and  */
1190    /*  directory, and get the processes host.                */
1191
1192    XtGetApplicationResources(toplevel, &application_args,
1193                              resources, XtNumber(resources), NULL,0);
1194
1195 #ifdef DT_PERFORMANCE
1196    gettimeofday(&update_time_f, NULL);
1197    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1198       update_time_f.tv_usec += 1000000;
1199       update_time_f.tv_sec--;
1200    }
1201    printf("    done Setting up Converters and got resources, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1202
1203    /* Added by Aloke Gupta */
1204    _DtPerfChkpntMsgSend("Done  Setup Converters");
1205 #endif
1206
1207 #ifdef DT_PERFORMANCE
1208    printf("  DtDbLoad\n");
1209    gettimeofday(&update_time_s, NULL);
1210    /* Added by Aloke Gupta */
1211    _DtPerfChkpntMsgSend("Begin DtDbLoad");
1212
1213 #endif
1214
1215    /*  Set up the messaging and file types  */
1216
1217    DtDbLoad();
1218 #ifdef DT_PERFORMANCE
1219    gettimeofday(&update_time_f, NULL);
1220    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1221       update_time_f.tv_usec += 1000000;
1222       update_time_f.tv_sec--;
1223    }
1224    printf("    done DtDbLoad, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1225
1226    /* Added by Aloke Gupta */
1227    _DtPerfChkpntMsgSend("Done  DtDbLoad");
1228
1229 #endif
1230
1231
1232    /* Create some global strings */
1233    db = XtDatabase(display);
1234    if (XrmGetResource (db, "dttypes.defaultActions",
1235                        "Dttypes.DefaultActions", &rep_type,
1236                        &resource_value))
1237    {
1238      string = XtNewString(resource_value.addr);
1239      for(str = DtStrtok(string, ",") ,i = 0; str != NULL && i < 2 ;
1240      str = DtStrtok(NULL, ","), i++) {
1241        if(i == 0)
1242          openInPlace = XtNewString(str);
1243        else
1244          openNewView = XtNewString(str);
1245      }
1246      XtFree(string);
1247    }
1248    if(openInPlace == NULL || strlen(openInPlace) == 0)
1249        openInPlace = XtNewString("OpenInPlace");
1250    if(openNewView == NULL || strlen(openNewView) == 0)
1251        openNewView = XtNewString("OpenNewView");
1252
1253    DtGetShortHostname (home_host_name, MAX_PATH);
1254
1255    /*  Get the lock established to ensure only one dtfile process  */
1256    /*  is running.                                                  */
1257    if (_DtGetLock (display, DTFILE_CLASS_NAME) == 0)
1258    {
1259       status = InitializeToolTalkProcid( &ttFd, toplevel, False );
1260       if (TT_OK != status)
1261       {
1262           char *errfmt, *errmsg, *title, *statmsg;
1263           title = GETMESSAGE(21,38,"File Manager Error");
1264           errfmt = GETMESSAGE(18, 40,
1265                    "Could not connect to ToolTalk:\n%s\nExiting ...");
1266           statmsg = tt_status_message(status);
1267
1268           errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1269           fprintf(stderr, errfmt, statmsg);
1270           sprintf(errmsg, errfmt, statmsg);
1271
1272           /* put up error dialog and loop,
1273            * application will exit in dialog callback
1274            */
1275           post_dialog(toplevel, title, errmsg, DtErrExitCB); 
1276       }
1277
1278       if (application_args.session != NULL)
1279       {
1280          msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1281                                     "DtFileSession_Run",
1282                                     (Tt_message_callback)ExitApp );
1283          tt_message_file_set( msg, application_args.session );
1284          tt_message_send( msg );
1285       }
1286       else if (application_args.directories != NULL)
1287       {
1288          msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1289                                     "DtFolder_Show",
1290                                     (Tt_message_callback)ExitApp );
1291          tt_message_file_set( msg, application_args.directories );
1292          SetupSendRequestArgs( application_args, msg );
1293          tt_message_send( msg );
1294       }
1295       else
1296       {
1297          /* Default action: Open up pwd or home dir */
1298          GetPWD(current_directory);
1299
1300          if (current_directory[0] != NULL)
1301          {
1302             msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1303                                        "DtFolder_Show",
1304                                        (Tt_message_callback)ExitApp );
1305             tt_message_file_set( msg, current_directory );
1306          }
1307          else
1308          {
1309             msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1310                                        "DtHome_Show",
1311                                        (Tt_message_callback)ExitApp );
1312          }
1313          SetupSendRequestArgs( application_args, msg );
1314          tt_message_send( msg );
1315       }
1316       WaitForResponseAndExit();
1317    }
1318
1319    /*  Initialize the encapsulation mechanism and install the dialogs  */
1320    /*  used by the file manager.                                       */
1321
1322    _DtInitializeEncapsulation (display, argv[0], DTFILE_CLASS_NAME);
1323    topPositionOffset = -8;
1324
1325    status = InitializeToolTalkProcid( &ttFd, toplevel, True );
1326    if (TT_OK != status)
1327    {
1328        char *errfmt, *errmsg, *title, *statmsg;
1329        title = GETMESSAGE(21,38,"File Manager Error");
1330        errfmt = GETMESSAGE(18, 40,
1331                 "Could not connect to ToolTalk:\n%s\nExiting ...");
1332        statmsg = tt_status_message(status);
1333
1334        errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1335        fprintf(stderr, errfmt, statmsg);
1336        sprintf(errmsg, errfmt, statmsg);
1337
1338        /* put up error dialog and loop,
1339         * application will exit in dialog callback
1340         */
1341        post_dialog(toplevel, title, errmsg, DtErrExitCB); 
1342    }
1343
1344
1345 #ifdef DT_PERFORMANCE
1346    printf("  Setup Callbacks (messaging)\n");
1347    gettimeofday(&update_time_s, NULL);
1348
1349    /* Added by Aloke Gupta */
1350    _DtPerfChkpntMsgSend("Begin Setup Callbacks");
1351
1352 #endif
1353    events2Watch = tt_pattern_create();
1354    tt_pattern_category_set( events2Watch, TT_OBSERVE );
1355    tt_pattern_class_add( events2Watch, TT_NOTICE );
1356    tt_pattern_scope_add( events2Watch, TT_SESSION );
1357    sessId = tt_default_session();
1358    tt_pattern_session_add( events2Watch, sessId );
1359    tt_free( sessId );
1360    tt_pattern_op_add( events2Watch, "DtTypes_Reloaded" );
1361    tt_pattern_op_add( events2Watch, "XSession_Ending" );
1362    tt_pattern_callback_add( events2Watch, ObserveTtNotice );
1363    tt_pattern_register( events2Watch );
1364
1365    requests2Handle = tt_pattern_create();
1366    tt_pattern_category_set( requests2Handle, TT_HANDLE );
1367    tt_pattern_class_add( requests2Handle, TT_REQUEST );
1368    tt_pattern_scope_add( requests2Handle, TT_SESSION );
1369    sessId = tt_default_session();
1370    tt_pattern_session_add( requests2Handle, sessId );
1371    tt_free( sessId );
1372    tt_pattern_op_add( requests2Handle, "DtFileSession_Run" );
1373    tt_pattern_op_add( requests2Handle, "DtFolder_Show" );
1374    tt_pattern_op_add( requests2Handle, "DtHome_Show" );
1375    tt_pattern_op_add( requests2Handle, "DtTools_Show" );
1376    tt_pattern_op_add( requests2Handle, "DtTrash_Show" );
1377    tt_pattern_op_add( requests2Handle, "DtTrash_Remove" );
1378    tt_pattern_op_add( requests2Handle, "DtTrash_Empty" );
1379    tt_pattern_op_add( requests2Handle, "DtTrash_File" );
1380    tt_pattern_op_add( requests2Handle, "DtTrash_Restore" );
1381    tt_pattern_op_add( requests2Handle, "DtFile_PutOnWorkspace" );
1382    tt_pattern_op_add( requests2Handle, "DtFile_Move" );
1383    tt_pattern_op_add( requests2Handle, "DtFile_Copy" );
1384    tt_pattern_op_add( requests2Handle, "DtFile_Link" );
1385    tt_pattern_callback_add( requests2Handle, HandleTtRequest );
1386    tt_pattern_register( requests2Handle );
1387
1388    /* Setup the settings file if any to setup */
1389
1390    _DtWsmAddMarqueeSelectionCallback(toplevel,
1391                                      (DtWsmMarqueeSelectionProc) MarqueeSelect,
1392                                      NULL);
1393
1394 #ifdef DT_PERFORMANCE
1395    gettimeofday(&update_time_f, NULL);
1396    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1397       update_time_f.tv_usec += 1000000;
1398       update_time_f.tv_sec--;
1399    }
1400    printf("    done Setting Callbacks (messaging), time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1401
1402     /* Added by Aloke Gupta */
1403    _DtPerfChkpntMsgSend("Done  Setup Callbacks");
1404
1405 #endif
1406
1407    smallIconWidth = application_args.smallIconWidth;
1408    smallIconHeight = application_args.smallIconHeight;
1409    largeIconWidth = application_args.largeIconWidth;
1410    largeIconHeight = application_args.largeIconHeight;
1411    user_font = application_args.user_font;
1412    dragThreshold = application_args.dragThreshold;
1413    rereadTime = application_args.rereadTime;
1414    checkBrokenLink = application_args.checkBrokenLink;
1415    maxDirectoryProcesses = application_args.maxDirectoryProcesses;
1416    maxRereadProcesses = application_args.maxRereadProcesses;
1417    maxRereadProcsPerTick = application_args.maxRereadProcsPerTick;
1418    trashWait = application_args.trashWait;
1419    showFilesystem = application_args.showFilesystem;
1420    showDropZone = application_args.showDropZone;
1421    showEmptySet = application_args.showEmptySet;
1422    showEmptyMsg = application_args.showEmptyMsg;
1423    restrictMode = application_args.restrictMode;
1424    openDirType = application_args.openDirType;
1425    desktopIconType = application_args.desktopIconType;
1426    desktopPlacement = application_args.desktopPlacement;
1427    freezeOnConfig = application_args.freezeOnConfig;
1428    emptyTrashOnExit = application_args.emptyTrashOnExit;
1429 #if defined(__hpux) || defined(sun)
1430    follow_links = application_args.follow_links;
1431 #endif
1432    instanceWidth = application_args.instanceIconWidth;
1433    instanceHeight = application_args.instanceIconHeight;
1434    fileMgrIcon = application_args.fileMgrIcon;
1435    appMgrIcon = application_args.appMgrIcon;
1436    trashIcon = application_args.trashIcon;
1437    retryLoadDesktopInfo = application_args.retryLoadDesktop;
1438    if( application_args.directories != NULL
1439        || (strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1440        || restrictMode )
1441    {
1442       special_view = True;
1443       if(strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1444       {
1445          if(application_args.directories != NULL)
1446             special_restricted = XtNewString(application_args.directories);
1447          else
1448          {
1449             /* Get users pwd so we can set the restricted dir to it */
1450             GetPWD(current_directory);
1451
1452             if (current_directory[0] != NULL)
1453                special_restricted = XtNewString(current_directory);
1454             else
1455                special_restricted = XtNewString("~");
1456          }
1457       }
1458       else if( restrictMode )
1459          special_restricted = XtNewString("~");
1460       else
1461          special_restricted = NULL;
1462       special_treeType = treeType = application_args.tree_view;
1463       special_treeFiles = treeFiles = application_args.tree_files;
1464       special_viewType = viewType = application_args.view;
1465       special_orderType = orderType = application_args.order;
1466       special_directionType = directionType = application_args.direction;
1467       special_randomType = randomType = application_args.grid;
1468       special_title = XtNewString(application_args.title);
1469       if(application_args.help_volume == NULL)
1470       {
1471          special_helpVol = XtNewString(DTFILE_HELP_NAME);
1472          fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1473       }
1474       else
1475       {
1476          special_helpVol = XtNewString(application_args.help_volume);
1477          fileMgrHelpVol = XtNewString(application_args.help_volume);
1478       }
1479       fileMgrTitle = application_args.title;
1480    }
1481    else
1482    {
1483       special_view = False;
1484       treeType = application_args.tree_view;
1485       treeFiles = application_args.tree_files;
1486       viewType = application_args.view;
1487       orderType = application_args.order;
1488       directionType = application_args.direction;
1489       randomType = application_args.grid;
1490       fileMgrTitle = application_args.title;
1491       if(application_args.help_volume == NULL)
1492          fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1493       else
1494          fileMgrHelpVol = XtNewString(application_args.help_volume);
1495    }
1496
1497
1498    if(desktopIconType == LARGE)
1499    {
1500       numRows = displayHeight / PIXELS_PER_ROW_LARGE;
1501       numColumns = displayWidth / PIXELS_PER_COLUMN_LARGE;
1502    }
1503    else /* small */
1504    {
1505       numRows = displayHeight / PIXELS_PER_ROW_SMALL;
1506       numColumns = displayWidth / PIXELS_PER_COLUMN_SMALL;
1507    }
1508
1509 #ifdef SHAPE
1510    /* determine whether the Server has the shape extension */
1511    if(XShapeQueryExtension(display, &base1, &base2) == True)
1512       shapeExtension = True;
1513    else
1514       shapeExtension = False;
1515 #endif
1516
1517    /* get the name for the root directory */
1518    root_title = (char *)XtMalloc(strlen(application_args.root_title) + 1);
1519    strcpy(root_title, application_args.root_title);
1520
1521    if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
1522    {
1523       pwInfo = getpwuid (getuid());
1524       homeDir = pwInfo->pw_dir;
1525    }
1526    strncpy(users_home_dir, homeDir, MAX_PATH - 1);
1527    if(restrictMode)
1528    {
1529       if(application_args.directories != NULL &&
1530                            strncmp(application_args.directories, "~", 1) != 0 )
1531       {
1532          if(strncmp(application_args.directories, users_home_dir,
1533                                                   strlen(users_home_dir)) != 0)
1534             RestrictModeUsage (argv);
1535       }
1536       else if (application_args.directories == NULL)
1537           application_args.directories = XtNewString("~");
1538    }
1539    if (strcmp(users_home_dir, "/") != 0)
1540       strcat(users_home_dir, "/");
1541
1542    XtAppAddActions(XtWidgetToApplicationContext (toplevel), actionTable, 2);
1543
1544    /* Create some global Xm strings for our dialog buttons */
1545
1546    okXmString = XmStringCreateLocalized((char*)_DtOkString);
1547    cancelXmString = XmStringCreateLocalized((char*)_DtCancelString);
1548    helpXmString = XmStringCreateLocalized((char*)_DtHelpString);
1549    applyXmString = XmStringCreateLocalized((char*)_DtApplyString);
1550    closeXmString = XmStringCreateLocalized((char*)_DtCloseString);
1551
1552    /*  Get the dt path created and initialized  */
1553
1554    dt_path = _DtCreateDtDirs (display);
1555
1556    if (dt_path == NULL)
1557    {
1558       Widget dialog;
1559       char *msg, *title;
1560       title = XtNewString((GETMESSAGE(21,38,"File Manager Error")));
1561       tmpStr = GETMESSAGE(18, 2, "Could not create the ~/.dt folder or sub folders.");
1562       msg = XtNewString(tmpStr);
1563
1564       /* put up error dialog and loop, application will exit in 
1565          dialog callback */
1566
1567       dialog = post_dialog(toplevel, title, msg, DtErrExitCB); 
1568       XtFree(msg);
1569       XtFree(title);
1570
1571       while (TRUE)
1572       {
1573         XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
1574       }
1575     }
1576
1577    /*  Set the black and white pixel globals.  */
1578
1579    black_pixel = BlackPixelOfScreen (XtScreen (toplevel));
1580    white_pixel = WhitePixelOfScreen (XtScreen (toplevel));
1581
1582    /*
1583     * Take over the drawing area's redisplay functions, so that we can get
1584     * the dtfile views to redraw according to stacking order, using our own
1585     * redraw function.
1586     */
1587    xmDrawingAreaWidgetClass->core_class.expose = DrawingAreaRedisplay;
1588
1589
1590    /* Get the root user id */
1591
1592    if ((pw = getpwnam("root")) == NULL)
1593       root_user = 0;          /* Assume root is uid 0 */
1594    else
1595       root_user = pw->pw_uid;
1596
1597
1598    file_mgr_dialog = _DtInstallDialog (fileMgrClass, True, True);
1599    change_dir_dialog = _DtInstallDialog (changeDirClass, True, True);
1600    preferences_dialog = _DtInstallDialog (preferencesClass, True, True);
1601    filter_dialog = _DtInstallDialog (filterClass, True, True);
1602    find_dialog = _DtInstallDialog (findClass, True, True);
1603    mod_attr_dialog = _DtInstallDialog (modAttrClass, True, True);
1604    help_dialog = _DtInstallDialog (helpClass, False, False);
1605
1606    if(special_view == True && special_restricted != NULL);
1607       if(strncmp(special_restricted, "~", 1) == 0)
1608       {
1609          char *ptr, *ptr1;
1610
1611          special_restricted = _DtChangeTildeToHome(special_restricted);
1612          ptr = strrchr(special_restricted, '/');
1613          ptr1 = ptr + 1;
1614          if(ptr1[0] == NULL)
1615             *ptr = '\0';
1616       }
1617
1618    /* Setup the settings file if any to setup */
1619    RestoreSettingsFile();
1620
1621 #ifdef DT_PERFORMANCE
1622    printf("  TrashCreateDialog\n");
1623    gettimeofday(&update_time_s, NULL);
1624
1625    /* Added by Aloke Gupta */
1626    _DtPerfChkpntMsgSend("Begin TrashCreateDialog");
1627
1628 #endif
1629    if( InitializeTrash( application_args.prompt_user ) )
1630
1631 #ifdef DEFER_TRASH_CREATION
1632 ;
1633 #else
1634      TrashCreateDialog (display);
1635 #endif
1636
1637 #ifdef DT_PERFORMANCE
1638    gettimeofday(&update_time_f, NULL);
1639    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1640       update_time_f.tv_usec += 1000000;
1641       update_time_f.tv_sec--;
1642    }
1643    printf("    done TrashCreateDialog, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1644
1645    /* Added by Aloke Gupta */
1646    _DtPerfChkpntMsgSend("Done  TrashCreateDialog");
1647 #endif
1648
1649    /* lets go empty the trash if there is any */
1650 /*
1651    TrashEmpty();
1652 */
1653
1654 #ifdef DT_PERFORMANCE
1655    printf("  Setup Desktop\n");
1656    gettimeofday(&update_time_s, NULL);
1657    /* Added by Aloke Gupta */
1658    _DtPerfChkpntMsgSend("Begin Setup Desktop");
1659
1660 #endif
1661    /* go build 10 desktop windows */
1662    desktop_data = NULL;
1663    InitializeDesktopWindows(10, display);
1664    InitializeDesktopGrid();
1665
1666    LoadDesktopInfo(application_args.session);
1667
1668    /* Install WorkSpaceRemoved handler.
1669       This handler will be called when a workspace is being removed
1670       so File Manager can go through its desktop icons and clean up.
1671    */
1672    DtWsmAddWorkspaceModifiedCallback( toplevel, WorkSpaceRemoved, NULL );
1673
1674 #ifdef DT_PERFORMANCE
1675    gettimeofday(&update_time_f, NULL);
1676    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1677       update_time_f.tv_usec += 1000000;
1678       update_time_f.tv_sec--;
1679    }
1680    printf("    done Setting up Desktop, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1681
1682    /* Added by Aloke Gupta */
1683    _DtPerfChkpntMsgSend("Done  Setup Desktop");
1684 #endif
1685
1686
1687    /*  Process the application resources to restore a session, dt  */
1688    /*  a directory set or display the users home directory.         */
1689
1690 #ifdef DT_PERFORMANCE
1691    printf("  Bring up View\n");
1692    gettimeofday(&update_time_s, NULL);
1693
1694    /* Added by Aloke Gupta */
1695    _DtPerfChkpntMsgSend("Begin Bring up View");
1696
1697 #endif
1698
1699    if (strcmp (application_args.no_view, "-noview") != 0)
1700    {
1701      if (application_args.session != NULL)
1702         session_flag =
1703           RestoreSession (application_args.session, NORMAL_RESTORE, NULL);
1704      else if (application_args.directories != NULL)
1705      {
1706         restoreType = CURRENT_DIR_RESTORE;
1707         OpenDirectories (application_args.directories, NULL);
1708      }
1709    }
1710
1711 #ifdef DT_PERFORMANCE
1712    gettimeofday(&update_time_f, NULL);
1713    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1714       update_time_f.tv_usec += 1000000;
1715       update_time_f.tv_sec--;
1716    }
1717    printf("    done Bringing up view, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);  fflush(stdout);
1718
1719    /* Added by Aloke Gupta */
1720     _DtPerfChkpntMsgSend("Done  Bring up View");
1721 #endif
1722
1723
1724    /*  If no views were opened upon invocation, display the  */
1725    /*  current directory.                                    */
1726
1727    if ( (strcmp (application_args.no_view, "-noview") != 0) &&
1728         ((application_args.session == NULL) ||
1729          (session_flag != 0)) )
1730    {
1731       if (view_count == 0)
1732       {
1733          /* Get users pwd so we can create a fileviewer window of it */
1734          GetPWD(current_directory);
1735
1736          if (current_directory[0] != NULL)
1737          {
1738            if (!GetNewView (home_host_name, current_directory, NULL, NULL, 0))
1739               ViewHomeDirectoryHandler (0);
1740          }
1741          else
1742          {
1743            ViewHomeDirectoryHandler (0);
1744          }
1745       }
1746    }
1747
1748
1749    /*  Set up the timer based directory reading.      */
1750    InitializeDirectoryRead (toplevel);
1751
1752    /* Process and dispatch incoming events */
1753    eventDebugging = getenv("EVENT_DEBUGGING") != NULL;
1754
1755 #ifdef DT_PERFORMANCE
1756    printf("  InitializeToolTalkSession\n");
1757    gettimeofday(&update_time_s, NULL);
1758 #endif
1759    (void) InitializeToolTalkSession( toplevel, ttFd );
1760 #ifdef DT_PERFORMANCE
1761    gettimeofday(&update_time_f, NULL);
1762    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1763       update_time_f.tv_usec += 1000000;
1764       update_time_f.tv_sec--;
1765    }
1766    printf("    done InitializeToolTalkSession, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1767 #endif
1768
1769  #ifdef DT_PERFORMANCE
1770    gettimeofday(&update_time_fs, NULL);
1771    if (update_time_ss.tv_usec > update_time_fs.tv_usec) {
1772       update_time_fs.tv_usec += 1000000;
1773       update_time_fs.tv_sec--;
1774    }
1775    printf("    Finish, time: %ld.%ld\n\n", update_time_fs.tv_sec - update_time_ss.tv_sec, update_time_fs.tv_usec - update_time_ss .tv_usec);
1776 #endif
1777
1778    while (1)
1779    {
1780       XtNextEvent(&event);
1781
1782       if (event.type != 0)
1783          XtDispatchEvent(&event);
1784    }
1785 }
1786
1787
1788
1789 /************************************************************************
1790  *
1791  *  ErrorHandler
1792  *
1793  ************************************************************************/
1794
1795 static void
1796 ErrorHandler(
1797         Display *disp,
1798         XErrorEvent *event )
1799 {
1800   #define _DTFILE_BUFSIZE 1024
1801   char errmsg[_DTFILE_BUFSIZE];
1802
1803   _DtPrintDefaultErrorSafe (disp, event, errmsg, _DTFILE_BUFSIZE);
1804   _DtSimpleError(application_name, DtWarning, NULL, errmsg, NULL);
1805   xErrorDetected = True;
1806
1807   /* We do not want to exit here lets try to continue... */
1808
1809 }
1810
1811 static void
1812 ToolkitErrorHandler(
1813         char *message )
1814 {
1815     char * msg;
1816     char * tmpStr;
1817
1818     tmpStr = GETMESSAGE(18, 6, "An X Toolkit error occurred... Exiting.\n");
1819     msg = (char *)malloc(strlen(tmpStr) + strlen(message) + 3);
1820     strcpy(msg, message);
1821     strcat(msg, "\n");
1822     strcat(msg, tmpStr);
1823     _DtSimpleError (application_name, DtError, NULL, msg);
1824     printf ("%s",msg);
1825     XtFree(msg);
1826     FinalizeToolTalkSession( );
1827     exit (1);
1828 }
1829
1830
1831
1832
1833 /************************************************************************
1834  *
1835  *  Usage
1836  *      When incorrect parameters have been specified on the command
1837  *      line, print out a set of messages detailing the correct use
1838  *      and exit.
1839  *
1840  ************************************************************************/
1841
1842 static void
1843 Usage(
1844         char **argv )
1845 {
1846    char * template;
1847    char * message_string1 = "\nUsage: %s...\n\n"
1848                          "   -noview\n\n\t"
1849                          "Dtfile runs in server mode.\n\n"
1850                          "   -session SessionFile\n\n\t"
1851                          "Dtfile runs with the session file specified in the SessionFile\n\t"
1852                          "parameter.\n\n"
1853                          "   -folder Folder[,Folder,Folder]\n"
1854                          "   -dir Folder[,Folder,Folder]\n\n\t"
1855                          "Dtfile displays a window for each folder specified in the\n\t"
1856                          "Folder parameter.  The Folder parameter may contain many\n\t"
1857                          "folders separated by commas.  Folders may be in the form\n\t"
1858                          "'path'.\n\n"
1859                          "   -title Title\n\n\t"
1860                          "Dtfile uses the string specified in the Title parameter as the\n\t"
1861                          "title for its windows.\n\n"
1862                          "   -help_volume HelpVolume\n\n\t"
1863                          "Dtfile uses the help volume specified in the HelpVolume parameter.\n\n"
1864                          "   -restricted\n\n\t"
1865                          "Dtfile will not display folders above the restricted folder.\n\t"
1866                          "If the -dir option is used, the folder specified in that option\n\t"
1867                          "is the restricted folder.  If the -dir option is not used, the\n\t"
1868                          "user's current folder is the restricted folder.\n\n"
1869                          "   -grid on/off\n\n\t"
1870                          "on     = Files are displayed in a grid pattern.\n\t"
1871                          "off    = Files are displayed as placed.\n\n"
1872                          "   -tree on/off\n\n\t"
1873                          "on     = Files are displayed in single folder mode.\n";
1874
1875    char * message_string2 = "\toff    = Files are displayed in folder tree mode.\n\n"
1876                          "   -tree_files never/always/choose\n\n\t"
1877                          "never  = Tree mode has two states: partially expanded or collapsed.\n\t"
1878                          "always = Tree mode has two states: fully expanded or collapsed.\n\t"
1879                          "choose = Tree mode has three states: partially expanded, fully\n\t"
1880                          "         expanded, or collapsed.\n\n"
1881                          "   -order alphabetical/file_type/date/size\n\n\t"
1882                          "Files are displayed in the specified order: alphabetical, by file\n\t"
1883                          "type, by date, or by size.\n\n"
1884                          "   -view no_icon/large_icon/small_icon/attributes\n\n\t"
1885                          "Files are displayed in the specified format: text only, text and\n\t"
1886                          "large icons, text and small icons, with attributes.\n\n"
1887                          "   -direction ascending/descending\n\n\t"
1888                          "Files are displayed in the specified direction: ascending or\n\t"
1889                          "descending.\n\n"
1890                          "   -large_icon_width  <size>\n\n"
1891                          "   -large_icon_height <size>\n\n"
1892                          "   -small_icon_width  <size>\n\n"
1893                          "   -small_icon_height <size>\n\n"
1894                          "        The display area size for the icon images in File Manager\n"
1895                          "        Icon images larger than this size will be clipped to this size\n"
1896                          "        The default display area size for large is 38 and small is 24\n\n"
1897                          "\n"
1898 ;
1899
1900    template = (GETMESSAGE(18,23, message_string1));
1901    fprintf (stderr, template, argv[0]);
1902    template = (GETMESSAGE(18,24, message_string2));
1903    fprintf (stderr, template);
1904
1905    exit (0);
1906 }
1907
1908 static void
1909 RestrictModeUsage(
1910         char **argv )
1911 {
1912    char * template;
1913    char * message_string = "\nRestricted Mode Usage: %s...\n\n"
1914                          "   -folder Folder[,Folder,Folder]\n"
1915                          "   -dir Folder[,Folder,Folder]\n\n\t"
1916                          "Where Folder is a Folder below and/or including\n\t"
1917                          "the user's Home Folder.\n\n";
1918
1919    template = (GETMESSAGE(18,26, message_string));
1920
1921    fprintf (stderr, template, argv[0]);
1922
1923    FinalizeToolTalkSession( );
1924    exit (0);
1925 }
1926
1927
1928
1929
1930 /************************************************************************
1931  *
1932  *  Stop
1933  *      Catches Ctrl C's and exits.
1934  *
1935  ************************************************************************/
1936
1937 static void
1938 Stop( void )
1939 {
1940   FinalizeToolTalkSession( );
1941   exit(0);
1942 }
1943
1944
1945
1946
1947
1948
1949
1950 /***********************************************************************
1951  *
1952  * RestoreSettingsFile
1953  *         Used to restore the save settings files from
1954  *         either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
1955  *
1956  ***********************************************************************/
1957 static void
1958 RestoreSettingsFile( void )
1959 {
1960    int             status, fd;
1961    char            *dtPath=NULL;
1962    char            *homeSavePath=NULL;
1963    char            *homeHomePath=NULL;
1964    char            *toolSavePath=NULL;
1965    char            *toolHomePath=NULL;
1966    char            *dirName=NULL;
1967    Atom            actualType;
1968    int             actualFormat;
1969    unsigned long   nitems;
1970    unsigned long   leftover;
1971    unsigned char   *data = NULL;
1972
1973
1974   /* go get the dt path */
1975   /* _DtCreateDtDirs returs a path of MaxPath Length */
1976    dtPath = (char *)_DtCreateDtDirs(display);
1977
1978   /* Determin which type of session we are running HOME or CURRENT */
1979
1980   /* get the root window property of SaveMode */
1981   XGetWindowProperty(display, RootWindow(display,0),
1982                          save_mode, 0L, (long)BUFSIZ,False,
1983                          XA_STRING, &actualType,
1984                          &actualFormat,&nitems,&leftover,
1985                          &data);
1986
1987   if(strcmp((char *)data, "home") == 0)
1988     dirName = XtNewString("home");
1989   else if(strcmp((char *)data, "current") == 0)
1990     dirName = XtNewString("current");
1991   else
1992   {
1993     XtFree(dtPath);
1994     return;  /* we are comming up in a system mode (e.g. default) */
1995   }
1996
1997
1998   /* Build the paths to read the files from */
1999
2000   toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2001                   strlen(TOOL_SETTINGS_FILENAME) +
2002                   strlen(dirName) + 4);
2003
2004   homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2005                   strlen(HOME_SETTINGS_FILENAME) +
2006                   strlen(dirName) + 4);
2007
2008   sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2009   sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2010
2011   /* open the home settings file to see if its there */
2012   if((fd = open(homeSavePath, O_RDONLY)) != -1)
2013   {
2014       close(fd);
2015      /* create where the saved file is going to go */
2016
2017       homeHomePath = (char *)XtMalloc(strlen(dtPath) +
2018                      strlen(HOME_SETTINGS_FILENAME) + 2);
2019
2020       sprintf( homeHomePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2021
2022      /* remove any existing dtfile.home (e.g. HOME_SETTINGS_FILENAME) */
2023       unlink(homeHomePath);
2024
2025      /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2026       * will be used by the dtfile
2027       */
2028       status = link(homeSavePath, homeHomePath);
2029       if(status != 0)
2030       {
2031         char *tmpStr, *msg;
2032
2033         tmpStr = GETMESSAGE(18,27, "Unable to recover the saved default home settings file, will use default.\n");
2034         msg = XtNewString(tmpStr);
2035         _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2036         XtFree(msg);
2037       }
2038
2039    }
2040
2041  /* open the tool settings file to see if its there */
2042   if((fd = open(toolSavePath, O_RDONLY)) != -1)
2043   {
2044       close(fd);
2045      /* create where the saved file is going to go */
2046       toolHomePath = (char *)XtMalloc(strlen(dtPath) +
2047                      strlen(TOOL_SETTINGS_FILENAME) + 2);
2048
2049       sprintf( toolHomePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2050
2051      /* remove any existing dtfile.tool (e.g. TOOL_SETTINGS_FILENAME) */
2052       unlink(toolHomePath);
2053
2054      /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2055       * will be used by the dtfile
2056       */
2057       status = link(toolSavePath, toolHomePath);
2058       if(status != 0)
2059       {
2060         char *tmpStr, *msg;
2061
2062         tmpStr = GETMESSAGE(18,28, "Unable to recover the saved default tool settings file, will use default.\n");
2063         msg = XtNewString(tmpStr);
2064         _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2065         XtFree(msg);
2066       }
2067    }
2068
2069
2070   /* free up space */
2071    XFree(data);
2072    XtFree(dtPath);
2073    XtFree(dirName);
2074    XtFree(homeSavePath);
2075    XtFree(toolSavePath);
2076    XtFree(toolHomePath);
2077    XtFree(homeHomePath);
2078
2079
2080 }
2081
2082
2083
2084
2085
2086 /***********************************************************************
2087  *
2088  * MoveDefaultSettings
2089  *         Used to save the dtfile.tool and dtfile.home settings files to
2090  *         either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
2091  *         The parameter mode determines whether it is home or
2092  *         current.
2093  *
2094  ***********************************************************************/
2095 static void
2096 MoveDefaultSettings(
2097         int mode )
2098 {
2099    int status;
2100    char *toolSavePath=NULL;
2101    char *homeSavePath=NULL;
2102    char *dirName=NULL;
2103    char *toolMovePath=NULL;
2104    char *homeMovePath=NULL;
2105    char *dtPath;
2106
2107    /* determine whether home or current */
2108    if(mode == HOME_DIR_RESTORE)
2109      dirName = XtNewString("home");
2110    else
2111      dirName = XtNewString("current");
2112
2113   /* go get the dt path */
2114   /* _DtCreateDtDirs returs a path of MaxPath Length */
2115   dtPath = (char *)_DtCreateDtDirs(display);
2116
2117
2118   /* Build the paths to save the files to */
2119
2120   toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2121                   strlen(TOOL_SETTINGS_FILENAME) +
2122                   strlen(dirName) + 4);
2123
2124   homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2125                   strlen(HOME_SETTINGS_FILENAME) +
2126                   strlen(dirName) + 4);
2127
2128
2129    /* create the directory and filename of where its going to be saved */
2130   sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2131   sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2132
2133    /* Setup the paths used to GET the old files */
2134
2135    toolMovePath= (char *)XtMalloc(strlen(dtPath) +
2136                    strlen(TOOL_SETTINGS_FILENAME) + 3);
2137
2138    homeMovePath= (char *)XtMalloc(strlen(dtPath) +
2139                    strlen(HOME_SETTINGS_FILENAME) + 3);
2140
2141    /* create the filename of where its going to be saved from */
2142
2143    /* Tool File location */
2144    sprintf( toolMovePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2145
2146    /* Home File location */
2147    sprintf( homeMovePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2148
2149
2150   /* get rid of the tool settings file that is already in home or current */
2151    status = unlink(toolSavePath);
2152
2153   /* get rid of the home settings file that is already in home or current */
2154    status = unlink(homeSavePath);
2155
2156
2157   /* now save tool settings file in home or current determined by savePath */
2158    status = link(toolMovePath, toolSavePath);
2159
2160   /* now save home settings file in home or current determined by savePath */
2161    status = link(homeMovePath, homeSavePath);
2162
2163    /* free up space */
2164    XtFree(homeMovePath);
2165    XtFree(toolMovePath);
2166    XtFree(homeSavePath);
2167    XtFree(toolSavePath);
2168    XtFree(dirName);
2169    XtFree(dtPath);
2170 }
2171
2172
2173 /************************************************************************
2174  *
2175  *  SaveSettingsCB
2176  *      Callback for the Save Settings menupick.
2177  *
2178  ************************************************************************/
2179 void
2180 SaveSettingsCB(
2181         Widget w,
2182         XtPointer client_data,
2183         XtPointer call_data )
2184 {
2185    Widget dlog;
2186    Widget mbar;
2187    Arg args[1];
2188    char * message;
2189    char * title;
2190    FileMgrRec * file_mgr_rec;
2191    DialogData * dialog_data;
2192    FileMgrData * file_mgr_data;
2193    char * tmpStr;
2194
2195    /* Strip the file_mgr_rec from the current widget
2196    * and attach it to the ok callback button
2197    */
2198
2199
2200    /* Get the file_mgr_rec hanging off the menubar */
2201    mbar = XmGetPostedFromWidget(XtParent(w));
2202    XmUpdateDisplay (w);
2203    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2204    XtGetValues(mbar, args, 1);
2205
2206
2207    /* Ignore accelerators when we're insensitive */
2208    if ((file_mgr_rec->menuStates & SETTINGS) == 0)
2209    {
2210      XSetInputFocus(XtDisplay(w),
2211                     XtWindow(file_mgr_rec->defaultEnvBtn_child),
2212                     RevertToParent, CurrentTime);
2213      return;
2214    }
2215
2216    /* Desensatize the save settings menu pick here */
2217    file_mgr_rec->menuStates &= ~SETTINGS;
2218
2219
2220    /* Get the file_mgr_rec dialog data info */
2221    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
2222      return;
2223    file_mgr_data = (FileMgrData *) dialog_data->data;
2224
2225
2226    /* Based on the path we must determine if we are saving a Tools or
2227     * HomeDir dtfile view.
2228     */
2229    if (file_mgr_data->restricted_directory != NULL && file_mgr_data->toolbox)
2230      file_mgr_data->restoreKind = TOOL_RESTORE;
2231    else
2232      file_mgr_data->restoreKind = HOME_RESTORE;
2233
2234
2235    /* Setup and call the _DtMessageDialog procedure to post the dialog */
2236
2237    if (file_mgr_data->restoreKind == HOME_RESTORE)
2238    {
2239      tmpStr = (GETMESSAGE(18,29, "Save the current File Manager View window size,\npreferences, and filter settings?\n\nThey will be used for any new File Manager View windows\nstarted from the Front Panel."));
2240    }
2241    else
2242    {
2243      tmpStr = (GETMESSAGE(18,35, "Save the current Application Manager\nView window size, preferences, and filter settings?\n\nThey will be used for any new Application Manager\nwindows started from the Front Panel."));
2244    }
2245    message = XtNewString(tmpStr);
2246
2247    if(file_mgr_data->title != NULL &&
2248                strcmp(file_mgr_data->helpVol, DTFILE_HELP_NAME) != 0)
2249    {
2250       tmpStr = GETMESSAGE(18, 16, "Save As Default Options");
2251       title = (char *)XtMalloc(strlen(tmpStr) +
2252                                  strlen(file_mgr_data->title) + 5);
2253       sprintf(title, "%s - %s", file_mgr_data->title, tmpStr);
2254    }
2255    else
2256    {
2257       tmpStr = GETMESSAGE(18, 32, "File Manager - Save As Default Options");
2258       title = XtNewString(tmpStr);
2259    }
2260    dlog = (Widget)_DtMessageDialog(mbar, title, message, NULL, TRUE,
2261                                    SaveDefaultCancelCB, SaveDefaultOkCB, NULL,
2262                                    HelpRequestCB, False, QUESTION_DIALOG);
2263    file_mgr_rec->defaultEnvBtn_child=dlog;
2264    XtFree (message);
2265    XtFree (title);
2266
2267
2268    /* Add array as userdata on the dialog. */
2269
2270    XtSetArg(args[0], XmNuserData, file_mgr_rec);
2271    XtSetValues(dlog, args, 1);
2272
2273 }
2274
2275 /************************************************************************
2276  *
2277  *  SaveDefaultCancelCB
2278  *      Cleanup and unmanage the save settings dialog.
2279  *
2280  ************************************************************************/
2281 static void
2282 SaveDefaultCancelCB(
2283         Widget w,
2284         XtPointer client_data,
2285         XtPointer call_data )
2286 {
2287   FileMgrRec * file_mgr_rec;
2288   Arg args[1];
2289
2290     /* Update the display, and un-post the dialog */
2291     XtUnmanageChild((Widget)client_data);
2292     XmUpdateDisplay((Widget)client_data);
2293     XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2294     XtGetValues((Widget)client_data, args, 1);
2295
2296
2297     /* Re-sensatize the save settings menu pick */
2298     file_mgr_rec->menuStates |= SETTINGS;
2299
2300
2301     XtDestroyWidget((Widget)client_data);
2302
2303 }
2304
2305
2306 /************************************************************************
2307  *
2308  *  SaveDefaultOkCB
2309  *      Save the current dtfile view as the default environment for
2310  *      new dtfiles created.
2311  *
2312  ************************************************************************/
2313 static void
2314 SaveDefaultOkCB(
2315         Widget w,
2316         XtPointer client_data,
2317         XtPointer call_data )
2318 {
2319
2320    FileMgrRec * file_mgr_rec;
2321    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
2322    char view_number[5];
2323    int fd;
2324    Arg args[1];
2325
2326    DialogData * dialog_data;
2327    FileMgrData * file_mgr_data;
2328    char * msg;
2329    char * tmp_path;
2330    char full_path[MAX_PATH + 1];
2331    char * tmpStr;
2332    char * save_host;
2333    char * save_directory;
2334    char ** save_branch_list;
2335    FileViewData ** save_selection_list;
2336    int save_selected_file_count;
2337
2338
2339    /* Get the file_mgr_rec hanging off the dialog */
2340    XtUnmanageChild((Widget)client_data);
2341    XmUpdateDisplay ((Widget)client_data);
2342    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2343    XtGetValues((Widget)client_data, args, 1);
2344
2345
2346    /* Re-sensatize the save settings menu pick */
2347    file_mgr_rec->menuStates |= SETTINGS;
2348
2349
2350    /* Get the file_mgr_rec dialog data info */
2351
2352    dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
2353    file_mgr_data = (FileMgrData *) dialog_data->data;
2354
2355
2356    /* Build the path for our env file */
2357
2358    tmp_path = _DtCreateDtDirs(display);
2359    if (tmp_path == NULL)
2360      {
2361        XtDestroyWidget(client_data);
2362        return;
2363      }
2364
2365
2366    /* Look and see what type of restore we are doing */
2367    if (file_mgr_data->restoreKind == TOOL_RESTORE)
2368    {
2369       sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
2370       application_args.tool_width = file_mgr_data->width;
2371       application_args.tool_height = file_mgr_data->height;
2372    }
2373    else
2374    {
2375       sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
2376       application_args.dir_width = file_mgr_data->width;
2377       application_args.dir_height = file_mgr_data->height;
2378    }
2379
2380    XtFree(tmp_path);
2381
2382
2383    /*  Create the Environment session file  */
2384
2385    if ((fd = creat(full_path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2386    {
2387       char *title;
2388       tmpStr = GETMESSAGE(18, 17, "Unable to create a file to store the default options.");
2389       title = XtNewString((GETMESSAGE(21,38,"Object Create Error")));
2390       msg = XtNewString(tmpStr);
2391       _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
2392       XtFree(msg);
2393       XtFree(title);
2394       return;
2395    }
2396
2397
2398    /*  Write out the general information  */
2399
2400    (void) write (fd, "*", strlen ("*"));
2401    (void) write (fd, DTFILE_CLASS_NAME,strlen (DTFILE_CLASS_NAME));
2402    (void) write (fd, "*view_count:      ", strlen ("*view_count:      "));
2403
2404    (void) sprintf (view_number, "%d", 1);
2405    (void) write (fd, view_number, strlen (view_number));
2406    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2407
2408    name_list[1] = view_number;
2409
2410    /* Temporarily remove data that we don't need or want saved */
2411
2412    save_host = file_mgr_data->host;
2413    save_directory = file_mgr_data->current_directory;
2414    save_branch_list = file_mgr_data->branch_list;
2415    save_selection_list = file_mgr_data->selection_list;
2416    save_selected_file_count = file_mgr_data->selected_file_count;
2417    file_mgr_data->host = NULL;
2418    file_mgr_data->current_directory = NULL;
2419    file_mgr_data->branch_list = NULL;
2420    file_mgr_data->selection_list = NULL;
2421    file_mgr_data->selected_file_count = 0;
2422
2423    /*  Call the encapsulation mechanism to write each dialog  */
2424
2425    (void) sprintf (view_number, "%d", 0);
2426    _DtWriteDialogData (dialog_data, fd, name_list);
2427    (void) write (fd, "#\n", strlen ("#\n"));
2428
2429    /* Restore the data that was temporarily removed */
2430
2431    file_mgr_data->host = save_host;
2432    file_mgr_data->current_directory = save_directory;
2433    file_mgr_data->branch_list = save_branch_list;
2434    file_mgr_data->selection_list = save_selection_list;
2435    file_mgr_data->selected_file_count = save_selected_file_count;
2436
2437    (void) close (fd);
2438
2439    XtDestroyWidget(client_data);
2440
2441 }
2442
2443
2444
2445 /************************************************************************
2446  *
2447  *  SaveSessionCallback
2448  *      Get the session name and call the function to save the session.
2449  *
2450  ************************************************************************/
2451
2452 void
2453 SaveSessionCallback(
2454         Widget w,
2455         XtPointer client_data,
2456         XtPointer call_data )
2457 {
2458    char * full_path=NULL;
2459    char * file_name=NULL;
2460    char * strPtr;
2461    int restore=NORMAL_RESTORE;
2462    Boolean status=FALSE;
2463    char * sessionFileName;
2464    char ** argv;
2465
2466    if(view_count == 0 && desktop_data->numIconsUsed == 0)
2467    {
2468       XChangeProperty (display, XtWindow (toplevel), command_atom,
2469                     XA_STRING, 8, PropModeReplace, (unsigned char *)NULL, 0);
2470       XSync(display, False);
2471       FinalizeToolTalkSession( );
2472       exit(0);
2473    }
2474
2475    status = DtSessionSavePath(w, &full_path, &file_name);
2476
2477    if (status)
2478      sessionFileName = file_name;
2479    else
2480    {
2481      XtFree( (char *)full_path);
2482      full_path = (char *) XtMalloc (sizeof (char) * MAX_PATH);
2483      sprintf( full_path, "%s/%s", dt_path, DTFILE_CLASS_NAME );
2484      sessionFileName = full_path;
2485    }
2486    SaveSession( full_path );
2487
2488    /* skip to the /.dt/ portion of the sessionFileName */
2489    strPtr = strstr(full_path, "/.dt/");
2490    (void)strcpy(full_path, strPtr);
2491
2492    /* Save off the settings files for both tool and home views */
2493    do {
2494         strPtr = DtStrrchr(full_path, '/');
2495         if ( !strPtr )
2496            continue;
2497         if ((strncmp(strPtr, "/home", 5) == 0))
2498            restore = HOME_DIR_RESTORE;
2499         else if ((strncmp(strPtr, "/current", 8) == 0))
2500            restore = CURRENT_DIR_RESTORE;
2501
2502         if (strPtr != NULL)
2503           *strPtr = '\0';
2504    } while ((strPtr != NULL) && (restore == NORMAL_RESTORE));
2505
2506    SaveDesktopInfo(restore);
2507
2508    /* Cop the settings files to the proper dir */
2509    MoveDefaultSettings(restore);
2510
2511    /*  Generate the reinvoking command and add it as the property value */
2512    argv = (char **) XtMalloc(3 * sizeof(char *));
2513    argv[0] = XtNewString(application_name);
2514    argv[1] = XtNewString("-session");
2515    argv[2] = XtNewString(sessionFileName);
2516    XSetCommand(XtDisplay(toplevel), XtWindow(toplevel), argv, 3);
2517
2518    XtFree ((char *) argv[0]);
2519    XtFree ((char *) argv[1]);
2520    XtFree ((char *) argv[2]);
2521    XtFree ((char *) argv);
2522
2523    XtFree ((char *) full_path);
2524    XtFree ((char *) file_name);
2525 }
2526
2527 /************************************************************************
2528  *
2529  *  SaveSession
2530  *      Save the current File Manager session as a set of resources
2531  *      within the file denoted by path.
2532  *
2533  ************************************************************************/
2534
2535 static void
2536 SaveSession(
2537         char *path
2538         )
2539 {
2540    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2541                                  NULL, NULL};
2542    char view_number[5];
2543    char number[5];
2544    char workspaceNumber[5];
2545    int fd;
2546    Atom * ws_presence = NULL;
2547    char * workspace_name=NULL;
2548    unsigned long num_workspaces = 0;
2549
2550    Atom actual_type;
2551    int  actual_format;
2552    unsigned long nitems;
2553    unsigned long leftover;
2554    WM_STATE * wm_state;
2555
2556    DialogData * dialog_data;
2557    FileMgrData * file_mgr_data;
2558    FileMgrRec  * file_mgr_rec;
2559    int i;
2560    int j;
2561    char * msg;
2562    int view_index;
2563    WorkspaceRec * workspaceInfo;
2564    char * tmpStr;
2565    Boolean saveTitle;
2566    char *actualSavedTitle;
2567
2568    /* This needs to be done because name_list is static and the values
2569       can be changed during the routine.  This means that they need to be
2570       NULL'd out each pass */
2571    name_list[1] = NULL;
2572    name_list[2] = NULL;
2573    name_list[3] = NULL;
2574    name_list[4] = NULL;
2575    name_list[5] = NULL;
2576
2577    /*  Disable any message box display during save session  */
2578
2579    message_display_enabled = False;
2580
2581
2582    /*  Create the session file  */
2583
2584    if ((fd = creat (path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2585    {
2586       tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2587       msg = XtNewString(tmpStr);
2588       _DtSimpleError (application_name, DtError, NULL, msg);
2589       XtFree(msg);
2590       message_display_enabled = True;
2591
2592       return;
2593    }
2594
2595
2596    /*  Write out the general information  */
2597
2598    /* Number of dtfile views */
2599    (void) write (fd, "*", strlen ("*"));
2600    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2601    (void) write (fd, "*view_count:      ", strlen ("*view_count:        "));
2602
2603    if (trashFileMgrData)
2604    {
2605       if (trashFileMgrData->file_mgr_rec)
2606          (void) sprintf (view_number, "%d", view_count + 1);
2607       else
2608          (void) sprintf (view_number, "%d", view_count);
2609    }
2610    else
2611    {
2612       (void) sprintf (view_number, "%d", view_count);
2613    }
2614    (void) write (fd, view_number, strlen (view_number));
2615    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2616
2617    (void) write (fd, "*", strlen ("*"));
2618    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2619    (void) write (fd, "*showFilesystem:  ", strlen ("*showFilesystem:    "));
2620
2621    if(showFilesystem)
2622       (void) write (fd, "True", strlen ("True"));
2623    else
2624       (void) write (fd, "False", strlen ("False"));
2625    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2626
2627    (void) write (fd, "*", strlen ("*"));
2628    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2629    (void) write (fd, "*restrictMode:    ", strlen ("*restrictMode:      "));
2630
2631    if(restrictMode)
2632       (void) write (fd, "True", strlen ("True"));
2633    else
2634       (void) write (fd, "False", strlen ("False"));
2635    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2636
2637    (void) write (fd, "*", strlen ("*"));
2638    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2639    (void) write (fd, "*openFolder:      ", strlen ("*openFolder:        "));
2640
2641    if(openDirType == NEW)
2642       (void) write (fd, "NEW", strlen ("NEW"));
2643    else
2644       (void) write (fd, "CURRENT", strlen ("CURRENT"));
2645    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2646
2647    view_index = 0;
2648    name_list[1] = view_number;
2649    saveTitle = False;
2650
2651
2652    /*  Write out each of the view's resources  */
2653    /*  start with -1 so we can include the trash dialog */
2654    for (i = -1; i < view_count; i++)
2655    {
2656       if(i == -1)
2657       {
2658          if(trashDialogData)
2659             dialog_data = (DialogData *) trashDialogData;
2660          else
2661             continue;
2662       }
2663       else
2664       {
2665          dialog_data = (DialogData *) view_set[i]->dialog_data;
2666       }
2667
2668       file_mgr_data = (FileMgrData *) dialog_data->data;
2669       if(i == -1 && trashDialogData)
2670           file_mgr_data->IsTrashCan = True;
2671       file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
2672       if(file_mgr_rec == NULL)
2673          continue;
2674
2675       /* This is a bug fix ... We don't want to save the title if the
2676          View is the Trash Can of if it is an Application Manager.  This
2677          is because if the user saves a session in one Locale, then logs
2678          in in another, the Title will be in the locale that the session was
2679          saved in rather then the new local.  So let's save the Title,
2680          Null it out, Save the session info, and finally restore the Title.
2681       */
2682       if(i == -1 || file_mgr_data->toolbox)
2683       {
2684          /* the Trash Can or toolbox (i.e. Application Manager) */
2685          actualSavedTitle = file_mgr_data->title;
2686          file_mgr_data->title = NULL;
2687          saveTitle = True;
2688       }
2689
2690       /*  Getting the WM_STATE property to see if iconified or not */
2691       XGetWindowProperty (display, XtWindow (file_mgr_rec->shell),
2692                              wm_state_atom, 0L, (long) BUFSIZ, False,
2693                              wm_state_atom, &actual_type, &actual_format,
2694                              &nitems, &leftover, (unsigned char **) &wm_state);
2695
2696       /* Write out if iconified our not */
2697
2698       write (fd, "*", strlen ("*"));
2699       write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2700       sprintf (view_number, "%d", view_index);
2701       write (fd, ".", strlen ("."));
2702       write (fd, view_number, strlen (view_number));
2703
2704       (void) write (fd, ".iconify:      ", strlen (".iconify:   "));
2705
2706       if (wm_state->state == IconicState)
2707         write (fd, "True\n", strlen ("True\n"));
2708       else
2709         write (fd, "False\n", strlen ("False\n"));
2710
2711
2712       /*  Get the workspaces for this dt by accessing the property.  */
2713
2714       if (DtWsmGetWorkspacesOccupied (display, XtWindow (file_mgr_rec->shell),
2715                                   &ws_presence, &num_workspaces) == Success)
2716       {
2717          write (fd, "*", strlen ("*"));
2718          write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2719          (void) write (fd, ".", strlen ("."));
2720          (void) write (fd, view_number, strlen (view_number));
2721          (void) write (fd, ".workspace: ", strlen (".workspace: "));
2722
2723
2724          for (j = 0; j < num_workspaces; j++)
2725          {
2726             if (j != 0) (void) write (fd, "*", strlen ("*"));
2727             workspace_name = XGetAtomName (display, ws_presence[j]);
2728             (void) write (fd, workspace_name, strlen (workspace_name));
2729             XtFree ((char *) workspace_name);
2730          }
2731
2732
2733          (void) write (fd, "\n", strlen ("\n"));
2734          XFree((char *)ws_presence);
2735       }
2736
2737
2738       /*  Call the encapsulation mechanism to write each dialog  */
2739
2740       if(i == -1)
2741          _DtWriteDialogData (trashDialogData, fd, name_list);
2742       else
2743          _DtWriteDialogData ((DialogData *)view_set[i]->dialog_data,
2744                              fd, name_list);
2745       (void) write (fd, "#\n", strlen ("#\n"));
2746
2747       view_index++;
2748       if(saveTitle)
2749       {
2750          file_mgr_data->title = actualSavedTitle;
2751          saveTitle = False;
2752       }
2753    }
2754
2755    /*
2756     * Save off help dialog information for each workspace.
2757     * These are the help dialogs used for the desktop objects.
2758     */
2759    name_list[1] = WS_LOAD_RES_HEADER;
2760    name_list[2] = workspaceNumber;
2761    name_list[3] = number;
2762
2763    for (i = 0; i < desktop_data->numWorkspaces; i++)
2764    {
2765       workspaceInfo = desktop_data->workspaceData[i];
2766
2767       /*
2768        * Save number of secondary help dialogs in format:
2769        *     *Dtfile.Workspace.<WS#>.secondaryHelpDialogCount:  <#>
2770        */
2771       write(fd, "*", strlen("*"));
2772       write(fd, DTFILE_CLASS_NAME, strlen(DTFILE_CLASS_NAME));
2773       write(fd, WS_RES_HEADER, strlen(WS_RES_HEADER));
2774       sprintf(workspaceNumber, "%d", i);
2775       write(fd, workspaceNumber, strlen(workspaceNumber));
2776       write(fd, SEC_HELP_RES_HEADER, strlen(SEC_HELP_RES_HEADER));
2777       sprintf(view_number, "%d", workspaceInfo->secondaryHelpDialogCount);
2778       write(fd, view_number, strlen(view_number));
2779       write (fd, "\n#\n", strlen ("\n#\n"));
2780
2781       /* Save each of the secondary help dialogs */
2782       for (j = 0; j < workspaceInfo->secondaryHelpDialogCount; j++)
2783       {
2784          sprintf(number, "%d", j + 1);
2785          _DtWriteDialogData(workspaceInfo->secondaryHelpDialogList[j],
2786                            fd, name_list);
2787       }
2788
2789       /* Save the primary help dialog window */
2790       if (workspaceInfo->primaryHelpDialog)
2791       {
2792          sprintf(number, "%d", 0);
2793          _DtWriteDialogData(workspaceInfo->primaryHelpDialog,
2794                            fd, name_list);
2795       }
2796       write (fd, "#\n", strlen ("#\n"));
2797    }
2798    (void) close (fd);
2799
2800    /*  Re-able message box display flag after save session  */
2801    message_display_enabled = True;
2802
2803
2804 }
2805
2806
2807
2808 /*
2809  * Given a directory name, this function will see if a view of the parent
2810  * directory is open; if so, then it will update the icon representing
2811  * this icon, in the parent view, so that it is drawn as 'open'.  This
2812  * function must only be called if openDirType == NEW.
2813  */
2814
2815 void
2816 ForceMyIconOpen (
2817    char * host_name,
2818    char * directory_name)
2819 {
2820    FileViewData * file_view_data = NULL;
2821    DesktopRec *desktopWindow;
2822    DialogData * dd;
2823    FileMgrData * fmd;
2824    char * parent;
2825    char * fname;
2826    char * ptr;
2827    char * full_path;
2828    int i, j, k;
2829    char *icon_name, *new_file_type_name, *file_type_name;
2830    Arg args[5];
2831
2832    /* if directory_name is passed in a NULL, we want to go through all
2833       existing open directories and check to see if there are any open
2834       directories in each of them. This is used at the end of OpenNewView
2835       and the end of ShowNewDirectory */
2836    if (directory_name == NULL)
2837    {
2838       for (i = 0; i < view_count; i++)
2839       {
2840          dd = (DialogData *) view_set[i]->dialog_data;
2841          fmd = (FileMgrData *) dd->data;
2842
2843          for(j = 0; j < fmd->directory_count; j++)
2844          {
2845             ForceMyIconOpen(view_set[i]->host_name,
2846                             fmd->directory_set[j]->name);
2847          }
2848       }
2849       return;
2850    }
2851
2852    parent = _DtPName(directory_name);
2853    fname =  DName(directory_name);
2854
2855    /* first lets check to see if the directory is open in one of the
2856       open file manager views */
2857    for (i = 0; i < view_count; i++)
2858    {
2859       dd = (DialogData *) view_set[i]->dialog_data;
2860       fmd = (FileMgrData *) dd->data;
2861
2862       /* loop through until we find the file_view_data structure for the
2863          directory to force open */
2864       if (strcmp(host_name, view_set[i]->host_name) == 0)
2865       {
2866          for(j = 0; j < fmd->directory_count; j++)
2867          {
2868             if (strcmp(parent, fmd->directory_set[j]->name) == 0)
2869             {
2870                for (k = 0; k < fmd->directory_set[j]->file_count; k++)
2871                {
2872                   file_view_data = fmd->directory_set[j]->file_view_data[k];
2873                   if (strcmp(file_view_data->file_data->file_name, fname) == 0)
2874                      break;
2875                   file_view_data = NULL;
2876                }
2877                break;
2878             }
2879          }
2880       }
2881
2882       if (file_view_data)
2883       {
2884          fmd = (FileMgrData *)(((DirectorySet *)file_view_data->directory_set)->
2885                            file_mgr_data);
2886
2887          file_type_name = file_view_data->file_data->logical_type;
2888
2889          if(fmd->view != BY_NAME)
2890             BuildAndShowIconName(file_type_name, fmd->view,
2891                                  fmd->show_type, file_view_data->widget);
2892       }
2893    }
2894
2895    /* now we need to check to see if the directory being opened has a
2896       representation on the Desktop */
2897    for(i = 0; i < desktop_data->numIconsUsed; i++)
2898    {
2899       char buf[MAX_PATH];
2900
2901       desktopWindow = desktop_data->desktopWindows[i];
2902       file_view_data = desktopWindow->file_view_data;
2903
2904       sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
2905                             desktopWindow->file_name);
2906       DtEliminateDots (buf);
2907
2908       if (strcmp(buf, directory_name) == 0 &&
2909                                     strcmp(desktopWindow->host, host_name) == 0)
2910       {
2911          file_type_name = file_view_data->file_data->logical_type;
2912          if(desktopIconType == LARGE)
2913              BuildAndShowIconName(file_type_name, BY_NAME_AND_ICON,
2914                                  SINGLE_DIRECTORY, desktopWindow->iconGadget);
2915          else /* SMALL */
2916              BuildAndShowIconName(file_type_name, BY_NAME_AND_SMALL_ICON,
2917                                  SINGLE_DIRECTORY, desktopWindow->iconGadget);
2918       }
2919    }
2920 }
2921
2922
2923
2924
2925 /************************************************************************
2926  *
2927  *  RestoreSession
2928  *      Open the file as a resource data base, and use the data to
2929  *      create a set of File Manager views.
2930  *
2931  ************************************************************************/
2932
2933 static int
2934 RestoreSession(
2935         char *path,
2936         int type_of_restore,
2937         char *directory)
2938 {
2939    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2940                                  NULL, NULL };
2941    XrmDatabase db;
2942    XrmName xrm_name[10];
2943    XrmRepresentation rep_type;
2944    XrmValue value;
2945    int num_views = 0;
2946    char * full_path = NULL;
2947    Boolean status=False;
2948    char * temp = NULL;
2949    char wsNum[5];
2950    char dialogNum[5];
2951    int num_sec_help_dialogs;
2952    int i;
2953    int j;
2954    DialogData * dialogData;
2955    struct stat stat_buf;
2956
2957
2958    /* Build the session path if we need to.
2959     * (e.g. When using the -session option)
2960     */
2961     if (type_of_restore == NORMAL_RESTORE)
2962     {
2963       status = DtSessionRestorePath(toplevel, &full_path, path);
2964
2965       if (!status)
2966          return;
2967
2968       if (stat(full_path, &stat_buf) != 0)
2969       {
2970         char *tmpStr, *msg, *title;
2971
2972         tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2973         msg = XtNewString(tmpStr);
2974         title = XtNewString((GETMESSAGE(21,39,"File Open Error")));
2975         _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
2976         XtFree(msg);
2977         XtFree(title);
2978         XtFree(full_path);
2979         full_path = NULL;
2980         return(-1);
2981       }
2982
2983       path = XtNewString(full_path);
2984     }
2985
2986    /* This prevents the encapsulator from placing the dialogs */
2987    disableDialogAutoPlacement = True;
2988
2989    /*  Open the file as a resource database and query it to  */
2990    /*  get the previously saved view count.                  */
2991
2992    db = XrmGetFileDatabase (path);
2993
2994    if (type_of_restore == NORMAL_RESTORE)
2995    {
2996       /* first find out if it should show the file system */
2997       xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
2998       xrm_name [1] = XrmStringToQuark ("showFilesystem");
2999       xrm_name [2] = NULL;
3000       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3001       {
3002          if ((temp = (char *) value.addr) != NULL &&
3003                  strcmp (temp, "True") == 0)
3004          {
3005             showFilesystem = True;
3006          }
3007          else
3008             showFilesystem = False;
3009       }
3010       else
3011          showFilesystem = True;
3012
3013       /* find out if it should be in restricted mode */
3014       xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3015       xrm_name [1] = XrmStringToQuark ("restrictMode");
3016       xrm_name [2] = NULL;
3017       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3018       {
3019          if ((temp = (char *) value.addr) != NULL &&
3020                  strcmp (temp, "True") == 0)
3021          {
3022             restrictMode = True;
3023          }
3024          else
3025             restrictMode = False;
3026       }
3027       else
3028          restrictMode = False;
3029
3030       /* find out openFolder mode */
3031       xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3032       xrm_name [1] = XrmStringToQuark ("openFolder");
3033       xrm_name [2] = NULL;
3034       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3035       {
3036          if ((temp = (char *) value.addr) != NULL &&
3037                  strcmp (temp, "NEW") == 0)
3038          {
3039             openDirType = NEW;
3040          }
3041          else
3042             openDirType = CURRENT;
3043       }
3044       else
3045          openDirType = CURRENT;
3046    }
3047
3048    xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3049    xrm_name [1] = XrmStringToQuark ("view_count");
3050    xrm_name [2] = NULL;
3051
3052    /* Load standard dtfile views */
3053    if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3054    {
3055       num_views = atoi (value.addr);
3056       if (num_views > 0)
3057          LoadViews(num_views, db, NULL, directory, special_restricted, 0);
3058    }
3059
3060    /* Restore any desktop help dialogs */
3061    if (type_of_restore == NORMAL_RESTORE)
3062    {
3063       for (i = 0; i < desktop_data->numWorkspaces; i++)
3064       {
3065          sprintf(wsNum, "%d", i);
3066          xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3067          xrm_name [1] = XrmStringToQuark (WS_LOAD_RES_HEADER);
3068          xrm_name [2] = XrmStringToQuark (wsNum);
3069          xrm_name [3] = XrmStringToQuark (SEC_LOAD_HELP_RES_HEADER);
3070          xrm_name [4] = NULL;
3071
3072          /* Load standard dtfile views */
3073          if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3074          {
3075             num_sec_help_dialogs = atoi (value.addr);
3076             if (num_sec_help_dialogs > 0)
3077             {
3078                desktop_data->workspaceData[i]->secondaryHelpDialogCount =
3079                   num_sec_help_dialogs;
3080                desktop_data->workspaceData[i]->secondaryHelpDialogList =
3081                 (DialogData **) XtMalloc(sizeof(DialogData *) *
3082                    num_sec_help_dialogs);
3083
3084                for (j = 0; j < num_sec_help_dialogs; j++)
3085                {
3086                   name_list[0] = DTFILE_CLASS_NAME;
3087                   name_list[1] = WS_LOAD_RES_HEADER;
3088                   name_list[2] = wsNum;
3089                   name_list[3] = dialogNum;
3090                   name_list[4] = NULL;
3091                   sprintf(dialogNum, "%d", j + 1);
3092                   dialogData =
3093                        _DtGetResourceDialogData(help_dialog, db, name_list);
3094                   desktop_data->workspaceData[i]->secondaryHelpDialogList[j]=
3095                      dialogData;
3096                   ShowDTHelpDialog(NULL, i, HYPER_HELP_DIALOG,
3097                                    dialogData, NULL, NULL, NULL, NULL,
3098                                    DtHELP_TYPE_TOPIC);
3099                }
3100             }
3101          }
3102
3103          /* Load the primary help dialog */
3104          name_list[0] = DTFILE_CLASS_NAME;
3105          name_list[1] = WS_LOAD_RES_HEADER;
3106          name_list[2] = wsNum;
3107          name_list[3] = dialogNum;
3108          name_list[4] = NULL;
3109          sprintf(dialogNum, "%d", 0);
3110          dialogData = _DtGetResourceDialogData(help_dialog, db, name_list);
3111
3112          /* Keep only if currently posted */
3113          if (!(((HelpData *)dialogData->data)->displayed))
3114          {
3115             /* Not currently displayed */
3116             _DtFreeDialogData(dialogData);
3117             dialogData = NULL;
3118          }
3119          desktop_data->workspaceData[i]->primaryHelpDialog = dialogData;
3120          if (dialogData)
3121          {
3122             ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
3123                              dialogData, NULL, DTFILE_HELP_NAME,
3124                              NULL, NULL, 0);
3125          }
3126       }
3127    }
3128
3129    XtFree(full_path);
3130    full_path = NULL;
3131
3132    /* Free the Xrm Database */
3133    XrmDestroyDatabase(db);
3134    disableDialogAutoPlacement = False;
3135
3136    return(0);
3137 }
3138
3139
3140 static void
3141 ViewAccept(
3142    View *view,
3143    Tt_message msg)
3144 {
3145    extern Tt_message FileCallback();
3146    extern Tt_message SessionCallback();
3147
3148    if ((msg == 0) || tt_is_err( tt_ptr_error( msg ))) {
3149       return;
3150    }
3151    view->msg = msg;
3152    /*
3153     * Register for notifications on the directory viewed.
3154     * This is done so that requesting apps can notify the
3155     * view if the directory name is changed.
3156     */
3157    view->pats = ttdt_file_join( view->directory_name, TT_SESSION, 0,
3158                                 FileCallback, view );
3159    if (tt_is_err( tt_ptr_error( view->pats ))) {
3160       view->pats = 0;
3161    }
3162
3163    /* Returned patterns automatically get destroyed when msg is destroyed */
3164    ttdt_message_accept( msg, SessionCallback,
3165                         _DtGetDialogShell( (DialogData *)view->dialog_data ),
3166                         view, 1, 1 );
3167 }
3168
3169
3170 static void
3171 LoadViews (
3172    int num_views,
3173    XrmDatabase db,
3174    char *host_name,
3175    char *directory_name,
3176    char *type,
3177    Tt_message msg)
3178
3179 {
3180    XrmName xrm_name[5];
3181    XrmRepresentation rep_type;
3182    XrmValue value;
3183    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
3184    char view_number[5];
3185    DialogData * dialog_data;
3186    FileMgrData * file_mgr_data;
3187    char * workspaces;
3188    XClassHint classHints;
3189    char * iconify = NULL;
3190    Boolean iconify_window;
3191    int i;
3192    char *title, *tmpTitle;
3193
3194    name_list[1] = view_number;
3195    xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3196
3197
3198    /*  Get and display view_count views.  */
3199
3200    for (i = 0; i < num_views; i++)
3201    {
3202       struct stat stat_buf;
3203
3204       (void) sprintf (view_number, "%d", i);
3205       xrm_name [1] = XrmStringToQuark (view_number);
3206
3207       /* Get the main dialog data and set up the view  */
3208
3209       dialog_data = _DtGetResourceDialogData (file_mgr_dialog, db, name_list);
3210       file_mgr_data = (FileMgrData *) dialog_data->data;
3211
3212       if(file_mgr_data->toolbox && file_mgr_data->title == NULL)
3213          file_mgr_data->title = DtActionLabel("Dtappmgr");
3214
3215       if (stat(file_mgr_data->current_directory, &stat_buf) != 0)
3216       {
3217          _DtFreeDialogData(dialog_data);
3218          continue;
3219       }
3220
3221       if (trashFileMgrData
3222           && (file_mgr_data->IsTrashCan == True)
3223           && strcmp(file_mgr_data->current_directory, trash_dir) == 0)
3224       {
3225          trashFileMgrData->view = file_mgr_data->view;
3226          trashFileMgrData->order = file_mgr_data->order;
3227          trashFileMgrData->direction = file_mgr_data->direction;
3228          trashFileMgrData->positionEnabled = file_mgr_data->positionEnabled;
3229          trashFileMgrData->preferences = file_mgr_data->preferences;
3230          file_mgr_data->preferences = NULL;
3231          _DtFreeDialogData(dialog_data);
3232          continue;
3233       }
3234
3235       /* Increment the view list size if necessary and add directory to list */
3236
3237       if (view_count == view_set_size)
3238       {
3239          view_set_size += 10;
3240          view_set =
3241             (View **) XtRealloc ((char *)view_set,
3242                                      sizeof (View **) * view_set_size);
3243       }
3244       view_set[view_count] = (View *) XtMalloc (sizeof (View));
3245       view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3246       view_set[view_count]->msg = 0;
3247       view_set[view_count]->pats = 0;
3248
3249       if(restoreType == TOOL_RESTORE)
3250          file_mgr_data->toolbox = True;
3251
3252       if(directory_name == NULL)
3253       {
3254          view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3255          view_set[view_count]->directory_name =
3256             XtNewString (file_mgr_data->current_directory);
3257       }
3258       else
3259       {
3260          XtFree(file_mgr_data->current_directory);
3261          file_mgr_data->current_directory = NULL;
3262          XtFree(file_mgr_data->restricted_directory);
3263          file_mgr_data->restricted_directory = NULL;
3264
3265          view_set[view_count]->directory_name = XtNewString(directory_name);
3266          XtFree((char *)file_mgr_data->selection_list);
3267          file_mgr_data->selection_list = NULL;
3268          if(host_name == NULL)
3269          {
3270             view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3271             file_mgr_data->current_directory = XtNewString(directory_name);
3272             if(type == NULL)
3273               file_mgr_data->restricted_directory =
3274                                               XtNewString(directory_name);
3275             else
3276               file_mgr_data->restricted_directory =
3277                                               XtNewString(type);
3278          }
3279          else
3280          {
3281             view_set[view_count]->host_name = XtNewString (host_name);
3282             XtFree(file_mgr_data->host);
3283             file_mgr_data->host = XtNewString(host_name);
3284             file_mgr_data->current_directory = XtNewString(directory_name);
3285             if(special_view && special_restricted != NULL)
3286                file_mgr_data->restricted_directory =
3287                                      XtNewString(special_restricted);
3288             else
3289                file_mgr_data->restricted_directory = NULL;
3290          }
3291          FileMgrBuildDirectories (file_mgr_data,
3292                           view_set[view_count]->host_name, directory_name);
3293       }
3294
3295       /*  Get the workspace set the view is contained in  */
3296       /*  and set the property for the view just created  */
3297
3298       xrm_name [2] = XrmStringToQuark ("workspace");
3299       xrm_name [3] = NULL;
3300
3301       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3302       {
3303          /*  Make sure we have some valid workspaces names to work with */
3304
3305          /* value.addr should = NULL if no workspace names */
3306          workspaces = (char *) value.addr;
3307       }
3308       else
3309         /* we have no workspace resource so use default */
3310         workspaces = NULL;
3311
3312       /*  Get and set whether the view is iconic  */
3313
3314       xrm_name [2] = XrmStringToQuark ("iconify");
3315       xrm_name [3] = NULL;
3316
3317       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3318       {
3319          /*  If there is an iconify resource and its value is True,  */
3320          /*  then mark the window as iconified.                      */
3321
3322          if ((iconify = (char *) value.addr) != NULL &&
3323               strcmp (iconify, "True") == 0)
3324          {
3325            iconify_window = True;
3326
3327          }
3328          else
3329           iconify_window = False;
3330       }
3331       else
3332          iconify_window = False;
3333
3334      if(file_mgr_data->positionEnabled == RANDOM_ON &&
3335                         (file_mgr_data->object_positions == NULL))
3336         LoadPositionInfo(file_mgr_data);
3337
3338       /* Call _DtShowDialog to create and manage the new window */
3339
3340      tmpTitle = file_mgr_data->title;
3341      title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3342      if (special_title)
3343         XtFree(special_title);
3344      special_title = XtNewString(title);
3345
3346      classHints.res_name = title;
3347      classHints.res_class = DTFILE_CLASS_NAME;
3348
3349      _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL,
3350                     RemoveTextFields, NULL, workspaces, iconify_window,
3351                     special_view, title, &classHints);
3352
3353      XtFree(title);
3354      file_mgr_data->title = tmpTitle;
3355
3356      if (msg != 0) {
3357         ViewAccept( view_set[view_count], msg );
3358         msg = 0;
3359      }
3360
3361      view_count++;
3362    }
3363
3364    if (openDirType == NEW)
3365       ForceMyIconOpen(file_mgr_data->host, NULL);
3366 }
3367
3368
3369 /************************************************************************
3370  *
3371  *  GetPWD
3372  *
3373  ************************************************************************/
3374 static void
3375 GetPWD(
3376         char current_directory[] )
3377 {
3378    FILE * pwd_file;
3379    register int i;
3380
3381     /*  Open a pwd process and read the current working directory  */
3382     /*  from it.  If the open fails or a read fails, then display  */
3383     /*  the users home directory.                                  */
3384
3385       pwd_file = popen ("pwd", "r");
3386       i = 0;
3387
3388       if (pwd_file != NULL)
3389       {
3390          while (1)
3391          {
3392             errno = 0;
3393             if (fread (&current_directory[i], sizeof(char), 1, pwd_file) != 1)
3394             {
3395                if (errno == EINTR)
3396                   continue;
3397                else
3398                   break;
3399             }
3400
3401             if (current_directory[i] == '\n')
3402                break;
3403
3404             i++;
3405          }
3406       }
3407     (void) pclose (pwd_file);
3408     current_directory[i] = NULL;
3409
3410 }
3411
3412 /************************************************************************
3413  *
3414  *  OpenDirectories
3415  *      Given a string that contains a single or set of host:path
3416  *      specifications, parse out each host:path, validate it as
3417  *      a accessible directory, and call a function to create a
3418  *      file manager view of the directory.
3419  *
3420  ************************************************************************/
3421
3422 static void
3423 OpenDirectories(
3424         char *directory_set,
3425         char *type)
3426 {
3427    char * separator;
3428    char * host;
3429    char * path;
3430
3431    /*  Loop the the directory set string until all of  */
3432    /*  the path specifications have be parsed.    */
3433
3434    while (1)
3435    {
3436       separator = DtStrchr (directory_set, ',');
3437       if (separator != NULL)
3438          *separator = NULL;
3439
3440       _DtPathFromInput(directory_set, NULL, &host, &path);
3441
3442       if (path)
3443       {
3444          GetNewView (host, path, type, NULL, 0);
3445       }
3446       else
3447       {
3448          char *tmpStr, *errTitle, *errMsg, *dmsg;
3449
3450          tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3451          errTitle = XtNewString(tmpStr);
3452          tmpStr = GETMESSAGE(18, 38, "Invalid folder specification, %s");
3453          errMsg = XtNewString(tmpStr);
3454          dmsg = XtMalloc(strlen(errMsg)+strlen(directory_set)+1);
3455          sprintf(dmsg, errMsg, directory_set);
3456          _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
3457
3458          XtFree(errTitle);
3459          XtFree(errMsg);
3460          XtFree(dmsg);
3461       }
3462
3463       /*  Free up the unique host and directory names  */
3464       /*  that were allocated.                         */
3465
3466       XtFree ((char *) host);
3467       XtFree ((char *) path);
3468
3469       /*  Set the starting position of the next host:path  */
3470
3471       if (separator != NULL)
3472          directory_set = separator + 1;
3473       else
3474          break;
3475    }
3476 }
3477
3478
3479
3480
3481 /************************************************************************
3482  *
3483  *  GetNewView
3484  *      Given a directory name, generate a new view for the directory.
3485  *
3486  ************************************************************************/
3487 DialogData *
3488 GetNewView(
3489         char *host_name,
3490         char *directory_name,
3491         char *type,
3492         WindowPosition *position,
3493         Tt_message msg)
3494 {
3495    DialogData * dialog_data;
3496    DialogInstanceData * instance_data;
3497    FileMgrData * file_mgr_data;
3498    FileMgrData * fmd;
3499    FileMgrRec * file_mgr_rec;
3500    char * real_directory_name;
3501    int i;
3502    XClassHint classHints;
3503    char *title, *tmpTitle;
3504    struct stat stat_buf;
3505    char *tmpStr;
3506    char *errMsg = NULL;
3507
3508    DtEliminateDots( directory_name );
3509
3510    if (stat(directory_name, &stat_buf) == 0)
3511    {
3512       if ((stat_buf.st_mode & S_IFMT) != S_IFDIR)
3513       {
3514          tmpStr = GETMESSAGE(18, 19,
3515                   "The folder specification,\n%s\nis not a folder.");
3516          errMsg = XtNewString(tmpStr);
3517       }
3518    }
3519    else
3520    {
3521       tmpStr = GETMESSAGE(18, 20,
3522                "The folder specification,\n%s\ndoes not exist.");
3523       errMsg = XtNewString(tmpStr);
3524    }
3525
3526    if (errMsg)
3527    {
3528       char *title, *dmsg;
3529
3530       tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3531       title = XtNewString(tmpStr);
3532       dmsg = XtMalloc(strlen(errMsg) +
3533                       strlen(directory_name) + 1);
3534       sprintf(dmsg, errMsg, directory_name);
3535       _DtMessage(toplevel, title, dmsg, NULL, HelpRequestCB);
3536
3537       XtFree(errMsg);
3538       XtFree(title);
3539       XtFree(dmsg);
3540       return(NULL);
3541    }
3542
3543    /*
3544     * Special case: When opening any of the special desktop directory
3545     * icons (Home, Remote Systems, etc), we want to display the correct
3546     * path (i.e. $HOME instead of $HOME/.dt/Desktop/Home).  So ... we'll
3547     * do the remap here.
3548     */
3549    real_directory_name = directory_name;
3550
3551    if(openDirType == NEW || (strcmp(real_directory_name, desktop_dir) == 0))
3552    {
3553       for(i = 0; i < view_count; i++)
3554       {
3555          if((strcmp(real_directory_name, view_set[i]->directory_name) == 0 &&
3556             (strcmp(host_name, view_set[i]->host_name) == 0))
3557                                   )
3558          {
3559              Window   rootWindow;
3560              Atom     pCurrent;
3561              Screen   *currentScreen;
3562              int      screen;
3563
3564              dialog_data = (DialogData *) view_set[i]->dialog_data;
3565              file_mgr_data = (FileMgrData *) dialog_data->data;
3566              file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
3567
3568              screen = XDefaultScreen(display);
3569              currentScreen = XScreenOfDisplay(display, screen);
3570              rootWindow = RootWindowOfScreen(currentScreen);
3571
3572              /* Get the current Workspace */
3573              if (DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
3574                                                                    == Success)
3575              {
3576                 Atom * ws_presence = NULL;
3577                 unsigned long num_workspaces = 0;
3578                 int k;
3579
3580                 if (DtWsmGetWorkspacesOccupied(display,
3581                      XtWindow(file_mgr_rec->shell), &ws_presence,
3582                      &num_workspaces) == Success)
3583                 {
3584                    /* Already in this workspace? */
3585                    for (k = 0; k < num_workspaces; k++)
3586                    {
3587                       if (ws_presence[k] == pCurrent)
3588                          break;
3589                    }
3590
3591                    if (k >= num_workspaces)
3592                    {
3593                       /* Add to the workspace */
3594                       ws_presence = (Atom *) XtRealloc((char *)ws_presence,
3595                            sizeof (Atom) * (num_workspaces + 1));
3596
3597                       ws_presence[num_workspaces] = pCurrent;
3598                       DtWsmSetWorkspacesOccupied(display,
3599                                           XtWindow(file_mgr_rec->shell),
3600                                           ws_presence, num_workspaces + 1);
3601                    }
3602                    XFree((char *)ws_presence);
3603                 }
3604                 else
3605                 {
3606                    /* Change the hints to reflect the current workspace */
3607                    DtWsmSetWorkspacesOccupied(display,
3608                                            XtWindow(file_mgr_rec->shell),
3609                                            &pCurrent, 1);
3610                 }
3611              }
3612
3613              /* must map the window to catch iconified windows */
3614              /* a XtPopup will not catch it */
3615              XtMapWidget(file_mgr_rec->shell);
3616              XRaiseWindow(display, XtWindow(file_mgr_rec->shell));
3617
3618              /* announce activity */
3619              {
3620                 Tt_message msg;
3621                 msg = tt_pnotice_create(TT_SESSION, "DtActivity_Began");
3622                 tt_message_send(msg);
3623                 tttk_message_destroy(msg);
3624              }
3625
3626              return(NULL);
3627          }
3628       }
3629    }
3630
3631    /* If in novice mode, force the icon for this dir to the 'Open' state */
3632    if (openDirType == NEW)
3633       ForceMyIconOpen(host_name, directory_name);
3634
3635    /*  Increment the list size if necessary.  */
3636
3637    if (view_count == view_set_size)
3638    {
3639       view_set_size += 10;
3640       view_set =
3641          (View **) XtRealloc ((char *)view_set,
3642                                     sizeof (View **) * view_set_size);
3643    }
3644
3645    view_set[view_count] = (View *) XtMalloc (sizeof (View));
3646    view_set[view_count]->msg = 0;
3647    view_set[view_count]->pats = 0;
3648
3649    if (initiating_view != NULL)
3650       dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3651    else
3652    {
3653       char * tmp_path;
3654       char full_path[MAX_PATH + 1];
3655       XrmDatabase db;
3656
3657       tmp_path = _DtCreateDtDirs(display);
3658       if(type != NULL)
3659          sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
3660       else
3661          sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
3662       XtFree(tmp_path);
3663       db = XrmGetFileDatabase (full_path);
3664       if(db != NULL)
3665       {
3666          if(type != NULL)
3667          {
3668             restoreType = TOOL_RESTORE;
3669             LoadViews(1, db, NULL, directory_name, type, msg);
3670          }
3671          else
3672          {
3673             restoreType = HOME_RESTORE;
3674             LoadViews(1, db, host_name, directory_name, NULL, msg);
3675          }
3676
3677          /*
3678           * Free the Xrm Database
3679           */
3680          XrmDestroyDatabase(db);
3681          dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
3682          file_mgr_data = (FileMgrData *) dialog_data->data;
3683          if(type != NULL)
3684          {
3685             application_args.tool_width = file_mgr_data->width;
3686             application_args.tool_height = file_mgr_data->height;
3687          }
3688          else
3689          {
3690             application_args.dir_width = file_mgr_data->width;
3691             application_args.dir_height = file_mgr_data->height;
3692          }
3693          if(file_mgr_data->find != NULL &&
3694                                 file_mgr_data->current_directory != NULL)
3695          {
3696             DialogData * dialog_data;
3697             FindData * find_data;
3698
3699             dialog_data = (DialogData *)file_mgr_data->find;
3700             find_data = (FindData *)dialog_data->data;
3701
3702             XtFree(find_data->directories);
3703             if(file_mgr_data->restricted_directory == NULL)
3704             {
3705                if(restrictMode)
3706                   find_data->directories = XtNewString(users_home_dir);
3707                else
3708                   find_data->directories =
3709                             XtNewString(file_mgr_data->current_directory);
3710             }
3711             else
3712             {
3713                if(strcmp(file_mgr_data->current_directory,
3714                          file_mgr_data->restricted_directory) == 0)
3715                   find_data->directories = XtNewString("/");
3716                else
3717                   find_data->directories =
3718                         XtNewString(file_mgr_data->current_directory +
3719                         strlen(file_mgr_data->restricted_directory));
3720             }
3721          }
3722
3723          /* If in novice mode, force the icon for all the dir's to the
3724             'Open' state */
3725          if (openDirType == NEW)
3726             ForceMyIconOpen(host_name, NULL);
3727
3728          return((DialogData *)view_set[view_count - 1]->dialog_data);
3729       }
3730       else
3731          dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3732    }
3733    view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3734    file_mgr_data = (FileMgrData *) dialog_data->data;
3735
3736    /*  Adjust the view settings if this new view was created  */
3737    /*  because of an action on a previous view.               */
3738
3739    if (initiating_view != NULL)
3740    {
3741       FileMgrPropagateSettings ((FileMgrData *)initiating_view, file_mgr_data);
3742       /* force new window to come up in flat mode */
3743       file_mgr_data->show_type =
3744         ((PreferencesData *)file_mgr_data->preferences->data)->show_type =
3745                                                               SINGLE_DIRECTORY;
3746       file_mgr_data->view = file_mgr_data->view_single;
3747    }
3748
3749       /*  Call the FileMgr dialog to build up its directory set for  */
3750       /*  the directory name.                                        */
3751    FileMgrBuildDirectories (file_mgr_data, host_name, real_directory_name);
3752
3753    if(type != NULL)
3754    {
3755       PreferencesData *preferences_data;
3756
3757       file_mgr_data->toolbox = True;
3758       file_mgr_data->width = application_args.tool_width;
3759       file_mgr_data->height = application_args.tool_height;
3760
3761       /* we want to default for the toolboxes (i.e. Application Manager) to
3762        * look different from a normal File Manager view.  Let's turn off
3763        * the iconic_path, current_directory, and status_line.
3764        */
3765       file_mgr_data->show_iconic_path = False;
3766       file_mgr_data->show_current_dir = False;
3767 /*
3768       file_mgr_data->show_status_line = True;
3769 */
3770
3771       preferences_data = (PreferencesData *)file_mgr_data->preferences->data;
3772       preferences_data->show_iconic_path = file_mgr_data->show_iconic_path;
3773       preferences_data->show_current_dir = file_mgr_data->show_current_dir;
3774       preferences_data->show_status_line = file_mgr_data->show_status_line;
3775    }
3776    else
3777    {
3778       file_mgr_data->toolbox = False;
3779       file_mgr_data->width = application_args.dir_width;
3780       file_mgr_data->height = application_args.dir_height;
3781    }
3782
3783
3784    if(file_mgr_data->find != NULL && file_mgr_data->current_directory != NULL)
3785    {
3786       DialogData * dialog_data;
3787       FindData * find_data;
3788
3789       dialog_data = (DialogData *)file_mgr_data->find;
3790       find_data = (FindData *)dialog_data->data;
3791
3792       XtFree(find_data->directories);
3793       if(file_mgr_data->restricted_directory == NULL)
3794       {
3795          if(restrictMode)
3796             find_data->directories = XtNewString(users_home_dir);
3797          else
3798             find_data->directories =
3799                             XtNewString(file_mgr_data->current_directory);
3800       }
3801       else
3802       {
3803          if(strcmp(file_mgr_data->current_directory,
3804                    file_mgr_data->restricted_directory) == 0)
3805             find_data->directories = XtNewString("/");
3806          else
3807             find_data->directories =
3808                    XtNewString(file_mgr_data->current_directory +
3809                    strlen(file_mgr_data->restricted_directory));
3810       }
3811    }
3812
3813    view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3814    view_set[view_count]->directory_name =
3815          XtNewString (file_mgr_data->current_directory);
3816
3817    /* Load default position info, or inherit, if appropriate */
3818    if ((fmd = (FileMgrData *)initiating_view) &&
3819        (strcmp(fmd->host, host_name) == 0) &&
3820        (strcmp(fmd->current_directory, real_directory_name) == 0))
3821    {
3822       InheritPositionInfo(fmd, file_mgr_data);
3823    }
3824    else
3825       LoadPositionInfo(file_mgr_data);
3826
3827
3828    /*  Get the dialog displayed.  */
3829    if (position)
3830    {
3831       instance_data = (DialogInstanceData *) dialog_data->data;
3832       instance_data->x = position->x;
3833       instance_data->y = position->y;
3834       instance_data->displayed = True;  /* @@@ Hack! without this,
3835                                           _DtShowDialog will ignore
3836                                            our position info */
3837    }
3838
3839    tmpTitle = file_mgr_data->title;
3840    title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3841    if (special_title)
3842       XtFree(special_title);
3843    special_title = XtNewString(title);
3844
3845    classHints.res_name = title;
3846    classHints.res_class = DTFILE_CLASS_NAME;
3847    initiating_view = NULL;
3848
3849    _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL, RemoveTextFields,
3850                NULL, NULL, False, special_view, title, &classHints);
3851
3852    XtFree(title);
3853    file_mgr_data->title = tmpTitle;
3854
3855    if (msg != 0) {
3856       ViewAccept( view_set[view_count], msg );
3857       msg = 0;
3858    }
3859
3860    view_count++;
3861
3862    /* If in novice mode, force the icon for all the dir's to the 'Open' state */
3863    if (openDirType == NEW)
3864       ForceMyIconOpen(host_name, NULL);
3865
3866    return(dialog_data);
3867 }
3868
3869
3870
3871
3872 /************************************************************************
3873  *
3874  *  CloseView
3875  *      Update the view set array when a view is closed.
3876  *
3877  ************************************************************************/
3878
3879 void
3880 CloseView(
3881         DialogData *dialog_data )
3882 {
3883    register int i;
3884    register int j;
3885    FileMgrData * file_mgr_data;
3886    DialogData * tmpDialog_data;
3887    FileMgrRec * file_mgr_rec;
3888    XmManagerWidget file_window;
3889    char *directory_name = NULL;
3890    char *host_name = NULL;
3891
3892    if(dialog_data == trashDialogData)
3893    {
3894       CloseTrash(NULL, NULL, NULL);
3895       return;
3896    }
3897
3898    for (i = 0; i < view_count; i++)
3899    {
3900       if (dialog_data == (DialogData *) (view_set[i]->dialog_data))
3901       {
3902          tmpDialog_data = (DialogData *) (view_set[i]->dialog_data);
3903          file_mgr_data = (FileMgrData *)tmpDialog_data->data;
3904
3905          directory_name = (char *)XtMalloc( strlen(view_set[i]->directory_name) + 1);
3906          strcpy(directory_name, view_set[i]->directory_name);
3907          host_name = (char *)XtMalloc( strlen(view_set[i]->host_name) + 1);
3908          strcpy(host_name, view_set[i]->host_name);
3909
3910          if (view_set[i]->msg != 0) {
3911             if (view_set[i]->pats != 0) {
3912                ttdt_file_quit( view_set[i]->pats, 0 );
3913                view_set[i]->pats = 0;
3914             }
3915             tt_message_reply( view_set[i]->msg );
3916             tttk_message_destroy( view_set[i]->msg );
3917             view_set[i]->msg = 0;
3918          }
3919
3920          XtFree ((char *) view_set[i]->directory_name);
3921          XtFree ((char *) view_set[i]->host_name);
3922          XtFree ((char *) view_set[i]);
3923          view_set[i] = NULL;
3924
3925          for (j = i; j < view_count - 1; j++)
3926             view_set[j] = view_set[j + 1];
3927
3928          view_count--;
3929
3930          _DtHideDialog (dialog_data, True);
3931
3932          file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
3933          file_window = (XmManagerWidget)file_mgr_rec->file_window;
3934          /* For next time, unmanage all the icons */
3935          XtUnmanageChildren(file_window->composite.children,
3936                             file_window->composite.num_children);
3937
3938          if(PositionFlagSet(file_mgr_data))
3939             SavePositionInfo(file_mgr_data);
3940
3941          /* If it is an Application Manager view, then no point in
3942           caching this dialog, so free it */
3943
3944          if(file_mgr_data->toolbox)
3945             _DtFreeDialog(dialog_data);
3946
3947          _DtFreeDialogData (dialog_data);
3948
3949          break;
3950       }
3951    }
3952
3953
3954    /*  Update the directory cache list to remove unneeded directories.  */
3955
3956    UpdateCachedDirectories (view_set, view_count);
3957
3958    if (openDirType == NEW)
3959       ForceMyIconClosed(host_name, directory_name);
3960
3961    XtFree(directory_name);
3962    XtFree(host_name);
3963 }
3964
3965
3966
3967
3968 /************************************************************************
3969  *
3970  *  DirectoryChanged
3971  *      This function is called when a view may be changing its
3972  *      current directory.  It updates the view_set list to the
3973  *      new host and directory.
3974  *
3975  ************************************************************************/
3976
3977 void
3978 DirectoryChanged(
3979         XtPointer file_mgr_data,
3980         char *old_host_name,
3981         char *new_host_name,
3982         char *old_directory_name,
3983         char *new_directory_name )
3984 {
3985    int i;
3986
3987
3988    /*  See if the directory is one being viewed  */
3989
3990    for (i = 0; i < view_count; i++)
3991    {
3992       if (((DialogData *) (view_set[i]->dialog_data))->data == file_mgr_data)
3993       {
3994          if (strcmp (old_host_name, view_set[i]->host_name) == 0              &&
3995              strcmp (old_directory_name, view_set[i]->directory_name) == 0)
3996          {
3997             XtFree ((char *) view_set[i]->host_name);
3998             view_set[i]->host_name = XtNewString (new_host_name);
3999
4000             XtFree ((char *) view_set[i]->directory_name);
4001             view_set[i]->directory_name = XtNewString (new_directory_name);
4002          }
4003       }
4004    }
4005
4006
4007    /*  Update the directory cache list to remove unneeded directories.  */
4008
4009    UpdateCachedDirectories (view_set, view_count);
4010 }
4011
4012
4013
4014 /************************************************************************
4015  *
4016  *  ObserveTtNotice
4017  *      Dispatch ToolTalk events to internal handlers.
4018  *
4019  ************************************************************************/
4020
4021 static Tt_callback_action
4022 ObserveTtNotice(
4023         Tt_message msg,
4024         Tt_pattern pat
4025 )
4026 {
4027    char *op;
4028    Tt_status status;
4029
4030    op = tt_message_op( msg );
4031    status = tt_ptr_error( op );
4032    if ((status != TT_OK) || (op == 0)) {
4033       /* Let tttk_Xt_input_handler() Do The Right Thing */
4034       return TT_CALLBACK_CONTINUE;
4035    }
4036    if (strcmp( op, "DtTypes_Reloaded" ) == 0) {
4037       ReloadDatabases();
4038    } else if (strcmp( op, "XSession_Ending" ) == 0) {
4039       if( emptyTrashOnExit )
4040          TrashEmpty();
4041    } else {
4042       tt_free( op );
4043       return TT_CALLBACK_CONTINUE;
4044    }
4045    tt_free( op );
4046    tttk_message_destroy( msg );
4047    return TT_CALLBACK_PROCESSED;
4048 }
4049
4050 /************************************************************************
4051  *
4052  *  HandleTtRequest
4053  *      Dispatch ToolTalk requests to internal handlers.
4054  *
4055  ************************************************************************/
4056
4057 Tt_callback_action
4058 HandleTtRequest(
4059         Tt_message msg,
4060         Tt_pattern pat
4061 )
4062 {
4063         char *op;
4064         Tt_status status;
4065
4066         op = tt_message_op( msg );
4067         status = tt_ptr_error( op );
4068         if ((status != TT_OK) || (op == 0)) {
4069                 /* Let tttk_Xt_input_handler() Do The Right Thing */
4070                 return TT_CALLBACK_CONTINUE;
4071         }
4072         if (strcmp( op, "DtFileSession_Run" ) == 0) {
4073                 ViewSessionHandler( msg );
4074         } else if (strcmp( op, "DtFolder_Show" ) == 0) {
4075                 ViewDirectoryHandler( msg );
4076         } else if (strcmp( op, "DtHome_Show" ) == 0) {
4077                 ViewHomeDirectoryHandler( msg );
4078         } else if (strcmp( op, "DtTools_Show" ) == 0) {
4079                 ViewToolsDirectoryHandler( msg );
4080         } else if (strcmp( op, "DtTrash_Show" ) == 0) {
4081                 TrashDisplayHandler( msg );
4082         } else if (strcmp( op, "DtTrash_Remove" ) == 0) {
4083                 TrashRemoveHandler( msg );
4084         } else if (strcmp( op, "DtTrash_Empty" ) == 0) {
4085                 TrashEmptyHandler( msg );
4086         } else if (strcmp( op, "DtTrash_File" ) == 0) {
4087                 TrashRemoveNoConfirmHandler( msg );
4088     } else if (strcmp( op, "DtTrash_Restore" ) == 0) {
4089          TrashRestoreHandler( msg );
4090     } else if (strcmp( op, "DtFile_PutOnWorkspace" ) == 0) {
4091          PutOnWorkspaceHandler( msg );
4092     } else if (strcmp( op, "DtFile_Move" ) == 0) {
4093          MoveCopyLinkHandler( msg, MOVE_FILE );
4094     } else if (strcmp( op, "DtFile_Copy" ) == 0) {
4095          MoveCopyLinkHandler( msg, COPY_FILE );
4096     } else if (strcmp( op, "DtFile_Link" ) == 0) {
4097          MoveCopyLinkHandler( msg, LINK_FILE );
4098     } else {
4099          tt_free( op );
4100          return TT_CALLBACK_CONTINUE;
4101     }
4102     tt_free( op );
4103     return TT_CALLBACK_PROCESSED;
4104 }
4105
4106
4107
4108
4109 /************************************************************************
4110  *
4111  *  ViewSessionHandler
4112  *      This function is called upon the dt session  message
4113  *      being received.  The name of the session file is extracted
4114  *      out of the message and a function is called to create
4115  *      a view or set of views described by the file.
4116  *
4117  ************************************************************************/
4118
4119 static void
4120 ViewSessionHandler(
4121    Tt_message msg)
4122 {
4123    char *file = tt_message_file( msg );
4124    tt_message_reply( msg );
4125    tttk_message_destroy( msg );
4126
4127    if (! tt_is_err( tt_ptr_error( file )))
4128    {
4129       if (view_count == 0 && desktop_data->numIconsUsed == 0)
4130       {
4131            int session_flag = 0;
4132            char *session_name;
4133
4134            session_name = strrchr(file, '/');
4135            session_name++;
4136            LoadDesktopInfo(session_name);
4137            session_flag = RestoreSession (session_name, NORMAL_RESTORE, NULL);
4138            if ((session_flag != 0) && (view_count == 0))
4139            {
4140               char current_directory[MAX_PATH];
4141
4142               GetPWD(current_directory);
4143               if (current_directory[0] != NULL)
4144               {
4145                  if (!GetNewView
4146                       (home_host_name, current_directory, NULL, NULL, 0))
4147                     ViewHomeDirectoryHandler (0);
4148               }
4149               else
4150               {
4151                  ViewHomeDirectoryHandler (0);
4152               }
4153            }
4154       }
4155       else
4156       {
4157            char *tmpStr, *msg, *title;
4158
4159            tmpStr = GETMESSAGE(18, 39, "Cannot start a second File Manager session because a File Manager\nsession is already open on the desktop.  If you want to start a new File\nManager session, you must first close all current File Manager windows\nand remove all File Manager objects from the workspaces.");
4160            msg = XtNewString(tmpStr);
4161            title = XtNewString((GETMESSAGE(18,40,"Session Error")));
4162            _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
4163            XtFree(msg);
4164            XtFree(title);
4165       }
4166    }
4167    tt_free( file );
4168 }
4169
4170
4171
4172
4173 /************************************************************************
4174  *
4175  *  ViewDirectoryHandler
4176  *      This function is called upon the dt directory message
4177  *      being received.  The name of the directory is extracted
4178  *      out of the message and a function is called to create
4179  *      a view of the directory.
4180  *
4181  ************************************************************************/
4182
4183 static void
4184 ViewDirectoryHandler(
4185    Tt_message msg)
4186 {
4187    int i, j, k;
4188    char *msgFile;
4189    int numArgs;
4190
4191    initiating_view = NULL;
4192    msgFile = tt_message_file( msg );
4193    if (tt_is_err( tt_ptr_error( msgFile ))) msgFile = 0;
4194
4195    if(restrictMode)
4196    {
4197       if(msgFile && strncmp(msgFile, "~", 1) != 0 )
4198       {
4199          if((strcmp(users_home_dir, "/") != 0) &&
4200             (strncmp(msgFile, users_home_dir, strlen(users_home_dir)-1) != 0))
4201          {
4202             char *tmpStr, *errTitle, *errMsg, *dmsg;
4203
4204             tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4205             errTitle = XtNewString(tmpStr);
4206             tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4207             errMsg = XtNewString(tmpStr);
4208             dmsg = XtMalloc(strlen(errMsg)+strlen(msgFile)+1);
4209             sprintf(dmsg, errMsg, msgFile);
4210             _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4211
4212             XtFree(errTitle);
4213             XtFree(errMsg);
4214             XtFree(dmsg);
4215
4216             tt_free( msgFile );
4217             tt_message_reply( msg );
4218             tttk_message_destroy( msg );
4219             return;
4220          }
4221       }
4222    }
4223
4224    numArgs = tt_message_args_count( msg );
4225    if (tt_is_err( tt_int_error( numArgs ))) numArgs = 0;
4226    if (numArgs > 0)
4227    {
4228       special_view = True;
4229       special_treeType = UNSET_VALUE;
4230       special_treeFiles = UNSET_VALUE;
4231       special_viewType = UNSET_VALUE;
4232       special_orderType = UNSET_VALUE;
4233       special_directionType = UNSET_VALUE;
4234       special_randomType = UNSET_VALUE;
4235       special_restricted = NULL;
4236       special_title = NULL;
4237       special_helpVol = XtNewString(DTFILE_HELP_NAME);
4238       for(i = 0; i < numArgs; i++)
4239       {
4240          char *vtype;
4241          char *val;
4242          vtype = tt_message_arg_type( msg, i );
4243          if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4244             continue;
4245          }
4246          val = tt_message_arg_val( msg, i );
4247          if(strcmp(vtype, "-title") == 0)
4248          {
4249             special_title = XtNewString(val);
4250          }
4251          else if(strcmp(vtype, "-help_volume") == 0)
4252          {
4253             special_helpVol = XtNewString(val);
4254          }
4255          if(strcmp(vtype, "-tree") == 0)
4256          {
4257             DtfileStringToTree(val, &special_treeType);
4258          }
4259          else if(strcmp(vtype, "-tree_files") == 0)
4260          {
4261             DtfileStringToTreeFiles(val, &special_treeFiles);
4262          }
4263          else if(strcmp(vtype, VIEW_HEADER) == 0)
4264          {
4265             DtfileStringToView(val, &special_viewType);
4266          }
4267          else if(strcmp(vtype, "-order") == 0)
4268          {
4269             DtfileStringToOrder(val, &special_orderType);
4270          }
4271          else if(strcmp(vtype, "-direction") == 0)
4272          {
4273             DtfileStringToDirection(val, &special_directionType);
4274          }
4275          else if(strcmp(vtype, "-grid") == 0)
4276          {
4277             DtfileStringToGrid(val, &special_randomType);
4278          }
4279          else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4280          {
4281             special_restricted = XtNewString(msgFile);
4282          }
4283          tt_free( val );
4284          tt_free( vtype );
4285
4286          if ((restrictMode) && (!special_restricted))
4287          {
4288             char *ptr;
4289
4290             ptr = strrchr(users_home_dir, '/');
4291             *ptr = '\0';
4292             special_restricted = XtNewString(users_home_dir);
4293             *ptr = '/';
4294          }
4295       }
4296    }
4297    else if (restrictMode)
4298    {
4299      char *ptr;
4300
4301      special_view = True;
4302      special_treeType = treeType;
4303      special_treeFiles = treeFiles;
4304      special_viewType = viewType;
4305      special_orderType = orderType;
4306      special_directionType = directionType;
4307      special_randomType = randomType;
4308
4309      ptr = strrchr(users_home_dir, '/');
4310      *ptr = '\0';
4311      special_restricted = XtNewString(users_home_dir);
4312      *ptr = '/';
4313
4314      special_title = NULL;
4315      special_helpVol = XtNewString(DTFILE_HELP_NAME);
4316
4317    }
4318    else
4319       special_view = False;
4320
4321    OpenDirectories (msgFile, NULL);
4322
4323    tt_free( msgFile );
4324    tt_message_reply( msg );
4325    tttk_message_destroy( msg );
4326 }
4327
4328
4329
4330
4331 /************************************************************************
4332  *
4333  *  ViewDirectoryProc
4334  *      This function is called upon the dt directory message
4335  *      being received.  The name of the directory is extracted
4336  *      out of the message and a function is called to create
4337  *      a view of the directory.  This function is passed directly
4338  *      to DtActionInvoke to be used as a callback.
4339  *
4340  ************************************************************************/
4341
4342 DialogData *
4343 ViewDirectoryProc(
4344    char* root_dir,
4345    int restricted,
4346    Tt_message msg
4347 )
4348 {
4349    DialogData *return_data;
4350
4351    if(restrictMode)
4352    {
4353       if(root_dir && strncmp(root_dir, "~", 1) != 0 )
4354       {
4355          if((strcmp(users_home_dir, "/") != 0) &&
4356             (strncmp(root_dir, users_home_dir, strlen(users_home_dir)-1) != 0))
4357          {
4358             char *tmpStr, *errTitle, *errMsg, *dmsg;
4359
4360             tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4361             errTitle = XtNewString(tmpStr);
4362             tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4363             errMsg = XtNewString(tmpStr);
4364             dmsg = XtMalloc(strlen(errMsg)+strlen(root_dir)+1);
4365             sprintf(dmsg, errMsg, root_dir);
4366             _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4367
4368             XtFree(errTitle);
4369             XtFree(errMsg);
4370             XtFree(dmsg);
4371             return;
4372          }
4373       }
4374    }
4375
4376    initiating_view = NULL;
4377    special_view = True;
4378    special_treeType = treeType;
4379    special_treeFiles = treeFiles;
4380    special_viewType = viewType;
4381    special_orderType = orderType;
4382    special_directionType = directionType;
4383    special_randomType = randomType;
4384
4385    if (restricted) {
4386      special_restricted = XtNewString(root_dir);
4387    }
4388    else {
4389      special_restricted = NULL;
4390    }
4391
4392    if ((restrictMode) && (!special_restricted))
4393    {
4394       char *ptr;
4395
4396       ptr = strrchr(users_home_dir, '/');
4397       *ptr = '\0';
4398       special_restricted = XtNewString(users_home_dir);
4399       *ptr = '/';
4400    }
4401
4402    special_title = NULL;
4403    special_helpVol = XtNewString(DTFILE_HELP_NAME);
4404
4405    return_data = GetNewView (home_host_name, root_dir, NULL, NULL, msg);
4406
4407    if ((!return_data) && msg)
4408    {
4409       tt_message_reply(msg);
4410       tttk_message_destroy( msg );
4411    }
4412
4413    return(return_data);
4414 }
4415
4416
4417
4418 /************************************************************************
4419  *
4420  *  ViewHomeDirectoryHandler
4421  *      This function is called upon the dt home directory message
4422  *      being received.  The home directory is extracted from the
4423  *      users uid and used to open the directory.
4424  *
4425  ************************************************************************/
4426
4427
4428 static void
4429 ViewHomeDirectoryHandler(
4430    Tt_message msg)
4431 {
4432    register int i, j, k;
4433    struct passwd * pwInfo;
4434    char * homeDir;
4435    char * tmp_path;
4436    char full_path[MAX_PATH + 1];
4437    struct stat stat_buf;
4438    int numArgs;
4439
4440    /* We have a new view so set initiating_view to null */
4441    initiating_view = NULL;
4442
4443    if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
4444    {
4445       pwInfo = getpwuid (getuid());
4446       homeDir = pwInfo->pw_dir;
4447    }
4448
4449    /* Look and see if we have a default environment file present */
4450    tmp_path = _DtCreateDtDirs(display);
4451
4452    numArgs = 0;
4453    if (msg) numArgs = tt_message_args_count(msg);
4454    if (tt_is_err(tt_int_error(numArgs))) numArgs = 0;
4455    if (numArgs > 0)
4456    {
4457       special_view = True;
4458       special_treeType = UNSET_VALUE;
4459       special_treeFiles = UNSET_VALUE;
4460       special_viewType = UNSET_VALUE;
4461       special_orderType = UNSET_VALUE;
4462       special_directionType = UNSET_VALUE;
4463       special_randomType = UNSET_VALUE;
4464       special_restricted = NULL;
4465       special_title = NULL;
4466       special_helpVol = XtNewString(DTFILE_HELP_NAME);
4467       for(i = 0; i < numArgs; i++)
4468       {
4469          char *vtype;
4470          char *val;
4471          vtype = tt_message_arg_type( msg, i );
4472          if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4473             continue;
4474          }
4475          val = tt_message_arg_val(msg, i);
4476          if(strcmp(vtype, "-title") == 0)
4477          {
4478             special_title = XtNewString(val);
4479          }
4480          else if(strcmp(vtype, "-help_volume") == 0)
4481          {
4482             special_helpVol = XtNewString(val);
4483          }
4484          if(strcmp(vtype, "-tree") == 0)
4485          {
4486             DtfileStringToTree(val, &special_treeType);
4487          }
4488          else if(strcmp(vtype, "-tree_files") == 0)
4489          {
4490             DtfileStringToTreeFiles(val, &special_treeFiles);
4491          }
4492          else if(strcmp(vtype, VIEW_HEADER) == 0)
4493          {
4494             DtfileStringToView(val, &special_viewType);
4495          }
4496          else if(strcmp(vtype, "-order") == 0)
4497          {
4498             DtfileStringToOrder(val, &special_orderType);
4499          }
4500          else if(strcmp(vtype, "-direction") == 0)
4501          {
4502             DtfileStringToDirection(val, &special_directionType);
4503          }
4504          else if(strcmp(vtype, "-grid") == 0)
4505          {
4506             DtfileStringToGrid(val, &special_randomType);
4507          }
4508          else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4509          {
4510             special_restricted = XtNewString(val);
4511          }
4512          tt_free( val );
4513          tt_free( vtype );
4514       }
4515    }
4516    else if (restrictMode)
4517    {
4518      char *ptr;
4519
4520      special_view = True;
4521      special_treeType = treeType;
4522      special_treeFiles = treeFiles;
4523      special_viewType = viewType;
4524      special_orderType = orderType;
4525      special_directionType = directionType;
4526      special_randomType = randomType;
4527
4528      ptr = strrchr(users_home_dir, '/');
4529      *ptr = '\0';
4530      special_restricted = XtNewString(users_home_dir);
4531      *ptr = '/';
4532
4533      special_title = NULL;
4534      special_helpVol = XtNewString(DTFILE_HELP_NAME);
4535    }
4536    else
4537       special_view = False;
4538
4539    if (tmp_path == NULL)
4540       OpenDirectories (homeDir, NULL);
4541    else
4542    {
4543      sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
4544      XtFree(tmp_path);
4545
4546      /* Stat the file and make sure its there */
4547      if(numArgs > 0)
4548      {
4549         if (stat (full_path, &stat_buf) == 0 && numArgs < 1)
4550         {
4551            restoreType = HOME_RESTORE;
4552            RestoreSession(full_path, HOME_RESTORE, NULL);
4553            restoreType = NORMAL_RESTORE;
4554         }
4555         else
4556         {
4557            char *ptr;
4558
4559            ptr = strrchr(users_home_dir, '/');
4560            *ptr = '\0';
4561            strcpy(full_path, users_home_dir);
4562            *ptr = '/';
4563            OpenDirectories (full_path, NULL);
4564         }
4565      }
4566      else if (numArgs < 1 && stat (full_path, &stat_buf) == 0)
4567      {
4568         restoreType = HOME_RESTORE;
4569         RestoreSession(full_path, HOME_RESTORE, NULL);
4570         restoreType = NORMAL_RESTORE;
4571      }
4572      else
4573      {
4574        char *ptr;
4575
4576        ptr = strrchr(users_home_dir, '/');
4577
4578        if( ptr != users_home_dir )
4579          *ptr = '\0';
4580
4581        strcpy(full_path, users_home_dir);
4582        *ptr = '/';
4583
4584        OpenDirectories (full_path, NULL);
4585      }
4586    }
4587
4588    if(msg)
4589    {
4590      tt_message_reply(msg);
4591      tttk_message_destroy(msg);
4592    }
4593 }
4594
4595 /************************************************************************
4596  *
4597  *  ViewToolsDirectroyHandler
4598  *      This function is called upon the dt tools message
4599  *      being received.  The names of the tools directories are
4600  *      retrieved from libXue, a view is created and the change
4601  *      directory dialog for the view is displayed with the
4602  *      set of directories contained in the list.
4603  *
4604  ************************************************************************/
4605
4606 static void
4607 ViewToolsDirectoryHandler(
4608    Tt_message msg)
4609 {
4610    register int i;
4611    char * tmp_path = NULL;
4612    char * tool_dir = NULL;
4613    char * msgFile = NULL;
4614    int numArgs = 0;
4615
4616    /* We have a new view so set initiating_view to null */
4617    initiating_view = NULL;
4618
4619    /* Look and see if we have a default environment file present */
4620    tmp_path = _DtCreateDtDirs(display);
4621
4622    if (msg) msgFile = tt_message_file(msg);
4623    if (tt_is_err(tt_ptr_error(msgFile))) msgFile = 0;
4624
4625    if (msg) numArgs = tt_message_args_count(msg);
4626    if (tt_is_err(tt_int_error( numArgs ))) numArgs = 0;
4627
4628    if(msgFile != NULL)
4629    {
4630       if(numArgs > 0)
4631       {
4632          char *link_point = NULL;
4633          char *root_toolbox = NULL;
4634          char *user_install_point = NULL;
4635
4636          special_view = True;
4637          special_treeType = treeType;
4638          special_treeFiles = treeFiles;
4639          special_viewType = viewType;
4640          special_orderType = orderType;
4641          special_directionType = directionType;
4642          special_randomType = randomType;
4643          special_restricted = XtNewString(msgFile);
4644          special_title = NULL;
4645          special_helpVol = XtNewString(DTFILE_HELP_NAME);
4646          for(i = 0; i < numArgs; i++)
4647          {
4648             char *vtype;
4649             char *val;
4650             vtype = tt_message_arg_type( msg, i );
4651             if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4652                continue;
4653             }
4654             val = tt_message_arg_val( msg, i );
4655             if(strcmp(vtype, "-title") == 0)
4656             {
4657                special_title = XtNewString(val);
4658             }
4659             else if(strcmp(vtype, "-help_volume") == 0)
4660             {
4661                special_helpVol = XtNewString(val);
4662             }
4663             else if(strcmp(vtype, "-root") == 0)
4664             {
4665                root_toolbox = XtNewString(val);
4666             }
4667             else if(strcmp(vtype, "-common_link_point") == 0)
4668             {
4669                link_point = XtNewString(val);
4670             }
4671             else if(strcmp(vtype, "-user_install_point") == 0)
4672             {
4673                user_install_point = XtNewString(val);
4674             }
4675             if(strcmp(vtype, "-tree") == 0)
4676             {
4677                DtfileStringToTree(val, &special_treeType);
4678             }
4679             else if(strcmp(vtype, "-tree_files") == 0)
4680             {
4681                DtfileStringToTreeFiles(val, &special_treeFiles);
4682             }
4683             else if(strcmp(vtype, VIEW_HEADER) == 0)
4684             {
4685                DtfileStringToView(val, &special_viewType);
4686             }
4687             else if(strcmp(vtype, "-order") == 0)
4688             {
4689                DtfileStringToOrder(val, &special_orderType);
4690             }
4691             else if(strcmp(vtype, "-direction") == 0)
4692             {
4693                DtfileStringToDirection(val, &special_directionType);
4694             }
4695             else if(strcmp(vtype, "-grid") == 0)
4696             {
4697                DtfileStringToGrid(val, &special_randomType);
4698             }
4699             else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4700             {
4701                ;
4702             }
4703             tt_free( val );
4704             tt_free( vtype );
4705          }
4706          /* Due to the use of tooltalk messaging, app manager objects
4707             that are dragged either to the desktop or to the front
4708             panel are identified by their fully resolved names (ie.
4709             /usr/dt/appconfig/appmanager/$LANG/.... as opposed to
4710             /var/dt/appconfig/appmanager/$DTUSERSESSION/....).  In order
4711             for the File Manager to treat these objects as links existing
4712             in the /var/.... directory, we use the following ugly code:
4713
4714               1. Search the incoming path for $LANG (if you can't find
4715                  $LANG, try C since this is the default).
4716               2. Concatenate the path following $LANG to the path for the
4717                  root toolbox (this comes in with the tooltalk message
4718                  so that we don't have to hardcode it).
4719               3. Call OpenDirectories with the new path that you have
4720                  created and with the root toolbox path as the restricted
4721                  directory.
4722
4723             This problem is further complicated by:
4724               1. Users traversing into APPGROUPs.
4725               2. Users opening the parent folders for workspace APPGROUPs.
4726
4727             For situation 1, File Manager kicks the user into the App Manager
4728             if he/she traverses into an APPGROUP.  BUT we don't want to
4729             make modifications to the path as we do above.
4730             So, if there is nothing following $LANG or if we can't find
4731             $LANG in the path,
4732             (ie. /var/dt/appconfig/appmanager/$DTUSERSESSION), call
4733             OpenDirectories with no parameter changes.
4734
4735             For situation 2, File Manager is unable to distinguish between
4736             workspace objects dragged from /usr/.... or /var/...., so
4737             the parent folder for all workspace APPGROUPS is considered to
4738             be in the /var path.  In addition to the OpenAppGroup action,
4739             there is an OpenParentAppGroup action which also triggers
4740             ViewToolsDirectoryHandler but sends in an additional
4741             parameter (user_install_point).
4742             If we know that this msg was generated by the OpenParentAppGroup
4743             action
4744             AND nothing follows $LANG.
4745               Modify the parameters as above.
4746             OR we can't find $LANG but we can find the user_install_point
4747               (user's personal appgroup path).
4748               Concatenate the path following .dt/appmanager to the path for the
4749               root toolbox. Call OpenDirectories with the new path and the
4750               root toolbox as the restricted directory.
4751          */
4752          if( root_toolbox )
4753          {
4754             if( link_point )
4755             {
4756                char *ptr;
4757
4758                if ((user_install_point) &&
4759                    (ptr = strstr(msgFile, user_install_point)))
4760                {
4761                   ptr += strlen(user_install_point);
4762                   tool_dir = XtMalloc(strlen(root_toolbox) + strlen(ptr) + 1);
4763                   sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4764                   XtFree(special_restricted);
4765                   special_restricted = XtNewString(root_toolbox);
4766                }
4767                else
4768                {
4769                   ptr = strstr(msgFile, link_point);
4770
4771                   if (!ptr)
4772                   {
4773                      XtFree(link_point);
4774                      link_point = XtNewString("C");
4775                      ptr = strstr(msgFile, link_point);
4776                   }
4777
4778                   if (ptr)
4779                   {
4780                      ptr += strlen(link_point);
4781                      if (strcmp(ptr, "") != 0)
4782                      {
4783                         tool_dir = XtMalloc(strlen(root_toolbox) +
4784                                             strlen(ptr) + 1);
4785                         sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4786                         XtFree(special_restricted);
4787                         special_restricted = XtNewString(root_toolbox);
4788                      }
4789                      else if (user_install_point)
4790                      {
4791                         tool_dir = XtNewString(root_toolbox);
4792                         XtFree(special_restricted);
4793                         special_restricted = XtNewString(root_toolbox);
4794                      }
4795                   }
4796                }
4797             }
4798          }
4799          XtFree(link_point);
4800          XtFree(root_toolbox);
4801          XtFree(user_install_point);
4802       }
4803       else if (restrictMode)
4804       {
4805          char *ptr;
4806
4807          special_view = True;
4808          ptr = strrchr(users_home_dir, '/');
4809          *ptr = '\0';
4810          special_restricted = XtNewString(users_home_dir);
4811          *ptr = '/';
4812       }
4813       else
4814          special_view = False;
4815    }
4816
4817    if (tmp_path == NULL)
4818    {
4819       if (tool_dir)
4820          OpenDirectories (tool_dir, special_restricted);
4821       else if (msgFile != NULL)
4822          OpenDirectories (msgFile, special_restricted);
4823    }
4824    else
4825    {
4826       char full_path[MAX_PATH + 1];
4827       struct stat stat_buf;
4828
4829       sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
4830       XtFree(tmp_path);
4831
4832       /* Stat the file and make sure its there */
4833       if (stat (full_path, &stat_buf) == 0 && numArgs > 0)
4834       {
4835          DialogData * dialog_data;
4836          FileMgrData * file_mgr_data;
4837
4838          restoreType = TOOL_RESTORE;
4839          if (tool_dir)
4840             RestoreSession(full_path, TOOL_RESTORE, tool_dir);
4841          else
4842             RestoreSession(full_path, TOOL_RESTORE, msgFile);
4843          dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
4844          file_mgr_data = (FileMgrData *) dialog_data->data;
4845          application_args.tool_width = file_mgr_data->width;
4846          application_args.tool_height = file_mgr_data->height;
4847          restoreType = NORMAL_RESTORE;
4848       }
4849       else
4850       {
4851          if (tool_dir)
4852             OpenDirectories (tool_dir, special_restricted);
4853          else if (msgFile != NULL)
4854             OpenDirectories (msgFile, special_restricted);
4855       }
4856    }
4857
4858    if( msgFile )
4859      tt_free( msgFile );
4860
4861    if( msg )
4862    {
4863      tt_message_reply( msg );
4864      tttk_message_destroy( msg );
4865    }
4866
4867    if (tool_dir)
4868       XtFree(tool_dir);
4869 }
4870
4871
4872 /************************************************************************
4873  *
4874  *  ExitHandler
4875  *      This function is called upon the DtSTOP message.
4876  *
4877  ************************************************************************/
4878
4879 static void
4880 ExitHandler(
4881    Tt_message msg,
4882    XtPointer clientData,
4883    String * messageFields,
4884    int numFields)
4885 {
4886    tt_message_reply( msg );
4887    tttk_message_destroy( msg );
4888    FinalizeToolTalkSession( );
4889    exit(0);
4890 }
4891
4892
4893 /*
4894  * This is the message handling function responsible for reloading
4895  * the filetype and action databases, and then updating our collection
4896  * of action menu items, and updating all open views.
4897  */
4898
4899 static void
4900 ReloadDatabases(void)
4901 {
4902    int i;
4903    DialogData * dialog_data;
4904    FileMgrData * file_mgr_data;
4905    FileMgrRec  * file_mgr_rec;
4906    FileViewData *file_view_data;
4907    DesktopRec *desktopWindow;
4908
4909    DtDbLoad();
4910
4911    XmeFlushIconFileCache ( NULL );
4912
4913    /* Update each directory_set view, both mapped and not */
4914    UpdateDirectorySet();
4915
4916    /* Force action menus to update the next time they're posted */
4917    XtFree(fileMgrPopup.action_pane_file_type);
4918    fileMgrPopup.action_pane_file_type = NULL;
4919    XtFree(desktop_data->popupMenu->action_pane_file_type);
4920    desktop_data->popupMenu->action_pane_file_type = NULL;
4921
4922    /* Update each view */
4923    for (i = 0; i < view_count; i++)
4924    {
4925       dialog_data = (DialogData *)view_set[i]->dialog_data;
4926       file_mgr_data = (FileMgrData *) dialog_data->data;
4927       file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
4928       XtFree(file_mgr_rec->action_pane_file_type);
4929       file_mgr_rec->action_pane_file_type = NULL;
4930       UpdateFilterAfterDBReread(file_mgr_data->filter_active);
4931       UpdateFilterAfterDBReread(file_mgr_data->filter_edit);
4932       FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
4933    }
4934
4935    /* go through the desktop objects to make sure the icons change
4936     * Do this by setting the logical_type to -l, CheckDesktop will
4937     * then update the logical type and the icon
4938     */
4939    for(i = 0; i < desktop_data->numIconsUsed; i++)
4940    {
4941       desktopWindow = desktop_data->desktopWindows[i];
4942       file_view_data = desktopWindow->file_view_data;
4943
4944       file_view_data->file_data->logical_type = NULL;
4945    }
4946    CheckDesktop();
4947 }
4948
4949
4950 /*
4951  * Whenever a directory view or drawer view is closed, we need to remove
4952  * any of its text field children, so that they will not magically reappear
4953  * should this view be reused from the cache to view the same directory later.
4954  */
4955
4956 static void
4957 RemoveTextFields (
4958    XtPointer client_data,
4959    DialogData * old_dialog_data,
4960    DialogData * new_dialog_data)
4961 {
4962    FileMgrRec * file_mgr_rec;
4963    XmManagerWidget file_window;
4964    int i;
4965    int num_children;
4966
4967    file_mgr_rec = (FileMgrRec *) _DtGetDialogInstance(old_dialog_data);
4968    file_window = (XmManagerWidget) file_mgr_rec->file_window;
4969    num_children = file_window->composite.num_children;
4970
4971    for (i = 0; i < num_children; i++)
4972    {
4973       if (XmIsTextField(file_window->composite.children[i]))
4974          XtDestroyWidget(file_window->composite.children[i]);
4975    }
4976
4977    _DtFreeDialogData (new_dialog_data);
4978 }
4979
4980
4981 /*
4982  * This function searches the view list, and returns the file_mgr_data
4983  * associated with the passed-in widget.
4984  */
4985
4986 FileMgrData *
4987 ReturnDesktopPtr (
4988    Widget w)
4989 {
4990    int i;
4991    DialogData * dialog_data;
4992    FileMgrData * file_mgr_data;
4993
4994    for (i = 0; i < view_count; i++)
4995    {
4996       dialog_data = (DialogData *) view_set[i]->dialog_data;
4997       file_mgr_data = (FileMgrData *) dialog_data->data;
4998
4999       if (w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->file_window ||
5000           w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->shell)
5001          return(file_mgr_data);
5002    }
5003
5004    return(NULL);
5005 }
5006
5007
5008 PixmapData *
5009 CheckForOpenDirectory(
5010      FileViewData *order_list,
5011      DirectorySet *directory_set,
5012      FileMgrData *file_mgr_data,
5013      char * logical_type)
5014 {
5015    int i;
5016    char *ptr;
5017    char *file_type_name, *new_file_type_name;
5018    char directory_name[MAX_PATH];
5019    char * real_dir_name;
5020    FileMgrRec *file_mgr_rec;
5021    int icon_size;
5022    PixmapData *pixmapData = NULL;
5023
5024    if (file_mgr_data->view == BY_NAME_AND_ICON)
5025      icon_size = LARGE;
5026    else
5027      icon_size = SMALL;
5028
5029    file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5030
5031    if (strcmp (directory_set->name, "/") != 0)
5032      sprintf( directory_name, "%s/%s", directory_set->name, order_list->file_data->file_name);
5033    else
5034      sprintf( directory_name, "%s%s", directory_set->name, order_list->file_data->file_name );
5035
5036    (void) DtEliminateDots (directory_name);
5037
5038    real_dir_name = XtNewString(directory_name);
5039
5040    for(i = 0; i < view_count; i++)
5041    {
5042       if(strcmp(real_dir_name, view_set[i]->directory_name) == 0)
5043       {
5044          file_type_name = order_list->file_data->logical_type;
5045          new_file_type_name = (char *)XtMalloc(strlen(file_type_name)
5046                                                + strlen(ICON_OPEN_PREFIX) + 1);
5047          sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5048          pixmapData = _DtRetrievePixmapData(new_file_type_name,
5049                                             NULL,
5050                                             NULL,
5051                                             file_mgr_rec->file_window,
5052                                             icon_size);
5053          XtFree(new_file_type_name);
5054          break;
5055       }
5056    }
5057    XtFree(real_dir_name);
5058
5059    if(pixmapData == NULL || pixmapData->iconFileName == NULL)
5060    {
5061      if( pixmapData != NULL )
5062      {
5063        DtDtsFreeAttributeValue(pixmapData->hostPrefix);
5064        DtDtsFreeAttributeValue(pixmapData->instanceIconName);
5065        DtDtsFreeAttributeValue(pixmapData->iconName);
5066        XtFree((char *)pixmapData);
5067      }
5068
5069        pixmapData = _DtRetrievePixmapData(logical_type,
5070                                           NULL,
5071                                           NULL,
5072                                           file_mgr_rec->file_window,
5073                                           icon_size);
5074    }
5075
5076    return(pixmapData);
5077 }
5078
5079
5080 /*
5081  * The is the menu callback function for cleaning up a view.
5082  */
5083
5084 void
5085 CleanUp (
5086    Widget w,
5087    XtPointer client_data,
5088    XtPointer call_data)
5089 {
5090    Widget mbar;
5091    Arg args[2];
5092    FileMgrRec * file_mgr_rec;
5093    DialogData * dialog_data;
5094    FileMgrData * file_mgr_data;
5095    int i, j;
5096    XmManagerWidget file_window;
5097    char * name;
5098    FileViewData * file_view_data;
5099    XRectangle textExtent;
5100    Position x, y;
5101
5102    if ((int) client_data == FM_POPUP)
5103      mbar = XtParent(w);
5104    else
5105      mbar = XmGetPostedFromWidget(XtParent(w));
5106
5107    XmUpdateDisplay(w);
5108    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
5109    XtGetValues(mbar, args, 1);
5110
5111    /* Ignore accelerators when we're insensitive */
5112    if ((file_mgr_rec->menuStates & CLEAN_UP) == 0)
5113       return;
5114
5115    /* Ignore accelerators received after we're unposted */
5116    if ((dialog_data = _DtGetInstanceData((XtPointer)file_mgr_rec)) == NULL)
5117       return;
5118
5119    file_mgr_data = (FileMgrData *)dialog_data->data;
5120
5121    /* Reset the grid size, so it will be recalculated later. */
5122    file_mgr_data->grid_height = 0;
5123    file_mgr_data->grid_width = 0;
5124
5125    if(file_mgr_data->object_positions)
5126       FreePositionInfo(file_mgr_data);
5127
5128    /* CLEAN_UP_OP is not really a menu state.
5129       It's a flag to let GetFileData in FileMgr.c (call when the directory
5130       is being reread) not to reload icon positions from the .!dt<userid> file.
5131    */
5132    file_mgr_rec->menuStates |= CLEAN_UP_OP;
5133
5134    /* Re-layout the view */
5135    FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
5136
5137    if ((file_mgr_data->show_type == SINGLE_DIRECTORY) &&
5138         (file_mgr_data->view != BY_ATTRIBUTES) &&
5139         (file_mgr_data->positionEnabled == RANDOM_ON))
5140    {
5141       ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5142           RANDOM_ON;
5143    }
5144    else
5145    {
5146       /* Update the preferences dialog */
5147       ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5148           RANDOM_OFF;
5149    }
5150
5151    /* Move any text widget, to keep them in sync with their icons */
5152    file_window = (XmManagerWidget)file_mgr_rec->file_window;
5153
5154    for (j = 0; j < file_window->composite.num_children; j++)
5155    {
5156       if (XmIsTextField(file_window->composite.children[j]) &&
5157           !file_window->composite.children[j]->core.being_destroyed)
5158       {
5159          XtSetArg(args[0], XmNuserData, &name);
5160          XtGetValues(file_window->composite.children[j], args, 1);
5161
5162          /* Find the associated icon data */
5163          /* @@@ this won't work for tree mode! */
5164          for (i = 0; i < file_mgr_data->directory_set[0]->file_count; i++)
5165          {
5166             file_view_data = file_mgr_data->directory_set[0]->file_view_data[i];
5167             if (strcmp(name, file_view_data->file_data->file_name) == 0)
5168             {
5169                _DtIconGetTextExtent_r(file_view_data->widget, &textExtent);
5170                x = textExtent.x;
5171                y = textExtent.y -
5172                    (Dimension)(file_window->composite.children[j]->core.height -
5173                     textExtent.height)/(Dimension)2;
5174                XtSetArg (args[0], XmNx, x);
5175                XtSetArg (args[1], XmNy, y);
5176                XtSetValues (file_window->composite.children[j], args, 2);
5177                break;
5178             }
5179          }
5180       }
5181    }
5182
5183    if ((file_mgr_rec->menuStates & CLEAN_UP_OP))
5184      file_mgr_rec->menuStates  &= ~CLEAN_UP_OP;
5185 }
5186
5187 /*************************************<->*************************************
5188  *
5189  *  DtfileCvtStringToObjPlace (args, numArgs, fromVal, toVal)
5190  *
5191  *
5192  *  Description:
5193  *  -----------
5194  *  This function converts a string to an desktop placement scheme description.
5195  *
5196  *
5197  *  Inputs:
5198  *  ------
5199  *  args = NULL (don't care)
5200  *
5201  *  numArgs = 0 (don't care)
5202  *
5203  *  fromVal = resource value to convert
5204  *
5205  *
5206  *  Outputs:
5207  *  -------
5208  *  toVal = descriptor to use to return converted value
5209  *
5210  *************************************<->***********************************/
5211
5212 static void
5213 DtfileCvtStringToObjPlace (
5214           XrmValue *args,
5215           Cardinal numArgs,
5216           XrmValue *fromVal,
5217           XrmValue *toVal)
5218 {
5219     unsigned char       *pch = (unsigned char *) (fromVal->addr);
5220     unsigned char       *pchNext;
5221     int         len;
5222     static long cval;
5223     char tmp[2];
5224     Boolean     fPrimarySet = False;
5225     Boolean     fSecondarySet = False;
5226
5227 /*
5228  * Icon placement layout values:
5229  */
5230
5231 #define OBJ_PLACE_BOTTOM_STR           (unsigned char *)"bottom"
5232 #define OBJ_PLACE_LEFT_STR             (unsigned char *)"left"
5233 #define OBJ_PLACE_RIGHT_STR            (unsigned char *)"right"
5234 #define OBJ_PLACE_TOP_STR              (unsigned char *)"top"
5235
5236
5237     /*
5238      * Convert the icon placement resource value:
5239      */
5240
5241     cval = 0;
5242
5243     while (*pch && _DtNextToken (pch, &len, &pchNext))
5244     {
5245         tmp[0] = pch[len];
5246         pch[len] = '\0';
5247         switch( *pch )
5248         {
5249             case 'B':
5250             case 'b':
5251                 if (_DtStringsAreEquivalent((char *)pch, (char *)OBJ_PLACE_BOTTOM_STR))
5252                 {
5253                   if (!fPrimarySet)
5254                   {
5255                     cval |= OBJ_PLACE_BOTTOM_PRIMARY;
5256                     fPrimarySet = True;
5257                   }
5258                   else if (!fSecondarySet)
5259                   {
5260                     if (!(cval &
5261                           (OBJ_PLACE_BOTTOM_PRIMARY | OBJ_PLACE_TOP_PRIMARY)))
5262                     {
5263                       cval |= OBJ_PLACE_BOTTOM_SECONDARY;
5264                       fSecondarySet = True;
5265                     }
5266                   }
5267                 }
5268                 break;
5269
5270
5271             case 'L':
5272             case 'l':
5273                 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_LEFT_STR))
5274                 {
5275                   if (!fPrimarySet)
5276                   {
5277                     cval |= OBJ_PLACE_LEFT_PRIMARY;
5278                     fPrimarySet = True;
5279                   }
5280                   else if (!fSecondarySet)
5281                   {
5282                     if (!(cval &
5283                           (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY)))
5284                     {
5285                       cval |= OBJ_PLACE_LEFT_SECONDARY;
5286                       fSecondarySet = True;
5287                     }
5288                   }
5289                 }
5290                 break;
5291
5292             case 'R':
5293             case 'r':
5294                 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_RIGHT_STR))
5295                 {
5296                   if (!fPrimarySet)
5297                   {
5298                     cval |= OBJ_PLACE_RIGHT_PRIMARY;
5299                     fPrimarySet = True;
5300                   }
5301                   else if (!fSecondarySet)
5302                   {
5303                     if (!(cval &
5304                           (OBJ_PLACE_RIGHT_PRIMARY | OBJ_PLACE_LEFT_PRIMARY)))
5305                     {
5306                       cval |= OBJ_PLACE_RIGHT_SECONDARY;
5307                       fSecondarySet = True;
5308                     }
5309                   }
5310                 }
5311                 break;
5312
5313             case 'T':
5314             case 't':
5315                 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_TOP_STR))
5316                 {
5317                   if (!fPrimarySet)
5318                   {
5319                     cval |= OBJ_PLACE_TOP_PRIMARY;
5320                     fPrimarySet = True;
5321                   }
5322                   else if (!fSecondarySet)
5323                   {
5324                     if (!(cval &
5325                           (OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_BOTTOM_PRIMARY)))
5326                     {
5327                       cval |= OBJ_PLACE_TOP_SECONDARY;
5328                       fSecondarySet = True;
5329                     }
5330                   }
5331                 }
5332
5333                 break;
5334         }
5335         pch[len] = tmp[0];
5336         pch = pchNext;
5337     }
5338
5339     if (!fPrimarySet)
5340     {
5341         cval =  OBJ_PLACE_TOP_PRIMARY;
5342     }
5343     if (!fSecondarySet)
5344     {
5345         if (cval & (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY))
5346         {
5347             cval |= OBJ_PLACE_TOP_SECONDARY;
5348         }
5349         else        {
5350             cval |= OBJ_PLACE_RIGHT_SECONDARY;
5351         }
5352     }
5353
5354
5355     (*toVal).size = sizeof (long);
5356     (*toVal).addr = (XtPointer) &cval;
5357
5358 } /* END OF FUNCTION DtfileCvtStringToObjPlace */
5359
5360 /*************************************<->*************************************
5361  *
5362  *  _DtNextToken (pchIn, pLen, ppchNext)
5363  *
5364  *
5365  *  Description:
5366  *  -----------
5367  *  XXDescription ...
5368  *
5369  *
5370  *  Inputs:
5371  *  ------
5372  *  pchIn = pointer to start of next token
5373  *
5374  *
5375  *  Outputs:
5376  *  -------
5377  *  pLen  =    pointer to integer containing number of characters in next token
5378  *  ppchNext = address of pointer to following token
5379  *
5380  *  Return =   next token or NULL
5381  *
5382  *
5383  *  Comments:
5384  *  --------
5385  *  None.
5386  *
5387  *************************************<->***********************************/
5388
5389 static unsigned char
5390 *_DtNextToken (
5391         unsigned char *pchIn,
5392         int *pLen,
5393         unsigned char **ppchNext)
5394 {
5395     unsigned char *pchR = pchIn;
5396     register int   i;
5397 #ifdef MULTIBYTE
5398     register int   chlen;
5399
5400     for (i = 0; ((chlen = mblen ((char *)pchIn, MB_CUR_MAX)) > 0); i++)
5401     /* find end of word: requires singlebyte whitespace terminator */
5402     {
5403         if ((chlen == 1) && isspace (*pchIn))
5404         {
5405             break;
5406         }
5407         pchIn += chlen;
5408     }
5409
5410 #else
5411     for (i = 0; *pchIn && !isspace (*pchIn); i++, pchIn++)
5412     /* find end of word */
5413     {
5414     }
5415 #endif
5416
5417     /* skip to next word */
5418 #ifdef MULTIBYTE
5419     while (pchIn && (mblen ((char *)pchIn, MB_CUR_MAX) == 1) && isspace (*pchIn))
5420 #else
5421     while (pchIn && isspace (*pchIn))
5422 #endif
5423     {
5424         *pchIn++;
5425     }
5426
5427     *ppchNext = pchIn;
5428     *pLen = i;
5429     if (i)
5430     {
5431         return(pchR);
5432     }
5433     else
5434     {
5435        return(NULL);
5436     }
5437
5438 } /* END OF FUNCTION _DtNextToken */
5439
5440 /*************************************<->*************************************
5441  *
5442  *  DtfileCvtStringToOpenDir (args, numArgs, fromVal, toVal)
5443  *
5444  *
5445  *  Description:
5446  *  -----------
5447  *  This function converts a string to an desktop placement scheme description.
5448  *
5449  *
5450  *  Inputs:
5451  *  ------
5452  *  args = NULL (don't care)
5453  *
5454  *  numArgs = 0 (don't care)
5455  *
5456  *  fromVal = resource value to convert
5457  *
5458  *
5459  *  Outputs:
5460  *  -------
5461  *  toVal = descriptor to use to return converted value
5462  *
5463  *************************************<->***********************************/
5464
5465 static void
5466 DtfileCvtStringToOpenDir (
5467           XrmValue *args,
5468           Cardinal numArgs,
5469           XrmValue *fromVal,
5470           XrmValue *toVal)
5471 {
5472    char * in_str = (char *) (fromVal->addr);
5473    static int i;
5474
5475    toVal->size = sizeof (int);
5476    toVal->addr = (XtPointer) &i;
5477
5478    if (_DtStringsAreEquivalent (in_str, "current"))
5479       i = CURRENT;
5480    else if (_DtStringsAreEquivalent (in_str, "new"))
5481       i = NEW;
5482    else
5483       i = CURRENT;
5484 /*
5485    else
5486    {
5487       toVal->size = 0;
5488       toVal->addr = NULL;
5489       XtStringConversionWarning ((char *)fromVal->addr, "OpenDir");
5490    }
5491 */
5492 }
5493
5494 /*************************************<->*************************************
5495  *
5496  *  DtfileCvtStringToDTIcon (args, numArgs, fromVal, toVal)
5497  *
5498  *
5499  *  Description:
5500  *  -----------
5501  *  This function converts a string to an desktop placement scheme description.
5502  *
5503  *
5504  *  Inputs:
5505  *  ------
5506  *  args = NULL (don't care)
5507  *
5508  *  numArgs = 0 (don't care)
5509  *
5510  *  fromVal = resource value to convert
5511  *
5512  *
5513  *  Outputs:
5514  *  -------
5515  *  toVal = descriptor to use to return converted value
5516  *
5517  *************************************<->***********************************/
5518
5519 static void
5520 DtfileCvtStringToDTIcon (
5521           XrmValue *args,
5522           Cardinal numArgs,
5523           XrmValue *fromVal,
5524           XrmValue *toVal)
5525 {
5526    char * in_str = (char *) (fromVal->addr);
5527    static int i;
5528
5529    toVal->size = sizeof (int);
5530    toVal->addr = (XtPointer) &i;
5531
5532    if (_DtStringsAreEquivalent (in_str, "large"))
5533       i = LARGE;
5534    else if (_DtStringsAreEquivalent (in_str, "small"))
5535       i = SMALL;
5536    else if (_DtStringsAreEquivalent (in_str, "default"))
5537       i = LARGE;  /* for now, eventually want to look at screen width/height*/
5538    else
5539       i = LARGE;
5540 /*
5541    else
5542    {
5543       toVal->size = 0;
5544       toVal->addr = NULL;
5545       XtStringConversionWarning ((char *)fromVal->addr, "DesktopIcon");
5546    }
5547 */
5548 }
5549
5550 static void
5551 DtfileCvtStringToTree (
5552           XrmValue *args,
5553           Cardinal numArgs,
5554           XrmValue *fromVal,
5555           XrmValue *toVal)
5556 {
5557    char * in_str = (char *) (fromVal->addr);
5558    static int i;
5559
5560    toVal->size = sizeof (int);
5561    toVal->addr = (XtPointer) &i;
5562
5563    DtfileStringToTree(in_str, &i);
5564 }
5565
5566 static void
5567 DtfileCvtStringToTreeFiles (
5568           XrmValue *args,
5569           Cardinal numArgs,
5570           XrmValue *fromVal,
5571           XrmValue *toVal)
5572 {
5573    char * in_str = (char *) (fromVal->addr);
5574    static int i;
5575
5576    toVal->size = sizeof (int);
5577    toVal->addr = (XtPointer) &i;
5578
5579    DtfileStringToTreeFiles(in_str, &i);
5580 }
5581
5582 static void
5583 DtfileCvtStringToView (
5584           XrmValue *args,
5585           Cardinal numArgs,
5586           XrmValue *fromVal,
5587           XrmValue *toVal)
5588 {
5589    char * in_str = (char *) (fromVal->addr);
5590    static int i;
5591
5592    toVal->size = sizeof (int);
5593    toVal->addr = (XtPointer) &i;
5594
5595    DtfileStringToView(in_str, &i);
5596 }
5597
5598 static void
5599 DtfileCvtStringToOrder (
5600           XrmValue *args,
5601           Cardinal numArgs,
5602           XrmValue *fromVal,
5603           XrmValue *toVal)
5604 {
5605    char * in_str = (char *) (fromVal->addr);
5606    static int i;
5607
5608    toVal->size = sizeof (int);
5609    toVal->addr = (XtPointer) &i;
5610
5611    DtfileStringToOrder(in_str, &i);
5612 }
5613
5614 static void
5615 DtfileCvtStringToDirection (
5616           XrmValue *args,
5617           Cardinal numArgs,
5618           XrmValue *fromVal,
5619           XrmValue *toVal)
5620 {
5621    char * in_str = (char *) (fromVal->addr);
5622    static int i;
5623
5624    toVal->size = sizeof (int);
5625    toVal->addr = (XtPointer) &i;
5626
5627    DtfileStringToDirection(in_str, &i);
5628 }
5629
5630 static void
5631 DtfileCvtStringToGrid (
5632           XrmValue *args,
5633           Cardinal numArgs,
5634           XrmValue *fromVal,
5635           XrmValue *toVal)
5636 {
5637    char * in_str = (char *) (fromVal->addr);
5638    static int i;
5639
5640    toVal->size = sizeof (int);
5641    toVal->addr = (XtPointer) &i;
5642
5643    DtfileStringToGrid(in_str, &i);
5644 }
5645
5646 FileMgrData *
5647 CheckOpenDir (
5648           char * directory,
5649           char * host)
5650 {
5651    int i;
5652    FileMgrData *file_mgr_data;
5653    DialogData *dialog_data;
5654
5655    for(i = 0; i < view_count; i++)
5656    {
5657       if(strcmp(directory, view_set[i]->directory_name) == 0 &&
5658                             strcmp(host, view_set[i]->host_name) == 0)
5659       {
5660          dialog_data = (DialogData *) view_set[i]->dialog_data;
5661          file_mgr_data = (FileMgrData *) dialog_data->data;
5662          return(file_mgr_data);
5663       }
5664    }
5665    return(NULL);
5666 }
5667
5668 char *
5669 GetRestrictedDirectory (
5670           Widget widget)
5671 {
5672    int i;
5673    FileMgrData *file_mgr_data;
5674    FileMgrRec *file_mgr_rec;
5675    DialogData *dialog_data;
5676
5677    for(i = 0; i < view_count; i++)
5678    {
5679       dialog_data = (DialogData *) view_set[i]->dialog_data;
5680       file_mgr_data = (FileMgrData *) dialog_data->data;
5681       file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5682       if(file_mgr_rec->current_directory_text == widget &&
5683                                           file_mgr_data->fast_cd_enabled)
5684       {
5685          return(file_mgr_data->restricted_directory);
5686       }
5687    }
5688    return((char *)NULL);
5689 }
5690
5691 static void
5692 DtfileStringToTree(
5693    char *str,
5694    int *type)
5695 {
5696    if (_DtStringsAreEquivalent (str, "on"))
5697       *type = MULTIPLE_DIRECTORY;
5698    else if (_DtStringsAreEquivalent (str, "off"))
5699       *type = SINGLE_DIRECTORY;
5700    else
5701       *type = UNSET_VALUE;
5702 }
5703
5704 static void
5705 DtfileStringToTreeFiles(
5706    char *str,
5707    int *type)
5708 {
5709    if (_DtStringsAreEquivalent (str, "never"))
5710       *type = TREE_FILES_NEVER;
5711    else if (_DtStringsAreEquivalent (str, "choose"))
5712       *type = TREE_FILES_CHOOSE;
5713    else if (_DtStringsAreEquivalent (str, "always"))
5714       *type = TREE_FILES_ALWAYS;
5715    else
5716       *type = UNSET_VALUE;
5717 }
5718
5719 static void
5720 DtfileStringToView(
5721    char *str,
5722    int *type)
5723 {
5724    if (_DtStringsAreEquivalent (str, "no_icon") ||
5725                             _DtStringsAreEquivalent (str, "no_icons"))
5726       *type = BY_NAME;
5727    else if (_DtStringsAreEquivalent (str, "large_icon") ||
5728                             _DtStringsAreEquivalent (str, "large_icons"))
5729       *type = BY_NAME_AND_ICON;
5730    else if (_DtStringsAreEquivalent (str, "small_icon") ||
5731                             _DtStringsAreEquivalent (str, "small_icons"))
5732       *type = BY_NAME_AND_SMALL_ICON;
5733    else if (_DtStringsAreEquivalent (str, "attributes"))
5734       *type = BY_ATTRIBUTES;
5735    else
5736       *type = UNSET_VALUE;
5737 }
5738
5739 static void
5740 DtfileStringToOrder(
5741    char *str,
5742    int *type)
5743 {
5744    if (_DtStringsAreEquivalent (str, "file_type"))
5745       *type = ORDER_BY_FILE_TYPE;
5746    else if (_DtStringsAreEquivalent (str, "alphabetical"))
5747       *type = ORDER_BY_ALPHABETICAL;
5748    else if (_DtStringsAreEquivalent (str, "date"))
5749       *type = ORDER_BY_DATE;
5750    else if (_DtStringsAreEquivalent (str, "size"))
5751       *type = ORDER_BY_SIZE;
5752    else
5753       *type = UNSET_VALUE;
5754 }
5755
5756
5757 static void
5758 DtfileStringToDirection(
5759    char *str,
5760    int *type)
5761 {
5762    if (_DtStringsAreEquivalent (str, "ascending"))
5763       *type = DIRECTION_ASCENDING;
5764    else if (_DtStringsAreEquivalent (str, "descending"))
5765       *type = DIRECTION_DESCENDING;
5766    else
5767       *type = UNSET_VALUE;
5768 }
5769
5770 static void
5771 DtfileStringToGrid(
5772    char *str,
5773    int *type)
5774 {
5775    if (_DtStringsAreEquivalent (str, "on"))
5776       *type = RANDOM_OFF;
5777    else if (_DtStringsAreEquivalent (str, "off"))
5778       *type = RANDOM_ON;
5779    else
5780       *type = UNSET_VALUE;
5781 }
5782
5783 static void
5784 SetupSendRequestArgs(
5785    ApplicationArgs application_args,
5786    Tt_message msg)
5787 {
5788    char *vtype;
5789    if(application_args.title != NULL)
5790    {
5791       tt_message_arg_add( msg, TT_IN, "-title", application_args.title );
5792    }
5793    if(application_args.restricted != NULL)
5794    {
5795       tt_message_arg_add( msg, TT_IN, RESTRICTED_HEADER, 0 );
5796    }
5797    vtype = VIEW_HEADER;
5798    switch( application_args.view )
5799    {
5800        case BY_NAME:
5801            tt_message_arg_add( msg, TT_IN, vtype, "no_icon" );
5802            break;
5803        case BY_NAME_AND_ICON:
5804            tt_message_arg_add( msg, TT_IN, vtype, "large_icon" );
5805            break;
5806        case BY_NAME_AND_SMALL_ICON:
5807            tt_message_arg_add( msg, TT_IN, vtype, "small_icon" );
5808            break;
5809        case BY_ATTRIBUTES:
5810            tt_message_arg_add( msg, TT_IN, vtype, "attributes" );
5811            break;
5812        default:
5813            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5814            break;
5815    }
5816
5817    vtype = "-order";
5818    switch( application_args.order )
5819    {
5820        case ORDER_BY_FILE_TYPE:
5821            tt_message_arg_add( msg, TT_IN, vtype, "file_type" );
5822            break;
5823        case ORDER_BY_ALPHABETICAL:
5824            tt_message_arg_add( msg, TT_IN, vtype, "alphabetical" );
5825            break;
5826        case ORDER_BY_DATE:
5827            tt_message_arg_add( msg, TT_IN, vtype, "date" );
5828            break;
5829        case ORDER_BY_SIZE:
5830            tt_message_arg_add( msg, TT_IN, vtype, "size" );
5831            break;
5832        default:
5833            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5834            break;
5835    }
5836
5837    vtype = "-direction";
5838    switch( application_args.direction )
5839    {
5840        case DIRECTION_ASCENDING:
5841            tt_message_arg_add( msg, TT_IN, vtype, "ascending" );
5842            break;
5843        case DIRECTION_DESCENDING:
5844            tt_message_arg_add( msg, TT_IN, vtype, "descending" );
5845            break;
5846        default:
5847            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5848            break;
5849    }
5850
5851    vtype = "-grid";
5852    switch( application_args.grid )
5853    {
5854        case RANDOM_OFF:
5855            tt_message_arg_add( msg, TT_IN, vtype, "on" );
5856            break;
5857        case RANDOM_ON:
5858            tt_message_arg_add( msg, TT_IN, vtype, "off" );
5859            break;
5860        default:
5861            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5862            break;
5863    }
5864    vtype = "-tree";
5865    switch( application_args.tree_view )
5866    {
5867        case MULTIPLE_DIRECTORY:
5868            tt_message_arg_add( msg, TT_IN, vtype, "on" );
5869            break;
5870        case SINGLE_DIRECTORY:
5871            tt_message_arg_add( msg, TT_IN, vtype, "off" );
5872            break;
5873        default:
5874            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5875            break;
5876    }
5877
5878    vtype = "-tree_files";
5879    switch( application_args.tree_files )
5880    {
5881        case TREE_FILES_NEVER:
5882            tt_message_arg_add( msg, TT_IN, vtype, "never" );
5883            break;
5884        case TREE_FILES_CHOOSE:
5885            tt_message_arg_add( msg, TT_IN, vtype, "choose" );
5886            break;
5887        case TREE_FILES_ALWAYS:
5888            tt_message_arg_add( msg, TT_IN, vtype, "always" );
5889            break;
5890        default:
5891            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5892            break;
5893    }
5894
5895    if(application_args.help_volume != NULL)
5896    {
5897       tt_message_arg_add( msg, TT_IN, "-help_volume",
5898                           application_args.help_volume );
5899    }
5900 }
5901
5902 /*
5903  * This routine is used by ForceMyIconOpen to get the "Open" filetype and
5904  * find out what the new icon is.  It then places that icon in the
5905  * correct icon gadget.
5906  */
5907 static void
5908 BuildAndShowIconName(
5909    char *file_type_name,
5910    unsigned char view,
5911    unsigned char show_type,
5912    Widget widget)
5913 {
5914    char *new_file_type_name;
5915    char *ptr;
5916    Arg args[1];
5917    PixmapData *pixmapData;
5918
5919    new_file_type_name = (char *)XtMalloc(strlen(file_type_name) +
5920                                          strlen(ICON_OPEN_PREFIX) + 1);
5921    sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5922
5923    if (view == BY_NAME_AND_ICON && show_type != MULTIPLE_DIRECTORY)
5924      pixmapData = _DtRetrievePixmapData(new_file_type_name,
5925                                         NULL,
5926                                         NULL,
5927                                         widget,
5928                                         LARGE);
5929    else
5930      pixmapData = _DtRetrievePixmapData(new_file_type_name,
5931                                         NULL,
5932                                         NULL,
5933                                         widget,
5934                                         SMALL);
5935
5936    if(pixmapData && pixmapData->iconFileName)
5937    {
5938      XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
5939      XtSetValues(widget, args, 1);
5940    }
5941 /*
5942    else
5943    {
5944      XtSetArg (args[0], XmNimageName, NULL);
5945      XtSetValues(widget, args, 1);
5946    }
5947 */
5948
5949    _DtCheckAndFreePixmapData(new_file_type_name,
5950                              widget,
5951                              (DtIconGadget) widget,
5952                              pixmapData);
5953
5954    XtFree(new_file_type_name);
5955 }
5956
5957
5958 /*
5959  * Given a directory name, this function will see if a view of the parent
5960  * directory is open; if so, then it will update the icon representing
5961  * this icon, in the parent view, so that it is drawn as 'closed'.  This
5962  * function must only be called if openDirType == NEW.
5963  */
5964
5965 void
5966 ForceMyIconClosed (
5967    char * host_name,
5968    char * directory_name)
5969 {
5970    register int i;
5971    register int j;
5972    register int k;
5973    Arg args[1];
5974    FileViewData * file_view_data = NULL;
5975    DialogData *dialog_data;
5976    FileMgrData *file_mgr_data;
5977    DesktopRec *desktopWindow;
5978    char * parent;
5979    char * fname;
5980    PixmapData *pixmapData;
5981
5982    /* find the parent directory of the one just removed */
5983    parent = _DtPName(directory_name);
5984    fname =  DName(directory_name);
5985
5986    /* first check to see if any File Manager views have this directory */
5987    for (i = 0; i < view_count; i++)
5988    {
5989       dialog_data = (DialogData *) view_set[i]->dialog_data;
5990       file_mgr_data = (FileMgrData *) dialog_data->data;
5991
5992       /* loop through until we find the file_view_data structure for
5993        * the directory to force open */
5994
5995       for(j = 0; j < file_mgr_data->directory_count; j++)
5996       {
5997          if (strcmp(parent, file_mgr_data->directory_set[j]->name) == 0)
5998          {
5999             for (k = 0; k < file_mgr_data->directory_set[j]->file_count; k++)
6000             {
6001                file_view_data =
6002                        file_mgr_data->directory_set[j]->file_view_data[k];
6003                if (strcmp(file_view_data->file_data->file_name, fname) == 0)
6004                   goto search_done;
6005             }
6006             break;
6007          }
6008       }
6009    }
6010
6011    search_done:
6012
6013    if( (file_view_data) && (file_mgr_data->view != BY_NAME) )
6014    {
6015       if (file_mgr_data->view == BY_NAME_AND_ICON  &&
6016                        file_mgr_data->show_type != MULTIPLE_DIRECTORY)
6017          pixmapData = _DtRetrievePixmapData(
6018                                  file_view_data->file_data->logical_type,
6019                                  fname,
6020                                  parent,
6021                                  file_view_data->widget,
6022                                  LARGE);
6023       else
6024          pixmapData = _DtRetrievePixmapData(
6025                                  file_view_data->file_data->logical_type,
6026                                  fname,
6027                                  parent,
6028                                  file_view_data->widget,
6029                                  SMALL);
6030
6031       if (pixmapData)
6032         XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6033       else
6034         XtSetArg (args[0], XmNimageName, NULL);
6035       XtSetValues (file_view_data->widget, args, 1);
6036
6037       _DtCheckAndFreePixmapData(file_view_data->file_data->logical_type,
6038                                 file_view_data->widget,
6039                                 (DtIconGadget) file_view_data->widget,
6040                                 pixmapData);
6041    }
6042
6043    /* now check to see if any desktop objects are this directory */
6044    for(j = 0; j < desktop_data->numIconsUsed; j++)
6045    {
6046       char buf[MAX_PATH];
6047
6048       desktopWindow = desktop_data->desktopWindows[j];
6049       file_view_data = desktopWindow->file_view_data;
6050
6051       sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
6052                             desktopWindow->file_name);
6053       DtEliminateDots (buf);
6054
6055       if( (strcmp(buf, directory_name) == 0) &&
6056           (strcmp(desktopWindow->host, host_name) == 0) )
6057       {
6058          pixmapData = _DtRetrievePixmapData(
6059               file_view_data->file_data->logical_type,
6060               fname,
6061               NULL,
6062               desktopWindow->shell,
6063               desktopIconType);
6064
6065          if(pixmapData)
6066            XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6067          else
6068            XtSetArg (args[0], XmNimageName, NULL);
6069          XtSetValues (desktopWindow->iconGadget, args, 1);
6070
6071          _DtCheckAndFreePixmapData(
6072                  desktopWindow->file_view_data->file_data->logical_type,
6073                  desktopWindow->shell,
6074                  (DtIconGadget) desktopWindow->iconGadget,
6075                  pixmapData);
6076       }
6077    }
6078 }
6079
6080
6081 /*************************************************************************
6082  *
6083  * MarqueeSelect - this is the callback which gets called when there is
6084  *    a marquee event happening on the root window.
6085  *
6086  ************************************************************************/
6087 static void
6088 MarqueeSelect (
6089       Widget w,
6090       int type,
6091       Position x,
6092       Position y,
6093       Dimension width,
6094       Dimension height,
6095       XtPointer client_data)
6096 {
6097    int i;
6098    Window   rootWindow;
6099    Atom     pCurrent;
6100    Screen   *currentScreen;
6101    int      screen;
6102    char     *workspace_name=NULL;
6103    Display *display;
6104
6105
6106    switch (type)
6107    {
6108        case DT_WSM_MARQUEE_SELECTION_TYPE_BEGIN:
6109             display = XtDisplay(desktop_data->desktopWindows[0]->shell);
6110             screen = XDefaultScreen(display);
6111             currentScreen = XScreenOfDisplay(display, screen);
6112             rootWindow = RootWindowOfScreen(currentScreen);
6113
6114             if(DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
6115                                                             == Success)
6116             {
6117                workspace_name = XGetAtomName (display, pCurrent);
6118                CleanUpWSName(workspace_name);
6119             }
6120             else
6121                workspace_name =
6122                   XtNewString(desktop_data->workspaceData[0]->name);
6123
6124             for(i = 0; i < desktop_data->numWorkspaces; i++)
6125             {
6126                if(strcmp(workspace_name,
6127                            desktop_data->workspaceData[i]->name) == 0)
6128                {
6129                   DeselectAllDTFiles(desktop_data->workspaceData[i]);
6130                   break;
6131                }
6132             }
6133             XtFree(workspace_name);
6134             break;
6135
6136        case DT_WSM_MARQUEE_SELECTION_TYPE_END:
6137             CheckDesktopMarquee(x, y, width, height);
6138             break;
6139
6140        case DT_WSM_MARQUEE_SELECTION_TYPE_CANCEL:
6141             break;
6142
6143        case DT_WSM_MARQUEE_SELECTION_TYPE_CONTINUE:
6144             CheckDesktopMarquee(x, y, width, height);
6145             break;
6146
6147        default:
6148             break;
6149    }
6150 }
6151
6152
6153 /*
6154  * We must wait for the message response, before exiting
6155  */
6156
6157 static void
6158 WaitForResponseAndExit( void )
6159
6160 {
6161    XtMainLoop();
6162 }
6163
6164 static void
6165 ExitApp(
6166         XtPointer clientData,
6167         DtString words[],
6168         int num_fields )
6169
6170 {
6171   FinalizeToolTalkSession( );
6172   exit(0);
6173 }
6174
6175
6176 /*
6177  * Puts up an Error dialog with Cancel and Help unmapped in the
6178  * center of the screen. The last argument is the OK callback
6179  */
6180
6181 static Widget
6182 post_dialog(Widget parent, char *title, char *msg, void (*DtErrExitCB)())
6183 {
6184    Widget dialog, dialogShell;
6185    XmString message_text, ok;
6186    Arg args[10];
6187    Dimension dialogWd, dialogHt;
6188    int n = 0;
6189
6190    ok = XmStringCreateLocalized ((char*)_DtOkString);
6191    message_text = XmStringCreateLocalized (msg);
6192
6193    XtSetArg(args[n], XmNautoUnmanage, False); n++;
6194    XtSetArg(args[n], XmNokLabelString, ok); n++;
6195    XtSetArg(args[n], XmNtitle, title); n++;
6196    XtSetArg(args[n], XmNmessageString, message_text); n++;
6197    XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
6198    XtSetArg (args[n], XmNdefaultPosition, False); n++;
6199    XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
6200
6201    dialog = XmCreateErrorDialog (parent, title, args, n);
6202    XtAddCallback (dialog, XmNokCallback, DtErrExitCB, NULL);
6203    XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON));
6204    XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
6205
6206    /* Disable the frame menu from dialog since we don't want the user
6207       to be able to close dialogs with the frame menu */
6208
6209    dialogShell = XtParent(dialog);
6210    XtSetArg(args[0], XmNmappedWhenManaged, False);
6211    XtSetArg(args[1], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU);
6212    XtSetValues(dialogShell, args, 2);
6213    XtManageChild (dialog);
6214    XtRealizeWidget (dialogShell);
6215
6216    /* Center the dialog */
6217
6218    XtSetArg(args[0], XmNwidth, &dialogWd);
6219    XtSetArg(args[1], XmNheight, &dialogHt);
6220    XtGetValues(dialog, args, 2);
6221    XtSetArg (args[0], XmNx,
6222                 (WidthOfScreen(XtScreen(dialog)) - dialogWd) / 2);
6223    XtSetArg (args[1], XmNy,
6224                 (HeightOfScreen(XtScreen(dialog)) - dialogHt) / 2);
6225    XtSetArg (args[2], XmNmappedWhenManaged, True); 
6226    XtSetValues (dialog, args, 3);
6227
6228    XtSetArg(args[0], XmNmappedWhenManaged, True);
6229    XtSetValues(dialogShell, args, 1);
6230
6231    XtManageChild (dialog);
6232    XmStringFree(message_text);
6233
6234    return (dialog);
6235 }
6236
6237 /*  
6238  * This is the Callback when an error occurs while trying to create 
6239  * the .dt folder or sub-folders. Application exits.
6240  */
6241
6242 static void 
6243 DtErrExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
6244 {
6245 XtPopdown (XtParent (dialog));
6246 FinalizeToolTalkSession();
6247 exit (1);
6248 }
6249
6250 #ifdef __osf__
6251 extern void
6252 sigchld_handler(int signo)      /* Do not use the arg signo at the moment */
6253 {
6254     pid_t   pid;
6255     int     stat_loc;
6256
6257     /*
6258       On DUX, the process remains in the ZOMBIE
6259       state untill parent invokes wait or waitpid.
6260     */
6261
6262     pid = waitpid(-1, &stat_loc, WNOHANG);
6263     /* Child exit handling code follows, if any */
6264 }
6265 #endif /* __osf__ */