2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: Main.c /main/29 1999/09/17 13:35:04 mgreess $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: This file contains the main program for dtfile.
32 * It also contains functions for session management and
33 * directory view control.
35 * FUNCTIONS: BlackPixelOfScreen
36 * BuildAndShowIconName
37 * CheckForOpenDirectory
44 * DtfileCvtStringToDTIcon
45 * DtfileCvtStringToDirection
46 * DtfileCvtStringToGrid
47 * DtfileCvtStringToObjPlace
48 * DtfileCvtStringToOpenDir
49 * DtfileCvtStringToOrder
50 * DtfileCvtStringToTree
51 * DtfileCvtStringToTreeFiles
52 * DtfileCvtStringToView
53 * DtfileStringToDirection
57 * DtfileStringToTreeFiles
66 * GetRestrictedDirectory
85 * SetupSendRequestArgs
90 * ViewDirectoryHandler
92 * ViewHomeDirectoryHandler
94 * ViewToolsDirectoryHandler
95 * WaitForResponseAndExit
99 * _DtWsmAddMarqueeSelectionCallback
105 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
106 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
107 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
108 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
110 ****************************************************************************
111 ************************************<+>*************************************/
113 #include <sys/types.h>
115 #include <sys/stat.h>
119 #include <sys/wait.h>
127 #ifndef sun /* don't need the nl_types.h file */
128 #include <nl_types.h>
134 #include <Xm/DrawingA.h>
135 #include <Xm/DrawingAP.h>
136 #include <Xm/MessageB.h>
137 #include <Xm/RowColumn.h>
138 #include <Xm/MwmUtil.h>
141 #include <Dt/IconP.h>
142 #include <Dt/IconFile.h>
144 #include <Dt/HelpDialog.h>
147 #include <X11/extensions/shape.h>
150 #include <X11/Shell.h>
151 #include <X11/Xatom.h>
152 #include <Xm/Protocols.h>
153 #include <X11/keysymdef.h>
155 #include <X11/Xmu/Editres.h>
157 #include <Dt/Session.h>
159 #include <Dt/Connect.h>
160 #include <Dt/FileM.h>
161 #include <Dt/Indicator.h>
163 #include <Dt/UserMsg.h>
166 #include <Dt/DtNlUtils.h>
167 #include <Dt/CommandM.h>
168 #include <Dt/EnvControlP.h>
172 #include "SharedProcs.h"
180 #include "ChangeDir.h"
187 /* When openDir resource is set to NEW
188 File Manager will use this prefix to find for a different icon
191 #define ICON_OPEN_PREFIX "OPEN_"
193 /* THESE ARE ONLY STRINGS WHICH DO NOT NEED TO BE LOCALIZED */
194 /* Don't use '#define' since you end up with multiple copies */
195 char DTFILE_CLASS_NAME[] = "Dtfile";
196 char DTFILE_HELP_NAME[] = "Filemgr";
197 char DESKTOP_DIR[] = ".dt/Desktop";
199 static char WS_RES_HEADER[] = ".Workspace.";
200 static char SEC_HELP_RES_HEADER[] = ".secondaryHelpDialogCount: ";
201 static char WS_LOAD_RES_HEADER[] = "Workspace";
202 static char SEC_LOAD_HELP_RES_HEADER[] = "secondaryHelpDialogCount";
203 static char RESTRICTED_HEADER[] = "-restricted";
204 static char VIEW_HEADER[] = "-view";
207 /* Structure, resource definitions, for View's optional parameters. */
220 int instanceIconWidth;
221 int instanceIconHeight;
222 XmFontList user_font;
223 Dimension tool_width;
224 Dimension tool_height;
226 Dimension dir_height;
235 int maxDirectoryProcesses;
236 int maxRereadProcesses;
237 int maxRereadProcsPerTick;
240 Boolean showFilesystem;
241 Boolean showDropZone;
242 Boolean showEmptySet;
243 Boolean showEmptyMsg;
245 Boolean restrictMode;
246 int desktopPlacement;
247 Boolean freezeOnConfig;
248 #if defined(__hpux) || defined(sun)
249 Boolean follow_links;
254 int retryLoadDesktop;
259 Boolean emptyTrashOnExit;
260 } ApplicationArgs, *ApplicationArgsPtr;
262 static ApplicationArgs application_args;
264 /******** Static Function Declarations ********/
266 static void ErrorHandler(
268 XErrorEvent *event) ;
269 static void ToolkitErrorHandler(
273 static void RestrictModeUsage(
275 static void Stop( void ) ;
276 static void RestoreSettingsFile( void ) ;
277 static void MoveDefaultSettings(
279 static void SaveDefaultCancelCB(
281 XtPointer client_data,
282 XtPointer call_data) ;
283 static void SaveDefaultOkCB(
285 XtPointer client_data,
286 XtPointer call_data) ;
287 static void SaveSession(
289 static int RestoreSession(
294 char current_directory[]) ;
295 static void OpenDirectories(
298 static Tt_callback_action ObserveTtNotice(
301 static void ViewSessionHandler(
303 static void ViewDirectoryHandler(
305 static void ViewHomeDirectoryHandler(
307 static void ViewToolsDirectoryHandler(
309 static void ExitHandler(
311 XtPointer clientData,
312 String * messageFields,
314 static void ReloadDatabases( void );
315 static void ViewAccept(
318 static void LoadViews (
322 char *directory_name,
325 static void RemoveTextFields (
326 XtPointer client_data,
327 DialogData * old_dialog_data,
328 DialogData * new_dialog_data) ;
329 static void DtfileCvtStringToObjPlace (
334 static unsigned char *_DtNextToken (
335 unsigned char *pchIn,
337 unsigned char **ppchNext) ;
338 static void DtfileCvtStringToOpenDir (
343 static void DtfileCvtStringToDTIcon (
348 static void DtfileCvtStringToTree (
353 static void DtfileCvtStringToTreeFiles (
358 static void DtfileCvtStringToView (
363 static void DtfileCvtStringToOrder (
368 static void DtfileCvtStringToDirection (
373 static void DtfileCvtStringToGrid (
378 static void DtfileStringToTree(
381 static void DtfileStringToTreeFiles(
384 static void DtfileStringToView(
387 static void DtfileStringToOrder(
390 static void DtfileStringToDirection(
393 static void DtfileStringToGrid(
396 static void SetupSendRequestArgs(
397 ApplicationArgs application_args,
399 static void BuildAndShowIconName(
400 char *file_type_name,
402 unsigned char show_type,
404 static void MarqueeSelect (
411 XtPointer client_data);
412 static void WaitForResponseAndExit( void ) ;
414 XtPointer clientData,
417 static Widget post_dialog(
422 static void DtErrExitCB(
424 XtPointer client_data,
425 XtPointer call_data);
427 /******** End Static Function Declarations ********/
434 /* performance flag */
435 #ifdef DT_PERFORMANCE
439 /* The id's of the dialogs registered by main */
442 int change_dir_dialog;
443 int preferences_dialog;
449 /* The shared menu button and pane Id's */
451 Widget * create_dataBtn;
454 Widget * duplicateBtn;
457 Widget * create_directoryBtn;
458 Widget * change_directoryBtn;
459 Widget * showHiddenMenu;
460 Widget * preferencesBtn;
462 Widget * defaultEnvBtn;
469 Widget * terminalBtn;
470 Widget * usingHelp = NULL;
471 Widget * fileManagerHelp = NULL;
472 Widget * applicationManagerHelp = NULL;
473 Widget * usingHelpTrash = NULL;
476 /* Bitmask used to indicate the current sensitivity state of shared menu btns */
478 unsigned int currentMenuStates = ( RENAME | MOVE | DUPLICATE | LINK | TRASH |
479 MODIFY | CHANGEDIR | PREFERENCES | FILTER |
480 FIND | CREATE_DIR | CREATE_FILE |
481 PUT_ON_DESKTOP | PUTBACK |
483 HOME | CHANGE_DIR | TERMINAL);
485 /* Drag manager globals */
487 Boolean dragActive = False;
489 /* Desktop Globals */
493 /* Globally referenced application name. Set to argv[0] in main */
495 char * application_name = NULL;
498 /* uid for root user; used when we are checking access permissions */
505 char home_host_name[MAX_PATH];
506 char users_home_dir[MAX_PATH];
509 /* Toolbox directory */
511 char * desktop_dir = NULL;
512 char * trash_dir = NULL;
513 char * remote_sys_dir = NULL;
517 int restoreType = NORMAL_RESTORE;
520 /* Black and White pixels */
526 /* File manager view set before a new view is created and */
527 /* used to propagate visual attributes from the initiating */
528 /* view to the new view. */
530 XtPointer initiating_view = NULL;
531 Boolean special_view = False;
532 Boolean TrashView = False;
535 /* system wide user font */
537 XmFontList user_font;
540 /* Global localizable strings */
546 /* Global dialog button labels, as XmStrings */
549 XmString cancelXmString;
550 XmString helpXmString;
551 XmString applyXmString;
552 XmString closeXmString;
555 /* Global top level widget */
559 /* Global Application resources */
560 Boolean showFilesystem;
561 Boolean showDropZone;
562 Boolean showEmptySet;
563 Boolean showEmptyMsg;
564 Boolean restrictMode;
568 char *fileMgrHelpVol;
573 int desktopPlacement;
574 Boolean freezeOnConfig;
575 #if defined(__hpux) || defined(sun)
576 Boolean follow_links;
586 unsigned char keybdFocusPolicy;
587 int special_treeType;
588 int special_treeFiles;
589 int special_viewType;
590 int special_orderType;
591 int special_directionType;
592 int special_randomType;
593 char *special_restricted;
595 char *special_helpVol;
599 int retryLoadDesktopInfo;
606 Boolean emptyTrashOnExit;
609 Boolean shapeExtension;
612 /* Drag state variables */
613 Boolean B1DragPossible = False;
614 Boolean B2DragPossible = False;
615 Boolean ProcessBtnUp = False;
616 Boolean ProcessBtnUpCD = True;
620 int xErrorDetected = False;
622 /* BMenu button binding */
625 View ** view_set = NULL;
627 int view_set_size = 0;
629 /* Globals used within this file. */
631 static Display * display;
632 char * dt_path = NULL;
633 static Boolean message_display_enabled = True;
636 static Atom save_yourself_atom;
637 static Atom command_atom;
638 static Atom wm_state_atom;
639 static Atom save_mode;
641 /* Structure used on a save session to see if a dt is iconic */
650 /* Application resource list definition */
652 static XrmOptionDescRec option_list[] =
654 { "-noview", "noView", XrmoptionIsArg, NULL },
655 { "-session", "session", XrmoptionSepArg, NULL },
656 { "-dir", "folder", XrmoptionSepArg, NULL },
657 { "-folder", "folder", XrmoptionSepArg, NULL },
658 { "-tree", "treeView", XrmoptionSepArg, NULL },
659 { "-tree_files", "treeFiles", XrmoptionSepArg, NULL },
660 { VIEW_HEADER, "view", XrmoptionSepArg, NULL },
661 { "-order", "order", XrmoptionSepArg, NULL },
662 { "-direction", "direction", XrmoptionSepArg, NULL },
663 { "-grid", "grid", XrmoptionSepArg, NULL },
664 { RESTRICTED_HEADER, "restricted", XrmoptionIsArg, NULL },
665 { "-title", "title", XrmoptionSepArg, NULL },
666 { "-help_volume", "help_volume", XrmoptionSepArg, NULL },
667 { "-noprompt", "promptUser", XrmoptionNoArg, "False" },
668 { "-small_icon_width", "smallIconWidth", XrmoptionSepArg, NULL },
669 { "-small_icon_height", "smallIconHeight", XrmoptionSepArg, NULL },
670 { "-large_icon_width", "largeIconWidth", XrmoptionSepArg, NULL },
671 { "-large_icon_height", "largeIconHeight", XrmoptionSepArg, NULL },
675 static XtResource resources[] =
678 "noView", "NoView", XmRString, sizeof (char *),
679 XtOffset (ApplicationArgsPtr, no_view), XmRImmediate, (XtPointer) NULL,
683 "session", "Session", XmRString, sizeof (char *),
684 XtOffset (ApplicationArgsPtr, session), XmRImmediate, (XtPointer) NULL,
688 "folder", "Folder", XmRString, sizeof (char *),
689 XtOffset (ApplicationArgsPtr, directories), XmRImmediate, (XtPointer) NULL,
693 "treeView", "TreeView", "Tree", sizeof (int),
694 XtOffset (ApplicationArgsPtr, tree_view), XmRImmediate,
695 (XtPointer) UNSET_VALUE,
699 "treeFiles", "TreeFiles", "TreeFiles", sizeof (int),
700 XtOffset (ApplicationArgsPtr, tree_files), XmRImmediate,
701 (XtPointer) UNSET_VALUE,
705 "view", "View", "View", sizeof (int),
706 XtOffset (ApplicationArgsPtr, view), XmRImmediate, (XtPointer) UNSET_VALUE,
710 "order", "Order", "Order", sizeof (int),
711 XtOffset (ApplicationArgsPtr, order), XmRImmediate, (XtPointer) UNSET_VALUE,
715 "direction", "Direction", "Direction", sizeof (int),
716 XtOffset (ApplicationArgsPtr, direction), XmRImmediate,
717 (XtPointer) UNSET_VALUE,
721 "grid", "Grid", "Grid", sizeof (int),
722 XtOffset (ApplicationArgsPtr, grid), XmRImmediate, (XtPointer) UNSET_VALUE,
726 "instanceIconWidth", "InstanceIconWidth", XmRInt, sizeof (int),
727 XtOffset (ApplicationArgsPtr, instanceIconWidth), XmRImmediate,
732 "instanceIconHeight", "InstanceIconHeight", XmRInt, sizeof (int),
733 XtOffset (ApplicationArgsPtr, instanceIconHeight), XmRImmediate,
738 "restricted", "Restricted", XmRString, sizeof (char *),
739 XtOffset (ApplicationArgsPtr, restricted), XmRImmediate, (XtPointer) NULL,
743 "title", "Title", XmRString, sizeof (char *),
744 XtOffset (ApplicationArgsPtr, title), XmRImmediate, (XtPointer)NULL,
748 "help_volume", "Help_volume", XmRString, sizeof (char *),
749 XtOffset (ApplicationArgsPtr, help_volume), XmRImmediate, (XtPointer)NULL,
753 "userFont", "XmCFontList", XmRFontList, sizeof (XmFontList),
754 XtOffset (ApplicationArgsPtr, user_font), XmRString, (XtPointer) "Fixed",
758 "toolWidth", "ToolWidth", XmRHorizontalDimension, sizeof (Dimension),
759 XtOffset (ApplicationArgsPtr, tool_width), XmRImmediate, (XtPointer) 700,
763 "toolHeight", "ToolHeight", XmRVerticalDimension, sizeof (Dimension),
764 XtOffset (ApplicationArgsPtr, tool_height), XmRImmediate, (XtPointer) 250,
768 "dirWidth", "DirWidth", XmRHorizontalDimension, sizeof (Dimension),
769 XtOffset (ApplicationArgsPtr, dir_width), XmRImmediate, (XtPointer) 555,
773 "dirHeight", "DirHeight", XmRVerticalDimension, sizeof (Dimension),
774 XtOffset (ApplicationArgsPtr, dir_height), XmRImmediate, (XtPointer) 400,
778 "promptUser", "PromptUser", XmRBoolean, sizeof (Boolean),
779 XtOffset (ApplicationArgsPtr, prompt_user), XmRImmediate, (XtPointer) True,
783 "rootTitle", "RootTitle", XmRString, sizeof (char *),
784 XtOffset (ApplicationArgsPtr, root_title), XmRImmediate, (XtPointer)"ROOT",
788 "moveThreshold", "MoveThreshold", XmRInt, sizeof (int),
789 XtOffset (ApplicationArgsPtr, dragThreshold), XmRImmediate, (XtPointer) 4,
793 "rereadTime", "RereadTime", XmRInt, sizeof (int),
794 XtOffset (ApplicationArgsPtr, rereadTime), XmRImmediate, (XtPointer) 3,
798 "checkBrokenLink", "CheckBrokenLink", XmRInt, sizeof (int),
799 XtOffset (ApplicationArgsPtr, checkBrokenLink), XmRImmediate,
804 "maxDirectoryProcesses", "MaxDirectoryProcesses", XmRInt, sizeof (int),
805 XtOffset (ApplicationArgsPtr, maxDirectoryProcesses), XmRImmediate,
810 "maxRereadProcesses", "MaxRereadProcesses", XmRInt, sizeof (int),
811 XtOffset (ApplicationArgsPtr, maxRereadProcesses), XmRImmediate,
816 "maxRereadProcsPerTick", "MaxRereadProcsPerTick", XmRInt, sizeof (int),
817 XtOffset (ApplicationArgsPtr, maxRereadProcsPerTick), XmRImmediate,
822 "trashWait", "TrashWait", XmRInt, sizeof (int),
823 XtOffset (ApplicationArgsPtr, trashWait), XmRImmediate, (XtPointer) 1,
827 "desktopIcon", "DesktopIcon", "DesktopIcon", sizeof (int),
828 XtOffset (ApplicationArgsPtr, desktopIconType), XmRImmediate,
833 "showFilesystem", "ShowFilesystem", XmRBoolean, sizeof (Boolean),
834 XtOffset (ApplicationArgsPtr, showFilesystem), XmRImmediate,
839 "showDropZone", "ShowDropZone", XmRBoolean, sizeof (Boolean),
840 XtOffset (ApplicationArgsPtr, showDropZone), XmRImmediate,
845 "showEmptySet", "ShowEmptySet", XmRBoolean, sizeof (Boolean),
846 XtOffset (ApplicationArgsPtr, showEmptySet), XmRImmediate,
851 "showEmptyMsg", "ShowEmptyMsg", XmRBoolean, sizeof (Boolean),
852 XtOffset (ApplicationArgsPtr, showEmptyMsg), XmRImmediate,
857 "openFolder", "OpenFolder", "OpenFolder", sizeof (int),
858 XtOffset (ApplicationArgsPtr, openDirType), XmRImmediate,
863 "restrictMode", "RestrictMode", XmRBoolean, sizeof (Boolean),
864 XtOffset (ApplicationArgsPtr, restrictMode), XmRImmediate,
869 "objectPlacement", "ObjectPlacement", "ObjectPlacement", sizeof (int),
870 XtOffset (ApplicationArgsPtr, desktopPlacement), XmRImmediate,
871 (XtPointer)(OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_RIGHT_SECONDARY),
875 "freezeOnConfig", "FreezeOnConfig", XmRBoolean, sizeof (Boolean),
876 XtOffset (ApplicationArgsPtr, freezeOnConfig), XmRImmediate,
881 "fileManagerIcon", "FileManagerIcon", XmRString, sizeof (char *),
882 XtOffset (ApplicationArgsPtr, fileMgrIcon), XmRImmediate,
883 (XtPointer) HOME_ICON_NAME,
887 "appManagerIcon", "AppManagerIcon", XmRString, sizeof (char *),
888 XtOffset (ApplicationArgsPtr, appMgrIcon), XmRImmediate,
889 (XtPointer) TOOL_ICON_NAME,
893 "trashIcon", "TrashIcon", XmRString, sizeof (char *),
894 XtOffset (ApplicationArgsPtr, trashIcon), XmRImmediate,
895 (XtPointer) TRASH_ICON_NAME,
899 "retryLoadDesktop", "RetryLoadDesktop", XmRInt, sizeof (int),
900 XtOffset (ApplicationArgsPtr, retryLoadDesktop), XmRImmediate,
905 "smallIconWidth", "SmallIconWidth", XmRInt, sizeof (int),
906 XtOffset (ApplicationArgsPtr, smallIconWidth), XmRImmediate,
911 "smallIconHeight", "SmallIconHeight", XmRInt, sizeof (int),
912 XtOffset (ApplicationArgsPtr, smallIconHeight), XmRImmediate,
917 "largeIconWidth", "LargeIconWidth", XmRInt, sizeof (int),
918 XtOffset (ApplicationArgsPtr, largeIconWidth), XmRImmediate,
923 "largeIconHeight", "LargeIconHeight", XmRInt, sizeof (int),
924 XtOffset (ApplicationArgsPtr, largeIconHeight), XmRImmediate,
929 "emptyTrashOnExit", "EmptyTrashOnExit", XmRBoolean, sizeof (Boolean),
930 XtOffset (ApplicationArgsPtr, emptyTrashOnExit), XmRImmediate,
934 #if defined(__hpux) || defined(sun)
935 { "followLinks", "FollowLinks", XmRBoolean, sizeof(Boolean),
936 XtOffset(ApplicationArgsPtr, follow_links), XmRImmediate,
943 XtActionsRec actionTable[] = {
944 {"Space", (XtActionProc)VFTextChangeSpace},
945 {"EscapeFM", (XtActionProc)CancelOut},
948 /************************************************************************
951 * The main program for the file manager.
953 ************************************************************************/
955 extern XtInputId ProcessToolTalkInputId;
958 extern void sigchld_handler(int);
966 #ifdef DT_PERFORMANCE
967 struct timeval update_time_s;
968 struct timeval update_time_f;
969 struct timeval update_time_ss;
970 struct timeval update_time_fs;
973 char current_directory[MAX_PATH];
974 struct passwd * pwInfo;
978 Boolean eventDebugging;
986 XSetWindowAttributes sAttributes;
991 XrmValue resource_value;
996 int ttFd; /* ToolTalk file descriptor */
998 Tt_pattern events2Watch;
999 Tt_pattern requests2Handle;
1003 struct sigaction sa, osa;
1004 #endif /* __osf__ */
1005 int session_flag = 0;
1007 #ifdef DT_PERFORMANCE
1009 gettimeofday(&update_time_ss, NULL);
1011 (void) signal (SIGINT, (void (*)())Stop);
1013 /* We don't want any zombie children, do we? */
1015 sa.sa_handler = sigchld_handler;
1016 sigemptyset(&sa.sa_mask);
1019 if (sigaction(SIGCHLD, &sa, &osa) < 0)
1020 /* error handling follows, none for now */
1023 (void) signal (SIGCHLD, SIG_IGN);
1024 #endif /* __osf__ */
1025 XtSetLanguageProc( NULL, NULL, NULL );
1027 #ifdef DT_PERFORMANCE
1028 { /* Initialize the checkpoint protocol - Aloke Gupta */
1030 display = XOpenDisplay("");
1031 _DtPerfChkpntInit(display, RootWindow(display, DefaultScreen(display)),
1037 _DtEnvControl(DT_ENV_SET);
1039 #ifdef DT_PERFORMANCE
1040 printf(" XtInitalize\n");
1041 gettimeofday(&update_time_s, NULL);
1043 /* Added by Aloke Gupta */
1044 _DtPerfChkpntMsgSend("Begin XtInitialize");
1047 /* Initialize the toolkit and open the display */
1048 toplevel = XtInitialize (argv[0], DTFILE_CLASS_NAME,
1049 option_list, XtNumber(option_list),
1050 (int *)&argc, argv);
1052 /* MERGE START: May not need
1054 _XmColorObjCreate ( toplevel, NULL, NULL );
1058 #ifdef DT_PERFORMANCE
1059 gettimeofday(&update_time_f, NULL);
1060 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1061 update_time_f.tv_usec += 1000000;
1062 update_time_f.tv_sec--;
1064 printf(" done XtInitialize, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1066 /* Added by Aloke Gupta */
1067 _DtPerfChkpntMsgSend("Done XtInitialize");
1070 /* Initialize the function ptr for alphabetic sorting */
1071 FMStrcoll = GetStrcollProc();
1073 /* Open the message catalog - DO NOT PERFORM until after XtInitialize! */
1075 char * foo = ((char *)GETMESSAGE(18, 1, ""));
1078 /* set application name for later */
1079 str = strrchr(argv[0], '/');
1081 application_name = XtNewString (str + 1);
1083 application_name = XtNewString (argv[0]);
1086 XtSetArg(args[n], XmNallowShellResize, True); n++;
1087 XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
1088 XtSetArg(args[n], XmNheight, 1); n++;
1089 XtSetArg(args[n], XmNwidth, 1); n++;
1090 XtSetValues(toplevel, args, n);
1091 XtRealizeWidget(toplevel);
1092 display = XtDisplay (toplevel);
1094 XtAddEventHandler(toplevel, 0, True,
1095 (XtEventHandler) _XEditResCheckMessages,
1099 /* Initialize BMenu button binding */
1101 int numMouseButtons = XGetPointerMapping(display,
1102 (unsigned char *)NULL, 0);
1103 bMenuButton = (numMouseButtons < 3) ? Button2 : Button3;
1106 /* initialize debugging flag */
1108 if ((tmpStr = getenv("DTFILE_DEBUG")) != NULL)
1110 debug = atoi(tmpStr);
1114 if (getenv("DTFILE_XSYNC") != NULL)
1116 XSynchronize(display, True);
1120 /* initialize performance flag */
1121 #ifdef DT_PERFORMANCE
1122 if ((tmpStr = getenv("DTFILE_PERFORM")) != NULL)
1124 perform = atoi(tmpStr);
1128 if (getenv("DTFILE_XSYNC") != NULL)
1130 XSynchronize(display, True);
1134 /* Create the atom set used by save and restore session */
1135 save_yourself_atom = XmInternAtom (display, "WM_SAVE_YOURSELF", False);
1136 wm_state_atom = XmInternAtom (display, "WM_STATE", False);
1137 command_atom = XA_WM_COMMAND;
1138 save_mode = XmInternAtom (display, _XA_DT_RESTORE_MODE, False);
1140 root = RootWindowOfScreen(XtScreen(toplevel));
1142 /* Set session property on the top level window */
1143 XmAddWMProtocols(toplevel, &save_yourself_atom, 1);
1144 XmAddWMProtocolCallback(toplevel, save_yourself_atom, SaveSessionCallback,
1147 XSetErrorHandler ((int (*)())ErrorHandler);
1148 XtAppSetErrorHandler (XtWidgetToApplicationContext(toplevel),
1149 ToolkitErrorHandler);
1151 /* get the keyboard focus policy so we know how we want to set up the */
1153 XtSetArg(args[0], XmNkeyboardFocusPolicy, &keybdFocusPolicy);
1154 XtGetValues(toplevel, args, 1);
1156 /* If all of the command line parameters were not processed */
1157 /* out, print out a usage message set and exit. */
1159 if (argc != 1) Usage (argv);
1161 displayWidth = DisplayWidth(display, DefaultScreen(display));
1162 displayHeight = DisplayHeight(display, DefaultScreen(display));
1164 /* Get Dt initialized */
1166 if (DtInitialize (display, toplevel, argv[0], FILE_MANAGER_TOOL_CLASS) == False)
1168 /* Fatal Error: could not connect to the messaging system. */
1169 /* DtInitialize() has already logged an appropriate error msg */
1173 #ifdef DT_PERFORMANCE
1174 printf(" Setup Converters and get resources\n");
1175 gettimeofday(&update_time_s, NULL);
1177 /* Added by Aloke Gupta */
1178 _DtPerfChkpntMsgSend("Begin Setup Converters");
1182 /* First lets add the resource converters needed */
1183 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1184 XtRString, "ObjectPlacement",
1185 (XtConverter)DtfileCvtStringToObjPlace, NULL, 0);
1186 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1187 XtRString, "OpenFolder",
1188 (XtConverter)DtfileCvtStringToOpenDir, NULL, 0);
1189 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1190 XtRString, "DesktopIcon",
1191 (XtConverter)DtfileCvtStringToDTIcon, NULL, 0);
1192 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1194 (XtConverter)DtfileCvtStringToTree, NULL, 0);
1195 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1196 XtRString, "TreeFiles",
1197 (XtConverter)DtfileCvtStringToTreeFiles, NULL, 0);
1198 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1200 (XtConverter)DtfileCvtStringToView, NULL, 0);
1201 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1203 (XtConverter)DtfileCvtStringToOrder, NULL, 0);
1204 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1205 XtRString, "Direction",
1206 (XtConverter)DtfileCvtStringToDirection, NULL, 0);
1207 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1209 (XtConverter)DtfileCvtStringToGrid, NULL, 0);
1211 /* Get the application defined resources of session and */
1212 /* directory, and get the processes host. */
1214 XtGetApplicationResources(toplevel, &application_args,
1215 resources, XtNumber(resources), NULL,0);
1217 #ifdef DT_PERFORMANCE
1218 gettimeofday(&update_time_f, NULL);
1219 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1220 update_time_f.tv_usec += 1000000;
1221 update_time_f.tv_sec--;
1223 printf(" done Setting up Converters and got resources, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1225 /* Added by Aloke Gupta */
1226 _DtPerfChkpntMsgSend("Done Setup Converters");
1229 #ifdef DT_PERFORMANCE
1230 printf(" DtDbLoad\n");
1231 gettimeofday(&update_time_s, NULL);
1232 /* Added by Aloke Gupta */
1233 _DtPerfChkpntMsgSend("Begin DtDbLoad");
1237 /* Set up the messaging and file types */
1240 #ifdef DT_PERFORMANCE
1241 gettimeofday(&update_time_f, NULL);
1242 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1243 update_time_f.tv_usec += 1000000;
1244 update_time_f.tv_sec--;
1246 printf(" done DtDbLoad, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1248 /* Added by Aloke Gupta */
1249 _DtPerfChkpntMsgSend("Done DtDbLoad");
1254 /* Create some global strings */
1255 db = XtDatabase(display);
1256 if (XrmGetResource (db, "dttypes.defaultActions",
1257 "Dttypes.DefaultActions", &rep_type,
1260 string = XtNewString(resource_value.addr);
1261 for(str = DtStrtok(string, ",") ,i = 0; str != NULL && i < 2 ;
1262 str = DtStrtok(NULL, ","), i++) {
1264 openInPlace = XtNewString(str);
1266 openNewView = XtNewString(str);
1270 if(openInPlace == NULL || strlen(openInPlace) == 0)
1271 openInPlace = XtNewString("OpenInPlace");
1272 if(openNewView == NULL || strlen(openNewView) == 0)
1273 openNewView = XtNewString("OpenNewView");
1275 DtGetShortHostname (home_host_name, MAX_PATH);
1277 /* Get the lock established to ensure only one dtfile process */
1279 if (_DtGetLock (display, DTFILE_CLASS_NAME) == 0)
1281 status = InitializeToolTalkProcid( &ttFd, toplevel, False );
1282 if (TT_OK != status)
1284 char *errfmt, *errmsg, *title, *statmsg;
1285 title = GETMESSAGE(21,38,"File Manager Error");
1286 errfmt = GETMESSAGE(18, 40,
1287 "Could not connect to ToolTalk:\n%s\nExiting ...");
1288 statmsg = tt_status_message(status);
1290 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1291 fprintf(stderr, errfmt, statmsg);
1292 sprintf(errmsg, errfmt, statmsg);
1294 /* put up error dialog and loop,
1295 * application will exit in dialog callback
1297 post_dialog(toplevel, title, errmsg, DtErrExitCB);
1300 if (application_args.session != NULL)
1302 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1303 "DtFileSession_Run",
1304 (Tt_message_callback)ExitApp );
1305 tt_message_file_set( msg, application_args.session );
1306 tt_message_send( msg );
1308 else if (application_args.directories != NULL)
1310 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1312 (Tt_message_callback)ExitApp );
1313 tt_message_file_set( msg, application_args.directories );
1314 SetupSendRequestArgs( application_args, msg );
1315 tt_message_send( msg );
1319 /* Default action: Open up pwd or home dir */
1320 GetPWD(current_directory);
1322 if (current_directory[0] != NULL)
1324 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1326 (Tt_message_callback)ExitApp );
1327 tt_message_file_set( msg, current_directory );
1331 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1333 (Tt_message_callback)ExitApp );
1335 SetupSendRequestArgs( application_args, msg );
1336 tt_message_send( msg );
1338 WaitForResponseAndExit();
1341 /* Initialize the encapsulation mechanism and install the dialogs */
1342 /* used by the file manager. */
1344 _DtInitializeEncapsulation (display, argv[0], DTFILE_CLASS_NAME);
1345 topPositionOffset = -8;
1347 status = InitializeToolTalkProcid( &ttFd, toplevel, True );
1348 if (TT_OK != status)
1350 char *errfmt, *errmsg, *title, *statmsg;
1351 title = GETMESSAGE(21,38,"File Manager Error");
1352 errfmt = GETMESSAGE(18, 40,
1353 "Could not connect to ToolTalk:\n%s\nExiting ...");
1354 statmsg = tt_status_message(status);
1356 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1357 fprintf(stderr, errfmt, statmsg);
1358 sprintf(errmsg, errfmt, statmsg);
1360 /* put up error dialog and loop,
1361 * application will exit in dialog callback
1363 post_dialog(toplevel, title, errmsg, DtErrExitCB);
1367 #ifdef DT_PERFORMANCE
1368 printf(" Setup Callbacks (messaging)\n");
1369 gettimeofday(&update_time_s, NULL);
1371 /* Added by Aloke Gupta */
1372 _DtPerfChkpntMsgSend("Begin Setup Callbacks");
1375 events2Watch = tt_pattern_create();
1376 tt_pattern_category_set( events2Watch, TT_OBSERVE );
1377 tt_pattern_class_add( events2Watch, TT_NOTICE );
1378 tt_pattern_scope_add( events2Watch, TT_SESSION );
1379 sessId = tt_default_session();
1380 tt_pattern_session_add( events2Watch, sessId );
1382 tt_pattern_op_add( events2Watch, "DtTypes_Reloaded" );
1383 tt_pattern_op_add( events2Watch, "XSession_Ending" );
1384 tt_pattern_callback_add( events2Watch, ObserveTtNotice );
1385 tt_pattern_register( events2Watch );
1387 requests2Handle = tt_pattern_create();
1388 tt_pattern_category_set( requests2Handle, TT_HANDLE );
1389 tt_pattern_class_add( requests2Handle, TT_REQUEST );
1390 tt_pattern_scope_add( requests2Handle, TT_SESSION );
1391 sessId = tt_default_session();
1392 tt_pattern_session_add( requests2Handle, sessId );
1394 tt_pattern_op_add( requests2Handle, "DtFileSession_Run" );
1395 tt_pattern_op_add( requests2Handle, "DtFolder_Show" );
1396 tt_pattern_op_add( requests2Handle, "DtHome_Show" );
1397 tt_pattern_op_add( requests2Handle, "DtTools_Show" );
1398 tt_pattern_op_add( requests2Handle, "DtTrash_Show" );
1399 tt_pattern_op_add( requests2Handle, "DtTrash_Remove" );
1400 tt_pattern_op_add( requests2Handle, "DtTrash_Empty" );
1401 tt_pattern_op_add( requests2Handle, "DtTrash_File" );
1402 tt_pattern_op_add( requests2Handle, "DtTrash_Restore" );
1403 tt_pattern_op_add( requests2Handle, "DtFile_PutOnWorkspace" );
1404 tt_pattern_op_add( requests2Handle, "DtFile_Move" );
1405 tt_pattern_op_add( requests2Handle, "DtFile_Copy" );
1406 tt_pattern_op_add( requests2Handle, "DtFile_Link" );
1407 tt_pattern_callback_add( requests2Handle, HandleTtRequest );
1408 tt_pattern_register( requests2Handle );
1410 /* Setup the settings file if any to setup */
1412 _DtWsmAddMarqueeSelectionCallback(toplevel,
1413 (DtWsmMarqueeSelectionProc) MarqueeSelect,
1416 #ifdef DT_PERFORMANCE
1417 gettimeofday(&update_time_f, NULL);
1418 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1419 update_time_f.tv_usec += 1000000;
1420 update_time_f.tv_sec--;
1422 printf(" done Setting Callbacks (messaging), time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1424 /* Added by Aloke Gupta */
1425 _DtPerfChkpntMsgSend("Done Setup Callbacks");
1429 smallIconWidth = application_args.smallIconWidth;
1430 smallIconHeight = application_args.smallIconHeight;
1431 largeIconWidth = application_args.largeIconWidth;
1432 largeIconHeight = application_args.largeIconHeight;
1433 user_font = application_args.user_font;
1434 dragThreshold = application_args.dragThreshold;
1435 rereadTime = application_args.rereadTime;
1436 checkBrokenLink = application_args.checkBrokenLink;
1437 maxDirectoryProcesses = application_args.maxDirectoryProcesses;
1438 maxRereadProcesses = application_args.maxRereadProcesses;
1439 maxRereadProcsPerTick = application_args.maxRereadProcsPerTick;
1440 trashWait = application_args.trashWait;
1441 showFilesystem = application_args.showFilesystem;
1442 showDropZone = application_args.showDropZone;
1443 showEmptySet = application_args.showEmptySet;
1444 showEmptyMsg = application_args.showEmptyMsg;
1445 restrictMode = application_args.restrictMode;
1446 openDirType = application_args.openDirType;
1447 desktopIconType = application_args.desktopIconType;
1448 desktopPlacement = application_args.desktopPlacement;
1449 freezeOnConfig = application_args.freezeOnConfig;
1450 emptyTrashOnExit = application_args.emptyTrashOnExit;
1451 #if defined(__hpux) || defined(sun)
1452 follow_links = application_args.follow_links;
1454 instanceWidth = application_args.instanceIconWidth;
1455 instanceHeight = application_args.instanceIconHeight;
1456 fileMgrIcon = application_args.fileMgrIcon;
1457 appMgrIcon = application_args.appMgrIcon;
1458 trashIcon = application_args.trashIcon;
1459 retryLoadDesktopInfo = application_args.retryLoadDesktop;
1460 if( application_args.directories != NULL
1461 || (strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1464 special_view = True;
1465 if(strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1467 if(application_args.directories != NULL)
1468 special_restricted = XtNewString(application_args.directories);
1471 /* Get users pwd so we can set the restricted dir to it */
1472 GetPWD(current_directory);
1474 if (current_directory[0] != NULL)
1475 special_restricted = XtNewString(current_directory);
1477 special_restricted = XtNewString("~");
1480 else if( restrictMode )
1481 special_restricted = XtNewString("~");
1483 special_restricted = NULL;
1484 special_treeType = treeType = application_args.tree_view;
1485 special_treeFiles = treeFiles = application_args.tree_files;
1486 special_viewType = viewType = application_args.view;
1487 special_orderType = orderType = application_args.order;
1488 special_directionType = directionType = application_args.direction;
1489 special_randomType = randomType = application_args.grid;
1490 special_title = XtNewString(application_args.title);
1491 if(application_args.help_volume == NULL)
1493 special_helpVol = XtNewString(DTFILE_HELP_NAME);
1494 fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1498 special_helpVol = XtNewString(application_args.help_volume);
1499 fileMgrHelpVol = XtNewString(application_args.help_volume);
1501 fileMgrTitle = application_args.title;
1505 special_view = False;
1506 treeType = application_args.tree_view;
1507 treeFiles = application_args.tree_files;
1508 viewType = application_args.view;
1509 orderType = application_args.order;
1510 directionType = application_args.direction;
1511 randomType = application_args.grid;
1512 fileMgrTitle = application_args.title;
1513 if(application_args.help_volume == NULL)
1514 fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1516 fileMgrHelpVol = XtNewString(application_args.help_volume);
1520 if(desktopIconType == LARGE)
1522 numRows = displayHeight / PIXELS_PER_ROW_LARGE;
1523 numColumns = displayWidth / PIXELS_PER_COLUMN_LARGE;
1527 numRows = displayHeight / PIXELS_PER_ROW_SMALL;
1528 numColumns = displayWidth / PIXELS_PER_COLUMN_SMALL;
1532 /* determine whether the Server has the shape extension */
1533 if(XShapeQueryExtension(display, &base1, &base2) == True)
1534 shapeExtension = True;
1536 shapeExtension = False;
1539 /* get the name for the root directory */
1540 root_title = (char *)XtMalloc(strlen(application_args.root_title) + 1);
1541 strcpy(root_title, application_args.root_title);
1543 if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
1545 pwInfo = getpwuid (getuid());
1546 homeDir = pwInfo->pw_dir;
1548 strncpy(users_home_dir, homeDir, MAX_PATH - 1);
1551 if(application_args.directories != NULL &&
1552 strncmp(application_args.directories, "~", 1) != 0 )
1554 if(strncmp(application_args.directories, users_home_dir,
1555 strlen(users_home_dir)) != 0)
1556 RestrictModeUsage (argv);
1558 else if (application_args.directories == NULL)
1559 application_args.directories = XtNewString("~");
1561 if (strcmp(users_home_dir, "/") != 0)
1562 strcat(users_home_dir, "/");
1564 XtAppAddActions(XtWidgetToApplicationContext (toplevel), actionTable, 2);
1566 /* Create some global Xm strings for our dialog buttons */
1568 okXmString = XmStringCreateLocalized((char*)_DtOkString);
1569 cancelXmString = XmStringCreateLocalized((char*)_DtCancelString);
1570 helpXmString = XmStringCreateLocalized((char*)_DtHelpString);
1571 applyXmString = XmStringCreateLocalized((char*)_DtApplyString);
1572 closeXmString = XmStringCreateLocalized((char*)_DtCloseString);
1574 /* Get the dt path created and initialized */
1576 dt_path = _DtCreateDtDirs (display);
1578 if (dt_path == NULL)
1582 title = XtNewString((GETMESSAGE(21,38,"File Manager Error")));
1583 tmpStr = GETMESSAGE(18, 2, "Could not create the ~/.dt folder or sub folders.");
1584 msg = XtNewString(tmpStr);
1586 /* put up error dialog and loop, application will exit in
1589 dialog = post_dialog(toplevel, title, msg, DtErrExitCB);
1595 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
1599 /* Set the black and white pixel globals. */
1601 black_pixel = BlackPixelOfScreen (XtScreen (toplevel));
1602 white_pixel = WhitePixelOfScreen (XtScreen (toplevel));
1605 * Take over the drawing area's redisplay functions, so that we can get
1606 * the dtfile views to redraw according to stacking order, using our own
1609 xmDrawingAreaWidgetClass->core_class.expose = DrawingAreaRedisplay;
1612 /* Get the root user id */
1614 if ((pw = getpwnam("root")) == NULL)
1615 root_user = 0; /* Assume root is uid 0 */
1617 root_user = pw->pw_uid;
1620 file_mgr_dialog = _DtInstallDialog (fileMgrClass, True, True);
1621 change_dir_dialog = _DtInstallDialog (changeDirClass, True, True);
1622 preferences_dialog = _DtInstallDialog (preferencesClass, True, True);
1623 filter_dialog = _DtInstallDialog (filterClass, True, True);
1624 find_dialog = _DtInstallDialog (findClass, True, True);
1625 mod_attr_dialog = _DtInstallDialog (modAttrClass, True, True);
1626 help_dialog = _DtInstallDialog (helpClass, False, False);
1628 if(special_view == True && special_restricted != NULL);
1629 if(strncmp(special_restricted, "~", 1) == 0)
1633 special_restricted = _DtChangeTildeToHome(special_restricted);
1634 ptr = strrchr(special_restricted, '/');
1640 /* Setup the settings file if any to setup */
1641 RestoreSettingsFile();
1643 #ifdef DT_PERFORMANCE
1644 printf(" TrashCreateDialog\n");
1645 gettimeofday(&update_time_s, NULL);
1647 /* Added by Aloke Gupta */
1648 _DtPerfChkpntMsgSend("Begin TrashCreateDialog");
1651 if( InitializeTrash( application_args.prompt_user ) )
1653 #ifdef DEFER_TRASH_CREATION
1656 TrashCreateDialog (display);
1659 #ifdef DT_PERFORMANCE
1660 gettimeofday(&update_time_f, NULL);
1661 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1662 update_time_f.tv_usec += 1000000;
1663 update_time_f.tv_sec--;
1665 printf(" done TrashCreateDialog, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1667 /* Added by Aloke Gupta */
1668 _DtPerfChkpntMsgSend("Done TrashCreateDialog");
1671 /* lets go empty the trash if there is any */
1676 #ifdef DT_PERFORMANCE
1677 printf(" Setup Desktop\n");
1678 gettimeofday(&update_time_s, NULL);
1679 /* Added by Aloke Gupta */
1680 _DtPerfChkpntMsgSend("Begin Setup Desktop");
1683 /* go build 10 desktop windows */
1684 desktop_data = NULL;
1685 InitializeDesktopWindows(10, display);
1686 InitializeDesktopGrid();
1688 LoadDesktopInfo(application_args.session);
1690 /* Install WorkSpaceRemoved handler.
1691 This handler will be called when a workspace is being removed
1692 so File Manager can go through its desktop icons and clean up.
1694 DtWsmAddWorkspaceModifiedCallback( toplevel, WorkSpaceRemoved, NULL );
1696 #ifdef DT_PERFORMANCE
1697 gettimeofday(&update_time_f, NULL);
1698 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1699 update_time_f.tv_usec += 1000000;
1700 update_time_f.tv_sec--;
1702 printf(" done Setting up Desktop, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1704 /* Added by Aloke Gupta */
1705 _DtPerfChkpntMsgSend("Done Setup Desktop");
1709 /* Process the application resources to restore a session, dt */
1710 /* a directory set or display the users home directory. */
1712 #ifdef DT_PERFORMANCE
1713 printf(" Bring up View\n");
1714 gettimeofday(&update_time_s, NULL);
1716 /* Added by Aloke Gupta */
1717 _DtPerfChkpntMsgSend("Begin Bring up View");
1721 if (strcmp (application_args.no_view, "-noview") != 0)
1723 if (application_args.session != NULL)
1725 RestoreSession (application_args.session, NORMAL_RESTORE, NULL);
1726 else if (application_args.directories != NULL)
1728 restoreType = CURRENT_DIR_RESTORE;
1729 OpenDirectories (application_args.directories, NULL);
1733 #ifdef DT_PERFORMANCE
1734 gettimeofday(&update_time_f, NULL);
1735 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1736 update_time_f.tv_usec += 1000000;
1737 update_time_f.tv_sec--;
1739 printf(" done Bringing up view, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec); fflush(stdout);
1741 /* Added by Aloke Gupta */
1742 _DtPerfChkpntMsgSend("Done Bring up View");
1746 /* If no views were opened upon invocation, display the */
1747 /* current directory. */
1749 if ( (strcmp (application_args.no_view, "-noview") != 0) &&
1750 ((application_args.session == NULL) ||
1751 (session_flag != 0)) )
1753 if (view_count == 0)
1755 /* Get users pwd so we can create a fileviewer window of it */
1756 GetPWD(current_directory);
1758 if (current_directory[0] != NULL)
1760 if (!GetNewView (home_host_name, current_directory, NULL, NULL, 0))
1761 ViewHomeDirectoryHandler (0);
1765 ViewHomeDirectoryHandler (0);
1771 /* Set up the timer based directory reading. */
1772 InitializeDirectoryRead (toplevel);
1774 /* Process and dispatch incoming events */
1775 eventDebugging = getenv("EVENT_DEBUGGING") != NULL;
1777 #ifdef DT_PERFORMANCE
1778 printf(" InitializeToolTalkSession\n");
1779 gettimeofday(&update_time_s, NULL);
1781 (void) InitializeToolTalkSession( toplevel, ttFd );
1782 #ifdef DT_PERFORMANCE
1783 gettimeofday(&update_time_f, NULL);
1784 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1785 update_time_f.tv_usec += 1000000;
1786 update_time_f.tv_sec--;
1788 printf(" done InitializeToolTalkSession, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1791 #ifdef DT_PERFORMANCE
1792 gettimeofday(&update_time_fs, NULL);
1793 if (update_time_ss.tv_usec > update_time_fs.tv_usec) {
1794 update_time_fs.tv_usec += 1000000;
1795 update_time_fs.tv_sec--;
1797 printf(" Finish, time: %ld.%ld\n\n", update_time_fs.tv_sec - update_time_ss.tv_sec, update_time_fs.tv_usec - update_time_ss .tv_usec);
1802 XtNextEvent(&event);
1804 if (event.type != 0)
1805 XtDispatchEvent(&event);
1811 /************************************************************************
1815 ************************************************************************/
1820 XErrorEvent *event )
1822 #define _DTFILE_BUFSIZE 1024
1823 char errmsg[_DTFILE_BUFSIZE];
1825 _DtPrintDefaultErrorSafe (disp, event, errmsg, _DTFILE_BUFSIZE);
1826 _DtSimpleError(application_name, DtWarning, NULL, errmsg, NULL);
1827 xErrorDetected = True;
1829 /* We do not want to exit here lets try to continue... */
1834 ToolkitErrorHandler(
1840 tmpStr = GETMESSAGE(18, 6, "An X Toolkit error occurred... Exiting.\n");
1841 msg = (char *)malloc(strlen(tmpStr) + strlen(message) + 3);
1842 strcpy(msg, message);
1844 strcat(msg, tmpStr);
1845 _DtSimpleError (application_name, DtError, NULL, msg);
1848 FinalizeToolTalkSession( );
1855 /************************************************************************
1858 * When incorrect parameters have been specified on the command
1859 * line, print out a set of messages detailing the correct use
1862 ************************************************************************/
1869 char * message_string1 = "\nUsage: %s...\n\n"
1871 "Dtfile runs in server mode.\n\n"
1872 " -session SessionFile\n\n\t"
1873 "Dtfile runs with the session file specified in the SessionFile\n\t"
1875 " -folder Folder[,Folder,Folder]\n"
1876 " -dir Folder[,Folder,Folder]\n\n\t"
1877 "Dtfile displays a window for each folder specified in the\n\t"
1878 "Folder parameter. The Folder parameter may contain many\n\t"
1879 "folders separated by commas. Folders may be in the form\n\t"
1881 " -title Title\n\n\t"
1882 "Dtfile uses the string specified in the Title parameter as the\n\t"
1883 "title for its windows.\n\n"
1884 " -help_volume HelpVolume\n\n\t"
1885 "Dtfile uses the help volume specified in the HelpVolume parameter.\n\n"
1886 " -restricted\n\n\t"
1887 "Dtfile will not display folders above the restricted folder.\n\t"
1888 "If the -dir option is used, the folder specified in that option\n\t"
1889 "is the restricted folder. If the -dir option is not used, the\n\t"
1890 "user's current folder is the restricted folder.\n\n"
1891 " -grid on/off\n\n\t"
1892 "on = Files are displayed in a grid pattern.\n\t"
1893 "off = Files are displayed as placed.\n\n"
1894 " -tree on/off\n\n\t"
1895 "on = Files are displayed in single folder mode.\n";
1897 char * message_string2 = "\toff = Files are displayed in folder tree mode.\n\n"
1898 " -tree_files never/always/choose\n\n\t"
1899 "never = Tree mode has two states: partially expanded or collapsed.\n\t"
1900 "always = Tree mode has two states: fully expanded or collapsed.\n\t"
1901 "choose = Tree mode has three states: partially expanded, fully\n\t"
1902 " expanded, or collapsed.\n\n"
1903 " -order alphabetical/file_type/date/size\n\n\t"
1904 "Files are displayed in the specified order: alphabetical, by file\n\t"
1905 "type, by date, or by size.\n\n"
1906 " -view no_icon/large_icon/small_icon/attributes\n\n\t"
1907 "Files are displayed in the specified format: text only, text and\n\t"
1908 "large icons, text and small icons, with attributes.\n\n"
1909 " -direction ascending/descending\n\n\t"
1910 "Files are displayed in the specified direction: ascending or\n\t"
1912 " -large_icon_width <size>\n\n"
1913 " -large_icon_height <size>\n\n"
1914 " -small_icon_width <size>\n\n"
1915 " -small_icon_height <size>\n\n"
1916 " The display area size for the icon images in File Manager\n"
1917 " Icon images larger than this size will be clipped to this size\n"
1918 " The default display area size for large is 38 and small is 24\n\n"
1922 template = (GETMESSAGE(18,23, message_string1));
1923 fprintf (stderr, template, argv[0]);
1924 template = (GETMESSAGE(18,24, message_string2));
1925 fprintf (stderr, template);
1935 char * message_string = "\nRestricted Mode Usage: %s...\n\n"
1936 " -folder Folder[,Folder,Folder]\n"
1937 " -dir Folder[,Folder,Folder]\n\n\t"
1938 "Where Folder is a Folder below and/or including\n\t"
1939 "the user's Home Folder.\n\n";
1941 template = (GETMESSAGE(18,26, message_string));
1943 fprintf (stderr, template, argv[0]);
1945 FinalizeToolTalkSession( );
1952 /************************************************************************
1955 * Catches Ctrl C's and exits.
1957 ************************************************************************/
1962 FinalizeToolTalkSession( );
1972 /***********************************************************************
1974 * RestoreSettingsFile
1975 * Used to restore the save settings files from
1976 * either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
1978 ***********************************************************************/
1980 RestoreSettingsFile( void )
1984 char *homeSavePath=NULL;
1985 char *homeHomePath=NULL;
1986 char *toolSavePath=NULL;
1987 char *toolHomePath=NULL;
1991 unsigned long nitems;
1992 unsigned long leftover;
1993 unsigned char *data = NULL;
1996 /* go get the dt path */
1997 /* _DtCreateDtDirs returs a path of MaxPath Length */
1998 dtPath = (char *)_DtCreateDtDirs(display);
2000 /* Determin which type of session we are running HOME or CURRENT */
2002 /* get the root window property of SaveMode */
2003 XGetWindowProperty(display, RootWindow(display,0),
2004 save_mode, 0L, (long)BUFSIZ,False,
2005 XA_STRING, &actualType,
2006 &actualFormat,&nitems,&leftover,
2009 if(strcmp((char *)data, "home") == 0)
2010 dirName = XtNewString("home");
2011 else if(strcmp((char *)data, "current") == 0)
2012 dirName = XtNewString("current");
2016 return; /* we are comming up in a system mode (e.g. default) */
2020 /* Build the paths to read the files from */
2022 toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2023 strlen(TOOL_SETTINGS_FILENAME) +
2024 strlen(dirName) + 4);
2026 homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2027 strlen(HOME_SETTINGS_FILENAME) +
2028 strlen(dirName) + 4);
2030 sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2031 sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2033 /* open the home settings file to see if its there */
2034 if((fd = open(homeSavePath, O_RDONLY)) != -1)
2037 /* create where the saved file is going to go */
2039 homeHomePath = (char *)XtMalloc(strlen(dtPath) +
2040 strlen(HOME_SETTINGS_FILENAME) + 2);
2042 sprintf( homeHomePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2044 /* remove any existing dtfile.home (e.g. HOME_SETTINGS_FILENAME) */
2045 unlink(homeHomePath);
2047 /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2048 * will be used by the dtfile
2050 status = link(homeSavePath, homeHomePath);
2055 tmpStr = GETMESSAGE(18,27, "Unable to recover the saved default home settings file, will use default.\n");
2056 msg = XtNewString(tmpStr);
2057 _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2063 /* open the tool settings file to see if its there */
2064 if((fd = open(toolSavePath, O_RDONLY)) != -1)
2067 /* create where the saved file is going to go */
2068 toolHomePath = (char *)XtMalloc(strlen(dtPath) +
2069 strlen(TOOL_SETTINGS_FILENAME) + 2);
2071 sprintf( toolHomePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2073 /* remove any existing dtfile.tool (e.g. TOOL_SETTINGS_FILENAME) */
2074 unlink(toolHomePath);
2076 /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2077 * will be used by the dtfile
2079 status = link(toolSavePath, toolHomePath);
2084 tmpStr = GETMESSAGE(18,28, "Unable to recover the saved default tool settings file, will use default.\n");
2085 msg = XtNewString(tmpStr);
2086 _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2096 XtFree(homeSavePath);
2097 XtFree(toolSavePath);
2098 XtFree(toolHomePath);
2099 XtFree(homeHomePath);
2108 /***********************************************************************
2110 * MoveDefaultSettings
2111 * Used to save the dtfile.tool and dtfile.home settings files to
2112 * either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
2113 * The parameter mode determines whether it is home or
2116 ***********************************************************************/
2118 MoveDefaultSettings(
2122 char *toolSavePath=NULL;
2123 char *homeSavePath=NULL;
2125 char *toolMovePath=NULL;
2126 char *homeMovePath=NULL;
2129 /* determine whether home or current */
2130 if(mode == HOME_DIR_RESTORE)
2131 dirName = XtNewString("home");
2133 dirName = XtNewString("current");
2135 /* go get the dt path */
2136 /* _DtCreateDtDirs returs a path of MaxPath Length */
2137 dtPath = (char *)_DtCreateDtDirs(display);
2140 /* Build the paths to save the files to */
2142 toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2143 strlen(TOOL_SETTINGS_FILENAME) +
2144 strlen(dirName) + 4);
2146 homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2147 strlen(HOME_SETTINGS_FILENAME) +
2148 strlen(dirName) + 4);
2151 /* create the directory and filename of where its going to be saved */
2152 sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2153 sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2155 /* Setup the paths used to GET the old files */
2157 toolMovePath= (char *)XtMalloc(strlen(dtPath) +
2158 strlen(TOOL_SETTINGS_FILENAME) + 3);
2160 homeMovePath= (char *)XtMalloc(strlen(dtPath) +
2161 strlen(HOME_SETTINGS_FILENAME) + 3);
2163 /* create the filename of where its going to be saved from */
2165 /* Tool File location */
2166 sprintf( toolMovePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2168 /* Home File location */
2169 sprintf( homeMovePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2172 /* get rid of the tool settings file that is already in home or current */
2173 status = unlink(toolSavePath);
2175 /* get rid of the home settings file that is already in home or current */
2176 status = unlink(homeSavePath);
2179 /* now save tool settings file in home or current determined by savePath */
2180 status = link(toolMovePath, toolSavePath);
2182 /* now save home settings file in home or current determined by savePath */
2183 status = link(homeMovePath, homeSavePath);
2186 XtFree(homeMovePath);
2187 XtFree(toolMovePath);
2188 XtFree(homeSavePath);
2189 XtFree(toolSavePath);
2195 /************************************************************************
2198 * Callback for the Save Settings menupick.
2200 ************************************************************************/
2204 XtPointer client_data,
2205 XtPointer call_data )
2212 FileMgrRec * file_mgr_rec;
2213 DialogData * dialog_data;
2214 FileMgrData * file_mgr_data;
2217 /* Strip the file_mgr_rec from the current widget
2218 * and attach it to the ok callback button
2222 /* Get the file_mgr_rec hanging off the menubar */
2223 mbar = XmGetPostedFromWidget(XtParent(w));
2224 XmUpdateDisplay (w);
2225 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2226 XtGetValues(mbar, args, 1);
2229 /* Ignore accelerators when we're insensitive */
2230 if ((file_mgr_rec->menuStates & SETTINGS) == 0)
2232 XSetInputFocus(XtDisplay(w),
2233 XtWindow(file_mgr_rec->defaultEnvBtn_child),
2234 RevertToParent, CurrentTime);
2238 /* Desensatize the save settings menu pick here */
2239 file_mgr_rec->menuStates &= ~SETTINGS;
2242 /* Get the file_mgr_rec dialog data info */
2243 if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
2245 file_mgr_data = (FileMgrData *) dialog_data->data;
2248 /* Based on the path we must determine if we are saving a Tools or
2249 * HomeDir dtfile view.
2251 if (file_mgr_data->restricted_directory != NULL && file_mgr_data->toolbox)
2252 file_mgr_data->restoreKind = TOOL_RESTORE;
2254 file_mgr_data->restoreKind = HOME_RESTORE;
2257 /* Setup and call the _DtMessageDialog procedure to post the dialog */
2259 if (file_mgr_data->restoreKind == HOME_RESTORE)
2261 tmpStr = (GETMESSAGE(18,29, "Save the current File Manager View window size,\npreferences, and filter settings?\n\nThey will be used for any new File Manager View windows\nstarted from the Front Panel."));
2265 tmpStr = (GETMESSAGE(18,35, "Save the current Application Manager\nView window size, preferences, and filter settings?\n\nThey will be used for any new Application Manager\nwindows started from the Front Panel."));
2267 message = XtNewString(tmpStr);
2269 if(file_mgr_data->title != NULL &&
2270 strcmp(file_mgr_data->helpVol, DTFILE_HELP_NAME) != 0)
2272 tmpStr = GETMESSAGE(18, 16, "Save As Default Options");
2273 title = (char *)XtMalloc(strlen(tmpStr) +
2274 strlen(file_mgr_data->title) + 5);
2275 sprintf(title, "%s - %s", file_mgr_data->title, tmpStr);
2279 tmpStr = GETMESSAGE(18, 32, "File Manager - Save As Default Options");
2280 title = XtNewString(tmpStr);
2282 dlog = (Widget)_DtMessageDialog(mbar, title, message, NULL, TRUE,
2283 SaveDefaultCancelCB, SaveDefaultOkCB, NULL,
2284 HelpRequestCB, False, QUESTION_DIALOG);
2285 file_mgr_rec->defaultEnvBtn_child=dlog;
2290 /* Add array as userdata on the dialog. */
2292 XtSetArg(args[0], XmNuserData, file_mgr_rec);
2293 XtSetValues(dlog, args, 1);
2297 /************************************************************************
2299 * SaveDefaultCancelCB
2300 * Cleanup and unmanage the save settings dialog.
2302 ************************************************************************/
2304 SaveDefaultCancelCB(
2306 XtPointer client_data,
2307 XtPointer call_data )
2309 FileMgrRec * file_mgr_rec;
2312 /* Update the display, and un-post the dialog */
2313 XtUnmanageChild((Widget)client_data);
2314 XmUpdateDisplay((Widget)client_data);
2315 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2316 XtGetValues((Widget)client_data, args, 1);
2319 /* Re-sensatize the save settings menu pick */
2320 file_mgr_rec->menuStates |= SETTINGS;
2323 XtDestroyWidget((Widget)client_data);
2328 /************************************************************************
2331 * Save the current dtfile view as the default environment for
2332 * new dtfiles created.
2334 ************************************************************************/
2338 XtPointer client_data,
2339 XtPointer call_data )
2342 FileMgrRec * file_mgr_rec;
2343 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
2344 char view_number[5];
2348 DialogData * dialog_data;
2349 FileMgrData * file_mgr_data;
2352 char full_path[MAX_PATH + 1];
2355 char * save_directory;
2356 char ** save_branch_list;
2357 FileViewData ** save_selection_list;
2358 int save_selected_file_count;
2361 /* Get the file_mgr_rec hanging off the dialog */
2362 XtUnmanageChild((Widget)client_data);
2363 XmUpdateDisplay ((Widget)client_data);
2364 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2365 XtGetValues((Widget)client_data, args, 1);
2368 /* Re-sensatize the save settings menu pick */
2369 file_mgr_rec->menuStates |= SETTINGS;
2372 /* Get the file_mgr_rec dialog data info */
2374 dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
2375 file_mgr_data = (FileMgrData *) dialog_data->data;
2378 /* Build the path for our env file */
2380 tmp_path = _DtCreateDtDirs(display);
2381 if (tmp_path == NULL)
2383 XtDestroyWidget(client_data);
2388 /* Look and see what type of restore we are doing */
2389 if (file_mgr_data->restoreKind == TOOL_RESTORE)
2391 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
2392 application_args.tool_width = file_mgr_data->width;
2393 application_args.tool_height = file_mgr_data->height;
2397 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
2398 application_args.dir_width = file_mgr_data->width;
2399 application_args.dir_height = file_mgr_data->height;
2405 /* Create the Environment session file */
2407 if ((fd = creat(full_path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2410 tmpStr = GETMESSAGE(18, 17, "Unable to create a file to store the default options.");
2411 title = XtNewString((GETMESSAGE(21,38,"Object Create Error")));
2412 msg = XtNewString(tmpStr);
2413 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
2420 /* Write out the general information */
2422 (void) write (fd, "*", strlen ("*"));
2423 (void) write (fd, DTFILE_CLASS_NAME,strlen (DTFILE_CLASS_NAME));
2424 (void) write (fd, "*view_count: ", strlen ("*view_count: "));
2426 (void) sprintf (view_number, "%d", 1);
2427 (void) write (fd, view_number, strlen (view_number));
2428 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2430 name_list[1] = view_number;
2432 /* Temporarily remove data that we don't need or want saved */
2434 save_host = file_mgr_data->host;
2435 save_directory = file_mgr_data->current_directory;
2436 save_branch_list = file_mgr_data->branch_list;
2437 save_selection_list = file_mgr_data->selection_list;
2438 save_selected_file_count = file_mgr_data->selected_file_count;
2439 file_mgr_data->host = NULL;
2440 file_mgr_data->current_directory = NULL;
2441 file_mgr_data->branch_list = NULL;
2442 file_mgr_data->selection_list = NULL;
2443 file_mgr_data->selected_file_count = 0;
2445 /* Call the encapsulation mechanism to write each dialog */
2447 (void) sprintf (view_number, "%d", 0);
2448 _DtWriteDialogData (dialog_data, fd, name_list);
2449 (void) write (fd, "#\n", strlen ("#\n"));
2451 /* Restore the data that was temporarily removed */
2453 file_mgr_data->host = save_host;
2454 file_mgr_data->current_directory = save_directory;
2455 file_mgr_data->branch_list = save_branch_list;
2456 file_mgr_data->selection_list = save_selection_list;
2457 file_mgr_data->selected_file_count = save_selected_file_count;
2461 XtDestroyWidget(client_data);
2467 /************************************************************************
2469 * SaveSessionCallback
2470 * Get the session name and call the function to save the session.
2472 ************************************************************************/
2475 SaveSessionCallback(
2477 XtPointer client_data,
2478 XtPointer call_data )
2480 char * full_path=NULL;
2481 char * file_name=NULL;
2483 int restore=NORMAL_RESTORE;
2484 Boolean status=FALSE;
2485 char * sessionFileName;
2488 if(view_count == 0 && desktop_data->numIconsUsed == 0)
2490 XChangeProperty (display, XtWindow (toplevel), command_atom,
2491 XA_STRING, 8, PropModeReplace, (unsigned char *)NULL, 0);
2492 XSync(display, False);
2493 FinalizeToolTalkSession( );
2497 status = DtSessionSavePath(w, &full_path, &file_name);
2500 sessionFileName = file_name;
2503 XtFree( (char *)full_path);
2504 full_path = (char *) XtMalloc (sizeof (char) * MAX_PATH);
2505 sprintf( full_path, "%s/%s", dt_path, DTFILE_CLASS_NAME );
2506 sessionFileName = full_path;
2508 SaveSession( full_path );
2510 /* skip to the /.dt/ portion of the sessionFileName */
2511 strPtr = strstr(full_path, "/.dt/");
2512 (void)strcpy(full_path, strPtr);
2514 /* Save off the settings files for both tool and home views */
2516 strPtr = DtStrrchr(full_path, '/');
2519 if ((strncmp(strPtr, "/home", 5) == 0))
2520 restore = HOME_DIR_RESTORE;
2521 else if ((strncmp(strPtr, "/current", 8) == 0))
2522 restore = CURRENT_DIR_RESTORE;
2526 } while ((strPtr != NULL) && (restore == NORMAL_RESTORE));
2528 SaveDesktopInfo(restore);
2530 /* Cop the settings files to the proper dir */
2531 MoveDefaultSettings(restore);
2533 /* Generate the reinvoking command and add it as the property value */
2534 argv = (char **) XtMalloc(3 * sizeof(char *));
2535 argv[0] = XtNewString(application_name);
2536 argv[1] = XtNewString("-session");
2537 argv[2] = XtNewString(sessionFileName);
2538 XSetCommand(XtDisplay(toplevel), XtWindow(toplevel), argv, 3);
2540 XtFree ((char *) argv[0]);
2541 XtFree ((char *) argv[1]);
2542 XtFree ((char *) argv[2]);
2543 XtFree ((char *) argv);
2545 XtFree ((char *) full_path);
2546 XtFree ((char *) file_name);
2549 /************************************************************************
2552 * Save the current File Manager session as a set of resources
2553 * within the file denoted by path.
2555 ************************************************************************/
2562 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2564 char view_number[5];
2566 char workspaceNumber[5];
2568 Atom * ws_presence = NULL;
2569 char * workspace_name=NULL;
2570 unsigned long num_workspaces = 0;
2574 unsigned long nitems;
2575 unsigned long leftover;
2576 WM_STATE * wm_state;
2578 DialogData * dialog_data;
2579 FileMgrData * file_mgr_data;
2580 FileMgrRec * file_mgr_rec;
2585 WorkspaceRec * workspaceInfo;
2588 char *actualSavedTitle;
2590 /* This needs to be done because name_list is static and the values
2591 can be changed during the routine. This means that they need to be
2592 NULL'd out each pass */
2593 name_list[1] = NULL;
2594 name_list[2] = NULL;
2595 name_list[3] = NULL;
2596 name_list[4] = NULL;
2597 name_list[5] = NULL;
2599 /* Disable any message box display during save session */
2601 message_display_enabled = False;
2604 /* Create the session file */
2606 if ((fd = creat (path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2608 tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2609 msg = XtNewString(tmpStr);
2610 _DtSimpleError (application_name, DtError, NULL, msg);
2612 message_display_enabled = True;
2618 /* Write out the general information */
2620 /* Number of dtfile views */
2621 (void) write (fd, "*", strlen ("*"));
2622 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2623 (void) write (fd, "*view_count: ", strlen ("*view_count: "));
2625 if (trashFileMgrData)
2627 if (trashFileMgrData->file_mgr_rec)
2628 (void) sprintf (view_number, "%d", view_count + 1);
2630 (void) sprintf (view_number, "%d", view_count);
2634 (void) sprintf (view_number, "%d", view_count);
2636 (void) write (fd, view_number, strlen (view_number));
2637 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2639 (void) write (fd, "*", strlen ("*"));
2640 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2641 (void) write (fd, "*showFilesystem: ", strlen ("*showFilesystem: "));
2644 (void) write (fd, "True", strlen ("True"));
2646 (void) write (fd, "False", strlen ("False"));
2647 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2649 (void) write (fd, "*", strlen ("*"));
2650 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2651 (void) write (fd, "*restrictMode: ", strlen ("*restrictMode: "));
2654 (void) write (fd, "True", strlen ("True"));
2656 (void) write (fd, "False", strlen ("False"));
2657 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2659 (void) write (fd, "*", strlen ("*"));
2660 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2661 (void) write (fd, "*openFolder: ", strlen ("*openFolder: "));
2663 if(openDirType == NEW)
2664 (void) write (fd, "NEW", strlen ("NEW"));
2666 (void) write (fd, "CURRENT", strlen ("CURRENT"));
2667 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2670 name_list[1] = view_number;
2674 /* Write out each of the view's resources */
2675 /* start with -1 so we can include the trash dialog */
2676 for (i = -1; i < view_count; i++)
2681 dialog_data = (DialogData *) trashDialogData;
2687 dialog_data = (DialogData *) view_set[i]->dialog_data;
2690 file_mgr_data = (FileMgrData *) dialog_data->data;
2691 if(i == -1 && trashDialogData)
2692 file_mgr_data->IsTrashCan = True;
2693 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
2694 if(file_mgr_rec == NULL)
2697 /* This is a bug fix ... We don't want to save the title if the
2698 View is the Trash Can of if it is an Application Manager. This
2699 is because if the user saves a session in one Locale, then logs
2700 in in another, the Title will be in the locale that the session was
2701 saved in rather then the new local. So let's save the Title,
2702 Null it out, Save the session info, and finally restore the Title.
2704 if(i == -1 || file_mgr_data->toolbox)
2706 /* the Trash Can or toolbox (i.e. Application Manager) */
2707 actualSavedTitle = file_mgr_data->title;
2708 file_mgr_data->title = NULL;
2712 /* Getting the WM_STATE property to see if iconified or not */
2713 XGetWindowProperty (display, XtWindow (file_mgr_rec->shell),
2714 wm_state_atom, 0L, (long) BUFSIZ, False,
2715 wm_state_atom, &actual_type, &actual_format,
2716 &nitems, &leftover, (unsigned char **) &wm_state);
2718 /* Write out if iconified our not */
2720 write (fd, "*", strlen ("*"));
2721 write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2722 sprintf (view_number, "%d", view_index);
2723 write (fd, ".", strlen ("."));
2724 write (fd, view_number, strlen (view_number));
2726 (void) write (fd, ".iconify: ", strlen (".iconify: "));
2728 if (wm_state->state == IconicState)
2729 write (fd, "True\n", strlen ("True\n"));
2731 write (fd, "False\n", strlen ("False\n"));
2734 /* Get the workspaces for this dt by accessing the property. */
2736 if (DtWsmGetWorkspacesOccupied (display, XtWindow (file_mgr_rec->shell),
2737 &ws_presence, &num_workspaces) == Success)
2739 write (fd, "*", strlen ("*"));
2740 write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2741 (void) write (fd, ".", strlen ("."));
2742 (void) write (fd, view_number, strlen (view_number));
2743 (void) write (fd, ".workspace: ", strlen (".workspace: "));
2746 for (j = 0; j < num_workspaces; j++)
2748 if (j != 0) (void) write (fd, "*", strlen ("*"));
2749 workspace_name = XGetAtomName (display, ws_presence[j]);
2750 (void) write (fd, workspace_name, strlen (workspace_name));
2751 XtFree ((char *) workspace_name);
2755 (void) write (fd, "\n", strlen ("\n"));
2756 XFree((char *)ws_presence);
2760 /* Call the encapsulation mechanism to write each dialog */
2763 _DtWriteDialogData (trashDialogData, fd, name_list);
2765 _DtWriteDialogData ((DialogData *)view_set[i]->dialog_data,
2767 (void) write (fd, "#\n", strlen ("#\n"));
2772 file_mgr_data->title = actualSavedTitle;
2778 * Save off help dialog information for each workspace.
2779 * These are the help dialogs used for the desktop objects.
2781 name_list[1] = WS_LOAD_RES_HEADER;
2782 name_list[2] = workspaceNumber;
2783 name_list[3] = number;
2785 for (i = 0; i < desktop_data->numWorkspaces; i++)
2787 workspaceInfo = desktop_data->workspaceData[i];
2790 * Save number of secondary help dialogs in format:
2791 * *Dtfile.Workspace.<WS#>.secondaryHelpDialogCount: <#>
2793 write(fd, "*", strlen("*"));
2794 write(fd, DTFILE_CLASS_NAME, strlen(DTFILE_CLASS_NAME));
2795 write(fd, WS_RES_HEADER, strlen(WS_RES_HEADER));
2796 sprintf(workspaceNumber, "%d", i);
2797 write(fd, workspaceNumber, strlen(workspaceNumber));
2798 write(fd, SEC_HELP_RES_HEADER, strlen(SEC_HELP_RES_HEADER));
2799 sprintf(view_number, "%d", workspaceInfo->secondaryHelpDialogCount);
2800 write(fd, view_number, strlen(view_number));
2801 write (fd, "\n#\n", strlen ("\n#\n"));
2803 /* Save each of the secondary help dialogs */
2804 for (j = 0; j < workspaceInfo->secondaryHelpDialogCount; j++)
2806 sprintf(number, "%d", j + 1);
2807 _DtWriteDialogData(workspaceInfo->secondaryHelpDialogList[j],
2811 /* Save the primary help dialog window */
2812 if (workspaceInfo->primaryHelpDialog)
2814 sprintf(number, "%d", 0);
2815 _DtWriteDialogData(workspaceInfo->primaryHelpDialog,
2818 write (fd, "#\n", strlen ("#\n"));
2822 /* Re-able message box display flag after save session */
2823 message_display_enabled = True;
2831 * Given a directory name, this function will see if a view of the parent
2832 * directory is open; if so, then it will update the icon representing
2833 * this icon, in the parent view, so that it is drawn as 'open'. This
2834 * function must only be called if openDirType == NEW.
2840 char * directory_name)
2842 FileViewData * file_view_data = NULL;
2843 DesktopRec *desktopWindow;
2851 char *icon_name, *new_file_type_name, *file_type_name;
2854 /* if directory_name is passed in a NULL, we want to go through all
2855 existing open directories and check to see if there are any open
2856 directories in each of them. This is used at the end of OpenNewView
2857 and the end of ShowNewDirectory */
2858 if (directory_name == NULL)
2860 for (i = 0; i < view_count; i++)
2862 dd = (DialogData *) view_set[i]->dialog_data;
2863 fmd = (FileMgrData *) dd->data;
2865 for(j = 0; j < fmd->directory_count; j++)
2867 ForceMyIconOpen(view_set[i]->host_name,
2868 fmd->directory_set[j]->name);
2874 parent = _DtPName(directory_name);
2875 fname = DName(directory_name);
2877 /* first lets check to see if the directory is open in one of the
2878 open file manager views */
2879 for (i = 0; i < view_count; i++)
2881 dd = (DialogData *) view_set[i]->dialog_data;
2882 fmd = (FileMgrData *) dd->data;
2884 /* loop through until we find the file_view_data structure for the
2885 directory to force open */
2886 if (strcmp(host_name, view_set[i]->host_name) == 0)
2888 for(j = 0; j < fmd->directory_count; j++)
2890 if (strcmp(parent, fmd->directory_set[j]->name) == 0)
2892 for (k = 0; k < fmd->directory_set[j]->file_count; k++)
2894 file_view_data = fmd->directory_set[j]->file_view_data[k];
2895 if (strcmp(file_view_data->file_data->file_name, fname) == 0)
2897 file_view_data = NULL;
2906 fmd = (FileMgrData *)(((DirectorySet *)file_view_data->directory_set)->
2909 file_type_name = file_view_data->file_data->logical_type;
2911 if(fmd->view != BY_NAME)
2912 BuildAndShowIconName(file_type_name, fmd->view,
2913 fmd->show_type, file_view_data->widget);
2917 /* now we need to check to see if the directory being opened has a
2918 representation on the Desktop */
2919 for(i = 0; i < desktop_data->numIconsUsed; i++)
2923 desktopWindow = desktop_data->desktopWindows[i];
2924 file_view_data = desktopWindow->file_view_data;
2926 sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
2927 desktopWindow->file_name);
2928 DtEliminateDots (buf);
2930 if (strcmp(buf, directory_name) == 0 &&
2931 strcmp(desktopWindow->host, host_name) == 0)
2933 file_type_name = file_view_data->file_data->logical_type;
2934 if(desktopIconType == LARGE)
2935 BuildAndShowIconName(file_type_name, BY_NAME_AND_ICON,
2936 SINGLE_DIRECTORY, desktopWindow->iconGadget);
2938 BuildAndShowIconName(file_type_name, BY_NAME_AND_SMALL_ICON,
2939 SINGLE_DIRECTORY, desktopWindow->iconGadget);
2947 /************************************************************************
2950 * Open the file as a resource data base, and use the data to
2951 * create a set of File Manager views.
2953 ************************************************************************/
2958 int type_of_restore,
2961 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2964 XrmName xrm_name[10];
2965 XrmRepresentation rep_type;
2968 char * full_path = NULL;
2969 Boolean status=False;
2973 int num_sec_help_dialogs;
2976 DialogData * dialogData;
2977 struct stat stat_buf;
2980 /* Build the session path if we need to.
2981 * (e.g. When using the -session option)
2983 if (type_of_restore == NORMAL_RESTORE)
2985 status = DtSessionRestorePath(toplevel, &full_path, path);
2990 if (stat(full_path, &stat_buf) != 0)
2992 char *tmpStr, *msg, *title;
2994 tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2995 msg = XtNewString(tmpStr);
2996 title = XtNewString((GETMESSAGE(21,39,"File Open Error")));
2997 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
3005 path = XtNewString(full_path);
3008 /* This prevents the encapsulator from placing the dialogs */
3009 disableDialogAutoPlacement = True;
3011 /* Open the file as a resource database and query it to */
3012 /* get the previously saved view count. */
3014 db = XrmGetFileDatabase (path);
3016 if (type_of_restore == NORMAL_RESTORE)
3018 /* first find out if it should show the file system */
3019 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3020 xrm_name [1] = XrmStringToQuark ("showFilesystem");
3021 xrm_name [2] = NULL;
3022 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3024 if ((temp = (char *) value.addr) != NULL &&
3025 strcmp (temp, "True") == 0)
3027 showFilesystem = True;
3030 showFilesystem = False;
3033 showFilesystem = True;
3035 /* find out if it should be in restricted mode */
3036 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3037 xrm_name [1] = XrmStringToQuark ("restrictMode");
3038 xrm_name [2] = NULL;
3039 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3041 if ((temp = (char *) value.addr) != NULL &&
3042 strcmp (temp, "True") == 0)
3044 restrictMode = True;
3047 restrictMode = False;
3050 restrictMode = False;
3052 /* find out openFolder mode */
3053 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3054 xrm_name [1] = XrmStringToQuark ("openFolder");
3055 xrm_name [2] = NULL;
3056 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3058 if ((temp = (char *) value.addr) != NULL &&
3059 strcmp (temp, "NEW") == 0)
3064 openDirType = CURRENT;
3067 openDirType = CURRENT;
3070 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3071 xrm_name [1] = XrmStringToQuark ("view_count");
3072 xrm_name [2] = NULL;
3074 /* Load standard dtfile views */
3075 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3077 num_views = atoi (value.addr);
3079 LoadViews(num_views, db, NULL, directory, special_restricted, 0);
3082 /* Restore any desktop help dialogs */
3083 if (type_of_restore == NORMAL_RESTORE)
3085 for (i = 0; i < desktop_data->numWorkspaces; i++)
3087 sprintf(wsNum, "%d", i);
3088 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3089 xrm_name [1] = XrmStringToQuark (WS_LOAD_RES_HEADER);
3090 xrm_name [2] = XrmStringToQuark (wsNum);
3091 xrm_name [3] = XrmStringToQuark (SEC_LOAD_HELP_RES_HEADER);
3092 xrm_name [4] = NULL;
3094 /* Load standard dtfile views */
3095 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3097 num_sec_help_dialogs = atoi (value.addr);
3098 if (num_sec_help_dialogs > 0)
3100 desktop_data->workspaceData[i]->secondaryHelpDialogCount =
3101 num_sec_help_dialogs;
3102 desktop_data->workspaceData[i]->secondaryHelpDialogList =
3103 (DialogData **) XtMalloc(sizeof(DialogData *) *
3104 num_sec_help_dialogs);
3106 for (j = 0; j < num_sec_help_dialogs; j++)
3108 name_list[0] = DTFILE_CLASS_NAME;
3109 name_list[1] = WS_LOAD_RES_HEADER;
3110 name_list[2] = wsNum;
3111 name_list[3] = dialogNum;
3112 name_list[4] = NULL;
3113 sprintf(dialogNum, "%d", j + 1);
3115 _DtGetResourceDialogData(help_dialog, db, name_list);
3116 desktop_data->workspaceData[i]->secondaryHelpDialogList[j]=
3118 ShowDTHelpDialog(NULL, i, HYPER_HELP_DIALOG,
3119 dialogData, NULL, NULL, NULL, NULL,
3125 /* Load the primary help dialog */
3126 name_list[0] = DTFILE_CLASS_NAME;
3127 name_list[1] = WS_LOAD_RES_HEADER;
3128 name_list[2] = wsNum;
3129 name_list[3] = dialogNum;
3130 name_list[4] = NULL;
3131 sprintf(dialogNum, "%d", 0);
3132 dialogData = _DtGetResourceDialogData(help_dialog, db, name_list);
3134 /* Keep only if currently posted */
3135 if (!(((HelpData *)dialogData->data)->displayed))
3137 /* Not currently displayed */
3138 _DtFreeDialogData(dialogData);
3141 desktop_data->workspaceData[i]->primaryHelpDialog = dialogData;
3144 ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
3145 dialogData, NULL, DTFILE_HELP_NAME,
3154 /* Free the Xrm Database */
3155 XrmDestroyDatabase(db);
3156 disableDialogAutoPlacement = False;
3167 extern Tt_message FileCallback();
3168 extern Tt_message SessionCallback();
3170 if ((msg == 0) || tt_is_err( tt_ptr_error( msg ))) {
3175 * Register for notifications on the directory viewed.
3176 * This is done so that requesting apps can notify the
3177 * view if the directory name is changed.
3179 view->pats = ttdt_file_join( view->directory_name, TT_SESSION, 0,
3180 FileCallback, view );
3181 if (tt_is_err( tt_ptr_error( view->pats ))) {
3185 /* Returned patterns automatically get destroyed when msg is destroyed */
3186 ttdt_message_accept( msg, SessionCallback,
3187 _DtGetDialogShell( (DialogData *)view->dialog_data ),
3197 char *directory_name,
3202 XrmName xrm_name[5];
3203 XrmRepresentation rep_type;
3205 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
3206 char view_number[5];
3207 DialogData * dialog_data;
3208 FileMgrData * file_mgr_data;
3210 XClassHint classHints;
3211 char * iconify = NULL;
3212 Boolean iconify_window;
3214 char *title, *tmpTitle;
3216 name_list[1] = view_number;
3217 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3220 /* Get and display view_count views. */
3222 for (i = 0; i < num_views; i++)
3224 struct stat stat_buf;
3226 (void) sprintf (view_number, "%d", i);
3227 xrm_name [1] = XrmStringToQuark (view_number);
3229 /* Get the main dialog data and set up the view */
3231 dialog_data = _DtGetResourceDialogData (file_mgr_dialog, db, name_list);
3232 file_mgr_data = (FileMgrData *) dialog_data->data;
3234 if(file_mgr_data->toolbox && file_mgr_data->title == NULL)
3235 file_mgr_data->title = DtActionLabel("Dtappmgr");
3237 if (stat(file_mgr_data->current_directory, &stat_buf) != 0)
3239 _DtFreeDialogData(dialog_data);
3243 if (trashFileMgrData
3244 && (file_mgr_data->IsTrashCan == True)
3245 && strcmp(file_mgr_data->current_directory, trash_dir) == 0)
3247 trashFileMgrData->view = file_mgr_data->view;
3248 trashFileMgrData->order = file_mgr_data->order;
3249 trashFileMgrData->direction = file_mgr_data->direction;
3250 trashFileMgrData->positionEnabled = file_mgr_data->positionEnabled;
3251 trashFileMgrData->preferences = file_mgr_data->preferences;
3252 file_mgr_data->preferences = NULL;
3253 _DtFreeDialogData(dialog_data);
3257 /* Increment the view list size if necessary and add directory to list */
3259 if (view_count == view_set_size)
3261 view_set_size += 10;
3263 (View **) XtRealloc ((char *)view_set,
3264 sizeof (View **) * view_set_size);
3266 view_set[view_count] = (View *) XtMalloc (sizeof (View));
3267 view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3268 view_set[view_count]->msg = 0;
3269 view_set[view_count]->pats = 0;
3271 if(restoreType == TOOL_RESTORE)
3272 file_mgr_data->toolbox = True;
3274 if(directory_name == NULL)
3276 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3277 view_set[view_count]->directory_name =
3278 XtNewString (file_mgr_data->current_directory);
3282 XtFree(file_mgr_data->current_directory);
3283 file_mgr_data->current_directory = NULL;
3284 XtFree(file_mgr_data->restricted_directory);
3285 file_mgr_data->restricted_directory = NULL;
3287 view_set[view_count]->directory_name = XtNewString(directory_name);
3288 XtFree((char *)file_mgr_data->selection_list);
3289 file_mgr_data->selection_list = NULL;
3290 if(host_name == NULL)
3292 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3293 file_mgr_data->current_directory = XtNewString(directory_name);
3295 file_mgr_data->restricted_directory =
3296 XtNewString(directory_name);
3298 file_mgr_data->restricted_directory =
3303 view_set[view_count]->host_name = XtNewString (host_name);
3304 XtFree(file_mgr_data->host);
3305 file_mgr_data->host = XtNewString(host_name);
3306 file_mgr_data->current_directory = XtNewString(directory_name);
3307 if(special_view && special_restricted != NULL)
3308 file_mgr_data->restricted_directory =
3309 XtNewString(special_restricted);
3311 file_mgr_data->restricted_directory = NULL;
3313 FileMgrBuildDirectories (file_mgr_data,
3314 view_set[view_count]->host_name, directory_name);
3317 /* Get the workspace set the view is contained in */
3318 /* and set the property for the view just created */
3320 xrm_name [2] = XrmStringToQuark ("workspace");
3321 xrm_name [3] = NULL;
3323 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3325 /* Make sure we have some valid workspaces names to work with */
3327 /* value.addr should = NULL if no workspace names */
3328 workspaces = (char *) value.addr;
3331 /* we have no workspace resource so use default */
3334 /* Get and set whether the view is iconic */
3336 xrm_name [2] = XrmStringToQuark ("iconify");
3337 xrm_name [3] = NULL;
3339 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3341 /* If there is an iconify resource and its value is True, */
3342 /* then mark the window as iconified. */
3344 if ((iconify = (char *) value.addr) != NULL &&
3345 strcmp (iconify, "True") == 0)
3347 iconify_window = True;
3351 iconify_window = False;
3354 iconify_window = False;
3356 if(file_mgr_data->positionEnabled == RANDOM_ON &&
3357 (file_mgr_data->object_positions == NULL))
3358 LoadPositionInfo(file_mgr_data);
3360 /* Call _DtShowDialog to create and manage the new window */
3362 tmpTitle = file_mgr_data->title;
3363 title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3365 XtFree(special_title);
3366 special_title = XtNewString(title);
3368 classHints.res_name = title;
3369 classHints.res_class = DTFILE_CLASS_NAME;
3371 _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL,
3372 RemoveTextFields, NULL, workspaces, iconify_window,
3373 special_view, title, &classHints);
3376 file_mgr_data->title = tmpTitle;
3379 ViewAccept( view_set[view_count], msg );
3386 if (openDirType == NEW)
3387 ForceMyIconOpen(file_mgr_data->host, NULL);
3391 /************************************************************************
3395 ************************************************************************/
3398 char current_directory[] )
3403 /* Open a pwd process and read the current working directory */
3404 /* from it. If the open fails or a read fails, then display */
3405 /* the users home directory. */
3407 pwd_file = popen ("pwd", "r");
3410 if (pwd_file != NULL)
3415 if (fread (¤t_directory[i], sizeof(char), 1, pwd_file) != 1)
3423 if (current_directory[i] == '\n')
3429 (void) pclose (pwd_file);
3430 current_directory[i] = NULL;
3434 /************************************************************************
3437 * Given a string that contains a single or set of host:path
3438 * specifications, parse out each host:path, validate it as
3439 * a accessible directory, and call a function to create a
3440 * file manager view of the directory.
3442 ************************************************************************/
3446 char *directory_set,
3453 /* Loop the the directory set string until all of */
3454 /* the path specifications have be parsed. */
3458 separator = DtStrchr (directory_set, ',');
3459 if (separator != NULL)
3462 _DtPathFromInput(directory_set, NULL, &host, &path);
3466 GetNewView (host, path, type, NULL, 0);
3470 char *tmpStr, *errTitle, *errMsg, *dmsg;
3472 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3473 errTitle = XtNewString(tmpStr);
3474 tmpStr = GETMESSAGE(18, 38, "Invalid folder specification, %s");
3475 errMsg = XtNewString(tmpStr);
3476 dmsg = XtMalloc(strlen(errMsg)+strlen(directory_set)+1);
3477 sprintf(dmsg, errMsg, directory_set);
3478 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
3485 /* Free up the unique host and directory names */
3486 /* that were allocated. */
3488 XtFree ((char *) host);
3489 XtFree ((char *) path);
3491 /* Set the starting position of the next host:path */
3493 if (separator != NULL)
3494 directory_set = separator + 1;
3503 /************************************************************************
3506 * Given a directory name, generate a new view for the directory.
3508 ************************************************************************/
3512 char *directory_name,
3514 WindowPosition *position,
3517 DialogData * dialog_data;
3518 DialogInstanceData * instance_data;
3519 FileMgrData * file_mgr_data;
3521 FileMgrRec * file_mgr_rec;
3522 char * real_directory_name;
3524 XClassHint classHints;
3525 char *title, *tmpTitle;
3526 struct stat stat_buf;
3528 char *errMsg = NULL;
3530 DtEliminateDots( directory_name );
3532 if (stat(directory_name, &stat_buf) == 0)
3534 if ((stat_buf.st_mode & S_IFMT) != S_IFDIR)
3536 tmpStr = GETMESSAGE(18, 19,
3537 "The folder specification,\n%s\nis not a folder.");
3538 errMsg = XtNewString(tmpStr);
3543 tmpStr = GETMESSAGE(18, 20,
3544 "The folder specification,\n%s\ndoes not exist.");
3545 errMsg = XtNewString(tmpStr);
3552 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3553 title = XtNewString(tmpStr);
3554 dmsg = XtMalloc(strlen(errMsg) +
3555 strlen(directory_name) + 1);
3556 sprintf(dmsg, errMsg, directory_name);
3557 _DtMessage(toplevel, title, dmsg, NULL, HelpRequestCB);
3566 * Special case: When opening any of the special desktop directory
3567 * icons (Home, Remote Systems, etc), we want to display the correct
3568 * path (i.e. $HOME instead of $HOME/.dt/Desktop/Home). So ... we'll
3569 * do the remap here.
3571 real_directory_name = directory_name;
3573 if(openDirType == NEW || (strcmp(real_directory_name, desktop_dir) == 0))
3575 for(i = 0; i < view_count; i++)
3577 if((strcmp(real_directory_name, view_set[i]->directory_name) == 0 &&
3578 (strcmp(host_name, view_set[i]->host_name) == 0))
3583 Screen *currentScreen;
3586 dialog_data = (DialogData *) view_set[i]->dialog_data;
3587 file_mgr_data = (FileMgrData *) dialog_data->data;
3588 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
3590 screen = XDefaultScreen(display);
3591 currentScreen = XScreenOfDisplay(display, screen);
3592 rootWindow = RootWindowOfScreen(currentScreen);
3594 /* Get the current Workspace */
3595 if (DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
3598 Atom * ws_presence = NULL;
3599 unsigned long num_workspaces = 0;
3602 if (DtWsmGetWorkspacesOccupied(display,
3603 XtWindow(file_mgr_rec->shell), &ws_presence,
3604 &num_workspaces) == Success)
3606 /* Already in this workspace? */
3607 for (k = 0; k < num_workspaces; k++)
3609 if (ws_presence[k] == pCurrent)
3613 if (k >= num_workspaces)
3615 /* Add to the workspace */
3616 ws_presence = (Atom *) XtRealloc((char *)ws_presence,
3617 sizeof (Atom) * (num_workspaces + 1));
3619 ws_presence[num_workspaces] = pCurrent;
3620 DtWsmSetWorkspacesOccupied(display,
3621 XtWindow(file_mgr_rec->shell),
3622 ws_presence, num_workspaces + 1);
3624 XFree((char *)ws_presence);
3628 /* Change the hints to reflect the current workspace */
3629 DtWsmSetWorkspacesOccupied(display,
3630 XtWindow(file_mgr_rec->shell),
3635 /* must map the window to catch iconified windows */
3636 /* a XtPopup will not catch it */
3637 XtMapWidget(file_mgr_rec->shell);
3638 XRaiseWindow(display, XtWindow(file_mgr_rec->shell));
3640 /* announce activity */
3643 msg = tt_pnotice_create(TT_SESSION, "DtActivity_Began");
3644 tt_message_send(msg);
3645 tttk_message_destroy(msg);
3653 /* If in novice mode, force the icon for this dir to the 'Open' state */
3654 if (openDirType == NEW)
3655 ForceMyIconOpen(host_name, directory_name);
3657 /* Increment the list size if necessary. */
3659 if (view_count == view_set_size)
3661 view_set_size += 10;
3663 (View **) XtRealloc ((char *)view_set,
3664 sizeof (View **) * view_set_size);
3667 view_set[view_count] = (View *) XtMalloc (sizeof (View));
3668 view_set[view_count]->msg = 0;
3669 view_set[view_count]->pats = 0;
3671 if (initiating_view != NULL)
3672 dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3676 char full_path[MAX_PATH + 1];
3679 tmp_path = _DtCreateDtDirs(display);
3681 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
3683 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
3685 db = XrmGetFileDatabase (full_path);
3690 restoreType = TOOL_RESTORE;
3691 LoadViews(1, db, NULL, directory_name, type, msg);
3695 restoreType = HOME_RESTORE;
3696 LoadViews(1, db, host_name, directory_name, NULL, msg);
3700 * Free the Xrm Database
3702 XrmDestroyDatabase(db);
3703 dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
3704 file_mgr_data = (FileMgrData *) dialog_data->data;
3707 application_args.tool_width = file_mgr_data->width;
3708 application_args.tool_height = file_mgr_data->height;
3712 application_args.dir_width = file_mgr_data->width;
3713 application_args.dir_height = file_mgr_data->height;
3715 if(file_mgr_data->find != NULL &&
3716 file_mgr_data->current_directory != NULL)
3718 DialogData * dialog_data;
3719 FindData * find_data;
3721 dialog_data = (DialogData *)file_mgr_data->find;
3722 find_data = (FindData *)dialog_data->data;
3724 XtFree(find_data->directories);
3725 if(file_mgr_data->restricted_directory == NULL)
3728 find_data->directories = XtNewString(users_home_dir);
3730 find_data->directories =
3731 XtNewString(file_mgr_data->current_directory);
3735 if(strcmp(file_mgr_data->current_directory,
3736 file_mgr_data->restricted_directory) == 0)
3737 find_data->directories = XtNewString("/");
3739 find_data->directories =
3740 XtNewString(file_mgr_data->current_directory +
3741 strlen(file_mgr_data->restricted_directory));
3745 /* If in novice mode, force the icon for all the dir's to the
3747 if (openDirType == NEW)
3748 ForceMyIconOpen(host_name, NULL);
3750 return((DialogData *)view_set[view_count - 1]->dialog_data);
3753 dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3755 view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3756 file_mgr_data = (FileMgrData *) dialog_data->data;
3758 /* Adjust the view settings if this new view was created */
3759 /* because of an action on a previous view. */
3761 if (initiating_view != NULL)
3763 FileMgrPropagateSettings ((FileMgrData *)initiating_view, file_mgr_data);
3764 /* force new window to come up in flat mode */
3765 file_mgr_data->show_type =
3766 ((PreferencesData *)file_mgr_data->preferences->data)->show_type =
3768 file_mgr_data->view = file_mgr_data->view_single;
3771 /* Call the FileMgr dialog to build up its directory set for */
3772 /* the directory name. */
3773 FileMgrBuildDirectories (file_mgr_data, host_name, real_directory_name);
3777 PreferencesData *preferences_data;
3779 file_mgr_data->toolbox = True;
3780 file_mgr_data->width = application_args.tool_width;
3781 file_mgr_data->height = application_args.tool_height;
3783 /* we want to default for the toolboxes (i.e. Application Manager) to
3784 * look different from a normal File Manager view. Let's turn off
3785 * the iconic_path, current_directory, and status_line.
3787 file_mgr_data->show_iconic_path = False;
3788 file_mgr_data->show_current_dir = False;
3790 file_mgr_data->show_status_line = True;
3793 preferences_data = (PreferencesData *)file_mgr_data->preferences->data;
3794 preferences_data->show_iconic_path = file_mgr_data->show_iconic_path;
3795 preferences_data->show_current_dir = file_mgr_data->show_current_dir;
3796 preferences_data->show_status_line = file_mgr_data->show_status_line;
3800 file_mgr_data->toolbox = False;
3801 file_mgr_data->width = application_args.dir_width;
3802 file_mgr_data->height = application_args.dir_height;
3806 if(file_mgr_data->find != NULL && file_mgr_data->current_directory != NULL)
3808 DialogData * dialog_data;
3809 FindData * find_data;
3811 dialog_data = (DialogData *)file_mgr_data->find;
3812 find_data = (FindData *)dialog_data->data;
3814 XtFree(find_data->directories);
3815 if(file_mgr_data->restricted_directory == NULL)
3818 find_data->directories = XtNewString(users_home_dir);
3820 find_data->directories =
3821 XtNewString(file_mgr_data->current_directory);
3825 if(strcmp(file_mgr_data->current_directory,
3826 file_mgr_data->restricted_directory) == 0)
3827 find_data->directories = XtNewString("/");
3829 find_data->directories =
3830 XtNewString(file_mgr_data->current_directory +
3831 strlen(file_mgr_data->restricted_directory));
3835 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3836 view_set[view_count]->directory_name =
3837 XtNewString (file_mgr_data->current_directory);
3839 /* Load default position info, or inherit, if appropriate */
3840 if ((fmd = (FileMgrData *)initiating_view) &&
3841 (strcmp(fmd->host, host_name) == 0) &&
3842 (strcmp(fmd->current_directory, real_directory_name) == 0))
3844 InheritPositionInfo(fmd, file_mgr_data);
3847 LoadPositionInfo(file_mgr_data);
3850 /* Get the dialog displayed. */
3853 instance_data = (DialogInstanceData *) dialog_data->data;
3854 instance_data->x = position->x;
3855 instance_data->y = position->y;
3856 instance_data->displayed = True; /* @@@ Hack! without this,
3857 _DtShowDialog will ignore
3858 our position info */
3861 tmpTitle = file_mgr_data->title;
3862 title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3864 XtFree(special_title);
3865 special_title = XtNewString(title);
3867 classHints.res_name = title;
3868 classHints.res_class = DTFILE_CLASS_NAME;
3869 initiating_view = NULL;
3871 _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL, RemoveTextFields,
3872 NULL, NULL, False, special_view, title, &classHints);
3875 file_mgr_data->title = tmpTitle;
3878 ViewAccept( view_set[view_count], msg );
3884 /* If in novice mode, force the icon for all the dir's to the 'Open' state */
3885 if (openDirType == NEW)
3886 ForceMyIconOpen(host_name, NULL);
3888 return(dialog_data);
3894 /************************************************************************
3897 * Update the view set array when a view is closed.
3899 ************************************************************************/
3903 DialogData *dialog_data )
3907 FileMgrData * file_mgr_data;
3908 DialogData * tmpDialog_data;
3909 FileMgrRec * file_mgr_rec;
3910 XmManagerWidget file_window;
3911 char *directory_name = NULL;
3912 char *host_name = NULL;
3914 if(dialog_data == trashDialogData)
3916 CloseTrash(NULL, NULL, NULL);
3920 for (i = 0; i < view_count; i++)
3922 if (dialog_data == (DialogData *) (view_set[i]->dialog_data))
3924 tmpDialog_data = (DialogData *) (view_set[i]->dialog_data);
3925 file_mgr_data = (FileMgrData *)tmpDialog_data->data;
3927 directory_name = (char *)XtMalloc( strlen(view_set[i]->directory_name) + 1);
3928 strcpy(directory_name, view_set[i]->directory_name);
3929 host_name = (char *)XtMalloc( strlen(view_set[i]->host_name) + 1);
3930 strcpy(host_name, view_set[i]->host_name);
3932 if (view_set[i]->msg != 0) {
3933 if (view_set[i]->pats != 0) {
3934 ttdt_file_quit( view_set[i]->pats, 0 );
3935 view_set[i]->pats = 0;
3937 tt_message_reply( view_set[i]->msg );
3938 tttk_message_destroy( view_set[i]->msg );
3939 view_set[i]->msg = 0;
3942 XtFree ((char *) view_set[i]->directory_name);
3943 XtFree ((char *) view_set[i]->host_name);
3944 XtFree ((char *) view_set[i]);
3947 for (j = i; j < view_count - 1; j++)
3948 view_set[j] = view_set[j + 1];
3952 _DtHideDialog (dialog_data, True);
3954 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
3955 file_window = (XmManagerWidget)file_mgr_rec->file_window;
3956 /* For next time, unmanage all the icons */
3957 XtUnmanageChildren(file_window->composite.children,
3958 file_window->composite.num_children);
3960 if(PositionFlagSet(file_mgr_data))
3961 SavePositionInfo(file_mgr_data);
3963 /* If it is an Application Manager view, then no point in
3964 caching this dialog, so free it */
3966 if(file_mgr_data->toolbox)
3967 _DtFreeDialog(dialog_data);
3969 _DtFreeDialogData (dialog_data);
3976 /* Update the directory cache list to remove unneeded directories. */
3978 UpdateCachedDirectories (view_set, view_count);
3980 if (openDirType == NEW)
3981 ForceMyIconClosed(host_name, directory_name);
3983 XtFree(directory_name);
3990 /************************************************************************
3993 * This function is called when a view may be changing its
3994 * current directory. It updates the view_set list to the
3995 * new host and directory.
3997 ************************************************************************/
4001 XtPointer file_mgr_data,
4002 char *old_host_name,
4003 char *new_host_name,
4004 char *old_directory_name,
4005 char *new_directory_name )
4010 /* See if the directory is one being viewed */
4012 for (i = 0; i < view_count; i++)
4014 if (((DialogData *) (view_set[i]->dialog_data))->data == file_mgr_data)
4016 if (strcmp (old_host_name, view_set[i]->host_name) == 0 &&
4017 strcmp (old_directory_name, view_set[i]->directory_name) == 0)
4019 XtFree ((char *) view_set[i]->host_name);
4020 view_set[i]->host_name = XtNewString (new_host_name);
4022 XtFree ((char *) view_set[i]->directory_name);
4023 view_set[i]->directory_name = XtNewString (new_directory_name);
4029 /* Update the directory cache list to remove unneeded directories. */
4031 UpdateCachedDirectories (view_set, view_count);
4036 /************************************************************************
4039 * Dispatch ToolTalk events to internal handlers.
4041 ************************************************************************/
4043 static Tt_callback_action
4052 op = tt_message_op( msg );
4053 status = tt_ptr_error( op );
4054 if ((status != TT_OK) || (op == 0)) {
4055 /* Let tttk_Xt_input_handler() Do The Right Thing */
4056 return TT_CALLBACK_CONTINUE;
4058 if (strcmp( op, "DtTypes_Reloaded" ) == 0) {
4060 } else if (strcmp( op, "XSession_Ending" ) == 0) {
4061 if( emptyTrashOnExit )
4065 return TT_CALLBACK_CONTINUE;
4068 tttk_message_destroy( msg );
4069 return TT_CALLBACK_PROCESSED;
4072 /************************************************************************
4075 * Dispatch ToolTalk requests to internal handlers.
4077 ************************************************************************/
4088 op = tt_message_op( msg );
4089 status = tt_ptr_error( op );
4090 if ((status != TT_OK) || (op == 0)) {
4091 /* Let tttk_Xt_input_handler() Do The Right Thing */
4092 return TT_CALLBACK_CONTINUE;
4094 if (strcmp( op, "DtFileSession_Run" ) == 0) {
4095 ViewSessionHandler( msg );
4096 } else if (strcmp( op, "DtFolder_Show" ) == 0) {
4097 ViewDirectoryHandler( msg );
4098 } else if (strcmp( op, "DtHome_Show" ) == 0) {
4099 ViewHomeDirectoryHandler( msg );
4100 } else if (strcmp( op, "DtTools_Show" ) == 0) {
4101 ViewToolsDirectoryHandler( msg );
4102 } else if (strcmp( op, "DtTrash_Show" ) == 0) {
4103 TrashDisplayHandler( msg );
4104 } else if (strcmp( op, "DtTrash_Remove" ) == 0) {
4105 TrashRemoveHandler( msg );
4106 } else if (strcmp( op, "DtTrash_Empty" ) == 0) {
4107 TrashEmptyHandler( msg );
4108 } else if (strcmp( op, "DtTrash_File" ) == 0) {
4109 TrashRemoveNoConfirmHandler( msg );
4110 } else if (strcmp( op, "DtTrash_Restore" ) == 0) {
4111 TrashRestoreHandler( msg );
4112 } else if (strcmp( op, "DtFile_PutOnWorkspace" ) == 0) {
4113 PutOnWorkspaceHandler( msg );
4114 } else if (strcmp( op, "DtFile_Move" ) == 0) {
4115 MoveCopyLinkHandler( msg, MOVE_FILE );
4116 } else if (strcmp( op, "DtFile_Copy" ) == 0) {
4117 MoveCopyLinkHandler( msg, COPY_FILE );
4118 } else if (strcmp( op, "DtFile_Link" ) == 0) {
4119 MoveCopyLinkHandler( msg, LINK_FILE );
4122 return TT_CALLBACK_CONTINUE;
4125 return TT_CALLBACK_PROCESSED;
4131 /************************************************************************
4133 * ViewSessionHandler
4134 * This function is called upon the dt session message
4135 * being received. The name of the session file is extracted
4136 * out of the message and a function is called to create
4137 * a view or set of views described by the file.
4139 ************************************************************************/
4145 char *file = tt_message_file( msg );
4146 tt_message_reply( msg );
4147 tttk_message_destroy( msg );
4149 if (! tt_is_err( tt_ptr_error( file )))
4151 if (view_count == 0 && desktop_data->numIconsUsed == 0)
4153 int session_flag = 0;
4156 session_name = strrchr(file, '/');
4158 LoadDesktopInfo(session_name);
4159 session_flag = RestoreSession (session_name, NORMAL_RESTORE, NULL);
4160 if ((session_flag != 0) && (view_count == 0))
4162 char current_directory[MAX_PATH];
4164 GetPWD(current_directory);
4165 if (current_directory[0] != NULL)
4168 (home_host_name, current_directory, NULL, NULL, 0))
4169 ViewHomeDirectoryHandler (0);
4173 ViewHomeDirectoryHandler (0);
4179 char *tmpStr, *msg, *title;
4181 tmpStr = GETMESSAGE(18, 39, "Cannot start a second File Manager session because a File Manager\nsession is already open on the desktop. If you want to start a new File\nManager session, you must first close all current File Manager windows\nand remove all File Manager objects from the workspaces.");
4182 msg = XtNewString(tmpStr);
4183 title = XtNewString((GETMESSAGE(18,40,"Session Error")));
4184 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
4195 /************************************************************************
4197 * ViewDirectoryHandler
4198 * This function is called upon the dt directory message
4199 * being received. The name of the directory is extracted
4200 * out of the message and a function is called to create
4201 * a view of the directory.
4203 ************************************************************************/
4206 ViewDirectoryHandler(
4213 initiating_view = NULL;
4214 msgFile = tt_message_file( msg );
4215 if (tt_is_err( tt_ptr_error( msgFile ))) msgFile = 0;
4219 if(msgFile && strncmp(msgFile, "~", 1) != 0 )
4221 if((strcmp(users_home_dir, "/") != 0) &&
4222 (strncmp(msgFile, users_home_dir, strlen(users_home_dir)-1) != 0))
4224 char *tmpStr, *errTitle, *errMsg, *dmsg;
4226 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4227 errTitle = XtNewString(tmpStr);
4228 tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4229 errMsg = XtNewString(tmpStr);
4230 dmsg = XtMalloc(strlen(errMsg)+strlen(msgFile)+1);
4231 sprintf(dmsg, errMsg, msgFile);
4232 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4239 tt_message_reply( msg );
4240 tttk_message_destroy( msg );
4246 numArgs = tt_message_args_count( msg );
4247 if (tt_is_err( tt_int_error( numArgs ))) numArgs = 0;
4250 special_view = True;
4251 special_treeType = UNSET_VALUE;
4252 special_treeFiles = UNSET_VALUE;
4253 special_viewType = UNSET_VALUE;
4254 special_orderType = UNSET_VALUE;
4255 special_directionType = UNSET_VALUE;
4256 special_randomType = UNSET_VALUE;
4257 special_restricted = NULL;
4258 special_title = NULL;
4259 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4260 for(i = 0; i < numArgs; i++)
4264 vtype = tt_message_arg_type( msg, i );
4265 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4268 val = tt_message_arg_val( msg, i );
4269 if(strcmp(vtype, "-title") == 0)
4271 special_title = XtNewString(val);
4273 else if(strcmp(vtype, "-help_volume") == 0)
4275 special_helpVol = XtNewString(val);
4277 if(strcmp(vtype, "-tree") == 0)
4279 DtfileStringToTree(val, &special_treeType);
4281 else if(strcmp(vtype, "-tree_files") == 0)
4283 DtfileStringToTreeFiles(val, &special_treeFiles);
4285 else if(strcmp(vtype, VIEW_HEADER) == 0)
4287 DtfileStringToView(val, &special_viewType);
4289 else if(strcmp(vtype, "-order") == 0)
4291 DtfileStringToOrder(val, &special_orderType);
4293 else if(strcmp(vtype, "-direction") == 0)
4295 DtfileStringToDirection(val, &special_directionType);
4297 else if(strcmp(vtype, "-grid") == 0)
4299 DtfileStringToGrid(val, &special_randomType);
4301 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4303 special_restricted = XtNewString(msgFile);
4308 if ((restrictMode) && (!special_restricted))
4312 ptr = strrchr(users_home_dir, '/');
4314 special_restricted = XtNewString(users_home_dir);
4319 else if (restrictMode)
4323 special_view = True;
4324 special_treeType = treeType;
4325 special_treeFiles = treeFiles;
4326 special_viewType = viewType;
4327 special_orderType = orderType;
4328 special_directionType = directionType;
4329 special_randomType = randomType;
4331 ptr = strrchr(users_home_dir, '/');
4333 special_restricted = XtNewString(users_home_dir);
4336 special_title = NULL;
4337 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4341 special_view = False;
4343 OpenDirectories (msgFile, NULL);
4346 tt_message_reply( msg );
4347 tttk_message_destroy( msg );
4353 /************************************************************************
4356 * This function is called upon the dt directory message
4357 * being received. The name of the directory is extracted
4358 * out of the message and a function is called to create
4359 * a view of the directory. This function is passed directly
4360 * to DtActionInvoke to be used as a callback.
4362 ************************************************************************/
4371 DialogData *return_data;
4375 if(root_dir && strncmp(root_dir, "~", 1) != 0 )
4377 if((strcmp(users_home_dir, "/") != 0) &&
4378 (strncmp(root_dir, users_home_dir, strlen(users_home_dir)-1) != 0))
4380 char *tmpStr, *errTitle, *errMsg, *dmsg;
4382 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4383 errTitle = XtNewString(tmpStr);
4384 tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4385 errMsg = XtNewString(tmpStr);
4386 dmsg = XtMalloc(strlen(errMsg)+strlen(root_dir)+1);
4387 sprintf(dmsg, errMsg, root_dir);
4388 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4398 initiating_view = NULL;
4399 special_view = True;
4400 special_treeType = treeType;
4401 special_treeFiles = treeFiles;
4402 special_viewType = viewType;
4403 special_orderType = orderType;
4404 special_directionType = directionType;
4405 special_randomType = randomType;
4408 special_restricted = XtNewString(root_dir);
4411 special_restricted = NULL;
4414 if ((restrictMode) && (!special_restricted))
4418 ptr = strrchr(users_home_dir, '/');
4420 special_restricted = XtNewString(users_home_dir);
4424 special_title = NULL;
4425 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4427 return_data = GetNewView (home_host_name, root_dir, NULL, NULL, msg);
4429 if ((!return_data) && msg)
4431 tt_message_reply(msg);
4432 tttk_message_destroy( msg );
4435 return(return_data);
4440 /************************************************************************
4442 * ViewHomeDirectoryHandler
4443 * This function is called upon the dt home directory message
4444 * being received. The home directory is extracted from the
4445 * users uid and used to open the directory.
4447 ************************************************************************/
4451 ViewHomeDirectoryHandler(
4454 register int i, j, k;
4455 struct passwd * pwInfo;
4458 char full_path[MAX_PATH + 1];
4459 struct stat stat_buf;
4462 /* We have a new view so set initiating_view to null */
4463 initiating_view = NULL;
4465 if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
4467 pwInfo = getpwuid (getuid());
4468 homeDir = pwInfo->pw_dir;
4471 /* Look and see if we have a default environment file present */
4472 tmp_path = _DtCreateDtDirs(display);
4475 if (msg) numArgs = tt_message_args_count(msg);
4476 if (tt_is_err(tt_int_error(numArgs))) numArgs = 0;
4479 special_view = True;
4480 special_treeType = UNSET_VALUE;
4481 special_treeFiles = UNSET_VALUE;
4482 special_viewType = UNSET_VALUE;
4483 special_orderType = UNSET_VALUE;
4484 special_directionType = UNSET_VALUE;
4485 special_randomType = UNSET_VALUE;
4486 special_restricted = NULL;
4487 special_title = NULL;
4488 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4489 for(i = 0; i < numArgs; i++)
4493 vtype = tt_message_arg_type( msg, i );
4494 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4497 val = tt_message_arg_val(msg, i);
4498 if(strcmp(vtype, "-title") == 0)
4500 special_title = XtNewString(val);
4502 else if(strcmp(vtype, "-help_volume") == 0)
4504 special_helpVol = XtNewString(val);
4506 if(strcmp(vtype, "-tree") == 0)
4508 DtfileStringToTree(val, &special_treeType);
4510 else if(strcmp(vtype, "-tree_files") == 0)
4512 DtfileStringToTreeFiles(val, &special_treeFiles);
4514 else if(strcmp(vtype, VIEW_HEADER) == 0)
4516 DtfileStringToView(val, &special_viewType);
4518 else if(strcmp(vtype, "-order") == 0)
4520 DtfileStringToOrder(val, &special_orderType);
4522 else if(strcmp(vtype, "-direction") == 0)
4524 DtfileStringToDirection(val, &special_directionType);
4526 else if(strcmp(vtype, "-grid") == 0)
4528 DtfileStringToGrid(val, &special_randomType);
4530 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4532 special_restricted = XtNewString(val);
4538 else if (restrictMode)
4542 special_view = True;
4543 special_treeType = treeType;
4544 special_treeFiles = treeFiles;
4545 special_viewType = viewType;
4546 special_orderType = orderType;
4547 special_directionType = directionType;
4548 special_randomType = randomType;
4550 ptr = strrchr(users_home_dir, '/');
4552 special_restricted = XtNewString(users_home_dir);
4555 special_title = NULL;
4556 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4559 special_view = False;
4561 if (tmp_path == NULL)
4562 OpenDirectories (homeDir, NULL);
4565 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
4568 /* Stat the file and make sure its there */
4571 if (stat (full_path, &stat_buf) == 0 && numArgs < 1)
4573 restoreType = HOME_RESTORE;
4574 RestoreSession(full_path, HOME_RESTORE, NULL);
4575 restoreType = NORMAL_RESTORE;
4581 ptr = strrchr(users_home_dir, '/');
4583 strcpy(full_path, users_home_dir);
4585 OpenDirectories (full_path, NULL);
4588 else if (numArgs < 1 && stat (full_path, &stat_buf) == 0)
4590 restoreType = HOME_RESTORE;
4591 RestoreSession(full_path, HOME_RESTORE, NULL);
4592 restoreType = NORMAL_RESTORE;
4598 ptr = strrchr(users_home_dir, '/');
4600 if( ptr != users_home_dir )
4603 strcpy(full_path, users_home_dir);
4606 OpenDirectories (full_path, NULL);
4612 tt_message_reply(msg);
4613 tttk_message_destroy(msg);
4617 /************************************************************************
4619 * ViewToolsDirectroyHandler
4620 * This function is called upon the dt tools message
4621 * being received. The names of the tools directories are
4622 * retrieved from libXue, a view is created and the change
4623 * directory dialog for the view is displayed with the
4624 * set of directories contained in the list.
4626 ************************************************************************/
4629 ViewToolsDirectoryHandler(
4633 char * tmp_path = NULL;
4634 char * tool_dir = NULL;
4635 char * msgFile = NULL;
4638 /* We have a new view so set initiating_view to null */
4639 initiating_view = NULL;
4641 /* Look and see if we have a default environment file present */
4642 tmp_path = _DtCreateDtDirs(display);
4644 if (msg) msgFile = tt_message_file(msg);
4645 if (tt_is_err(tt_ptr_error(msgFile))) msgFile = 0;
4647 if (msg) numArgs = tt_message_args_count(msg);
4648 if (tt_is_err(tt_int_error( numArgs ))) numArgs = 0;
4654 char *link_point = NULL;
4655 char *root_toolbox = NULL;
4656 char *user_install_point = NULL;
4658 special_view = True;
4659 special_treeType = treeType;
4660 special_treeFiles = treeFiles;
4661 special_viewType = viewType;
4662 special_orderType = orderType;
4663 special_directionType = directionType;
4664 special_randomType = randomType;
4665 special_restricted = XtNewString(msgFile);
4666 special_title = NULL;
4667 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4668 for(i = 0; i < numArgs; i++)
4672 vtype = tt_message_arg_type( msg, i );
4673 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4676 val = tt_message_arg_val( msg, i );
4677 if(strcmp(vtype, "-title") == 0)
4679 special_title = XtNewString(val);
4681 else if(strcmp(vtype, "-help_volume") == 0)
4683 special_helpVol = XtNewString(val);
4685 else if(strcmp(vtype, "-root") == 0)
4687 root_toolbox = XtNewString(val);
4689 else if(strcmp(vtype, "-common_link_point") == 0)
4691 link_point = XtNewString(val);
4693 else if(strcmp(vtype, "-user_install_point") == 0)
4695 user_install_point = XtNewString(val);
4697 if(strcmp(vtype, "-tree") == 0)
4699 DtfileStringToTree(val, &special_treeType);
4701 else if(strcmp(vtype, "-tree_files") == 0)
4703 DtfileStringToTreeFiles(val, &special_treeFiles);
4705 else if(strcmp(vtype, VIEW_HEADER) == 0)
4707 DtfileStringToView(val, &special_viewType);
4709 else if(strcmp(vtype, "-order") == 0)
4711 DtfileStringToOrder(val, &special_orderType);
4713 else if(strcmp(vtype, "-direction") == 0)
4715 DtfileStringToDirection(val, &special_directionType);
4717 else if(strcmp(vtype, "-grid") == 0)
4719 DtfileStringToGrid(val, &special_randomType);
4721 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4728 /* Due to the use of tooltalk messaging, app manager objects
4729 that are dragged either to the desktop or to the front
4730 panel are identified by their fully resolved names (ie.
4731 /usr/dt/appconfig/appmanager/$LANG/.... as opposed to
4732 /var/dt/appconfig/appmanager/$DTUSERSESSION/....). In order
4733 for the File Manager to treat these objects as links existing
4734 in the /var/.... directory, we use the following ugly code:
4736 1. Search the incoming path for $LANG (if you can't find
4737 $LANG, try C since this is the default).
4738 2. Concatenate the path following $LANG to the path for the
4739 root toolbox (this comes in with the tooltalk message
4740 so that we don't have to hardcode it).
4741 3. Call OpenDirectories with the new path that you have
4742 created and with the root toolbox path as the restricted
4745 This problem is further complicated by:
4746 1. Users traversing into APPGROUPs.
4747 2. Users opening the parent folders for workspace APPGROUPs.
4749 For situation 1, File Manager kicks the user into the App Manager
4750 if he/she traverses into an APPGROUP. BUT we don't want to
4751 make modifications to the path as we do above.
4752 So, if there is nothing following $LANG or if we can't find
4754 (ie. /var/dt/appconfig/appmanager/$DTUSERSESSION), call
4755 OpenDirectories with no parameter changes.
4757 For situation 2, File Manager is unable to distinguish between
4758 workspace objects dragged from /usr/.... or /var/...., so
4759 the parent folder for all workspace APPGROUPS is considered to
4760 be in the /var path. In addition to the OpenAppGroup action,
4761 there is an OpenParentAppGroup action which also triggers
4762 ViewToolsDirectoryHandler but sends in an additional
4763 parameter (user_install_point).
4764 If we know that this msg was generated by the OpenParentAppGroup
4766 AND nothing follows $LANG.
4767 Modify the parameters as above.
4768 OR we can't find $LANG but we can find the user_install_point
4769 (user's personal appgroup path).
4770 Concatenate the path following .dt/appmanager to the path for the
4771 root toolbox. Call OpenDirectories with the new path and the
4772 root toolbox as the restricted directory.
4780 if ((user_install_point) &&
4781 (ptr = strstr(msgFile, user_install_point)))
4783 ptr += strlen(user_install_point);
4784 tool_dir = XtMalloc(strlen(root_toolbox) + strlen(ptr) + 1);
4785 sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4786 XtFree(special_restricted);
4787 special_restricted = XtNewString(root_toolbox);
4791 ptr = strstr(msgFile, link_point);
4796 link_point = XtNewString("C");
4797 ptr = strstr(msgFile, link_point);
4802 ptr += strlen(link_point);
4803 if (strcmp(ptr, "") != 0)
4805 tool_dir = XtMalloc(strlen(root_toolbox) +
4807 sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4808 XtFree(special_restricted);
4809 special_restricted = XtNewString(root_toolbox);
4811 else if (user_install_point)
4813 tool_dir = XtNewString(root_toolbox);
4814 XtFree(special_restricted);
4815 special_restricted = XtNewString(root_toolbox);
4822 XtFree(root_toolbox);
4823 XtFree(user_install_point);
4825 else if (restrictMode)
4829 special_view = True;
4830 ptr = strrchr(users_home_dir, '/');
4832 special_restricted = XtNewString(users_home_dir);
4836 special_view = False;
4839 if (tmp_path == NULL)
4842 OpenDirectories (tool_dir, special_restricted);
4843 else if (msgFile != NULL)
4844 OpenDirectories (msgFile, special_restricted);
4848 char full_path[MAX_PATH + 1];
4849 struct stat stat_buf;
4851 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
4854 /* Stat the file and make sure its there */
4855 if (stat (full_path, &stat_buf) == 0 && numArgs > 0)
4857 DialogData * dialog_data;
4858 FileMgrData * file_mgr_data;
4860 restoreType = TOOL_RESTORE;
4862 RestoreSession(full_path, TOOL_RESTORE, tool_dir);
4864 RestoreSession(full_path, TOOL_RESTORE, msgFile);
4865 dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
4866 file_mgr_data = (FileMgrData *) dialog_data->data;
4867 application_args.tool_width = file_mgr_data->width;
4868 application_args.tool_height = file_mgr_data->height;
4869 restoreType = NORMAL_RESTORE;
4874 OpenDirectories (tool_dir, special_restricted);
4875 else if (msgFile != NULL)
4876 OpenDirectories (msgFile, special_restricted);
4885 tt_message_reply( msg );
4886 tttk_message_destroy( msg );
4894 /************************************************************************
4897 * This function is called upon the DtSTOP message.
4899 ************************************************************************/
4904 XtPointer clientData,
4905 String * messageFields,
4908 tt_message_reply( msg );
4909 tttk_message_destroy( msg );
4910 FinalizeToolTalkSession( );
4916 * This is the message handling function responsible for reloading
4917 * the filetype and action databases, and then updating our collection
4918 * of action menu items, and updating all open views.
4922 ReloadDatabases(void)
4925 DialogData * dialog_data;
4926 FileMgrData * file_mgr_data;
4927 FileMgrRec * file_mgr_rec;
4928 FileViewData *file_view_data;
4929 DesktopRec *desktopWindow;
4933 XmeFlushIconFileCache ( NULL );
4935 /* Update each directory_set view, both mapped and not */
4936 UpdateDirectorySet();
4938 /* Force action menus to update the next time they're posted */
4939 XtFree(fileMgrPopup.action_pane_file_type);
4940 fileMgrPopup.action_pane_file_type = NULL;
4941 XtFree(desktop_data->popupMenu->action_pane_file_type);
4942 desktop_data->popupMenu->action_pane_file_type = NULL;
4944 /* Update each view */
4945 for (i = 0; i < view_count; i++)
4947 dialog_data = (DialogData *)view_set[i]->dialog_data;
4948 file_mgr_data = (FileMgrData *) dialog_data->data;
4949 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
4950 XtFree(file_mgr_rec->action_pane_file_type);
4951 file_mgr_rec->action_pane_file_type = NULL;
4952 UpdateFilterAfterDBReread(file_mgr_data->filter_active);
4953 UpdateFilterAfterDBReread(file_mgr_data->filter_edit);
4954 FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
4957 /* go through the desktop objects to make sure the icons change
4958 * Do this by setting the logical_type to -l, CheckDesktop will
4959 * then update the logical type and the icon
4961 for(i = 0; i < desktop_data->numIconsUsed; i++)
4963 desktopWindow = desktop_data->desktopWindows[i];
4964 file_view_data = desktopWindow->file_view_data;
4966 file_view_data->file_data->logical_type = NULL;
4973 * Whenever a directory view or drawer view is closed, we need to remove
4974 * any of its text field children, so that they will not magically reappear
4975 * should this view be reused from the cache to view the same directory later.
4980 XtPointer client_data,
4981 DialogData * old_dialog_data,
4982 DialogData * new_dialog_data)
4984 FileMgrRec * file_mgr_rec;
4985 XmManagerWidget file_window;
4989 file_mgr_rec = (FileMgrRec *) _DtGetDialogInstance(old_dialog_data);
4990 file_window = (XmManagerWidget) file_mgr_rec->file_window;
4991 num_children = file_window->composite.num_children;
4993 for (i = 0; i < num_children; i++)
4995 if (XmIsTextField(file_window->composite.children[i]))
4996 XtDestroyWidget(file_window->composite.children[i]);
4999 _DtFreeDialogData (new_dialog_data);
5004 * This function searches the view list, and returns the file_mgr_data
5005 * associated with the passed-in widget.
5013 DialogData * dialog_data;
5014 FileMgrData * file_mgr_data;
5016 for (i = 0; i < view_count; i++)
5018 dialog_data = (DialogData *) view_set[i]->dialog_data;
5019 file_mgr_data = (FileMgrData *) dialog_data->data;
5021 if (w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->file_window ||
5022 w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->shell)
5023 return(file_mgr_data);
5031 CheckForOpenDirectory(
5032 FileViewData *order_list,
5033 DirectorySet *directory_set,
5034 FileMgrData *file_mgr_data,
5035 char * logical_type)
5039 char *file_type_name, *new_file_type_name;
5040 char directory_name[MAX_PATH];
5041 char * real_dir_name;
5042 FileMgrRec *file_mgr_rec;
5044 PixmapData *pixmapData = NULL;
5046 if (file_mgr_data->view == BY_NAME_AND_ICON)
5051 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5053 if (strcmp (directory_set->name, "/") != 0)
5054 sprintf( directory_name, "%s/%s", directory_set->name, order_list->file_data->file_name);
5056 sprintf( directory_name, "%s%s", directory_set->name, order_list->file_data->file_name );
5058 (void) DtEliminateDots (directory_name);
5060 real_dir_name = XtNewString(directory_name);
5062 for(i = 0; i < view_count; i++)
5064 if(strcmp(real_dir_name, view_set[i]->directory_name) == 0)
5066 file_type_name = order_list->file_data->logical_type;
5067 new_file_type_name = (char *)XtMalloc(strlen(file_type_name)
5068 + strlen(ICON_OPEN_PREFIX) + 1);
5069 sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5070 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5073 file_mgr_rec->file_window,
5075 XtFree(new_file_type_name);
5079 XtFree(real_dir_name);
5081 if(pixmapData == NULL || pixmapData->iconFileName == NULL)
5083 if( pixmapData != NULL )
5085 DtDtsFreeAttributeValue(pixmapData->hostPrefix);
5086 DtDtsFreeAttributeValue(pixmapData->instanceIconName);
5087 DtDtsFreeAttributeValue(pixmapData->iconName);
5088 XtFree((char *)pixmapData);
5091 pixmapData = _DtRetrievePixmapData(logical_type,
5094 file_mgr_rec->file_window,
5103 * The is the menu callback function for cleaning up a view.
5109 XtPointer client_data,
5110 XtPointer call_data)
5114 FileMgrRec * file_mgr_rec;
5115 DialogData * dialog_data;
5116 FileMgrData * file_mgr_data;
5118 XmManagerWidget file_window;
5120 FileViewData * file_view_data;
5121 XRectangle textExtent;
5124 if ((int) client_data == FM_POPUP)
5127 mbar = XmGetPostedFromWidget(XtParent(w));
5130 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
5131 XtGetValues(mbar, args, 1);
5133 /* Ignore accelerators when we're insensitive */
5134 if ((file_mgr_rec->menuStates & CLEAN_UP) == 0)
5137 /* Ignore accelerators received after we're unposted */
5138 if ((dialog_data = _DtGetInstanceData((XtPointer)file_mgr_rec)) == NULL)
5141 file_mgr_data = (FileMgrData *)dialog_data->data;
5143 /* Reset the grid size, so it will be recalculated later. */
5144 file_mgr_data->grid_height = 0;
5145 file_mgr_data->grid_width = 0;
5147 if(file_mgr_data->object_positions)
5148 FreePositionInfo(file_mgr_data);
5150 /* CLEAN_UP_OP is not really a menu state.
5151 It's a flag to let GetFileData in FileMgr.c (call when the directory
5152 is being reread) not to reload icon positions from the .!dt<userid> file.
5154 file_mgr_rec->menuStates |= CLEAN_UP_OP;
5156 /* Re-layout the view */
5157 FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
5159 if ((file_mgr_data->show_type == SINGLE_DIRECTORY) &&
5160 (file_mgr_data->view != BY_ATTRIBUTES) &&
5161 (file_mgr_data->positionEnabled == RANDOM_ON))
5163 ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5168 /* Update the preferences dialog */
5169 ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5173 /* Move any text widget, to keep them in sync with their icons */
5174 file_window = (XmManagerWidget)file_mgr_rec->file_window;
5176 for (j = 0; j < file_window->composite.num_children; j++)
5178 if (XmIsTextField(file_window->composite.children[j]) &&
5179 !file_window->composite.children[j]->core.being_destroyed)
5181 XtSetArg(args[0], XmNuserData, &name);
5182 XtGetValues(file_window->composite.children[j], args, 1);
5184 /* Find the associated icon data */
5185 /* @@@ this won't work for tree mode! */
5186 for (i = 0; i < file_mgr_data->directory_set[0]->file_count; i++)
5188 file_view_data = file_mgr_data->directory_set[0]->file_view_data[i];
5189 if (strcmp(name, file_view_data->file_data->file_name) == 0)
5191 _DtIconGetTextExtent_r(file_view_data->widget, &textExtent);
5194 (Dimension)(file_window->composite.children[j]->core.height -
5195 textExtent.height)/(Dimension)2;
5196 XtSetArg (args[0], XmNx, x);
5197 XtSetArg (args[1], XmNy, y);
5198 XtSetValues (file_window->composite.children[j], args, 2);
5205 if ((file_mgr_rec->menuStates & CLEAN_UP_OP))
5206 file_mgr_rec->menuStates &= ~CLEAN_UP_OP;
5209 /*************************************<->*************************************
5211 * DtfileCvtStringToObjPlace (args, numArgs, fromVal, toVal)
5216 * This function converts a string to an desktop placement scheme description.
5221 * args = NULL (don't care)
5223 * numArgs = 0 (don't care)
5225 * fromVal = resource value to convert
5230 * toVal = descriptor to use to return converted value
5232 *************************************<->***********************************/
5235 DtfileCvtStringToObjPlace (
5241 unsigned char *pch = (unsigned char *) (fromVal->addr);
5242 unsigned char *pchNext;
5246 Boolean fPrimarySet = False;
5247 Boolean fSecondarySet = False;
5250 * Icon placement layout values:
5253 #define OBJ_PLACE_BOTTOM_STR (unsigned char *)"bottom"
5254 #define OBJ_PLACE_LEFT_STR (unsigned char *)"left"
5255 #define OBJ_PLACE_RIGHT_STR (unsigned char *)"right"
5256 #define OBJ_PLACE_TOP_STR (unsigned char *)"top"
5260 * Convert the icon placement resource value:
5265 while (*pch && _DtNextToken (pch, &len, &pchNext))
5273 if (_DtStringsAreEquivalent((char *)pch, (char *)OBJ_PLACE_BOTTOM_STR))
5277 cval |= OBJ_PLACE_BOTTOM_PRIMARY;
5280 else if (!fSecondarySet)
5283 (OBJ_PLACE_BOTTOM_PRIMARY | OBJ_PLACE_TOP_PRIMARY)))
5285 cval |= OBJ_PLACE_BOTTOM_SECONDARY;
5286 fSecondarySet = True;
5295 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_LEFT_STR))
5299 cval |= OBJ_PLACE_LEFT_PRIMARY;
5302 else if (!fSecondarySet)
5305 (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY)))
5307 cval |= OBJ_PLACE_LEFT_SECONDARY;
5308 fSecondarySet = True;
5316 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_RIGHT_STR))
5320 cval |= OBJ_PLACE_RIGHT_PRIMARY;
5323 else if (!fSecondarySet)
5326 (OBJ_PLACE_RIGHT_PRIMARY | OBJ_PLACE_LEFT_PRIMARY)))
5328 cval |= OBJ_PLACE_RIGHT_SECONDARY;
5329 fSecondarySet = True;
5337 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_TOP_STR))
5341 cval |= OBJ_PLACE_TOP_PRIMARY;
5344 else if (!fSecondarySet)
5347 (OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_BOTTOM_PRIMARY)))
5349 cval |= OBJ_PLACE_TOP_SECONDARY;
5350 fSecondarySet = True;
5363 cval = OBJ_PLACE_TOP_PRIMARY;
5367 if (cval & (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY))
5369 cval |= OBJ_PLACE_TOP_SECONDARY;
5372 cval |= OBJ_PLACE_RIGHT_SECONDARY;
5377 (*toVal).size = sizeof (long);
5378 (*toVal).addr = (XtPointer) &cval;
5380 } /* END OF FUNCTION DtfileCvtStringToObjPlace */
5382 /*************************************<->*************************************
5384 * _DtNextToken (pchIn, pLen, ppchNext)
5394 * pchIn = pointer to start of next token
5399 * pLen = pointer to integer containing number of characters in next token
5400 * ppchNext = address of pointer to following token
5402 * Return = next token or NULL
5409 *************************************<->***********************************/
5411 static unsigned char
5413 unsigned char *pchIn,
5415 unsigned char **ppchNext)
5417 unsigned char *pchR = pchIn;
5422 for (i = 0; ((chlen = mblen ((char *)pchIn, MB_CUR_MAX)) > 0); i++)
5423 /* find end of word: requires singlebyte whitespace terminator */
5425 if ((chlen == 1) && isspace (*pchIn))
5433 for (i = 0; *pchIn && !isspace (*pchIn); i++, pchIn++)
5434 /* find end of word */
5439 /* skip to next word */
5441 while (pchIn && (mblen ((char *)pchIn, MB_CUR_MAX) == 1) && isspace (*pchIn))
5443 while (pchIn && isspace (*pchIn))
5460 } /* END OF FUNCTION _DtNextToken */
5462 /*************************************<->*************************************
5464 * DtfileCvtStringToOpenDir (args, numArgs, fromVal, toVal)
5469 * This function converts a string to an desktop placement scheme description.
5474 * args = NULL (don't care)
5476 * numArgs = 0 (don't care)
5478 * fromVal = resource value to convert
5483 * toVal = descriptor to use to return converted value
5485 *************************************<->***********************************/
5488 DtfileCvtStringToOpenDir (
5494 char * in_str = (char *) (fromVal->addr);
5497 toVal->size = sizeof (int);
5498 toVal->addr = (XtPointer) &i;
5500 if (_DtStringsAreEquivalent (in_str, "current"))
5502 else if (_DtStringsAreEquivalent (in_str, "new"))
5511 XtStringConversionWarning ((char *)fromVal->addr, "OpenDir");
5516 /*************************************<->*************************************
5518 * DtfileCvtStringToDTIcon (args, numArgs, fromVal, toVal)
5523 * This function converts a string to an desktop placement scheme description.
5528 * args = NULL (don't care)
5530 * numArgs = 0 (don't care)
5532 * fromVal = resource value to convert
5537 * toVal = descriptor to use to return converted value
5539 *************************************<->***********************************/
5542 DtfileCvtStringToDTIcon (
5548 char * in_str = (char *) (fromVal->addr);
5551 toVal->size = sizeof (int);
5552 toVal->addr = (XtPointer) &i;
5554 if (_DtStringsAreEquivalent (in_str, "large"))
5556 else if (_DtStringsAreEquivalent (in_str, "small"))
5558 else if (_DtStringsAreEquivalent (in_str, "default"))
5559 i = LARGE; /* for now, eventually want to look at screen width/height*/
5567 XtStringConversionWarning ((char *)fromVal->addr, "DesktopIcon");
5573 DtfileCvtStringToTree (
5579 char * in_str = (char *) (fromVal->addr);
5582 toVal->size = sizeof (int);
5583 toVal->addr = (XtPointer) &i;
5585 DtfileStringToTree(in_str, &i);
5589 DtfileCvtStringToTreeFiles (
5595 char * in_str = (char *) (fromVal->addr);
5598 toVal->size = sizeof (int);
5599 toVal->addr = (XtPointer) &i;
5601 DtfileStringToTreeFiles(in_str, &i);
5605 DtfileCvtStringToView (
5611 char * in_str = (char *) (fromVal->addr);
5614 toVal->size = sizeof (int);
5615 toVal->addr = (XtPointer) &i;
5617 DtfileStringToView(in_str, &i);
5621 DtfileCvtStringToOrder (
5627 char * in_str = (char *) (fromVal->addr);
5630 toVal->size = sizeof (int);
5631 toVal->addr = (XtPointer) &i;
5633 DtfileStringToOrder(in_str, &i);
5637 DtfileCvtStringToDirection (
5643 char * in_str = (char *) (fromVal->addr);
5646 toVal->size = sizeof (int);
5647 toVal->addr = (XtPointer) &i;
5649 DtfileStringToDirection(in_str, &i);
5653 DtfileCvtStringToGrid (
5659 char * in_str = (char *) (fromVal->addr);
5662 toVal->size = sizeof (int);
5663 toVal->addr = (XtPointer) &i;
5665 DtfileStringToGrid(in_str, &i);
5674 FileMgrData *file_mgr_data;
5675 DialogData *dialog_data;
5677 for(i = 0; i < view_count; i++)
5679 if(strcmp(directory, view_set[i]->directory_name) == 0 &&
5680 strcmp(host, view_set[i]->host_name) == 0)
5682 dialog_data = (DialogData *) view_set[i]->dialog_data;
5683 file_mgr_data = (FileMgrData *) dialog_data->data;
5684 return(file_mgr_data);
5691 GetRestrictedDirectory (
5695 FileMgrData *file_mgr_data;
5696 FileMgrRec *file_mgr_rec;
5697 DialogData *dialog_data;
5699 for(i = 0; i < view_count; i++)
5701 dialog_data = (DialogData *) view_set[i]->dialog_data;
5702 file_mgr_data = (FileMgrData *) dialog_data->data;
5703 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5704 if(file_mgr_rec->current_directory_text == widget &&
5705 file_mgr_data->fast_cd_enabled)
5707 return(file_mgr_data->restricted_directory);
5710 return((char *)NULL);
5718 if (_DtStringsAreEquivalent (str, "on"))
5719 *type = MULTIPLE_DIRECTORY;
5720 else if (_DtStringsAreEquivalent (str, "off"))
5721 *type = SINGLE_DIRECTORY;
5723 *type = UNSET_VALUE;
5727 DtfileStringToTreeFiles(
5731 if (_DtStringsAreEquivalent (str, "never"))
5732 *type = TREE_FILES_NEVER;
5733 else if (_DtStringsAreEquivalent (str, "choose"))
5734 *type = TREE_FILES_CHOOSE;
5735 else if (_DtStringsAreEquivalent (str, "always"))
5736 *type = TREE_FILES_ALWAYS;
5738 *type = UNSET_VALUE;
5746 if (_DtStringsAreEquivalent (str, "no_icon") ||
5747 _DtStringsAreEquivalent (str, "no_icons"))
5749 else if (_DtStringsAreEquivalent (str, "large_icon") ||
5750 _DtStringsAreEquivalent (str, "large_icons"))
5751 *type = BY_NAME_AND_ICON;
5752 else if (_DtStringsAreEquivalent (str, "small_icon") ||
5753 _DtStringsAreEquivalent (str, "small_icons"))
5754 *type = BY_NAME_AND_SMALL_ICON;
5755 else if (_DtStringsAreEquivalent (str, "attributes"))
5756 *type = BY_ATTRIBUTES;
5758 *type = UNSET_VALUE;
5762 DtfileStringToOrder(
5766 if (_DtStringsAreEquivalent (str, "file_type"))
5767 *type = ORDER_BY_FILE_TYPE;
5768 else if (_DtStringsAreEquivalent (str, "alphabetical"))
5769 *type = ORDER_BY_ALPHABETICAL;
5770 else if (_DtStringsAreEquivalent (str, "date"))
5771 *type = ORDER_BY_DATE;
5772 else if (_DtStringsAreEquivalent (str, "size"))
5773 *type = ORDER_BY_SIZE;
5775 *type = UNSET_VALUE;
5780 DtfileStringToDirection(
5784 if (_DtStringsAreEquivalent (str, "ascending"))
5785 *type = DIRECTION_ASCENDING;
5786 else if (_DtStringsAreEquivalent (str, "descending"))
5787 *type = DIRECTION_DESCENDING;
5789 *type = UNSET_VALUE;
5797 if (_DtStringsAreEquivalent (str, "on"))
5799 else if (_DtStringsAreEquivalent (str, "off"))
5802 *type = UNSET_VALUE;
5806 SetupSendRequestArgs(
5807 ApplicationArgs application_args,
5811 if(application_args.title != NULL)
5813 tt_message_arg_add( msg, TT_IN, "-title", application_args.title );
5815 if(application_args.restricted != NULL)
5817 tt_message_arg_add( msg, TT_IN, RESTRICTED_HEADER, 0 );
5819 vtype = VIEW_HEADER;
5820 switch( application_args.view )
5823 tt_message_arg_add( msg, TT_IN, vtype, "no_icon" );
5825 case BY_NAME_AND_ICON:
5826 tt_message_arg_add( msg, TT_IN, vtype, "large_icon" );
5828 case BY_NAME_AND_SMALL_ICON:
5829 tt_message_arg_add( msg, TT_IN, vtype, "small_icon" );
5832 tt_message_arg_add( msg, TT_IN, vtype, "attributes" );
5835 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5840 switch( application_args.order )
5842 case ORDER_BY_FILE_TYPE:
5843 tt_message_arg_add( msg, TT_IN, vtype, "file_type" );
5845 case ORDER_BY_ALPHABETICAL:
5846 tt_message_arg_add( msg, TT_IN, vtype, "alphabetical" );
5849 tt_message_arg_add( msg, TT_IN, vtype, "date" );
5852 tt_message_arg_add( msg, TT_IN, vtype, "size" );
5855 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5859 vtype = "-direction";
5860 switch( application_args.direction )
5862 case DIRECTION_ASCENDING:
5863 tt_message_arg_add( msg, TT_IN, vtype, "ascending" );
5865 case DIRECTION_DESCENDING:
5866 tt_message_arg_add( msg, TT_IN, vtype, "descending" );
5869 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5874 switch( application_args.grid )
5877 tt_message_arg_add( msg, TT_IN, vtype, "on" );
5880 tt_message_arg_add( msg, TT_IN, vtype, "off" );
5883 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5887 switch( application_args.tree_view )
5889 case MULTIPLE_DIRECTORY:
5890 tt_message_arg_add( msg, TT_IN, vtype, "on" );
5892 case SINGLE_DIRECTORY:
5893 tt_message_arg_add( msg, TT_IN, vtype, "off" );
5896 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5900 vtype = "-tree_files";
5901 switch( application_args.tree_files )
5903 case TREE_FILES_NEVER:
5904 tt_message_arg_add( msg, TT_IN, vtype, "never" );
5906 case TREE_FILES_CHOOSE:
5907 tt_message_arg_add( msg, TT_IN, vtype, "choose" );
5909 case TREE_FILES_ALWAYS:
5910 tt_message_arg_add( msg, TT_IN, vtype, "always" );
5913 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5917 if(application_args.help_volume != NULL)
5919 tt_message_arg_add( msg, TT_IN, "-help_volume",
5920 application_args.help_volume );
5925 * This routine is used by ForceMyIconOpen to get the "Open" filetype and
5926 * find out what the new icon is. It then places that icon in the
5927 * correct icon gadget.
5930 BuildAndShowIconName(
5931 char *file_type_name,
5933 unsigned char show_type,
5936 char *new_file_type_name;
5939 PixmapData *pixmapData;
5941 new_file_type_name = (char *)XtMalloc(strlen(file_type_name) +
5942 strlen(ICON_OPEN_PREFIX) + 1);
5943 sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5945 if (view == BY_NAME_AND_ICON && show_type != MULTIPLE_DIRECTORY)
5946 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5952 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5958 if(pixmapData && pixmapData->iconFileName)
5960 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
5961 XtSetValues(widget, args, 1);
5966 XtSetArg (args[0], XmNimageName, NULL);
5967 XtSetValues(widget, args, 1);
5971 _DtCheckAndFreePixmapData(new_file_type_name,
5973 (DtIconGadget) widget,
5976 XtFree(new_file_type_name);
5981 * Given a directory name, this function will see if a view of the parent
5982 * directory is open; if so, then it will update the icon representing
5983 * this icon, in the parent view, so that it is drawn as 'closed'. This
5984 * function must only be called if openDirType == NEW.
5990 char * directory_name)
5996 FileViewData * file_view_data = NULL;
5997 DialogData *dialog_data;
5998 FileMgrData *file_mgr_data;
5999 DesktopRec *desktopWindow;
6002 PixmapData *pixmapData;
6004 /* find the parent directory of the one just removed */
6005 parent = _DtPName(directory_name);
6006 fname = DName(directory_name);
6008 /* first check to see if any File Manager views have this directory */
6009 for (i = 0; i < view_count; i++)
6011 dialog_data = (DialogData *) view_set[i]->dialog_data;
6012 file_mgr_data = (FileMgrData *) dialog_data->data;
6014 /* loop through until we find the file_view_data structure for
6015 * the directory to force open */
6017 for(j = 0; j < file_mgr_data->directory_count; j++)
6019 if (strcmp(parent, file_mgr_data->directory_set[j]->name) == 0)
6021 for (k = 0; k < file_mgr_data->directory_set[j]->file_count; k++)
6024 file_mgr_data->directory_set[j]->file_view_data[k];
6025 if (strcmp(file_view_data->file_data->file_name, fname) == 0)
6035 if( (file_view_data) && (file_mgr_data->view != BY_NAME) )
6037 if (file_mgr_data->view == BY_NAME_AND_ICON &&
6038 file_mgr_data->show_type != MULTIPLE_DIRECTORY)
6039 pixmapData = _DtRetrievePixmapData(
6040 file_view_data->file_data->logical_type,
6043 file_view_data->widget,
6046 pixmapData = _DtRetrievePixmapData(
6047 file_view_data->file_data->logical_type,
6050 file_view_data->widget,
6054 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6056 XtSetArg (args[0], XmNimageName, NULL);
6057 XtSetValues (file_view_data->widget, args, 1);
6059 _DtCheckAndFreePixmapData(file_view_data->file_data->logical_type,
6060 file_view_data->widget,
6061 (DtIconGadget) file_view_data->widget,
6065 /* now check to see if any desktop objects are this directory */
6066 for(j = 0; j < desktop_data->numIconsUsed; j++)
6070 desktopWindow = desktop_data->desktopWindows[j];
6071 file_view_data = desktopWindow->file_view_data;
6073 sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
6074 desktopWindow->file_name);
6075 DtEliminateDots (buf);
6077 if( (strcmp(buf, directory_name) == 0) &&
6078 (strcmp(desktopWindow->host, host_name) == 0) )
6080 pixmapData = _DtRetrievePixmapData(
6081 file_view_data->file_data->logical_type,
6084 desktopWindow->shell,
6088 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6090 XtSetArg (args[0], XmNimageName, NULL);
6091 XtSetValues (desktopWindow->iconGadget, args, 1);
6093 _DtCheckAndFreePixmapData(
6094 desktopWindow->file_view_data->file_data->logical_type,
6095 desktopWindow->shell,
6096 (DtIconGadget) desktopWindow->iconGadget,
6103 /*************************************************************************
6105 * MarqueeSelect - this is the callback which gets called when there is
6106 * a marquee event happening on the root window.
6108 ************************************************************************/
6117 XtPointer client_data)
6122 Screen *currentScreen;
6124 char *workspace_name=NULL;
6130 case DT_WSM_MARQUEE_SELECTION_TYPE_BEGIN:
6131 display = XtDisplay(desktop_data->desktopWindows[0]->shell);
6132 screen = XDefaultScreen(display);
6133 currentScreen = XScreenOfDisplay(display, screen);
6134 rootWindow = RootWindowOfScreen(currentScreen);
6136 if(DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
6139 workspace_name = XGetAtomName (display, pCurrent);
6140 CleanUpWSName(workspace_name);
6144 XtNewString(desktop_data->workspaceData[0]->name);
6146 for(i = 0; i < desktop_data->numWorkspaces; i++)
6148 if(strcmp(workspace_name,
6149 desktop_data->workspaceData[i]->name) == 0)
6151 DeselectAllDTFiles(desktop_data->workspaceData[i]);
6155 XtFree(workspace_name);
6158 case DT_WSM_MARQUEE_SELECTION_TYPE_END:
6159 CheckDesktopMarquee(x, y, width, height);
6162 case DT_WSM_MARQUEE_SELECTION_TYPE_CANCEL:
6165 case DT_WSM_MARQUEE_SELECTION_TYPE_CONTINUE:
6166 CheckDesktopMarquee(x, y, width, height);
6176 * We must wait for the message response, before exiting
6180 WaitForResponseAndExit( void )
6188 XtPointer clientData,
6193 FinalizeToolTalkSession( );
6199 * Puts up an Error dialog with Cancel and Help unmapped in the
6200 * center of the screen. The last argument is the OK callback
6204 post_dialog(Widget parent, char *title, char *msg, void (*DtErrExitCB)())
6206 Widget dialog, dialogShell;
6207 XmString message_text, ok;
6209 Dimension dialogWd, dialogHt;
6212 ok = XmStringCreateLocalized ((char*)_DtOkString);
6213 message_text = XmStringCreateLocalized (msg);
6215 XtSetArg(args[n], XmNautoUnmanage, False); n++;
6216 XtSetArg(args[n], XmNokLabelString, ok); n++;
6217 XtSetArg(args[n], XmNtitle, title); n++;
6218 XtSetArg(args[n], XmNmessageString, message_text); n++;
6219 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
6220 XtSetArg (args[n], XmNdefaultPosition, False); n++;
6221 XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
6223 dialog = XmCreateErrorDialog (parent, title, args, n);
6224 XtAddCallback (dialog, XmNokCallback, DtErrExitCB, NULL);
6225 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON));
6226 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
6228 /* Disable the frame menu from dialog since we don't want the user
6229 to be able to close dialogs with the frame menu */
6231 dialogShell = XtParent(dialog);
6232 XtSetArg(args[0], XmNmappedWhenManaged, False);
6233 XtSetArg(args[1], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU);
6234 XtSetValues(dialogShell, args, 2);
6235 XtManageChild (dialog);
6236 XtRealizeWidget (dialogShell);
6238 /* Center the dialog */
6240 XtSetArg(args[0], XmNwidth, &dialogWd);
6241 XtSetArg(args[1], XmNheight, &dialogHt);
6242 XtGetValues(dialog, args, 2);
6243 XtSetArg (args[0], XmNx,
6244 (WidthOfScreen(XtScreen(dialog)) - dialogWd) / 2);
6245 XtSetArg (args[1], XmNy,
6246 (HeightOfScreen(XtScreen(dialog)) - dialogHt) / 2);
6247 XtSetArg (args[2], XmNmappedWhenManaged, True);
6248 XtSetValues (dialog, args, 3);
6250 XtSetArg(args[0], XmNmappedWhenManaged, True);
6251 XtSetValues(dialogShell, args, 1);
6253 XtManageChild (dialog);
6254 XmStringFree(message_text);
6260 * This is the Callback when an error occurs while trying to create
6261 * the .dt folder or sub-folders. Application exits.
6265 DtErrExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
6267 XtPopdown (XtParent (dialog));
6268 FinalizeToolTalkSession();
6274 sigchld_handler(int signo) /* Do not use the arg signo at the moment */
6280 On DUX, the process remains in the ZOMBIE
6281 state untill parent invokes wait or waitpid.
6284 pid = waitpid(-1, &stat_loc, WNOHANG);
6285 /* Child exit handling code follows, if any */
6287 #endif /* __osf__ */