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 /* $XConsortium: ChangeDir.c /main/7 1996/10/30 11:09:35 drk $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * DESCRIPTION: Source file for the change directory dialog.
33 * FUNCTIONS: ChangeToNewDir
52 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
53 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
54 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
55 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
57 ****************************************************************************
58 ************************************<+>*************************************/
62 #include <sys/types.h>
66 #include <sys/inode.h>
74 #include <Xm/MessageB.h>
75 #include <Xm/SelectioB.h>
77 #include <Xm/VendorSEP.h>
79 #include <Xm/MwmUtil.h>
80 #include <Xm/Protocols.h>
82 #include <X11/ShellP.h>
83 #include <X11/Shell.h>
84 #include <X11/Xatom.h>
86 #include <Dt/Action.h>
87 #include <Dt/Connect.h>
88 #include <Dt/DtNlUtils.h>
92 #include <Xm/DragIcon.h>
97 #include "SharedProcs.h"
101 #include "ChangeDir.h"
103 #include "SharedMsgs.h"
106 #define MAX_PATH 1024
108 static char * CHANGEDIRECTORY = "ChangeDirectory";
111 static DialogResource resources[] =
113 { "string_path", XmRXmString, sizeof(XmString),
114 XtOffset(ChangeDirDataPtr, string_path), NULL, _DtXmStringToString },
116 { "historyList", XmRXmStringTable, sizeof(XmStringTable),
117 XtOffset(ChangeDirDataPtr, history_list), NULL, _DtXmStringTableToString },
119 { "visibleCount", XmRInt, sizeof(int),
120 XtOffset(ChangeDirDataPtr, visible_count), (XtPointer) 8, _DtIntToString },
122 { "listCount", XmRInt, sizeof(int),
123 XtOffset(ChangeDirDataPtr, list_count), NULL, _DtIntToString },
127 /******** Static Function Declarations ********/
129 static void Create( Display *display,
133 static void InstallChange( ChangeDirRec *change_dir_rec,
134 XtCallbackProc callback,
135 XtPointer client_data) ;
136 static void InstallClose( ChangeDirRec *change_dir_rec,
137 XtCallbackProc callback,
138 XtPointer client_data) ;
139 static void Destroy( ChangeDirRec *change_dir_rec) ;
140 static XtPointer GetValues( ChangeDirRec *change_dir_rec) ;
141 static XtPointer GetDefaultValues( void ) ;
142 static XtPointer GetResourceValues( XrmDatabase data_base,
144 static void SetValues( ChangeDirRec *change_dir_rec,
145 ChangeDirData *change_dir_data) ;
146 static void WriteResourceValues( DialogData *values,
149 static void FreeValues( ChangeDirData *change_dir_data) ;
150 static Boolean TryToChangeDir( Boolean isFromDialog,
151 char * incoming_string,
152 FileMgrData * file_mgr_data,
153 FileMgrRec * file_mgr_rec,
154 ChangeDirData * change_dir_data,
155 Widget selection_box,
156 ChangeDirApply * apply_data,
157 XmSelectionBoxCallbackStruct * callback_data,
158 void (*callback)()) ;
159 static void OkCallback( Widget selection_box,
160 ChangeDirApply *apply_data,
161 XmSelectionBoxCallbackStruct *callback_data) ;
162 static int CheckRestrictedDir ( FileMgrRec * file_mgr_rec,
163 FileMgrData * file_mgr_data,
165 Boolean relative_name);
166 static void GoToNewDir ( FileMgrData * file_mgr_data,
168 static void SetFocus(
169 ChangeDirRec *change_dir_rec,
170 ChangeDirData *change_dir_data) ;
173 /******** End Static Function Declarations ********/
175 extern char *getwd(char *);
178 * The Dialog Class structure.
181 static DialogClass changeDirClassRec =
186 (DialogInstallChangeProc) InstallChange,
187 (DialogInstallCloseProc) InstallClose,
188 (DialogDestroyProc) Destroy,
189 (DialogGetValuesProc) GetValues,
192 (DialogSetValuesProc) SetValues,
194 (DialogFreeValuesProc) FreeValues,
195 (DialogMapWindowProc) _DtGenericMapWindow,
196 (DialogSetFocusProc) SetFocus,
199 DialogClass * changeDirClass = (DialogClass *) &changeDirClassRec;
204 /************************************************************************
208 ************************************************************************/
217 ChangeDirRec * change_dir_rec;
222 XtTranslations trans_table;
226 /* Allocate the change directory dialog instance record. */
228 change_dir_rec = (ChangeDirRec *) XtMalloc (sizeof (ChangeDirRec));
230 prompt = XmStringCreateLocalized (((char *)GETMESSAGE(2,14, "Destination Folder:")));
232 trans_table = XtParseTranslationTable(translations_space);
234 XtSetArg (args[n], XmNselectionLabelString, prompt); n++;
235 XtSetArg (args[n], XmNokLabelString, okXmString); n++;
236 XtSetArg (args[n], XmNcancelLabelString, cancelXmString); n++;
237 XtSetArg (args[n], XmNhelpLabelString, helpXmString); n++;
238 XtSetArg (args[n], XmNautoUnmanage, False); n++;
239 XtSetArg (args[n], XmNtextTranslations, trans_table); n++;
240 change_dir = change_dir_rec->change_dir =
241 XmCreateSelectionDialog (parent, "change_directory", args, n);
242 change_dir_rec->shell = XtParent(change_dir);
244 XmStringFree (prompt);
246 /* Add the help callback to each of the important sub-components */
247 XtAddCallback(change_dir, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
248 HELP_CHANGEDIR_DIALOG_STR);
249 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_APPLY_BUTTON);
250 XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
251 HELP_CHANGEDIR_DIALOG_STR);
252 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_CANCEL_BUTTON);
253 XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
254 HELP_CHANGEDIR_DIALOG_STR);
255 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_HELP_BUTTON);
256 XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
257 HELP_CHANGEDIR_DIALOG_STR);
258 XtAddCallback(w, XmNactivateCallback, (XtCallbackProc)HelpRequestCB,
259 HELP_CHANGEDIR_DIALOG_STR);
260 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_OK_BUTTON);
261 XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
262 HELP_CHANGEDIR_DIALOG_STR);
263 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_LIST);
264 XtAddCallback(XtParent(w), XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
265 HELP_CHANGEDIR_DIALOG_STR);
266 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_LIST_LABEL);
267 XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
268 HELP_CHANGEDIR_DIALOG_STR);
269 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_SELECTION_LABEL);
270 XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
271 HELP_CHANGEDIR_DIALOG_STR);
272 w = XmSelectionBoxGetChild(change_dir, XmDIALOG_TEXT);
273 XtAddCallback(w, XmNhelpCallback, (XtCallbackProc)HelpRequestCB,
274 HELP_CHANGEDIR_DIALOG_STR);
277 /* Adjust the margin widths and heights of each of the buttons */
279 XtSetArg (args[0], XmNmarginWidth, 6);
280 XtSetArg (args[1], XmNmarginHeight, 2);
282 w = XmSelectionBoxGetChild (change_dir_rec->change_dir, XmDIALOG_OK_BUTTON);
283 XtSetValues (w, args, 2);
285 w = XmSelectionBoxGetChild (change_dir_rec->change_dir,
286 XmDIALOG_HELP_BUTTON);
287 XtSetValues (w, args, 2);
289 w = XmSelectionBoxGetChild (change_dir_rec->change_dir,
290 XmDIALOG_CANCEL_BUTTON);
291 XtSetValues (w, args, 2);
293 XtUnmanageChild(XmSelectionBoxGetChild (change_dir_rec->change_dir,
294 XmDIALOG_APPLY_BUTTON));
297 /* Adjust the decorations for the dialog shell of the dialog */
299 XtSetArg(args[0], XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE);
300 XtSetArg(args[1], XmNmwmDecorations,
301 MWM_DECOR_BORDER | MWM_DECOR_TITLE);
302 XtSetValues (change_dir_rec->shell, args, 2);
304 XtSetArg(args[0], XmNcancelButton, w);
305 XtSetValues (change_dir_rec->change_dir, args, 1);
307 /* Set the return values for the dialog widget and dialog instance. */
309 *shell = change_dir_rec->change_dir;
310 *dialog = (XtPointer) change_dir_rec;
317 /************************************************************************
321 ************************************************************************/
325 ChangeDirRec *change_dir_rec,
326 XtCallbackProc callback,
327 XtPointer client_data )
329 Widget selection_box = change_dir_rec->change_dir;
330 ChangeDirApply * apply_data;
332 /* Setup the callback data to be sent to the Ok callback. */
333 /* This contains the encapsulation callback to invoke upon */
334 /* the data within the dialog being changed. */
336 apply_data = (ChangeDirApply *) XtMalloc (sizeof (ChangeDirApply));
337 apply_data->callback = callback;
338 apply_data->client_data = client_data;
339 apply_data->change_dir_rec = (XtPointer) change_dir_rec;
340 change_dir_rec->apply_data = apply_data;
342 /* Add the callbacks for list item insertion and help. */
344 XtAddCallback (selection_box, XmNokCallback, (XtCallbackProc) OkCallback,
345 (XtPointer) apply_data);
351 /************************************************************************
355 ************************************************************************/
359 ChangeDirRec *change_dir_rec,
360 XtCallbackProc callback,
361 XtPointer client_data )
364 Atom delete_window_atom;
367 XmSelectionBoxGetChild (change_dir_rec->change_dir,
368 XmDIALOG_CANCEL_BUTTON);
370 XtAddCallback (close_widget, XmNactivateCallback, callback, client_data);
372 delete_window_atom = XmInternAtom (XtDisplay(change_dir_rec->shell),
373 "WM_DELETE_WINDOW", True);
374 XmRemoveWMProtocols( change_dir_rec->shell, &delete_window_atom, 1 );
375 XmAddWMProtocolCallback( change_dir_rec->shell, delete_window_atom, callback,
376 (XtPointer)client_data );
382 /************************************************************************
386 ************************************************************************/
390 ChangeDirRec *change_dir_rec )
392 XtDestroyWidget (change_dir_rec->change_dir);
393 XtFree ((char *) change_dir_rec->apply_data);
394 XtFree ((char *) change_dir_rec);
400 /************************************************************************
404 ************************************************************************/
408 ChangeDirRec *change_dir_rec )
410 ChangeDirData * change_dir_data;
413 XmStringTable history_list;
414 XmString string_path;
417 /* Allocate and initialize the change dir dialog data. */
419 change_dir_data = (ChangeDirData *) XtMalloc (sizeof (ChangeDirData));
421 change_dir_data->displayed = True;
422 change_dir_data->host_name = NULL;
423 change_dir_data->file_mgr_rec = NULL;
426 XtSetArg (args[n], XmNx, &change_dir_data->x); n++;
427 XtSetArg (args[n], XmNy, &change_dir_data->y); n++;
428 XtSetArg (args[n], XmNwidth, &change_dir_data->width); n++;
429 XtSetArg (args[n], XmNheight, &change_dir_data->height); n++;
430 XtSetArg (args[n], XmNlistItemCount, &change_dir_data->list_count); n++;
431 XtSetArg (args[n], XmNlistVisibleItemCount, &change_dir_data->visible_count); n++;
432 XtSetArg (args[n], XmNtextString, &string_path); n++;
433 XtSetArg (args[n], XmNlistItems, &history_list); n++;
434 XtGetValues (change_dir_rec->change_dir, args, n);
437 /* Extract and make local copies of the XmString data. */
439 change_dir_data->history_list = (XmStringTable)
440 XtMalloc (sizeof(XmStringTable) * (change_dir_data->list_count + 1));
442 for (n = 0; n < change_dir_data->list_count; n++)
443 change_dir_data->history_list[n] = XmStringCopy (history_list[n]);
444 change_dir_data->history_list[n] = NULL;
446 if(change_dir_data->string_path)
447 XmStringFree (change_dir_data->string_path);
448 change_dir_data->string_path = XmStringCopy (string_path);
450 return ((XtPointer) change_dir_data);
456 /************************************************************************
460 ************************************************************************/
463 GetDefaultValues( void )
465 ChangeDirData * change_dir_data;
468 /* Allocate and initialize the default change dir dialog data. */
470 change_dir_data = (ChangeDirData *) XtMalloc (sizeof (ChangeDirData));
472 change_dir_data->displayed = False;
473 change_dir_data->x = 0;
474 change_dir_data->y = 0;
475 change_dir_data->height = 0;
476 change_dir_data->width = 0;
477 change_dir_data->string_path = NULL;
480 This will cause users_home_dir to be displayed in
481 Application Manager go to dialog.
484 change_dir_data->string_path =
485 XmStringCreateLocalized(users_home_dir, XmFONTLIST_DEFAULT_TAG);
487 change_dir_data->string_path = NULL;
489 change_dir_data->history_list = NULL;
490 change_dir_data->visible_count = 8;
491 change_dir_data->list_count = 0;
492 change_dir_data->host_name = NULL;
493 change_dir_data->file_mgr_rec = NULL;
496 return ((XtPointer) change_dir_data);
502 /************************************************************************
506 ************************************************************************/
510 XrmDatabase data_base,
513 ChangeDirData * change_dir_data;
514 XmStringTable new_table;
518 /* Allocate and get the resources for change dir dialog data. */
520 change_dir_data = (ChangeDirData *) XtMalloc (sizeof (ChangeDirData));
522 _DtDialogGetResources (data_base, name_list,
523 CHANGEDIRECTORY, (char *) change_dir_data,
524 resources, changeDirClass->resource_count);
526 change_dir_data->host_name = NULL;
529 /* If the history list is Non-Null, realloc the pointer array */
530 /* one element larger and NULL out the new last element */
532 if (change_dir_data->list_count != 0)
534 new_table = (XmStringTable) XtMalloc (sizeof (XmStringTable) *
535 (change_dir_data->list_count + 1));
537 for (i = 0; i < change_dir_data->list_count; i++)
538 new_table[i] = change_dir_data->history_list[i];
540 new_table[change_dir_data->list_count] = NULL;
543 THIS WILL BE A MEMORY HOLE WHEN MOTIF FIXES THE XMSTRINGTABLE
544 CONVERTER. EITHER REALLOC THE RETURNED TABLE OR COPY AND FREE IT.
546 change_dir_data->history_list = new_table;
549 return ((XtPointer) change_dir_data);
555 /************************************************************************
559 ************************************************************************/
563 ChangeDirRec *change_dir_rec,
564 ChangeDirData *change_dir_data )
567 char *tmp_str, *host_name;
568 XmString host_string;
569 DialogData * dialog_data;
570 FileMgrData * file_mgr_data;
572 dialog_data = _DtGetInstanceData (change_dir_data->file_mgr_rec);
573 file_mgr_data = (FileMgrData *) dialog_data->data;
575 if(change_dir_data->string_path)
576 XmStringFree (change_dir_data->string_path);
579 && file_mgr_data->toolbox == False )
580 change_dir_data->string_path =
581 XmStringCreateLocalized( users_home_dir);
582 else if( file_mgr_data->restricted_directory )
583 change_dir_data->string_path =
584 XmStringCreateLocalized( file_mgr_data->current_directory);
586 change_dir_data->string_path = NULL;
588 XtSetArg (args[0], XmNlistItemCount, change_dir_data->list_count);
589 XtSetArg (args[1], XmNlistVisibleItemCount, change_dir_data->visible_count);
590 XtSetArg (args[2], XmNtextString, change_dir_data->string_path);
591 XtSetArg (args[3], XmNlistItems, change_dir_data->history_list);
593 XtSetValues (change_dir_rec->change_dir, args, 4);
595 if( change_dir_data->string_path )
599 text = XmSelectionBoxGetChild(change_dir_rec->change_dir, XmDIALOG_TEXT);
600 XtAddCallback (text, XmNmodifyVerifyCallback,
601 (XtCallbackProc)TextChange, (XtPointer)file_mgr_data );
602 XtAddCallback (text, XmNmotionVerifyCallback,
603 (XtCallbackProc)TextChange, (XtPointer)file_mgr_data );
604 XtAddCallback (text, XmNvalueChangedCallback,
605 (XtCallbackProc)TextChange, (XtPointer)file_mgr_data );
608 tmp_str = GETMESSAGE(2, 16, "System Name: ");
609 host_name = XtMalloc(strlen(tmp_str) + strlen(change_dir_data->host_name)+1);
610 sprintf(host_name, "%s%s", tmp_str, change_dir_data->host_name);
611 host_string = XmStringCreateLocalized (host_name);
612 XtSetArg (args[0], XmNlabelString, host_string);
613 XtSetValues (XmSelectionBoxGetChild (change_dir_rec->change_dir,
614 XmDIALOG_LIST_LABEL), args, 1);
617 XmStringFree(host_string);
623 /************************************************************************
625 * WriteResourceValues
627 ************************************************************************/
635 ChangeDirData * change_dir_data = (ChangeDirData *) values->data;
636 ChangeDirRec * change_dir_rec;
638 /* If the dialog is currently displayed, update the geometry */
639 /* fields to their current values. */
641 if (change_dir_data->displayed == True)
643 _DtGenericUpdateWindowPosition(values);
644 change_dir_rec = (ChangeDirRec *) _DtGetDialogInstance (values);
647 _DtDialogPutResources (fd, name_list, CHANGEDIRECTORY, values->data,
648 resources, changeDirClass->resource_count);
654 /************************************************************************
658 ************************************************************************/
662 ChangeDirData *change_dir_data )
666 for (i = 0; i < change_dir_data->list_count; i++)
667 XmStringFree (change_dir_data->history_list[i]);
668 XtFree ((char *) change_dir_data->history_list);
670 XmStringFree (change_dir_data->string_path);
671 XtFree ((char *) change_dir_data->host_name);
673 XtFree ((char *) change_dir_data);
677 /************************************************************************
678 ************************************************************************
680 * Internal functions used by the ChangeDir dialog
682 ************************************************************************
683 ************************************************************************/
685 /*****************************************************************************
690 This function is used both by the ChangeDir dialog, and the FileMgr
691 dialog's text field; it attempts to verify the incoming string, and
692 then change to the indicated directory.
694 *****************************************************************************/
697 Boolean isFromDialog,
698 char * incoming_string,
699 FileMgrData * file_mgr_data,
700 FileMgrRec * file_mgr_rec,
701 ChangeDirData * change_dir_data,
702 Widget selection_box,
703 ChangeDirApply * apply_data,
704 XmSelectionBoxCallbackStruct * callback_data,
707 char * new_directory;
710 struct stat stat_buf;
712 XmString path_string;
713 XmString host_string;
720 char *restricted = NULL;
722 new_directory = XtNewString(incoming_string);
724 if ((new_directory) && (strcmp(new_directory, "") != 0))
726 _DtPathFromInput(new_directory, file_mgr_data->current_directory,
731 tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
732 title = XtNewString(tmpStr);
733 tmpStr = GETMESSAGE(2,18, "Destination Folder name is missing.\nType in a folder name or select a folder from the list.");
734 msg = XtNewString(tmpStr);
737 _DtMessage(selection_box, title, msg, NULL, HelpRequestCB);
739 _DtMessage(file_mgr_rec->current_directory_text, title, msg, NULL,
748 /* Don't allow access to the desktop directory */
751 char *ttpath = (char *) GetTTPath(path);
752 char *dtpath = (char *) GetTTPath(desktop_dir);
753 if( ttpath && strcmp(ttpath, dtpath) == 0)
761 /* Stat the file and see if it is a valid directory. (If the current view
762 is restricted, make sure that the new directory doesn't violate the
763 directory restrictions. If so, refilter the displayed file set to show
764 the files in this directory.
767 &&(stat(path, &stat_buf) == 0)
768 &&((stat_buf.st_mode & S_IFMT) == S_IFDIR)
769 &&(CheckRestrictedDir(file_mgr_rec, file_mgr_data, &path, False) == 0))
771 /* Check for read/xcute permission */
772 if (CheckAccess(path, R_OK | X_OK))
774 tmpStr = GETMESSAGE(9, 6, "Action Error");
775 title = XtNewString(tmpStr);
776 msg = (char *)XtMalloc(strlen(GETMESSAGE(30, 1, "Cannot read from %s"))
777 + strlen(new_directory)
779 sprintf(msg, GETMESSAGE(30, 1, "Cannot read from %s"), new_directory);
782 _DtMessage(selection_box, title, msg, NULL, HelpRequestCB);
784 _DtMessage(file_mgr_rec->current_directory_text, title,
785 msg, NULL, HelpRequestCB);
795 /* Adjust the selection box elements to add the text item
798 list = XmSelectionBoxGetChild(selection_box, XmDIALOG_LIST);
800 path_string = XmStringCreateLocalized(path);
802 if (XmListItemExists(list, path_string))
803 XmListDeselectAllItems(list);
805 XmListAddItem(list, path_string, 0);
807 XmListSelectItem(list, path_string, False);
808 XmListSetBottomPos(list, 0);
810 XmStringFree(path_string);
813 /* Clear out the text string */
819 XmStringCreateLocalized(users_home_dir));
821 XtSetArg(args[0], XmNtextString, NULL);
822 XtSetValues(selection_box, args, 1);
826 if(!file_mgr_data || !file_mgr_data->restricted_directory)
827 XmTextFieldSetString(file_mgr_rec->current_directory_text,
833 /* Update the change directory host name field
834 and the host name indicator widget in the dialog.
836 XtFree((char *) change_dir_data->host_name);
837 change_dir_data->host_name = XtNewString(host);
841 tmpStr = GETMESSAGE(2, 16, "System Name: ");
842 message_buf = XtMalloc(strlen(tmpStr) +
843 strlen(change_dir_data->host_name) + 1);
844 sprintf(message_buf, "%s%s", tmpStr, change_dir_data->host_name);
846 XmStringCreateLocalized(message_buf);
847 XtSetArg(args[0], XmNlabelString, host_string);
848 XtSetValues(XmSelectionBoxGetChild(selection_box,XmDIALOG_LIST_LABEL),
851 XmStringFree(host_string);
853 XmUpdateDisplay (selection_box);
856 /* Call the encapsulation change data callback */
858 (*callback)(selection_box, apply_data->client_data, path);
860 (*callback)(file_mgr_data, path);
865 tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
866 title = XtNewString(tmpStr);
869 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.");
873 tmpStr = GETMESSAGE(2,19,"The following folder name is invalid.\n\n%s");
876 message_buf = XtMalloc(strlen(tmpStr) + strlen(path) + 1);
877 sprintf(message_buf, tmpStr, path);
881 message_buf = XtMalloc(strlen(tmpStr) + strlen(new_directory) + 1);
882 sprintf(message_buf, tmpStr, new_directory);
886 _DtMessage(selection_box, title, message_buf, NULL, HelpRequestCB);
888 _DtMessage(file_mgr_rec->current_directory_text, title, message_buf,
889 NULL, HelpRequestCB);
897 XtFree((char *) path);
898 XtFree((char *) host);
899 XtFree((char *) new_directory);
906 /************************************************************************
909 * This is a callback function called when the Ok button (Apply)
910 * is pressed. It adds the string contained within the call data
911 * into the selection boxes list.
913 ************************************************************************/
917 Widget selection_box,
918 ChangeDirApply *apply_data,
919 XmSelectionBoxCallbackStruct *callback_data )
921 DialogData * dialog_data;
922 ChangeDirData * change_dir_data;
923 FileMgrRec * file_mgr_rec;
924 FileMgrData * file_mgr_data;
928 char message_buf[MAX_PATH + 100];
934 /* Get the change dir data record */
936 dialog_data = _DtGetInstanceData (apply_data->change_dir_rec);
937 change_dir_data = (ChangeDirData *) dialog_data->data;
939 file_mgr_rec = (FileMgrRec *) change_dir_data->file_mgr_rec;
940 dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
941 file_mgr_data = (FileMgrData *) dialog_data->data;
943 value = (char *) _XmStringUngenerate((XmString)callback_data->value,
944 XmFONTLIST_DEFAULT_TAG,
945 XmCHARSET_TEXT, XmCHARSET_TEXT);
949 tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
950 title = XtNewString(tmpStr);
951 tmpStr = (char *) GETMESSAGE(2, 11, "Cannot get the new folder name.");
952 msg = XtNewString(tmpStr);
954 _DtMessage(selection_box, title, message_buf, NULL, HelpRequestCB);
961 strValue = XtNewString(value);
962 if(file_mgr_data->toolbox && strValue[0] != '/')
963 result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue, True);
965 result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue,False);
967 /* Process the string representing a directory to verify */
968 /* that it is a valid path. */
971 TryToChangeDir(True, (char *)strValue, file_mgr_data,
972 file_mgr_rec, change_dir_data, selection_box, apply_data,
973 callback_data, apply_data->callback);
981 /************************************************************************
983 * CheckRestrictedDir:
984 * Make sure we stay inside a restricted directory
986 ************************************************************************/
990 FileMgrRec * file_mgr_rec,
991 FileMgrData * file_mgr_data,
993 Boolean relative_name)
995 char *tmpStr, directory[MAXPATHLEN];
997 char *tmpBuffer, *title, *msg;
999 /* If not in restricte mode, everything is ok. */
1000 if (file_mgr_data->restricted_directory == NULL && !restrictMode)
1003 /* get real file name */
1006 tmpStr = (char *)XtMalloc(strlen(*value) +
1007 strlen(file_mgr_data->restricted_directory) + 3);
1008 strcpy(tmpStr, file_mgr_data->restricted_directory);
1009 if(*value[0] != '/')
1010 strcat(tmpStr, "/");
1011 strcat(tmpStr, *value);
1015 *value = (char *) DtEliminateDots (*value);
1018 && file_mgr_data->toolbox == False )
1020 if( strcmp( users_home_dir, "/" ) == 0 )
1022 strcpy( directory, users_home_dir );
1025 strcpy( directory, file_mgr_data->restricted_directory );
1027 len = strlen(directory);
1029 if( len > 1 && directory[len-1] == '/' )
1031 directory[len - 1] = 0x0;
1035 /* check if value is inside the restricted subdir */
1036 len = strlen(directory);
1037 if (strncmp(*value, directory, len) != 0 ||
1038 (*value)[len] != '/' && (*value)[len] != '\0')
1040 tmpBuffer = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
1041 title = XtNewString(tmpBuffer);
1043 tmpBuffer = GETMESSAGE(2,8, "You cannot switch to this folder. You are\nallowed to view only folders beneath your\ncurrent folder. You cannot specify an absolute\npath to the new folder.");
1045 tmpBuffer = GETMESSAGE(2,9, "This view is in restricted mode. You cannot go\nto the specified folder because it is not in the\nrelative path of the restricted folder.\n");
1046 msg = XtNewString(tmpBuffer);
1048 _DtMessage(file_mgr_rec->current_directory_text, title, msg,
1049 NULL, HelpRequestCB);
1060 /************************************************************************
1063 * This is the activate callback for the FileMgr text field provided
1064 * for quickly changing the current directory being viewed.
1066 ************************************************************************/
1071 XtPointer client_data,
1072 XmAnyCallbackStruct * callback_data )
1074 DialogData * dialog_data;
1075 ChangeDirData * change_dir_data;
1076 ChangeDirRec * change_dir_rec;
1077 FileMgrRec * file_mgr_rec;
1078 FileMgrData * file_mgr_data;
1080 Widget selection_box;
1085 /* Get the change dir data record */
1087 file_mgr_rec = (FileMgrRec *) client_data;
1088 dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
1089 file_mgr_data = (FileMgrData *) dialog_data->data;
1090 change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
1091 change_dir_rec =(ChangeDirRec *)_DtGetDialogInstance(file_mgr_data->change_dir);
1094 selection_box = change_dir_rec->change_dir;
1096 selection_box = NULL;
1098 value = (char *)XmTextFieldGetString(text_field);
1100 /* check if user attempts to go outside restricted directory */
1101 rc = CheckRestrictedDir (file_mgr_rec, file_mgr_data, &value, True);
1104 This code will de-activate the text widget.
1105 HCI requests that if the switch is not successful, don't de-activate it
1106 so user has a change to go back and correct it without having to pop it
1109 XmProcessTraversal(file_mgr_rec->file_window, XmTRAVERSE_CURRENT);
1110 XtSetArg (args[0], XmNallowShellResize, False);
1111 XtSetValues (file_mgr_rec->shell, args, 1);
1112 XtUnmanageChild(file_mgr_rec->current_directory_text);
1113 XtSetArg (args[0], XmNallowShellResize, True);
1114 XtSetValues (file_mgr_rec->shell, args, 1);
1115 file_mgr_data->fast_cd_enabled = False;
1118 /* Process the string representing a directory to verify */
1119 /* that it is a valid path. */
1122 if( TryToChangeDir(False, value, file_mgr_data, file_mgr_rec,
1123 change_dir_data, selection_box, NULL, NULL,
1125 /* de-activate the text widget */
1126 UnpostTextPath( file_mgr_data );
1133 /************************************************************************
1136 * This is the drop callback for the change-view icon provided
1137 * for quickly changing the current directory being viewed.
1139 ************************************************************************/
1144 XtPointer client_data,
1145 XtPointer call_data)
1147 DtDndDropCallbackStruct *fileList = (DtDndDropCallbackStruct *)call_data;
1148 FileMgrRec *file_mgr_rec;
1149 DialogData * dialog_data;
1150 ChangeDirData * change_dir_data;
1151 ChangeDirRec * change_dir_rec;
1152 FileMgrData * file_mgr_data;
1153 Widget selection_box;
1154 char *full_path_name;
1157 numFiles = fileList->dropData->numItems;
1159 /* if multiple selection, ignore all but the last one */
1161 if (numFiles > 0 && fileList->reason == DtCR_DND_DROP_ANIMATE)
1163 file_mgr_rec = (FileMgrRec *) client_data;
1164 dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
1165 file_mgr_data = (FileMgrData *) dialog_data->data;
1167 full_path_name = XtNewString(fileList->dropData->data.files[numFiles-1]);
1169 if (CheckRestrictedDir(file_mgr_rec, file_mgr_data,
1170 &full_path_name, False) == 0)
1172 change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
1174 (ChangeDirRec *)_DtGetDialogInstance(file_mgr_data->change_dir);
1176 selection_box = change_dir_rec->change_dir;
1178 selection_box = NULL;
1180 TryToChangeDir(False, full_path_name, file_mgr_data, file_mgr_rec,
1181 change_dir_data, selection_box, NULL, NULL,
1184 XtFree(full_path_name);
1187 fileList->status = DtDND_FAILURE;
1193 FileMgrData * file_mgr_data,
1196 ChangeDirData * change_dir_data;
1199 XmString xm_dir_name;
1201 /* Clear out any selected portion of the old CWD string */
1202 if (file_mgr_data->cd_select != NULL)
1204 XtFree(file_mgr_data->cd_select);
1205 file_mgr_data->cd_select = NULL;
1208 /* Update the internal copy of the dialog history list */
1209 if (file_mgr_data->change_dir)
1211 change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
1212 xm_dir_name = XmStringCreateLocalized(dir_name);
1214 /* Add the directory only if not already in the list */
1215 for (i = 0, found = False; i < change_dir_data->list_count; i++)
1217 if (XmStringCompare(xm_dir_name, change_dir_data->history_list[i]))
1220 XmStringFree(xm_dir_name);
1227 change_dir_data->list_count++;
1228 change_dir_data->history_list = (XmStringTable)
1229 XtRealloc((char *)change_dir_data->history_list,
1230 sizeof(XmStringTable) * (change_dir_data->list_count + 1));
1231 change_dir_data->history_list[change_dir_data->list_count - 1] =
1233 change_dir_data->history_list[change_dir_data->list_count] = NULL;
1236 /* Update view to display the new directory */
1237 ShowNewDirectory(file_mgr_data, change_dir_data->host_name, dir_name);
1243 * Class function for forcing the focus to the text field, each time
1244 * the Change Dir dialog is posted.
1249 ChangeDirRec *change_dir_rec,
1250 ChangeDirData *change_dir_data )
1254 /* Force the focus to the text field */
1255 text = XmSelectionBoxGetChild (change_dir_rec->change_dir, XmDIALOG_TEXT);
1256 XmProcessTraversal(text, XmTRAVERSE_CURRENT);
1260 /***************************************************************************
1262 * TextChange() - callback from editable text widgets when something is
1263 * typed in the text widget. Only used when in restricted mode.
1264 * Used to make sure the users are not going out of their
1265 * "restricted" space.
1267 ****************************************************************************/
1272 XtPointer client_data,
1273 XmTextVerifyCallbackStruct * callback_data )
1275 char *homeDir, *homeDirBackup;
1278 if (callback_data->reason == XmCR_MODIFYING_TEXT_VALUE ||
1279 callback_data->reason == XmCR_MOVING_INSERT_CURSOR )
1281 FileMgrData * file_mgr_data;
1283 file_mgr_data = (FileMgrData *) client_data;
1285 selection = XmTextFieldGetSelection(text);
1287 /* get whats in the text widget */
1288 homeDir = homeDirBackup = XmTextFieldGetString(text);
1290 if(selection != NULL)
1292 if(callback_data->event == NULL)
1293 XmTextFieldClearSelection(text, CurrentTime);
1295 XmTextFieldClearSelection(text, callback_data->event->xkey.time);
1296 callback_data->doit = False;
1298 else if(callback_data->reason == XmCR_MODIFYING_TEXT_VALUE)
1300 /* see if the user is trying to back over the 'restricted'
1301 * text, in this case users_home_dir
1303 if( strcmp( homeDir, "" ) != 0
1304 && strcmp( homeDir, file_mgr_data->restricted_directory ) <= 0 )
1306 if( callback_data->text->length != 0 )
1308 if( strncmp( file_mgr_data->restricted_directory,
1309 callback_data->text->ptr,
1310 strlen(file_mgr_data->restricted_directory)) != 0)
1312 callback_data->doit = True;
1317 callback_data->doit = False;
1325 maxlength = strlen( file_mgr_data->restricted_directory );
1327 if(callback_data->newInsert < maxlength)
1329 if(callback_data->event == NULL)
1330 _XmTextFieldSetDestination((Widget)text,
1331 (Position)callback_data->currInsert, CurrentTime);
1334 _XmTextFieldSetDestination((Widget)text,
1335 (Position)callback_data->currInsert,
1336 callback_data->event->xkey.time);
1337 callback_data->doit = False;
1342 XtFree(homeDirBackup);
1348 ChangeDirectoryToParent(
1349 FileMgrRec * file_mgr_rec,
1352 DialogData * dialog_data;
1353 ChangeDirData * change_dir_data;
1354 ChangeDirRec * change_dir_rec;
1355 FileMgrData * file_mgr_data;
1356 Widget selection_box;
1360 /* Get the change dir data record */
1362 dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
1363 file_mgr_data = (FileMgrData *) dialog_data->data;
1364 change_dir_data = (ChangeDirData *) file_mgr_data->change_dir->data;
1365 change_dir_rec =(ChangeDirRec *)_DtGetDialogInstance(file_mgr_data->change_dir);
1368 selection_box = change_dir_rec->change_dir;
1370 selection_box = NULL;
1372 /* check if user attempts to go outside restricted directory */
1373 rc = CheckRestrictedDir (file_mgr_rec, file_mgr_data, &directory, True);
1375 /* Process the string representing a directory to verify */
1376 /* that it is a valid path. */
1379 TryToChangeDir(False, directory, file_mgr_data, file_mgr_rec,
1380 change_dir_data, selection_box, NULL, NULL,