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>
116 #include <sys/stat.h>
120 #include <sys/wait.h>
128 #ifndef sun /* don't need the nl_types.h file */
129 #include <nl_types.h>
135 #include <Xm/DrawingA.h>
136 #include <Xm/DrawingAP.h>
137 #include <Xm/MessageB.h>
138 #include <Xm/RowColumn.h>
139 #include <Xm/MwmUtil.h>
142 #include <Dt/IconP.h>
143 #include <Dt/IconFile.h>
145 #include <Dt/HelpDialog.h>
148 #include <X11/extensions/shape.h>
151 #include <X11/Shell.h>
152 #include <X11/Xatom.h>
153 #include <Xm/Protocols.h>
154 #include <X11/keysymdef.h>
156 #include <X11/Xmu/Editres.h>
158 #include <Dt/Session.h>
160 #include <Dt/Connect.h>
161 #include <Dt/FileM.h>
162 #include <Dt/Indicator.h>
164 #include <Dt/UserMsg.h>
167 #include <Dt/DtNlUtils.h>
168 #include <Dt/CommandM.h>
169 #include <Dt/EnvControlP.h>
173 #include "SharedProcs.h"
181 #include "ChangeDir.h"
188 /* When openDir resource is set to NEW
189 File Manager will use this prefix to find for a different icon
192 #define ICON_OPEN_PREFIX "OPEN_"
194 /* THESE ARE ONLY STRINGS WHICH DO NOT NEED TO BE LOCALIZED */
195 /* Don't use '#define' since you end up with multiple copies */
196 char DTFILE_CLASS_NAME[] = "Dtfile";
197 char DTFILE_HELP_NAME[] = "Filemgr";
198 char DESKTOP_DIR[] = ".dt/Desktop";
200 static char WS_RES_HEADER[] = ".Workspace.";
201 static char SEC_HELP_RES_HEADER[] = ".secondaryHelpDialogCount: ";
202 static char WS_LOAD_RES_HEADER[] = "Workspace";
203 static char SEC_LOAD_HELP_RES_HEADER[] = "secondaryHelpDialogCount";
204 static char RESTRICTED_HEADER[] = "-restricted";
205 static char VIEW_HEADER[] = "-view";
208 /* Structure, resource definitions, for View's optional parameters. */
221 int instanceIconWidth;
222 int instanceIconHeight;
223 XmFontList user_font;
224 Dimension tool_width;
225 Dimension tool_height;
227 Dimension dir_height;
236 int maxDirectoryProcesses;
237 int maxRereadProcesses;
238 int maxRereadProcsPerTick;
241 Boolean showFilesystem;
242 Boolean showDropZone;
243 Boolean showEmptySet;
244 Boolean showEmptyMsg;
246 Boolean restrictMode;
247 int desktopPlacement;
248 Boolean freezeOnConfig;
249 #if defined(__hpux) || defined(sun)
250 Boolean follow_links;
255 int retryLoadDesktop;
260 Boolean emptyTrashOnExit;
261 } ApplicationArgs, *ApplicationArgsPtr;
263 static ApplicationArgs application_args;
265 /******** Static Function Declarations ********/
267 static void ErrorHandler(
269 XErrorEvent *event) ;
270 static void ToolkitErrorHandler(
274 static void RestrictModeUsage(
276 static void Stop( void ) ;
277 static void RestoreSettingsFile( void ) ;
278 static void MoveDefaultSettings(
280 static void SaveDefaultCancelCB(
282 XtPointer client_data,
283 XtPointer call_data) ;
284 static void SaveDefaultOkCB(
286 XtPointer client_data,
287 XtPointer call_data) ;
288 static void SaveSession(
290 static int RestoreSession(
295 char current_directory[]) ;
296 static void OpenDirectories(
299 static Tt_callback_action ObserveTtNotice(
302 static void ViewSessionHandler(
304 static void ViewDirectoryHandler(
306 static void ViewHomeDirectoryHandler(
308 static void ViewToolsDirectoryHandler(
310 static void ExitHandler(
312 XtPointer clientData,
313 String * messageFields,
315 static void ReloadDatabases( void );
316 static void ViewAccept(
319 static void LoadViews (
323 char *directory_name,
326 static void RemoveTextFields (
327 XtPointer client_data,
328 DialogData * old_dialog_data,
329 DialogData * new_dialog_data) ;
330 static void DtfileCvtStringToObjPlace (
335 static unsigned char *_DtNextToken (
336 unsigned char *pchIn,
338 unsigned char **ppchNext) ;
339 static void DtfileCvtStringToOpenDir (
344 static void DtfileCvtStringToDTIcon (
349 static void DtfileCvtStringToTree (
354 static void DtfileCvtStringToTreeFiles (
359 static void DtfileCvtStringToView (
364 static void DtfileCvtStringToOrder (
369 static void DtfileCvtStringToDirection (
374 static void DtfileCvtStringToGrid (
379 static void DtfileStringToTree(
382 static void DtfileStringToTreeFiles(
385 static void DtfileStringToView(
388 static void DtfileStringToOrder(
391 static void DtfileStringToDirection(
394 static void DtfileStringToGrid(
397 static void SetupSendRequestArgs(
398 ApplicationArgs application_args,
400 static void BuildAndShowIconName(
401 char *file_type_name,
403 unsigned char show_type,
405 static void MarqueeSelect (
412 XtPointer client_data);
413 static void WaitForResponseAndExit( void ) ;
415 XtPointer clientData,
418 static Widget post_dialog(
423 static void DtErrExitCB(
425 XtPointer client_data,
426 XtPointer call_data);
428 /******** End Static Function Declarations ********/
435 /* performance flag */
436 #ifdef DT_PERFORMANCE
440 /* The id's of the dialogs registered by main */
443 int change_dir_dialog;
444 int preferences_dialog;
450 /* The shared menu button and pane Id's */
452 Widget * create_dataBtn;
455 Widget * duplicateBtn;
458 Widget * create_directoryBtn;
459 Widget * change_directoryBtn;
460 Widget * showHiddenMenu;
461 Widget * preferencesBtn;
463 Widget * defaultEnvBtn;
470 Widget * terminalBtn;
471 Widget * usingHelp = NULL;
472 Widget * fileManagerHelp = NULL;
473 Widget * applicationManagerHelp = NULL;
474 Widget * usingHelpTrash = NULL;
477 /* Bitmask used to indicate the current sensitivity state of shared menu btns */
479 unsigned int currentMenuStates = ( RENAME | MOVE | DUPLICATE | LINK | TRASH |
480 MODIFY | CHANGEDIR | PREFERENCES | FILTER |
481 FIND | CREATE_DIR | CREATE_FILE |
482 PUT_ON_DESKTOP | PUTBACK |
484 HOME | CHANGE_DIR | TERMINAL);
486 /* Drag manager globals */
488 Boolean dragActive = False;
490 /* Desktop Globals */
494 /* Globally referenced application name. Set to argv[0] in main */
496 char * application_name = NULL;
499 /* uid for root user; used when we are checking access permissions */
506 char home_host_name[MAX_PATH];
507 char users_home_dir[MAX_PATH];
510 /* Toolbox directory */
512 char * desktop_dir = NULL;
513 char * trash_dir = NULL;
514 char * remote_sys_dir = NULL;
518 int restoreType = NORMAL_RESTORE;
521 /* Black and White pixels */
527 /* File manager view set before a new view is created and */
528 /* used to propagate visual attributes from the initiating */
529 /* view to the new view. */
531 XtPointer initiating_view = NULL;
532 Boolean special_view = False;
533 Boolean TrashView = False;
536 /* system wide user font */
538 XmFontList user_font;
541 /* Global localizable strings */
547 /* Global dialog button labels, as XmStrings */
550 XmString cancelXmString;
551 XmString helpXmString;
552 XmString applyXmString;
553 XmString closeXmString;
556 /* Global top level widget */
560 /* Global Application resources */
561 Boolean showFilesystem;
562 Boolean showDropZone;
563 Boolean showEmptySet;
564 Boolean showEmptyMsg;
565 Boolean restrictMode;
569 char *fileMgrHelpVol;
574 int desktopPlacement;
575 Boolean freezeOnConfig;
576 #if defined(__hpux) || defined(sun)
577 Boolean follow_links;
587 unsigned char keybdFocusPolicy;
588 int special_treeType;
589 int special_treeFiles;
590 int special_viewType;
591 int special_orderType;
592 int special_directionType;
593 int special_randomType;
594 char *special_restricted;
596 char *special_helpVol;
600 int retryLoadDesktopInfo;
607 Boolean emptyTrashOnExit;
610 Boolean shapeExtension;
613 /* Drag state variables */
614 Boolean B1DragPossible = False;
615 Boolean B2DragPossible = False;
616 Boolean ProcessBtnUp = False;
617 Boolean ProcessBtnUpCD = True;
621 int xErrorDetected = False;
623 /* BMenu button binding */
626 View ** view_set = NULL;
628 int view_set_size = 0;
630 /* Globals used within this file. */
632 static Display * display;
633 char * dt_path = NULL;
634 static Boolean message_display_enabled = True;
637 static Atom save_yourself_atom;
638 static Atom command_atom;
639 static Atom wm_state_atom;
640 static Atom save_mode;
642 /* Structure used on a save session to see if a dt is iconic */
651 /* Application resource list definition */
653 static XrmOptionDescRec option_list[] =
655 { "-noview", "noView", XrmoptionIsArg, NULL },
656 { "-session", "session", XrmoptionSepArg, NULL },
657 { "-dir", "folder", XrmoptionSepArg, NULL },
658 { "-folder", "folder", XrmoptionSepArg, NULL },
659 { "-tree", "treeView", XrmoptionSepArg, NULL },
660 { "-tree_files", "treeFiles", XrmoptionSepArg, NULL },
661 { VIEW_HEADER, "view", XrmoptionSepArg, NULL },
662 { "-order", "order", XrmoptionSepArg, NULL },
663 { "-direction", "direction", XrmoptionSepArg, NULL },
664 { "-grid", "grid", XrmoptionSepArg, NULL },
665 { RESTRICTED_HEADER, "restricted", XrmoptionIsArg, NULL },
666 { "-title", "title", XrmoptionSepArg, NULL },
667 { "-help_volume", "help_volume", XrmoptionSepArg, NULL },
668 { "-noprompt", "promptUser", XrmoptionNoArg, "False" },
669 { "-small_icon_width", "smallIconWidth", XrmoptionSepArg, NULL },
670 { "-small_icon_height", "smallIconHeight", XrmoptionSepArg, NULL },
671 { "-large_icon_width", "largeIconWidth", XrmoptionSepArg, NULL },
672 { "-large_icon_height", "largeIconHeight", XrmoptionSepArg, NULL },
676 static XtResource resources[] =
679 "noView", "NoView", XmRString, sizeof (char *),
680 XtOffset (ApplicationArgsPtr, no_view), XmRImmediate, (XtPointer) NULL,
684 "session", "Session", XmRString, sizeof (char *),
685 XtOffset (ApplicationArgsPtr, session), XmRImmediate, (XtPointer) NULL,
689 "folder", "Folder", XmRString, sizeof (char *),
690 XtOffset (ApplicationArgsPtr, directories), XmRImmediate, (XtPointer) NULL,
694 "treeView", "TreeView", "Tree", sizeof (int),
695 XtOffset (ApplicationArgsPtr, tree_view), XmRImmediate,
696 (XtPointer) UNSET_VALUE,
700 "treeFiles", "TreeFiles", "TreeFiles", sizeof (int),
701 XtOffset (ApplicationArgsPtr, tree_files), XmRImmediate,
702 (XtPointer) UNSET_VALUE,
706 "view", "View", "View", sizeof (int),
707 XtOffset (ApplicationArgsPtr, view), XmRImmediate, (XtPointer) UNSET_VALUE,
711 "order", "Order", "Order", sizeof (int),
712 XtOffset (ApplicationArgsPtr, order), XmRImmediate, (XtPointer) UNSET_VALUE,
716 "direction", "Direction", "Direction", sizeof (int),
717 XtOffset (ApplicationArgsPtr, direction), XmRImmediate,
718 (XtPointer) UNSET_VALUE,
722 "grid", "Grid", "Grid", sizeof (int),
723 XtOffset (ApplicationArgsPtr, grid), XmRImmediate, (XtPointer) UNSET_VALUE,
727 "instanceIconWidth", "InstanceIconWidth", XmRInt, sizeof (int),
728 XtOffset (ApplicationArgsPtr, instanceIconWidth), XmRImmediate,
733 "instanceIconHeight", "InstanceIconHeight", XmRInt, sizeof (int),
734 XtOffset (ApplicationArgsPtr, instanceIconHeight), XmRImmediate,
739 "restricted", "Restricted", XmRString, sizeof (char *),
740 XtOffset (ApplicationArgsPtr, restricted), XmRImmediate, (XtPointer) NULL,
744 "title", "Title", XmRString, sizeof (char *),
745 XtOffset (ApplicationArgsPtr, title), XmRImmediate, (XtPointer)NULL,
749 "help_volume", "Help_volume", XmRString, sizeof (char *),
750 XtOffset (ApplicationArgsPtr, help_volume), XmRImmediate, (XtPointer)NULL,
754 "userFont", "XmCFontList", XmRFontList, sizeof (XmFontList),
755 XtOffset (ApplicationArgsPtr, user_font), XmRString, (XtPointer) "Fixed",
759 "toolWidth", "ToolWidth", XmRHorizontalDimension, sizeof (Dimension),
760 XtOffset (ApplicationArgsPtr, tool_width), XmRImmediate, (XtPointer) 700,
764 "toolHeight", "ToolHeight", XmRVerticalDimension, sizeof (Dimension),
765 XtOffset (ApplicationArgsPtr, tool_height), XmRImmediate, (XtPointer) 250,
769 "dirWidth", "DirWidth", XmRHorizontalDimension, sizeof (Dimension),
770 XtOffset (ApplicationArgsPtr, dir_width), XmRImmediate, (XtPointer) 555,
774 "dirHeight", "DirHeight", XmRVerticalDimension, sizeof (Dimension),
775 XtOffset (ApplicationArgsPtr, dir_height), XmRImmediate, (XtPointer) 400,
779 "promptUser", "PromptUser", XmRBoolean, sizeof (Boolean),
780 XtOffset (ApplicationArgsPtr, prompt_user), XmRImmediate, (XtPointer) True,
784 "rootTitle", "RootTitle", XmRString, sizeof (char *),
785 XtOffset (ApplicationArgsPtr, root_title), XmRImmediate, (XtPointer)"ROOT",
789 "moveThreshold", "MoveThreshold", XmRInt, sizeof (int),
790 XtOffset (ApplicationArgsPtr, dragThreshold), XmRImmediate, (XtPointer) 4,
794 "rereadTime", "RereadTime", XmRInt, sizeof (int),
795 XtOffset (ApplicationArgsPtr, rereadTime), XmRImmediate, (XtPointer) 3,
799 "checkBrokenLink", "CheckBrokenLink", XmRInt, sizeof (int),
800 XtOffset (ApplicationArgsPtr, checkBrokenLink), XmRImmediate,
805 "maxDirectoryProcesses", "MaxDirectoryProcesses", XmRInt, sizeof (int),
806 XtOffset (ApplicationArgsPtr, maxDirectoryProcesses), XmRImmediate,
811 "maxRereadProcesses", "MaxRereadProcesses", XmRInt, sizeof (int),
812 XtOffset (ApplicationArgsPtr, maxRereadProcesses), XmRImmediate,
817 "maxRereadProcsPerTick", "MaxRereadProcsPerTick", XmRInt, sizeof (int),
818 XtOffset (ApplicationArgsPtr, maxRereadProcsPerTick), XmRImmediate,
823 "trashWait", "TrashWait", XmRInt, sizeof (int),
824 XtOffset (ApplicationArgsPtr, trashWait), XmRImmediate, (XtPointer) 1,
828 "desktopIcon", "DesktopIcon", "DesktopIcon", sizeof (int),
829 XtOffset (ApplicationArgsPtr, desktopIconType), XmRImmediate,
834 "showFilesystem", "ShowFilesystem", XmRBoolean, sizeof (Boolean),
835 XtOffset (ApplicationArgsPtr, showFilesystem), XmRImmediate,
840 "showDropZone", "ShowDropZone", XmRBoolean, sizeof (Boolean),
841 XtOffset (ApplicationArgsPtr, showDropZone), XmRImmediate,
846 "showEmptySet", "ShowEmptySet", XmRBoolean, sizeof (Boolean),
847 XtOffset (ApplicationArgsPtr, showEmptySet), XmRImmediate,
852 "showEmptyMsg", "ShowEmptyMsg", XmRBoolean, sizeof (Boolean),
853 XtOffset (ApplicationArgsPtr, showEmptyMsg), XmRImmediate,
858 "openFolder", "OpenFolder", "OpenFolder", sizeof (int),
859 XtOffset (ApplicationArgsPtr, openDirType), XmRImmediate,
864 "restrictMode", "RestrictMode", XmRBoolean, sizeof (Boolean),
865 XtOffset (ApplicationArgsPtr, restrictMode), XmRImmediate,
870 "objectPlacement", "ObjectPlacement", "ObjectPlacement", sizeof (int),
871 XtOffset (ApplicationArgsPtr, desktopPlacement), XmRImmediate,
872 (XtPointer)(OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_RIGHT_SECONDARY),
876 "freezeOnConfig", "FreezeOnConfig", XmRBoolean, sizeof (Boolean),
877 XtOffset (ApplicationArgsPtr, freezeOnConfig), XmRImmediate,
882 "fileManagerIcon", "FileManagerIcon", XmRString, sizeof (char *),
883 XtOffset (ApplicationArgsPtr, fileMgrIcon), XmRImmediate,
884 (XtPointer) HOME_ICON_NAME,
888 "appManagerIcon", "AppManagerIcon", XmRString, sizeof (char *),
889 XtOffset (ApplicationArgsPtr, appMgrIcon), XmRImmediate,
890 (XtPointer) TOOL_ICON_NAME,
894 "trashIcon", "TrashIcon", XmRString, sizeof (char *),
895 XtOffset (ApplicationArgsPtr, trashIcon), XmRImmediate,
896 (XtPointer) TRASH_ICON_NAME,
900 "retryLoadDesktop", "RetryLoadDesktop", XmRInt, sizeof (int),
901 XtOffset (ApplicationArgsPtr, retryLoadDesktop), XmRImmediate,
906 "smallIconWidth", "SmallIconWidth", XmRInt, sizeof (int),
907 XtOffset (ApplicationArgsPtr, smallIconWidth), XmRImmediate,
912 "smallIconHeight", "SmallIconHeight", XmRInt, sizeof (int),
913 XtOffset (ApplicationArgsPtr, smallIconHeight), XmRImmediate,
918 "largeIconWidth", "LargeIconWidth", XmRInt, sizeof (int),
919 XtOffset (ApplicationArgsPtr, largeIconWidth), XmRImmediate,
924 "largeIconHeight", "LargeIconHeight", XmRInt, sizeof (int),
925 XtOffset (ApplicationArgsPtr, largeIconHeight), XmRImmediate,
930 "emptyTrashOnExit", "EmptyTrashOnExit", XmRBoolean, sizeof (Boolean),
931 XtOffset (ApplicationArgsPtr, emptyTrashOnExit), XmRImmediate,
935 #if defined(__hpux) || defined(sun)
936 { "followLinks", "FollowLinks", XmRBoolean, sizeof(Boolean),
937 XtOffset(ApplicationArgsPtr, follow_links), XmRImmediate,
944 XtActionsRec actionTable[] = {
945 {"Space", (XtActionProc)VFTextChangeSpace},
946 {"EscapeFM", (XtActionProc)CancelOut},
949 /************************************************************************
952 * The main program for the file manager.
954 ************************************************************************/
956 extern XtInputId ProcessToolTalkInputId;
959 extern void sigchld_handler(int);
967 #ifdef DT_PERFORMANCE
968 struct timeval update_time_s;
969 struct timeval update_time_f;
970 struct timeval update_time_ss;
971 struct timeval update_time_fs;
974 char current_directory[MAX_PATH];
975 struct passwd * pwInfo;
979 Boolean eventDebugging;
987 XSetWindowAttributes sAttributes;
992 XrmValue resource_value;
997 int ttFd; /* ToolTalk file descriptor */
999 Tt_pattern events2Watch;
1000 Tt_pattern requests2Handle;
1004 struct sigaction sa, osa;
1005 #endif /* __osf__ */
1006 int session_flag = 0;
1008 #ifdef DT_PERFORMANCE
1010 gettimeofday(&update_time_ss, NULL);
1012 (void) signal (SIGINT, (void (*)())Stop);
1014 /* We don't want any zombie children, do we? */
1016 sa.sa_handler = sigchld_handler;
1017 sigemptyset(&sa.sa_mask);
1020 if (sigaction(SIGCHLD, &sa, &osa) < 0)
1021 /* error handling follows, none for now */
1024 (void) signal (SIGCHLD, SIG_IGN);
1025 #endif /* __osf__ */
1026 XtSetLanguageProc( NULL, NULL, NULL );
1028 #ifdef DT_PERFORMANCE
1029 { /* Initialize the checkpoint protocol - Aloke Gupta */
1031 display = XOpenDisplay("");
1032 _DtPerfChkpntInit(display, RootWindow(display, DefaultScreen(display)),
1038 _DtEnvControl(DT_ENV_SET);
1040 #ifdef DT_PERFORMANCE
1041 printf(" XtInitalize\n");
1042 gettimeofday(&update_time_s, NULL);
1044 /* Added by Aloke Gupta */
1045 _DtPerfChkpntMsgSend("Begin XtInitialize");
1048 /* Initialize the toolkit and open the display */
1049 toplevel = XtInitialize (argv[0], DTFILE_CLASS_NAME,
1050 option_list, XtNumber(option_list),
1051 (int *)&argc, argv);
1053 /* MERGE START: May not need
1055 _XmColorObjCreate ( toplevel, NULL, NULL );
1059 #ifdef DT_PERFORMANCE
1060 gettimeofday(&update_time_f, NULL);
1061 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1062 update_time_f.tv_usec += 1000000;
1063 update_time_f.tv_sec--;
1065 printf(" done XtInitialize, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1067 /* Added by Aloke Gupta */
1068 _DtPerfChkpntMsgSend("Done XtInitialize");
1071 /* Initialize the function ptr for alphabetic sorting */
1072 FMStrcoll = GetStrcollProc();
1074 /* Open the message catalog - DO NOT PERFORM until after XtInitialize! */
1076 char * foo = ((char *)GETMESSAGE(18, 1, ""));
1079 /* set application name for later */
1080 str = strrchr(argv[0], '/');
1082 application_name = XtNewString (str + 1);
1084 application_name = XtNewString (argv[0]);
1087 XtSetArg(args[n], XmNallowShellResize, True); n++;
1088 XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
1089 XtSetArg(args[n], XmNheight, 1); n++;
1090 XtSetArg(args[n], XmNwidth, 1); n++;
1091 XtSetValues(toplevel, args, n);
1092 XtRealizeWidget(toplevel);
1093 display = XtDisplay (toplevel);
1095 XtAddEventHandler(toplevel, 0, True,
1096 (XtEventHandler) _XEditResCheckMessages,
1100 /* Initialize BMenu button binding */
1102 int numMouseButtons = XGetPointerMapping(display,
1103 (unsigned char *)NULL, 0);
1104 bMenuButton = (numMouseButtons < 3) ? Button2 : Button3;
1107 /* initialize debugging flag */
1109 if ((tmpStr = getenv("DTFILE_DEBUG")) != NULL)
1111 debug = atoi(tmpStr);
1115 if (getenv("DTFILE_XSYNC") != NULL)
1117 XSynchronize(display, True);
1121 /* initialize performance flag */
1122 #ifdef DT_PERFORMANCE
1123 if ((tmpStr = getenv("DTFILE_PERFORM")) != NULL)
1125 perform = atoi(tmpStr);
1129 if (getenv("DTFILE_XSYNC") != NULL)
1131 XSynchronize(display, True);
1135 /* Create the atom set used by save and restore session */
1136 save_yourself_atom = XmInternAtom (display, "WM_SAVE_YOURSELF", False);
1137 wm_state_atom = XmInternAtom (display, "WM_STATE", False);
1138 command_atom = XA_WM_COMMAND;
1139 save_mode = XmInternAtom (display, _XA_DT_RESTORE_MODE, False);
1141 root = RootWindowOfScreen(XtScreen(toplevel));
1143 /* Set session property on the top level window */
1144 XmAddWMProtocols(toplevel, &save_yourself_atom, 1);
1145 XmAddWMProtocolCallback(toplevel, save_yourself_atom, SaveSessionCallback,
1148 XSetErrorHandler ((int (*)())ErrorHandler);
1149 XtAppSetErrorHandler (XtWidgetToApplicationContext(toplevel),
1150 ToolkitErrorHandler);
1152 /* get the keyboard focus policy so we know how we want to set up the */
1154 XtSetArg(args[0], XmNkeyboardFocusPolicy, &keybdFocusPolicy);
1155 XtGetValues(toplevel, args, 1);
1157 /* If all of the command line parameters were not processed */
1158 /* out, print out a usage message set and exit. */
1160 if (argc != 1) Usage (argv);
1162 displayWidth = DisplayWidth(display, DefaultScreen(display));
1163 displayHeight = DisplayHeight(display, DefaultScreen(display));
1165 /* Get Dt initialized */
1167 if (DtInitialize (display, toplevel, argv[0], FILE_MANAGER_TOOL_CLASS) == False)
1169 /* Fatal Error: could not connect to the messaging system. */
1170 /* DtInitialize() has already logged an appropriate error msg */
1174 #ifdef DT_PERFORMANCE
1175 printf(" Setup Converters and get resources\n");
1176 gettimeofday(&update_time_s, NULL);
1178 /* Added by Aloke Gupta */
1179 _DtPerfChkpntMsgSend("Begin Setup Converters");
1183 /* First lets add the resource converters needed */
1184 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1185 XtRString, "ObjectPlacement",
1186 (XtConverter)DtfileCvtStringToObjPlace, NULL, 0);
1187 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1188 XtRString, "OpenFolder",
1189 (XtConverter)DtfileCvtStringToOpenDir, NULL, 0);
1190 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1191 XtRString, "DesktopIcon",
1192 (XtConverter)DtfileCvtStringToDTIcon, NULL, 0);
1193 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1195 (XtConverter)DtfileCvtStringToTree, NULL, 0);
1196 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1197 XtRString, "TreeFiles",
1198 (XtConverter)DtfileCvtStringToTreeFiles, NULL, 0);
1199 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1201 (XtConverter)DtfileCvtStringToView, NULL, 0);
1202 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1204 (XtConverter)DtfileCvtStringToOrder, NULL, 0);
1205 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1206 XtRString, "Direction",
1207 (XtConverter)DtfileCvtStringToDirection, NULL, 0);
1208 XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1210 (XtConverter)DtfileCvtStringToGrid, NULL, 0);
1212 /* Get the application defined resources of session and */
1213 /* directory, and get the processes host. */
1215 XtGetApplicationResources(toplevel, &application_args,
1216 resources, XtNumber(resources), NULL,0);
1218 #ifdef DT_PERFORMANCE
1219 gettimeofday(&update_time_f, NULL);
1220 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1221 update_time_f.tv_usec += 1000000;
1222 update_time_f.tv_sec--;
1224 printf(" done 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);
1226 /* Added by Aloke Gupta */
1227 _DtPerfChkpntMsgSend("Done Setup Converters");
1230 #ifdef DT_PERFORMANCE
1231 printf(" DtDbLoad\n");
1232 gettimeofday(&update_time_s, NULL);
1233 /* Added by Aloke Gupta */
1234 _DtPerfChkpntMsgSend("Begin DtDbLoad");
1238 /* Set up the messaging and file types */
1241 #ifdef DT_PERFORMANCE
1242 gettimeofday(&update_time_f, NULL);
1243 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1244 update_time_f.tv_usec += 1000000;
1245 update_time_f.tv_sec--;
1247 printf(" done DtDbLoad, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1249 /* Added by Aloke Gupta */
1250 _DtPerfChkpntMsgSend("Done DtDbLoad");
1255 /* Create some global strings */
1256 db = XtDatabase(display);
1257 if (XrmGetResource (db, "dttypes.defaultActions",
1258 "Dttypes.DefaultActions", &rep_type,
1261 string = XtNewString(resource_value.addr);
1262 for(str = DtStrtok(string, ",") ,i = 0; str != NULL && i < 2 ;
1263 str = DtStrtok(NULL, ","), i++) {
1265 openInPlace = XtNewString(str);
1267 openNewView = XtNewString(str);
1271 if(openInPlace == NULL || strlen(openInPlace) == 0)
1272 openInPlace = XtNewString("OpenInPlace");
1273 if(openNewView == NULL || strlen(openNewView) == 0)
1274 openNewView = XtNewString("OpenNewView");
1276 DtGetShortHostname (home_host_name, MAX_PATH);
1278 /* Get the lock established to ensure only one dtfile process */
1280 if (_DtGetLock (display, DTFILE_CLASS_NAME) == 0)
1282 status = InitializeToolTalkProcid( &ttFd, toplevel, False );
1283 if (TT_OK != status)
1285 char *errfmt, *errmsg, *title, *statmsg;
1286 title = GETMESSAGE(21,38,"File Manager Error");
1287 errfmt = GETMESSAGE(18, 40,
1288 "Could not connect to ToolTalk:\n%s\nExiting ...");
1289 statmsg = tt_status_message(status);
1291 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1292 fprintf(stderr, errfmt, statmsg);
1293 sprintf(errmsg, errfmt, statmsg);
1295 /* put up error dialog and loop,
1296 * application will exit in dialog callback
1298 post_dialog(toplevel, title, errmsg, DtErrExitCB);
1301 if (application_args.session != NULL)
1303 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1304 "DtFileSession_Run",
1305 (Tt_message_callback)ExitApp );
1306 tt_message_file_set( msg, application_args.session );
1307 tt_message_send( msg );
1309 else if (application_args.directories != NULL)
1311 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1313 (Tt_message_callback)ExitApp );
1314 tt_message_file_set( msg, application_args.directories );
1315 SetupSendRequestArgs( application_args, msg );
1316 tt_message_send( msg );
1320 /* Default action: Open up pwd or home dir */
1321 GetPWD(current_directory);
1323 if (current_directory[0] != '\0')
1325 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1327 (Tt_message_callback)ExitApp );
1328 tt_message_file_set( msg, current_directory );
1332 msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1334 (Tt_message_callback)ExitApp );
1336 SetupSendRequestArgs( application_args, msg );
1337 tt_message_send( msg );
1339 WaitForResponseAndExit();
1342 /* Initialize the encapsulation mechanism and install the dialogs */
1343 /* used by the file manager. */
1345 _DtInitializeEncapsulation (display, argv[0], DTFILE_CLASS_NAME);
1346 topPositionOffset = -8;
1348 status = InitializeToolTalkProcid( &ttFd, toplevel, True );
1349 if (TT_OK != status)
1351 char *errfmt, *errmsg, *title, *statmsg;
1352 title = GETMESSAGE(21,38,"File Manager Error");
1353 errfmt = GETMESSAGE(18, 40,
1354 "Could not connect to ToolTalk:\n%s\nExiting ...");
1355 statmsg = tt_status_message(status);
1357 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1358 fprintf(stderr, errfmt, statmsg);
1359 sprintf(errmsg, errfmt, statmsg);
1361 /* put up error dialog and loop,
1362 * application will exit in dialog callback
1364 post_dialog(toplevel, title, errmsg, DtErrExitCB);
1368 #ifdef DT_PERFORMANCE
1369 printf(" Setup Callbacks (messaging)\n");
1370 gettimeofday(&update_time_s, NULL);
1372 /* Added by Aloke Gupta */
1373 _DtPerfChkpntMsgSend("Begin Setup Callbacks");
1376 events2Watch = tt_pattern_create();
1377 tt_pattern_category_set( events2Watch, TT_OBSERVE );
1378 tt_pattern_class_add( events2Watch, TT_NOTICE );
1379 tt_pattern_scope_add( events2Watch, TT_SESSION );
1380 sessId = tt_default_session();
1381 tt_pattern_session_add( events2Watch, sessId );
1383 tt_pattern_op_add( events2Watch, "DtTypes_Reloaded" );
1384 tt_pattern_op_add( events2Watch, "XSession_Ending" );
1385 tt_pattern_callback_add( events2Watch, ObserveTtNotice );
1386 tt_pattern_register( events2Watch );
1388 requests2Handle = tt_pattern_create();
1389 tt_pattern_category_set( requests2Handle, TT_HANDLE );
1390 tt_pattern_class_add( requests2Handle, TT_REQUEST );
1391 tt_pattern_scope_add( requests2Handle, TT_SESSION );
1392 sessId = tt_default_session();
1393 tt_pattern_session_add( requests2Handle, sessId );
1395 tt_pattern_op_add( requests2Handle, "DtFileSession_Run" );
1396 tt_pattern_op_add( requests2Handle, "DtFolder_Show" );
1397 tt_pattern_op_add( requests2Handle, "DtHome_Show" );
1398 tt_pattern_op_add( requests2Handle, "DtTools_Show" );
1399 tt_pattern_op_add( requests2Handle, "DtTrash_Show" );
1400 tt_pattern_op_add( requests2Handle, "DtTrash_Remove" );
1401 tt_pattern_op_add( requests2Handle, "DtTrash_Empty" );
1402 tt_pattern_op_add( requests2Handle, "DtTrash_File" );
1403 tt_pattern_op_add( requests2Handle, "DtTrash_Restore" );
1404 tt_pattern_op_add( requests2Handle, "DtFile_PutOnWorkspace" );
1405 tt_pattern_op_add( requests2Handle, "DtFile_Move" );
1406 tt_pattern_op_add( requests2Handle, "DtFile_Copy" );
1407 tt_pattern_op_add( requests2Handle, "DtFile_Link" );
1408 tt_pattern_callback_add( requests2Handle, HandleTtRequest );
1409 tt_pattern_register( requests2Handle );
1411 /* Setup the settings file if any to setup */
1413 _DtWsmAddMarqueeSelectionCallback(toplevel,
1414 (DtWsmMarqueeSelectionProc) MarqueeSelect,
1417 #ifdef DT_PERFORMANCE
1418 gettimeofday(&update_time_f, NULL);
1419 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1420 update_time_f.tv_usec += 1000000;
1421 update_time_f.tv_sec--;
1423 printf(" done Setting Callbacks (messaging), time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1425 /* Added by Aloke Gupta */
1426 _DtPerfChkpntMsgSend("Done Setup Callbacks");
1430 smallIconWidth = application_args.smallIconWidth;
1431 smallIconHeight = application_args.smallIconHeight;
1432 largeIconWidth = application_args.largeIconWidth;
1433 largeIconHeight = application_args.largeIconHeight;
1434 user_font = application_args.user_font;
1435 dragThreshold = application_args.dragThreshold;
1436 rereadTime = application_args.rereadTime;
1437 checkBrokenLink = application_args.checkBrokenLink;
1438 maxDirectoryProcesses = application_args.maxDirectoryProcesses;
1439 maxRereadProcesses = application_args.maxRereadProcesses;
1440 maxRereadProcsPerTick = application_args.maxRereadProcsPerTick;
1441 trashWait = application_args.trashWait;
1442 showFilesystem = application_args.showFilesystem;
1443 showDropZone = application_args.showDropZone;
1444 showEmptySet = application_args.showEmptySet;
1445 showEmptyMsg = application_args.showEmptyMsg;
1446 restrictMode = application_args.restrictMode;
1447 openDirType = application_args.openDirType;
1448 desktopIconType = application_args.desktopIconType;
1449 desktopPlacement = application_args.desktopPlacement;
1450 freezeOnConfig = application_args.freezeOnConfig;
1451 emptyTrashOnExit = application_args.emptyTrashOnExit;
1452 #if defined(__hpux) || defined(sun)
1453 follow_links = application_args.follow_links;
1455 instanceWidth = application_args.instanceIconWidth;
1456 instanceHeight = application_args.instanceIconHeight;
1457 fileMgrIcon = application_args.fileMgrIcon;
1458 appMgrIcon = application_args.appMgrIcon;
1459 trashIcon = application_args.trashIcon;
1460 retryLoadDesktopInfo = application_args.retryLoadDesktop;
1461 if( application_args.directories != NULL
1462 || (strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1465 special_view = True;
1466 if(strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1468 if(application_args.directories != NULL)
1469 special_restricted = XtNewString(application_args.directories);
1472 /* Get users pwd so we can set the restricted dir to it */
1473 GetPWD(current_directory);
1475 if (current_directory[0] != '\0')
1476 special_restricted = XtNewString(current_directory);
1478 special_restricted = XtNewString("~");
1481 else if( restrictMode )
1482 special_restricted = XtNewString("~");
1484 special_restricted = NULL;
1485 special_treeType = treeType = application_args.tree_view;
1486 special_treeFiles = treeFiles = application_args.tree_files;
1487 special_viewType = viewType = application_args.view;
1488 special_orderType = orderType = application_args.order;
1489 special_directionType = directionType = application_args.direction;
1490 special_randomType = randomType = application_args.grid;
1491 special_title = XtNewString(application_args.title);
1492 if(application_args.help_volume == NULL)
1494 special_helpVol = XtNewString(DTFILE_HELP_NAME);
1495 fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1499 special_helpVol = XtNewString(application_args.help_volume);
1500 fileMgrHelpVol = XtNewString(application_args.help_volume);
1502 fileMgrTitle = application_args.title;
1506 special_view = False;
1507 treeType = application_args.tree_view;
1508 treeFiles = application_args.tree_files;
1509 viewType = application_args.view;
1510 orderType = application_args.order;
1511 directionType = application_args.direction;
1512 randomType = application_args.grid;
1513 fileMgrTitle = application_args.title;
1514 if(application_args.help_volume == NULL)
1515 fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1517 fileMgrHelpVol = XtNewString(application_args.help_volume);
1521 if(desktopIconType == LARGE)
1523 numRows = displayHeight / PIXELS_PER_ROW_LARGE;
1524 numColumns = displayWidth / PIXELS_PER_COLUMN_LARGE;
1528 numRows = displayHeight / PIXELS_PER_ROW_SMALL;
1529 numColumns = displayWidth / PIXELS_PER_COLUMN_SMALL;
1533 /* determine whether the Server has the shape extension */
1534 if(XShapeQueryExtension(display, &base1, &base2) == True)
1535 shapeExtension = True;
1537 shapeExtension = False;
1540 /* get the name for the root directory */
1541 root_title = (char *)XtMalloc(strlen(application_args.root_title) + 1);
1542 strcpy(root_title, application_args.root_title);
1544 if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
1546 pwInfo = getpwuid (getuid());
1547 homeDir = pwInfo->pw_dir;
1549 strncpy(users_home_dir, homeDir, MAX_PATH - 1);
1552 if(application_args.directories != NULL &&
1553 strncmp(application_args.directories, "~", 1) != 0 )
1555 if(strncmp(application_args.directories, users_home_dir,
1556 strlen(users_home_dir)) != 0)
1557 RestrictModeUsage (argv);
1559 else if (application_args.directories == NULL)
1560 application_args.directories = XtNewString("~");
1562 if (strcmp(users_home_dir, "/") != 0)
1563 strcat(users_home_dir, "/");
1565 XtAppAddActions(XtWidgetToApplicationContext (toplevel), actionTable, 2);
1567 /* Create some global Xm strings for our dialog buttons */
1569 okXmString = XmStringCreateLocalized((char*)_DtOkString);
1570 cancelXmString = XmStringCreateLocalized((char*)_DtCancelString);
1571 helpXmString = XmStringCreateLocalized((char*)_DtHelpString);
1572 applyXmString = XmStringCreateLocalized((char*)_DtApplyString);
1573 closeXmString = XmStringCreateLocalized((char*)_DtCloseString);
1575 /* Get the dt path created and initialized */
1577 dt_path = _DtCreateDtDirs (display);
1579 if (dt_path == NULL)
1583 title = XtNewString((GETMESSAGE(21,38,"File Manager Error")));
1584 tmpStr = GETMESSAGE(18, 2, "Could not create the ~/.dt folder or sub folders.");
1585 msg = XtNewString(tmpStr);
1587 /* put up error dialog and loop, application will exit in
1590 dialog = post_dialog(toplevel, title, msg, DtErrExitCB);
1596 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
1600 /* Set the black and white pixel globals. */
1602 black_pixel = BlackPixelOfScreen (XtScreen (toplevel));
1603 white_pixel = WhitePixelOfScreen (XtScreen (toplevel));
1606 * Take over the drawing area's redisplay functions, so that we can get
1607 * the dtfile views to redraw according to stacking order, using our own
1610 xmDrawingAreaWidgetClass->core_class.expose = DrawingAreaRedisplay;
1613 /* Get the root user id */
1615 if ((pw = getpwnam("root")) == NULL)
1616 root_user = 0; /* Assume root is uid 0 */
1618 root_user = pw->pw_uid;
1621 file_mgr_dialog = _DtInstallDialog (fileMgrClass, True, True);
1622 change_dir_dialog = _DtInstallDialog (changeDirClass, True, True);
1623 preferences_dialog = _DtInstallDialog (preferencesClass, True, True);
1624 filter_dialog = _DtInstallDialog (filterClass, True, True);
1625 find_dialog = _DtInstallDialog (findClass, True, True);
1626 mod_attr_dialog = _DtInstallDialog (modAttrClass, True, True);
1627 help_dialog = _DtInstallDialog (helpClass, False, False);
1629 if(special_view == True && special_restricted != NULL);
1630 if(strncmp(special_restricted, "~", 1) == 0)
1634 special_restricted = _DtChangeTildeToHome(special_restricted);
1635 ptr = strrchr(special_restricted, '/');
1641 /* Setup the settings file if any to setup */
1642 RestoreSettingsFile();
1644 #ifdef DT_PERFORMANCE
1645 printf(" TrashCreateDialog\n");
1646 gettimeofday(&update_time_s, NULL);
1648 /* Added by Aloke Gupta */
1649 _DtPerfChkpntMsgSend("Begin TrashCreateDialog");
1652 if( InitializeTrash( application_args.prompt_user ) )
1654 #ifdef DEFER_TRASH_CREATION
1657 TrashCreateDialog (display);
1660 #ifdef DT_PERFORMANCE
1661 gettimeofday(&update_time_f, NULL);
1662 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1663 update_time_f.tv_usec += 1000000;
1664 update_time_f.tv_sec--;
1666 printf(" done TrashCreateDialog, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1668 /* Added by Aloke Gupta */
1669 _DtPerfChkpntMsgSend("Done TrashCreateDialog");
1672 /* lets go empty the trash if there is any */
1677 #ifdef DT_PERFORMANCE
1678 printf(" Setup Desktop\n");
1679 gettimeofday(&update_time_s, NULL);
1680 /* Added by Aloke Gupta */
1681 _DtPerfChkpntMsgSend("Begin Setup Desktop");
1684 /* go build 10 desktop windows */
1685 desktop_data = NULL;
1686 InitializeDesktopWindows(10, display);
1687 InitializeDesktopGrid();
1689 LoadDesktopInfo(application_args.session);
1691 /* Install WorkSpaceRemoved handler.
1692 This handler will be called when a workspace is being removed
1693 so File Manager can go through its desktop icons and clean up.
1695 DtWsmAddWorkspaceModifiedCallback( toplevel, WorkSpaceRemoved, NULL );
1697 #ifdef DT_PERFORMANCE
1698 gettimeofday(&update_time_f, NULL);
1699 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1700 update_time_f.tv_usec += 1000000;
1701 update_time_f.tv_sec--;
1703 printf(" done Setting up Desktop, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1705 /* Added by Aloke Gupta */
1706 _DtPerfChkpntMsgSend("Done Setup Desktop");
1710 /* Process the application resources to restore a session, dt */
1711 /* a directory set or display the users home directory. */
1713 #ifdef DT_PERFORMANCE
1714 printf(" Bring up View\n");
1715 gettimeofday(&update_time_s, NULL);
1717 /* Added by Aloke Gupta */
1718 _DtPerfChkpntMsgSend("Begin Bring up View");
1722 if (strcmp (application_args.no_view, "-noview") != 0)
1724 if (application_args.session != NULL)
1726 RestoreSession (application_args.session, NORMAL_RESTORE, NULL);
1727 else if (application_args.directories != NULL)
1729 restoreType = CURRENT_DIR_RESTORE;
1730 OpenDirectories (application_args.directories, NULL);
1734 #ifdef DT_PERFORMANCE
1735 gettimeofday(&update_time_f, NULL);
1736 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1737 update_time_f.tv_usec += 1000000;
1738 update_time_f.tv_sec--;
1740 printf(" done Bringing up view, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec); fflush(stdout);
1742 /* Added by Aloke Gupta */
1743 _DtPerfChkpntMsgSend("Done Bring up View");
1747 /* If no views were opened upon invocation, display the */
1748 /* current directory. */
1750 if ( (strcmp (application_args.no_view, "-noview") != 0) &&
1751 ((application_args.session == NULL) ||
1752 (session_flag != 0)) )
1754 if (view_count == 0)
1756 /* Get users pwd so we can create a fileviewer window of it */
1757 GetPWD(current_directory);
1759 if (current_directory[0] != '\0')
1761 if (!GetNewView (home_host_name, current_directory, NULL, NULL, 0))
1762 ViewHomeDirectoryHandler (0);
1766 ViewHomeDirectoryHandler (0);
1772 /* Set up the timer based directory reading. */
1773 InitializeDirectoryRead (toplevel);
1775 /* Process and dispatch incoming events */
1776 eventDebugging = getenv("EVENT_DEBUGGING") != NULL;
1778 #ifdef DT_PERFORMANCE
1779 printf(" InitializeToolTalkSession\n");
1780 gettimeofday(&update_time_s, NULL);
1782 (void) InitializeToolTalkSession( toplevel, ttFd );
1783 #ifdef DT_PERFORMANCE
1784 gettimeofday(&update_time_f, NULL);
1785 if (update_time_s.tv_usec > update_time_f.tv_usec) {
1786 update_time_f.tv_usec += 1000000;
1787 update_time_f.tv_sec--;
1789 printf(" done InitializeToolTalkSession, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1792 #ifdef DT_PERFORMANCE
1793 gettimeofday(&update_time_fs, NULL);
1794 if (update_time_ss.tv_usec > update_time_fs.tv_usec) {
1795 update_time_fs.tv_usec += 1000000;
1796 update_time_fs.tv_sec--;
1798 printf(" Finish, time: %ld.%ld\n\n", update_time_fs.tv_sec - update_time_ss.tv_sec, update_time_fs.tv_usec - update_time_ss .tv_usec);
1803 XtNextEvent(&event);
1805 if (event.type != 0)
1806 XtDispatchEvent(&event);
1809 return EXIT_SUCCESS;
1814 /************************************************************************
1818 ************************************************************************/
1823 XErrorEvent *event )
1825 #define _DTFILE_BUFSIZE 1024
1826 char errmsg[_DTFILE_BUFSIZE];
1828 _DtPrintDefaultErrorSafe (disp, event, errmsg, _DTFILE_BUFSIZE);
1829 _DtSimpleError(application_name, DtWarning, NULL, errmsg, NULL);
1830 xErrorDetected = True;
1832 /* We do not want to exit here lets try to continue... */
1837 ToolkitErrorHandler(
1843 tmpStr = GETMESSAGE(18, 6, "An X Toolkit error occurred... Exiting.\n");
1844 msg = (char *)malloc(strlen(tmpStr) + strlen(message) + 3);
1845 strcpy(msg, message);
1847 strcat(msg, tmpStr);
1848 _DtSimpleError (application_name, DtError, NULL, msg);
1851 FinalizeToolTalkSession( );
1858 /************************************************************************
1861 * When incorrect parameters have been specified on the command
1862 * line, print out a set of messages detailing the correct use
1865 ************************************************************************/
1872 char * message_string1 = "\nUsage: %s...\n\n"
1874 "Dtfile runs in server mode.\n\n"
1875 " -session SessionFile\n\n\t"
1876 "Dtfile runs with the session file specified in the SessionFile\n\t"
1878 " -folder Folder[,Folder,Folder]\n"
1879 " -dir Folder[,Folder,Folder]\n\n\t"
1880 "Dtfile displays a window for each folder specified in the\n\t"
1881 "Folder parameter. The Folder parameter may contain many\n\t"
1882 "folders separated by commas. Folders may be in the form\n\t"
1884 " -title Title\n\n\t"
1885 "Dtfile uses the string specified in the Title parameter as the\n\t"
1886 "title for its windows.\n\n"
1887 " -help_volume HelpVolume\n\n\t"
1888 "Dtfile uses the help volume specified in the HelpVolume parameter.\n\n"
1889 " -restricted\n\n\t"
1890 "Dtfile will not display folders above the restricted folder.\n\t"
1891 "If the -dir option is used, the folder specified in that option\n\t"
1892 "is the restricted folder. If the -dir option is not used, the\n\t"
1893 "user's current folder is the restricted folder.\n\n"
1894 " -grid on/off\n\n\t"
1895 "on = Files are displayed in a grid pattern.\n\t"
1896 "off = Files are displayed as placed.\n\n"
1897 " -tree on/off\n\n\t"
1898 "on = Files are displayed in single folder mode.\n";
1900 char * message_string2 = "\toff = Files are displayed in folder tree mode.\n\n"
1901 " -tree_files never/always/choose\n\n\t"
1902 "never = Tree mode has two states: partially expanded or collapsed.\n\t"
1903 "always = Tree mode has two states: fully expanded or collapsed.\n\t"
1904 "choose = Tree mode has three states: partially expanded, fully\n\t"
1905 " expanded, or collapsed.\n\n"
1906 " -order alphabetical/file_type/date/size\n\n\t"
1907 "Files are displayed in the specified order: alphabetical, by file\n\t"
1908 "type, by date, or by size.\n\n"
1909 " -view no_icon/large_icon/small_icon/attributes\n\n\t"
1910 "Files are displayed in the specified format: text only, text and\n\t"
1911 "large icons, text and small icons, with attributes.\n\n"
1912 " -direction ascending/descending\n\n\t"
1913 "Files are displayed in the specified direction: ascending or\n\t"
1915 " -large_icon_width <size>\n\n"
1916 " -large_icon_height <size>\n\n"
1917 " -small_icon_width <size>\n\n"
1918 " -small_icon_height <size>\n\n"
1919 " The display area size for the icon images in File Manager\n"
1920 " Icon images larger than this size will be clipped to this size\n"
1921 " The default display area size for large is 38 and small is 24\n\n"
1925 template = (GETMESSAGE(18,23, message_string1));
1926 fprintf (stderr, template, argv[0]);
1927 template = (GETMESSAGE(18,24, message_string2));
1928 fprintf (stderr, "%s", template);
1938 char * message_string = "\nRestricted Mode Usage: %s...\n\n"
1939 " -folder Folder[,Folder,Folder]\n"
1940 " -dir Folder[,Folder,Folder]\n\n\t"
1941 "Where Folder is a Folder below and/or including\n\t"
1942 "the user's Home Folder.\n\n";
1944 template = (GETMESSAGE(18,26, message_string));
1946 fprintf (stderr, template, argv[0]);
1948 FinalizeToolTalkSession( );
1955 /************************************************************************
1958 * Catches Ctrl C's and exits.
1960 ************************************************************************/
1965 FinalizeToolTalkSession( );
1975 /***********************************************************************
1977 * RestoreSettingsFile
1978 * Used to restore the save settings files from
1979 * either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
1981 ***********************************************************************/
1983 RestoreSettingsFile( void )
1987 char *homeSavePath=NULL;
1988 char *homeHomePath=NULL;
1989 char *toolSavePath=NULL;
1990 char *toolHomePath=NULL;
1994 unsigned long nitems;
1995 unsigned long leftover;
1996 unsigned char *data = NULL;
1999 /* go get the dt path */
2000 /* _DtCreateDtDirs returs a path of MaxPath Length */
2001 dtPath = (char *)_DtCreateDtDirs(display);
2003 /* Determin which type of session we are running HOME or CURRENT */
2005 /* get the root window property of SaveMode */
2006 XGetWindowProperty(display, RootWindow(display,0),
2007 save_mode, 0L, (long)BUFSIZ,False,
2008 XA_STRING, &actualType,
2009 &actualFormat,&nitems,&leftover,
2012 if(strcmp((char *)data, "home") == 0)
2013 dirName = XtNewString("home");
2014 else if(strcmp((char *)data, "current") == 0)
2015 dirName = XtNewString("current");
2019 return; /* we are comming up in a system mode (e.g. default) */
2023 /* Build the paths to read the files from */
2025 toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2026 strlen(TOOL_SETTINGS_FILENAME) +
2027 strlen(dirName) + 4);
2029 homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2030 strlen(HOME_SETTINGS_FILENAME) +
2031 strlen(dirName) + 4);
2033 sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2034 sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2036 /* open the home settings file to see if its there */
2037 if((fd = open(homeSavePath, O_RDONLY)) != -1)
2040 /* create where the saved file is going to go */
2042 homeHomePath = (char *)XtMalloc(strlen(dtPath) +
2043 strlen(HOME_SETTINGS_FILENAME) + 2);
2045 sprintf( homeHomePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2047 /* remove any existing dtfile.home (e.g. HOME_SETTINGS_FILENAME) */
2048 unlink(homeHomePath);
2050 /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2051 * will be used by the dtfile
2053 status = link(homeSavePath, homeHomePath);
2058 tmpStr = GETMESSAGE(18,27, "Unable to recover the saved default home settings file, will use default.\n");
2059 msg = XtNewString(tmpStr);
2060 _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2066 /* open the tool settings file to see if its there */
2067 if((fd = open(toolSavePath, O_RDONLY)) != -1)
2070 /* create where the saved file is going to go */
2071 toolHomePath = (char *)XtMalloc(strlen(dtPath) +
2072 strlen(TOOL_SETTINGS_FILENAME) + 2);
2074 sprintf( toolHomePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2076 /* remove any existing dtfile.tool (e.g. TOOL_SETTINGS_FILENAME) */
2077 unlink(toolHomePath);
2079 /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2080 * will be used by the dtfile
2082 status = link(toolSavePath, toolHomePath);
2087 tmpStr = GETMESSAGE(18,28, "Unable to recover the saved default tool settings file, will use default.\n");
2088 msg = XtNewString(tmpStr);
2089 _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2099 XtFree(homeSavePath);
2100 XtFree(toolSavePath);
2101 XtFree(toolHomePath);
2102 XtFree(homeHomePath);
2111 /***********************************************************************
2113 * MoveDefaultSettings
2114 * Used to save the dtfile.tool and dtfile.home settings files to
2115 * either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
2116 * The parameter mode determines whether it is home or
2119 ***********************************************************************/
2121 MoveDefaultSettings(
2125 char *toolSavePath=NULL;
2126 char *homeSavePath=NULL;
2128 char *toolMovePath=NULL;
2129 char *homeMovePath=NULL;
2132 /* determine whether home or current */
2133 if(mode == HOME_DIR_RESTORE)
2134 dirName = XtNewString("home");
2136 dirName = XtNewString("current");
2138 /* go get the dt path */
2139 /* _DtCreateDtDirs returs a path of MaxPath Length */
2140 dtPath = (char *)_DtCreateDtDirs(display);
2143 /* Build the paths to save the files to */
2145 toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2146 strlen(TOOL_SETTINGS_FILENAME) +
2147 strlen(dirName) + 4);
2149 homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2150 strlen(HOME_SETTINGS_FILENAME) +
2151 strlen(dirName) + 4);
2154 /* create the directory and filename of where its going to be saved */
2155 sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2156 sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2158 /* Setup the paths used to GET the old files */
2160 toolMovePath= (char *)XtMalloc(strlen(dtPath) +
2161 strlen(TOOL_SETTINGS_FILENAME) + 3);
2163 homeMovePath= (char *)XtMalloc(strlen(dtPath) +
2164 strlen(HOME_SETTINGS_FILENAME) + 3);
2166 /* create the filename of where its going to be saved from */
2168 /* Tool File location */
2169 sprintf( toolMovePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2171 /* Home File location */
2172 sprintf( homeMovePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2175 /* get rid of the tool settings file that is already in home or current */
2176 status = unlink(toolSavePath);
2178 /* get rid of the home settings file that is already in home or current */
2179 status = unlink(homeSavePath);
2182 /* now save tool settings file in home or current determined by savePath */
2183 status = link(toolMovePath, toolSavePath);
2185 /* now save home settings file in home or current determined by savePath */
2186 status = link(homeMovePath, homeSavePath);
2189 XtFree(homeMovePath);
2190 XtFree(toolMovePath);
2191 XtFree(homeSavePath);
2192 XtFree(toolSavePath);
2198 /************************************************************************
2201 * Callback for the Save Settings menupick.
2203 ************************************************************************/
2207 XtPointer client_data,
2208 XtPointer call_data )
2215 FileMgrRec * file_mgr_rec;
2216 DialogData * dialog_data;
2217 FileMgrData * file_mgr_data;
2220 /* Strip the file_mgr_rec from the current widget
2221 * and attach it to the ok callback button
2225 /* Get the file_mgr_rec hanging off the menubar */
2226 mbar = XmGetPostedFromWidget(XtParent(w));
2227 XmUpdateDisplay (w);
2228 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2229 XtGetValues(mbar, args, 1);
2232 /* Ignore accelerators when we're insensitive */
2233 if ((file_mgr_rec->menuStates & SETTINGS) == 0)
2235 XSetInputFocus(XtDisplay(w),
2236 XtWindow(file_mgr_rec->defaultEnvBtn_child),
2237 RevertToParent, CurrentTime);
2241 /* Desensatize the save settings menu pick here */
2242 file_mgr_rec->menuStates &= ~SETTINGS;
2245 /* Get the file_mgr_rec dialog data info */
2246 if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
2248 file_mgr_data = (FileMgrData *) dialog_data->data;
2251 /* Based on the path we must determine if we are saving a Tools or
2252 * HomeDir dtfile view.
2254 if (file_mgr_data->restricted_directory != NULL && file_mgr_data->toolbox)
2255 file_mgr_data->restoreKind = TOOL_RESTORE;
2257 file_mgr_data->restoreKind = HOME_RESTORE;
2260 /* Setup and call the _DtMessageDialog procedure to post the dialog */
2262 if (file_mgr_data->restoreKind == HOME_RESTORE)
2264 tmpStr = (GETMESSAGE(18,29, "Save the current File Manager View window size,\npreferences, and filter settings?\n\nThey will be used for any new File Manager View windows\nstarted from the Front Panel."));
2268 tmpStr = (GETMESSAGE(18,35, "Save the current Application Manager\nView window size, preferences, and filter settings?\n\nThey will be used for any new Application Manager\nwindows started from the Front Panel."));
2270 message = XtNewString(tmpStr);
2272 if(file_mgr_data->title != NULL &&
2273 strcmp(file_mgr_data->helpVol, DTFILE_HELP_NAME) != 0)
2275 tmpStr = GETMESSAGE(18, 16, "Save As Default Options");
2276 title = (char *)XtMalloc(strlen(tmpStr) +
2277 strlen(file_mgr_data->title) + 5);
2278 sprintf(title, "%s - %s", file_mgr_data->title, tmpStr);
2282 tmpStr = GETMESSAGE(18, 32, "File Manager - Save As Default Options");
2283 title = XtNewString(tmpStr);
2285 dlog = (Widget)_DtMessageDialog(mbar, title, message, NULL, TRUE,
2286 SaveDefaultCancelCB, SaveDefaultOkCB, NULL,
2287 HelpRequestCB, False, QUESTION_DIALOG);
2288 file_mgr_rec->defaultEnvBtn_child=dlog;
2293 /* Add array as userdata on the dialog. */
2295 XtSetArg(args[0], XmNuserData, file_mgr_rec);
2296 XtSetValues(dlog, args, 1);
2300 /************************************************************************
2302 * SaveDefaultCancelCB
2303 * Cleanup and unmanage the save settings dialog.
2305 ************************************************************************/
2307 SaveDefaultCancelCB(
2309 XtPointer client_data,
2310 XtPointer call_data )
2312 FileMgrRec * file_mgr_rec;
2315 /* Update the display, and un-post the dialog */
2316 XtUnmanageChild((Widget)client_data);
2317 XmUpdateDisplay((Widget)client_data);
2318 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2319 XtGetValues((Widget)client_data, args, 1);
2322 /* Re-sensatize the save settings menu pick */
2323 file_mgr_rec->menuStates |= SETTINGS;
2326 XtDestroyWidget((Widget)client_data);
2331 /************************************************************************
2334 * Save the current dtfile view as the default environment for
2335 * new dtfiles created.
2337 ************************************************************************/
2341 XtPointer client_data,
2342 XtPointer call_data )
2345 FileMgrRec * file_mgr_rec;
2346 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
2347 char view_number[5];
2351 DialogData * dialog_data;
2352 FileMgrData * file_mgr_data;
2355 char full_path[MAX_PATH + 1];
2358 char * save_directory;
2359 char ** save_branch_list;
2360 FileViewData ** save_selection_list;
2361 int save_selected_file_count;
2364 /* Get the file_mgr_rec hanging off the dialog */
2365 XtUnmanageChild((Widget)client_data);
2366 XmUpdateDisplay ((Widget)client_data);
2367 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2368 XtGetValues((Widget)client_data, args, 1);
2371 /* Re-sensatize the save settings menu pick */
2372 file_mgr_rec->menuStates |= SETTINGS;
2375 /* Get the file_mgr_rec dialog data info */
2377 dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
2378 file_mgr_data = (FileMgrData *) dialog_data->data;
2381 /* Build the path for our env file */
2383 tmp_path = _DtCreateDtDirs(display);
2384 if (tmp_path == NULL)
2386 XtDestroyWidget(client_data);
2391 /* Look and see what type of restore we are doing */
2392 if (file_mgr_data->restoreKind == TOOL_RESTORE)
2394 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
2395 application_args.tool_width = file_mgr_data->width;
2396 application_args.tool_height = file_mgr_data->height;
2400 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
2401 application_args.dir_width = file_mgr_data->width;
2402 application_args.dir_height = file_mgr_data->height;
2408 /* Create the Environment session file */
2410 if ((fd = creat(full_path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2413 tmpStr = GETMESSAGE(18, 17, "Unable to create a file to store the default options.");
2414 title = XtNewString((GETMESSAGE(21,38,"Object Create Error")));
2415 msg = XtNewString(tmpStr);
2416 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
2423 /* Write out the general information */
2425 (void) write (fd, "*", strlen ("*"));
2426 (void) write (fd, DTFILE_CLASS_NAME,strlen (DTFILE_CLASS_NAME));
2427 (void) write (fd, "*view_count: ", strlen ("*view_count: "));
2429 (void) sprintf (view_number, "%d", 1);
2430 (void) write (fd, view_number, strlen (view_number));
2431 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2433 name_list[1] = view_number;
2435 /* Temporarily remove data that we don't need or want saved */
2437 save_host = file_mgr_data->host;
2438 save_directory = file_mgr_data->current_directory;
2439 save_branch_list = file_mgr_data->branch_list;
2440 save_selection_list = file_mgr_data->selection_list;
2441 save_selected_file_count = file_mgr_data->selected_file_count;
2442 file_mgr_data->host = NULL;
2443 file_mgr_data->current_directory = NULL;
2444 file_mgr_data->branch_list = NULL;
2445 file_mgr_data->selection_list = NULL;
2446 file_mgr_data->selected_file_count = 0;
2448 /* Call the encapsulation mechanism to write each dialog */
2450 (void) sprintf (view_number, "%d", 0);
2451 _DtWriteDialogData (dialog_data, fd, name_list);
2452 (void) write (fd, "#\n", strlen ("#\n"));
2454 /* Restore the data that was temporarily removed */
2456 file_mgr_data->host = save_host;
2457 file_mgr_data->current_directory = save_directory;
2458 file_mgr_data->branch_list = save_branch_list;
2459 file_mgr_data->selection_list = save_selection_list;
2460 file_mgr_data->selected_file_count = save_selected_file_count;
2464 XtDestroyWidget(client_data);
2470 /************************************************************************
2472 * SaveSessionCallback
2473 * Get the session name and call the function to save the session.
2475 ************************************************************************/
2478 SaveSessionCallback(
2480 XtPointer client_data,
2481 XtPointer call_data )
2483 char * full_path=NULL;
2484 char * file_name=NULL;
2486 int restore=NORMAL_RESTORE;
2487 Boolean status=FALSE;
2488 char * sessionFileName;
2491 if(view_count == 0 && desktop_data->numIconsUsed == 0)
2493 XChangeProperty (display, XtWindow (toplevel), command_atom,
2494 XA_STRING, 8, PropModeReplace, (unsigned char *)NULL, 0);
2495 XSync(display, False);
2496 FinalizeToolTalkSession( );
2500 status = DtSessionSavePath(w, &full_path, &file_name);
2503 sessionFileName = file_name;
2506 XtFree( (char *)full_path);
2507 full_path = (char *) XtMalloc (sizeof (char) * MAX_PATH);
2508 sprintf( full_path, "%s/%s", dt_path, DTFILE_CLASS_NAME );
2509 sessionFileName = full_path;
2511 SaveSession( full_path );
2513 /* skip to the /.dt/ portion of the sessionFileName */
2514 strPtr = strstr(full_path, "/.dt/");
2515 (void)strcpy(full_path, strPtr);
2517 /* Save off the settings files for both tool and home views */
2519 strPtr = DtStrrchr(full_path, '/');
2522 if ((strncmp(strPtr, "/home", 5) == 0))
2523 restore = HOME_DIR_RESTORE;
2524 else if ((strncmp(strPtr, "/current", 8) == 0))
2525 restore = CURRENT_DIR_RESTORE;
2529 } while ((strPtr != NULL) && (restore == NORMAL_RESTORE));
2531 SaveDesktopInfo(restore);
2533 /* Cop the settings files to the proper dir */
2534 MoveDefaultSettings(restore);
2536 /* Generate the reinvoking command and add it as the property value */
2537 argv = (char **) XtMalloc(3 * sizeof(char *));
2538 argv[0] = XtNewString(application_name);
2539 argv[1] = XtNewString("-session");
2540 argv[2] = XtNewString(sessionFileName);
2541 XSetCommand(XtDisplay(toplevel), XtWindow(toplevel), argv, 3);
2543 XtFree ((char *) argv[0]);
2544 XtFree ((char *) argv[1]);
2545 XtFree ((char *) argv[2]);
2546 XtFree ((char *) argv);
2548 XtFree ((char *) full_path);
2549 XtFree ((char *) file_name);
2552 /************************************************************************
2555 * Save the current File Manager session as a set of resources
2556 * within the file denoted by path.
2558 ************************************************************************/
2565 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2567 char view_number[5];
2569 char workspaceNumber[5];
2571 Atom * ws_presence = NULL;
2572 char * workspace_name=NULL;
2573 unsigned long num_workspaces = 0;
2577 unsigned long nitems;
2578 unsigned long leftover;
2579 WM_STATE * wm_state;
2581 DialogData * dialog_data;
2582 FileMgrData * file_mgr_data;
2583 FileMgrRec * file_mgr_rec;
2588 WorkspaceRec * workspaceInfo;
2591 char *actualSavedTitle;
2593 /* This needs to be done because name_list is static and the values
2594 can be changed during the routine. This means that they need to be
2595 NULL'd out each pass */
2596 name_list[1] = NULL;
2597 name_list[2] = NULL;
2598 name_list[3] = NULL;
2599 name_list[4] = NULL;
2600 name_list[5] = NULL;
2602 /* Disable any message box display during save session */
2604 message_display_enabled = False;
2607 /* Create the session file */
2609 if ((fd = creat (path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2611 tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2612 msg = XtNewString(tmpStr);
2613 _DtSimpleError (application_name, DtError, NULL, msg);
2615 message_display_enabled = True;
2621 /* Write out the general information */
2623 /* Number of dtfile views */
2624 (void) write (fd, "*", strlen ("*"));
2625 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2626 (void) write (fd, "*view_count: ", strlen ("*view_count: "));
2628 if (trashFileMgrData)
2630 if (trashFileMgrData->file_mgr_rec)
2631 (void) sprintf (view_number, "%d", view_count + 1);
2633 (void) sprintf (view_number, "%d", view_count);
2637 (void) sprintf (view_number, "%d", view_count);
2639 (void) write (fd, view_number, strlen (view_number));
2640 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2642 (void) write (fd, "*", strlen ("*"));
2643 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2644 (void) write (fd, "*showFilesystem: ", strlen ("*showFilesystem: "));
2647 (void) write (fd, "True", strlen ("True"));
2649 (void) write (fd, "False", strlen ("False"));
2650 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2652 (void) write (fd, "*", strlen ("*"));
2653 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2654 (void) write (fd, "*restrictMode: ", strlen ("*restrictMode: "));
2657 (void) write (fd, "True", strlen ("True"));
2659 (void) write (fd, "False", strlen ("False"));
2660 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2662 (void) write (fd, "*", strlen ("*"));
2663 (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2664 (void) write (fd, "*openFolder: ", strlen ("*openFolder: "));
2666 if(openDirType == NEW)
2667 (void) write (fd, "NEW", strlen ("NEW"));
2669 (void) write (fd, "CURRENT", strlen ("CURRENT"));
2670 (void) write (fd, "\n#\n", strlen ("\n#\n"));
2673 name_list[1] = view_number;
2677 /* Write out each of the view's resources */
2678 /* start with -1 so we can include the trash dialog */
2679 for (i = -1; i < view_count; i++)
2684 dialog_data = (DialogData *) trashDialogData;
2690 dialog_data = (DialogData *) view_set[i]->dialog_data;
2693 file_mgr_data = (FileMgrData *) dialog_data->data;
2694 if(i == -1 && trashDialogData)
2695 file_mgr_data->IsTrashCan = True;
2696 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
2697 if(file_mgr_rec == NULL)
2700 /* This is a bug fix ... We don't want to save the title if the
2701 View is the Trash Can of if it is an Application Manager. This
2702 is because if the user saves a session in one Locale, then logs
2703 in in another, the Title will be in the locale that the session was
2704 saved in rather then the new local. So let's save the Title,
2705 Null it out, Save the session info, and finally restore the Title.
2707 if(i == -1 || file_mgr_data->toolbox)
2709 /* the Trash Can or toolbox (i.e. Application Manager) */
2710 actualSavedTitle = file_mgr_data->title;
2711 file_mgr_data->title = NULL;
2715 /* Getting the WM_STATE property to see if iconified or not */
2716 XGetWindowProperty (display, XtWindow (file_mgr_rec->shell),
2717 wm_state_atom, 0L, (long) BUFSIZ, False,
2718 wm_state_atom, &actual_type, &actual_format,
2719 &nitems, &leftover, (unsigned char **) &wm_state);
2721 /* Write out if iconified our not */
2723 write (fd, "*", strlen ("*"));
2724 write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2725 sprintf (view_number, "%d", view_index);
2726 write (fd, ".", strlen ("."));
2727 write (fd, view_number, strlen (view_number));
2729 (void) write (fd, ".iconify: ", strlen (".iconify: "));
2731 if (wm_state->state == IconicState)
2732 write (fd, "True\n", strlen ("True\n"));
2734 write (fd, "False\n", strlen ("False\n"));
2737 /* Get the workspaces for this dt by accessing the property. */
2739 if (DtWsmGetWorkspacesOccupied (display, XtWindow (file_mgr_rec->shell),
2740 &ws_presence, &num_workspaces) == Success)
2742 write (fd, "*", strlen ("*"));
2743 write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2744 (void) write (fd, ".", strlen ("."));
2745 (void) write (fd, view_number, strlen (view_number));
2746 (void) write (fd, ".workspace: ", strlen (".workspace: "));
2749 for (j = 0; j < num_workspaces; j++)
2751 if (j != 0) (void) write (fd, "*", strlen ("*"));
2752 workspace_name = XGetAtomName (display, ws_presence[j]);
2753 (void) write (fd, workspace_name, strlen (workspace_name));
2754 XtFree ((char *) workspace_name);
2758 (void) write (fd, "\n", strlen ("\n"));
2759 XFree((char *)ws_presence);
2763 /* Call the encapsulation mechanism to write each dialog */
2766 _DtWriteDialogData (trashDialogData, fd, name_list);
2768 _DtWriteDialogData ((DialogData *)view_set[i]->dialog_data,
2770 (void) write (fd, "#\n", strlen ("#\n"));
2775 file_mgr_data->title = actualSavedTitle;
2781 * Save off help dialog information for each workspace.
2782 * These are the help dialogs used for the desktop objects.
2784 name_list[1] = WS_LOAD_RES_HEADER;
2785 name_list[2] = workspaceNumber;
2786 name_list[3] = number;
2788 for (i = 0; i < desktop_data->numWorkspaces; i++)
2790 workspaceInfo = desktop_data->workspaceData[i];
2793 * Save number of secondary help dialogs in format:
2794 * *Dtfile.Workspace.<WS#>.secondaryHelpDialogCount: <#>
2796 write(fd, "*", strlen("*"));
2797 write(fd, DTFILE_CLASS_NAME, strlen(DTFILE_CLASS_NAME));
2798 write(fd, WS_RES_HEADER, strlen(WS_RES_HEADER));
2799 sprintf(workspaceNumber, "%d", i);
2800 write(fd, workspaceNumber, strlen(workspaceNumber));
2801 write(fd, SEC_HELP_RES_HEADER, strlen(SEC_HELP_RES_HEADER));
2802 sprintf(view_number, "%d", workspaceInfo->secondaryHelpDialogCount);
2803 write(fd, view_number, strlen(view_number));
2804 write (fd, "\n#\n", strlen ("\n#\n"));
2806 /* Save each of the secondary help dialogs */
2807 for (j = 0; j < workspaceInfo->secondaryHelpDialogCount; j++)
2809 sprintf(number, "%d", j + 1);
2810 _DtWriteDialogData(workspaceInfo->secondaryHelpDialogList[j],
2814 /* Save the primary help dialog window */
2815 if (workspaceInfo->primaryHelpDialog)
2817 sprintf(number, "%d", 0);
2818 _DtWriteDialogData(workspaceInfo->primaryHelpDialog,
2821 write (fd, "#\n", strlen ("#\n"));
2825 /* Re-able message box display flag after save session */
2826 message_display_enabled = True;
2834 * Given a directory name, this function will see if a view of the parent
2835 * directory is open; if so, then it will update the icon representing
2836 * this icon, in the parent view, so that it is drawn as 'open'. This
2837 * function must only be called if openDirType == NEW.
2843 char * directory_name)
2845 FileViewData * file_view_data = NULL;
2846 DesktopRec *desktopWindow;
2854 char *icon_name, *new_file_type_name, *file_type_name;
2857 /* if directory_name is passed in a NULL, we want to go through all
2858 existing open directories and check to see if there are any open
2859 directories in each of them. This is used at the end of OpenNewView
2860 and the end of ShowNewDirectory */
2861 if (directory_name == NULL)
2863 for (i = 0; i < view_count; i++)
2865 dd = (DialogData *) view_set[i]->dialog_data;
2866 fmd = (FileMgrData *) dd->data;
2868 for(j = 0; j < fmd->directory_count; j++)
2870 ForceMyIconOpen(view_set[i]->host_name,
2871 fmd->directory_set[j]->name);
2877 parent = _DtPName(directory_name);
2878 fname = DName(directory_name);
2880 /* first lets check to see if the directory is open in one of the
2881 open file manager views */
2882 for (i = 0; i < view_count; i++)
2884 dd = (DialogData *) view_set[i]->dialog_data;
2885 fmd = (FileMgrData *) dd->data;
2887 /* loop through until we find the file_view_data structure for the
2888 directory to force open */
2889 if (strcmp(host_name, view_set[i]->host_name) == 0)
2891 for(j = 0; j < fmd->directory_count; j++)
2893 if (strcmp(parent, fmd->directory_set[j]->name) == 0)
2895 for (k = 0; k < fmd->directory_set[j]->file_count; k++)
2897 file_view_data = fmd->directory_set[j]->file_view_data[k];
2898 if (strcmp(file_view_data->file_data->file_name, fname) == 0)
2900 file_view_data = NULL;
2909 fmd = (FileMgrData *)(((DirectorySet *)file_view_data->directory_set)->
2912 file_type_name = file_view_data->file_data->logical_type;
2914 if(fmd->view != BY_NAME)
2915 BuildAndShowIconName(file_type_name, fmd->view,
2916 fmd->show_type, file_view_data->widget);
2920 /* now we need to check to see if the directory being opened has a
2921 representation on the Desktop */
2922 for(i = 0; i < desktop_data->numIconsUsed; i++)
2926 desktopWindow = desktop_data->desktopWindows[i];
2927 file_view_data = desktopWindow->file_view_data;
2929 sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
2930 desktopWindow->file_name);
2931 DtEliminateDots (buf);
2933 if (strcmp(buf, directory_name) == 0 &&
2934 strcmp(desktopWindow->host, host_name) == 0)
2936 file_type_name = file_view_data->file_data->logical_type;
2937 if(desktopIconType == LARGE)
2938 BuildAndShowIconName(file_type_name, BY_NAME_AND_ICON,
2939 SINGLE_DIRECTORY, desktopWindow->iconGadget);
2941 BuildAndShowIconName(file_type_name, BY_NAME_AND_SMALL_ICON,
2942 SINGLE_DIRECTORY, desktopWindow->iconGadget);
2950 /************************************************************************
2953 * Open the file as a resource data base, and use the data to
2954 * create a set of File Manager views.
2956 ************************************************************************/
2961 int type_of_restore,
2964 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2967 XrmName xrm_name[10];
2968 XrmRepresentation rep_type;
2971 char * full_path = NULL;
2972 Boolean status=False;
2976 int num_sec_help_dialogs;
2979 DialogData * dialogData;
2980 struct stat stat_buf;
2983 /* Build the session path if we need to.
2984 * (e.g. When using the -session option)
2986 if (type_of_restore == NORMAL_RESTORE)
2988 status = DtSessionRestorePath(toplevel, &full_path, path);
2993 if (stat(full_path, &stat_buf) != 0)
2995 char *tmpStr, *msg, *title;
2997 tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2998 msg = XtNewString(tmpStr);
2999 title = XtNewString((GETMESSAGE(21,39,"File Open Error")));
3000 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
3008 path = XtNewString(full_path);
3011 /* This prevents the encapsulator from placing the dialogs */
3012 disableDialogAutoPlacement = True;
3014 /* Open the file as a resource database and query it to */
3015 /* get the previously saved view count. */
3017 db = XrmGetFileDatabase (path);
3019 if (type_of_restore == NORMAL_RESTORE)
3021 /* first find out if it should show the file system */
3022 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3023 xrm_name [1] = XrmStringToQuark ("showFilesystem");
3025 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3027 if ((temp = (char *) value.addr) != NULL &&
3028 strcmp (temp, "True") == 0)
3030 showFilesystem = True;
3033 showFilesystem = False;
3036 showFilesystem = True;
3038 /* find out if it should be in restricted mode */
3039 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3040 xrm_name [1] = XrmStringToQuark ("restrictMode");
3042 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3044 if ((temp = (char *) value.addr) != NULL &&
3045 strcmp (temp, "True") == 0)
3047 restrictMode = True;
3050 restrictMode = False;
3053 restrictMode = False;
3055 /* find out openFolder mode */
3056 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3057 xrm_name [1] = XrmStringToQuark ("openFolder");
3059 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3061 if ((temp = (char *) value.addr) != NULL &&
3062 strcmp (temp, "NEW") == 0)
3067 openDirType = CURRENT;
3070 openDirType = CURRENT;
3073 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3074 xrm_name [1] = XrmStringToQuark ("view_count");
3077 /* Load standard dtfile views */
3078 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3080 num_views = atoi (value.addr);
3082 LoadViews(num_views, db, NULL, directory, special_restricted, 0);
3085 /* Restore any desktop help dialogs */
3086 if (type_of_restore == NORMAL_RESTORE)
3088 for (i = 0; i < desktop_data->numWorkspaces; i++)
3090 sprintf(wsNum, "%d", i);
3091 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3092 xrm_name [1] = XrmStringToQuark (WS_LOAD_RES_HEADER);
3093 xrm_name [2] = XrmStringToQuark (wsNum);
3094 xrm_name [3] = XrmStringToQuark (SEC_LOAD_HELP_RES_HEADER);
3097 /* Load standard dtfile views */
3098 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3100 num_sec_help_dialogs = atoi (value.addr);
3101 if (num_sec_help_dialogs > 0)
3103 desktop_data->workspaceData[i]->secondaryHelpDialogCount =
3104 num_sec_help_dialogs;
3105 desktop_data->workspaceData[i]->secondaryHelpDialogList =
3106 (DialogData **) XtMalloc(sizeof(DialogData *) *
3107 num_sec_help_dialogs);
3109 for (j = 0; j < num_sec_help_dialogs; j++)
3111 name_list[0] = DTFILE_CLASS_NAME;
3112 name_list[1] = WS_LOAD_RES_HEADER;
3113 name_list[2] = wsNum;
3114 name_list[3] = dialogNum;
3115 name_list[4] = NULL;
3116 sprintf(dialogNum, "%d", j + 1);
3118 _DtGetResourceDialogData(help_dialog, db, name_list);
3119 desktop_data->workspaceData[i]->secondaryHelpDialogList[j]=
3121 ShowDTHelpDialog(NULL, i, HYPER_HELP_DIALOG,
3122 dialogData, NULL, NULL, NULL, NULL,
3128 /* Load the primary help dialog */
3129 name_list[0] = DTFILE_CLASS_NAME;
3130 name_list[1] = WS_LOAD_RES_HEADER;
3131 name_list[2] = wsNum;
3132 name_list[3] = dialogNum;
3133 name_list[4] = NULL;
3134 sprintf(dialogNum, "%d", 0);
3135 dialogData = _DtGetResourceDialogData(help_dialog, db, name_list);
3137 /* Keep only if currently posted */
3138 if (!(((HelpData *)dialogData->data)->displayed))
3140 /* Not currently displayed */
3141 _DtFreeDialogData(dialogData);
3144 desktop_data->workspaceData[i]->primaryHelpDialog = dialogData;
3147 ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
3148 dialogData, NULL, DTFILE_HELP_NAME,
3157 /* Free the Xrm Database */
3158 XrmDestroyDatabase(db);
3159 disableDialogAutoPlacement = False;
3170 extern Tt_message FileCallback();
3171 extern Tt_message SessionCallback();
3173 if ((msg == 0) || tt_is_err( tt_ptr_error( msg ))) {
3178 * Register for notifications on the directory viewed.
3179 * This is done so that requesting apps can notify the
3180 * view if the directory name is changed.
3182 view->pats = ttdt_file_join( view->directory_name, TT_SESSION, 0,
3183 FileCallback, view );
3184 if (tt_is_err( tt_ptr_error( view->pats ))) {
3188 /* Returned patterns automatically get destroyed when msg is destroyed */
3189 ttdt_message_accept( msg, SessionCallback,
3190 _DtGetDialogShell( (DialogData *)view->dialog_data ),
3200 char *directory_name,
3205 XrmName xrm_name[5];
3206 XrmRepresentation rep_type;
3208 static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
3209 char view_number[5];
3210 DialogData * dialog_data;
3211 FileMgrData * file_mgr_data;
3213 XClassHint classHints;
3214 char * iconify = NULL;
3215 Boolean iconify_window;
3217 char *title, *tmpTitle;
3219 name_list[1] = view_number;
3220 xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3223 /* Get and display view_count views. */
3225 for (i = 0; i < num_views; i++)
3227 struct stat stat_buf;
3229 (void) sprintf (view_number, "%d", i);
3230 xrm_name [1] = XrmStringToQuark (view_number);
3232 /* Get the main dialog data and set up the view */
3234 dialog_data = _DtGetResourceDialogData (file_mgr_dialog, db, name_list);
3235 file_mgr_data = (FileMgrData *) dialog_data->data;
3237 if(file_mgr_data->toolbox && file_mgr_data->title == NULL)
3238 file_mgr_data->title = DtActionLabel("Dtappmgr");
3240 if (stat(file_mgr_data->current_directory, &stat_buf) != 0)
3242 _DtFreeDialogData(dialog_data);
3246 if (trashFileMgrData
3247 && (file_mgr_data->IsTrashCan == True)
3248 && strcmp(file_mgr_data->current_directory, trash_dir) == 0)
3250 trashFileMgrData->view = file_mgr_data->view;
3251 trashFileMgrData->order = file_mgr_data->order;
3252 trashFileMgrData->direction = file_mgr_data->direction;
3253 trashFileMgrData->positionEnabled = file_mgr_data->positionEnabled;
3254 trashFileMgrData->preferences = file_mgr_data->preferences;
3255 file_mgr_data->preferences = NULL;
3256 _DtFreeDialogData(dialog_data);
3260 /* Increment the view list size if necessary and add directory to list */
3262 if (view_count == view_set_size)
3264 view_set_size += 10;
3266 (View **) XtRealloc ((char *)view_set,
3267 sizeof (View **) * view_set_size);
3269 view_set[view_count] = (View *) XtMalloc (sizeof (View));
3270 view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3271 view_set[view_count]->msg = 0;
3272 view_set[view_count]->pats = 0;
3274 if(restoreType == TOOL_RESTORE)
3275 file_mgr_data->toolbox = True;
3277 if(directory_name == NULL)
3279 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3280 view_set[view_count]->directory_name =
3281 XtNewString (file_mgr_data->current_directory);
3285 XtFree(file_mgr_data->current_directory);
3286 file_mgr_data->current_directory = NULL;
3287 XtFree(file_mgr_data->restricted_directory);
3288 file_mgr_data->restricted_directory = NULL;
3290 view_set[view_count]->directory_name = XtNewString(directory_name);
3291 XtFree((char *)file_mgr_data->selection_list);
3292 file_mgr_data->selection_list = NULL;
3293 if(host_name == NULL)
3295 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3296 file_mgr_data->current_directory = XtNewString(directory_name);
3298 file_mgr_data->restricted_directory =
3299 XtNewString(directory_name);
3301 file_mgr_data->restricted_directory =
3306 view_set[view_count]->host_name = XtNewString (host_name);
3307 XtFree(file_mgr_data->host);
3308 file_mgr_data->host = XtNewString(host_name);
3309 file_mgr_data->current_directory = XtNewString(directory_name);
3310 if(special_view && special_restricted != NULL)
3311 file_mgr_data->restricted_directory =
3312 XtNewString(special_restricted);
3314 file_mgr_data->restricted_directory = NULL;
3316 FileMgrBuildDirectories (file_mgr_data,
3317 view_set[view_count]->host_name, directory_name);
3320 /* Get the workspace set the view is contained in */
3321 /* and set the property for the view just created */
3323 xrm_name [2] = XrmStringToQuark ("workspace");
3326 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3328 /* Make sure we have some valid workspaces names to work with */
3330 /* value.addr should = NULL if no workspace names */
3331 workspaces = (char *) value.addr;
3334 /* we have no workspace resource so use default */
3337 /* Get and set whether the view is iconic */
3339 xrm_name [2] = XrmStringToQuark ("iconify");
3342 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3344 /* If there is an iconify resource and its value is True, */
3345 /* then mark the window as iconified. */
3347 if ((iconify = (char *) value.addr) != NULL &&
3348 strcmp (iconify, "True") == 0)
3350 iconify_window = True;
3354 iconify_window = False;
3357 iconify_window = False;
3359 if(file_mgr_data->positionEnabled == RANDOM_ON &&
3360 (file_mgr_data->object_positions == NULL))
3361 LoadPositionInfo(file_mgr_data);
3363 /* Call _DtShowDialog to create and manage the new window */
3365 tmpTitle = file_mgr_data->title;
3366 title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3368 XtFree(special_title);
3369 special_title = XtNewString(title);
3371 classHints.res_name = title;
3372 classHints.res_class = DTFILE_CLASS_NAME;
3374 _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL,
3375 RemoveTextFields, NULL, workspaces, iconify_window,
3376 special_view, title, &classHints);
3379 file_mgr_data->title = tmpTitle;
3382 ViewAccept( view_set[view_count], msg );
3389 if (openDirType == NEW)
3390 ForceMyIconOpen(file_mgr_data->host, NULL);
3394 /************************************************************************
3398 ************************************************************************/
3401 char current_directory[] )
3406 /* Open a pwd process and read the current working directory */
3407 /* from it. If the open fails or a read fails, then display */
3408 /* the users home directory. */
3410 pwd_file = popen ("pwd", "r");
3413 if (pwd_file != NULL)
3418 if (fread (¤t_directory[i], sizeof(char), 1, pwd_file) != 1)
3426 if (current_directory[i] == '\n')
3432 (void) pclose (pwd_file);
3433 current_directory[i] = '\0';
3437 /************************************************************************
3440 * Given a string that contains a single or set of host:path
3441 * specifications, parse out each host:path, validate it as
3442 * a accessible directory, and call a function to create a
3443 * file manager view of the directory.
3445 ************************************************************************/
3449 char *directory_set,
3456 /* Loop the the directory set string until all of */
3457 /* the path specifications have be parsed. */
3461 separator = DtStrchr (directory_set, ',');
3462 if (separator != NULL)
3465 _DtPathFromInput(directory_set, NULL, &host, &path);
3469 GetNewView (host, path, type, NULL, 0);
3473 char *tmpStr, *errTitle, *errMsg, *dmsg;
3475 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3476 errTitle = XtNewString(tmpStr);
3477 tmpStr = GETMESSAGE(18, 38, "Invalid folder specification, %s");
3478 errMsg = XtNewString(tmpStr);
3479 dmsg = XtMalloc(strlen(errMsg)+strlen(directory_set)+1);
3480 sprintf(dmsg, errMsg, directory_set);
3481 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
3488 /* Free up the unique host and directory names */
3489 /* that were allocated. */
3491 XtFree ((char *) host);
3492 XtFree ((char *) path);
3494 /* Set the starting position of the next host:path */
3496 if (separator != NULL)
3497 directory_set = separator + 1;
3506 /************************************************************************
3509 * Given a directory name, generate a new view for the directory.
3511 ************************************************************************/
3515 char *directory_name,
3517 WindowPosition *position,
3520 DialogData * dialog_data;
3521 DialogInstanceData * instance_data;
3522 FileMgrData * file_mgr_data;
3524 FileMgrRec * file_mgr_rec;
3525 char * real_directory_name;
3527 XClassHint classHints;
3528 char *title, *tmpTitle;
3529 struct stat stat_buf;
3531 char *errMsg = NULL;
3533 DtEliminateDots( directory_name );
3535 if (stat(directory_name, &stat_buf) == 0)
3537 if ((stat_buf.st_mode & S_IFMT) != S_IFDIR)
3539 tmpStr = GETMESSAGE(18, 19,
3540 "The folder specification,\n%s\nis not a folder.");
3541 errMsg = XtNewString(tmpStr);
3546 tmpStr = GETMESSAGE(18, 20,
3547 "The folder specification,\n%s\ndoes not exist.");
3548 errMsg = XtNewString(tmpStr);
3555 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3556 title = XtNewString(tmpStr);
3557 dmsg = XtMalloc(strlen(errMsg) +
3558 strlen(directory_name) + 1);
3559 sprintf(dmsg, errMsg, directory_name);
3560 _DtMessage(toplevel, title, dmsg, NULL, HelpRequestCB);
3569 * Special case: When opening any of the special desktop directory
3570 * icons (Home, Remote Systems, etc), we want to display the correct
3571 * path (i.e. $HOME instead of $HOME/.dt/Desktop/Home). So ... we'll
3572 * do the remap here.
3574 real_directory_name = directory_name;
3576 if(openDirType == NEW || (strcmp(real_directory_name, desktop_dir) == 0))
3578 for(i = 0; i < view_count; i++)
3580 if((strcmp(real_directory_name, view_set[i]->directory_name) == 0 &&
3581 (strcmp(host_name, view_set[i]->host_name) == 0))
3586 Screen *currentScreen;
3589 dialog_data = (DialogData *) view_set[i]->dialog_data;
3590 file_mgr_data = (FileMgrData *) dialog_data->data;
3591 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
3593 screen = XDefaultScreen(display);
3594 currentScreen = XScreenOfDisplay(display, screen);
3595 rootWindow = RootWindowOfScreen(currentScreen);
3597 /* Get the current Workspace */
3598 if (DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
3601 Atom * ws_presence = NULL;
3602 unsigned long num_workspaces = 0;
3605 if (DtWsmGetWorkspacesOccupied(display,
3606 XtWindow(file_mgr_rec->shell), &ws_presence,
3607 &num_workspaces) == Success)
3609 /* Already in this workspace? */
3610 for (k = 0; k < num_workspaces; k++)
3612 if (ws_presence[k] == pCurrent)
3616 if (k >= num_workspaces)
3618 /* Add to the workspace */
3619 ws_presence = (Atom *) XtRealloc((char *)ws_presence,
3620 sizeof (Atom) * (num_workspaces + 1));
3622 ws_presence[num_workspaces] = pCurrent;
3623 DtWsmSetWorkspacesOccupied(display,
3624 XtWindow(file_mgr_rec->shell),
3625 ws_presence, num_workspaces + 1);
3627 XFree((char *)ws_presence);
3631 /* Change the hints to reflect the current workspace */
3632 DtWsmSetWorkspacesOccupied(display,
3633 XtWindow(file_mgr_rec->shell),
3638 /* must map the window to catch iconified windows */
3639 /* a XtPopup will not catch it */
3640 XtMapWidget(file_mgr_rec->shell);
3641 XRaiseWindow(display, XtWindow(file_mgr_rec->shell));
3643 /* announce activity */
3646 msg = tt_pnotice_create(TT_SESSION, "DtActivity_Began");
3647 tt_message_send(msg);
3648 tttk_message_destroy(msg);
3656 /* If in novice mode, force the icon for this dir to the 'Open' state */
3657 if (openDirType == NEW)
3658 ForceMyIconOpen(host_name, directory_name);
3660 /* Increment the list size if necessary. */
3662 if (view_count == view_set_size)
3664 view_set_size += 10;
3666 (View **) XtRealloc ((char *)view_set,
3667 sizeof (View **) * view_set_size);
3670 view_set[view_count] = (View *) XtMalloc (sizeof (View));
3671 view_set[view_count]->msg = 0;
3672 view_set[view_count]->pats = 0;
3674 if (initiating_view != NULL)
3675 dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3679 char full_path[MAX_PATH + 1];
3682 tmp_path = _DtCreateDtDirs(display);
3684 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
3686 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
3688 db = XrmGetFileDatabase (full_path);
3693 restoreType = TOOL_RESTORE;
3694 LoadViews(1, db, NULL, directory_name, type, msg);
3698 restoreType = HOME_RESTORE;
3699 LoadViews(1, db, host_name, directory_name, NULL, msg);
3703 * Free the Xrm Database
3705 XrmDestroyDatabase(db);
3706 dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
3707 file_mgr_data = (FileMgrData *) dialog_data->data;
3710 application_args.tool_width = file_mgr_data->width;
3711 application_args.tool_height = file_mgr_data->height;
3715 application_args.dir_width = file_mgr_data->width;
3716 application_args.dir_height = file_mgr_data->height;
3718 if(file_mgr_data->find != NULL &&
3719 file_mgr_data->current_directory != NULL)
3721 DialogData * dialog_data;
3722 FindData * find_data;
3724 dialog_data = (DialogData *)file_mgr_data->find;
3725 find_data = (FindData *)dialog_data->data;
3727 XtFree(find_data->directories);
3728 if(file_mgr_data->restricted_directory == NULL)
3731 find_data->directories = XtNewString(users_home_dir);
3733 find_data->directories =
3734 XtNewString(file_mgr_data->current_directory);
3738 if(strcmp(file_mgr_data->current_directory,
3739 file_mgr_data->restricted_directory) == 0)
3740 find_data->directories = XtNewString("/");
3742 find_data->directories =
3743 XtNewString(file_mgr_data->current_directory +
3744 strlen(file_mgr_data->restricted_directory));
3748 /* If in novice mode, force the icon for all the dir's to the
3750 if (openDirType == NEW)
3751 ForceMyIconOpen(host_name, NULL);
3753 return((DialogData *)view_set[view_count - 1]->dialog_data);
3756 dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3758 view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3759 file_mgr_data = (FileMgrData *) dialog_data->data;
3761 /* Adjust the view settings if this new view was created */
3762 /* because of an action on a previous view. */
3764 if (initiating_view != NULL)
3766 FileMgrPropagateSettings ((FileMgrData *)initiating_view, file_mgr_data);
3767 /* force new window to come up in flat mode */
3768 file_mgr_data->show_type =
3769 ((PreferencesData *)file_mgr_data->preferences->data)->show_type =
3771 file_mgr_data->view = file_mgr_data->view_single;
3774 /* Call the FileMgr dialog to build up its directory set for */
3775 /* the directory name. */
3776 FileMgrBuildDirectories (file_mgr_data, host_name, real_directory_name);
3780 PreferencesData *preferences_data;
3782 file_mgr_data->toolbox = True;
3783 file_mgr_data->width = application_args.tool_width;
3784 file_mgr_data->height = application_args.tool_height;
3786 /* we want to default for the toolboxes (i.e. Application Manager) to
3787 * look different from a normal File Manager view. Let's turn off
3788 * the iconic_path, current_directory, and status_line.
3790 file_mgr_data->show_iconic_path = False;
3791 file_mgr_data->show_current_dir = False;
3793 file_mgr_data->show_status_line = True;
3796 preferences_data = (PreferencesData *)file_mgr_data->preferences->data;
3797 preferences_data->show_iconic_path = file_mgr_data->show_iconic_path;
3798 preferences_data->show_current_dir = file_mgr_data->show_current_dir;
3799 preferences_data->show_status_line = file_mgr_data->show_status_line;
3803 file_mgr_data->toolbox = False;
3804 file_mgr_data->width = application_args.dir_width;
3805 file_mgr_data->height = application_args.dir_height;
3809 if(file_mgr_data->find != NULL && file_mgr_data->current_directory != NULL)
3811 DialogData * dialog_data;
3812 FindData * find_data;
3814 dialog_data = (DialogData *)file_mgr_data->find;
3815 find_data = (FindData *)dialog_data->data;
3817 XtFree(find_data->directories);
3818 if(file_mgr_data->restricted_directory == NULL)
3821 find_data->directories = XtNewString(users_home_dir);
3823 find_data->directories =
3824 XtNewString(file_mgr_data->current_directory);
3828 if(strcmp(file_mgr_data->current_directory,
3829 file_mgr_data->restricted_directory) == 0)
3830 find_data->directories = XtNewString("/");
3832 find_data->directories =
3833 XtNewString(file_mgr_data->current_directory +
3834 strlen(file_mgr_data->restricted_directory));
3838 view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3839 view_set[view_count]->directory_name =
3840 XtNewString (file_mgr_data->current_directory);
3842 /* Load default position info, or inherit, if appropriate */
3843 if ((fmd = (FileMgrData *)initiating_view) &&
3844 (strcmp(fmd->host, host_name) == 0) &&
3845 (strcmp(fmd->current_directory, real_directory_name) == 0))
3847 InheritPositionInfo(fmd, file_mgr_data);
3850 LoadPositionInfo(file_mgr_data);
3853 /* Get the dialog displayed. */
3856 instance_data = (DialogInstanceData *) dialog_data->data;
3857 instance_data->x = position->x;
3858 instance_data->y = position->y;
3859 instance_data->displayed = True; /* @@@ Hack! without this,
3860 _DtShowDialog will ignore
3861 our position info */
3864 tmpTitle = file_mgr_data->title;
3865 title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3867 XtFree(special_title);
3868 special_title = XtNewString(title);
3870 classHints.res_name = title;
3871 classHints.res_class = DTFILE_CLASS_NAME;
3872 initiating_view = NULL;
3874 _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL, RemoveTextFields,
3875 NULL, NULL, False, special_view, title, &classHints);
3878 file_mgr_data->title = tmpTitle;
3881 ViewAccept( view_set[view_count], msg );
3887 /* If in novice mode, force the icon for all the dir's to the 'Open' state */
3888 if (openDirType == NEW)
3889 ForceMyIconOpen(host_name, NULL);
3891 return(dialog_data);
3897 /************************************************************************
3900 * Update the view set array when a view is closed.
3902 ************************************************************************/
3906 DialogData *dialog_data )
3910 FileMgrData * file_mgr_data;
3911 DialogData * tmpDialog_data;
3912 FileMgrRec * file_mgr_rec;
3913 XmManagerWidget file_window;
3914 char *directory_name = NULL;
3915 char *host_name = NULL;
3917 if(dialog_data == trashDialogData)
3919 CloseTrash(NULL, NULL, NULL);
3923 for (i = 0; i < view_count; i++)
3925 if (dialog_data == (DialogData *) (view_set[i]->dialog_data))
3927 tmpDialog_data = (DialogData *) (view_set[i]->dialog_data);
3928 file_mgr_data = (FileMgrData *)tmpDialog_data->data;
3930 directory_name = (char *)XtMalloc( strlen(view_set[i]->directory_name) + 1);
3931 strcpy(directory_name, view_set[i]->directory_name);
3932 host_name = (char *)XtMalloc( strlen(view_set[i]->host_name) + 1);
3933 strcpy(host_name, view_set[i]->host_name);
3935 if (view_set[i]->msg != 0) {
3936 if (view_set[i]->pats != 0) {
3937 ttdt_file_quit( view_set[i]->pats, 0 );
3938 view_set[i]->pats = 0;
3940 tt_message_reply( view_set[i]->msg );
3941 tttk_message_destroy( view_set[i]->msg );
3942 view_set[i]->msg = 0;
3945 XtFree ((char *) view_set[i]->directory_name);
3946 XtFree ((char *) view_set[i]->host_name);
3947 XtFree ((char *) view_set[i]);
3950 for (j = i; j < view_count - 1; j++)
3951 view_set[j] = view_set[j + 1];
3955 _DtHideDialog (dialog_data, True);
3957 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
3958 file_window = (XmManagerWidget)file_mgr_rec->file_window;
3959 /* For next time, unmanage all the icons */
3960 XtUnmanageChildren(file_window->composite.children,
3961 file_window->composite.num_children);
3963 if(PositionFlagSet(file_mgr_data))
3964 SavePositionInfo(file_mgr_data);
3966 /* If it is an Application Manager view, then no point in
3967 caching this dialog, so free it */
3969 if(file_mgr_data->toolbox)
3970 _DtFreeDialog(dialog_data);
3972 _DtFreeDialogData (dialog_data);
3979 /* Update the directory cache list to remove unneeded directories. */
3981 UpdateCachedDirectories (view_set, view_count);
3983 if (openDirType == NEW)
3984 ForceMyIconClosed(host_name, directory_name);
3986 XtFree(directory_name);
3993 /************************************************************************
3996 * This function is called when a view may be changing its
3997 * current directory. It updates the view_set list to the
3998 * new host and directory.
4000 ************************************************************************/
4004 XtPointer file_mgr_data,
4005 char *old_host_name,
4006 char *new_host_name,
4007 char *old_directory_name,
4008 char *new_directory_name )
4013 /* See if the directory is one being viewed */
4015 for (i = 0; i < view_count; i++)
4017 if (((DialogData *) (view_set[i]->dialog_data))->data == file_mgr_data)
4019 if (strcmp (old_host_name, view_set[i]->host_name) == 0 &&
4020 strcmp (old_directory_name, view_set[i]->directory_name) == 0)
4022 XtFree ((char *) view_set[i]->host_name);
4023 view_set[i]->host_name = XtNewString (new_host_name);
4025 XtFree ((char *) view_set[i]->directory_name);
4026 view_set[i]->directory_name = XtNewString (new_directory_name);
4032 /* Update the directory cache list to remove unneeded directories. */
4034 UpdateCachedDirectories (view_set, view_count);
4039 /************************************************************************
4042 * Dispatch ToolTalk events to internal handlers.
4044 ************************************************************************/
4046 static Tt_callback_action
4055 op = tt_message_op( msg );
4056 status = tt_ptr_error( op );
4057 if ((status != TT_OK) || (op == 0)) {
4058 /* Let tttk_Xt_input_handler() Do The Right Thing */
4059 return TT_CALLBACK_CONTINUE;
4061 if (strcmp( op, "DtTypes_Reloaded" ) == 0) {
4063 } else if (strcmp( op, "XSession_Ending" ) == 0) {
4064 if( emptyTrashOnExit )
4068 return TT_CALLBACK_CONTINUE;
4071 tttk_message_destroy( msg );
4072 return TT_CALLBACK_PROCESSED;
4075 /************************************************************************
4078 * Dispatch ToolTalk requests to internal handlers.
4080 ************************************************************************/
4091 op = tt_message_op( msg );
4092 status = tt_ptr_error( op );
4093 if ((status != TT_OK) || (op == 0)) {
4094 /* Let tttk_Xt_input_handler() Do The Right Thing */
4095 return TT_CALLBACK_CONTINUE;
4097 if (strcmp( op, "DtFileSession_Run" ) == 0) {
4098 ViewSessionHandler( msg );
4099 } else if (strcmp( op, "DtFolder_Show" ) == 0) {
4100 ViewDirectoryHandler( msg );
4101 } else if (strcmp( op, "DtHome_Show" ) == 0) {
4102 ViewHomeDirectoryHandler( msg );
4103 } else if (strcmp( op, "DtTools_Show" ) == 0) {
4104 ViewToolsDirectoryHandler( msg );
4105 } else if (strcmp( op, "DtTrash_Show" ) == 0) {
4106 TrashDisplayHandler( msg );
4107 } else if (strcmp( op, "DtTrash_Remove" ) == 0) {
4108 TrashRemoveHandler( msg );
4109 } else if (strcmp( op, "DtTrash_Empty" ) == 0) {
4110 TrashEmptyHandler( msg );
4111 } else if (strcmp( op, "DtTrash_File" ) == 0) {
4112 TrashRemoveNoConfirmHandler( msg );
4113 } else if (strcmp( op, "DtTrash_Restore" ) == 0) {
4114 TrashRestoreHandler( msg );
4115 } else if (strcmp( op, "DtFile_PutOnWorkspace" ) == 0) {
4116 PutOnWorkspaceHandler( msg );
4117 } else if (strcmp( op, "DtFile_Move" ) == 0) {
4118 MoveCopyLinkHandler( msg, MOVE_FILE );
4119 } else if (strcmp( op, "DtFile_Copy" ) == 0) {
4120 MoveCopyLinkHandler( msg, COPY_FILE );
4121 } else if (strcmp( op, "DtFile_Link" ) == 0) {
4122 MoveCopyLinkHandler( msg, LINK_FILE );
4125 return TT_CALLBACK_CONTINUE;
4128 return TT_CALLBACK_PROCESSED;
4134 /************************************************************************
4136 * ViewSessionHandler
4137 * This function is called upon the dt session message
4138 * being received. The name of the session file is extracted
4139 * out of the message and a function is called to create
4140 * a view or set of views described by the file.
4142 ************************************************************************/
4148 char *file = tt_message_file( msg );
4149 tt_message_reply( msg );
4150 tttk_message_destroy( msg );
4152 if (! tt_is_err( tt_ptr_error( file )))
4154 if (view_count == 0 && desktop_data->numIconsUsed == 0)
4156 int session_flag = 0;
4159 session_name = strrchr(file, '/');
4161 LoadDesktopInfo(session_name);
4162 session_flag = RestoreSession (session_name, NORMAL_RESTORE, NULL);
4163 if ((session_flag != 0) && (view_count == 0))
4165 char current_directory[MAX_PATH];
4167 GetPWD(current_directory);
4168 if (current_directory[0] != '\0')
4171 (home_host_name, current_directory, NULL, NULL, 0))
4172 ViewHomeDirectoryHandler (0);
4176 ViewHomeDirectoryHandler (0);
4182 char *tmpStr, *msg, *title;
4184 tmpStr = GETMESSAGE(18, 39, "Cannot start a second File Manager session because a File Manager\nsession is already open on the desktop. If you want to start a new File\nManager session, you must first close all current File Manager windows\nand remove all File Manager objects from the workspaces.");
4185 msg = XtNewString(tmpStr);
4186 title = XtNewString((GETMESSAGE(18,40,"Session Error")));
4187 _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
4198 /************************************************************************
4200 * ViewDirectoryHandler
4201 * This function is called upon the dt directory message
4202 * being received. The name of the directory is extracted
4203 * out of the message and a function is called to create
4204 * a view of the directory.
4206 ************************************************************************/
4209 ViewDirectoryHandler(
4216 initiating_view = NULL;
4217 msgFile = tt_message_file( msg );
4218 if (tt_is_err( tt_ptr_error( msgFile ))) msgFile = 0;
4222 if(msgFile && strncmp(msgFile, "~", 1) != 0 )
4224 if((strcmp(users_home_dir, "/") != 0) &&
4225 (strncmp(msgFile, users_home_dir, strlen(users_home_dir)-1) != 0))
4227 char *tmpStr, *errTitle, *errMsg, *dmsg;
4229 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4230 errTitle = XtNewString(tmpStr);
4231 tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4232 errMsg = XtNewString(tmpStr);
4233 dmsg = XtMalloc(strlen(errMsg)+strlen(msgFile)+1);
4234 sprintf(dmsg, errMsg, msgFile);
4235 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4242 tt_message_reply( msg );
4243 tttk_message_destroy( msg );
4249 numArgs = tt_message_args_count( msg );
4250 if (tt_is_err( tt_int_error( numArgs ))) numArgs = 0;
4253 special_view = True;
4254 special_treeType = UNSET_VALUE;
4255 special_treeFiles = UNSET_VALUE;
4256 special_viewType = UNSET_VALUE;
4257 special_orderType = UNSET_VALUE;
4258 special_directionType = UNSET_VALUE;
4259 special_randomType = UNSET_VALUE;
4260 special_restricted = NULL;
4261 special_title = NULL;
4262 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4263 for(i = 0; i < numArgs; i++)
4267 vtype = tt_message_arg_type( msg, i );
4268 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4271 val = tt_message_arg_val( msg, i );
4272 if(strcmp(vtype, "-title") == 0)
4274 special_title = XtNewString(val);
4276 else if(strcmp(vtype, "-help_volume") == 0)
4278 special_helpVol = XtNewString(val);
4280 if(strcmp(vtype, "-tree") == 0)
4282 DtfileStringToTree(val, &special_treeType);
4284 else if(strcmp(vtype, "-tree_files") == 0)
4286 DtfileStringToTreeFiles(val, &special_treeFiles);
4288 else if(strcmp(vtype, VIEW_HEADER) == 0)
4290 DtfileStringToView(val, &special_viewType);
4292 else if(strcmp(vtype, "-order") == 0)
4294 DtfileStringToOrder(val, &special_orderType);
4296 else if(strcmp(vtype, "-direction") == 0)
4298 DtfileStringToDirection(val, &special_directionType);
4300 else if(strcmp(vtype, "-grid") == 0)
4302 DtfileStringToGrid(val, &special_randomType);
4304 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4306 special_restricted = XtNewString(msgFile);
4311 if ((restrictMode) && (!special_restricted))
4315 ptr = strrchr(users_home_dir, '/');
4317 special_restricted = XtNewString(users_home_dir);
4322 else if (restrictMode)
4326 special_view = True;
4327 special_treeType = treeType;
4328 special_treeFiles = treeFiles;
4329 special_viewType = viewType;
4330 special_orderType = orderType;
4331 special_directionType = directionType;
4332 special_randomType = randomType;
4334 ptr = strrchr(users_home_dir, '/');
4336 special_restricted = XtNewString(users_home_dir);
4339 special_title = NULL;
4340 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4344 special_view = False;
4346 OpenDirectories (msgFile, NULL);
4349 tt_message_reply( msg );
4350 tttk_message_destroy( msg );
4356 /************************************************************************
4359 * This function is called upon the dt directory message
4360 * being received. The name of the directory is extracted
4361 * out of the message and a function is called to create
4362 * a view of the directory. This function is passed directly
4363 * to DtActionInvoke to be used as a callback.
4365 ************************************************************************/
4374 DialogData *return_data;
4378 if(root_dir && strncmp(root_dir, "~", 1) != 0 )
4380 if((strcmp(users_home_dir, "/") != 0) &&
4381 (strncmp(root_dir, users_home_dir, strlen(users_home_dir)-1) != 0))
4383 char *tmpStr, *errTitle, *errMsg, *dmsg;
4385 tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4386 errTitle = XtNewString(tmpStr);
4387 tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4388 errMsg = XtNewString(tmpStr);
4389 dmsg = XtMalloc(strlen(errMsg)+strlen(root_dir)+1);
4390 sprintf(dmsg, errMsg, root_dir);
4391 _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4401 initiating_view = NULL;
4402 special_view = True;
4403 special_treeType = treeType;
4404 special_treeFiles = treeFiles;
4405 special_viewType = viewType;
4406 special_orderType = orderType;
4407 special_directionType = directionType;
4408 special_randomType = randomType;
4411 special_restricted = XtNewString(root_dir);
4414 special_restricted = NULL;
4417 if ((restrictMode) && (!special_restricted))
4421 ptr = strrchr(users_home_dir, '/');
4423 special_restricted = XtNewString(users_home_dir);
4427 special_title = NULL;
4428 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4430 return_data = GetNewView (home_host_name, root_dir, NULL, NULL, msg);
4432 if ((!return_data) && msg)
4434 tt_message_reply(msg);
4435 tttk_message_destroy( msg );
4438 return(return_data);
4443 /************************************************************************
4445 * ViewHomeDirectoryHandler
4446 * This function is called upon the dt home directory message
4447 * being received. The home directory is extracted from the
4448 * users uid and used to open the directory.
4450 ************************************************************************/
4454 ViewHomeDirectoryHandler(
4457 register int i, j, k;
4458 struct passwd * pwInfo;
4461 char full_path[MAX_PATH + 1];
4462 struct stat stat_buf;
4465 /* We have a new view so set initiating_view to null */
4466 initiating_view = NULL;
4468 if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
4470 pwInfo = getpwuid (getuid());
4471 homeDir = pwInfo->pw_dir;
4474 /* Look and see if we have a default environment file present */
4475 tmp_path = _DtCreateDtDirs(display);
4478 if (msg) numArgs = tt_message_args_count(msg);
4479 if (tt_is_err(tt_int_error(numArgs))) numArgs = 0;
4482 special_view = True;
4483 special_treeType = UNSET_VALUE;
4484 special_treeFiles = UNSET_VALUE;
4485 special_viewType = UNSET_VALUE;
4486 special_orderType = UNSET_VALUE;
4487 special_directionType = UNSET_VALUE;
4488 special_randomType = UNSET_VALUE;
4489 special_restricted = NULL;
4490 special_title = NULL;
4491 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4492 for(i = 0; i < numArgs; i++)
4496 vtype = tt_message_arg_type( msg, i );
4497 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4500 val = tt_message_arg_val(msg, i);
4501 if(strcmp(vtype, "-title") == 0)
4503 special_title = XtNewString(val);
4505 else if(strcmp(vtype, "-help_volume") == 0)
4507 special_helpVol = XtNewString(val);
4509 if(strcmp(vtype, "-tree") == 0)
4511 DtfileStringToTree(val, &special_treeType);
4513 else if(strcmp(vtype, "-tree_files") == 0)
4515 DtfileStringToTreeFiles(val, &special_treeFiles);
4517 else if(strcmp(vtype, VIEW_HEADER) == 0)
4519 DtfileStringToView(val, &special_viewType);
4521 else if(strcmp(vtype, "-order") == 0)
4523 DtfileStringToOrder(val, &special_orderType);
4525 else if(strcmp(vtype, "-direction") == 0)
4527 DtfileStringToDirection(val, &special_directionType);
4529 else if(strcmp(vtype, "-grid") == 0)
4531 DtfileStringToGrid(val, &special_randomType);
4533 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4535 special_restricted = XtNewString(val);
4541 else if (restrictMode)
4545 special_view = True;
4546 special_treeType = treeType;
4547 special_treeFiles = treeFiles;
4548 special_viewType = viewType;
4549 special_orderType = orderType;
4550 special_directionType = directionType;
4551 special_randomType = randomType;
4553 ptr = strrchr(users_home_dir, '/');
4555 special_restricted = XtNewString(users_home_dir);
4558 special_title = NULL;
4559 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4562 special_view = False;
4564 if (tmp_path == NULL)
4565 OpenDirectories (homeDir, NULL);
4568 sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
4571 /* Stat the file and make sure its there */
4574 if (stat (full_path, &stat_buf) == 0 && numArgs < 1)
4576 restoreType = HOME_RESTORE;
4577 RestoreSession(full_path, HOME_RESTORE, NULL);
4578 restoreType = NORMAL_RESTORE;
4584 ptr = strrchr(users_home_dir, '/');
4586 strcpy(full_path, users_home_dir);
4588 OpenDirectories (full_path, NULL);
4591 else if (numArgs < 1 && stat (full_path, &stat_buf) == 0)
4593 restoreType = HOME_RESTORE;
4594 RestoreSession(full_path, HOME_RESTORE, NULL);
4595 restoreType = NORMAL_RESTORE;
4601 ptr = strrchr(users_home_dir, '/');
4603 if( ptr != users_home_dir )
4606 strcpy(full_path, users_home_dir);
4609 OpenDirectories (full_path, NULL);
4615 tt_message_reply(msg);
4616 tttk_message_destroy(msg);
4620 /************************************************************************
4622 * ViewToolsDirectroyHandler
4623 * This function is called upon the dt tools message
4624 * being received. The names of the tools directories are
4625 * retrieved from libXue, a view is created and the change
4626 * directory dialog for the view is displayed with the
4627 * set of directories contained in the list.
4629 ************************************************************************/
4632 ViewToolsDirectoryHandler(
4636 char * tmp_path = NULL;
4637 char * tool_dir = NULL;
4638 char * msgFile = NULL;
4641 /* We have a new view so set initiating_view to null */
4642 initiating_view = NULL;
4644 /* Look and see if we have a default environment file present */
4645 tmp_path = _DtCreateDtDirs(display);
4647 if (msg) msgFile = tt_message_file(msg);
4648 if (tt_is_err(tt_ptr_error(msgFile))) msgFile = 0;
4650 if (msg) numArgs = tt_message_args_count(msg);
4651 if (tt_is_err(tt_int_error( numArgs ))) numArgs = 0;
4657 char *link_point = NULL;
4658 char *root_toolbox = NULL;
4659 char *user_install_point = NULL;
4661 special_view = True;
4662 special_treeType = treeType;
4663 special_treeFiles = treeFiles;
4664 special_viewType = viewType;
4665 special_orderType = orderType;
4666 special_directionType = directionType;
4667 special_randomType = randomType;
4668 special_restricted = XtNewString(msgFile);
4669 special_title = NULL;
4670 special_helpVol = XtNewString(DTFILE_HELP_NAME);
4671 for(i = 0; i < numArgs; i++)
4675 vtype = tt_message_arg_type( msg, i );
4676 if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4679 val = tt_message_arg_val( msg, i );
4680 if(strcmp(vtype, "-title") == 0)
4682 special_title = XtNewString(val);
4684 else if(strcmp(vtype, "-help_volume") == 0)
4686 special_helpVol = XtNewString(val);
4688 else if(strcmp(vtype, "-root") == 0)
4690 root_toolbox = XtNewString(val);
4692 else if(strcmp(vtype, "-common_link_point") == 0)
4694 link_point = XtNewString(val);
4696 else if(strcmp(vtype, "-user_install_point") == 0)
4698 user_install_point = XtNewString(val);
4700 if(strcmp(vtype, "-tree") == 0)
4702 DtfileStringToTree(val, &special_treeType);
4704 else if(strcmp(vtype, "-tree_files") == 0)
4706 DtfileStringToTreeFiles(val, &special_treeFiles);
4708 else if(strcmp(vtype, VIEW_HEADER) == 0)
4710 DtfileStringToView(val, &special_viewType);
4712 else if(strcmp(vtype, "-order") == 0)
4714 DtfileStringToOrder(val, &special_orderType);
4716 else if(strcmp(vtype, "-direction") == 0)
4718 DtfileStringToDirection(val, &special_directionType);
4720 else if(strcmp(vtype, "-grid") == 0)
4722 DtfileStringToGrid(val, &special_randomType);
4724 else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4731 /* Due to the use of tooltalk messaging, app manager objects
4732 that are dragged either to the desktop or to the front
4733 panel are identified by their fully resolved names (ie.
4734 /usr/dt/appconfig/appmanager/$LANG/.... as opposed to
4735 /var/dt/appconfig/appmanager/$DTUSERSESSION/....). In order
4736 for the File Manager to treat these objects as links existing
4737 in the /var/.... directory, we use the following ugly code:
4739 1. Search the incoming path for $LANG (if you can't find
4740 $LANG, try C since this is the default).
4741 2. Concatenate the path following $LANG to the path for the
4742 root toolbox (this comes in with the tooltalk message
4743 so that we don't have to hardcode it).
4744 3. Call OpenDirectories with the new path that you have
4745 created and with the root toolbox path as the restricted
4748 This problem is further complicated by:
4749 1. Users traversing into APPGROUPs.
4750 2. Users opening the parent folders for workspace APPGROUPs.
4752 For situation 1, File Manager kicks the user into the App Manager
4753 if he/she traverses into an APPGROUP. BUT we don't want to
4754 make modifications to the path as we do above.
4755 So, if there is nothing following $LANG or if we can't find
4757 (ie. /var/dt/appconfig/appmanager/$DTUSERSESSION), call
4758 OpenDirectories with no parameter changes.
4760 For situation 2, File Manager is unable to distinguish between
4761 workspace objects dragged from /usr/.... or /var/...., so
4762 the parent folder for all workspace APPGROUPS is considered to
4763 be in the /var path. In addition to the OpenAppGroup action,
4764 there is an OpenParentAppGroup action which also triggers
4765 ViewToolsDirectoryHandler but sends in an additional
4766 parameter (user_install_point).
4767 If we know that this msg was generated by the OpenParentAppGroup
4769 AND nothing follows $LANG.
4770 Modify the parameters as above.
4771 OR we can't find $LANG but we can find the user_install_point
4772 (user's personal appgroup path).
4773 Concatenate the path following .dt/appmanager to the path for the
4774 root toolbox. Call OpenDirectories with the new path and the
4775 root toolbox as the restricted directory.
4783 if ((user_install_point) &&
4784 (ptr = strstr(msgFile, user_install_point)))
4786 ptr += strlen(user_install_point);
4787 tool_dir = XtMalloc(strlen(root_toolbox) + strlen(ptr) + 1);
4788 sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4789 XtFree(special_restricted);
4790 special_restricted = XtNewString(root_toolbox);
4794 ptr = strstr(msgFile, link_point);
4799 link_point = XtNewString("C");
4800 ptr = strstr(msgFile, link_point);
4805 ptr += strlen(link_point);
4806 if (strcmp(ptr, "") != 0)
4808 tool_dir = XtMalloc(strlen(root_toolbox) +
4810 sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4811 XtFree(special_restricted);
4812 special_restricted = XtNewString(root_toolbox);
4814 else if (user_install_point)
4816 tool_dir = XtNewString(root_toolbox);
4817 XtFree(special_restricted);
4818 special_restricted = XtNewString(root_toolbox);
4825 XtFree(root_toolbox);
4826 XtFree(user_install_point);
4828 else if (restrictMode)
4832 special_view = True;
4833 ptr = strrchr(users_home_dir, '/');
4835 special_restricted = XtNewString(users_home_dir);
4839 special_view = False;
4842 if (tmp_path == NULL)
4845 OpenDirectories (tool_dir, special_restricted);
4846 else if (msgFile != NULL)
4847 OpenDirectories (msgFile, special_restricted);
4851 char full_path[MAX_PATH + 1];
4852 struct stat stat_buf;
4854 sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
4857 /* Stat the file and make sure its there */
4858 if (stat (full_path, &stat_buf) == 0 && numArgs > 0)
4860 DialogData * dialog_data;
4861 FileMgrData * file_mgr_data;
4863 restoreType = TOOL_RESTORE;
4865 RestoreSession(full_path, TOOL_RESTORE, tool_dir);
4867 RestoreSession(full_path, TOOL_RESTORE, msgFile);
4868 dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
4869 file_mgr_data = (FileMgrData *) dialog_data->data;
4870 application_args.tool_width = file_mgr_data->width;
4871 application_args.tool_height = file_mgr_data->height;
4872 restoreType = NORMAL_RESTORE;
4877 OpenDirectories (tool_dir, special_restricted);
4878 else if (msgFile != NULL)
4879 OpenDirectories (msgFile, special_restricted);
4888 tt_message_reply( msg );
4889 tttk_message_destroy( msg );
4897 /************************************************************************
4900 * This function is called upon the DtSTOP message.
4902 ************************************************************************/
4907 XtPointer clientData,
4908 String * messageFields,
4911 tt_message_reply( msg );
4912 tttk_message_destroy( msg );
4913 FinalizeToolTalkSession( );
4919 * This is the message handling function responsible for reloading
4920 * the filetype and action databases, and then updating our collection
4921 * of action menu items, and updating all open views.
4925 ReloadDatabases(void)
4928 DialogData * dialog_data;
4929 FileMgrData * file_mgr_data;
4930 FileMgrRec * file_mgr_rec;
4931 FileViewData *file_view_data;
4932 DesktopRec *desktopWindow;
4936 XmeFlushIconFileCache ( NULL );
4938 /* Update each directory_set view, both mapped and not */
4939 UpdateDirectorySet();
4941 /* Force action menus to update the next time they're posted */
4942 XtFree(fileMgrPopup.action_pane_file_type);
4943 fileMgrPopup.action_pane_file_type = NULL;
4944 XtFree(desktop_data->popupMenu->action_pane_file_type);
4945 desktop_data->popupMenu->action_pane_file_type = NULL;
4947 /* Update each view */
4948 for (i = 0; i < view_count; i++)
4950 dialog_data = (DialogData *)view_set[i]->dialog_data;
4951 file_mgr_data = (FileMgrData *) dialog_data->data;
4952 file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
4953 XtFree(file_mgr_rec->action_pane_file_type);
4954 file_mgr_rec->action_pane_file_type = NULL;
4955 UpdateFilterAfterDBReread(file_mgr_data->filter_active);
4956 UpdateFilterAfterDBReread(file_mgr_data->filter_edit);
4957 FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
4960 /* go through the desktop objects to make sure the icons change
4961 * Do this by setting the logical_type to -l, CheckDesktop will
4962 * then update the logical type and the icon
4964 for(i = 0; i < desktop_data->numIconsUsed; i++)
4966 desktopWindow = desktop_data->desktopWindows[i];
4967 file_view_data = desktopWindow->file_view_data;
4969 file_view_data->file_data->logical_type = NULL;
4976 * Whenever a directory view or drawer view is closed, we need to remove
4977 * any of its text field children, so that they will not magically reappear
4978 * should this view be reused from the cache to view the same directory later.
4983 XtPointer client_data,
4984 DialogData * old_dialog_data,
4985 DialogData * new_dialog_data)
4987 FileMgrRec * file_mgr_rec;
4988 XmManagerWidget file_window;
4992 file_mgr_rec = (FileMgrRec *) _DtGetDialogInstance(old_dialog_data);
4993 file_window = (XmManagerWidget) file_mgr_rec->file_window;
4994 num_children = file_window->composite.num_children;
4996 for (i = 0; i < num_children; i++)
4998 if (XmIsTextField(file_window->composite.children[i]))
4999 XtDestroyWidget(file_window->composite.children[i]);
5002 _DtFreeDialogData (new_dialog_data);
5007 * This function searches the view list, and returns the file_mgr_data
5008 * associated with the passed-in widget.
5016 DialogData * dialog_data;
5017 FileMgrData * file_mgr_data;
5019 for (i = 0; i < view_count; i++)
5021 dialog_data = (DialogData *) view_set[i]->dialog_data;
5022 file_mgr_data = (FileMgrData *) dialog_data->data;
5024 if (w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->file_window ||
5025 w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->shell)
5026 return(file_mgr_data);
5034 CheckForOpenDirectory(
5035 FileViewData *order_list,
5036 DirectorySet *directory_set,
5037 FileMgrData *file_mgr_data,
5038 char * logical_type)
5042 char *file_type_name, *new_file_type_name;
5043 char directory_name[MAX_PATH];
5044 char * real_dir_name;
5045 FileMgrRec *file_mgr_rec;
5047 PixmapData *pixmapData = NULL;
5049 if (file_mgr_data->view == BY_NAME_AND_ICON)
5054 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5056 if (strcmp (directory_set->name, "/") != 0)
5057 sprintf( directory_name, "%s/%s", directory_set->name, order_list->file_data->file_name);
5059 sprintf( directory_name, "%s%s", directory_set->name, order_list->file_data->file_name );
5061 (void) DtEliminateDots (directory_name);
5063 real_dir_name = XtNewString(directory_name);
5065 for(i = 0; i < view_count; i++)
5067 if(strcmp(real_dir_name, view_set[i]->directory_name) == 0)
5069 file_type_name = order_list->file_data->logical_type;
5070 new_file_type_name = (char *)XtMalloc(strlen(file_type_name)
5071 + strlen(ICON_OPEN_PREFIX) + 1);
5072 sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5073 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5076 file_mgr_rec->file_window,
5078 XtFree(new_file_type_name);
5082 XtFree(real_dir_name);
5084 if(pixmapData == NULL || pixmapData->iconFileName == NULL)
5086 if( pixmapData != NULL )
5088 DtDtsFreeAttributeValue(pixmapData->hostPrefix);
5089 DtDtsFreeAttributeValue(pixmapData->instanceIconName);
5090 DtDtsFreeAttributeValue(pixmapData->iconName);
5091 XtFree((char *)pixmapData);
5094 pixmapData = _DtRetrievePixmapData(logical_type,
5097 file_mgr_rec->file_window,
5106 * The is the menu callback function for cleaning up a view.
5112 XtPointer client_data,
5113 XtPointer call_data)
5117 FileMgrRec * file_mgr_rec;
5118 DialogData * dialog_data;
5119 FileMgrData * file_mgr_data;
5121 XmManagerWidget file_window;
5123 FileViewData * file_view_data;
5124 XRectangle textExtent;
5127 if ((int) client_data == FM_POPUP)
5130 mbar = XmGetPostedFromWidget(XtParent(w));
5133 XtSetArg(args[0], XmNuserData, &file_mgr_rec);
5134 XtGetValues(mbar, args, 1);
5136 /* Ignore accelerators when we're insensitive */
5137 if ((file_mgr_rec->menuStates & CLEAN_UP) == 0)
5140 /* Ignore accelerators received after we're unposted */
5141 if ((dialog_data = _DtGetInstanceData((XtPointer)file_mgr_rec)) == NULL)
5144 file_mgr_data = (FileMgrData *)dialog_data->data;
5146 /* Reset the grid size, so it will be recalculated later. */
5147 file_mgr_data->grid_height = 0;
5148 file_mgr_data->grid_width = 0;
5150 if(file_mgr_data->object_positions)
5151 FreePositionInfo(file_mgr_data);
5153 /* CLEAN_UP_OP is not really a menu state.
5154 It's a flag to let GetFileData in FileMgr.c (call when the directory
5155 is being reread) not to reload icon positions from the .!dt<userid> file.
5157 file_mgr_rec->menuStates |= CLEAN_UP_OP;
5159 /* Re-layout the view */
5160 FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
5162 if ((file_mgr_data->show_type == SINGLE_DIRECTORY) &&
5163 (file_mgr_data->view != BY_ATTRIBUTES) &&
5164 (file_mgr_data->positionEnabled == RANDOM_ON))
5166 ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5171 /* Update the preferences dialog */
5172 ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5176 /* Move any text widget, to keep them in sync with their icons */
5177 file_window = (XmManagerWidget)file_mgr_rec->file_window;
5179 for (j = 0; j < file_window->composite.num_children; j++)
5181 if (XmIsTextField(file_window->composite.children[j]) &&
5182 !file_window->composite.children[j]->core.being_destroyed)
5184 XtSetArg(args[0], XmNuserData, &name);
5185 XtGetValues(file_window->composite.children[j], args, 1);
5187 /* Find the associated icon data */
5188 /* @@@ this won't work for tree mode! */
5189 for (i = 0; i < file_mgr_data->directory_set[0]->file_count; i++)
5191 file_view_data = file_mgr_data->directory_set[0]->file_view_data[i];
5192 if (strcmp(name, file_view_data->file_data->file_name) == 0)
5194 _DtIconGetTextExtent_r(file_view_data->widget, &textExtent);
5197 (Dimension)(file_window->composite.children[j]->core.height -
5198 textExtent.height)/(Dimension)2;
5199 XtSetArg (args[0], XmNx, x);
5200 XtSetArg (args[1], XmNy, y);
5201 XtSetValues (file_window->composite.children[j], args, 2);
5208 if ((file_mgr_rec->menuStates & CLEAN_UP_OP))
5209 file_mgr_rec->menuStates &= ~CLEAN_UP_OP;
5212 /*************************************<->*************************************
5214 * DtfileCvtStringToObjPlace (args, numArgs, fromVal, toVal)
5219 * This function converts a string to an desktop placement scheme description.
5224 * args = NULL (don't care)
5226 * numArgs = 0 (don't care)
5228 * fromVal = resource value to convert
5233 * toVal = descriptor to use to return converted value
5235 *************************************<->***********************************/
5238 DtfileCvtStringToObjPlace (
5244 unsigned char *pch = (unsigned char *) (fromVal->addr);
5245 unsigned char *pchNext;
5249 Boolean fPrimarySet = False;
5250 Boolean fSecondarySet = False;
5253 * Icon placement layout values:
5256 #define OBJ_PLACE_BOTTOM_STR (unsigned char *)"bottom"
5257 #define OBJ_PLACE_LEFT_STR (unsigned char *)"left"
5258 #define OBJ_PLACE_RIGHT_STR (unsigned char *)"right"
5259 #define OBJ_PLACE_TOP_STR (unsigned char *)"top"
5263 * Convert the icon placement resource value:
5268 while (*pch && _DtNextToken (pch, &len, &pchNext))
5276 if (_DtStringsAreEquivalent((char *)pch, (char *)OBJ_PLACE_BOTTOM_STR))
5280 cval |= OBJ_PLACE_BOTTOM_PRIMARY;
5283 else if (!fSecondarySet)
5286 (OBJ_PLACE_BOTTOM_PRIMARY | OBJ_PLACE_TOP_PRIMARY)))
5288 cval |= OBJ_PLACE_BOTTOM_SECONDARY;
5289 fSecondarySet = True;
5298 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_LEFT_STR))
5302 cval |= OBJ_PLACE_LEFT_PRIMARY;
5305 else if (!fSecondarySet)
5308 (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY)))
5310 cval |= OBJ_PLACE_LEFT_SECONDARY;
5311 fSecondarySet = True;
5319 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_RIGHT_STR))
5323 cval |= OBJ_PLACE_RIGHT_PRIMARY;
5326 else if (!fSecondarySet)
5329 (OBJ_PLACE_RIGHT_PRIMARY | OBJ_PLACE_LEFT_PRIMARY)))
5331 cval |= OBJ_PLACE_RIGHT_SECONDARY;
5332 fSecondarySet = True;
5340 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_TOP_STR))
5344 cval |= OBJ_PLACE_TOP_PRIMARY;
5347 else if (!fSecondarySet)
5350 (OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_BOTTOM_PRIMARY)))
5352 cval |= OBJ_PLACE_TOP_SECONDARY;
5353 fSecondarySet = True;
5366 cval = OBJ_PLACE_TOP_PRIMARY;
5370 if (cval & (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY))
5372 cval |= OBJ_PLACE_TOP_SECONDARY;
5375 cval |= OBJ_PLACE_RIGHT_SECONDARY;
5380 (*toVal).size = sizeof (long);
5381 (*toVal).addr = (XtPointer) &cval;
5383 } /* END OF FUNCTION DtfileCvtStringToObjPlace */
5385 /*************************************<->*************************************
5387 * _DtNextToken (pchIn, pLen, ppchNext)
5397 * pchIn = pointer to start of next token
5402 * pLen = pointer to integer containing number of characters in next token
5403 * ppchNext = address of pointer to following token
5405 * Return = next token or NULL
5412 *************************************<->***********************************/
5414 static unsigned char
5416 unsigned char *pchIn,
5418 unsigned char **ppchNext)
5420 unsigned char *pchR = pchIn;
5425 for (i = 0; ((chlen = mblen ((char *)pchIn, MB_CUR_MAX)) > 0); i++)
5426 /* find end of word: requires singlebyte whitespace terminator */
5428 if ((chlen == 1) && isspace (*pchIn))
5436 for (i = 0; *pchIn && !isspace (*pchIn); i++, pchIn++)
5437 /* find end of word */
5442 /* skip to next word */
5444 while (pchIn && (mblen ((char *)pchIn, MB_CUR_MAX) == 1) && isspace (*pchIn))
5446 while (pchIn && isspace (*pchIn))
5463 } /* END OF FUNCTION _DtNextToken */
5465 /*************************************<->*************************************
5467 * DtfileCvtStringToOpenDir (args, numArgs, fromVal, toVal)
5472 * This function converts a string to an desktop placement scheme description.
5477 * args = NULL (don't care)
5479 * numArgs = 0 (don't care)
5481 * fromVal = resource value to convert
5486 * toVal = descriptor to use to return converted value
5488 *************************************<->***********************************/
5491 DtfileCvtStringToOpenDir (
5497 char * in_str = (char *) (fromVal->addr);
5500 toVal->size = sizeof (int);
5501 toVal->addr = (XtPointer) &i;
5503 if (_DtStringsAreEquivalent (in_str, "current"))
5505 else if (_DtStringsAreEquivalent (in_str, "new"))
5514 XtStringConversionWarning ((char *)fromVal->addr, "OpenDir");
5519 /*************************************<->*************************************
5521 * DtfileCvtStringToDTIcon (args, numArgs, fromVal, toVal)
5526 * This function converts a string to an desktop placement scheme description.
5531 * args = NULL (don't care)
5533 * numArgs = 0 (don't care)
5535 * fromVal = resource value to convert
5540 * toVal = descriptor to use to return converted value
5542 *************************************<->***********************************/
5545 DtfileCvtStringToDTIcon (
5551 char * in_str = (char *) (fromVal->addr);
5554 toVal->size = sizeof (int);
5555 toVal->addr = (XtPointer) &i;
5557 if (_DtStringsAreEquivalent (in_str, "large"))
5559 else if (_DtStringsAreEquivalent (in_str, "small"))
5561 else if (_DtStringsAreEquivalent (in_str, "default"))
5562 i = LARGE; /* for now, eventually want to look at screen width/height*/
5570 XtStringConversionWarning ((char *)fromVal->addr, "DesktopIcon");
5576 DtfileCvtStringToTree (
5582 char * in_str = (char *) (fromVal->addr);
5585 toVal->size = sizeof (int);
5586 toVal->addr = (XtPointer) &i;
5588 DtfileStringToTree(in_str, &i);
5592 DtfileCvtStringToTreeFiles (
5598 char * in_str = (char *) (fromVal->addr);
5601 toVal->size = sizeof (int);
5602 toVal->addr = (XtPointer) &i;
5604 DtfileStringToTreeFiles(in_str, &i);
5608 DtfileCvtStringToView (
5614 char * in_str = (char *) (fromVal->addr);
5617 toVal->size = sizeof (int);
5618 toVal->addr = (XtPointer) &i;
5620 DtfileStringToView(in_str, &i);
5624 DtfileCvtStringToOrder (
5630 char * in_str = (char *) (fromVal->addr);
5633 toVal->size = sizeof (int);
5634 toVal->addr = (XtPointer) &i;
5636 DtfileStringToOrder(in_str, &i);
5640 DtfileCvtStringToDirection (
5646 char * in_str = (char *) (fromVal->addr);
5649 toVal->size = sizeof (int);
5650 toVal->addr = (XtPointer) &i;
5652 DtfileStringToDirection(in_str, &i);
5656 DtfileCvtStringToGrid (
5662 char * in_str = (char *) (fromVal->addr);
5665 toVal->size = sizeof (int);
5666 toVal->addr = (XtPointer) &i;
5668 DtfileStringToGrid(in_str, &i);
5677 FileMgrData *file_mgr_data;
5678 DialogData *dialog_data;
5680 for(i = 0; i < view_count; i++)
5682 if(strcmp(directory, view_set[i]->directory_name) == 0 &&
5683 strcmp(host, view_set[i]->host_name) == 0)
5685 dialog_data = (DialogData *) view_set[i]->dialog_data;
5686 file_mgr_data = (FileMgrData *) dialog_data->data;
5687 return(file_mgr_data);
5694 GetRestrictedDirectory (
5698 FileMgrData *file_mgr_data;
5699 FileMgrRec *file_mgr_rec;
5700 DialogData *dialog_data;
5702 for(i = 0; i < view_count; i++)
5704 dialog_data = (DialogData *) view_set[i]->dialog_data;
5705 file_mgr_data = (FileMgrData *) dialog_data->data;
5706 file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5707 if(file_mgr_rec->current_directory_text == widget &&
5708 file_mgr_data->fast_cd_enabled)
5710 return(file_mgr_data->restricted_directory);
5713 return((char *)NULL);
5721 if (_DtStringsAreEquivalent (str, "on"))
5722 *type = MULTIPLE_DIRECTORY;
5723 else if (_DtStringsAreEquivalent (str, "off"))
5724 *type = SINGLE_DIRECTORY;
5726 *type = UNSET_VALUE;
5730 DtfileStringToTreeFiles(
5734 if (_DtStringsAreEquivalent (str, "never"))
5735 *type = TREE_FILES_NEVER;
5736 else if (_DtStringsAreEquivalent (str, "choose"))
5737 *type = TREE_FILES_CHOOSE;
5738 else if (_DtStringsAreEquivalent (str, "always"))
5739 *type = TREE_FILES_ALWAYS;
5741 *type = UNSET_VALUE;
5749 if (_DtStringsAreEquivalent (str, "no_icon") ||
5750 _DtStringsAreEquivalent (str, "no_icons"))
5752 else if (_DtStringsAreEquivalent (str, "large_icon") ||
5753 _DtStringsAreEquivalent (str, "large_icons"))
5754 *type = BY_NAME_AND_ICON;
5755 else if (_DtStringsAreEquivalent (str, "small_icon") ||
5756 _DtStringsAreEquivalent (str, "small_icons"))
5757 *type = BY_NAME_AND_SMALL_ICON;
5758 else if (_DtStringsAreEquivalent (str, "attributes"))
5759 *type = BY_ATTRIBUTES;
5761 *type = UNSET_VALUE;
5765 DtfileStringToOrder(
5769 if (_DtStringsAreEquivalent (str, "file_type"))
5770 *type = ORDER_BY_FILE_TYPE;
5771 else if (_DtStringsAreEquivalent (str, "alphabetical"))
5772 *type = ORDER_BY_ALPHABETICAL;
5773 else if (_DtStringsAreEquivalent (str, "date"))
5774 *type = ORDER_BY_DATE;
5775 else if (_DtStringsAreEquivalent (str, "size"))
5776 *type = ORDER_BY_SIZE;
5778 *type = UNSET_VALUE;
5783 DtfileStringToDirection(
5787 if (_DtStringsAreEquivalent (str, "ascending"))
5788 *type = DIRECTION_ASCENDING;
5789 else if (_DtStringsAreEquivalent (str, "descending"))
5790 *type = DIRECTION_DESCENDING;
5792 *type = UNSET_VALUE;
5800 if (_DtStringsAreEquivalent (str, "on"))
5802 else if (_DtStringsAreEquivalent (str, "off"))
5805 *type = UNSET_VALUE;
5809 SetupSendRequestArgs(
5810 ApplicationArgs application_args,
5814 if(application_args.title != NULL)
5816 tt_message_arg_add( msg, TT_IN, "-title", application_args.title );
5818 if(application_args.restricted != NULL)
5820 tt_message_arg_add( msg, TT_IN, RESTRICTED_HEADER, 0 );
5822 vtype = VIEW_HEADER;
5823 switch( application_args.view )
5826 tt_message_arg_add( msg, TT_IN, vtype, "no_icon" );
5828 case BY_NAME_AND_ICON:
5829 tt_message_arg_add( msg, TT_IN, vtype, "large_icon" );
5831 case BY_NAME_AND_SMALL_ICON:
5832 tt_message_arg_add( msg, TT_IN, vtype, "small_icon" );
5835 tt_message_arg_add( msg, TT_IN, vtype, "attributes" );
5838 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5843 switch( application_args.order )
5845 case ORDER_BY_FILE_TYPE:
5846 tt_message_arg_add( msg, TT_IN, vtype, "file_type" );
5848 case ORDER_BY_ALPHABETICAL:
5849 tt_message_arg_add( msg, TT_IN, vtype, "alphabetical" );
5852 tt_message_arg_add( msg, TT_IN, vtype, "date" );
5855 tt_message_arg_add( msg, TT_IN, vtype, "size" );
5858 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5862 vtype = "-direction";
5863 switch( application_args.direction )
5865 case DIRECTION_ASCENDING:
5866 tt_message_arg_add( msg, TT_IN, vtype, "ascending" );
5868 case DIRECTION_DESCENDING:
5869 tt_message_arg_add( msg, TT_IN, vtype, "descending" );
5872 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5877 switch( application_args.grid )
5880 tt_message_arg_add( msg, TT_IN, vtype, "on" );
5883 tt_message_arg_add( msg, TT_IN, vtype, "off" );
5886 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5890 switch( application_args.tree_view )
5892 case MULTIPLE_DIRECTORY:
5893 tt_message_arg_add( msg, TT_IN, vtype, "on" );
5895 case SINGLE_DIRECTORY:
5896 tt_message_arg_add( msg, TT_IN, vtype, "off" );
5899 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5903 vtype = "-tree_files";
5904 switch( application_args.tree_files )
5906 case TREE_FILES_NEVER:
5907 tt_message_arg_add( msg, TT_IN, vtype, "never" );
5909 case TREE_FILES_CHOOSE:
5910 tt_message_arg_add( msg, TT_IN, vtype, "choose" );
5912 case TREE_FILES_ALWAYS:
5913 tt_message_arg_add( msg, TT_IN, vtype, "always" );
5916 tt_message_arg_add( msg, TT_IN, vtype, "none" );
5920 if(application_args.help_volume != NULL)
5922 tt_message_arg_add( msg, TT_IN, "-help_volume",
5923 application_args.help_volume );
5928 * This routine is used by ForceMyIconOpen to get the "Open" filetype and
5929 * find out what the new icon is. It then places that icon in the
5930 * correct icon gadget.
5933 BuildAndShowIconName(
5934 char *file_type_name,
5936 unsigned char show_type,
5939 char *new_file_type_name;
5942 PixmapData *pixmapData;
5944 new_file_type_name = (char *)XtMalloc(strlen(file_type_name) +
5945 strlen(ICON_OPEN_PREFIX) + 1);
5946 sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5948 if (view == BY_NAME_AND_ICON && show_type != MULTIPLE_DIRECTORY)
5949 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5955 pixmapData = _DtRetrievePixmapData(new_file_type_name,
5961 if(pixmapData && pixmapData->iconFileName)
5963 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
5964 XtSetValues(widget, args, 1);
5969 XtSetArg (args[0], XmNimageName, NULL);
5970 XtSetValues(widget, args, 1);
5974 _DtCheckAndFreePixmapData(new_file_type_name,
5976 (DtIconGadget) widget,
5979 XtFree(new_file_type_name);
5984 * Given a directory name, this function will see if a view of the parent
5985 * directory is open; if so, then it will update the icon representing
5986 * this icon, in the parent view, so that it is drawn as 'closed'. This
5987 * function must only be called if openDirType == NEW.
5993 char * directory_name)
5999 FileViewData * file_view_data = NULL;
6000 DialogData *dialog_data;
6001 FileMgrData *file_mgr_data;
6002 DesktopRec *desktopWindow;
6005 PixmapData *pixmapData;
6007 /* find the parent directory of the one just removed */
6008 parent = _DtPName(directory_name);
6009 fname = DName(directory_name);
6011 /* first check to see if any File Manager views have this directory */
6012 for (i = 0; i < view_count; i++)
6014 dialog_data = (DialogData *) view_set[i]->dialog_data;
6015 file_mgr_data = (FileMgrData *) dialog_data->data;
6017 /* loop through until we find the file_view_data structure for
6018 * the directory to force open */
6020 for(j = 0; j < file_mgr_data->directory_count; j++)
6022 if (strcmp(parent, file_mgr_data->directory_set[j]->name) == 0)
6024 for (k = 0; k < file_mgr_data->directory_set[j]->file_count; k++)
6027 file_mgr_data->directory_set[j]->file_view_data[k];
6028 if (strcmp(file_view_data->file_data->file_name, fname) == 0)
6038 if( (file_view_data) && (file_mgr_data->view != BY_NAME) )
6040 if (file_mgr_data->view == BY_NAME_AND_ICON &&
6041 file_mgr_data->show_type != MULTIPLE_DIRECTORY)
6042 pixmapData = _DtRetrievePixmapData(
6043 file_view_data->file_data->logical_type,
6046 file_view_data->widget,
6049 pixmapData = _DtRetrievePixmapData(
6050 file_view_data->file_data->logical_type,
6053 file_view_data->widget,
6057 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6059 XtSetArg (args[0], XmNimageName, NULL);
6060 XtSetValues (file_view_data->widget, args, 1);
6062 _DtCheckAndFreePixmapData(file_view_data->file_data->logical_type,
6063 file_view_data->widget,
6064 (DtIconGadget) file_view_data->widget,
6068 /* now check to see if any desktop objects are this directory */
6069 for(j = 0; j < desktop_data->numIconsUsed; j++)
6073 desktopWindow = desktop_data->desktopWindows[j];
6074 file_view_data = desktopWindow->file_view_data;
6076 sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
6077 desktopWindow->file_name);
6078 DtEliminateDots (buf);
6080 if( (strcmp(buf, directory_name) == 0) &&
6081 (strcmp(desktopWindow->host, host_name) == 0) )
6083 pixmapData = _DtRetrievePixmapData(
6084 file_view_data->file_data->logical_type,
6087 desktopWindow->shell,
6091 XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6093 XtSetArg (args[0], XmNimageName, NULL);
6094 XtSetValues (desktopWindow->iconGadget, args, 1);
6096 _DtCheckAndFreePixmapData(
6097 desktopWindow->file_view_data->file_data->logical_type,
6098 desktopWindow->shell,
6099 (DtIconGadget) desktopWindow->iconGadget,
6106 /*************************************************************************
6108 * MarqueeSelect - this is the callback which gets called when there is
6109 * a marquee event happening on the root window.
6111 ************************************************************************/
6120 XtPointer client_data)
6125 Screen *currentScreen;
6127 char *workspace_name=NULL;
6133 case DT_WSM_MARQUEE_SELECTION_TYPE_BEGIN:
6134 display = XtDisplay(desktop_data->desktopWindows[0]->shell);
6135 screen = XDefaultScreen(display);
6136 currentScreen = XScreenOfDisplay(display, screen);
6137 rootWindow = RootWindowOfScreen(currentScreen);
6139 if(DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
6142 workspace_name = XGetAtomName (display, pCurrent);
6143 CleanUpWSName(workspace_name);
6147 XtNewString(desktop_data->workspaceData[0]->name);
6149 for(i = 0; i < desktop_data->numWorkspaces; i++)
6151 if(strcmp(workspace_name,
6152 desktop_data->workspaceData[i]->name) == 0)
6154 DeselectAllDTFiles(desktop_data->workspaceData[i]);
6158 XtFree(workspace_name);
6161 case DT_WSM_MARQUEE_SELECTION_TYPE_END:
6162 CheckDesktopMarquee(x, y, width, height);
6165 case DT_WSM_MARQUEE_SELECTION_TYPE_CANCEL:
6168 case DT_WSM_MARQUEE_SELECTION_TYPE_CONTINUE:
6169 CheckDesktopMarquee(x, y, width, height);
6179 * We must wait for the message response, before exiting
6183 WaitForResponseAndExit( void )
6191 XtPointer clientData,
6196 FinalizeToolTalkSession( );
6202 * Puts up an Error dialog with Cancel and Help unmapped in the
6203 * center of the screen. The last argument is the OK callback
6207 post_dialog(Widget parent, char *title, char *msg, void (*DtErrExitCB)())
6209 Widget dialog, dialogShell;
6210 XmString message_text, ok;
6212 Dimension dialogWd, dialogHt;
6215 ok = XmStringCreateLocalized ((char*)_DtOkString);
6216 message_text = XmStringCreateLocalized (msg);
6218 XtSetArg(args[n], XmNautoUnmanage, False); n++;
6219 XtSetArg(args[n], XmNokLabelString, ok); n++;
6220 XtSetArg(args[n], XmNtitle, title); n++;
6221 XtSetArg(args[n], XmNmessageString, message_text); n++;
6222 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
6223 XtSetArg (args[n], XmNdefaultPosition, False); n++;
6224 XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
6226 dialog = XmCreateErrorDialog (parent, title, args, n);
6227 XtAddCallback (dialog, XmNokCallback, DtErrExitCB, NULL);
6228 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON));
6229 XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
6231 /* Disable the frame menu from dialog since we don't want the user
6232 to be able to close dialogs with the frame menu */
6234 dialogShell = XtParent(dialog);
6235 XtSetArg(args[0], XmNmappedWhenManaged, False);
6236 XtSetArg(args[1], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU);
6237 XtSetValues(dialogShell, args, 2);
6238 XtManageChild (dialog);
6239 XtRealizeWidget (dialogShell);
6241 /* Center the dialog */
6243 XtSetArg(args[0], XmNwidth, &dialogWd);
6244 XtSetArg(args[1], XmNheight, &dialogHt);
6245 XtGetValues(dialog, args, 2);
6246 XtSetArg (args[0], XmNx,
6247 (WidthOfScreen(XtScreen(dialog)) - dialogWd) / 2);
6248 XtSetArg (args[1], XmNy,
6249 (HeightOfScreen(XtScreen(dialog)) - dialogHt) / 2);
6250 XtSetArg (args[2], XmNmappedWhenManaged, True);
6251 XtSetValues (dialog, args, 3);
6253 XtSetArg(args[0], XmNmappedWhenManaged, True);
6254 XtSetValues(dialogShell, args, 1);
6256 XtManageChild (dialog);
6257 XmStringFree(message_text);
6263 * This is the Callback when an error occurs while trying to create
6264 * the .dt folder or sub-folders. Application exits.
6268 DtErrExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
6270 XtPopdown (XtParent (dialog));
6271 FinalizeToolTalkSession();
6277 sigchld_handler(int signo) /* Do not use the arg signo at the moment */
6283 On DUX, the process remains in the ZOMBIE
6284 state untill parent invokes wait or waitpid.
6287 pid = waitpid(-1, &stat_loc, WNOHANG);
6288 /* Child exit handling code follows, if any */
6290 #endif /* __osf__ */