Example #1
0
OSErr squeakFindImage(char* pathName)
{
    NavDialogCreationOptions    dialogOptions;
    NavObjectFilterUPP  filterProc =  NewNavObjectFilterUPP(findImageFilterProc);
    OSErr               anErr = noErr;
    NavDialogRef		navDialog;
	FSRef fileAsFSRef;
	
    //  Specify default options for dialog box
    anErr = NavGetDefaultDialogCreationOptions(&dialogOptions);
    if (anErr != noErr)
		return anErr;
		

	//  Adjust the options to fit our needs
	//  Set default location option
	dialogOptions.optionFlags |= kNavSelectDefaultLocation;
	dialogOptions.optionFlags  |= kNavAllFilesInPopup;
	dialogOptions.optionFlags  |= kNavSelectAllReadableItem;
	//  Clear preview option
	dialogOptions.optionFlags  ^= kNavAllowPreviews;
	
				
	// Call NavGetFile() with specified options and
	// declare our app-defined functions and type list
	NavCreateChooseFileDialog (
			&dialogOptions,
			nil,
			nil,
			nil,
			filterProc,
			nil,
			&navDialog);
	anErr = NavDialogRun (navDialog);
	if (anErr != noErr )
		return anErr;
		
	NavReplyRecord outReply;
	anErr = NavDialogGetReply (navDialog,&outReply);
	
    DisposeNavObjectFilterUPP(filterProc);
	NavDialogDispose(navDialog);	
		
	if (anErr != noErr)
		return anErr;
		
	if (!outReply.validRecord) {
		anErr = NavDisposeReply(&outReply);
		return -1;
	}

	// Get the file
	anErr = AEGetNthPtr(&(outReply.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	PathToFileViaFSRef(pathName,DOCUMENT_NAME_SIZE, &fileAsFSRef, gCurrentVMEncoding);

	//  Dispose of NavReplyRecord, resources, descriptors
	anErr = NavDisposeReply(&outReply);

    return 0;
}
Example #2
0
char *Sys_PathFromSaveMenu(void) {
    /* present a save file dialog and return the file's path */
    OSStatus res;
    NavDialogCreationOptions options;
    NavDialogRef dialog;
    NavReplyRecord reply;
    NavUserAction action;

    AEKeyword keyword;
    DescType actualType;
    Size actualSize;
    FSRef outputDir;
    CFURLRef cfUrl;
    CFStringRef cfString;
    char filename[PATH_MAX];
    int pathlen;

    NavGetDefaultDialogCreationOptions(&options);
    options.modality = kWindowModalityAppModal;
    /*options.modality = kWindowModalityWindowModal;
     *options.parentWindow = g_Window.window;*/
    options.saveFileName = CFStringCreateWithCString(NULL,
                                                     "Untitled.js",
                                                     kCFStringEncodingASCII);

    res = NavCreatePutFileDialog(&options, FOURC_TO_INT("JSON"), FOURC_TO_INT("PLAT"), NULL, NULL, &dialog);
    NavDialogRun(dialog);

    action = NavDialogGetUserAction(dialog);
    if (action == kNavUserActionNone || action == kNavUserActionCancel)
        return NULL;

    res = NavDialogGetReply(dialog, &reply);
    if (res != noErr)
        return NULL;

    res = AEGetNthPtr(&reply.selection, 1, typeFSRef, &keyword, &actualType, &outputDir,
                      sizeof(FSRef), &actualSize);

    cfUrl = CFURLCreateFromFSRef(kCFAllocatorDefault, &outputDir);
    cfString = NULL;

    if (cfUrl) {
        cfString = CFURLCopyFileSystemPath(cfUrl, kCFURLPOSIXPathStyle);
        CFRelease(cfUrl);
    }

    memset(g_SaveFileName, 0, PATH_MAX);
    CFStringGetCString(cfString, g_SaveFileName, PATH_MAX, kCFStringEncodingMacRoman);
    CFStringGetCString(reply.saveFileName, filename, PATH_MAX, kCFStringEncodingMacRoman);

    pathlen = strlen(g_SaveFileName);
    snprintf(g_SaveFileName+pathlen, PATH_MAX-pathlen, "/%s", filename);

    NavDialogDispose(dialog);

    return g_SaveFileName;
}
//---------------------------------------------------------------------
// Gets a file to open from the user. Caller must release the CFURLRef.
CFURLRef GetOpenFileFromUser(bool bFolder)
{
	NavDialogCreationOptions dialogOptions;
	NavDialogRef dialog;
	NavReplyRecord replyRecord;
	CFURLRef fileAsCFURLRef = NULL;
	FSRef fileAsFSRef;
	OSStatus status;
	
	// Get the standard set of defaults
	status = NavGetDefaultDialogCreationOptions(&dialogOptions);

	require_noerr( status, CantGetNavOptions );
	
	// Make the window app-wide modal
	dialogOptions.modality = kWindowModalityAppModal;
	dialogOptions.optionFlags != kNavAllowOpenPackages;
	
	// Create the dialog
	if( bFolder ){
		status = NavCreateChooseFolderDialog(&dialogOptions, NULL, NULL, NULL, &dialog);
	}else{
		status = NavCreateGetFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, NULL, &dialog);
	}
	
	require_noerr( status, CantCreateDialog );
	
	// Show it
	status = NavDialogRun(dialog);
	require_noerr( status, CantRunDialog );
	
	// Get the reply
	status = NavDialogGetReply(dialog, &replyRecord);
	require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );
	
	// If the user clicked "Cancel", just bail
	if ( status == userCanceledErr ) goto UserCanceled;
	
	// Get the file
	//TODO: for multiple files - 1 specifies index	
	status = AEGetNthPtr(&(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	require_noerr( status, CantExtractFSRef );
	
	// Convert it to a CFURL
	fileAsCFURLRef = CFURLCreateFromFSRef(NULL, &fileAsFSRef);
	
	// Cleanup
CantExtractFSRef:
UserCanceled:
	verify_noerr( NavDisposeReply(&replyRecord) );
CantGetReply:
CantRunDialog:
	NavDialogDispose(dialog);
CantCreateDialog:
CantGetNavOptions:
    return fileAsCFURLRef;
}
Example #4
0
static int manually_locate_product(const char *name, char *buf, size_t bufsize, const char *title)
{
    NavDialogCreationOptions dlgopt;
    NavDialogRef dlg;
    NavReplyRecord reply;
    NavUserAction action;
    AEKeyword keyword;
    AEDesc desc;
    FSRef fsref;
    OSStatus rc;
    int retval = 0;
    const char *promptfmt = _("We can't find your \"%s\" installation."
                            " Would you like to show us where it is?");
    char *promptstr = alloca(strlen(name) + strlen(promptfmt) + 1);

    if (promptstr == NULL)
    {
        log_fatal(_("Out of memory."));
        return(0);
    } /* if */
    sprintf(promptstr, promptfmt, name);

    if (!ui_prompt_yn(promptstr, title))
        return(0);

    NavGetDefaultDialogCreationOptions(&dlgopt);
    dlgopt.optionFlags |= kNavSupportPackages;
    dlgopt.optionFlags |= kNavAllowOpenPackages;
    dlgopt.optionFlags &= ~kNavAllowMultipleFiles;
    dlgopt.windowTitle = CFSTR("Please select the product's icon and click 'OK'.");  /* !!! FIXME! */
    dlgopt.actionButtonLabel = CFSTR("OK");
    NavCreateChooseFolderDialog(&dlgopt, NULL, NULL, NULL, &dlg);
    NavDialogRun(dlg);
    action = NavDialogGetUserAction(dlg);
    if (action != kNavUserActionCancel)
    {
        NavDialogGetReply(dlg, &reply);
        rc = AEGetNthDesc(&reply.selection, 1, typeFSRef, &keyword, &desc);
        if (rc != noErr)
            log_fatal("Unexpected error in AEGetNthDesc: %d", (int) rc);
        else
        {
            /* !!! FIXME: Check return values here! */
            BlockMoveData(*desc.dataHandle, &fsref, sizeof (fsref));
            FSRefMakePath(&fsref, BAD_CAST buf, bufsize - 1);
            buf[bufsize - 1] = '\0';
            AEDisposeDesc(&desc);
            retval = 1;
        } /* if */

        NavDisposeReply(&reply);
    } /* else */

    NavDialogDispose(dlg);

    return(retval);
} /* manually_locate_product */
OSStatus OpenFileDialog(
    OSType applicationSignature,
    short numTypes,
    OSType typeList[],
    NavDialogRef *outDialog )
{
    OSStatus theErr = noErr;
    if ( gOpenFileDialog == NULL )
    {
        NavDialogCreationOptions	dialogOptions;
        NavTypeListHandle			openList	= NULL;

        NavGetDefaultDialogCreationOptions( &dialogOptions );

        dialogOptions.modality = kWindowModalityNone;
        dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding());

        openList = (NavTypeListHandle)NewOpenHandle( applicationSignature, numTypes, typeList );

        theErr = NavCreateGetFileDialog( &dialogOptions, openList, GetPrivateEventUPP(), NULL, NULL, NULL, &gOpenFileDialog );

        if ( theErr == noErr )
        {
            theErr = NavDialogRun( gOpenFileDialog );
            if ( theErr != noErr )
            {
                NavDialogDispose( gOpenFileDialog );
                gOpenFileDialog = NULL;
            }
        }

        if (openList != NULL)
        {
            DisposeHandle((Handle)openList);
        }

        if ( dialogOptions.clientName != NULL )
        {
            CFRelease( dialogOptions.clientName );
        }
    }
    else
    {
        if ( NavDialogGetWindow( gOpenFileDialog ) != NULL )
        {
            SelectWindow( NavDialogGetWindow( gOpenFileDialog ));
        }
    }

    if ( outDialog != NULL )
    {
        *outDialog = gOpenFileDialog;
    }

    return NULL;
}
Example #6
0
pascal OSStatus OpenEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
	NavDialogRef fileDialog;
	NavDialogCreationOptions fo;
	NavGetDefaultDialogCreationOptions(&fo);
	fo.optionFlags=0;
	fo.parentWindow=win;
	NavCreateChooseFileDialog(&fo,NULL,NULL,NULL,NULL,NULL,&fileDialog);
// if someone wants to somehow get the file selector to filter like in the Windows example, that'd be nice ;)
	if (!NavDialogRun(fileDialog)) {
		NavReplyRecord r;
		if (!NavDialogGetReply(fileDialog,&r)) {
			AEKeyword k;
			FSRef fr;
			if (!AEGetNthPtr(&r.selection,1,typeFSRef,&k,NULL,&fr,sizeof(fr),NULL)) {
				char file[256];
				FSRefMakePath(&fr,(BYTE*)file,sizeof(file));
				BASS_StreamFree(chan); // free old stream before opening new
				if (!(chan=BASS_StreamCreateFile(FALSE,file,0,0,BASS_SAMPLE_LOOP|BASS_SAMPLE_FLOAT))) {
					SetControlTitleWithCFString(inUserData,CFSTR("click here to open a file..."));
					{
						ControlRef cref=GetControl(11);
						SetControlData(cref,kControlNoPart,kControlStaticTextTextTag,0,"");
						DrawOneControl(cref);
					}
					SetControl32BitMaximum(GetControl(12),0);
					Error("Can't play the file");
				} else {
					CFStringRef cs=CFStringCreateWithCString(0,file,kCFStringEncodingUTF8);
					SetControlTitleWithCFString(inUserData,cs);
					CFRelease(cs);
					{ // display the file type and length
						QWORD bytes=BASS_ChannelGetLength(chan,BASS_POS_BYTE);
						DWORD time=BASS_ChannelBytes2Seconds(chan,bytes);
						BASS_CHANNELINFO info;
						BASS_ChannelGetInfo(chan,&info);
						sprintf(file,"channel type = %x (%s)\nlength = %llu (%u:%02u)",
							info.ctype,GetCTypeString(info.ctype,info.plugin),bytes,time/60,time%60);
						{
							ControlRef cref=GetControl(11);
							SetControlData(cref,kControlNoPart,kControlStaticTextTextTag,strlen(file),file);
							DrawOneControl(cref);
						}
						SetControl32BitMaximum(GetControl(12),time); // update scroller range
					}
					BASS_ChannelPlay(chan,FALSE);
				}
			}
			NavDisposeReply(&r);
		}
	}
	NavDialogDispose(fileDialog);
    return noErr;
}
Example #7
0
// this code originates from the NavServices sample code in the CarbonLib SDK
OSStatus DoSaveAsPDF(WindowRef w, void *ourDataP)
{
    OSStatus 			err = noErr;
    static NavEventUPP	gNavEventProc = NULL;		// event proc for our Nav Dialogs 
    NavDialogCreationOptions	dialogOptions;
    if(!gNavEventProc){
        gNavEventProc = NewNavEventUPP(NavEventProc);
        if(!gNavEventProc)
            err = memFullErr;
    }

    if(!err && (( err = NavGetDefaultDialogCreationOptions( &dialogOptions )) == noErr ))
    {
	OurSaveDialogData *dialogDataP = NULL;
	CFStringRef	tempString;
	CopyWindowTitleAsCFString(w, &tempString);

        dialogOptions.saveFileName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, 
                                                kFileTypePDFCFStr, tempString);
	
	CFRelease(tempString);
	
	// make the dialog modal to our parent doc, AKA sheets
        dialogOptions.parentWindow = w;
	dialogOptions.modality = kWindowModalityWindowModal;
	
	dialogDataP = (OurSaveDialogData *)malloc(sizeof(OurSaveDialogData));
	if(dialogDataP){
	    dialogDataP->dialogRef = NULL;
	    dialogDataP->parentWindow = w;
	    dialogDataP->documentDataP = ourDataP;
	    err = NavCreatePutFileDialog(&dialogOptions, kFileTypePDF, kFileCreator,
						    gNavEventProc, dialogDataP,
						    &dialogDataP->dialogRef);
	    if (!err && dialogDataP->dialogRef != NULL)
	    {
		err = NavDialogRun( dialogDataP->dialogRef );
		if (err != noErr)
		{
		    NavDialogDispose( dialogDataP->dialogRef );
		    dialogDataP->dialogRef = NULL;
		    free(dialogDataP);
		}
	    }
	}else
	    err = memFullErr;
       	
     	if ( dialogOptions.saveFileName != NULL )
	    CFRelease( dialogOptions.saveFileName );

    }
    return err;
}
LLDirPicker::LLDirPicker() :
	mFileName(NULL),
	mLocked(false)
{
	reset();

	memset(&mNavOptions, 0, sizeof(mNavOptions));
	OSStatus	error = NavGetDefaultDialogCreationOptions(&mNavOptions);
	if (error == noErr)
	{
		mNavOptions.modality = kWindowModalityAppModal;
	}
}
static void DoAddTest(void)
	// Called in response to a click of the "Add" button. 
{
	OSStatus 					err;
	NavDialogCreationOptions	navOptions;
	NavDialogRef				navDialog;

	navDialog = NULL;
	
	if (gAddNavEventUPP == NULL) {
		gAddNavEventUPP = NewNavEventUPP(AddNavEvent);
		assert(gAddNavEventUPP != NULL);
	}

	// Create and run a Nav choose object dialog (which lets you 
	// choose a file, folder or volume).
	
	err = NavGetDefaultDialogCreationOptions(&navOptions);
	if (err == noErr) {
		navOptions.optionFlags  |= kNavSupportPackages;
		navOptions.modality      = kWindowModalityWindowModal;
		navOptions.parentWindow  = gMainWindow;
		
		err = NavCreateChooseObjectDialog(
			&navOptions,					// inOptions
			gAddNavEventUPP,
			NULL,							// inPreviewProc
			NULL,							// inFilterProc
			NULL,							// inClientData
			&navDialog
		);
	}
	if (err == noErr) {
		err = NavDialogRun(navDialog);
		
		// The process of adding the item continues in AddNavEvent 
		// when the user has chosen an item to add.
	}

	// Clean up.

	// Dispose the Nav dialog if we didn't manage to start it running.
	
	if (err != noErr) {
		if (navDialog != NULL) {
			NavDialogDispose(navDialog);
		}
	}

	DisplayError(err);
}
OSStatus DoOpenDocument(void)
{
    OSStatus 	err = noErr;
    NavDialogCreationOptions	dialogOptions;
    OurDialogData *dialogDataP = NULL;
    static NavEventUPP	gNavEventProc = NULL;		// event proc for our Nav Dialogs 
    if(!gNavEventProc){
        gNavEventProc = NewNavEventUPP(NavEventProc);
        if(!gNavEventProc)
            err = memFullErr;
    }

    // while our open dialog is up we'll disable our Open command, else
    // we might end up with more than one open dialog. Yuk
    DisableMenuCommand(NULL, kHICommandOpen);

    dialogDataP = (OurDialogData *)calloc(1, sizeof(OurDialogData));
    if(!dialogDataP)
	err = memFullErr;
	
    if (!err && ( err = NavGetDefaultDialogCreationOptions( &dialogOptions )) == noErr )
	{
		dialogOptions.preferenceKey = kOpenPrefKey;
		dialogOptions.modality = kWindowModalityAppModal;	// make it modal
		
		if ((err = NavCreateGetFileDialog( 	&dialogOptions,
							NULL,		   //openListH,
							gNavEventProc,
							NULL,		// no custom previews
							NULL,		// filter proc is NULL
							dialogDataP,
							&dialogDataP->dialogRef )) == noErr)
		{
			if (( err = NavDialogRun( dialogDataP->dialogRef )) != noErr){
				if ( dialogDataP->dialogRef != NULL ){
					NavDialogDispose( dialogDataP->dialogRef );
					dialogDataP->dialogRef = NULL;
					free(dialogDataP);
				}
			}
		}
		
		if(err == userCanceledErr){
			err = noErr;
		}
		EnableMenuCommand(NULL, kHICommandOpen);
	}

    return err;
}
Example #11
0
fileData*
MacOSXDirScanner::saveFileDialog() { 

    //XXX not finished yet. 

    fprintf(stderr, "start OSX File Save Dialog\n");
    OSStatus   err;
    NavDialogRef  saveDialog;

    NavDialogCreationOptions dialogAttributes;
        
    int n = 0;
    if ( savefD ) { 
        delete savefD;
        savefD = NULL;
    }

    if( AudicleWindow::our_fullscreen )
    {
        glutReshapeWindow( AudicleWindow::main()->m_w, AudicleWindow::main()->m_h );
        glutPostRedisplay();
        AudicleWindow::our_fullscreen = FALSE;
        return NULL;
    }

    err = NavGetDefaultDialogCreationOptions( &dialogAttributes );
    
    dialogAttributes.modality = kWindowModalityAppModal;   
    
    gNavEventHandlerPtr = NewNavEventUPP( dialogFileCallback );    
    
    err = NavCreatePutFileDialog( &dialogAttributes, 'ChuK', kNavGenericSignature,
                                  gNavEventHandlerPtr, NULL, &saveDialog );
    
    if ( !AudicleGfx::cursor_on ) { ShowCursor(); AudicleGfx::cursor_on = true; }
    err = NavDialogRun( saveDialog );
    
    if ( err != noErr )
    {
        NavDialogDispose( saveDialog );
        DisposeNavEventUPP( gNavEventHandlerPtr );
        return NULL;
    }
    
    
    return savefD;
}
Example #12
0
fileData*
MacOSXDirScanner::openFileDialog() { 

    OSStatus   err;
    NavDialogRef  openDialog;
    NavDialogCreationOptions dialogAttributes;
    
    int n = 0;

    if ( openfD ) { 
        delete openfD;
        openfD = NULL;
    }

    if( AudicleWindow::our_fullscreen )
    {
        glutReshapeWindow( AudicleWindow::main()->m_w, AudicleWindow::main()->m_h );
        glutPostRedisplay();
        AudicleWindow::our_fullscreen = FALSE;
        return NULL;
    }
    
    err = NavGetDefaultDialogCreationOptions( &dialogAttributes );
    
    dialogAttributes.modality = kWindowModalityAppModal;   
    
    gNavEventHandlerPtr = NewNavEventUPP( dialogFileCallback );    
    
    err = NavCreateGetFileDialog( &dialogAttributes, NULL, 
                                  gNavEventHandlerPtr, NULL, NULL, 
                                  NULL, &openDialog );
    
    if ( !AudicleGfx::cursor_on ) { ShowCursor(); AudicleGfx::cursor_on = true; }
    err = NavDialogRun( openDialog );
    
    if ( err != noErr )
    {
        NavDialogDispose( openDialog );
        DisposeNavEventUPP( gNavEventHandlerPtr );
        return NULL;
    }

    
    return openfD;
}
Example #13
0
	OSFileRequest::OSFileRequest (const int reqType, const char *title,
																const char *fileType, const char *ext, const char *baseName,
																const char *path,	const char *_baseDirType, int bufLen)
	:	type(reqType),
		m_data(new Data)
	{
		m_data->status = NavGetDefaultDialogCreationOptions(&m_data->dialogOptions);
		m_data->dialogOptions.modality = kWindowModalityAppModal;
		m_data->dialogOptions.windowTitle = CFStringCreateWithCString(NULL, title, kCFStringEncodingMacRoman);
		m_data->dialogOptions.saveFileName = CFStringCreateWithCString(NULL, baseName, kCFStringEncodingMacRoman);
		if (type == FREQ_LOAD)
		{
			m_data->status = NavCreateGetFileDialog(&m_data->dialogOptions, NULL, NULL, NULL, NULL, NULL, &m_data->dialog);
		}
		else if (type == FREQ_SAVE)
		{
			m_data->status = NavCreatePutFileDialog(&m_data->dialogOptions, kUnknownType, kUnknownType, NULL, NULL, &m_data->dialog);
		}
	}
Example #14
0
char *Sys_PathFromOpenMenu(void) {
    /* present an open file dialog and return the file's path */
    OSStatus res;
    NavDialogCreationOptions options;
    NavDialogRef dialog;
    NavReplyRecord reply;
    NavUserAction action;

    FSRef fileRef;
    CFURLRef cfUrl;
    CFStringRef cfString;

    res = NavGetDefaultDialogCreationOptions(&options);
    options.modality = kWindowModalityAppModal;

    res = NavCreateGetFileDialog(&options, NULL, NULL, NULL, NULL, NULL, &dialog);
    NavDialogRun(dialog);

    action = NavDialogGetUserAction(dialog);
    if (action == kNavUserActionNone || action == kNavUserActionCancel)
        return NULL;

    res = NavDialogGetReply(dialog, &reply);
    if (res != noErr)
        return NULL;

    res = AEGetNthPtr(&reply.selection, 1, typeFSRef, NULL, NULL, &fileRef,
                      sizeof(FSRef), NULL);

    cfUrl = CFURLCreateFromFSRef(NULL, &fileRef);
    cfString = NULL;

    if (cfUrl) {
        cfString = CFURLCopyFileSystemPath(cfUrl, kCFURLPOSIXPathStyle);
        CFRelease(cfUrl);
    }

    memset(g_OpenFileName, 0, PATH_MAX);
    CFStringGetCString(cfString, g_OpenFileName, PATH_MAX, kCFStringEncodingMacRoman);
    return g_OpenFileName;
}
OSStatus SaveFileDialog(
    WindowRef parentWindow,
    CFStringRef documentName,
    OSType filetype,
    OSType fileCreator,
    void *inContextData,
    NavDialogRef *outDialog )
{
    NavDialogCreationOptions	dialogOptions;
    OSStatus					theErr = noErr;

    NavGetDefaultDialogCreationOptions( &dialogOptions );

    dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding());
    dialogOptions.saveFileName = documentName;
    dialogOptions.modality = ( parentWindow != NULL ) ? kWindowModalityWindowModal : kWindowModalityAppModal;
    dialogOptions.parentWindow = parentWindow;

    theErr = NavCreatePutFileDialog( &dialogOptions, filetype, fileCreator, GetEventUPP(), inContextData, outDialog );

    if ( theErr == noErr )
    {
        theErr = NavDialogRun( *outDialog );
        if ( theErr != noErr )
        {
            NavDialogDispose( *outDialog );
        }
        if ( theErr != noErr || dialogOptions.modality == kWindowModalityAppModal )
        {
            *outDialog = NULL;	// The dialog has already been disposed.
        }
    }

    if ( dialogOptions.clientName != NULL )
    {
        CFRelease( dialogOptions.clientName );
    }

    return theErr;
}
Example #16
0
bool nav_open_file(char *filetype,char *path)
{
    NavDialogCreationOptions	navoption;
    NavReplyRecord				navreply;
	NavEventUPP					navevent;
    NavObjectFilterUPP			navfilter;
	AEKeyword					keyword;
	DescType					typecode;
    Size						sz;
    NavDialogRef				diagref;
	FSRef						fsref;

    strcpy(nav_filetype,filetype);

	NavGetDefaultDialogCreationOptions(&navoption);
	navoption.optionFlags-=kNavDontAddTranslateItems;
	navoption.optionFlags-=kNavAllowPreviews;

	navevent=NewNavEventUPP(nav_event_proc);
	navfilter=NewNavObjectFilterUPP(nav_file_filter);
	NavCreateGetFileDialog(&navoption,NULL,navevent,NULL,navfilter,NULL,&diagref);
	NavDialogRun(diagref);
 
 	NavDialogGetReply(diagref,&navreply);
	NavDialogDispose(diagref);
	DisposeNavEventUPP(navevent);
    DisposeNavObjectFilterUPP(navfilter);
    
	if (!navreply.validRecord) {
		NavDisposeReply(&navreply);
        return(FALSE);
    }
    
	AEGetNthPtr(&(navreply.selection),1,typeFSRef,&keyword,&typecode,(void*)&fsref,sizeof(FSRef),&sz);
    NavDisposeReply(&navreply);
	
    FSRefMakePath(&fsref,(unsigned char*)path,1024);
	
    return(TRUE);
}
//
// Implementation
//
LLFilePicker::LLFilePicker()
	: mCurrentFile(0),
	  mLocked(false)

{
	reset();

#if LL_WINDOWS
	mOFN.lStructSize = sizeof(OPENFILENAMEW);
	mOFN.hwndOwner = NULL;  // Set later
	mOFN.hInstance = NULL;
	mOFN.lpstrCustomFilter = NULL;
	mOFN.nMaxCustFilter = 0;
	mOFN.lpstrFile = NULL;							// set in open and close
	mOFN.nMaxFile = LL_MAX_PATH;
	mOFN.lpstrFileTitle = NULL;
	mOFN.nMaxFileTitle = 0;
	mOFN.lpstrInitialDir = NULL;
	mOFN.lpstrTitle = NULL;
	mOFN.Flags = 0;									// set in open and close
	mOFN.nFileOffset = 0;
	mOFN.nFileExtension = 0;
	mOFN.lpstrDefExt = NULL;
	mOFN.lCustData = 0L;
	mOFN.lpfnHook = NULL;
	mOFN.lpTemplateName = NULL;
	mFilesW[0] = '\0';
#endif

#if LL_DARWIN
	memset(&mNavOptions, 0, sizeof(mNavOptions));
	OSStatus	error = NavGetDefaultDialogCreationOptions(&mNavOptions);
	if (error == noErr)
	{
		mNavOptions.modality = kWindowModalityAppModal;
	}
#endif
}
Example #18
0
static OSStatus
MyChooseFolder()
{
    NavDialogRef dialog;
    NavDialogCreationOptions options;
    OSStatus err = noErr;

    if (gNavEventUPP == NULL) {
        gNavEventUPP = NewNavEventUPP(MyNavEventCallBack);
        assert(gNavEventUPP != NULL);
    }

    err = NavGetDefaultDialogCreationOptions(&options);
    if (err == noErr) {
    
        err = NavCreateChooseFolderDialog(&options, gNavEventUPP, NULL, NULL, &dialog);
        if (err == noErr) {        
            err = NavDialogRun(dialog);
        }
    }
        
    return err;
}
ofFileDialogResult ofFileSaveDialog(string defaultName, string messageName){
	
	ofFileDialogResult results;
	
	//----------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------       OSX
	//----------------------------------------------------------------------------------------
#ifdef TARGET_OSX
	
	short fRefNumOut;
	FSRef output_file;
	OSStatus err;
	
	NavDialogCreationOptions options;
	NavGetDefaultDialogCreationOptions( &options );
	
	options.optionFlags = kNavNoTypePopup + kNavSupportPackages + kNavAllowOpenPackages;
	options.modality = kWindowModalityAppModal;
	
	options.optionFlags = kNavDefaultNavDlogOptions;
	options.message = CFStringCreateWithCString(NULL, messageName.c_str(), kCFStringEncodingASCII);;
	options.saveFileName = CFStringCreateWithCString(NULL, defaultName.c_str(), kCFStringEncodingASCII);
	NavDialogRef dialog;
	
	err = NavCreatePutFileDialog(&options, '.mov', 'Moov', NULL, NULL, &dialog);
	
	//printf("NavCreatePutFileDialog returned %i\n", err );
	
	err = NavDialogRun(dialog);
	//printf("NavDialogRun returned %i\n", err );
	
	NavUserAction action;
	action = NavDialogGetUserAction( dialog );
	//printf("got action %i\n", action);
	if (action == kNavUserActionNone || action == kNavUserActionCancel) {
		
		return results;
	}
	
	// get dialog reply
	NavReplyRecord reply;
	err = NavDialogGetReply(dialog, &reply);
	if ( err != noErr )
		return results;
	
	if ( reply.replacing )
	{
		printf("need to replace\n");
	}
	
	AEKeyword keyword;
	DescType actual_type;
	Size actual_size;
	FSRef output_dir;
	err = AEGetNthPtr(&(reply.selection), 1, typeFSRef, &keyword, &actual_type,
					  &output_dir, sizeof(output_file), &actual_size);
	
	//printf("AEGetNthPtr returned %i\n", err );
	
	
	CFURLRef cfUrl = CFURLCreateFromFSRef( kCFAllocatorDefault, &output_dir );
	CFStringRef cfString = NULL;
	if ( cfUrl != NULL )
	{
		cfString = CFURLCopyFileSystemPath( cfUrl, kCFURLPOSIXPathStyle );
		CFRelease( cfUrl );
	}
	
	// copy from a CFString into a local c string (http://www.carbondev.com/site/?page=CStrings+)
	const int kBufferSize = 255;
	
	char folderURL[kBufferSize];
	Boolean bool1 = CFStringGetCString(cfString,folderURL,kBufferSize,kCFStringEncodingMacRoman);
	
	char fileName[kBufferSize];
	Boolean bool2 = CFStringGetCString(reply.saveFileName,fileName,kBufferSize,kCFStringEncodingMacRoman);
	
	// append strings together
	
	string url1 = folderURL;
	string url2 = fileName;
	string finalURL = url1 + "/" + url2;
	
	results.filePath = finalURL.c_str();
	
	//printf("url %s\n", finalURL.c_str());
	
	// cleanup dialog
	NavDialogDispose(dialog);
	
#endif
	//----------------------------------------------------------------------------------------
	//----------------------------------------------------------------------------------------
	//----------------------------------------------------------------------------------------
	
	//----------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------   windoze
	//----------------------------------------------------------------------------------------
#ifdef TARGET_WIN32
	
	
	wchar_t fileName[MAX_PATH] = L"";
	char * extension;
	OPENFILENAME ofn;
    memset(&ofn, 0, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	HWND hwnd = WindowFromDC(wglGetCurrentDC());
	ofn.hwndOwner = hwnd;
	ofn.hInstance = GetModuleHandle(0);
	ofn.nMaxFileTitle = 31;
	ofn.lpstrFile = fileName;
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrFilter = _T("All Files (*.*)\0*.*\0");
	ofn.lpstrDefExt = _T("");	// we could do .rxml here?
	ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
	ofn.lpstrTitle = _T("Select Output File");

	if (GetSaveFileName(&ofn)){
		results.filePath = convertWideToNarrow(fileName);
	}

#endif
	//----------------------------------------------------------------------------------------
	//----------------------------------------------------------------------------------------
	//----------------------------------------------------------------------------------------


	//----------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------   linux
	//----------------------------------------------------------------------------------------
#if defined( TARGET_LINUX ) && defined (OF_USING_GTK)

	gtkFileDialog(GTK_FILE_CHOOSER_ACTION_SAVE, messageName,defaultName);

#endif
	//----------------------------------------------------------------------------------------
	//----------------------------------------------------------------------------------------
	//----------------------------------------------------------------------------------------

	if( results.filePath.length() > 0 ){
		results.bSuccess = true;
		results.fileName = ofFileUtils::getFilenameFromPath(results.filePath);		
	}
	
	return results;	
}
Example #20
0
int wxDirDialog::ShowModal()
{
    WX_HOOK_MODAL_DIALOG();

    NavDialogRef dialog = NULL;
    NavDialogCreationOptions options;
    NavReplyRecord reply ;
    bool disposeReply = false ;
    OSStatus err = noErr;

    err = NavGetDefaultDialogCreationOptions(&options);
    options.optionFlags &= ~kNavAllowMultipleFiles;
    if (err == noErr)
    {
        wxCFStringRef message(m_message, GetFont().GetEncoding());
        options.message = message;
        err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL,  this , &dialog);
        if (err == noErr)
        {
            wxDialog::OSXBeginModalDialog();
            err = NavDialogRun(dialog);
            wxDialog::OSXEndModalDialog();
            if ( err == noErr )
            {
                err = NavDialogGetReply(dialog, &reply);
                disposeReply = true ;
            }
        }
    }

    if ( err == noErr )
    {
        if ( reply.validRecord )
        {
            FSRef folderInfo;
            AEDesc specDesc ;

            OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
            if ( err != noErr )
            {
                m_path = wxEmptyString ;
            }
            else
            {
                folderInfo = **(FSRef**) specDesc.dataHandle;
                m_path = wxMacFSRefToPath( &folderInfo ) ;
                if (specDesc.dataHandle != nil)
                {
                    ::AEDisposeDesc(&specDesc);
                }
            }
        }
        else
        {
            err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
        }
    }

    if ( disposeReply )
        ::NavDisposeReply(&reply);

    // apparently cancelling shouldn't change m_path
    if ( err != noErr && err != userCanceledErr )
        m_path = wxEmptyString ;

    if ( dialog )
        ::NavDialogDispose(dialog);

    return (err == noErr) ? wxID_OK : wxID_CANCEL ;
}
PPOpenPanel::ReturnCodes PPOpenPanel::runModal()
{
	ReturnCodes result = ReturnCodeCANCEL;
	
	OSStatus err = noErr;
	NavDialogRef theOpenDialog;
	NavDialogCreationOptions dialogOptions;
	
	if ((err = NavGetDefaultDialogCreationOptions(&dialogOptions)) == noErr)
	{
		
		dialogOptions.modality = kWindowModalityAppModal;
		dialogOptions.windowTitle = CFStringCreateWithCString(NULL, caption, kCFStringEncodingASCII);
		
		err = NavCreateChooseFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, NULL, &theOpenDialog);
	
		if (theOpenDialog)
		{
			err = NavDialogRun(theOpenDialog);
			
			NavReplyRecord reply;
			
			err = NavDialogGetReply (theOpenDialog, &reply);
			
			if (err == noErr)
			{
				
				// retrieve filename
				AEDesc actualDesc;
				FSRef fileToOpen;
				//HFSUniStr255 theFileName;
				//CFStringRef fileNameCFString;
				
				err = AECoerceDesc(&reply.selection, typeFSRef, &actualDesc);
				
				err = AEGetDescData(&actualDesc, reinterpret_cast<void*>(&fileToOpen), sizeof(FSRef));
				
				// gib ihm
				int len = PATH_MAX;
				char* buffer = new char[PATH_MAX+1];
				
				FSRefMakePath (&fileToOpen, (UInt8*)buffer, len);			
				
				fileName = buffer;
					
				delete[] buffer;
				
				result = ReturnCodeOK;
				
				NavDisposeReply(&reply);
			}
			
			NavDialogDispose(theOpenDialog);
			
		}
		
		if (dialogOptions.windowTitle)
			CFRelease(dialogOptions.windowTitle);
				
	}
	
	return result;

}
Example #22
0
std::string GetOpenFileFromUser(dialog_type d_type)
{
#ifdef UNDEFINED
  NavDialogCreationOptions dialogOptions;
  NavDialogRef dialog;
  NavReplyRecord replyRecord;
  //CFURLRef fileAsCFURLRef = NULL;
  FSRef fileAsFSRef;
  OSStatus status;
    CFIndex sz;
    CFRange r;
  
  std::string res;

  // Get the standard set of defaults
  status = NavGetDefaultDialogCreationOptions(&dialogOptions);
  require_noerr( status, CantGetNavOptions );

  // Make the window app-wide modal
  dialogOptions.modality = kWindowModalityAppModal;
  dialogOptions.optionFlags |= kNavDontConfirmReplacement;

  // Create the dialog
  status = (DO_LOAD == d_type)?
    NavCreateGetFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, NULL, &dialog):
    NavCreatePutFileDialog(&dialogOptions,  kNavGenericSignature, kNavGenericSignature, NULL, NULL, &dialog);
  require_noerr( status, CantCreateDialog );

  // Show it
  status = NavDialogRun(dialog);
  require_noerr( status, CantRunDialog );
        
  // Get the reply
  status = NavDialogGetReply(dialog, &replyRecord);
  require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );

  // If the user clicked "Cancel", just bail
  if ( status == userCanceledErr ) goto UserCanceled;

  // Get the file
  status = AEGetNthPtr(&(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
  require_noerr( status, CantExtractFSRef );
        
  // Convert it to a CFURL
  // fileAsCFURLRef = CFURLCreateFromFSRef(NULL, &fileAsFSRef);
  //success, lets extraxct info:
  // kdl;
 
 unsigned char buf[100];
  buf[0]=0; //null terminated
  FSRefMakePath( &fileAsFSRef, (UInt8 *)buf, 100); 
  res = std::string((char *)buf, strlen((char *)buf));
  
  if(DO_SAVE == d_type){ //then add file name to the path.
    r.location = 0;
    r.length = CFStringGetLength(replyRecord.saveFileName);
    CFStringGetBytes(
		     replyRecord.saveFileName,
		     r,
		     kCFStringEncodingUTF8,
		     0,     //dont want to deal with uncovertable strings
		     false, //internal representation
		     buf,
		     100,
		     &sz);
    res += "/";
    res += std::string((char *)buf, sz);		     
  };
  
  // Cleanup
 CantExtractFSRef:
 UserCanceled:
  verify_noerr( NavDisposeReply(&replyRecord) );
 CantGetReply:
 CantRunDialog:
  NavDialogDispose(dialog);
 CantCreateDialog:
 CantGetNavOptions:
  return res;
#else
  return "";
#endif //UNDEFINED
};
Example #23
0
QString qt_mac_get_save_file_name(const QFileDialogArgs &args, QString *pwd,
                                  QString *selectedFilter)
{
    QWidget *parent = args.parent;
    OSErr err;
    QString retstr;
    NavDialogCreationOptions options;
    NavGetDefaultDialogCreationOptions(&options);
    static const int w = 450, h = 350;
    if (args.options & QFileDialog::DontConfirmOverwrite)
        options.optionFlags |= kNavDontConfirmReplacement;
    options.modality = kWindowModalityAppModal;
    options.location.h = options.location.v = -1;
    if (!args.directory.isEmpty())
        options.saveFileName = QCFString::toCFStringRef(args.selection);
    if (!args.caption.isEmpty())
        options.windowTitle = QCFString::toCFStringRef(args.caption);
    if (parent && parent->isVisible()) {
        WindowClass wclass;
        GetWindowClass(qt_mac_window_for(parent), &wclass);
        if (!(args.options & QFileDialog::DontUseSheet) && (wclass == kDocumentWindowClass ||
                                                            wclass == kFloatingWindowClass || wclass == kMovableModalWindowClass)) {
            options.modality = kWindowModalityWindowModal;
            options.parentWindow = qt_mac_window_for(parent);

            // The parent needs to be active for the sheet to get keyboard focus.
            if (!parent->isActiveWindow())
                parent->activateWindow();
        } else {
            parent = parent->window();
            QString s = parent->windowTitle();
            options.clientName = CFStringCreateWithCharacters(0, (UniChar *)s.unicode(), s.length());
            options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
            options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);

            QRect r = QApplication::desktop()->screenGeometry(
                QApplication::desktop()->screenNumber(parent));
            if (options.location.h + w > r.right())
                options.location.h -= (options.location.h + w) - r.right() + 10;
            if (options.location.v + h > r.bottom())
                options.location.v -= (options.location.v + h) - r.bottom() + 10;
        }
#if 0
    } else if (QWidget *p = qApp->mainWidget()) {
        static int last_screen = -1;
        int scr = QApplication::desktop()->screenNumber(p);
        if (last_screen != scr) {
            QRect r = QApplication::desktop()->screenGeometry(scr);
            options.location.h = (r.x() + (r.width() / 2)) - (w / 2);
            options.location.v = (r.y() + (r.height() / 2)) - (h / 2);
        }
#endif
    }

    QList<qt_mac_filter_name*> filts = qt_mac_make_filters_list(args.filter);
    qt_mac_nav_filter_type t;
    t.saveDialog = true;
    t.index = 0;
    t.filts = &filts;
    if (filts.count() > 1) {
        int i = 0;
        CFStringRef *arr = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef) * filts.count()));
        for (QList<qt_mac_filter_name*>::const_iterator it = filts.constBegin();
             it != filts.constEnd(); ++it)
            arr[i++] = QCFString::toCFStringRef((*it)->description);
        options.popupExtension = CFArrayCreate(0, reinterpret_cast<const void **>(arr), filts.count(), 0);
    }

    NavDialogRef dlg;
    if (NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(),
                               static_cast<void *>(filts.isEmpty() ? 0 : &t), &dlg)) {
        qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
        return retstr;
    }
    if (pwd && !pwd->isEmpty()) {
        FSRef fsref;
        if (qt_mac_create_fsref(*pwd, &fsref) == noErr) {
            AEDesc desc;
            if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr)
                NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc);
        }
    }
    NavDialogRun(dlg);
    if (selectedFilter) {
        NavMenuItemSpec navSpec;
        bzero(&navSpec, sizeof(NavMenuItemSpec));
        qt_mac_filter_name *sel_filt_name = qt_mac_make_filters_list(*selectedFilter).at(0);
        for (int i = 0; i < filts.count(); ++i) {
            const qt_mac_filter_name *filter = filts.at(i);
            if (sel_filt_name->description == filter->description
                    && sel_filt_name->regxp == filter->regxp
                    && sel_filt_name->filter == filter->filter) {
                navSpec.menuType = i;
                break;
            }
        }
        NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec);
    }
    if (options.modality == kWindowModalityWindowModal) { //simulate modality
        QWidget modal_widg(parent, Qt::Sheet);
        modal_widg.createWinId();
        QApplicationPrivate::enterModal(&modal_widg);
        while (g_nav_blocking)
            qApp->processEvents(QEventLoop::WaitForMoreEvents);
        QApplicationPrivate::leaveModal(&modal_widg);
    }

    if (NavDialogGetUserAction(dlg) != kNavUserActionSaveAs) {
        NavDialogDispose(dlg);
        return retstr;
    }
    NavReplyRecord ret;
    NavDialogGetReply(dlg, &ret);
    NavDialogDispose(dlg);

    long count;
    err = AECountItems(&(ret.selection), &count);
    if (!ret.validRecord || err != noErr || !count) {
        NavDisposeReply(&ret);
        return retstr;
    }

    AEKeyword        keyword;
    DescType    type;
    Size        size;
    FSRef ref;
    err = AEGetNthPtr(&(ret.selection), 1, typeFSRef, &keyword,
                      &type, &ref, sizeof(ref), &size);
    if (err == noErr) {
        if (!str_buffer) {
            qAddPostRoutine(cleanup_str_buffer);
            str_buffer = (UInt8 *)malloc(1024);
        }
        FSRefMakePath(&ref, str_buffer, 1024);
        retstr = QString::fromUtf8((const char *)str_buffer);
        //now filename
        CFStringGetCString(ret.saveFileName, (char *)str_buffer, 1024, kCFStringEncodingUTF8);
        retstr += QLatin1String("/") + QString::fromUtf8((const char *)str_buffer);
    }
    NavDisposeReply(&ret);
    if (selectedFilter)
        *selectedFilter = filts.at(t.index)->filter;
    while (!filts.isEmpty())
        delete filts.takeFirst();
    return retstr;
}
Example #24
0
QStringList qt_mac_get_open_file_names(const QFileDialogArgs &args, QString *pwd,
                                       QString *selectedFilter)
{
    QWidget *parent = args.parent;
    OSErr err;
    QStringList retstrl;

    NavDialogCreationOptions options;
    NavGetDefaultDialogCreationOptions(&options);
    options.modality = kWindowModalityAppModal;
    options.optionFlags |= kNavSupportPackages;
    if (args.options & QFileDialog::DontConfirmOverwrite)
        options.optionFlags |= kNavDontConfirmReplacement;
    if (args.mode != QFileDialog::ExistingFiles)
        options.optionFlags &= ~kNavAllowMultipleFiles;

    if (!args.caption.isEmpty())
        options.windowTitle = QCFString::toCFStringRef(args.caption);

    static const int w = 450, h = 350;
    options.location.h = options.location.v = -1;
    if (parent && parent->isVisible()) {
        WindowClass wclass;
        GetWindowClass(qt_mac_window_for(parent), &wclass);
        if (!(args.options & QFileDialog::DontUseSheet) && (wclass == kDocumentWindowClass ||
                                                            wclass == kFloatingWindowClass || wclass == kMovableModalWindowClass)) {
            options.modality = kWindowModalityWindowModal;
            options.parentWindow = qt_mac_window_for(parent);
        } else {
            parent = parent->window();
            QString s = parent->windowTitle();
            options.clientName = QCFString::toCFStringRef(s);
            options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
            options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);

            QRect r = QApplication::desktop()->screenGeometry(
                QApplication::desktop()->screenNumber(parent));
            const int border = 10;
            if (options.location.h + w > r.right())
                options.location.h -= (options.location.h + w) - r.right() + border;
            if (options.location.v + h > r.bottom())
                options.location.v -= (options.location.v + h) - r.bottom() + border;
            if (options.location.h < r.left())
                options.location.h = r.left() + border;
            if (options.location.v < r.top())
                options.location.v = r.top() + border;
        }
#if 0
    } else if (QWidget *p = qApp->mainWidget()) {
        static int last_screen = -1;
        int scr = QApplication::desktop()->screenNumber(p);
        if (last_screen != scr) {
            QRect r = QApplication::desktop()->screenGeometry(scr);
            options.location.h = (r.x() + (r.width() / 2)) - (w / 2);
            options.location.v = (r.y() + (r.height() / 2)) - (h / 2);
        }
#endif
    }

    QList<qt_mac_filter_name*> filts = qt_mac_make_filters_list(args.filter);
    qt_mac_nav_filter_type t;
    t.saveDialog = false;
    t.index = 0;
    t.filts = &filts;
    if (filts.count() > 1) {
        int i = 0;
        CFStringRef *arr = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef) * filts.count()));
        for (QList<qt_mac_filter_name*>::const_iterator it = filts.constBegin();
             it != filts.constEnd(); ++it)
            arr[i++] = QCFString::toCFStringRef((*it)->description);
        options.popupExtension = CFArrayCreate(0, reinterpret_cast<const void **>(arr), filts.count(), 0);
    }

    NavDialogRef dlg;
    if (args.mode == QFileDialog::DirectoryOnly ||
        args.mode == QFileDialog::Directory) {
        if (NavCreateChooseFolderDialog(&options, make_navProcUPP(), 0, 0, &dlg)) {
            qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
            return retstrl;
        }
    } else {
        if (NavCreateGetFileDialog(&options, 0, make_navProcUPP(), 0,
                                  make_navFilterUPP(), (void *) (filts.isEmpty() ? 0 : &t),
                                  &dlg)) {
            qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
            return retstrl;
        }
    }
    if (pwd && !pwd->isEmpty()) {
        FSRef fsref;
        if (qt_mac_create_fsref(*pwd, &fsref) == noErr) {
            AEDesc desc;
            if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr)
                NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc);
        }
    }

    NavDialogRun(dlg);

    if (selectedFilter) {
        NavMenuItemSpec navSpec;
        bzero(&navSpec, sizeof(NavMenuItemSpec));
        qt_mac_filter_name *sel_filt_name = qt_mac_make_filters_list(*selectedFilter).at(0);
        for (int i = 0; i < filts.count(); ++i) {
            const qt_mac_filter_name *filter = filts.at(i);
            if (sel_filt_name->description == filter->description
                    && sel_filt_name->regxp == filter->regxp
                    && sel_filt_name->filter == filter->filter) {
                navSpec.menuType = i;
                break;
            }
        }
        NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec);
    }

    if (options.modality == kWindowModalityWindowModal) { //simulate modality
        QWidget modal_widg(parent, Qt::Sheet);
        modal_widg.createWinId();
        QApplicationPrivate::enterModal(&modal_widg);
        while (g_nav_blocking)
            qApp->processEvents(QEventLoop::WaitForMoreEvents);
        QApplicationPrivate::leaveModal(&modal_widg);
    }

    if (!(NavDialogGetUserAction(dlg) &
          (kNavUserActionOpen | kNavUserActionChoose | kNavUserActionNewFolder))) {
        NavDialogDispose(dlg);
        return retstrl;
    }
    NavReplyRecord ret;
    NavDialogGetReply(dlg, &ret);
    NavDialogDispose(dlg);

    long count;
    err = AECountItems(&(ret.selection), &count);
    if (!ret.validRecord || err != noErr || !count) {
        NavDisposeReply(&ret);
        return retstrl;
    }

    for (long index = 1; index <= count; index++) {
        FSRef ref;
        err = AEGetNthPtr(&(ret.selection), index, typeFSRef, 0, 0, &ref, sizeof(ref), 0);
        if (err != noErr)
            break;

        if (!str_buffer) {
            qAddPostRoutine(cleanup_str_buffer);
            str_buffer = (UInt8 *)malloc(1024);
        }
        FSRefMakePath(&ref, str_buffer, 1024);
        retstrl.append(QString::fromUtf8((const char *)str_buffer));
    }
    NavDisposeReply(&ret);
    if (selectedFilter)
        *selectedFilter = filts.at(t.index)->filter;
    while (!filts.isEmpty())
        delete filts.takeFirst();
    return retstrl;
}
CFURLRef GetOpenDialogForUser(kDialogType type, char* title, char* message)
{
	NavDialogCreationOptions dialogOptions;
	NavDialogRef dialog = NULL;
	NavReplyRecord replyRecord;
	CFURLRef fileAsCFURLRef = NULL;
	FSRef fileAsFSRef;
	OSStatus status;
	
	CFAllocatorRef alloc_default = kCFAllocatorDefault;  // = NULL;

	// Get the standard set of defaults
	status = NavGetDefaultDialogCreationOptions(&dialogOptions);
	require_noerr( status, CantGetNavOptions );

	dialogOptions.optionFlags = kNavNoTypePopup + kNavSupportPackages + kNavAllowOpenPackages;


	if (title != NULL) {
		CFStringRef cftitle = CFStringCreateWithCString(alloc_default,title,kCFStringEncodingMacRoman);
		dialogOptions.windowTitle = cftitle;
	}

	if (message != NULL) {
		CFStringRef cfmessage = CFStringCreateWithCString(alloc_default,message,kCFStringEncodingMacRoman);
		dialogOptions.message = cfmessage;
	}


	// Make the window app-wide modal
	dialogOptions.modality = kWindowModalityAppModal;

	// Create the dialog
	if (type == kDialogFile) {
		status = NavCreateGetFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, NULL, &dialog);
	} else if (type == kDialogFolder) {
		status = NavCreateChooseFolderDialog(&dialogOptions, NULL, NULL, NULL, &dialog);
	}
	require_noerr( status, CantCreateDialog );

	// Show it
	status = NavDialogRun(dialog);
	require_noerr( status, CantRunDialog );

	// Get the reply
	status = NavDialogGetReply(dialog, &replyRecord);
	require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );

	// If the user clicked "Cancel", just bail
	if ( status == userCanceledErr ) goto UserCanceled;

	// Get the file
	status = AEGetNthPtr(&(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	require_noerr( status, CantExtractFSRef );

	// Convert it to a CFURL
	fileAsCFURLRef = CFURLCreateFromFSRef(NULL, &fileAsFSRef);

	// Cleanup
CantExtractFSRef:
UserCanceled:
	verify_noerr( NavDisposeReply(&replyRecord) );
CantGetReply:
CantRunDialog:
	NavDialogDispose(dialog);
CantCreateDialog:
CantGetNavOptions:
    return fileAsCFURLRef;
}
Example #26
0
QStringList Q3FileDialog::macGetOpenFileNames(const QString &filter, QString *pwd,
                                             QWidget *parent, const char* /*name*/,
                                             const QString& caption, QString *selectedFilter,
                                             bool multi, bool directory)
{
    OSErr err;
    QStringList retstrl;

    NavDialogCreationOptions options;
    NavGetDefaultDialogCreationOptions(&options);
    options.modality = kWindowModalityAppModal;
    options.optionFlags |= kNavDontConfirmReplacement | kNavSupportPackages;
    if (!multi)
        options.optionFlags &= ~kNavAllowMultipleFiles;
    if(!caption.isEmpty())
        options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(),
                                                           caption.length());

    static const int w = 450, h = 350;
    options.location.h = options.location.v = -1;
    if(parent && parent->isVisible()) {
        Qt::WindowType wt = parent->window()->windowType();
        if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) {
            options.modality = kWindowModalityWindowModal;
            options.parentWindow = qt_mac_window_for(parent);
        } else {
            parent = parent->window();
            QString s = parent->windowTitle();
            options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length());
            options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
            options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);

            QRect r = QApplication::desktop()->screenGeometry(
                QApplication::desktop()->screenNumber(parent));
            if(options.location.h + w > r.right())
                options.location.h -= (options.location.h + w) - r.right() + 10;
            if(options.location.v + h > r.bottom())
                options.location.v -= (options.location.v + h) - r.bottom() + 10;
        }
    } else if(QWidget *p = qApp->mainWidget()) {
        static int last_screen = -1;
        int scr = QApplication::desktop()->screenNumber(p);
        if(last_screen != scr) {
            QRect r = QApplication::desktop()->screenGeometry(scr);
            options.location.h = (r.x() + (r.width() / 2)) - (w / 2);
            options.location.v = (r.y() + (r.height() / 2)) - (h / 2);
        }
    }

    QList<qt_mac_filter_name*> filts = makeFiltersList(filter);
    qt_mac_nav_filter_type t;
    t.index = 0;
    t.filts = &filts;
    if(filts.count() > 1) {
        int i = 0;
        CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count());
        for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) {
            QString rg = (*it)->description;
            arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length());
        }
        options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL);
    }

    NavDialogRef dlg;
    if(directory) {
        if(NavCreateChooseFolderDialog(&options, make_navProcUPP(), NULL, NULL, &dlg)) {
            qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
            return retstrl;
        }
    } else {
        if(NavCreateGetFileDialog(&options, NULL, make_navProcUPP(), NULL,
                                  make_navFilterUPP(), (void *) (filts.isEmpty() ? NULL : &t),
                                  &dlg)) {
            qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
            return retstrl;
        }
    }
    if(pwd && !pwd->isEmpty()) {
        FSRef fsref;
        if(qt_mac_create_fsref(*pwd, &fsref) == noErr) {
            AEDesc desc;
            if(AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr)
                NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc);
        }
    }

    NavDialogRun(dlg);
    if (selectedFilter) {
        NavMenuItemSpec navSpec;
        bzero(&navSpec, sizeof(NavMenuItemSpec));
        qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0);
        for (int i = 0; i < filts.count(); ++i) {
            const qt_mac_filter_name *filter = filts.at(i);
            if (sel_filt_name->description == filter->description
                    && sel_filt_name->regxp == filter->regxp
                    && sel_filt_name->filter == filter->filter) {
                navSpec.menuType = i;
                break;
            }
        }
        NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec);
    }
    if(options.modality == kWindowModalityWindowModal) { //simulate modality
        QWidget modal_widg(parent, __FILE__ "__modal_dlg",
                           Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder);
        modal_widg.createWinId();
        QApplicationPrivate::enterModal(&modal_widg);
        while(g_nav_blocking)
            qApp->processEvents(QEventLoop::WaitForMoreEvents);
        QApplicationPrivate::leaveModal(&modal_widg);
    }

    if(!(NavDialogGetUserAction(dlg) &
          (kNavUserActionOpen | kNavUserActionChoose | kNavUserActionNewFolder))) {
        NavDialogDispose(dlg);
        return retstrl;
    }
    NavReplyRecord ret;
    NavDialogGetReply(dlg, &ret);
    NavDialogDispose(dlg);

    long count;
    err = AECountItems(&(ret.selection), &count);
    if(!ret.validRecord || err != noErr || !count) {
        NavDisposeReply(&ret);
        return retstrl;
    }

    for(long index = 1; index <= count; index++) {
        FSRef ref;
        err = AEGetNthPtr(&(ret.selection), index, typeFSRef, 0, 0, &ref, sizeof(ref), 0);
        if(err != noErr)
            break;

        if(!str_buffer) {
            qAddPostRoutine(cleanup_str_buffer);
            str_buffer = (UInt8 *)malloc(1024);
        }
        FSRefMakePath(&ref, str_buffer, 1024);
        retstrl.append(QString::fromUtf8((const char *)str_buffer));
    }
    NavDisposeReply(&ret);
    if(selectedFilter)
        *selectedFilter = filts.at(t.index)->filter;
    while (!filts.isEmpty())
        delete filts.takeFirst();
    return retstrl;
}
CFURLRef GetSaveDialogForUser(char* title, char* message)
{
	NavDialogCreationOptions dialogOptions;
	FSRef output_file;
	CFURLRef fileAsCFURLRef = NULL;
	OSStatus status;
	CFAllocatorRef alloc_default = kCFAllocatorDefault;
	
	
	AEKeyword keyword;
	DescType actual_type;
	Size actual_size;
	FSRef output_dir;
	NavReplyRecord reply;
	CFIndex len;

	// Get the standard set of defaults
	status = NavGetDefaultDialogCreationOptions( &dialogOptions );
	require_noerr( status, CantGetNavOptions );

	dialogOptions.optionFlags = kNavNoTypePopup + kNavSupportPackages + kNavAllowOpenPackages;

	  // = NULL;

	if (title != NULL) {
		CFStringRef cftitle = CFStringCreateWithCString(alloc_default,title,kCFStringEncodingMacRoman);
		dialogOptions.windowTitle = cftitle;
	}

	if (message != NULL) {
		CFStringRef cfmessage = CFStringCreateWithCString(alloc_default,message,kCFStringEncodingMacRoman);
		dialogOptions.message = cfmessage;
	}
	// Make the window app-wide modal
	dialogOptions.modality = kWindowModalityAppModal;

	NavDialogRef dialog;
	status = NavCreatePutFileDialog ( &dialogOptions, NULL, NULL, NULL, NULL, &dialog);
	require_noerr( status, CantCreateDialog );

	status = NavDialogRun(dialog);
	require_noerr( status, CantRunDialog );

	// get dialog reply
	status = NavDialogGetReply(dialog, &reply);
	require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );

	//get file directory
	status = AEGetNthPtr(&(reply.selection), 1, typeFSRef, &keyword, &actual_type,
						 &output_dir, sizeof(output_file), &actual_size);
	require_noerr( status, CantExtractFSRef );

	UInt8 output_dir_name[1024];
	FSRefMakePath(&output_dir, output_dir_name, 1024 );

	// now get filename
	len = CFStringGetLength(reply.saveFileName);
	if (len > 255)
		len = 255;
	UniChar output_filename[255];
	CFStringGetCharacters(reply.saveFileName, CFRangeMake(0, len), output_filename);

	// need to unlink the old file
	if ( reply.replacing )
	{
		FSRef oldfile;

		status = FSMakeFSRefUnicode(&output_dir, len, output_filename,
								 kTextEncodingUnicodeDefault,
								 &oldfile);
		if (status == noErr) status = FSDeleteObject(&oldfile);
		//overwrite failed!
		require_noerr( status, UserCanceled );
	}

	//create fsref again to new file (NOTE: this actually makes a file...)
	status = FSCreateFileUnicode( &output_dir, len, output_filename, kFSCatInfoNone,
								 NULL, &output_file, NULL );
	require_noerr( status, CantExtractFSRef );

	// Convert it to a CFURL
	fileAsCFURLRef = CFURLCreateFromFSRef(NULL, &output_file);

CantExtractFSRef:
UserCanceled:
	verify_noerr( NavDisposeReply(&reply) );
CantGetReply:
CantRunDialog:
	// cleanup dialog
	NavDialogDispose(dialog);
CantCreateDialog:
CantGetNavOptions:
    return fileAsCFURLRef;
}
Example #28
0
void GetOpenFileFromUser( char *title, char *path, char *okMsg, char *cancelMsg ) {
	// Allow the user to choose an existing file
	
	NavDialogCreationOptions dialogOptions;
	NavDialogRef dialog;
	NavReplyRecord replyRecord;
	CFURLRef fileAsCFURLRef = NULL;
	FSRef fileAsFSRef;
	OSStatus status;
	UInt8 output_dir_name[1024];
	
	ZFileSpec fs( path );
	
	
	// Get the standard set of defaults
	status = NavGetDefaultDialogCreationOptions(&dialogOptions);
	require_noerr( status, CantGetNavOptions );
	
	// Make the window app-wide modal
	dialogOptions.modality = kWindowModalityAppModal;

	dialogOptions.windowTitle = CFStringCreateWithCString( NULL, title, 0 );
	dialogOptions.saveFileName = CFStringCreateWithCString( NULL, fs.getFile(), 0 ); 
	
	// Create the dialog
	status = NavCreateGetFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, NULL, &dialog);
	require_noerr( status, CantCreateDialog );
	
	// Show it
	status = NavDialogRun(dialog);
	require_noerr( status, CantRunDialog );
	
	// Get the reply
	status = NavDialogGetReply(dialog, &replyRecord);
	require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );
	
	// If the user clicked "Cancel", just bail
	if ( status == userCanceledErr ) {
		if( cancelMsg ) {
			zMsgQueue( cancelMsg );
			NavDialogDispose( dialog );
			return;
		}
	}
	
	// Get the file
	status = AEGetNthPtr(&(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	require_noerr( status, CantExtractFSRef );
	
	FSRefMakePath( &fileAsFSRef, output_dir_name, 1024 );
	if( okMsg ) {
		zMsgQueue( "%s osx=1 filespec='%s'", okMsg, escapeQuotes( (char*)output_dir_name ) );
	}
	
	// Cleanup
CantExtractFSRef:
UserCanceled:
	verify_noerr( NavDisposeReply(&replyRecord) );
CantGetReply:
CantRunDialog:
	NavDialogDispose(dialog);
CantCreateDialog:
CantGetNavOptions:
	return;
}
Example #29
0
QString Q3FileDialog::macGetSaveFileName(const QString &start, const QString &filter,
                                         QString *, QWidget *parent, const char* /*name*/,
                                         const QString& caption, QString *selectedFilter)
{
    OSErr err;
    QString retstr;
    NavDialogCreationOptions options;
    NavGetDefaultDialogCreationOptions(&options);
    static const int w = 450, h = 350;
    options.optionFlags |= kNavDontConfirmReplacement;
    options.modality = kWindowModalityAppModal;
    options.location.h = options.location.v = -1;
    QString workingDir;
    QString initialSelection;
    if (!start.isEmpty()) {
        Q3UrlOperator u(encodeFileName(start));
        if (u.isLocalFile() && QFileInfo(u.path()).isDir()) {
            workingDir = start;
        } else {
            if (u.isLocalFile()) {
                QFileInfo fi(u.dirPath());
                if (fi.exists()) {
                    workingDir = u.dirPath();
                    initialSelection = u.fileName();
                }
            } else {
                workingDir = u.toString();
            }
        }
        if (!initialSelection.isEmpty())
            options.saveFileName = CFStringCreateWithCharacters(0,
                                                            (UniChar *)initialSelection.unicode(),
                                                            initialSelection.length());
    }
    if(!caption.isEmpty())
        options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(),
                                                           caption.length());
    if(parent && parent->isVisible()) {
        Qt::WindowType wt = parent->window()->windowType();
        if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) {
            options.modality = kWindowModalityWindowModal;
            options.parentWindow = qt_mac_window_for(parent);
        } else {
            parent = parent->window();
            QString s = parent->windowTitle();
            options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length());
            options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
            options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);

            QRect r = QApplication::desktop()->screenGeometry(
                QApplication::desktop()->screenNumber(parent));
            if(options.location.h + w > r.right())
                options.location.h -= (options.location.h + w) - r.right() + 10;
            if(options.location.v + h > r.bottom())
                options.location.v -= (options.location.v + h) - r.bottom() + 10;
        }
    } else if(QWidget *p = qApp->mainWidget()) {
        static int last_screen = -1;
        int scr = QApplication::desktop()->screenNumber(p);
        if(last_screen != scr) {
            QRect r = QApplication::desktop()->screenGeometry(scr);
            options.location.h = (r.x() + (r.width() / 2)) - (w / 2);
            options.location.v = (r.y() + (r.height() / 2)) - (h / 2);
        }
    }

    QList<qt_mac_filter_name*> filts = makeFiltersList(filter);
    qt_mac_nav_filter_type t;
    t.index = 0;
    t.filts = &filts;
    if(filts.count() > 1) {
        int i = 0;
        CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count());
        for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) {
            QString rg = (*it)->description;
            arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length());
        }
        options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL);
    }

    NavDialogRef dlg;
    if(NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(),
                              (void *) (filts.isEmpty() ? NULL : &t), &dlg)) {
        qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
        return retstr;
    }
    if (!workingDir.isEmpty()) {
        FSRef fsref;
        if (qt_mac_create_fsref(workingDir, &fsref) == noErr) {
            AEDesc desc;
            if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr)
                NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc);
        }
    }
    NavDialogRun(dlg);
    if (selectedFilter) {
        NavMenuItemSpec navSpec;
        bzero(&navSpec, sizeof(NavMenuItemSpec));
        qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0);
        for (int i = 0; i < filts.count(); ++i) {
            const qt_mac_filter_name *filter = filts.at(i);
            if (sel_filt_name->description == filter->description
                    && sel_filt_name->regxp == filter->regxp
                    && sel_filt_name->filter == filter->filter) {
                navSpec.menuType = i;
                break;
            }
        }
        NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec);
    }
    if(options.modality == kWindowModalityWindowModal) { //simulate modality
        QWidget modal_widg(parent, __FILE__ "__modal_dlg",
                           Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder);
        modal_widg.createWinId();
        QApplicationPrivate::enterModal(&modal_widg);
        while(g_nav_blocking)
            qApp->processEvents(QEventLoop::WaitForMoreEvents);
        QApplicationPrivate::leaveModal(&modal_widg);
    }

    if(NavDialogGetUserAction(dlg) != kNavUserActionSaveAs) {
        NavDialogDispose(dlg);
        return retstr;
    }
    NavReplyRecord ret;
    NavDialogGetReply(dlg, &ret);
    NavDialogDispose(dlg);

    long count;
    err = AECountItems(&(ret.selection), &count);
    if(!ret.validRecord || err != noErr || !count) {
        NavDisposeReply(&ret);
        return retstr;
    }

    AEKeyword        keyword;
    DescType    type;
    Size        size;
    FSRef ref;
    err = AEGetNthPtr(&(ret.selection), 1, typeFSRef, &keyword,
                      &type, &ref, sizeof(ref), &size);
    if(err == noErr) {
        if(!str_buffer) {
            qAddPostRoutine(cleanup_str_buffer);
            str_buffer = (UInt8 *)malloc(1024);
        }
        FSRefMakePath(&ref, str_buffer, 1024);
        retstr = QString::fromUtf8((const char *)str_buffer);
        //now filename
        CFStringGetCString(ret.saveFileName, (char *)str_buffer, 1024, kCFStringEncodingUTF8);
        retstr += QLatin1Char('/') + QString::fromUtf8((const char *)str_buffer);
    }
    NavDisposeReply(&ret);
    if(selectedFilter)
        *selectedFilter = filts.at(t.index)->filter;
    while (!filts.isEmpty())
        delete filts.takeFirst();
    return retstr;
}
Example #30
0
void GetSaveFileFromUser( char *title, char *path, char *okMsg, char *cancelMsg ) {
	// Allow the user to specify a name to save a file - the file need not already
	// exist.
	
	NavDialogCreationOptions dialogOptions;
	NavDialogRef dialog;
	NavReplyRecord replyRecord;
	CFURLRef fileAsCFURLRef = NULL;
	FSRef fileAsFSRef;
	OSStatus status;
	UInt8 output_dir_name[1024];
	UniChar output_filename[255];
	CFIndex len = 255;
	int i,pathlen;
	
	ZFileSpec fs( path );
	//char *debug = fs.getFile();

	
	// Get the standard set of defaults
	status = NavGetDefaultDialogCreationOptions(&dialogOptions);
	require_noerr( status, CantGetNavOptions );
	
	// Make the window app-wide modal
	dialogOptions.modality = kWindowModalityAppModal;
	
	dialogOptions.windowTitle = CFStringCreateWithCString( NULL, title, 0 );
	dialogOptions.saveFileName = CFStringCreateWithCString( NULL, fs.getFile(), 0 ); 
	//dialogOptions.optionFlags |= kNavPreserveSaveFileExtension;
	dialogOptions.optionFlags |= kNavNoTypePopup;
	
	// Create the dialog
	status = NavCreatePutFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, &dialog);
	require_noerr( status, CantCreateDialog );
	
	// Show it
	status = NavDialogRun(dialog);
	require_noerr( status, CantRunDialog );
	
	// Get the reply
	status = NavDialogGetReply(dialog, &replyRecord);
	require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );
	
	// If the user clicked "Cancel", just bail
	if ( status == userCanceledErr ) {
		if( cancelMsg ) {
			zMsgQueue( cancelMsg );
			NavDialogDispose( dialog );
			return;
		}
	}
	
	// Get the file
	status = AEGetNthPtr(&(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	require_noerr( status, CantExtractFSRef );
	
	// Get folder name
	FSRefMakePath( &fileAsFSRef, output_dir_name, 1024 );
	pathlen = strlen( (const char *)output_dir_name );
	output_dir_name[ pathlen++ ] = '/';
	
	
	// Get filename
	len = CFStringGetLength( replyRecord.saveFileName);
	for( i=0; i<len && pathlen < 1023; i++ ) {
		output_dir_name[ pathlen++ ] = CFStringGetCharacterAtIndex( replyRecord.saveFileName, i );
	}
	output_dir_name[ pathlen ] = 0;
	if( okMsg ) {
		zMsgQueue( "%s overwriteExisting=1 osx=1 filespec='%s'", okMsg, escapeQuotes( (char*)output_dir_name ) );
			// on OSX, the confirm to overwrite existing files happens as part of the native dialog 
	}
	
	
	// Cleanup
CantExtractFSRef:
	verify_noerr( NavDisposeReply(&replyRecord) );
CantGetReply:
CantRunDialog:
	NavDialogDispose(dialog);
CantCreateDialog:
CantGetNavOptions:
	return;
}