1 /* $TOG: Main.c /main/29 1999/09/17 13:35:04 mgreess $ */
2 /************************************<+>*************************************
3 ****************************************************************************
7 * COMPONENT_NAME: Desktop File Manager (dtfile)
9 * Description: This file contains the main program for dtfile.
10 * It also contains functions for session management and
11 * directory view control.
13 * FUNCTIONS: BlackPixelOfScreen
14 * BuildAndShowIconName
15 * CheckForOpenDirectory
22 * DtfileCvtStringToDTIcon
23 * DtfileCvtStringToDirection
24 * DtfileCvtStringToGrid
25 * DtfileCvtStringToObjPlace
26 * DtfileCvtStringToOpenDir
27 * DtfileCvtStringToOrder
28 * DtfileCvtStringToTree
29 * DtfileCvtStringToTreeFiles
30 * DtfileCvtStringToView
31 * DtfileStringToDirection
35 * DtfileStringToTreeFiles
44 * GetRestrictedDirectory
63 * SetupSendRequestArgs
68 * ViewDirectoryHandler
70 * ViewHomeDirectoryHandler
72 * ViewToolsDirectoryHandler
73 * WaitForResponseAndExit
77 * _DtWsmAddMarqueeSelectionCallback
83 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
84 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
85 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
86 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
88 ****************************************************************************
89 ************************************<+>*************************************/
91 #include <sys/types.h>
105 #ifndef sun /* don't need the nl_types.h file */
106 #include <nl_types.h>
112 #include <Xm/DrawingA.h>
113 #include <Xm/DrawingAP.h>
114 #include <Xm/MessageB.h>
115 #include <Xm/RowColumn.h>
116 #include <Xm/MwmUtil.h>
119 #include <Dt/IconP.h>
120 #include <Dt/IconFile.h>
122 #include <Dt/HelpDialog.h>
125 #include <X11/extensions/shape.h>
128 #include <X11/Shell.h>
129 #include <X11/Xatom.h>
130 #include <Xm/Protocols.h>
131 #include <X11/keysymdef.h>
133 #include <X11/Xmu/Editres.h>
135 #include <Dt/Session.h>
137 #include <Dt/Connect.h>
138 #include <Dt/FileM.h>
139 #include <Dt/Indicator.h>
141 #include <Dt/UserMsg.h>
144 #include <Dt/DtNlUtils.h>
145 #include <Dt/CommandM.h>
146 #include <Dt/EnvControlP.h>
150 #include "SharedProcs.h"
158 #include "ChangeDir.h"
165 /* When openDir resource is set to NEW
166 File Manager will use this prefix to find for a different icon
169 #define ICON_OPEN_PREFIX "OPEN_"
171 /* THESE ARE ONLY STRINGS WHICH DO NOT NEED TO BE LOCALIZED */
172 /* Don't use '#define' since you end up with multiple copies */
173 char DTFILE_CLASS_NAME[] = "Dtfile";
174 char DTFILE_HELP_NAME[] = "Filemgr";
175 char DESKTOP_DIR[] = ".dt/Desktop";
177 static char WS_RES_HEADER[] = ".Workspace.";
178 static char SEC_HELP_RES_HEADER[] = ".secondaryHelpDialogCount: ";
179 static char WS_LOAD_RES_HEADER[] = "Workspace";
180 static char SEC_LOAD_HELP_RES_HEADER[] = "secondaryHelpDialogCount";
181 static char RESTRICTED_HEADER[] = "-restricted";
182 static char VIEW_HEADER[] = "-view";
185 /* Structure, resource definitions, for View's optional parameters. */
198 int instanceIconWidth;
199 int instanceIconHeight;
200 XmFontList user_font;
201 Dimension tool_width;
202 Dimension tool_height;
204 Dimension dir_height;
213 int maxDirectoryProcesses;
214 int maxRereadProcesses;
215 int maxRereadProcsPerTick;
218 Boolean showFilesystem;
219 Boolean showDropZone;
220 Boolean showEmptySet;
221 Boolean showEmptyMsg;
223 Boolean restrictMode;
224 int desktopPlacement;
225 Boolean freezeOnConfig;
226 #if defined(__hpux) || defined(sun)
227 Boolean follow_links;
232 int retryLoadDesktop;
237 Boolean emptyTrashOnExit;
238 } ApplicationArgs, *ApplicationArgsPtr;
240 static ApplicationArgs application_args;
242 /******** Static Function Declarations ********/
244 static void ErrorHandler(
246 XErrorEvent *event) ;
247 static void ToolkitErrorHandler(
251 static void RestrictModeUsage(
253 static void Stop( void ) ;
254 static void RestoreSettingsFile( void ) ;
255 static void MoveDefaultSettings(
257 static void SaveDefaultCancelCB(
259 XtPointer client_data,
260 XtPointer call_data) ;
261 static void SaveDefaultOkCB(
263 XtPointer client_data,
264 XtPointer call_data) ;
265 static void SaveSession(
267 static int RestoreSession(
272 char current_directory[]) ;
273 static void OpenDirectories(
276 static Tt_callback_action ObserveTtNotice(
279 static void ViewSessionHandler(
281 static void ViewDirectoryHandler(
283 static void ViewHomeDirectoryHandler(
285 static void ViewToolsDirectoryHandler(
287 static void ExitHandler(
289 XtPointer clientData,
290 String * messageFields,
292 static void ReloadDatabases( void );
293 static void ViewAccept(
296 static void LoadViews (
300 char *directory_name,
303 static void RemoveTextFields (
304 XtPointer client_data,
305 DialogData * old_dialog_data,
306 DialogData * new_dialog_data) ;
307 static void DtfileCvtStringToObjPlace (
312 static unsigned char *_DtNextToken (
313 unsigned char *pchIn,
315 unsigned char **ppchNext) ;
316 static void DtfileCvtStringToOpenDir (
321 static void DtfileCvtStringToDTIcon (
326 static void DtfileCvtStringToTree (
331 static void DtfileCvtStringToTreeFiles (
336 static void DtfileCvtStringToView (
341 static void DtfileCvtStringToOrder (
346 static void DtfileCvtStringToDirection (
351 static void DtfileCvtStringToGrid (
356 static void DtfileStringToTree(
359 static void DtfileStringToTreeFiles(
362 static void DtfileStringToView(
365 static void DtfileStringToOrder(
368 static void DtfileStringToDirection(
371 static void DtfileStringToGrid(
374 static void SetupSendRequestArgs(
375 ApplicationArgs application_args,
377 static void BuildAndShowIconName(
378 char *file_type_name,
380 unsigned char show_type,
382 static void MarqueeSelect (
389 XtPointer client_data);
390 static void WaitForResponseAndExit( void ) ;
392 XtPointer clientData,
395 static Widget post_dialog(
400 static void DtErrExitCB(
402 XtPointer client_data,
403 XtPointer call_data);
405 /******** End Static Function Declarations ********/
412 /* performance flag */
413 #ifdef DT_PERFORMANCE
417 /* The id's of the dialogs registered by main */
420 int change_dir_dialog;
421 int preferences_dialog;
427 /* The shared menu button and pane Id's */
429 Widget * create_dataBtn;
432 Widget * duplicateBtn;
435 Widget * create_directoryBtn;
436 Widget * change_directoryBtn;
437 Widget * showHiddenMenu;
438 Widget * preferencesBtn;
440 Widget * defaultEnvBtn;
447 Widget * terminalBtn;
448 Widget * usingHelp = NULL;
449 Widget * fileManagerHelp = NULL;
450 Widget * applicationManagerHelp = NULL;
451 Widget * usingHelpTrash = NULL;
454 /* Bitmask used to indicate the current sensitivity state of shared menu btns */
456 unsigned int currentMenuStates = ( RENAME | MOVE | DUPLICATE | LINK | TRASH |
457 MODIFY | CHANGEDIR | PREFERENCES | FILTER |
458 FIND | CREATE_DIR | CREATE_FILE |
459 PUT_ON_DESKTOP | PUTBACK |
461 HOME | CHANGE_DIR | TERMINAL);
463 /* Drag manager globals */
465 Boolean dragActive = False;
467 /* Desktop Globals */
471 /* Globally referenced application name. Set to argv[0] in main */
473 char * application_name = NULL;
476 /* uid for root user; used when we are checking access permissions */
483 char home_host_name[MAX_PATH];
484 char users_home_dir[MAX_PATH];
487 /* Toolbox directory */
489 char * desktop_dir = NULL;
490 char * trash_dir = NULL;
491 char * remote_sys_dir = NULL;
495 int restoreType = NORMAL_RESTORE;
498 /* Black and White pixels */
504 /* File manager view set before a new view is created and */
505 /* used to propagate visual attributes from the initiating */
506 /* view to the new view. */
508 XtPointer initiating_view = NULL;
509 Boolean special_view = False;
510 Boolean TrashView = False;
513 /* system wide user font */
515 XmFontList user_font;
518 /* Global localizable strings */
524 /* Global dialog button labels, as XmStrings */
527 XmString cancelXmString;
528 XmString helpXmString;
529 XmString applyXmString;
530 XmString closeXmString;
533 /* Global top level widget */
537 /* Global Application resources */
538 Boolean showFilesystem;
539 Boolean showDropZone;
540 Boolean showEmptySet;
541 Boolean showEmptyMsg;
542 Boolean restrictMode;
546 char *fileMgrHelpVol;
551 int desktopPlacement;
552 Boolean freezeOnConfig;
553 #if defined(__hpux) || defined(sun)
554 Boolean follow_links;
564 unsigned char keybdFocusPolicy;
565 int special_treeType;
566 int special_treeFiles;
567 int special_viewType;
568 int special_orderType;
569 int special_directionType;
570 int special_randomType;
571 char *special_restricted;
573 char *special_helpVol;
577 int retryLoadDesktopInfo;
584 Boolean emptyTrashOnExit;
587 Boolean shapeExtension;
590 /* Drag state variables */
591 Boolean B1DragPossible = False;
592 Boolean B2DragPossible = False;
593 Boolean ProcessBtnUp = False;
594 Boolean ProcessBtnUpCD = True;
598 int xErrorDetected = False;
600 /* BMenu button binding */
603 View ** view_set = NULL;
605 int view_set_size = 0;
607 /* Globals used within this file. */
609 static Display * display;
610 char * dt_path = NULL;
611 static Boolean message_display_enabled = True;
614 static Atom save_yourself_atom;
615 static Atom command_atom;
616 static Atom wm_state_atom;
617 static Atom save_mode;
619 /* Structure used on a save session to see if a dt is iconic */
628 /* Application resource list definition */
630 static XrmOptionDescRec option_list[] =
632 { "-noview", "noView", XrmoptionIsArg, NULL },
633 { "-session", "session", XrmoptionSepArg, NULL },
634 { "-dir", "folder", XrmoptionSepArg, NULL },
635 { "-folder", "folder", XrmoptionSepArg, NULL },
636 { "-tree", "treeView", XrmoptionSepArg, NULL },
637 { "-tree_files", "treeFiles", XrmoptionSepArg, NULL },
638 { VIEW_HEADER, "view", XrmoptionSepArg, NULL },
639 { "-order", "order", XrmoptionSepArg, NULL },
640 { "-direction", "direction", XrmoptionSepArg, NULL },
641 { "-grid", "grid", XrmoptionSepArg, NULL },
642 { RESTRICTED_HEADER, "restricted", XrmoptionIsArg, NULL },
643 { "-title", "title", XrmoptionSepArg, NULL },
644 { "-help_volume", "help_volume", XrmoptionSepArg, NULL },
645 { "-noprompt", "promptUser", XrmoptionNoArg, "False" },
646 { "-small_icon_width", "smallIconWidth", XrmoptionSepArg, NULL },
647 { "-small_icon_height", "smallIconHeight", XrmoptionSepArg, NULL },
648 { "-large_icon_width", "largeIconWidth", XrmoptionSepArg, NULL },
649 { "-large_icon_height", "largeIconHeight", XrmoptionSepArg, NULL },
653 static XtResource resources[] =
656 "noView", "NoView", XmRString, sizeof (char *),
657 XtOffset (ApplicationArgsPtr, no_view), XmRImmediate, (XtPointer) NULL,
661 "session", "Session", XmRString, sizeof (char *),
662 XtOffset (ApplicationArgsPtr, session), XmRImmediate, (XtPointer) NULL,
666 "folder", "Folder", XmRString, sizeof (char *),
667 XtOffset (ApplicationArgsPtr, directories), XmRImmediate, (XtPointer) NULL,
671 "treeView", "TreeView", "Tree", sizeof (int),
672 XtOffset (ApplicationArgsPtr, tree_view), XmRImmediate,
673 (XtPointer) UNSET_VALUE,
677 "treeFiles", "TreeFiles", "TreeFiles", sizeof (int),
678 XtOffset (ApplicationArgsPtr, tree_files), XmRImmediate,
679 (XtPointer) UNSET_VALUE,
683 "view", "View", "View", sizeof (int),
684 XtOffset (ApplicationArgsPtr, view), XmRImmediate, (XtPointer) UNSET_VALUE,
688 "order", "Order", "Order", sizeof (int),
689 XtOffset (ApplicationArgsPtr, order), XmRImmediate, (XtPointer) UNSET_VALUE,
693 "direction", "Direction", "Direction", sizeof (int),
694 XtOffset (ApplicationArgsPtr, direction), XmRImmediate,
695 (XtPointer) UNSET_VALUE,
699 "grid", "Grid", "Grid", sizeof (int),
700 XtOffset (ApplicationArgsPtr, grid), XmRImmediate, (XtPointer) UNSET_VALUE,
704 "instanceIconWidth", "InstanceIconWidth", XmRInt, sizeof (int),
705 XtOffset (ApplicationArgsPtr, instanceIconWidth), XmRImmediate,
710 "instanceIconHeight", "InstanceIconHeight", XmRInt, sizeof (int),
711 XtOffset (ApplicationArgsPtr, instanceIconHeight), XmRImmediate,
716 "restricted", "Restricted", XmRString, sizeof (char *),
717 XtOffset (ApplicationArgsPtr, restricted), XmRImmediate, (XtPointer) NULL,
721 "title", "Title", XmRString, sizeof (char *),
722 XtOffset (ApplicationArgsPtr, title), XmRImmediate, (XtPointer)NULL,
726 "help_volume", "Help_volume", XmRString, sizeof (char *),
727 XtOffset (ApplicationArgsPtr, help_volume), XmRImmediate, (XtPointer)NULL,
731 "userFont", "XmCFontList", XmRFontList, sizeof (XmFontList),
732 XtOffset (ApplicationArgsPtr, user_font), XmRString, (XtPointer) "Fixed",
736 "toolWidth", "ToolWidth", XmRHorizontalDimension, sizeof (Dimension),
737 XtOffset (ApplicationArgsPtr, tool_width), XmRImmediate, (XtPointer) 700,
741 "toolHeight", "ToolHeight", XmRVerticalDimension, sizeof (Dimension),
742 XtOffset (ApplicationArgsPtr, tool_height), XmRImmediate, (XtPointer) 250,
746 "dirWidth", "DirWidth", XmRHorizontalDimension, sizeof (Dimension),
747 XtOffset (ApplicationArgsPtr, dir_width), XmRImmediate, (XtPointer) 555,
751 "dirHeight", "DirHeight", XmRVerticalDimension, sizeof (Dimension),
752 XtOffset (ApplicationArgsPtr, dir_height), XmRImmediate, (XtPointer) 400,
756 "promptUser", "PromptUser", XmRBoolean, sizeof (Boolean),
757 XtOffset (ApplicationArgsPtr, prompt_user), XmRImmediate, (XtPointer) True,
761 "rootTitle", "RootTitle", XmRString, sizeof (char *),
762 XtOffset (ApplicationArgsPtr, root_title), XmRImmediate, (XtPointer)"ROOT",
766 "moveThreshold", "MoveThreshold", XmRInt, sizeof (int),
767 XtOffset (ApplicationArgsPtr, dragThreshold), XmRImmediate, (XtPointer) 4,
771 "rereadTime", "RereadTime", XmRInt, sizeof (int),
772 XtOffset (ApplicationArgsPtr, rereadTime), XmRImmediate, (XtPointer) 3,
776 "checkBrokenLink", "CheckBrokenLink", XmRInt, sizeof (int),
777 XtOffset (ApplicationArgsPtr, checkBrokenLink), XmRImmediate,
782 "maxDirectoryProcesses", "MaxDirectoryProcesses", XmRInt, sizeof (int),
783 XtOffset (ApplicationArgsPtr, maxDirectoryProcesses), XmRImmediate,
788 "maxRereadProcesses", "MaxRereadProcesses", XmRInt, sizeof (int),
789 XtOffset (ApplicationArgsPtr, maxRereadProcesses), XmRImmediate,
794 "maxRereadProcsPerTick", "MaxRereadProcsPerTick", XmRInt, sizeof (int),
795 XtOffset (ApplicationArgsPtr, maxRereadProcsPerTick), XmRImmediate,
800 "trashWait", "TrashWait", XmRInt, sizeof (int),
801 XtOffset (ApplicationArgsPtr, trashWait), XmRImmediate, (XtPointer) 1,
805 "desktopIcon", "DesktopIcon", "DesktopIcon", sizeof (int),
806 XtOffset (ApplicationArgsPtr, desktopIconType), XmRImmediate,
811 "showFilesystem", "ShowFilesystem", XmRBoolean, sizeof (Boolean),
812 XtOffset (ApplicationArgsPtr, showFilesystem), XmRImmediate,
817 "showDropZone", "ShowDropZone", XmRBoolean, sizeof (Boolean),
818 XtOffset (ApplicationArgsPtr, showDropZone), XmRImmediate,
823 "showEmptySet", "ShowEmptySet", XmRBoolean, sizeof (Boolean),
824 XtOffset (ApplicationArgsPtr, showEmptySet), XmRImmediate,
829 "showEmptyMsg", "ShowEmptyMsg", XmRBoolean, sizeof (Boolean),
830 XtOffset (ApplicationArgsPtr, showEmptyMsg), XmRImmediate,
835 "openFolder", "OpenFolder", "OpenFolder", sizeof (int),
836 XtOffset (ApplicationArgsPtr, openDirType), XmRImmediate,
841 "restrictMode", "RestrictMode", XmRBoolean, sizeof (Boolean),
842 XtOffset (ApplicationArgsPtr, restrictMode), XmRImmediate,
847 "objectPlacement", "ObjectPlacement", "ObjectPlacement", sizeof (int),
848 XtOffset (ApplicationArgsPtr, desktopPlacement), XmRImmediate,
849 (XtPointer)(OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_RIGHT_SECONDARY),
853 "freezeOnConfig", "FreezeOnConfig", XmRBoolean, sizeof (Boolean),
854 XtOffset (ApplicationArgsPtr, freezeOnConfig), XmRImmediate,
859 "fileManagerIcon", "FileManagerIcon", XmRString, sizeof (char *),
860 XtOffset (ApplicationArgsPtr, fileMgrIcon), XmRImmediate,
861 (XtPointer) HOME_ICON_NAME,
865 "appManagerIcon", "AppManagerIcon", XmRString, sizeof (char *),
866 XtOffset (ApplicationArgsPtr, appMgrIcon), XmRImmediate,
867 (XtPointer) TOOL_ICON_NAME,
871 "trashIcon", "TrashIcon", XmRString, sizeof (char *),
872 XtOffset (ApplicationArgsPtr, trashIcon), XmRImmediate,
873 (XtPointer) TRASH_ICON_NAME,
877 "retryLoadDesktop", "RetryLoadDesktop", XmRInt, sizeof (int),
878 XtOffset (ApplicationArgsPtr, retryLoadDesktop), XmRImmediate,
883 "smallIconWidth", "SmallIconWidth", XmRInt, sizeof (int),
884 XtOffset (ApplicationArgsPtr, smallIconWidth), XmRImmediate,
889 "smallIconHeight", "SmallIconHeight", XmRInt, sizeof (int),
890 XtOffset (ApplicationArgsPtr, smallIconHeight), XmRImmediate,
895 "largeIconWidth", "LargeIconWidth", XmRInt, sizeof (int),
896 XtOffset (ApplicationArgsPtr, largeIconWidth), XmRImmediate,
901 "largeIconHeight", "LargeIconHeight", XmRInt, sizeof (int),
902 XtOffset (ApplicationArgsPtr, largeIconHeight), XmRImmediate,
907 "emptyTrashOnExit", "EmptyTrashOnExit", XmRBoolean, sizeof (Boolean),
908 XtOffset (ApplicationArgsPtr, emptyTrashOnExit), XmRImmediate,
912 #if defined(__hpux) || defined(sun)
913 { "followLinks", "FollowLinks", XmRBoolean, sizeof(Boolean),
914 XtOffset(ApplicationArgsPtr, follow_links), XmRImmediate,
921 XtActionsRec actionTable[] = {
922 {"Space", (XtActionProc)VFTextChangeSpace},
923 {"EscapeFM", (XtActionProc)CancelOut},
926 /************************************************************************
929 * The main program for the file manager.
931 ************************************************************************/
933 extern XtInputId ProcessToolTalkInputId;
936 extern void sigchld_handler(int);
944 #ifdef DT_PERFORMANCE
945 struct timeval update_time_s;
946 struct timeval update_time_f;
947 struct timeval update_time_ss;
948 struct timeval update_time_fs;
951 char current_directory[MAX_PATH];
952 struct passwd * pwInfo;
956 Boolean eventDebugging;
964 XSetWindowAttributes sAttributes;
969 XrmValue resource_value;
974 int ttFd; /* ToolTalk file descriptor */
976 Tt_pattern events2Watch;
977 Tt_pattern requests2Handle;
981 struct sigaction sa, osa;
983 int session_flag = 0;
985 #ifdef DT_PERFORMANCE
987 gettimeofday(&update_time_ss, NULL);
989 (void) signal (SIGINT, (void (*)())Stop);
991 /* We don't want any zombie children, do we? */
993 sa.sa_handler = sigchld_handler;
994 sigemptyset(&sa.sa_mask);
997 if (sigaction(SIGCHLD, &sa, &osa) < 0)
998 /* error handling follows, none for now */
1001 (void) signal (SIGCLD, SIG_IGN);
1002 #endif /* __osf__ */
1003 XtSetLanguageProc( NULL, NULL, NULL );
1005 #ifdef DT_PERFORMANCE
1006 { /* Initialize the checkpoint protocol - Aloke Gupta */
1008 display = XOpenDisplay("");
1009 _DtPerfChkpntInit(display, RootWindow(display, DefaultScreen(display)),
1015 _DtEnvControl(DT_ENV_SET);
1017 #ifdef DT_PERFORMANCE
1018 printf(" XtInitalize\n");
1019 gettimeofday(&update_time_s, NULL);
1021 /* Added by Aloke Gupta */
1022 _DtPerfChkpntMsgSend("Begin XtInitialize");
1025 /* Initialize the toolkit and open the display */
1026 toplevel = XtInitialize (argv[0], DTFILE_CLASS_NAME,
1027 option_list, XtNumber(option_list),
1028 (int *)&argc, argv);
1030 /* MERGE START: May not need
1032 _XmColorObjCreate ( toplevel, NULL, NULL );
1036 #ifdef DT_PERFORMANCE
1037 gettimeofday(&update_time_f, NULL);
1038 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1039 update_time_f.tv_usec += 1000000;
1040 update_time_f.tv_sec--;
1042 printf(" done XtInitialize, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1044 /* Added by Aloke Gupta */
1045 _DtPerfChkpntMsgSend("Done XtInitialize");
1048 /* Initialize the function ptr for alphabetic sorting */
1049 FMStrcoll = GetStrcollProc();
1051 /* Open the message catalog - DO NOT PERFORM until after XtInitialize! */
1053 char * foo = ((char *)GETMESSAGE(18, 1, ""));
1056 /* set application name for later */
1057 str = strrchr(argv[0], '/');
1059 application_name = XtNewString (str + 1);
1061 application_name = XtNewString (argv[0]);
1064 XtSetArg(args[n], XmNallowShellResize, True); n++;
1065 XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
1066 XtSetArg(args[n], XmNheight, 1); n++;
1067 XtSetArg(args[n], XmNwidth, 1); n++;
1068 XtSetValues(toplevel, args, n);
1069 XtRealizeWidget(toplevel);
1070 display = XtDisplay (toplevel);
1072 XtAddEventHandler(toplevel, 0, True,
1073 (XtEventHandler) _XEditResCheckMessages,
1077 /* Initialize BMenu button binding */
1079 int numMouseButtons = XGetPointerMapping(display,
1080 (unsigned char *)NULL, 0);
1081 bMenuButton = (numMouseButtons < 3) ? Button2 : Button3;
1084 /* initialize debugging flag */
1086 if ((tmpStr = getenv("DTFILE_DEBUG")) != NULL)
1088 debug = atoi(tmpStr);
1092 if (getenv("DTFILE_XSYNC") != NULL)
1094 XSynchronize(display, True);
1098 /* initialize performance flag */
1099 #ifdef DT_PERFORMANCE
1100 if ((tmpStr = getenv("DTFILE_PERFORM")) != NULL)
1102 perform = atoi(tmpStr);
1106 if (getenv("DTFILE_XSYNC") != NULL)
1108 XSynchronize(display, True);
1112 /* Create the atom set used by save and restore session */
1113 save_yourself_atom = XmInternAtom (display, "WM_SAVE_YOURSELF", False);
1114 wm_state_atom = XmInternAtom (display, "WM_STATE", False);
1115 command_atom = XA_WM_COMMAND;
1116 save_mode = XmInternAtom (display, _XA_DT_RESTORE_MODE, False);
1118 root = RootWindowOfScreen(XtScreen(toplevel));
1120 /* Set session property on the top level window */
1121 XmAddWMProtocols(toplevel, &save_yourself_atom, 1);
1122 XmAddWMProtocolCallback(toplevel, save_yourself_atom, SaveSessionCallback,
1125 XSetErrorHandler ((int (*)())ErrorHandler);
1126 XtAppSetErrorHandler (XtWidgetToApplicationContext(toplevel),
1127 ToolkitErrorHandler);
1129 /* get the keyboard focus policy so we know how we want to set up the */
1131 XtSetArg(args[0], XmNkeyboardFocusPolicy, &keybdFocusPolicy);
1132 XtGetValues(toplevel, args, 1);
1134 /* If all of the command line parameters were not processed */
1135 /* out, print out a usage message set and exit. */
1137 if (argc != 1) Usage (argv);
1139 displayWidth = DisplayWidth(display, DefaultScreen(display));
1140 displayHeight = DisplayHeight(display, DefaultScreen(display));
1142 /* Get Dt initialized */
1144 if (DtInitialize (display, toplevel, argv[0], FILE_MANAGER_TOOL_CLASS) == False)
1146 /* Fatal Error: could not connect to the messaging system. */
1147 /* DtInitialize() has already logged an appropriate error msg */
1151 #ifdef DT_PERFORMANCE
1152 printf(" Setup Converters and get resources\n");
1153 gettimeofday(&update_time_s, NULL);
1155 /* Added by Aloke Gupta */
1156 _DtPerfChkpntMsgSend("Begin Setup Converters");
1160 /* First lets add the resource converters needed */
1161 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1162 XtRString, "ObjectPlacement",
1163 (XtConverter)DtfileCvtStringToObjPlace, NULL, 0);
1164 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1165 XtRString, "OpenFolder",
1166 (XtConverter)DtfileCvtStringToOpenDir, NULL, 0);
1167 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1168 XtRString, "DesktopIcon",
1169 (XtConverter)DtfileCvtStringToDTIcon, NULL, 0);
1170 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1172 (XtConverter)DtfileCvtStringToTree, NULL, 0);
1173 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1174 XtRString, "TreeFiles",
1175 (XtConverter)DtfileCvtStringToTreeFiles, NULL, 0);
1176 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1178 (XtConverter)DtfileCvtStringToView, NULL, 0);
1179 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1181 (XtConverter)DtfileCvtStringToOrder, NULL, 0);
1182 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1183 XtRString, "Direction",
1184 (XtConverter)DtfileCvtStringToDirection, NULL, 0);
1185 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1187 (XtConverter)DtfileCvtStringToGrid, NULL, 0);
1189 /* Get the application defined resources of session and */
1190 /* directory, and get the processes host. */
1192 XtGetApplicationResources(toplevel, &application_args,
1193 resources, XtNumber(resources), NULL,0);
1195 #ifdef DT_PERFORMANCE
1196 gettimeofday(&update_time_f, NULL);
1197 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1198 update_time_f.tv_usec += 1000000;
1199 update_time_f.tv_sec--;
1201 printf(" done Setting up Converters and got resources, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1203 /* Added by Aloke Gupta */
1204 _DtPerfChkpntMsgSend("Done Setup Converters");
1207 #ifdef DT_PERFORMANCE
1208 printf(" DtDbLoad\n");
1209 gettimeofday(&update_time_s, NULL);
1210 /* Added by Aloke Gupta */
1211 _DtPerfChkpntMsgSend("Begin DtDbLoad");
1215 /* Set up the messaging and file types */
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--;
1224 printf(" done DtDbLoad, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1226 /* Added by Aloke Gupta */
1227 _DtPerfChkpntMsgSend("Done DtDbLoad");
1232 /* Create some global strings */
1233 db = XtDatabase(display);
1234 if (XrmGetResource (db, "dttypes.defaultActions",
1235 "Dttypes.DefaultActions", &rep_type,
1238 string = XtNewString(resource_value.addr);
1239 for(str = DtStrtok(string, ",") ,i = 0; str != NULL && i < 2 ;
1240 str = DtStrtok(NULL, ","), i++) {
1242 openInPlace = XtNewString(str);
1244 openNewView = XtNewString(str);
1248 if(openInPlace == NULL || strlen(openInPlace) == 0)
1249 openInPlace = XtNewString("OpenInPlace");
1250 if(openNewView == NULL || strlen(openNewView) == 0)
1251 openNewView = XtNewString("OpenNewView");
1253 DtGetShortHostname (home_host_name, MAX_PATH);
1255 /* Get the lock established to ensure only one dtfile process */
1257 if (_DtGetLock (display, DTFILE_CLASS_NAME) == 0)
1259 status = InitializeToolTalkProcid( &ttFd, toplevel, False );
1260 if (TT_OK != status)
1262 char *errfmt, *errmsg, *title, *statmsg;
1263 title = GETMESSAGE(21,38,"File Manager Error");
1264 errfmt = GETMESSAGE(18, 40,
1265 "Could not connect to ToolTalk:\n%s\nExiting ...");
1266 statmsg = tt_status_message(status);
1268 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1269 fprintf(stderr, errfmt, statmsg);
1270 sprintf(errmsg, errfmt, statmsg);
1272 /* put up error dialog and loop,
1273 * application will exit in dialog callback
1275 post_dialog(toplevel, title, errmsg, DtErrExitCB);
1278 if (application_args.session != NULL)
1280 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1281 "DtFileSession_Run",
1282 (Tt_message_callback)ExitApp );
1283 tt_message_file_set( msg, application_args.session );
1284 tt_message_send( msg );
1286 else if (application_args.directories != NULL)
1288 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1290 (Tt_message_callback)ExitApp );
1291 tt_message_file_set( msg, application_args.directories );
1292 SetupSendRequestArgs( application_args, msg );
1293 tt_message_send( msg );
1297 /* Default action: Open up pwd or home dir */
1298 GetPWD(current_directory);
1300 if (current_directory[0] != NULL)
1302 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1304 (Tt_message_callback)ExitApp );
1305 tt_message_file_set( msg, current_directory );
1309 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1311 (Tt_message_callback)ExitApp );
1313 SetupSendRequestArgs( application_args, msg );
1314 tt_message_send( msg );
1316 WaitForResponseAndExit();
1319 /* Initialize the encapsulation mechanism and install the dialogs */
1320 /* used by the file manager. */
1322 _DtInitializeEncapsulation (display, argv[0], DTFILE_CLASS_NAME);
1323 topPositionOffset = -8;
1325 status = InitializeToolTalkProcid( &ttFd, toplevel, True );
1326 if (TT_OK != status)
1328 char *errfmt, *errmsg, *title, *statmsg;
1329 title = GETMESSAGE(21,38,"File Manager Error");
1330 errfmt = GETMESSAGE(18, 40,
1331 "Could not connect to ToolTalk:\n%s\nExiting ...");
1332 statmsg = tt_status_message(status);
1334 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1335 fprintf(stderr, errfmt, statmsg);
1336 sprintf(errmsg, errfmt, statmsg);
1338 /* put up error dialog and loop,
1339 * application will exit in dialog callback
1341 post_dialog(toplevel, title, errmsg, DtErrExitCB);
1345 #ifdef DT_PERFORMANCE
1346 printf(" Setup Callbacks (messaging)\n");
1347 gettimeofday(&update_time_s, NULL);
1349 /* Added by Aloke Gupta */
1350 _DtPerfChkpntMsgSend("Begin Setup Callbacks");
1353 events2Watch = tt_pattern_create();
1354 tt_pattern_category_set( events2Watch, TT_OBSERVE );
1355 tt_pattern_class_add( events2Watch, TT_NOTICE );
1356 tt_pattern_scope_add( events2Watch, TT_SESSION );
1357 sessId = tt_default_session();
1358 tt_pattern_session_add( events2Watch, sessId );
1360 tt_pattern_op_add( events2Watch, "DtTypes_Reloaded" );
1361 tt_pattern_op_add( events2Watch, "XSession_Ending" );
1362 tt_pattern_callback_add( events2Watch, ObserveTtNotice );
1363 tt_pattern_register( events2Watch );
1365 requests2Handle = tt_pattern_create();
1366 tt_pattern_category_set( requests2Handle, TT_HANDLE );
1367 tt_pattern_class_add( requests2Handle, TT_REQUEST );
1368 tt_pattern_scope_add( requests2Handle, TT_SESSION );
1369 sessId = tt_default_session();
1370 tt_pattern_session_add( requests2Handle, sessId );
1372 tt_pattern_op_add( requests2Handle, "DtFileSession_Run" );
1373 tt_pattern_op_add( requests2Handle, "DtFolder_Show" );
1374 tt_pattern_op_add( requests2Handle, "DtHome_Show" );
1375 tt_pattern_op_add( requests2Handle, "DtTools_Show" );
1376 tt_pattern_op_add( requests2Handle, "DtTrash_Show" );
1377 tt_pattern_op_add( requests2Handle, "DtTrash_Remove" );
1378 tt_pattern_op_add( requests2Handle, "DtTrash_Empty" );
1379 tt_pattern_op_add( requests2Handle, "DtTrash_File" );
1380 tt_pattern_op_add( requests2Handle, "DtTrash_Restore" );
1381 tt_pattern_op_add( requests2Handle, "DtFile_PutOnWorkspace" );
1382 tt_pattern_op_add( requests2Handle, "DtFile_Move" );
1383 tt_pattern_op_add( requests2Handle, "DtFile_Copy" );
1384 tt_pattern_op_add( requests2Handle, "DtFile_Link" );
1385 tt_pattern_callback_add( requests2Handle, HandleTtRequest );
1386 tt_pattern_register( requests2Handle );
1388 /* Setup the settings file if any to setup */
1390 _DtWsmAddMarqueeSelectionCallback(toplevel,
1391 (DtWsmMarqueeSelectionProc) MarqueeSelect,
1394 #ifdef DT_PERFORMANCE
1395 gettimeofday(&update_time_f, NULL);
1396 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1397 update_time_f.tv_usec += 1000000;
1398 update_time_f.tv_sec--;
1400 printf(" done Setting Callbacks (messaging), time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1402 /* Added by Aloke Gupta */
1403 _DtPerfChkpntMsgSend("Done Setup Callbacks");
1407 smallIconWidth = application_args.smallIconWidth;
1408 smallIconHeight = application_args.smallIconHeight;
1409 largeIconWidth = application_args.largeIconWidth;
1410 largeIconHeight = application_args.largeIconHeight;
1411 user_font = application_args.user_font;
1412 dragThreshold = application_args.dragThreshold;
1413 rereadTime = application_args.rereadTime;
1414 checkBrokenLink = application_args.checkBrokenLink;
1415 maxDirectoryProcesses = application_args.maxDirectoryProcesses;
1416 maxRereadProcesses = application_args.maxRereadProcesses;
1417 maxRereadProcsPerTick = application_args.maxRereadProcsPerTick;
1418 trashWait = application_args.trashWait;
1419 showFilesystem = application_args.showFilesystem;
1420 showDropZone = application_args.showDropZone;
1421 showEmptySet = application_args.showEmptySet;
1422 showEmptyMsg = application_args.showEmptyMsg;
1423 restrictMode = application_args.restrictMode;
1424 openDirType = application_args.openDirType;
1425 desktopIconType = application_args.desktopIconType;
1426 desktopPlacement = application_args.desktopPlacement;
1427 freezeOnConfig = application_args.freezeOnConfig;
1428 emptyTrashOnExit = application_args.emptyTrashOnExit;
1429 #if defined(__hpux) || defined(sun)
1430 follow_links = application_args.follow_links;
1432 instanceWidth = application_args.instanceIconWidth;
1433 instanceHeight = application_args.instanceIconHeight;
1434 fileMgrIcon = application_args.fileMgrIcon;
1435 appMgrIcon = application_args.appMgrIcon;
1436 trashIcon = application_args.trashIcon;
1437 retryLoadDesktopInfo = application_args.retryLoadDesktop;
1438 if( application_args.directories != NULL
1439 || (strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1442 special_view = True;
1443 if(strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1445 if(application_args.directories != NULL)
1446 special_restricted = XtNewString(application_args.directories);
1449 /* Get users pwd so we can set the restricted dir to it */
1450 GetPWD(current_directory);
1452 if (current_directory[0] != NULL)
1453 special_restricted = XtNewString(current_directory);
1455 special_restricted = XtNewString("~");
1458 else if( restrictMode )
1459 special_restricted = XtNewString("~");
1461 special_restricted = NULL;
1462 special_treeType = treeType = application_args.tree_view;
1463 special_treeFiles = treeFiles = application_args.tree_files;
1464 special_viewType = viewType = application_args.view;
1465 special_orderType = orderType = application_args.order;
1466 special_directionType = directionType = application_args.direction;
1467 special_randomType = randomType = application_args.grid;
1468 special_title = XtNewString(application_args.title);
1469 if(application_args.help_volume == NULL)
1471 special_helpVol = XtNewString(DTFILE_HELP_NAME);
1472 fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1476 special_helpVol = XtNewString(application_args.help_volume);
1477 fileMgrHelpVol = XtNewString(application_args.help_volume);
1479 fileMgrTitle = application_args.title;
1483 special_view = False;
1484 treeType = application_args.tree_view;
1485 treeFiles = application_args.tree_files;
1486 viewType = application_args.view;
1487 orderType = application_args.order;
1488 directionType = application_args.direction;
1489 randomType = application_args.grid;
1490 fileMgrTitle = application_args.title;
1491 if(application_args.help_volume == NULL)
1492 fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1494 fileMgrHelpVol = XtNewString(application_args.help_volume);
1498 if(desktopIconType == LARGE)
1500 numRows = displayHeight / PIXELS_PER_ROW_LARGE;
1501 numColumns = displayWidth / PIXELS_PER_COLUMN_LARGE;
1505 numRows = displayHeight / PIXELS_PER_ROW_SMALL;
1506 numColumns = displayWidth / PIXELS_PER_COLUMN_SMALL;
1510 /* determine whether the Server has the shape extension */
1511 if(XShapeQueryExtension(display, &base1, &base2) == True)
1512 shapeExtension = True;
1514 shapeExtension = False;
1517 /* get the name for the root directory */
1518 root_title = (char *)XtMalloc(strlen(application_args.root_title) + 1);
1519 strcpy(root_title, application_args.root_title);
1521 if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
1523 pwInfo = getpwuid (getuid());
1524 homeDir = pwInfo->pw_dir;
1526 strncpy(users_home_dir, homeDir, MAX_PATH - 1);
1529 if(application_args.directories != NULL &&
1530 strncmp(application_args.directories, "~", 1) != 0 )
1532 if(strncmp(application_args.directories, users_home_dir,
1533 strlen(users_home_dir)) != 0)
1534 RestrictModeUsage (argv);
1536 else if (application_args.directories == NULL)
1537 application_args.directories = XtNewString("~");
1539 if (strcmp(users_home_dir, "/") != 0)
1540 strcat(users_home_dir, "/");
1542 XtAppAddActions(XtWidgetToApplicationContext (toplevel), actionTable, 2);
1544 /* Create some global Xm strings for our dialog buttons */
1546 okXmString = XmStringCreateLocalized((char*)_DtOkString);
1547 cancelXmString = XmStringCreateLocalized((char*)_DtCancelString);
1548 helpXmString = XmStringCreateLocalized((char*)_DtHelpString);
1549 applyXmString = XmStringCreateLocalized((char*)_DtApplyString);
1550 closeXmString = XmStringCreateLocalized((char*)_DtCloseString);
1552 /* Get the dt path created and initialized */
1554 dt_path = _DtCreateDtDirs (display);
1556 if (dt_path == NULL)
1560 title = XtNewString((GETMESSAGE(21,38,"File Manager Error")));
1561 tmpStr = GETMESSAGE(18, 2, "Could not create the ~/.dt folder or sub folders.");
1562 msg = XtNewString(tmpStr);
1564 /* put up error dialog and loop, application will exit in
1567 dialog = post_dialog(toplevel, title, msg, DtErrExitCB);
1573 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
1577 /* Set the black and white pixel globals. */
1579 black_pixel = BlackPixelOfScreen (XtScreen (toplevel));
1580 white_pixel = WhitePixelOfScreen (XtScreen (toplevel));
1583 * Take over the drawing area's redisplay functions, so that we can get
1584 * the dtfile views to redraw according to stacking order, using our own
1587 xmDrawingAreaWidgetClass->core_class.expose = DrawingAreaRedisplay;
1590 /* Get the root user id */
1592 if ((pw = getpwnam("root")) == NULL)
1593 root_user = 0; /* Assume root is uid 0 */
1595 root_user = pw->pw_uid;
1598 file_mgr_dialog = _DtInstallDialog (fileMgrClass, True, True);
1599 change_dir_dialog = _DtInstallDialog (changeDirClass, True, True);
1600 preferences_dialog = _DtInstallDialog (preferencesClass, True, True);
1601 filter_dialog = _DtInstallDialog (filterClass, True, True);
1602 find_dialog = _DtInstallDialog (findClass, True, True);
1603 mod_attr_dialog = _DtInstallDialog (modAttrClass, True, True);
1604 help_dialog = _DtInstallDialog (helpClass, False, False);
1606 if(special_view == True && special_restricted != NULL);
1607 if(strncmp(special_restricted, "~", 1) == 0)
1611 special_restricted = _DtChangeTildeToHome(special_restricted);
1612 ptr = strrchr(special_restricted, '/');
1618 /* Setup the settings file if any to setup */
1619 RestoreSettingsFile();
1621 #ifdef DT_PERFORMANCE
1622 printf(" TrashCreateDialog\n");
1623 gettimeofday(&update_time_s, NULL);
1625 /* Added by Aloke Gupta */
1626 _DtPerfChkpntMsgSend("Begin TrashCreateDialog");
1629 if( InitializeTrash( application_args.prompt_user ) )
1631 #ifdef DEFER_TRASH_CREATION
1634 TrashCreateDialog (display);
1637 #ifdef DT_PERFORMANCE
1638 gettimeofday(&update_time_f, NULL);
1639 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1640 update_time_f.tv_usec += 1000000;
1641 update_time_f.tv_sec--;
1643 printf(" done TrashCreateDialog, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1645 /* Added by Aloke Gupta */
1646 _DtPerfChkpntMsgSend("Done TrashCreateDialog");
1649 /* lets go empty the trash if there is any */
1654 #ifdef DT_PERFORMANCE
1655 printf(" Setup Desktop\n");
1656 gettimeofday(&update_time_s, NULL);
1657 /* Added by Aloke Gupta */
1658 _DtPerfChkpntMsgSend("Begin Setup Desktop");
1661 /* go build 10 desktop windows */
1662 desktop_data = NULL;
1663 InitializeDesktopWindows(10, display);
1664 InitializeDesktopGrid();
1666 LoadDesktopInfo(application_args.session);
1668 /* Install WorkSpaceRemoved handler.
1669 This handler will be called when a workspace is being removed
1670 so File Manager can go through its desktop icons and clean up.
1672 DtWsmAddWorkspaceModifiedCallback( toplevel, WorkSpaceRemoved, NULL );
1674 #ifdef DT_PERFORMANCE
1675 gettimeofday(&update_time_f, NULL);
1676 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1677 update_time_f.tv_usec += 1000000;
1678 update_time_f.tv_sec--;
1680 printf(" done Setting up Desktop, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1682 /* Added by Aloke Gupta */
1683 _DtPerfChkpntMsgSend("Done Setup Desktop");
1687 /* Process the application resources to restore a session, dt */
1688 /* a directory set or display the users home directory. */
1690 #ifdef DT_PERFORMANCE
1691 printf(" Bring up View\n");
1692 gettimeofday(&update_time_s, NULL);
1694 /* Added by Aloke Gupta */
1695 _DtPerfChkpntMsgSend("Begin Bring up View");
1699 if (strcmp (application_args.no_view, "-noview") != 0)
1701 if (application_args.session != NULL)
1703 RestoreSession (application_args.session, NORMAL_RESTORE, NULL);
1704 else if (application_args.directories != NULL)
1706 restoreType = CURRENT_DIR_RESTORE;
1707 OpenDirectories (application_args.directories, NULL);
1711 #ifdef DT_PERFORMANCE
1712 gettimeofday(&update_time_f, NULL);
1713 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1714 update_time_f.tv_usec += 1000000;
1715 update_time_f.tv_sec--;
1717 printf(" done Bringing up view, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec); fflush(stdout);
1719 /* Added by Aloke Gupta */
1720 _DtPerfChkpntMsgSend("Done Bring up View");
1724 /* If no views were opened upon invocation, display the */
1725 /* current directory. */
1727 if ( (strcmp (application_args.no_view, "-noview") != 0) &&
1728 ((application_args.session == NULL) ||
1729 (session_flag != 0)) )
1731 if (view_count == 0)
1733 /* Get users pwd so we can create a fileviewer window of it */
1734 GetPWD(current_directory);
1736 if (current_directory[0] != NULL)
1738 if (!GetNewView (home_host_name, current_directory, NULL, NULL, 0))
1739 ViewHomeDirectoryHandler (0);
1743 ViewHomeDirectoryHandler (0);
1749 /* Set up the timer based directory reading. */
1750 InitializeDirectoryRead (toplevel);
1752 /* Process and dispatch incoming events */
1753 eventDebugging = getenv("EVENT_DEBUGGING") != NULL;
1755 #ifdef DT_PERFORMANCE
1756 printf(" InitializeToolTalkSession\n");
1757 gettimeofday(&update_time_s, NULL);
1759 (void) InitializeToolTalkSession( toplevel, ttFd );
1760 #ifdef DT_PERFORMANCE
1761 gettimeofday(&update_time_f, NULL);
1762 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1763 update_time_f.tv_usec += 1000000;
1764 update_time_f.tv_sec--;
1766 printf(" done InitializeToolTalkSession, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1769 #ifdef DT_PERFORMANCE
1770 gettimeofday(&update_time_fs, NULL);
1771 if (update_time_ss.tv_usec > update_time_fs.tv_usec) {
1772 update_time_fs.tv_usec += 1000000;
1773 update_time_fs.tv_sec--;
1775 printf(" Finish, time: %ld.%ld\n\n", update_time_fs.tv_sec - update_time_ss.tv_sec, update_time_fs.tv_usec - update_time_ss .tv_usec);
1780 XtNextEvent(&event);
1782 if (event.type != 0)
1783 XtDispatchEvent(&event);
1789 /************************************************************************
1793 ************************************************************************/
1798 XErrorEvent *event )
1800 #define _DTFILE_BUFSIZE 1024
1801 char errmsg[_DTFILE_BUFSIZE];
1803 _DtPrintDefaultErrorSafe (disp, event, errmsg, _DTFILE_BUFSIZE);
1804 _DtSimpleError(application_name, DtWarning, NULL, errmsg, NULL);
1805 xErrorDetected = True;
1807 /* We do not want to exit here lets try to continue... */
1812 ToolkitErrorHandler(
1818 tmpStr = GETMESSAGE(18, 6, "An X Toolkit error occurred... Exiting.\n");
1819 msg = (char *)malloc(strlen(tmpStr) + strlen(message) + 3);
1820 strcpy(msg, message);
1822 strcat(msg, tmpStr);
1823 _DtSimpleError (application_name, DtError, NULL, msg);
1826 FinalizeToolTalkSession( );
1833 /************************************************************************
1836 * When incorrect parameters have been specified on the command
1837 * line, print out a set of messages detailing the correct use
1840 ************************************************************************/
1847 char * message_string1 = "\nUsage: %s...\n\n"
1849 "Dtfile runs in server mode.\n\n"
1850 " -session SessionFile\n\n\t"
1851 "Dtfile runs with the session file specified in the SessionFile\n\t"
1853 " -folder Folder[,Folder,Folder]\n"
1854 " -dir Folder[,Folder,Folder]\n\n\t"
1855 "Dtfile displays a window for each folder specified in the\n\t"
1856 "Folder parameter. The Folder parameter may contain many\n\t"
1857 "folders separated by commas. Folders may be in the form\n\t"
1859 " -title Title\n\n\t"
1860 "Dtfile uses the string specified in the Title parameter as the\n\t"
1861 "title for its windows.\n\n"
1862 " -help_volume HelpVolume\n\n\t"
1863 "Dtfile uses the help volume specified in the HelpVolume parameter.\n\n"
1864 " -restricted\n\n\t"
1865 "Dtfile will not display folders above the restricted folder.\n\t"
1866 "If the -dir option is used, the folder specified in that option\n\t"
1867 "is the restricted folder. If the -dir option is not used, the\n\t"
1868 "user's current folder is the restricted folder.\n\n"
1869 " -grid on/off\n\n\t"
1870 "on = Files are displayed in a grid pattern.\n\t"
1871 "off = Files are displayed as placed.\n\n"
1872 " -tree on/off\n\n\t"
1873 "on = Files are displayed in single folder mode.\n";
1875 char * message_string2 = "\toff = Files are displayed in folder tree mode.\n\n"
1876 " -tree_files never/always/choose\n\n\t"
1877 "never = Tree mode has two states: partially expanded or collapsed.\n\t"
1878 "always = Tree mode has two states: fully expanded or collapsed.\n\t"
1879 "choose = Tree mode has three states: partially expanded, fully\n\t"
1880 " expanded, or collapsed.\n\n"
1881 " -order alphabetical/file_type/date/size\n\n\t"
1882 "Files are displayed in the specified order: alphabetical, by file\n\t"
1883 "type, by date, or by size.\n\n"
1884 " -view no_icon/large_icon/small_icon/attributes\n\n\t"
1885 "Files are displayed in the specified format: text only, text and\n\t"
1886 "large icons, text and small icons, with attributes.\n\n"
1887 " -direction ascending/descending\n\n\t"
1888 "Files are displayed in the specified direction: ascending or\n\t"
1890 " -large_icon_width <size>\n\n"
1891 " -large_icon_height <size>\n\n"
1892 " -small_icon_width <size>\n\n"
1893 " -small_icon_height <size>\n\n"
1894 " The display area size for the icon images in File Manager\n"
1895 " Icon images larger than this size will be clipped to this size\n"
1896 " The default display area size for large is 38 and small is 24\n\n"
1900 template = (GETMESSAGE(18,23, message_string1));
1901 fprintf (stderr, template, argv[0]);
1902 template = (GETMESSAGE(18,24, message_string2));
1903 fprintf (stderr, template);
1913 char * message_string = "\nRestricted Mode Usage: %s...\n\n"
1914 " -folder Folder[,Folder,Folder]\n"
1915 " -dir Folder[,Folder,Folder]\n\n\t"
1916 "Where Folder is a Folder below and/or including\n\t"
1917 "the user's Home Folder.\n\n";
1919 template = (GETMESSAGE(18,26, message_string));
1921 fprintf (stderr, template, argv[0]);
1923 FinalizeToolTalkSession( );
1930 /************************************************************************
1933 * Catches Ctrl C's and exits.
1935 ************************************************************************/
1940 FinalizeToolTalkSession( );
1950 /***********************************************************************
1952 * RestoreSettingsFile
1953 * Used to restore the save settings files from
1954 * either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
1956 ***********************************************************************/
1958 RestoreSettingsFile( void )
1962 char *homeSavePath=NULL;
1963 char *homeHomePath=NULL;
1964 char *toolSavePath=NULL;
1965 char *toolHomePath=NULL;
1969 unsigned long nitems;
1970 unsigned long leftover;
1971 unsigned char *data = NULL;
1974 /* go get the dt path */
1975 /* _DtCreateDtDirs returs a path of MaxPath Length */
1976 dtPath = (char *)_DtCreateDtDirs(display);
1978 /* Determin which type of session we are running HOME or CURRENT */
1980 /* get the root window property of SaveMode */
1981 XGetWindowProperty(display, RootWindow(display,0),
1982 save_mode, 0L, (long)BUFSIZ,False,
1983 XA_STRING, &actualType,
1984 &actualFormat,&nitems,&leftover,
1987 if(strcmp((char *)data, "home") == 0)
1988 dirName = XtNewString("home");
1989 else if(strcmp((char *)data, "current") == 0)
1990 dirName = XtNewString("current");
1994 return; /* we are comming up in a system mode (e.g. default) */
1998 /* Build the paths to read the files from */
2000 toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2001 strlen(TOOL_SETTINGS_FILENAME) +
2002 strlen(dirName) + 4);
2004 homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2005 strlen(HOME_SETTINGS_FILENAME) +
2006 strlen(dirName) + 4);
2008 sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2009 sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2011 /* open the home settings file to see if its there */
2012 if((fd = open(homeSavePath, O_RDONLY)) != -1)
2015 /* create where the saved file is going to go */
2017 homeHomePath = (char *)XtMalloc(strlen(dtPath) +
2018 strlen(HOME_SETTINGS_FILENAME) + 2);
2020 sprintf( homeHomePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2022 /* remove any existing dtfile.home (e.g. HOME_SETTINGS_FILENAME) */
2023 unlink(homeHomePath);
2025 /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2026 * will be used by the dtfile
2028 status = link(homeSavePath, homeHomePath);
2033 tmpStr = GETMESSAGE(18,27, "Unable to recover the saved default home settings file, will use default.\n");
2034 msg = XtNewString(tmpStr);
2035 _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2041 /* open the tool settings file to see if its there */
2042 if((fd = open(toolSavePath, O_RDONLY)) != -1)
2045 /* create where the saved file is going to go */
2046 toolHomePath = (char *)XtMalloc(strlen(dtPath) +
2047 strlen(TOOL_SETTINGS_FILENAME) + 2);
2049 sprintf( toolHomePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2051 /* remove any existing dtfile.tool (e.g. TOOL_SETTINGS_FILENAME) */
2052 unlink(toolHomePath);
2054 /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2055 * will be used by the dtfile
2057 status = link(toolSavePath, toolHomePath);
2062 tmpStr = GETMESSAGE(18,28, "Unable to recover the saved default tool settings file, will use default.\n");
2063 msg = XtNewString(tmpStr);
2064 _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2074 XtFree(homeSavePath);
2075 XtFree(toolSavePath);
2076 XtFree(toolHomePath);
2077 XtFree(homeHomePath);
2086 /***********************************************************************
2088 * MoveDefaultSettings
2089 * Used to save the dtfile.tool and dtfile.home settings files to
2090 * either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
2091 * The parameter mode determines whether it is home or
2094 ***********************************************************************/
2096 MoveDefaultSettings(
2100 char *toolSavePath=NULL;
2101 char *homeSavePath=NULL;
2103 char *toolMovePath=NULL;
2104 char *homeMovePath=NULL;
2107 /* determine whether home or current */
2108 if(mode == HOME_DIR_RESTORE)
2109 dirName = XtNewString("home");
2111 dirName = XtNewString("current");
2113 /* go get the dt path */
2114 /* _DtCreateDtDirs returs a path of MaxPath Length */
2115 dtPath = (char *)_DtCreateDtDirs(display);
2118 /* Build the paths to save the files to */
2120 toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2121 strlen(TOOL_SETTINGS_FILENAME) +
2122 strlen(dirName) + 4);
2124 homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2125 strlen(HOME_SETTINGS_FILENAME) +
2126 strlen(dirName) + 4);
2129 /* create the directory and filename of where its going to be saved */
2130 sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2131 sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2133 /* Setup the paths used to GET the old files */
2135 toolMovePath= (char *)XtMalloc(strlen(dtPath) +
2136 strlen(TOOL_SETTINGS_FILENAME) + 3);
2138 homeMovePath= (char *)XtMalloc(strlen(dtPath) +
2139 strlen(HOME_SETTINGS_FILENAME) + 3);
2141 /* create the filename of where its going to be saved from */
2143 /* Tool File location */
2144 sprintf( toolMovePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2146 /* Home File location */
2147 sprintf( homeMovePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2150 /* get rid of the tool settings file that is already in home or current */
2151 status = unlink(toolSavePath);
2153 /* get rid of the home settings file that is already in home or current */
2154 status = unlink(homeSavePath);
2157 /* now save tool settings file in home or current determined by savePath */
2158 status = link(toolMovePath, toolSavePath);
2160 /* now save home settings file in home or current determined by savePath */
2161 status = link(homeMovePath, homeSavePath);
2164 XtFree(homeMovePath);
2165 XtFree(toolMovePath);
2166 XtFree(homeSavePath);
2167 XtFree(toolSavePath);
2173 /************************************************************************
2176 * Callback for the Save Settings menupick.
2178 ************************************************************************/
2182 XtPointer client_data,
2183 XtPointer call_data )
2190 FileMgrRec * file_mgr_rec;
2191 DialogData * dialog_data;
2192 FileMgrData * file_mgr_data;
2195 /* Strip the file_mgr_rec from the current widget
2196 * and attach it to the ok callback button
2200 /* Get the file_mgr_rec hanging off the menubar */
2201 mbar = XmGetPostedFromWidget(XtParent(w));
2202 XmUpdateDisplay (w);
2203 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2204 XtGetValues(mbar, args, 1);
2207 /* Ignore accelerators when we're insensitive */
2208 if ((file_mgr_rec->menuStates & SETTINGS) == 0)
2210 XSetInputFocus(XtDisplay(w),
2211 XtWindow(file_mgr_rec->defaultEnvBtn_child),
2212 RevertToParent, CurrentTime);
2216 /* Desensatize the save settings menu pick here */
2217 file_mgr_rec->menuStates &= ~SETTINGS;
2220 /* Get the file_mgr_rec dialog data info */
2221 if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
2223 file_mgr_data = (FileMgrData *) dialog_data->data;
2226 /* Based on the path we must determine if we are saving a Tools or
2227 * HomeDir dtfile view.
2229 if (file_mgr_data->restricted_directory != NULL && file_mgr_data->toolbox)
2230 file_mgr_data->restoreKind = TOOL_RESTORE;
2232 file_mgr_data->restoreKind = HOME_RESTORE;
2235 /* Setup and call the _DtMessageDialog procedure to post the dialog */
2237 if (file_mgr_data->restoreKind == HOME_RESTORE)
2239 tmpStr = (GETMESSAGE(18,29, "Save the current File Manager View window size,\npreferences, and filter settings?\n\nThey will be used for any new File Manager View windows\nstarted from the Front Panel."));
2243 tmpStr = (GETMESSAGE(18,35, "Save the current Application Manager\nView window size, preferences, and filter settings?\n\nThey will be used for any new Application Manager\nwindows started from the Front Panel."));
2245 message = XtNewString(tmpStr);
2247 if(file_mgr_data->title != NULL &&
2248 strcmp(file_mgr_data->helpVol, DTFILE_HELP_NAME) != 0)
2250 tmpStr = GETMESSAGE(18, 16, "Save As Default Options");
2251 title = (char *)XtMalloc(strlen(tmpStr) +
2252 strlen(file_mgr_data->title) + 5);
2253 sprintf(title, "%s - %s", file_mgr_data->title, tmpStr);
2257 tmpStr = GETMESSAGE(18, 32, "File Manager - Save As Default Options");
2258 title = XtNewString(tmpStr);
2260 dlog = (Widget)_DtMessageDialog(mbar, title, message, NULL, TRUE,
2261 SaveDefaultCancelCB, SaveDefaultOkCB, NULL,
2262 HelpRequestCB, False, QUESTION_DIALOG);
2263 file_mgr_rec->defaultEnvBtn_child=dlog;
2268 /* Add array as userdata on the dialog. */
2270 XtSetArg(args[0], XmNuserData, file_mgr_rec);
2271 XtSetValues(dlog, args, 1);
2275 /************************************************************************
2277 * SaveDefaultCancelCB
2278 * Cleanup and unmanage the save settings dialog.
2280 ************************************************************************/
2282 SaveDefaultCancelCB(
2284 XtPointer client_data,
2285 XtPointer call_data )
2287 FileMgrRec * file_mgr_rec;
2290 /* Update the display, and un-post the dialog */
2291 XtUnmanageChild((Widget)client_data);
2292 XmUpdateDisplay((Widget)client_data);
2293 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2294 XtGetValues((Widget)client_data, args, 1);
2297 /* Re-sensatize the save settings menu pick */
2298 file_mgr_rec->menuStates |= SETTINGS;
2301 XtDestroyWidget((Widget)client_data);
2306 /************************************************************************
2309 * Save the current dtfile view as the default environment for
2310 * new dtfiles created.
2312 ************************************************************************/
2316 XtPointer client_data,
2317 XtPointer call_data )
2320 FileMgrRec * file_mgr_rec;
2321 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
2322 char view_number[5];
2326 DialogData * dialog_data;
2327 FileMgrData * file_mgr_data;
2330 char full_path[MAX_PATH + 1];
2333 char * save_directory;
2334 char ** save_branch_list;
2335 FileViewData ** save_selection_list;
2336 int save_selected_file_count;
2339 /* Get the file_mgr_rec hanging off the dialog */
2340 XtUnmanageChild((Widget)client_data);
2341 XmUpdateDisplay ((Widget)client_data);
2342 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2343 XtGetValues((Widget)client_data, args, 1);
2346 /* Re-sensatize the save settings menu pick */
2347 file_mgr_rec->menuStates |= SETTINGS;
2350 /* Get the file_mgr_rec dialog data info */
2352 dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
2353 file_mgr_data = (FileMgrData *) dialog_data->data;
2356 /* Build the path for our env file */
2358 tmp_path = _DtCreateDtDirs(display);
2359 if (tmp_path == NULL)
2361 XtDestroyWidget(client_data);
2366 /* Look and see what type of restore we are doing */
2367 if (file_mgr_data->restoreKind == TOOL_RESTORE)
2369 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
2370 application_args.tool_width = file_mgr_data->width;
2371 application_args.tool_height = file_mgr_data->height;
2375 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
2376 application_args.dir_width = file_mgr_data->width;
2377 application_args.dir_height = file_mgr_data->height;
2383 /* Create the Environment session file */
2385 if ((fd = creat(full_path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2388 tmpStr = GETMESSAGE(18, 17, "Unable to create a file to store the default options.");
2389 title = XtNewString((GETMESSAGE(21,38,"Object Create Error")));
2390 msg = XtNewString(tmpStr);
2391 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
2398 /* Write out the general information */
2400 (void) write (fd, "*", strlen ("*"));
2401 (void) write (fd, DTFILE_CLASS_NAME,strlen (DTFILE_CLASS_NAME));
2402 (void) write (fd, "*view_count: ", strlen ("*view_count: "));
2404 (void) sprintf (view_number, "%d", 1);
2405 (void) write (fd, view_number, strlen (view_number));
2406 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2408 name_list[1] = view_number;
2410 /* Temporarily remove data that we don't need or want saved */
2412 save_host = file_mgr_data->host;
2413 save_directory = file_mgr_data->current_directory;
2414 save_branch_list = file_mgr_data->branch_list;
2415 save_selection_list = file_mgr_data->selection_list;
2416 save_selected_file_count = file_mgr_data->selected_file_count;
2417 file_mgr_data->host = NULL;
2418 file_mgr_data->current_directory = NULL;
2419 file_mgr_data->branch_list = NULL;
2420 file_mgr_data->selection_list = NULL;
2421 file_mgr_data->selected_file_count = 0;
2423 /* Call the encapsulation mechanism to write each dialog */
2425 (void) sprintf (view_number, "%d", 0);
2426 _DtWriteDialogData (dialog_data, fd, name_list);
2427 (void) write (fd, "#\n", strlen ("#\n"));
2429 /* Restore the data that was temporarily removed */
2431 file_mgr_data->host = save_host;
2432 file_mgr_data->current_directory = save_directory;
2433 file_mgr_data->branch_list = save_branch_list;
2434 file_mgr_data->selection_list = save_selection_list;
2435 file_mgr_data->selected_file_count = save_selected_file_count;
2439 XtDestroyWidget(client_data);
2445 /************************************************************************
2447 * SaveSessionCallback
2448 * Get the session name and call the function to save the session.
2450 ************************************************************************/
2453 SaveSessionCallback(
2455 XtPointer client_data,
2456 XtPointer call_data )
2458 char * full_path=NULL;
2459 char * file_name=NULL;
2461 int restore=NORMAL_RESTORE;
2462 Boolean status=FALSE;
2463 char * sessionFileName;
2466 if(view_count == 0 && desktop_data->numIconsUsed == 0)
2468 XChangeProperty (display, XtWindow (toplevel), command_atom,
2469 XA_STRING, 8, PropModeReplace, (unsigned char *)NULL, 0);
2470 XSync(display, False);
2471 FinalizeToolTalkSession( );
2475 status = DtSessionSavePath(w, &full_path, &file_name);
2478 sessionFileName = file_name;
2481 XtFree( (char *)full_path);
2482 full_path = (char *) XtMalloc (sizeof (char) * MAX_PATH);
2483 sprintf( full_path, "%s/%s", dt_path, DTFILE_CLASS_NAME );
2484 sessionFileName = full_path;
2486 SaveSession( full_path );
2488 /* skip to the /.dt/ portion of the sessionFileName */
2489 strPtr = strstr(full_path, "/.dt/");
2490 (void)strcpy(full_path, strPtr);
2492 /* Save off the settings files for both tool and home views */
2494 strPtr = DtStrrchr(full_path, '/');
2497 if ((strncmp(strPtr, "/home", 5) == 0))
2498 restore = HOME_DIR_RESTORE;
2499 else if ((strncmp(strPtr, "/current", 8) == 0))
2500 restore = CURRENT_DIR_RESTORE;
2504 } while ((strPtr != NULL) && (restore == NORMAL_RESTORE));
2506 SaveDesktopInfo(restore);
2508 /* Cop the settings files to the proper dir */
2509 MoveDefaultSettings(restore);
2511 /* Generate the reinvoking command and add it as the property value */
2512 argv = (char **) XtMalloc(3 * sizeof(char *));
2513 argv[0] = XtNewString(application_name);
2514 argv[1] = XtNewString("-session");
2515 argv[2] = XtNewString(sessionFileName);
2516 XSetCommand(XtDisplay(toplevel), XtWindow(toplevel), argv, 3);
2518 XtFree ((char *) argv[0]);
2519 XtFree ((char *) argv[1]);
2520 XtFree ((char *) argv[2]);
2521 XtFree ((char *) argv);
2523 XtFree ((char *) full_path);
2524 XtFree ((char *) file_name);
2527 /************************************************************************
2530 * Save the current File Manager session as a set of resources
2531 * within the file denoted by path.
2533 ************************************************************************/
2540 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2542 char view_number[5];
2544 char workspaceNumber[5];
2546 Atom * ws_presence = NULL;
2547 char * workspace_name=NULL;
2548 unsigned long num_workspaces = 0;
2552 unsigned long nitems;
2553 unsigned long leftover;
2554 WM_STATE * wm_state;
2556 DialogData * dialog_data;
2557 FileMgrData * file_mgr_data;
2558 FileMgrRec * file_mgr_rec;
2563 WorkspaceRec * workspaceInfo;
2566 char *actualSavedTitle;
2568 /* This needs to be done because name_list is static and the values
2569 can be changed during the routine. This means that they need to be
2570 NULL'd out each pass */
2571 name_list[1] = NULL;
2572 name_list[2] = NULL;
2573 name_list[3] = NULL;
2574 name_list[4] = NULL;
2575 name_list[5] = NULL;
2577 /* Disable any message box display during save session */
2579 message_display_enabled = False;
2582 /* Create the session file */
2584 if ((fd = creat (path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2586 tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2587 msg = XtNewString(tmpStr);
2588 _DtSimpleError (application_name, DtError, NULL, msg);
2590 message_display_enabled = True;
2596 /* Write out the general information */
2598 /* Number of dtfile views */
2599 (void) write (fd, "*", strlen ("*"));
2600 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2601 (void) write (fd, "*view_count: ", strlen ("*view_count: "));
2603 if (trashFileMgrData)
2605 if (trashFileMgrData->file_mgr_rec)
2606 (void) sprintf (view_number, "%d", view_count + 1);
2608 (void) sprintf (view_number, "%d", view_count);
2612 (void) sprintf (view_number, "%d", view_count);
2614 (void) write (fd, view_number, strlen (view_number));
2615 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2617 (void) write (fd, "*", strlen ("*"));
2618 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2619 (void) write (fd, "*showFilesystem: ", strlen ("*showFilesystem: "));
2622 (void) write (fd, "True", strlen ("True"));
2624 (void) write (fd, "False", strlen ("False"));
2625 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2627 (void) write (fd, "*", strlen ("*"));
2628 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2629 (void) write (fd, "*restrictMode: ", strlen ("*restrictMode: "));
2632 (void) write (fd, "True", strlen ("True"));
2634 (void) write (fd, "False", strlen ("False"));
2635 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2637 (void) write (fd, "*", strlen ("*"));
2638 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2639 (void) write (fd, "*openFolder: ", strlen ("*openFolder: "));
2641 if(openDirType == NEW)
2642 (void) write (fd, "NEW", strlen ("NEW"));
2644 (void) write (fd, "CURRENT", strlen ("CURRENT"));
2645 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2648 name_list[1] = view_number;
2652 /* Write out each of the view's resources */
2653 /* start with -1 so we can include the trash dialog */
2654 for (i = -1; i < view_count; i++)
2659 dialog_data = (DialogData *) trashDialogData;
2665 dialog_data = (DialogData *) view_set[i]->dialog_data;
2668 file_mgr_data = (FileMgrData *) dialog_data->data;
2669 if(i == -1 && trashDialogData)
2670 file_mgr_data->IsTrashCan = True;
2671 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
2672 if(file_mgr_rec == NULL)
2675 /* This is a bug fix ... We don't want to save the title if the
2676 View is the Trash Can of if it is an Application Manager. This
2677 is because if the user saves a session in one Locale, then logs
2678 in in another, the Title will be in the locale that the session was
2679 saved in rather then the new local. So let's save the Title,
2680 Null it out, Save the session info, and finally restore the Title.
2682 if(i == -1 || file_mgr_data->toolbox)
2684 /* the Trash Can or toolbox (i.e. Application Manager) */
2685 actualSavedTitle = file_mgr_data->title;
2686 file_mgr_data->title = NULL;
2690 /* Getting the WM_STATE property to see if iconified or not */
2691 XGetWindowProperty (display, XtWindow (file_mgr_rec->shell),
2692 wm_state_atom, 0L, (long) BUFSIZ, False,
2693 wm_state_atom, &actual_type, &actual_format,
2694 &nitems, &leftover, (unsigned char **) &wm_state);
2696 /* Write out if iconified our not */
2698 write (fd, "*", strlen ("*"));
2699 write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2700 sprintf (view_number, "%d", view_index);
2701 write (fd, ".", strlen ("."));
2702 write (fd, view_number, strlen (view_number));
2704 (void) write (fd, ".iconify: ", strlen (".iconify: "));
2706 if (wm_state->state == IconicState)
2707 write (fd, "True\n", strlen ("True\n"));
2709 write (fd, "False\n", strlen ("False\n"));
2712 /* Get the workspaces for this dt by accessing the property. */
2714 if (DtWsmGetWorkspacesOccupied (display, XtWindow (file_mgr_rec->shell),
2715 &ws_presence, &num_workspaces) == Success)
2717 write (fd, "*", strlen ("*"));
2718 write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2719 (void) write (fd, ".", strlen ("."));
2720 (void) write (fd, view_number, strlen (view_number));
2721 (void) write (fd, ".workspace: ", strlen (".workspace: "));
2724 for (j = 0; j < num_workspaces; j++)
2726 if (j != 0) (void) write (fd, "*", strlen ("*"));
2727 workspace_name = XGetAtomName (display, ws_presence[j]);
2728 (void) write (fd, workspace_name, strlen (workspace_name));
2729 XtFree ((char *) workspace_name);
2733 (void) write (fd, "\n", strlen ("\n"));
2734 XFree((char *)ws_presence);
2738 /* Call the encapsulation mechanism to write each dialog */
2741 _DtWriteDialogData (trashDialogData, fd, name_list);
2743 _DtWriteDialogData ((DialogData *)view_set[i]->dialog_data,
2745 (void) write (fd, "#\n", strlen ("#\n"));
2750 file_mgr_data->title = actualSavedTitle;
2756 * Save off help dialog information for each workspace.
2757 * These are the help dialogs used for the desktop objects.
2759 name_list[1] = WS_LOAD_RES_HEADER;
2760 name_list[2] = workspaceNumber;
2761 name_list[3] = number;
2763 for (i = 0; i < desktop_data->numWorkspaces; i++)
2765 workspaceInfo = desktop_data->workspaceData[i];
2768 * Save number of secondary help dialogs in format:
2769 * *Dtfile.Workspace.<WS#>.secondaryHelpDialogCount: <#>
2771 write(fd, "*", strlen("*"));
2772 write(fd, DTFILE_CLASS_NAME, strlen(DTFILE_CLASS_NAME));
2773 write(fd, WS_RES_HEADER, strlen(WS_RES_HEADER));
2774 sprintf(workspaceNumber, "%d", i);
2775 write(fd, workspaceNumber, strlen(workspaceNumber));
2776 write(fd, SEC_HELP_RES_HEADER, strlen(SEC_HELP_RES_HEADER));
2777 sprintf(view_number, "%d", workspaceInfo->secondaryHelpDialogCount);
2778 write(fd, view_number, strlen(view_number));
2779 write (fd, "\n#\n", strlen ("\n#\n"));
2781 /* Save each of the secondary help dialogs */
2782 for (j = 0; j < workspaceInfo->secondaryHelpDialogCount; j++)
2784 sprintf(number, "%d", j + 1);
2785 _DtWriteDialogData(workspaceInfo->secondaryHelpDialogList[j],
2789 /* Save the primary help dialog window */
2790 if (workspaceInfo->primaryHelpDialog)
2792 sprintf(number, "%d", 0);
2793 _DtWriteDialogData(workspaceInfo->primaryHelpDialog,
2796 write (fd, "#\n", strlen ("#\n"));
2800 /* Re-able message box display flag after save session */
2801 message_display_enabled = True;
2809 * Given a directory name, this function will see if a view of the parent
2810 * directory is open; if so, then it will update the icon representing
2811 * this icon, in the parent view, so that it is drawn as 'open'. This
2812 * function must only be called if openDirType == NEW.
2818 char * directory_name)
2820 FileViewData * file_view_data = NULL;
2821 DesktopRec *desktopWindow;
2829 char *icon_name, *new_file_type_name, *file_type_name;
2832 /* if directory_name is passed in a NULL, we want to go through all
2833 existing open directories and check to see if there are any open
2834 directories in each of them. This is used at the end of OpenNewView
2835 and the end of ShowNewDirectory */
2836 if (directory_name == NULL)
2838 for (i = 0; i < view_count; i++)
2840 dd = (DialogData *) view_set[i]->dialog_data;
2841 fmd = (FileMgrData *) dd->data;
2843 for(j = 0; j < fmd->directory_count; j++)
2845 ForceMyIconOpen(view_set[i]->host_name,
2846 fmd->directory_set[j]->name);
2852 parent = _DtPName(directory_name);
2853 fname = DName(directory_name);
2855 /* first lets check to see if the directory is open in one of the
2856 open file manager views */
2857 for (i = 0; i < view_count; i++)
2859 dd = (DialogData *) view_set[i]->dialog_data;
2860 fmd = (FileMgrData *) dd->data;
2862 /* loop through until we find the file_view_data structure for the
2863 directory to force open */
2864 if (strcmp(host_name, view_set[i]->host_name) == 0)
2866 for(j = 0; j < fmd->directory_count; j++)
2868 if (strcmp(parent, fmd->directory_set[j]->name) == 0)
2870 for (k = 0; k < fmd->directory_set[j]->file_count; k++)
2872 file_view_data = fmd->directory_set[j]->file_view_data[k];
2873 if (strcmp(file_view_data->file_data->file_name, fname) == 0)
2875 file_view_data = NULL;
2884 fmd = (FileMgrData *)(((DirectorySet *)file_view_data->directory_set)->
2887 file_type_name = file_view_data->file_data->logical_type;
2889 if(fmd->view != BY_NAME)
2890 BuildAndShowIconName(file_type_name, fmd->view,
2891 fmd->show_type, file_view_data->widget);
2895 /* now we need to check to see if the directory being opened has a
2896 representation on the Desktop */
2897 for(i = 0; i < desktop_data->numIconsUsed; i++)
2901 desktopWindow = desktop_data->desktopWindows[i];
2902 file_view_data = desktopWindow->file_view_data;
2904 sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
2905 desktopWindow->file_name);
2906 DtEliminateDots (buf);
2908 if (strcmp(buf, directory_name) == 0 &&
2909 strcmp(desktopWindow->host, host_name) == 0)
2911 file_type_name = file_view_data->file_data->logical_type;
2912 if(desktopIconType == LARGE)
2913 BuildAndShowIconName(file_type_name, BY_NAME_AND_ICON,
2914 SINGLE_DIRECTORY, desktopWindow->iconGadget);
2916 BuildAndShowIconName(file_type_name, BY_NAME_AND_SMALL_ICON,
2917 SINGLE_DIRECTORY, desktopWindow->iconGadget);
2925 /************************************************************************
2928 * Open the file as a resource data base, and use the data to
2929 * create a set of File Manager views.
2931 ************************************************************************/
2936 int type_of_restore,
2939 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2942 XrmName xrm_name[10];
2943 XrmRepresentation rep_type;
2946 char * full_path = NULL;
2947 Boolean status=False;
2951 int num_sec_help_dialogs;
2954 DialogData * dialogData;
2955 struct stat stat_buf;
2958 /* Build the session path if we need to.
2959 * (e.g. When using the -session option)
2961 if (type_of_restore == NORMAL_RESTORE)
2963 status = DtSessionRestorePath(toplevel, &full_path, path);
2968 if (stat(full_path, &stat_buf) != 0)
2970 char *tmpStr, *msg, *title;
2972 tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2973 msg = XtNewString(tmpStr);
2974 title = XtNewString((GETMESSAGE(21,39,"File Open Error")));
2975 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
2983 path = XtNewString(full_path);
2986 /* This prevents the encapsulator from placing the dialogs */
2987 disableDialogAutoPlacement = True;
2989 /* Open the file as a resource database and query it to */
2990 /* get the previously saved view count. */
2992 db = XrmGetFileDatabase (path);
2994 if (type_of_restore == NORMAL_RESTORE)
2996 /* first find out if it should show the file system */
2997 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
2998 xrm_name [1] = XrmStringToQuark ("showFilesystem");
2999 xrm_name [2] = NULL;
3000 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3002 if ((temp = (char *) value.addr) != NULL &&
3003 strcmp (temp, "True") == 0)
3005 showFilesystem = True;
3008 showFilesystem = False;
3011 showFilesystem = True;
3013 /* find out if it should be in restricted mode */
3014 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3015 xrm_name [1] = XrmStringToQuark ("restrictMode");
3016 xrm_name [2] = NULL;
3017 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3019 if ((temp = (char *) value.addr) != NULL &&
3020 strcmp (temp, "True") == 0)
3022 restrictMode = True;
3025 restrictMode = False;
3028 restrictMode = False;
3030 /* find out openFolder mode */
3031 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3032 xrm_name [1] = XrmStringToQuark ("openFolder");
3033 xrm_name [2] = NULL;
3034 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3036 if ((temp = (char *) value.addr) != NULL &&
3037 strcmp (temp, "NEW") == 0)
3042 openDirType = CURRENT;
3045 openDirType = CURRENT;
3048 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3049 xrm_name [1] = XrmStringToQuark ("view_count");
3050 xrm_name [2] = NULL;
3052 /* Load standard dtfile views */
3053 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3055 num_views = atoi (value.addr);
3057 LoadViews(num_views, db, NULL, directory, special_restricted, 0);
3060 /* Restore any desktop help dialogs */
3061 if (type_of_restore == NORMAL_RESTORE)
3063 for (i = 0; i < desktop_data->numWorkspaces; i++)
3065 sprintf(wsNum, "%d", i);
3066 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3067 xrm_name [1] = XrmStringToQuark (WS_LOAD_RES_HEADER);
3068 xrm_name [2] = XrmStringToQuark (wsNum);
3069 xrm_name [3] = XrmStringToQuark (SEC_LOAD_HELP_RES_HEADER);
3070 xrm_name [4] = NULL;
3072 /* Load standard dtfile views */
3073 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3075 num_sec_help_dialogs = atoi (value.addr);
3076 if (num_sec_help_dialogs > 0)
3078 desktop_data->workspaceData[i]->secondaryHelpDialogCount =
3079 num_sec_help_dialogs;
3080 desktop_data->workspaceData[i]->secondaryHelpDialogList =
3081 (DialogData **) XtMalloc(sizeof(DialogData *) *
3082 num_sec_help_dialogs);
3084 for (j = 0; j < num_sec_help_dialogs; j++)
3086 name_list[0] = DTFILE_CLASS_NAME;
3087 name_list[1] = WS_LOAD_RES_HEADER;
3088 name_list[2] = wsNum;
3089 name_list[3] = dialogNum;
3090 name_list[4] = NULL;
3091 sprintf(dialogNum, "%d", j + 1);
3093 _DtGetResourceDialogData(help_dialog, db, name_list);
3094 desktop_data->workspaceData[i]->secondaryHelpDialogList[j]=
3096 ShowDTHelpDialog(NULL, i, HYPER_HELP_DIALOG,
3097 dialogData, NULL, NULL, NULL, NULL,
3103 /* Load the primary help dialog */
3104 name_list[0] = DTFILE_CLASS_NAME;
3105 name_list[1] = WS_LOAD_RES_HEADER;
3106 name_list[2] = wsNum;
3107 name_list[3] = dialogNum;
3108 name_list[4] = NULL;
3109 sprintf(dialogNum, "%d", 0);
3110 dialogData = _DtGetResourceDialogData(help_dialog, db, name_list);
3112 /* Keep only if currently posted */
3113 if (!(((HelpData *)dialogData->data)->displayed))
3115 /* Not currently displayed */
3116 _DtFreeDialogData(dialogData);
3119 desktop_data->workspaceData[i]->primaryHelpDialog = dialogData;
3122 ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
3123 dialogData, NULL, DTFILE_HELP_NAME,
3132 /* Free the Xrm Database */
3133 XrmDestroyDatabase(db);
3134 disableDialogAutoPlacement = False;
3145 extern Tt_message FileCallback();
3146 extern Tt_message SessionCallback();
3148 if ((msg == 0) || tt_is_err( tt_ptr_error( msg ))) {
3153 * Register for notifications on the directory viewed.
3154 * This is done so that requesting apps can notify the
3155 * view if the directory name is changed.
3157 view->pats = ttdt_file_join( view->directory_name, TT_SESSION, 0,
3158 FileCallback, view );
3159 if (tt_is_err( tt_ptr_error( view->pats ))) {
3163 /* Returned patterns automatically get destroyed when msg is destroyed */
3164 ttdt_message_accept( msg, SessionCallback,
3165 _DtGetDialogShell( (DialogData *)view->dialog_data ),
3175 char *directory_name,
3180 XrmName xrm_name[5];
3181 XrmRepresentation rep_type;
3183 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
3184 char view_number[5];
3185 DialogData * dialog_data;
3186 FileMgrData * file_mgr_data;
3188 XClassHint classHints;
3189 char * iconify = NULL;
3190 Boolean iconify_window;
3192 char *title, *tmpTitle;
3194 name_list[1] = view_number;
3195 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3198 /* Get and display view_count views. */
3200 for (i = 0; i < num_views; i++)
3202 struct stat stat_buf;
3204 (void) sprintf (view_number, "%d", i);
3205 xrm_name [1] = XrmStringToQuark (view_number);
3207 /* Get the main dialog data and set up the view */
3209 dialog_data = _DtGetResourceDialogData (file_mgr_dialog, db, name_list);
3210 file_mgr_data = (FileMgrData *) dialog_data->data;
3212 if(file_mgr_data->toolbox && file_mgr_data->title == NULL)
3213 file_mgr_data->title = DtActionLabel("Dtappmgr");
3215 if (stat(file_mgr_data->current_directory, &stat_buf) != 0)
3217 _DtFreeDialogData(dialog_data);
3221 if (trashFileMgrData
3222 && (file_mgr_data->IsTrashCan == True)
3223 && strcmp(file_mgr_data->current_directory, trash_dir) == 0)
3225 trashFileMgrData->view = file_mgr_data->view;
3226 trashFileMgrData->order = file_mgr_data->order;
3227 trashFileMgrData->direction = file_mgr_data->direction;
3228 trashFileMgrData->positionEnabled = file_mgr_data->positionEnabled;
3229 trashFileMgrData->preferences = file_mgr_data->preferences;
3230 file_mgr_data->preferences = NULL;
3231 _DtFreeDialogData(dialog_data);
3235 /* Increment the view list size if necessary and add directory to list */
3237 if (view_count == view_set_size)
3239 view_set_size += 10;
3241 (View **) XtRealloc ((char *)view_set,
3242 sizeof (View **) * view_set_size);
3244 view_set[view_count] = (View *) XtMalloc (sizeof (View));
3245 view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3246 view_set[view_count]->msg = 0;
3247 view_set[view_count]->pats = 0;
3249 if(restoreType == TOOL_RESTORE)
3250 file_mgr_data->toolbox = True;
3252 if(directory_name == NULL)
3254 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3255 view_set[view_count]->directory_name =
3256 XtNewString (file_mgr_data->current_directory);
3260 XtFree(file_mgr_data->current_directory);
3261 file_mgr_data->current_directory = NULL;
3262 XtFree(file_mgr_data->restricted_directory);
3263 file_mgr_data->restricted_directory = NULL;
3265 view_set[view_count]->directory_name = XtNewString(directory_name);
3266 XtFree((char *)file_mgr_data->selection_list);
3267 file_mgr_data->selection_list = NULL;
3268 if(host_name == NULL)
3270 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3271 file_mgr_data->current_directory = XtNewString(directory_name);
3273 file_mgr_data->restricted_directory =
3274 XtNewString(directory_name);
3276 file_mgr_data->restricted_directory =
3281 view_set[view_count]->host_name = XtNewString (host_name);
3282 XtFree(file_mgr_data->host);
3283 file_mgr_data->host = XtNewString(host_name);
3284 file_mgr_data->current_directory = XtNewString(directory_name);
3285 if(special_view && special_restricted != NULL)
3286 file_mgr_data->restricted_directory =
3287 XtNewString(special_restricted);
3289 file_mgr_data->restricted_directory = NULL;
3291 FileMgrBuildDirectories (file_mgr_data,
3292 view_set[view_count]->host_name, directory_name);
3295 /* Get the workspace set the view is contained in */
3296 /* and set the property for the view just created */
3298 xrm_name [2] = XrmStringToQuark ("workspace");
3299 xrm_name [3] = NULL;
3301 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3303 /* Make sure we have some valid workspaces names to work with */
3305 /* value.addr should = NULL if no workspace names */
3306 workspaces = (char *) value.addr;
3309 /* we have no workspace resource so use default */
3312 /* Get and set whether the view is iconic */
3314 xrm_name [2] = XrmStringToQuark ("iconify");
3315 xrm_name [3] = NULL;
3317 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3319 /* If there is an iconify resource and its value is True, */
3320 /* then mark the window as iconified. */
3322 if ((iconify = (char *) value.addr) != NULL &&
3323 strcmp (iconify, "True") == 0)
3325 iconify_window = True;
3329 iconify_window = False;
3332 iconify_window = False;
3334 if(file_mgr_data->positionEnabled == RANDOM_ON &&
3335 (file_mgr_data->object_positions == NULL))
3336 LoadPositionInfo(file_mgr_data);
3338 /* Call _DtShowDialog to create and manage the new window */
3340 tmpTitle = file_mgr_data->title;
3341 title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3343 XtFree(special_title);
3344 special_title = XtNewString(title);
3346 classHints.res_name = title;
3347 classHints.res_class = DTFILE_CLASS_NAME;
3349 _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL,
3350 RemoveTextFields, NULL, workspaces, iconify_window,
3351 special_view, title, &classHints);
3354 file_mgr_data->title = tmpTitle;
3357 ViewAccept( view_set[view_count], msg );
3364 if (openDirType == NEW)
3365 ForceMyIconOpen(file_mgr_data->host, NULL);
3369 /************************************************************************
3373 ************************************************************************/
3376 char current_directory[] )
3381 /* Open a pwd process and read the current working directory */
3382 /* from it. If the open fails or a read fails, then display */
3383 /* the users home directory. */
3385 pwd_file = popen ("pwd", "r");
3388 if (pwd_file != NULL)
3393 if (fread (¤t_directory[i], sizeof(char), 1, pwd_file) != 1)
3401 if (current_directory[i] == '\n')
3407 (void) pclose (pwd_file);
3408 current_directory[i] = NULL;
3412 /************************************************************************
3415 * Given a string that contains a single or set of host:path
3416 * specifications, parse out each host:path, validate it as
3417 * a accessible directory, and call a function to create a
3418 * file manager view of the directory.
3420 ************************************************************************/
3424 char *directory_set,
3431 /* Loop the the directory set string until all of */
3432 /* the path specifications have be parsed. */
3436 separator = DtStrchr (directory_set, ',');
3437 if (separator != NULL)
3440 _DtPathFromInput(directory_set, NULL, &host, &path);
3444 GetNewView (host, path, type, NULL, 0);
3448 char *tmpStr, *errTitle, *errMsg, *dmsg;
3450 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3451 errTitle = XtNewString(tmpStr);
3452 tmpStr = GETMESSAGE(18, 38, "Invalid folder specification, %s");
3453 errMsg = XtNewString(tmpStr);
3454 dmsg = XtMalloc(strlen(errMsg)+strlen(directory_set)+1);
3455 sprintf(dmsg, errMsg, directory_set);
3456 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
3463 /* Free up the unique host and directory names */
3464 /* that were allocated. */
3466 XtFree ((char *) host);
3467 XtFree ((char *) path);
3469 /* Set the starting position of the next host:path */
3471 if (separator != NULL)
3472 directory_set = separator + 1;
3481 /************************************************************************
3484 * Given a directory name, generate a new view for the directory.
3486 ************************************************************************/
3490 char *directory_name,
3492 WindowPosition *position,
3495 DialogData * dialog_data;
3496 DialogInstanceData * instance_data;
3497 FileMgrData * file_mgr_data;
3499 FileMgrRec * file_mgr_rec;
3500 char * real_directory_name;
3502 XClassHint classHints;
3503 char *title, *tmpTitle;
3504 struct stat stat_buf;
3506 char *errMsg = NULL;
3508 DtEliminateDots( directory_name );
3510 if (stat(directory_name, &stat_buf) == 0)
3512 if ((stat_buf.st_mode & S_IFMT) != S_IFDIR)
3514 tmpStr = GETMESSAGE(18, 19,
3515 "The folder specification,\n%s\nis not a folder.");
3516 errMsg = XtNewString(tmpStr);
3521 tmpStr = GETMESSAGE(18, 20,
3522 "The folder specification,\n%s\ndoes not exist.");
3523 errMsg = XtNewString(tmpStr);
3530 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3531 title = XtNewString(tmpStr);
3532 dmsg = XtMalloc(strlen(errMsg) +
3533 strlen(directory_name) + 1);
3534 sprintf(dmsg, errMsg, directory_name);
3535 _DtMessage(toplevel, title, dmsg, NULL, HelpRequestCB);
3544 * Special case: When opening any of the special desktop directory
3545 * icons (Home, Remote Systems, etc), we want to display the correct
3546 * path (i.e. $HOME instead of $HOME/.dt/Desktop/Home). So ... we'll
3547 * do the remap here.
3549 real_directory_name = directory_name;
3551 if(openDirType == NEW || (strcmp(real_directory_name, desktop_dir) == 0))
3553 for(i = 0; i < view_count; i++)
3555 if((strcmp(real_directory_name, view_set[i]->directory_name) == 0 &&
3556 (strcmp(host_name, view_set[i]->host_name) == 0))
3561 Screen *currentScreen;
3564 dialog_data = (DialogData *) view_set[i]->dialog_data;
3565 file_mgr_data = (FileMgrData *) dialog_data->data;
3566 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
3568 screen = XDefaultScreen(display);
3569 currentScreen = XScreenOfDisplay(display, screen);
3570 rootWindow = RootWindowOfScreen(currentScreen);
3572 /* Get the current Workspace */
3573 if (DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
3576 Atom * ws_presence = NULL;
3577 unsigned long num_workspaces = 0;
3580 if (DtWsmGetWorkspacesOccupied(display,
3581 XtWindow(file_mgr_rec->shell), &ws_presence,
3582 &num_workspaces) == Success)
3584 /* Already in this workspace? */
3585 for (k = 0; k < num_workspaces; k++)
3587 if (ws_presence[k] == pCurrent)
3591 if (k >= num_workspaces)
3593 /* Add to the workspace */
3594 ws_presence = (Atom *) XtRealloc((char *)ws_presence,
3595 sizeof (Atom) * (num_workspaces + 1));
3597 ws_presence[num_workspaces] = pCurrent;
3598 DtWsmSetWorkspacesOccupied(display,
3599 XtWindow(file_mgr_rec->shell),
3600 ws_presence, num_workspaces + 1);
3602 XFree((char *)ws_presence);
3606 /* Change the hints to reflect the current workspace */
3607 DtWsmSetWorkspacesOccupied(display,
3608 XtWindow(file_mgr_rec->shell),
3613 /* must map the window to catch iconified windows */
3614 /* a XtPopup will not catch it */
3615 XtMapWidget(file_mgr_rec->shell);
3616 XRaiseWindow(display, XtWindow(file_mgr_rec->shell));
3618 /* announce activity */
3621 msg = tt_pnotice_create(TT_SESSION, "DtActivity_Began");
3622 tt_message_send(msg);
3623 tttk_message_destroy(msg);
3631 /* If in novice mode, force the icon for this dir to the 'Open' state */
3632 if (openDirType == NEW)
3633 ForceMyIconOpen(host_name, directory_name);
3635 /* Increment the list size if necessary. */
3637 if (view_count == view_set_size)
3639 view_set_size += 10;
3641 (View **) XtRealloc ((char *)view_set,
3642 sizeof (View **) * view_set_size);
3645 view_set[view_count] = (View *) XtMalloc (sizeof (View));
3646 view_set[view_count]->msg = 0;
3647 view_set[view_count]->pats = 0;
3649 if (initiating_view != NULL)
3650 dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3654 char full_path[MAX_PATH + 1];
3657 tmp_path = _DtCreateDtDirs(display);
3659 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
3661 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
3663 db = XrmGetFileDatabase (full_path);
3668 restoreType = TOOL_RESTORE;
3669 LoadViews(1, db, NULL, directory_name, type, msg);
3673 restoreType = HOME_RESTORE;
3674 LoadViews(1, db, host_name, directory_name, NULL, msg);
3678 * Free the Xrm Database
3680 XrmDestroyDatabase(db);
3681 dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
3682 file_mgr_data = (FileMgrData *) dialog_data->data;
3685 application_args.tool_width = file_mgr_data->width;
3686 application_args.tool_height = file_mgr_data->height;
3690 application_args.dir_width = file_mgr_data->width;
3691 application_args.dir_height = file_mgr_data->height;
3693 if(file_mgr_data->find != NULL &&
3694 file_mgr_data->current_directory != NULL)
3696 DialogData * dialog_data;
3697 FindData * find_data;
3699 dialog_data = (DialogData *)file_mgr_data->find;
3700 find_data = (FindData *)dialog_data->data;
3702 XtFree(find_data->directories);
3703 if(file_mgr_data->restricted_directory == NULL)
3706 find_data->directories = XtNewString(users_home_dir);
3708 find_data->directories =
3709 XtNewString(file_mgr_data->current_directory);
3713 if(strcmp(file_mgr_data->current_directory,
3714 file_mgr_data->restricted_directory) == 0)
3715 find_data->directories = XtNewString("/");
3717 find_data->directories =
3718 XtNewString(file_mgr_data->current_directory +
3719 strlen(file_mgr_data->restricted_directory));
3723 /* If in novice mode, force the icon for all the dir's to the
3725 if (openDirType == NEW)
3726 ForceMyIconOpen(host_name, NULL);
3728 return((DialogData *)view_set[view_count - 1]->dialog_data);
3731 dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3733 view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3734 file_mgr_data = (FileMgrData *) dialog_data->data;
3736 /* Adjust the view settings if this new view was created */
3737 /* because of an action on a previous view. */
3739 if (initiating_view != NULL)
3741 FileMgrPropagateSettings ((FileMgrData *)initiating_view, file_mgr_data);
3742 /* force new window to come up in flat mode */
3743 file_mgr_data->show_type =
3744 ((PreferencesData *)file_mgr_data->preferences->data)->show_type =
3746 file_mgr_data->view = file_mgr_data->view_single;
3749 /* Call the FileMgr dialog to build up its directory set for */
3750 /* the directory name. */
3751 FileMgrBuildDirectories (file_mgr_data, host_name, real_directory_name);
3755 PreferencesData *preferences_data;
3757 file_mgr_data->toolbox = True;
3758 file_mgr_data->width = application_args.tool_width;
3759 file_mgr_data->height = application_args.tool_height;
3761 /* we want to default for the toolboxes (i.e. Application Manager) to
3762 * look different from a normal File Manager view. Let's turn off
3763 * the iconic_path, current_directory, and status_line.
3765 file_mgr_data->show_iconic_path = False;
3766 file_mgr_data->show_current_dir = False;
3768 file_mgr_data->show_status_line = True;
3771 preferences_data = (PreferencesData *)file_mgr_data->preferences->data;
3772 preferences_data->show_iconic_path = file_mgr_data->show_iconic_path;
3773 preferences_data->show_current_dir = file_mgr_data->show_current_dir;
3774 preferences_data->show_status_line = file_mgr_data->show_status_line;
3778 file_mgr_data->toolbox = False;
3779 file_mgr_data->width = application_args.dir_width;
3780 file_mgr_data->height = application_args.dir_height;
3784 if(file_mgr_data->find != NULL && file_mgr_data->current_directory != NULL)
3786 DialogData * dialog_data;
3787 FindData * find_data;
3789 dialog_data = (DialogData *)file_mgr_data->find;
3790 find_data = (FindData *)dialog_data->data;
3792 XtFree(find_data->directories);
3793 if(file_mgr_data->restricted_directory == NULL)
3796 find_data->directories = XtNewString(users_home_dir);
3798 find_data->directories =
3799 XtNewString(file_mgr_data->current_directory);
3803 if(strcmp(file_mgr_data->current_directory,
3804 file_mgr_data->restricted_directory) == 0)
3805 find_data->directories = XtNewString("/");
3807 find_data->directories =
3808 XtNewString(file_mgr_data->current_directory +
3809 strlen(file_mgr_data->restricted_directory));
3813 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3814 view_set[view_count]->directory_name =
3815 XtNewString (file_mgr_data->current_directory);
3817 /* Load default position info, or inherit, if appropriate */
3818 if ((fmd = (FileMgrData *)initiating_view) &&
3819 (strcmp(fmd->host, host_name) == 0) &&
3820 (strcmp(fmd->current_directory, real_directory_name) == 0))
3822 InheritPositionInfo(fmd, file_mgr_data);
3825 LoadPositionInfo(file_mgr_data);
3828 /* Get the dialog displayed. */
3831 instance_data = (DialogInstanceData *) dialog_data->data;
3832 instance_data->x = position->x;
3833 instance_data->y = position->y;
3834 instance_data->displayed = True; /* @@@ Hack! without this,
3835 _DtShowDialog will ignore
3836 our position info */
3839 tmpTitle = file_mgr_data->title;
3840 title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3842 XtFree(special_title);
3843 special_title = XtNewString(title);
3845 classHints.res_name = title;
3846 classHints.res_class = DTFILE_CLASS_NAME;
3847 initiating_view = NULL;
3849 _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL, RemoveTextFields,
3850 NULL, NULL, False, special_view, title, &classHints);
3853 file_mgr_data->title = tmpTitle;
3856 ViewAccept( view_set[view_count], msg );
3862 /* If in novice mode, force the icon for all the dir's to the 'Open' state */
3863 if (openDirType == NEW)
3864 ForceMyIconOpen(host_name, NULL);
3866 return(dialog_data);
3872 /************************************************************************
3875 * Update the view set array when a view is closed.
3877 ************************************************************************/
3881 DialogData *dialog_data )
3885 FileMgrData * file_mgr_data;
3886 DialogData * tmpDialog_data;
3887 FileMgrRec * file_mgr_rec;
3888 XmManagerWidget file_window;
3889 char *directory_name = NULL;
3890 char *host_name = NULL;
3892 if(dialog_data == trashDialogData)
3894 CloseTrash(NULL, NULL, NULL);
3898 for (i = 0; i < view_count; i++)
3900 if (dialog_data == (DialogData *) (view_set[i]->dialog_data))
3902 tmpDialog_data = (DialogData *) (view_set[i]->dialog_data);
3903 file_mgr_data = (FileMgrData *)tmpDialog_data->data;
3905 directory_name = (char *)XtMalloc( strlen(view_set[i]->directory_name) + 1);
3906 strcpy(directory_name, view_set[i]->directory_name);
3907 host_name = (char *)XtMalloc( strlen(view_set[i]->host_name) + 1);
3908 strcpy(host_name, view_set[i]->host_name);
3910 if (view_set[i]->msg != 0) {
3911 if (view_set[i]->pats != 0) {
3912 ttdt_file_quit( view_set[i]->pats, 0 );
3913 view_set[i]->pats = 0;
3915 tt_message_reply( view_set[i]->msg );
3916 tttk_message_destroy( view_set[i]->msg );
3917 view_set[i]->msg = 0;
3920 XtFree ((char *) view_set[i]->directory_name);
3921 XtFree ((char *) view_set[i]->host_name);
3922 XtFree ((char *) view_set[i]);
3925 for (j = i; j < view_count - 1; j++)
3926 view_set[j] = view_set[j + 1];
3930 _DtHideDialog (dialog_data, True);
3932 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
3933 file_window = (XmManagerWidget)file_mgr_rec->file_window;
3934 /* For next time, unmanage all the icons */
3935 XtUnmanageChildren(file_window->composite.children,
3936 file_window->composite.num_children);
3938 if(PositionFlagSet(file_mgr_data))
3939 SavePositionInfo(file_mgr_data);
3941 /* If it is an Application Manager view, then no point in
3942 caching this dialog, so free it */
3944 if(file_mgr_data->toolbox)
3945 _DtFreeDialog(dialog_data);
3947 _DtFreeDialogData (dialog_data);
3954 /* Update the directory cache list to remove unneeded directories. */
3956 UpdateCachedDirectories (view_set, view_count);
3958 if (openDirType == NEW)
3959 ForceMyIconClosed(host_name, directory_name);
3961 XtFree(directory_name);
3968 /************************************************************************
3971 * This function is called when a view may be changing its
3972 * current directory. It updates the view_set list to the
3973 * new host and directory.
3975 ************************************************************************/
3979 XtPointer file_mgr_data,
3980 char *old_host_name,
3981 char *new_host_name,
3982 char *old_directory_name,
3983 char *new_directory_name )
3988 /* See if the directory is one being viewed */
3990 for (i = 0; i < view_count; i++)
3992 if (((DialogData *) (view_set[i]->dialog_data))->data == file_mgr_data)
3994 if (strcmp (old_host_name, view_set[i]->host_name) == 0 &&
3995 strcmp (old_directory_name, view_set[i]->directory_name) == 0)
3997 XtFree ((char *) view_set[i]->host_name);
3998 view_set[i]->host_name = XtNewString (new_host_name);
4000 XtFree ((char *) view_set[i]->directory_name);
4001 view_set[i]->directory_name = XtNewString (new_directory_name);
4007 /* Update the directory cache list to remove unneeded directories. */
4009 UpdateCachedDirectories (view_set, view_count);
4014 /************************************************************************
4017 * Dispatch ToolTalk events to internal handlers.
4019 ************************************************************************/
4021 static Tt_callback_action
4030 op = tt_message_op( msg );
4031 status = tt_ptr_error( op );
4032 if ((status != TT_OK) || (op == 0)) {
4033 /* Let tttk_Xt_input_handler() Do The Right Thing */
4034 return TT_CALLBACK_CONTINUE;
4036 if (strcmp( op, "DtTypes_Reloaded" ) == 0) {
4038 } else if (strcmp( op, "XSession_Ending" ) == 0) {
4039 if( emptyTrashOnExit )
4043 return TT_CALLBACK_CONTINUE;
4046 tttk_message_destroy( msg );
4047 return TT_CALLBACK_PROCESSED;
4050 /************************************************************************
4053 * Dispatch ToolTalk requests to internal handlers.
4055 ************************************************************************/
4066 op = tt_message_op( msg );
4067 status = tt_ptr_error( op );
4068 if ((status != TT_OK) || (op == 0)) {
4069 /* Let tttk_Xt_input_handler() Do The Right Thing */
4070 return TT_CALLBACK_CONTINUE;
4072 if (strcmp( op, "DtFileSession_Run" ) == 0) {
4073 ViewSessionHandler( msg );
4074 } else if (strcmp( op, "DtFolder_Show" ) == 0) {
4075 ViewDirectoryHandler( msg );
4076 } else if (strcmp( op, "DtHome_Show" ) == 0) {
4077 ViewHomeDirectoryHandler( msg );
4078 } else if (strcmp( op, "DtTools_Show" ) == 0) {
4079 ViewToolsDirectoryHandler( msg );
4080 } else if (strcmp( op, "DtTrash_Show" ) == 0) {
4081 TrashDisplayHandler( msg );
4082 } else if (strcmp( op, "DtTrash_Remove" ) == 0) {
4083 TrashRemoveHandler( msg );
4084 } else if (strcmp( op, "DtTrash_Empty" ) == 0) {
4085 TrashEmptyHandler( msg );
4086 } else if (strcmp( op, "DtTrash_File" ) == 0) {
4087 TrashRemoveNoConfirmHandler( msg );
4088 } else if (strcmp( op, "DtTrash_Restore" ) == 0) {
4089 TrashRestoreHandler( msg );
4090 } else if (strcmp( op, "DtFile_PutOnWorkspace" ) == 0) {
4091 PutOnWorkspaceHandler( msg );
4092 } else if (strcmp( op, "DtFile_Move" ) == 0) {
4093 MoveCopyLinkHandler( msg, MOVE_FILE );
4094 } else if (strcmp( op, "DtFile_Copy" ) == 0) {
4095 MoveCopyLinkHandler( msg, COPY_FILE );
4096 } else if (strcmp( op, "DtFile_Link" ) == 0) {
4097 MoveCopyLinkHandler( msg, LINK_FILE );
4100 return TT_CALLBACK_CONTINUE;
4103 return TT_CALLBACK_PROCESSED;
4109 /************************************************************************
4111 * ViewSessionHandler
4112 * This function is called upon the dt session message
4113 * being received. The name of the session file is extracted
4114 * out of the message and a function is called to create
4115 * a view or set of views described by the file.
4117 ************************************************************************/
4123 char *file = tt_message_file( msg );
4124 tt_message_reply( msg );
4125 tttk_message_destroy( msg );
4127 if (! tt_is_err( tt_ptr_error( file )))
4129 if (view_count == 0 && desktop_data->numIconsUsed == 0)
4131 int session_flag = 0;
4134 session_name = strrchr(file, '/');
4136 LoadDesktopInfo(session_name);
4137 session_flag = RestoreSession (session_name, NORMAL_RESTORE, NULL);
4138 if ((session_flag != 0) && (view_count == 0))
4140 char current_directory[MAX_PATH];
4142 GetPWD(current_directory);
4143 if (current_directory[0] != NULL)
4146 (home_host_name, current_directory, NULL, NULL, 0))
4147 ViewHomeDirectoryHandler (0);
4151 ViewHomeDirectoryHandler (0);
4157 char *tmpStr, *msg, *title;
4159 tmpStr = GETMESSAGE(18, 39, "Cannot start a second File Manager session because a File Manager\nsession is already open on the desktop. If you want to start a new File\nManager session, you must first close all current File Manager windows\nand remove all File Manager objects from the workspaces.");
4160 msg = XtNewString(tmpStr);
4161 title = XtNewString((GETMESSAGE(18,40,"Session Error")));
4162 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
4173 /************************************************************************
4175 * ViewDirectoryHandler
4176 * This function is called upon the dt directory message
4177 * being received. The name of the directory is extracted
4178 * out of the message and a function is called to create
4179 * a view of the directory.
4181 ************************************************************************/
4184 ViewDirectoryHandler(
4191 initiating_view = NULL;
4192 msgFile = tt_message_file( msg );
4193 if (tt_is_err( tt_ptr_error( msgFile ))) msgFile = 0;
4197 if(msgFile && strncmp(msgFile, "~", 1) != 0 )
4199 if((strcmp(users_home_dir, "/") != 0) &&
4200 (strncmp(msgFile, users_home_dir, strlen(users_home_dir)-1) != 0))
4202 char *tmpStr, *errTitle, *errMsg, *dmsg;
4204 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4205 errTitle = XtNewString(tmpStr);
4206 tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4207 errMsg = XtNewString(tmpStr);
4208 dmsg = XtMalloc(strlen(errMsg)+strlen(msgFile)+1);
4209 sprintf(dmsg, errMsg, msgFile);
4210 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4217 tt_message_reply( msg );
4218 tttk_message_destroy( msg );
4224 numArgs = tt_message_args_count( msg );
4225 if (tt_is_err( tt_int_error( numArgs ))) numArgs = 0;
4228 special_view = True;
4229 special_treeType = UNSET_VALUE;
4230 special_treeFiles = UNSET_VALUE;
4231 special_viewType = UNSET_VALUE;
4232 special_orderType = UNSET_VALUE;
4233 special_directionType = UNSET_VALUE;
4234 special_randomType = UNSET_VALUE;
4235 special_restricted = NULL;
4236 special_title = NULL;
4237 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4238 for(i = 0; i < numArgs; i++)
4242 vtype = tt_message_arg_type( msg, i );
4243 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4246 val = tt_message_arg_val( msg, i );
4247 if(strcmp(vtype, "-title") == 0)
4249 special_title = XtNewString(val);
4251 else if(strcmp(vtype, "-help_volume") == 0)
4253 special_helpVol = XtNewString(val);
4255 if(strcmp(vtype, "-tree") == 0)
4257 DtfileStringToTree(val, &special_treeType);
4259 else if(strcmp(vtype, "-tree_files") == 0)
4261 DtfileStringToTreeFiles(val, &special_treeFiles);
4263 else if(strcmp(vtype, VIEW_HEADER) == 0)
4265 DtfileStringToView(val, &special_viewType);
4267 else if(strcmp(vtype, "-order") == 0)
4269 DtfileStringToOrder(val, &special_orderType);
4271 else if(strcmp(vtype, "-direction") == 0)
4273 DtfileStringToDirection(val, &special_directionType);
4275 else if(strcmp(vtype, "-grid") == 0)
4277 DtfileStringToGrid(val, &special_randomType);
4279 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4281 special_restricted = XtNewString(msgFile);
4286 if ((restrictMode) && (!special_restricted))
4290 ptr = strrchr(users_home_dir, '/');
4292 special_restricted = XtNewString(users_home_dir);
4297 else if (restrictMode)
4301 special_view = True;
4302 special_treeType = treeType;
4303 special_treeFiles = treeFiles;
4304 special_viewType = viewType;
4305 special_orderType = orderType;
4306 special_directionType = directionType;
4307 special_randomType = randomType;
4309 ptr = strrchr(users_home_dir, '/');
4311 special_restricted = XtNewString(users_home_dir);
4314 special_title = NULL;
4315 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4319 special_view = False;
4321 OpenDirectories (msgFile, NULL);
4324 tt_message_reply( msg );
4325 tttk_message_destroy( msg );
4331 /************************************************************************
4334 * This function is called upon the dt directory message
4335 * being received. The name of the directory is extracted
4336 * out of the message and a function is called to create
4337 * a view of the directory. This function is passed directly
4338 * to DtActionInvoke to be used as a callback.
4340 ************************************************************************/
4349 DialogData *return_data;
4353 if(root_dir && strncmp(root_dir, "~", 1) != 0 )
4355 if((strcmp(users_home_dir, "/") != 0) &&
4356 (strncmp(root_dir, users_home_dir, strlen(users_home_dir)-1) != 0))
4358 char *tmpStr, *errTitle, *errMsg, *dmsg;
4360 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4361 errTitle = XtNewString(tmpStr);
4362 tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4363 errMsg = XtNewString(tmpStr);
4364 dmsg = XtMalloc(strlen(errMsg)+strlen(root_dir)+1);
4365 sprintf(dmsg, errMsg, root_dir);
4366 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4376 initiating_view = NULL;
4377 special_view = True;
4378 special_treeType = treeType;
4379 special_treeFiles = treeFiles;
4380 special_viewType = viewType;
4381 special_orderType = orderType;
4382 special_directionType = directionType;
4383 special_randomType = randomType;
4386 special_restricted = XtNewString(root_dir);
4389 special_restricted = NULL;
4392 if ((restrictMode) && (!special_restricted))
4396 ptr = strrchr(users_home_dir, '/');
4398 special_restricted = XtNewString(users_home_dir);
4402 special_title = NULL;
4403 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4405 return_data = GetNewView (home_host_name, root_dir, NULL, NULL, msg);
4407 if ((!return_data) && msg)
4409 tt_message_reply(msg);
4410 tttk_message_destroy( msg );
4413 return(return_data);
4418 /************************************************************************
4420 * ViewHomeDirectoryHandler
4421 * This function is called upon the dt home directory message
4422 * being received. The home directory is extracted from the
4423 * users uid and used to open the directory.
4425 ************************************************************************/
4429 ViewHomeDirectoryHandler(
4432 register int i, j, k;
4433 struct passwd * pwInfo;
4436 char full_path[MAX_PATH + 1];
4437 struct stat stat_buf;
4440 /* We have a new view so set initiating_view to null */
4441 initiating_view = NULL;
4443 if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
4445 pwInfo = getpwuid (getuid());
4446 homeDir = pwInfo->pw_dir;
4449 /* Look and see if we have a default environment file present */
4450 tmp_path = _DtCreateDtDirs(display);
4453 if (msg) numArgs = tt_message_args_count(msg);
4454 if (tt_is_err(tt_int_error(numArgs))) numArgs = 0;
4457 special_view = True;
4458 special_treeType = UNSET_VALUE;
4459 special_treeFiles = UNSET_VALUE;
4460 special_viewType = UNSET_VALUE;
4461 special_orderType = UNSET_VALUE;
4462 special_directionType = UNSET_VALUE;
4463 special_randomType = UNSET_VALUE;
4464 special_restricted = NULL;
4465 special_title = NULL;
4466 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4467 for(i = 0; i < numArgs; i++)
4471 vtype = tt_message_arg_type( msg, i );
4472 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4475 val = tt_message_arg_val(msg, i);
4476 if(strcmp(vtype, "-title") == 0)
4478 special_title = XtNewString(val);
4480 else if(strcmp(vtype, "-help_volume") == 0)
4482 special_helpVol = XtNewString(val);
4484 if(strcmp(vtype, "-tree") == 0)
4486 DtfileStringToTree(val, &special_treeType);
4488 else if(strcmp(vtype, "-tree_files") == 0)
4490 DtfileStringToTreeFiles(val, &special_treeFiles);
4492 else if(strcmp(vtype, VIEW_HEADER) == 0)
4494 DtfileStringToView(val, &special_viewType);
4496 else if(strcmp(vtype, "-order") == 0)
4498 DtfileStringToOrder(val, &special_orderType);
4500 else if(strcmp(vtype, "-direction") == 0)
4502 DtfileStringToDirection(val, &special_directionType);
4504 else if(strcmp(vtype, "-grid") == 0)
4506 DtfileStringToGrid(val, &special_randomType);
4508 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4510 special_restricted = XtNewString(val);
4516 else if (restrictMode)
4520 special_view = True;
4521 special_treeType = treeType;
4522 special_treeFiles = treeFiles;
4523 special_viewType = viewType;
4524 special_orderType = orderType;
4525 special_directionType = directionType;
4526 special_randomType = randomType;
4528 ptr = strrchr(users_home_dir, '/');
4530 special_restricted = XtNewString(users_home_dir);
4533 special_title = NULL;
4534 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4537 special_view = False;
4539 if (tmp_path == NULL)
4540 OpenDirectories (homeDir, NULL);
4543 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
4546 /* Stat the file and make sure its there */
4549 if (stat (full_path, &stat_buf) == 0 && numArgs < 1)
4551 restoreType = HOME_RESTORE;
4552 RestoreSession(full_path, HOME_RESTORE, NULL);
4553 restoreType = NORMAL_RESTORE;
4559 ptr = strrchr(users_home_dir, '/');
4561 strcpy(full_path, users_home_dir);
4563 OpenDirectories (full_path, NULL);
4566 else if (numArgs < 1 && stat (full_path, &stat_buf) == 0)
4568 restoreType = HOME_RESTORE;
4569 RestoreSession(full_path, HOME_RESTORE, NULL);
4570 restoreType = NORMAL_RESTORE;
4576 ptr = strrchr(users_home_dir, '/');
4578 if( ptr != users_home_dir )
4581 strcpy(full_path, users_home_dir);
4584 OpenDirectories (full_path, NULL);
4590 tt_message_reply(msg);
4591 tttk_message_destroy(msg);
4595 /************************************************************************
4597 * ViewToolsDirectroyHandler
4598 * This function is called upon the dt tools message
4599 * being received. The names of the tools directories are
4600 * retrieved from libXue, a view is created and the change
4601 * directory dialog for the view is displayed with the
4602 * set of directories contained in the list.
4604 ************************************************************************/
4607 ViewToolsDirectoryHandler(
4611 char * tmp_path = NULL;
4612 char * tool_dir = NULL;
4613 char * msgFile = NULL;
4616 /* We have a new view so set initiating_view to null */
4617 initiating_view = NULL;
4619 /* Look and see if we have a default environment file present */
4620 tmp_path = _DtCreateDtDirs(display);
4622 if (msg) msgFile = tt_message_file(msg);
4623 if (tt_is_err(tt_ptr_error(msgFile))) msgFile = 0;
4625 if (msg) numArgs = tt_message_args_count(msg);
4626 if (tt_is_err(tt_int_error( numArgs ))) numArgs = 0;
4632 char *link_point = NULL;
4633 char *root_toolbox = NULL;
4634 char *user_install_point = NULL;
4636 special_view = True;
4637 special_treeType = treeType;
4638 special_treeFiles = treeFiles;
4639 special_viewType = viewType;
4640 special_orderType = orderType;
4641 special_directionType = directionType;
4642 special_randomType = randomType;
4643 special_restricted = XtNewString(msgFile);
4644 special_title = NULL;
4645 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4646 for(i = 0; i < numArgs; i++)
4650 vtype = tt_message_arg_type( msg, i );
4651 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4654 val = tt_message_arg_val( msg, i );
4655 if(strcmp(vtype, "-title") == 0)
4657 special_title = XtNewString(val);
4659 else if(strcmp(vtype, "-help_volume") == 0)
4661 special_helpVol = XtNewString(val);
4663 else if(strcmp(vtype, "-root") == 0)
4665 root_toolbox = XtNewString(val);
4667 else if(strcmp(vtype, "-common_link_point") == 0)
4669 link_point = XtNewString(val);
4671 else if(strcmp(vtype, "-user_install_point") == 0)
4673 user_install_point = XtNewString(val);
4675 if(strcmp(vtype, "-tree") == 0)
4677 DtfileStringToTree(val, &special_treeType);
4679 else if(strcmp(vtype, "-tree_files") == 0)
4681 DtfileStringToTreeFiles(val, &special_treeFiles);
4683 else if(strcmp(vtype, VIEW_HEADER) == 0)
4685 DtfileStringToView(val, &special_viewType);
4687 else if(strcmp(vtype, "-order") == 0)
4689 DtfileStringToOrder(val, &special_orderType);
4691 else if(strcmp(vtype, "-direction") == 0)
4693 DtfileStringToDirection(val, &special_directionType);
4695 else if(strcmp(vtype, "-grid") == 0)
4697 DtfileStringToGrid(val, &special_randomType);
4699 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4706 /* Due to the use of tooltalk messaging, app manager objects
4707 that are dragged either to the desktop or to the front
4708 panel are identified by their fully resolved names (ie.
4709 /usr/dt/appconfig/appmanager/$LANG/.... as opposed to
4710 /var/dt/appconfig/appmanager/$DTUSERSESSION/....). In order
4711 for the File Manager to treat these objects as links existing
4712 in the /var/.... directory, we use the following ugly code:
4714 1. Search the incoming path for $LANG (if you can't find
4715 $LANG, try C since this is the default).
4716 2. Concatenate the path following $LANG to the path for the
4717 root toolbox (this comes in with the tooltalk message
4718 so that we don't have to hardcode it).
4719 3. Call OpenDirectories with the new path that you have
4720 created and with the root toolbox path as the restricted
4723 This problem is further complicated by:
4724 1. Users traversing into APPGROUPs.
4725 2. Users opening the parent folders for workspace APPGROUPs.
4727 For situation 1, File Manager kicks the user into the App Manager
4728 if he/she traverses into an APPGROUP. BUT we don't want to
4729 make modifications to the path as we do above.
4730 So, if there is nothing following $LANG or if we can't find
4732 (ie. /var/dt/appconfig/appmanager/$DTUSERSESSION), call
4733 OpenDirectories with no parameter changes.
4735 For situation 2, File Manager is unable to distinguish between
4736 workspace objects dragged from /usr/.... or /var/...., so
4737 the parent folder for all workspace APPGROUPS is considered to
4738 be in the /var path. In addition to the OpenAppGroup action,
4739 there is an OpenParentAppGroup action which also triggers
4740 ViewToolsDirectoryHandler but sends in an additional
4741 parameter (user_install_point).
4742 If we know that this msg was generated by the OpenParentAppGroup
4744 AND nothing follows $LANG.
4745 Modify the parameters as above.
4746 OR we can't find $LANG but we can find the user_install_point
4747 (user's personal appgroup path).
4748 Concatenate the path following .dt/appmanager to the path for the
4749 root toolbox. Call OpenDirectories with the new path and the
4750 root toolbox as the restricted directory.
4758 if ((user_install_point) &&
4759 (ptr = strstr(msgFile, user_install_point)))
4761 ptr += strlen(user_install_point);
4762 tool_dir = XtMalloc(strlen(root_toolbox) + strlen(ptr) + 1);
4763 sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4764 XtFree(special_restricted);
4765 special_restricted = XtNewString(root_toolbox);
4769 ptr = strstr(msgFile, link_point);
4774 link_point = XtNewString("C");
4775 ptr = strstr(msgFile, link_point);
4780 ptr += strlen(link_point);
4781 if (strcmp(ptr, "") != 0)
4783 tool_dir = XtMalloc(strlen(root_toolbox) +
4785 sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4786 XtFree(special_restricted);
4787 special_restricted = XtNewString(root_toolbox);
4789 else if (user_install_point)
4791 tool_dir = XtNewString(root_toolbox);
4792 XtFree(special_restricted);
4793 special_restricted = XtNewString(root_toolbox);
4800 XtFree(root_toolbox);
4801 XtFree(user_install_point);
4803 else if (restrictMode)
4807 special_view = True;
4808 ptr = strrchr(users_home_dir, '/');
4810 special_restricted = XtNewString(users_home_dir);
4814 special_view = False;
4817 if (tmp_path == NULL)
4820 OpenDirectories (tool_dir, special_restricted);
4821 else if (msgFile != NULL)
4822 OpenDirectories (msgFile, special_restricted);
4826 char full_path[MAX_PATH + 1];
4827 struct stat stat_buf;
4829 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
4832 /* Stat the file and make sure its there */
4833 if (stat (full_path, &stat_buf) == 0 && numArgs > 0)
4835 DialogData * dialog_data;
4836 FileMgrData * file_mgr_data;
4838 restoreType = TOOL_RESTORE;
4840 RestoreSession(full_path, TOOL_RESTORE, tool_dir);
4842 RestoreSession(full_path, TOOL_RESTORE, msgFile);
4843 dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
4844 file_mgr_data = (FileMgrData *) dialog_data->data;
4845 application_args.tool_width = file_mgr_data->width;
4846 application_args.tool_height = file_mgr_data->height;
4847 restoreType = NORMAL_RESTORE;
4852 OpenDirectories (tool_dir, special_restricted);
4853 else if (msgFile != NULL)
4854 OpenDirectories (msgFile, special_restricted);
4863 tt_message_reply( msg );
4864 tttk_message_destroy( msg );
4872 /************************************************************************
4875 * This function is called upon the DtSTOP message.
4877 ************************************************************************/
4882 XtPointer clientData,
4883 String * messageFields,
4886 tt_message_reply( msg );
4887 tttk_message_destroy( msg );
4888 FinalizeToolTalkSession( );
4894 * This is the message handling function responsible for reloading
4895 * the filetype and action databases, and then updating our collection
4896 * of action menu items, and updating all open views.
4900 ReloadDatabases(void)
4903 DialogData * dialog_data;
4904 FileMgrData * file_mgr_data;
4905 FileMgrRec * file_mgr_rec;
4906 FileViewData *file_view_data;
4907 DesktopRec *desktopWindow;
4911 XmeFlushIconFileCache ( NULL );
4913 /* Update each directory_set view, both mapped and not */
4914 UpdateDirectorySet();
4916 /* Force action menus to update the next time they're posted */
4917 XtFree(fileMgrPopup.action_pane_file_type);
4918 fileMgrPopup.action_pane_file_type = NULL;
4919 XtFree(desktop_data->popupMenu->action_pane_file_type);
4920 desktop_data->popupMenu->action_pane_file_type = NULL;
4922 /* Update each view */
4923 for (i = 0; i < view_count; i++)
4925 dialog_data = (DialogData *)view_set[i]->dialog_data;
4926 file_mgr_data = (FileMgrData *) dialog_data->data;
4927 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
4928 XtFree(file_mgr_rec->action_pane_file_type);
4929 file_mgr_rec->action_pane_file_type = NULL;
4930 UpdateFilterAfterDBReread(file_mgr_data->filter_active);
4931 UpdateFilterAfterDBReread(file_mgr_data->filter_edit);
4932 FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
4935 /* go through the desktop objects to make sure the icons change
4936 * Do this by setting the logical_type to -l, CheckDesktop will
4937 * then update the logical type and the icon
4939 for(i = 0; i < desktop_data->numIconsUsed; i++)
4941 desktopWindow = desktop_data->desktopWindows[i];
4942 file_view_data = desktopWindow->file_view_data;
4944 file_view_data->file_data->logical_type = NULL;
4951 * Whenever a directory view or drawer view is closed, we need to remove
4952 * any of its text field children, so that they will not magically reappear
4953 * should this view be reused from the cache to view the same directory later.
4958 XtPointer client_data,
4959 DialogData * old_dialog_data,
4960 DialogData * new_dialog_data)
4962 FileMgrRec * file_mgr_rec;
4963 XmManagerWidget file_window;
4967 file_mgr_rec = (FileMgrRec *) _DtGetDialogInstance(old_dialog_data);
4968 file_window = (XmManagerWidget) file_mgr_rec->file_window;
4969 num_children = file_window->composite.num_children;
4971 for (i = 0; i < num_children; i++)
4973 if (XmIsTextField(file_window->composite.children[i]))
4974 XtDestroyWidget(file_window->composite.children[i]);
4977 _DtFreeDialogData (new_dialog_data);
4982 * This function searches the view list, and returns the file_mgr_data
4983 * associated with the passed-in widget.
4991 DialogData * dialog_data;
4992 FileMgrData * file_mgr_data;
4994 for (i = 0; i < view_count; i++)
4996 dialog_data = (DialogData *) view_set[i]->dialog_data;
4997 file_mgr_data = (FileMgrData *) dialog_data->data;
4999 if (w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->file_window ||
5000 w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->shell)
5001 return(file_mgr_data);
5009 CheckForOpenDirectory(
5010 FileViewData *order_list,
5011 DirectorySet *directory_set,
5012 FileMgrData *file_mgr_data,
5013 char * logical_type)
5017 char *file_type_name, *new_file_type_name;
5018 char directory_name[MAX_PATH];
5019 char * real_dir_name;
5020 FileMgrRec *file_mgr_rec;
5022 PixmapData *pixmapData = NULL;
5024 if (file_mgr_data->view == BY_NAME_AND_ICON)
5029 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5031 if (strcmp (directory_set->name, "/") != 0)
5032 sprintf( directory_name, "%s/%s", directory_set->name, order_list->file_data->file_name);
5034 sprintf( directory_name, "%s%s", directory_set->name, order_list->file_data->file_name );
5036 (void) DtEliminateDots (directory_name);
5038 real_dir_name = XtNewString(directory_name);
5040 for(i = 0; i < view_count; i++)
5042 if(strcmp(real_dir_name, view_set[i]->directory_name) == 0)
5044 file_type_name = order_list->file_data->logical_type;
5045 new_file_type_name = (char *)XtMalloc(strlen(file_type_name)
5046 + strlen(ICON_OPEN_PREFIX) + 1);
5047 sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5048 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5051 file_mgr_rec->file_window,
5053 XtFree(new_file_type_name);
5057 XtFree(real_dir_name);
5059 if(pixmapData == NULL || pixmapData->iconFileName == NULL)
5061 if( pixmapData != NULL )
5063 DtDtsFreeAttributeValue(pixmapData->hostPrefix);
5064 DtDtsFreeAttributeValue(pixmapData->instanceIconName);
5065 DtDtsFreeAttributeValue(pixmapData->iconName);
5066 XtFree((char *)pixmapData);
5069 pixmapData = _DtRetrievePixmapData(logical_type,
5072 file_mgr_rec->file_window,
5081 * The is the menu callback function for cleaning up a view.
5087 XtPointer client_data,
5088 XtPointer call_data)
5092 FileMgrRec * file_mgr_rec;
5093 DialogData * dialog_data;
5094 FileMgrData * file_mgr_data;
5096 XmManagerWidget file_window;
5098 FileViewData * file_view_data;
5099 XRectangle textExtent;
5102 if ((int) client_data == FM_POPUP)
5105 mbar = XmGetPostedFromWidget(XtParent(w));
5108 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
5109 XtGetValues(mbar, args, 1);
5111 /* Ignore accelerators when we're insensitive */
5112 if ((file_mgr_rec->menuStates & CLEAN_UP) == 0)
5115 /* Ignore accelerators received after we're unposted */
5116 if ((dialog_data = _DtGetInstanceData((XtPointer)file_mgr_rec)) == NULL)
5119 file_mgr_data = (FileMgrData *)dialog_data->data;
5121 /* Reset the grid size, so it will be recalculated later. */
5122 file_mgr_data->grid_height = 0;
5123 file_mgr_data->grid_width = 0;
5125 if(file_mgr_data->object_positions)
5126 FreePositionInfo(file_mgr_data);
5128 /* CLEAN_UP_OP is not really a menu state.
5129 It's a flag to let GetFileData in FileMgr.c (call when the directory
5130 is being reread) not to reload icon positions from the .!dt<userid> file.
5132 file_mgr_rec->menuStates |= CLEAN_UP_OP;
5134 /* Re-layout the view */
5135 FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
5137 if ((file_mgr_data->show_type == SINGLE_DIRECTORY) &&
5138 (file_mgr_data->view != BY_ATTRIBUTES) &&
5139 (file_mgr_data->positionEnabled == RANDOM_ON))
5141 ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5146 /* Update the preferences dialog */
5147 ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5151 /* Move any text widget, to keep them in sync with their icons */
5152 file_window = (XmManagerWidget)file_mgr_rec->file_window;
5154 for (j = 0; j < file_window->composite.num_children; j++)
5156 if (XmIsTextField(file_window->composite.children[j]) &&
5157 !file_window->composite.children[j]->core.being_destroyed)
5159 XtSetArg(args[0], XmNuserData, &name);
5160 XtGetValues(file_window->composite.children[j], args, 1);
5162 /* Find the associated icon data */
5163 /* @@@ this won't work for tree mode! */
5164 for (i = 0; i < file_mgr_data->directory_set[0]->file_count; i++)
5166 file_view_data = file_mgr_data->directory_set[0]->file_view_data[i];
5167 if (strcmp(name, file_view_data->file_data->file_name) == 0)
5169 _DtIconGetTextExtent_r(file_view_data->widget, &textExtent);
5172 (Dimension)(file_window->composite.children[j]->core.height -
5173 textExtent.height)/(Dimension)2;
5174 XtSetArg (args[0], XmNx, x);
5175 XtSetArg (args[1], XmNy, y);
5176 XtSetValues (file_window->composite.children[j], args, 2);
5183 if ((file_mgr_rec->menuStates & CLEAN_UP_OP))
5184 file_mgr_rec->menuStates &= ~CLEAN_UP_OP;
5187 /*************************************<->*************************************
5189 * DtfileCvtStringToObjPlace (args, numArgs, fromVal, toVal)
5194 * This function converts a string to an desktop placement scheme description.
5199 * args = NULL (don't care)
5201 * numArgs = 0 (don't care)
5203 * fromVal = resource value to convert
5208 * toVal = descriptor to use to return converted value
5210 *************************************<->***********************************/
5213 DtfileCvtStringToObjPlace (
5219 unsigned char *pch = (unsigned char *) (fromVal->addr);
5220 unsigned char *pchNext;
5224 Boolean fPrimarySet = False;
5225 Boolean fSecondarySet = False;
5228 * Icon placement layout values:
5231 #define OBJ_PLACE_BOTTOM_STR (unsigned char *)"bottom"
5232 #define OBJ_PLACE_LEFT_STR (unsigned char *)"left"
5233 #define OBJ_PLACE_RIGHT_STR (unsigned char *)"right"
5234 #define OBJ_PLACE_TOP_STR (unsigned char *)"top"
5238 * Convert the icon placement resource value:
5243 while (*pch && _DtNextToken (pch, &len, &pchNext))
5251 if (_DtStringsAreEquivalent((char *)pch, (char *)OBJ_PLACE_BOTTOM_STR))
5255 cval |= OBJ_PLACE_BOTTOM_PRIMARY;
5258 else if (!fSecondarySet)
5261 (OBJ_PLACE_BOTTOM_PRIMARY | OBJ_PLACE_TOP_PRIMARY)))
5263 cval |= OBJ_PLACE_BOTTOM_SECONDARY;
5264 fSecondarySet = True;
5273 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_LEFT_STR))
5277 cval |= OBJ_PLACE_LEFT_PRIMARY;
5280 else if (!fSecondarySet)
5283 (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY)))
5285 cval |= OBJ_PLACE_LEFT_SECONDARY;
5286 fSecondarySet = True;
5294 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_RIGHT_STR))
5298 cval |= OBJ_PLACE_RIGHT_PRIMARY;
5301 else if (!fSecondarySet)
5304 (OBJ_PLACE_RIGHT_PRIMARY | OBJ_PLACE_LEFT_PRIMARY)))
5306 cval |= OBJ_PLACE_RIGHT_SECONDARY;
5307 fSecondarySet = True;
5315 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_TOP_STR))
5319 cval |= OBJ_PLACE_TOP_PRIMARY;
5322 else if (!fSecondarySet)
5325 (OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_BOTTOM_PRIMARY)))
5327 cval |= OBJ_PLACE_TOP_SECONDARY;
5328 fSecondarySet = True;
5341 cval = OBJ_PLACE_TOP_PRIMARY;
5345 if (cval & (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY))
5347 cval |= OBJ_PLACE_TOP_SECONDARY;
5350 cval |= OBJ_PLACE_RIGHT_SECONDARY;
5355 (*toVal).size = sizeof (long);
5356 (*toVal).addr = (XtPointer) &cval;
5358 } /* END OF FUNCTION DtfileCvtStringToObjPlace */
5360 /*************************************<->*************************************
5362 * _DtNextToken (pchIn, pLen, ppchNext)
5372 * pchIn = pointer to start of next token
5377 * pLen = pointer to integer containing number of characters in next token
5378 * ppchNext = address of pointer to following token
5380 * Return = next token or NULL
5387 *************************************<->***********************************/
5389 static unsigned char
5391 unsigned char *pchIn,
5393 unsigned char **ppchNext)
5395 unsigned char *pchR = pchIn;
5400 for (i = 0; ((chlen = mblen ((char *)pchIn, MB_CUR_MAX)) > 0); i++)
5401 /* find end of word: requires singlebyte whitespace terminator */
5403 if ((chlen == 1) && isspace (*pchIn))
5411 for (i = 0; *pchIn && !isspace (*pchIn); i++, pchIn++)
5412 /* find end of word */
5417 /* skip to next word */
5419 while (pchIn && (mblen ((char *)pchIn, MB_CUR_MAX) == 1) && isspace (*pchIn))
5421 while (pchIn && isspace (*pchIn))
5438 } /* END OF FUNCTION _DtNextToken */
5440 /*************************************<->*************************************
5442 * DtfileCvtStringToOpenDir (args, numArgs, fromVal, toVal)
5447 * This function converts a string to an desktop placement scheme description.
5452 * args = NULL (don't care)
5454 * numArgs = 0 (don't care)
5456 * fromVal = resource value to convert
5461 * toVal = descriptor to use to return converted value
5463 *************************************<->***********************************/
5466 DtfileCvtStringToOpenDir (
5472 char * in_str = (char *) (fromVal->addr);
5475 toVal->size = sizeof (int);
5476 toVal->addr = (XtPointer) &i;
5478 if (_DtStringsAreEquivalent (in_str, "current"))
5480 else if (_DtStringsAreEquivalent (in_str, "new"))
5489 XtStringConversionWarning ((char *)fromVal->addr, "OpenDir");
5494 /*************************************<->*************************************
5496 * DtfileCvtStringToDTIcon (args, numArgs, fromVal, toVal)
5501 * This function converts a string to an desktop placement scheme description.
5506 * args = NULL (don't care)
5508 * numArgs = 0 (don't care)
5510 * fromVal = resource value to convert
5515 * toVal = descriptor to use to return converted value
5517 *************************************<->***********************************/
5520 DtfileCvtStringToDTIcon (
5526 char * in_str = (char *) (fromVal->addr);
5529 toVal->size = sizeof (int);
5530 toVal->addr = (XtPointer) &i;
5532 if (_DtStringsAreEquivalent (in_str, "large"))
5534 else if (_DtStringsAreEquivalent (in_str, "small"))
5536 else if (_DtStringsAreEquivalent (in_str, "default"))
5537 i = LARGE; /* for now, eventually want to look at screen width/height*/
5545 XtStringConversionWarning ((char *)fromVal->addr, "DesktopIcon");
5551 DtfileCvtStringToTree (
5557 char * in_str = (char *) (fromVal->addr);
5560 toVal->size = sizeof (int);
5561 toVal->addr = (XtPointer) &i;
5563 DtfileStringToTree(in_str, &i);
5567 DtfileCvtStringToTreeFiles (
5573 char * in_str = (char *) (fromVal->addr);
5576 toVal->size = sizeof (int);
5577 toVal->addr = (XtPointer) &i;
5579 DtfileStringToTreeFiles(in_str, &i);
5583 DtfileCvtStringToView (
5589 char * in_str = (char *) (fromVal->addr);
5592 toVal->size = sizeof (int);
5593 toVal->addr = (XtPointer) &i;
5595 DtfileStringToView(in_str, &i);
5599 DtfileCvtStringToOrder (
5605 char * in_str = (char *) (fromVal->addr);
5608 toVal->size = sizeof (int);
5609 toVal->addr = (XtPointer) &i;
5611 DtfileStringToOrder(in_str, &i);
5615 DtfileCvtStringToDirection (
5621 char * in_str = (char *) (fromVal->addr);
5624 toVal->size = sizeof (int);
5625 toVal->addr = (XtPointer) &i;
5627 DtfileStringToDirection(in_str, &i);
5631 DtfileCvtStringToGrid (
5637 char * in_str = (char *) (fromVal->addr);
5640 toVal->size = sizeof (int);
5641 toVal->addr = (XtPointer) &i;
5643 DtfileStringToGrid(in_str, &i);
5652 FileMgrData *file_mgr_data;
5653 DialogData *dialog_data;
5655 for(i = 0; i < view_count; i++)
5657 if(strcmp(directory, view_set[i]->directory_name) == 0 &&
5658 strcmp(host, view_set[i]->host_name) == 0)
5660 dialog_data = (DialogData *) view_set[i]->dialog_data;
5661 file_mgr_data = (FileMgrData *) dialog_data->data;
5662 return(file_mgr_data);
5669 GetRestrictedDirectory (
5673 FileMgrData *file_mgr_data;
5674 FileMgrRec *file_mgr_rec;
5675 DialogData *dialog_data;
5677 for(i = 0; i < view_count; i++)
5679 dialog_data = (DialogData *) view_set[i]->dialog_data;
5680 file_mgr_data = (FileMgrData *) dialog_data->data;
5681 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5682 if(file_mgr_rec->current_directory_text == widget &&
5683 file_mgr_data->fast_cd_enabled)
5685 return(file_mgr_data->restricted_directory);
5688 return((char *)NULL);
5696 if (_DtStringsAreEquivalent (str, "on"))
5697 *type = MULTIPLE_DIRECTORY;
5698 else if (_DtStringsAreEquivalent (str, "off"))
5699 *type = SINGLE_DIRECTORY;
5701 *type = UNSET_VALUE;
5705 DtfileStringToTreeFiles(
5709 if (_DtStringsAreEquivalent (str, "never"))
5710 *type = TREE_FILES_NEVER;
5711 else if (_DtStringsAreEquivalent (str, "choose"))
5712 *type = TREE_FILES_CHOOSE;
5713 else if (_DtStringsAreEquivalent (str, "always"))
5714 *type = TREE_FILES_ALWAYS;
5716 *type = UNSET_VALUE;
5724 if (_DtStringsAreEquivalent (str, "no_icon") ||
5725 _DtStringsAreEquivalent (str, "no_icons"))
5727 else if (_DtStringsAreEquivalent (str, "large_icon") ||
5728 _DtStringsAreEquivalent (str, "large_icons"))
5729 *type = BY_NAME_AND_ICON;
5730 else if (_DtStringsAreEquivalent (str, "small_icon") ||
5731 _DtStringsAreEquivalent (str, "small_icons"))
5732 *type = BY_NAME_AND_SMALL_ICON;
5733 else if (_DtStringsAreEquivalent (str, "attributes"))
5734 *type = BY_ATTRIBUTES;
5736 *type = UNSET_VALUE;
5740 DtfileStringToOrder(
5744 if (_DtStringsAreEquivalent (str, "file_type"))
5745 *type = ORDER_BY_FILE_TYPE;
5746 else if (_DtStringsAreEquivalent (str, "alphabetical"))
5747 *type = ORDER_BY_ALPHABETICAL;
5748 else if (_DtStringsAreEquivalent (str, "date"))
5749 *type = ORDER_BY_DATE;
5750 else if (_DtStringsAreEquivalent (str, "size"))
5751 *type = ORDER_BY_SIZE;
5753 *type = UNSET_VALUE;
5758 DtfileStringToDirection(
5762 if (_DtStringsAreEquivalent (str, "ascending"))
5763 *type = DIRECTION_ASCENDING;
5764 else if (_DtStringsAreEquivalent (str, "descending"))
5765 *type = DIRECTION_DESCENDING;
5767 *type = UNSET_VALUE;
5775 if (_DtStringsAreEquivalent (str, "on"))
5777 else if (_DtStringsAreEquivalent (str, "off"))
5780 *type = UNSET_VALUE;
5784 SetupSendRequestArgs(
5785 ApplicationArgs application_args,
5789 if(application_args.title != NULL)
5791 tt_message_arg_add( msg, TT_IN, "-title", application_args.title );
5793 if(application_args.restricted != NULL)
5795 tt_message_arg_add( msg, TT_IN, RESTRICTED_HEADER, 0 );
5797 vtype = VIEW_HEADER;
5798 switch( application_args.view )
5801 tt_message_arg_add( msg, TT_IN, vtype, "no_icon" );
5803 case BY_NAME_AND_ICON:
5804 tt_message_arg_add( msg, TT_IN, vtype, "large_icon" );
5806 case BY_NAME_AND_SMALL_ICON:
5807 tt_message_arg_add( msg, TT_IN, vtype, "small_icon" );
5810 tt_message_arg_add( msg, TT_IN, vtype, "attributes" );
5813 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5818 switch( application_args.order )
5820 case ORDER_BY_FILE_TYPE:
5821 tt_message_arg_add( msg, TT_IN, vtype, "file_type" );
5823 case ORDER_BY_ALPHABETICAL:
5824 tt_message_arg_add( msg, TT_IN, vtype, "alphabetical" );
5827 tt_message_arg_add( msg, TT_IN, vtype, "date" );
5830 tt_message_arg_add( msg, TT_IN, vtype, "size" );
5833 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5837 vtype = "-direction";
5838 switch( application_args.direction )
5840 case DIRECTION_ASCENDING:
5841 tt_message_arg_add( msg, TT_IN, vtype, "ascending" );
5843 case DIRECTION_DESCENDING:
5844 tt_message_arg_add( msg, TT_IN, vtype, "descending" );
5847 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5852 switch( application_args.grid )
5855 tt_message_arg_add( msg, TT_IN, vtype, "on" );
5858 tt_message_arg_add( msg, TT_IN, vtype, "off" );
5861 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5865 switch( application_args.tree_view )
5867 case MULTIPLE_DIRECTORY:
5868 tt_message_arg_add( msg, TT_IN, vtype, "on" );
5870 case SINGLE_DIRECTORY:
5871 tt_message_arg_add( msg, TT_IN, vtype, "off" );
5874 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5878 vtype = "-tree_files";
5879 switch( application_args.tree_files )
5881 case TREE_FILES_NEVER:
5882 tt_message_arg_add( msg, TT_IN, vtype, "never" );
5884 case TREE_FILES_CHOOSE:
5885 tt_message_arg_add( msg, TT_IN, vtype, "choose" );
5887 case TREE_FILES_ALWAYS:
5888 tt_message_arg_add( msg, TT_IN, vtype, "always" );
5891 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5895 if(application_args.help_volume != NULL)
5897 tt_message_arg_add( msg, TT_IN, "-help_volume",
5898 application_args.help_volume );
5903 * This routine is used by ForceMyIconOpen to get the "Open" filetype and
5904 * find out what the new icon is. It then places that icon in the
5905 * correct icon gadget.
5908 BuildAndShowIconName(
5909 char *file_type_name,
5911 unsigned char show_type,
5914 char *new_file_type_name;
5917 PixmapData *pixmapData;
5919 new_file_type_name = (char *)XtMalloc(strlen(file_type_name) +
5920 strlen(ICON_OPEN_PREFIX) + 1);
5921 sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5923 if (view == BY_NAME_AND_ICON && show_type != MULTIPLE_DIRECTORY)
5924 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5930 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5936 if(pixmapData && pixmapData->iconFileName)
5938 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
5939 XtSetValues(widget, args, 1);
5944 XtSetArg (args[0], XmNimageName, NULL);
5945 XtSetValues(widget, args, 1);
5949 _DtCheckAndFreePixmapData(new_file_type_name,
5951 (DtIconGadget) widget,
5954 XtFree(new_file_type_name);
5959 * Given a directory name, this function will see if a view of the parent
5960 * directory is open; if so, then it will update the icon representing
5961 * this icon, in the parent view, so that it is drawn as 'closed'. This
5962 * function must only be called if openDirType == NEW.
5968 char * directory_name)
5974 FileViewData * file_view_data = NULL;
5975 DialogData *dialog_data;
5976 FileMgrData *file_mgr_data;
5977 DesktopRec *desktopWindow;
5980 PixmapData *pixmapData;
5982 /* find the parent directory of the one just removed */
5983 parent = _DtPName(directory_name);
5984 fname = DName(directory_name);
5986 /* first check to see if any File Manager views have this directory */
5987 for (i = 0; i < view_count; i++)
5989 dialog_data = (DialogData *) view_set[i]->dialog_data;
5990 file_mgr_data = (FileMgrData *) dialog_data->data;
5992 /* loop through until we find the file_view_data structure for
5993 * the directory to force open */
5995 for(j = 0; j < file_mgr_data->directory_count; j++)
5997 if (strcmp(parent, file_mgr_data->directory_set[j]->name) == 0)
5999 for (k = 0; k < file_mgr_data->directory_set[j]->file_count; k++)
6002 file_mgr_data->directory_set[j]->file_view_data[k];
6003 if (strcmp(file_view_data->file_data->file_name, fname) == 0)
6013 if( (file_view_data) && (file_mgr_data->view != BY_NAME) )
6015 if (file_mgr_data->view == BY_NAME_AND_ICON &&
6016 file_mgr_data->show_type != MULTIPLE_DIRECTORY)
6017 pixmapData = _DtRetrievePixmapData(
6018 file_view_data->file_data->logical_type,
6021 file_view_data->widget,
6024 pixmapData = _DtRetrievePixmapData(
6025 file_view_data->file_data->logical_type,
6028 file_view_data->widget,
6032 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6034 XtSetArg (args[0], XmNimageName, NULL);
6035 XtSetValues (file_view_data->widget, args, 1);
6037 _DtCheckAndFreePixmapData(file_view_data->file_data->logical_type,
6038 file_view_data->widget,
6039 (DtIconGadget) file_view_data->widget,
6043 /* now check to see if any desktop objects are this directory */
6044 for(j = 0; j < desktop_data->numIconsUsed; j++)
6048 desktopWindow = desktop_data->desktopWindows[j];
6049 file_view_data = desktopWindow->file_view_data;
6051 sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
6052 desktopWindow->file_name);
6053 DtEliminateDots (buf);
6055 if( (strcmp(buf, directory_name) == 0) &&
6056 (strcmp(desktopWindow->host, host_name) == 0) )
6058 pixmapData = _DtRetrievePixmapData(
6059 file_view_data->file_data->logical_type,
6062 desktopWindow->shell,
6066 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6068 XtSetArg (args[0], XmNimageName, NULL);
6069 XtSetValues (desktopWindow->iconGadget, args, 1);
6071 _DtCheckAndFreePixmapData(
6072 desktopWindow->file_view_data->file_data->logical_type,
6073 desktopWindow->shell,
6074 (DtIconGadget) desktopWindow->iconGadget,
6081 /*************************************************************************
6083 * MarqueeSelect - this is the callback which gets called when there is
6084 * a marquee event happening on the root window.
6086 ************************************************************************/
6095 XtPointer client_data)
6100 Screen *currentScreen;
6102 char *workspace_name=NULL;
6108 case DT_WSM_MARQUEE_SELECTION_TYPE_BEGIN:
6109 display = XtDisplay(desktop_data->desktopWindows[0]->shell);
6110 screen = XDefaultScreen(display);
6111 currentScreen = XScreenOfDisplay(display, screen);
6112 rootWindow = RootWindowOfScreen(currentScreen);
6114 if(DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
6117 workspace_name = XGetAtomName (display, pCurrent);
6118 CleanUpWSName(workspace_name);
6122 XtNewString(desktop_data->workspaceData[0]->name);
6124 for(i = 0; i < desktop_data->numWorkspaces; i++)
6126 if(strcmp(workspace_name,
6127 desktop_data->workspaceData[i]->name) == 0)
6129 DeselectAllDTFiles(desktop_data->workspaceData[i]);
6133 XtFree(workspace_name);
6136 case DT_WSM_MARQUEE_SELECTION_TYPE_END:
6137 CheckDesktopMarquee(x, y, width, height);
6140 case DT_WSM_MARQUEE_SELECTION_TYPE_CANCEL:
6143 case DT_WSM_MARQUEE_SELECTION_TYPE_CONTINUE:
6144 CheckDesktopMarquee(x, y, width, height);
6154 * We must wait for the message response, before exiting
6158 WaitForResponseAndExit( void )
6166 XtPointer clientData,
6171 FinalizeToolTalkSession( );
6177 * Puts up an Error dialog with Cancel and Help unmapped in the
6178 * center of the screen. The last argument is the OK callback
6182 post_dialog(Widget parent, char *title, char *msg, void (*DtErrExitCB)())
6184 Widget dialog, dialogShell;
6185 XmString message_text, ok;
6187 Dimension dialogWd, dialogHt;
6190 ok = XmStringCreateLocalized ((char*)_DtOkString);
6191 message_text = XmStringCreateLocalized (msg);
6193 XtSetArg(args[n], XmNautoUnmanage, False); n++;
6194 XtSetArg(args[n], XmNokLabelString, ok); n++;
6195 XtSetArg(args[n], XmNtitle, title); n++;
6196 XtSetArg(args[n], XmNmessageString, message_text); n++;
6197 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
6198 XtSetArg (args[n], XmNdefaultPosition, False); n++;
6199 XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
6201 dialog = XmCreateErrorDialog (parent, title, args, n);
6202 XtAddCallback (dialog, XmNokCallback, DtErrExitCB, NULL);
6203 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON));
6204 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
6206 /* Disable the frame menu from dialog since we don't want the user
6207 to be able to close dialogs with the frame menu */
6209 dialogShell = XtParent(dialog);
6210 XtSetArg(args[0], XmNmappedWhenManaged, False);
6211 XtSetArg(args[1], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU);
6212 XtSetValues(dialogShell, args, 2);
6213 XtManageChild (dialog);
6214 XtRealizeWidget (dialogShell);
6216 /* Center the dialog */
6218 XtSetArg(args[0], XmNwidth, &dialogWd);
6219 XtSetArg(args[1], XmNheight, &dialogHt);
6220 XtGetValues(dialog, args, 2);
6221 XtSetArg (args[0], XmNx,
6222 (WidthOfScreen(XtScreen(dialog)) - dialogWd) / 2);
6223 XtSetArg (args[1], XmNy,
6224 (HeightOfScreen(XtScreen(dialog)) - dialogHt) / 2);
6225 XtSetArg (args[2], XmNmappedWhenManaged, True);
6226 XtSetValues (dialog, args, 3);
6228 XtSetArg(args[0], XmNmappedWhenManaged, True);
6229 XtSetValues(dialogShell, args, 1);
6231 XtManageChild (dialog);
6232 XmStringFree(message_text);
6238 * This is the Callback when an error occurs while trying to create
6239 * the .dt folder or sub-folders. Application exits.
6243 DtErrExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
6245 XtPopdown (XtParent (dialog));
6246 FinalizeToolTalkSession();
6252 sigchld_handler(int signo) /* Do not use the arg signo at the moment */
6258 On DUX, the process remains in the ZOMBIE
6259 state untill parent invokes wait or waitpid.
6262 pid = waitpid(-1, &stat_loc, WNOHANG);
6263 /* Child exit handling code follows, if any */
6265 #endif /* __osf__ */