void TrashHelpRequestCB( Widget w, XtPointer clientData, XtPointer callData ) { Arg args[5]; char *vol; char *locId; /* Refresh the display */ XmUpdateDisplay(w); /* printf ("topic = %s\n", clientData); */ /* Check for item help */ if (strcmp(clientData, HELP_HELP_MODE_STR) == 0) { if( ! ProcessItemHelp(trashShell) ) { char *tmpStr, *title, *msg; tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE); title = XtNewString(tmpStr); tmpStr = GetSharedMessage( ITEM_HELP_ERROR ), msg = XtNewString(tmpStr); _DtMessage(trashShell, title, msg, NULL, HelpRequestCB); XtFree(title); XtFree(msg); } return; } /* Special check for 'Using Help'; required different volume */ locId = (char *)clientData; if ((w == *usingHelpTrash) && (strcmp(locId, HELP_HOME_TOPIC) == 0)) vol = "Help4Help"; else vol = DTFILE_HELP_NAME; if (primaryTrashHelpDialog) { ReusePrimaryHelpWindow(primaryTrashHelpDialog, clientData, vol, NULL, NULL, DtHELP_TYPE_TOPIC); } else { /* Create the main help window for this view */ ShowTrashHelpDialog(trashShell, MAIN_HELP_DIALOG, NULL, clientData, vol); } }
void HelpRequestCB( Widget w, XtPointer clientData, XtPointer callData ) { XtPointer recordStruct; DialogData * dialogData; Arg args[8]; int n; String topicTitle = NULL; int helpType; Boolean freeClientData; String fileType; String strVal; char *vol; char *locId; /* Refresh the display */ /* printf ("in HelpRequestCB: clientdata=\"%s\"\n",(char *)clientData); */ XmUpdateDisplay(w); if (recordStruct = LocateRecordStructure(w)) { if (dialogData = _DtGetInstanceData(recordStruct)) { if (IsMainWinDialog(dialogData)) { FileMgrData * fileMgrData = (FileMgrData *)dialogData->data; FileMgrRec * fileMgrRec = (FileMgrRec *)recordStruct; /* Check for item help */ if (clientData && strcmp(clientData, HELP_HELP_MODE_STR) == 0) { if( !ProcessItemHelp( fileMgrRec->shell ) ) { char *tmpStr, *title, *msg; tmpStr = GetSharedMessage(ITEM_HELP_ERROR_TITLE); title = XtNewString(tmpStr); if( fileMgrData->toolbox ) { tmpStr = GetSharedMessage( AMITEM_HELP_ERROR ); msg = XtNewString(tmpStr); } else { tmpStr = GetSharedMessage( ITEM_HELP_ERROR ), msg = XtNewString(tmpStr); } _DtMessage(fileMgrRec->shell, title, msg, NULL, HelpRequestCB); XtFree(title); XtFree(msg); } return; } /* Item help comes in with a NULL client data */ if (clientData) { fileType = NULL; topicTitle = NULL; helpType = DtHELP_TYPE_TOPIC; freeClientData = False; } else { if(fileMgrData->selected_file_count > 1) { Widget warn; String s; XmString xmstr; n=0; XtSetArg(args[n], XmNokLabelString, okXmString); n++; XtSetArg(args[n], XmNcancelLabelString, cancelXmString); n++; s = GETMESSAGE(29,10, "Help is not available for multiple selected objects."); xmstr = XmStringCreateLocalized(s); XtSetArg(args[n], XmNmessageString, xmstr); n++; XtSetArg(args[n], XmNtitle, (GETMESSAGE(29,1, "File Manager Help"))); n++; warn = XmCreateWarningDialog(fileMgrRec->shell, "warn_msg", args, n); XtUnmanageChild(XmMessageBoxGetChild(warn,XmDIALOG_HELP_BUTTON)); XtManageChild(warn); XmStringFree(xmstr); return; } /* Action/Filetype Help */ topicTitle = GetSharedMessage(ACTION_FT_HELP_TITLE); helpType = DtHELP_TYPE_DYNAMIC_STRING; fileType = NULL; /* Determine string, and set clientData accordingly */ if ((clientData = MapIconWidgetToFileType(w, fileMgrData)) == NULL) { /* Not a file icon; is it an action menu item? */ if (!IsMenuWidget(w, fileMgrRec, fileMgrData, &strVal, &fileType)) { if (! IsFilterIcon(w, fileMgrData, &strVal)) return; } clientData = (XtPointer)strVal; } freeClientData = True; } /* printf ("topic = %s\n", clientData); */ /* Special check for 'Using Help'; required different volume */ locId = (char *)clientData; if ((w == *usingHelp) && (strcmp(locId, HELP_HOME_TOPIC) == 0)) vol = "Help4Help"; else vol = fileMgrData->helpVol; if (fileMgrData->primaryHelpDialog) { ReusePrimaryHelpWindow( fileMgrData->primaryHelpDialog, clientData, vol, topicTitle, fileType, helpType); } else { /* Create the main help window for this view */ ShowHelpDialog(fileMgrRec->shell, (XtPointer)fileMgrRec, MAIN_HELP_DIALOG, NULL, clientData, vol, topicTitle, fileType, helpType); } if (freeClientData) { XtFree(fileType); XtFree(clientData); } } } } else if (clientData) { Widget mainHelpDialog=NULL; Arg args[10]; int i=0; XtSetArg(args[0],XmNuserData,&mainHelpDialog); XtGetValues(w,args,1); XtSetArg(args[i], DtNhelpType,(unsigned char) DtHELP_TYPE_TOPIC); i++; XtSetArg(args[i], DtNhelpVolume, DTFILE_HELP_NAME); i++; XtSetArg(args[i], DtNlocationId, clientData); i++; XtSetArg(args[i], XmNtitle, (GETMESSAGE(29,1, "File Manager Help")));i++; if(!mainHelpDialog || ( mainHelpDialog && !XtIsManaged(mainHelpDialog)) ) { mainHelpDialog = DtCreateHelpDialog(w, "mainHelpDialog", args, i); XtAddCallback(mainHelpDialog, DtNcloseCallback, closeCB_mainHelpDialog, (XtPointer)NULL); XtManageChild(mainHelpDialog); XtSetArg(args[0],XmNuserData,mainHelpDialog); XtSetValues(w,args,1); } else XtSetValues(mainHelpDialog, args, i); } }
static void OkCallback( Widget selection_box, ChangeDirApply *apply_data, XmSelectionBoxCallbackStruct *callback_data ) { DialogData * dialog_data; ChangeDirData * change_dir_data; FileMgrRec * file_mgr_rec; FileMgrData * file_mgr_data; char *strValue; char *value = NULL; int result; char message_buf[MAX_PATH + 100]; char * tmpStr; char * title; char * msg; /* Get the change dir data record */ dialog_data = _DtGetInstanceData (apply_data->change_dir_rec); change_dir_data = (ChangeDirData *) dialog_data->data; file_mgr_rec = (FileMgrRec *) change_dir_data->file_mgr_rec; dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec); file_mgr_data = (FileMgrData *) dialog_data->data; value = (char *) _XmStringUngenerate((XmString)callback_data->value, XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT); if ( value == NULL) { tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE); title = XtNewString(tmpStr); tmpStr = (char *) GETMESSAGE(2, 11, "Cannot get the new folder name."); msg = XtNewString(tmpStr); _DtMessage(selection_box, title, message_buf, NULL, HelpRequestCB); XtFree(title); XtFree(msg); return; } strValue = XtNewString(value); if(file_mgr_data->toolbox && strValue[0] != '/') result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue, True); else result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue,False); /* Process the string representing a directory to verify */ /* that it is a valid path. */ if (result == 0) { TryToChangeDir(True, (char *)strValue, file_mgr_data, file_mgr_rec, change_dir_data, selection_box, apply_data, callback_data, apply_data->callback); } XtFree(value); XtFree(strValue); }
static int CheckRestrictedDir ( FileMgrRec * file_mgr_rec, FileMgrData * file_mgr_data, char ** value, Boolean relative_name) { char *tmpStr, directory[MAXPATHLEN]; int len; char *tmpBuffer, *title, *msg; /* If not in restricte mode, everything is ok. */ if (file_mgr_data->restricted_directory == NULL && !restrictMode) return 0; /* get real file name */ if (relative_name) { tmpStr = (char *)XtMalloc(strlen(*value) + strlen(file_mgr_data->restricted_directory) + 3); strcpy(tmpStr, file_mgr_data->restricted_directory); if(*value[0] != '/') strcat(tmpStr, "/"); strcat(tmpStr, *value); XtFree(*value); *value = tmpStr; } *value = (char *) DtEliminateDots (*value); if( restrictMode && file_mgr_data->toolbox == False ) { if( strcmp( users_home_dir, "/" ) == 0 ) return 0; strcpy( directory, users_home_dir ); } else strcpy( directory, file_mgr_data->restricted_directory ); len = strlen(directory); if( len > 1 && directory[len-1] == '/' ) { directory[len - 1] = 0x0; --len; } /* check if value is inside the restricted subdir */ len = strlen(directory); if (strncmp(*value, directory, len) != 0 || (*value)[len] != '/' && (*value)[len] != '\0') { tmpBuffer = GetSharedMessage(CHANGE_DIR_ERROR_TITLE); title = XtNewString(tmpBuffer); if(restrictMode) 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."); else 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"); msg = XtNewString(tmpBuffer); _DtMessage(file_mgr_rec->current_directory_text, title, msg, NULL, HelpRequestCB); XtFree(title); XtFree(msg); return -1; } return 0; }
/***************************************************************************** TryToChangeDir INPUT: OUTPUT: DESCRIPTION: This function is used both by the ChangeDir dialog, and the FileMgr dialog's text field; it attempts to verify the incoming string, and then change to the indicated directory. NOTE: *****************************************************************************/ static Boolean TryToChangeDir( Boolean isFromDialog, char * incoming_string, FileMgrData * file_mgr_data, FileMgrRec * file_mgr_rec, ChangeDirData * change_dir_data, Widget selection_box, ChangeDirApply * apply_data, XmSelectionBoxCallbackStruct * callback_data, void (*callback)()) { char * new_directory; char * host; char * path; struct stat stat_buf; Widget list; XmString path_string; XmString host_string; Arg args[1]; char * message_buf; char * tmpStr; char * title; char * msg; Boolean rc = True; char *restricted = NULL; new_directory = XtNewString(incoming_string); if ((new_directory) && (strcmp(new_directory, "") != 0)) { _DtPathFromInput(new_directory, file_mgr_data->current_directory, &host, &path); } else { tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE); title = XtNewString(tmpStr); tmpStr = GETMESSAGE(2,18, "Destination Folder name is missing.\nType in a folder name or select a folder from the list."); msg = XtNewString(tmpStr); if(isFromDialog) _DtMessage(selection_box, title, msg, NULL, HelpRequestCB); else _DtMessage(file_mgr_rec->current_directory_text, title, msg, NULL, HelpRequestCB); XtFree(title); XtFree(msg); return False; } /* Don't allow access to the desktop directory */ if (path) { char *ttpath = (char *) GetTTPath(path); char *dtpath = (char *) GetTTPath(desktop_dir); if( ttpath && strcmp(ttpath, dtpath) == 0) { restricted = ttpath; XtFree(path); path = NULL; } } /* Stat the file and see if it is a valid directory. (If the current view is restricted, make sure that the new directory doesn't violate the directory restrictions. If so, refilter the displayed file set to show the files in this directory. */ if ((path) &&(stat(path, &stat_buf) == 0) &&((stat_buf.st_mode & S_IFMT) == S_IFDIR) &&(CheckRestrictedDir(file_mgr_rec, file_mgr_data, &path, False) == 0)) { /* Check for read/xcute permission */ if (CheckAccess(path, R_OK | X_OK)) { tmpStr = GETMESSAGE(9, 6, "Action Error"); title = XtNewString(tmpStr); msg = (char *)XtMalloc(strlen(GETMESSAGE(30, 1, "Cannot read from %s")) + strlen(new_directory) + 1); sprintf(msg, GETMESSAGE(30, 1, "Cannot read from %s"), new_directory); if(isFromDialog) _DtMessage(selection_box, title, msg, NULL, HelpRequestCB); else _DtMessage(file_mgr_rec->current_directory_text, title, msg, NULL, HelpRequestCB); XtFree(title); XtFree(msg); return; } else { if (selection_box) { /* Adjust the selection box elements to add the text item into the list. */ list = XmSelectionBoxGetChild(selection_box, XmDIALOG_LIST); path_string = XmStringCreateLocalized(path); if (XmListItemExists(list, path_string)) XmListDeselectAllItems(list); else XmListAddItem(list, path_string, 0); XmListSelectItem(list, path_string, False); XmListSetBottomPos(list, 0); XmStringFree(path_string); } /* Clear out the text string */ if (isFromDialog) { if(restrictMode) XtSetArg(args[0], XmNtextString, XmStringCreateLocalized(users_home_dir)); else XtSetArg(args[0], XmNtextString, NULL); XtSetValues(selection_box, args, 1); } else { if(!file_mgr_data || !file_mgr_data->restricted_directory) XmTextFieldSetString(file_mgr_rec->current_directory_text, incoming_string); } /* Update the change directory host name field and the host name indicator widget in the dialog. */ XtFree((char *) change_dir_data->host_name); change_dir_data->host_name = XtNewString(host); if (selection_box) { tmpStr = GETMESSAGE(2, 16, "System Name: "); message_buf = XtMalloc(strlen(tmpStr) + strlen(change_dir_data->host_name) + 1); sprintf(message_buf, "%s%s", tmpStr, change_dir_data->host_name); host_string = XmStringCreateLocalized(message_buf); XtSetArg(args[0], XmNlabelString, host_string); XtSetValues(XmSelectionBoxGetChild(selection_box,XmDIALOG_LIST_LABEL), args, 1); XtFree(message_buf); XmStringFree(host_string); XmUpdateDisplay (selection_box); } /* Call the encapsulation change data callback */ if (isFromDialog) (*callback)(selection_box, apply_data->client_data, path); else (*callback)(file_mgr_data, path); } } else { tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE); title = XtNewString(tmpStr); if(restricted) { 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."); path = restricted; } else tmpStr = GETMESSAGE(2,19,"The following folder name is invalid.\n\n%s"); if(path) { message_buf = XtMalloc(strlen(tmpStr) + strlen(path) + 1); sprintf(message_buf, tmpStr, path); } else { message_buf = XtMalloc(strlen(tmpStr) + strlen(new_directory) + 1); sprintf(message_buf, tmpStr, new_directory); } if (isFromDialog) _DtMessage(selection_box, title, message_buf, NULL, HelpRequestCB); else _DtMessage(file_mgr_rec->current_directory_text, title, message_buf, NULL, HelpRequestCB); XtFree(title); XtFree(message_buf); rc = False; } if (path) XtFree((char *) path); XtFree((char *) host); XtFree((char *) new_directory); return rc; }