annotate addons/ofxFileDialogOSX/src/ofxFileDialogOSX.cpp @ 0:572c856e38ac

Starting up openFrameworks project for audio time warping. The ofxFileReader goes in addons of your OF folder, the libraries and source (chromogram, fftw and source code src+ timewarp) are probably best kept in the repository, then dragged into the project afresh. That way, as we update the repository, the code that the openFrameworks project looks for will be updated.
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 17 May 2011 08:48:58 +0100
parents
children
rev   line source
andrew@0 1 /*
andrew@0 2 * ofxFileDialogOSX.cpp
andrew@0 3 *
andrew@0 4 * Created by timknapen on 07/05/10.
andrew@0 5 * www.wereldderindianen.be
andrew@0 6 * code stolen from 'mantissa' over here:
andrew@0 7 * http://www.openframeworks.cc/forum/viewtopic.php?p=5028#p5028
andrew@0 8 *
andrew@0 9 */
andrew@0 10
andrew@0 11 #include "ofxFileDialogOSX.h"
andrew@0 12
andrew@0 13
andrew@0 14 //---------------------------------------------------------------------------------
andrew@0 15 int ofxFileDialogOSX::saveFile(string& URL, string& fileURL){
andrew@0 16
andrew@0 17 short fRefNumOut;
andrew@0 18 FSRef output_file;
andrew@0 19 OSStatus err;
andrew@0 20
andrew@0 21 NavDialogCreationOptions options;
andrew@0 22 NavGetDefaultDialogCreationOptions( &options );
andrew@0 23 options.modality = kWindowModalityAppModal;
andrew@0 24
andrew@0 25 NavDialogRef dialog;
andrew@0 26 err = NavCreatePutFileDialog(&options, '.mov', 'Moov', NULL, NULL, &dialog);
andrew@0 27 err = NavDialogRun(dialog);
andrew@0 28
andrew@0 29 NavUserAction action;
andrew@0 30 action = NavDialogGetUserAction( dialog );
andrew@0 31 if (action == kNavUserActionNone || action == kNavUserActionCancel) return 0;
andrew@0 32
andrew@0 33 NavReplyRecord reply;
andrew@0 34 err = NavDialogGetReply(dialog, &reply);
andrew@0 35 if ( err != noErr ) return 0;
andrew@0 36
andrew@0 37 if ( reply.replacing )
andrew@0 38 {
andrew@0 39 printf("need to replace\n");
andrew@0 40 }
andrew@0 41
andrew@0 42 AEKeyword keyword;
andrew@0 43 DescType actual_type;
andrew@0 44 Size actual_size;
andrew@0 45 FSRef output_dir;
andrew@0 46 err = AEGetNthPtr(&(reply.selection), 1, typeFSRef, &keyword, &actual_type,
andrew@0 47 &output_dir, sizeof(output_file), &actual_size);
andrew@0 48
andrew@0 49
andrew@0 50
andrew@0 51 CFURLRef cfUrl = CFURLCreateFromFSRef( kCFAllocatorDefault, &output_dir );
andrew@0 52 CFStringRef cfString = NULL;
andrew@0 53 if ( cfUrl != NULL )
andrew@0 54 {
andrew@0 55 cfString = CFURLCopyFileSystemPath( cfUrl, kCFURLPOSIXPathStyle ); // LEAK?
andrew@0 56 CFRelease( cfUrl );
andrew@0 57 }
andrew@0 58
andrew@0 59 // copy from a CFString into a local c string (http://www.carbondev.com/site/?page=CStrings+)
andrew@0 60 const int kBufferSize = 255;
andrew@0 61
andrew@0 62 char folderURL[kBufferSize];
andrew@0 63 Boolean bool1 = CFStringGetCString(cfString,folderURL,kBufferSize,kCFStringEncodingMacRoman);
andrew@0 64
andrew@0 65 char fileName[kBufferSize];
andrew@0 66 Boolean bool2 = CFStringGetCString(reply.saveFileName,fileName,kBufferSize,kCFStringEncodingMacRoman);
andrew@0 67
andrew@0 68 URL = folderURL;
andrew@0 69 fileURL = fileName;
andrew@0 70 // cleanup dialog
andrew@0 71 NavDialogDispose(dialog);
andrew@0 72 // dispose of reply:
andrew@0 73 NavDisposeReply(&reply);
andrew@0 74 // dispose of cfString
andrew@0 75 CFRelease( cfString );
andrew@0 76
andrew@0 77
andrew@0 78 return 1;
andrew@0 79 }
andrew@0 80
andrew@0 81
andrew@0 82 //---------------------------------------------------------------------------------
andrew@0 83 int ofxFileDialogOSX::openFile(string& URL){
andrew@0 84
andrew@0 85 short fRefNumOut;
andrew@0 86 FSRef output_file;
andrew@0 87 OSStatus err;
andrew@0 88
andrew@0 89 NavDialogCreationOptions options;
andrew@0 90 NavGetDefaultDialogCreationOptions( &options );
andrew@0 91 options.modality = kWindowModalityAppModal;
andrew@0 92 // adding a banner
andrew@0 93 // options.message = CFStringCreateWithCString(kCFAllocatorDefault, "hello world", kCFStringEncodingMacRoman);
andrew@0 94 NavDialogRef dialog;
andrew@0 95
andrew@0 96 err = NavCreateGetFileDialog(&options, NULL, NULL ,NULL, NULL, NULL, &dialog);
andrew@0 97 err = NavDialogRun(dialog);
andrew@0 98
andrew@0 99 NavUserAction action;
andrew@0 100 action = NavDialogGetUserAction( dialog );
andrew@0 101
andrew@0 102 if (action == kNavUserActionNone || action == kNavUserActionCancel) {
andrew@0 103 cout << "no action or action cancel" << endl;
andrew@0 104 return 0;
andrew@0 105 }
andrew@0 106
andrew@0 107 // get dialog reply
andrew@0 108 NavReplyRecord reply;
andrew@0 109 err = NavDialogGetReply(dialog, &reply);
andrew@0 110 if ( err != noErr ){
andrew@0 111 cout << "error getting DialogReply" << endl;
andrew@0 112 return 0;
andrew@0 113 }
andrew@0 114 if ( reply.replacing )
andrew@0 115 {
andrew@0 116 cout << (" need to replace\n ") << endl;
andrew@0 117 }
andrew@0 118
andrew@0 119 AEKeyword keyword;
andrew@0 120 DescType actual_type;
andrew@0 121 Size actual_size;
andrew@0 122 FSRef output_dir;
andrew@0 123 err = AEGetNthPtr(&(reply.selection), 1, typeFSRef, &keyword, &actual_type,
andrew@0 124 &output_dir, sizeof(output_file), &actual_size);
andrew@0 125
andrew@0 126 CFURLRef cfUrl = CFURLCreateFromFSRef( kCFAllocatorDefault, &output_dir );
andrew@0 127 CFStringRef cfString = NULL;
andrew@0 128 if ( cfUrl != NULL )
andrew@0 129 {
andrew@0 130 cfString = CFURLCopyFileSystemPath( cfUrl, kCFURLPOSIXPathStyle );
andrew@0 131 CFRelease( cfUrl );
andrew@0 132 }
andrew@0 133
andrew@0 134 // copy from a CFString into a local c string (http://www.carbondev.com/site/?page=CStrings+)
andrew@0 135 const int kBufferSize = 255;
andrew@0 136
andrew@0 137 char fileURL[kBufferSize];
andrew@0 138 Boolean bool1 = CFStringGetCString(cfString,fileURL,kBufferSize,kCFStringEncodingMacRoman);
andrew@0 139 URL = fileURL;
andrew@0 140 // cleanup dialog
andrew@0 141 NavDialogDispose(dialog);
andrew@0 142 // dispose of reply:
andrew@0 143 NavDisposeReply(&reply);
andrew@0 144 // dispose of cfString
andrew@0 145 CFRelease( cfString );
andrew@0 146 return 1;
andrew@0 147 }