Changeset 355 for trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
- Timestamp:
- 11/23/07 04:58:05 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
r133 r355 8 8 9 9 #import "NJRQTMediaPopUpButton.h" 10 #import "SoundFileManager.h"11 10 #import "NJRSoundManager.h" 12 11 #import "NSMovie-NJRExtensions.h" 13 #import "NSImage-NJRExtensions.h" 14 #import <QuickTime/Movies.h> 15 16 // XXX workaround for SoundFileManager log message in 10.2.3 and earlier 17 #include <stdio.h> 18 #include <unistd.h> 19 #include <fcntl.h> 20 // XXX end workaround 12 #import "NSMenuItem-NJRExtensions.h" 13 14 #import <QTKit/QTKit.h> 15 16 #include <QuickTime/Movies.h> 17 #include <limits.h> 21 18 22 19 static const int NJRQTMediaPopUpButtonMaxRecentItems = 10; … … 66 63 [item setTarget: self]; 67 64 [item setRepresentedObject: alias]; 68 [item setImage : [[[NSWorkspace sharedWorkspace] iconForFile: path] bestFitImageForSize: NSMakeSize(16, 16)]];65 [item setImageFromPath: path]; 69 66 [recentMediaAliasData addObject: [alias aliasData]]; 70 67 if ([recentMediaAliasData count] > NJRQTMediaPopUpButtonMaxRecentItems) { … … 115 112 - (void)_setUp; 116 113 { 117 NSMenu *menu; 118 NSMenuItem *item; 119 SoundFileManager *sfm = [SoundFileManager sharedSoundFileManager]; 120 int soundCount = [sfm count]; 121 114 NSMenu *menu = [self menu]; 122 115 [self removeAllItems]; 123 menu = [self menu]; 124 item = [menu addItemWithTitle: @"Alert sound" action: @selector(_beepSelected:) keyEquivalent: @""]; 116 [menu setAutoenablesItems: NO]; 117 118 NSMenuItem *item = [menu addItemWithTitle: @"Alert sound" action: @selector(_beepSelected:) keyEquivalent: @""]; 125 119 [item setTarget: self]; 126 120 [menu addItem: [NSMenuItem separatorItem]]; 127 if (soundCount == 0) { 121 122 NSMutableArray *soundFolderPaths = [[NSMutableArray alloc] initWithCapacity: kLastDomainConstant - kSystemDomain + 1]; 123 for (FSVolumeRefNum domain = kSystemDomain ; domain <= kLastDomainConstant ; domain++) { 124 OSStatus err; 125 FSRef fsr; 126 err = FSFindFolder(domain, kSystemSoundsFolderType, false, &fsr); 127 if (err != noErr) continue; 128 129 UInt8 path[PATH_MAX]; 130 err = FSRefMakePath(&fsr, path, PATH_MAX); 131 if (err != noErr) continue; 132 133 CFStringRef pathString = CFStringCreateWithFileSystemRepresentation(NULL, (const char *)path); 134 if (pathString == NULL) continue; 135 136 [soundFolderPaths addObject: (NSString *)pathString]; 137 CFRelease(pathString); 138 } 139 NSFileManager *fm = [NSFileManager defaultManager]; 140 NSEnumerator *e = [soundFolderPaths objectEnumerator]; 141 NSString *folderPath; 142 while ( (folderPath = [e nextObject]) != nil) { 143 if (![fm changeCurrentDirectoryPath: folderPath]) continue; 144 145 NSDirectoryEnumerator *de = [fm enumeratorAtPath: folderPath]; 146 NSString *path; 147 while ( (path = [de nextObject]) != nil) { 148 BOOL isDir; 149 if (![fm fileExistsAtPath: path isDirectory: &isDir] || isDir) { 150 [de skipDescendents]; 151 continue; 152 } 153 154 if (![QTMovie canInitWithFile: path]) continue; 155 156 item = [menu addItemWithTitle: [fm displayNameAtPath: path] 157 action: @selector(_systemSoundSelected:) 158 keyEquivalent: @""]; 159 [item setTarget: self]; 160 [item setImageFromPath: path]; 161 path = [folderPath stringByAppendingPathComponent: path]; 162 [item setRepresentedObject: path]; 163 [item setToolTip: path]; 164 } 165 } 166 [soundFolderPaths release]; 167 168 if ([menu numberOfItems] == 2) { 128 169 item = [menu addItemWithTitle: NSLocalizedString(@"Can't locate alert sounds", "QuickTime media popup menu item surrogate for alert sound list if no sounds are found") action: nil keyEquivalent: @""]; 129 170 [item setEnabled: NO]; 130 } else { 131 SoundFile *sf; 132 int i; 133 [sfm sortByName]; 134 for (i = 0 ; i < soundCount ; i++) { 135 sf = [sfm soundFileAtIndex: i]; 136 item = [menu addItemWithTitle: [sf name] action: @selector(_soundFileSelected:) keyEquivalent: @""]; 137 [item setTarget: self]; 138 [item setRepresentedObject: sf]; 139 [item setImage: [[[NSWorkspace sharedWorkspace] iconForFile: [sf path]] bestFitImageForSize: NSMakeSize(16, 16)]]; 140 } 141 } 171 } 172 142 173 [menu addItem: [NSMenuItem separatorItem]]; 143 174 item = [menu addItemWithTitle: NSLocalizedString(@"Other...", "Media popup item to select another sound/movie/image") action: @selector(select:) keyEquivalent: @""]; … … 212 243 - (NSMenuItem *)_itemForAlias:(BDAlias *)alias; 213 244 { 214 NSString *path; 215 SoundFile *sf; 216 if (alias == nil) { 217 return [self itemAtIndex: 0]; 218 } 245 if (alias == nil) return [self itemAtIndex: 0]; 219 246 220 247 // [self _validateRecentMedia]; 221 path = [alias fullPath]; 222 { // XXX suppress log message from Apple's code: 223 // 2002-12-14 14:09:58.740 Pester[26529] Could not find sound type for directory /Users/nicholas/Desktop 224 int errfd = dup(STDERR_FILENO), nullfd = open("/dev/null", O_WRONLY, 0); 225 // need to have something open in STDERR_FILENO because if it isn't, 226 // NSLog will log to /dev/console 227 dup2(nullfd, STDERR_FILENO); 228 close(nullfd); 229 sf = [[SoundFileManager sharedSoundFileManager] soundFileFromPath: path]; 230 dup2(errfd, STDERR_FILENO); 231 close(errfd); 232 } 233 // NSLog(@"_itemForAlias: %@", path); 248 NSString *path = [alias fullPath]; 234 249 235 250 // selected a system sound? 236 if (sf != nil) { 251 int itemIndex = [[self menu] indexOfItemWithRepresentedObject: path]; 252 if (itemIndex != -1) { 237 253 // NSLog(@"_itemForAlias: selected system sound"); 238 return [self itemAtIndex: [self indexOfItemWithRepresentedObject: sf]];254 return [self itemAtIndex: itemIndex]; 239 255 } else { 240 256 NSEnumerator *e = [recentMediaAliasData reverseObjectEnumerator]; … … 406 422 } 407 423 408 - (void)_s oundFileSelected:(NSMenuItem *)sender;409 { 410 [self _setPath: [ (SoundFile *)[sender representedObject] path]];424 - (void)_systemSoundSelected:(NSMenuItem *)sender; 425 { 426 [self _setPath: [sender representedObject]]; 411 427 if (![self _validateWithPreview: YES]) { 412 428 [[self menu] removeItem: sender];
Note:
See TracChangeset
for help on using the changeset viewer.