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