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