Ignore:
Timestamp:
11/23/07 04:58:05 (16 years ago)
Author:
Nicholas Riley
Message:

English.lproj/MainMenu.nib: Modernize menu and alarm set dialog
layout. Use keyed archiving (10.2+) nib format.

Info-Pester.plist: Moved from old PBX project.

NJRFSObjectSelector.m: Bug fixes from code sent to Joey: remove
incorrect usage of tryToPerform:with:; fix logic error in menu
construction. Work around Cocoa's deciding that the menu font size
needs adjustment when it doesn't - so the menu font size now matches
the button font size, though the position is still off. Don't pop up
a menu if we're disabled. Use IconRefs for menu icons, though not
(yet) for the button icon.

NJRHistoryTrackingComboBox.m: Remove item height adjustment
workaround; it now makes the items too tall.

NJRHotKey.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyField.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyManager.m: Add a missing [super dealloc] caught by current
GCC.

NJRIntervalField.m: Fix some type errors.

NJRQTMediaPopUpButton.m: Replace SoundFileManager SPI usage, which
doesn't work in Leopard anyway, with manual enumeration of system
sounds. Start migration to QTKit. Use IconRefs for menu icons.

NJRReadMeController.m: Change source encoding to UTF-8.

NJRSoundManager.m: Fix a type error.

NJRVoicePopUpButton.m: Change source encoding to UTF-8.

NSMenuItem-NJRExtensions.[hm]: Code from ICeCoffEE to use IconRefs for
menu item icons.

PSAlarm.m: Change source encoding to UTF-8.

PSAlarms.m: Fix a signedness mismatch.

PSAlarmsController.m: Change source encoding to UTF-8.

PSAlarmSetController.m: Set keyboard focus after unchecking "Do
script:" and "Play" checkboxes.

PSAlerts.m: Add a missing [super dealloc] caught by current GCC. Fix
a memory leak in property list serialization.

PSPowerManager.[hm]: There's now API for scheduling wakeups; use it
(the old code asserted on startup). To fix: removing scheduled
wakeup. Fix a small type-checking error.

PSPreferencesController.m: Add a missing [super dealloc] caught by
current GCC.

PSScriptAlert.m: Change source encoding to UTF-8.

PSTimeDateEditor.m: Fix a tiny, and one-time, memory leak.

PSTimer.m: Update for new PSPowerManager API.

Pester.pbproj: Deleted; now supporting OS X 10.4+ (up from 10.1,
aiee.)

Pester.xcodeproj: Xcode 2.4+ project, upgraded targets, etc.

SoundFileManager.h: Deleted; this SPI no longer exists in Leopard and
possibly earlier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m

    r133 r355  
    88
    99#import "NJRQTMediaPopUpButton.h"
    10 #import "SoundFileManager.h"
    1110#import "NJRSoundManager.h"
    1211#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>
    2118
    2219static const int NJRQTMediaPopUpButtonMaxRecentItems = 10;
     
    6663    [item setTarget: self];
    6764    [item setRepresentedObject: alias];
    68     [item setImage: [[[NSWorkspace sharedWorkspace] iconForFile: path] bestFitImageForSize: NSMakeSize(16, 16)]];
     65    [item setImageFromPath: path];
    6966    [recentMediaAliasData addObject: [alias aliasData]];
    7067    if ([recentMediaAliasData count] > NJRQTMediaPopUpButtonMaxRecentItems) {
     
    115112- (void)_setUp;
    116113{
    117     NSMenu *menu;
    118     NSMenuItem *item;
    119     SoundFileManager *sfm = [SoundFileManager sharedSoundFileManager];
    120     int soundCount = [sfm count];
    121 
     114    NSMenu *menu = [self menu];
    122115    [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: @""];
    125119    [item setTarget: self];
    126120    [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) {
    128169        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: @""];
    129170        [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         
    142173    [menu addItem: [NSMenuItem separatorItem]];
    143174    item = [menu addItemWithTitle: NSLocalizedString(@"Other...", "Media popup item to select another sound/movie/image") action: @selector(select:) keyEquivalent: @""];
     
    212243- (NSMenuItem *)_itemForAlias:(BDAlias *)alias;
    213244{
    214     NSString *path;
    215     SoundFile *sf;
    216     if (alias == nil) {
    217         return [self itemAtIndex: 0];
    218     }
     245    if (alias == nil) return [self itemAtIndex: 0];
    219246
    220247    // [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];
    234249
    235250    // selected a system sound?
    236     if (sf != nil) {
     251    int itemIndex = [[self menu] indexOfItemWithRepresentedObject: path];
     252    if (itemIndex != -1) {
    237253        // NSLog(@"_itemForAlias: selected system sound");
    238         return [self itemAtIndex: [self indexOfItemWithRepresentedObject: sf]];
     254        return [self itemAtIndex: itemIndex];
    239255    } else {
    240256        NSEnumerator *e = [recentMediaAliasData reverseObjectEnumerator];
     
    406422}
    407423
    408 - (void)_soundFileSelected:(NSMenuItem *)sender;
    409 {
    410     [self _setPath: [(SoundFile *)[sender representedObject] path]];
     424- (void)_systemSoundSelected:(NSMenuItem *)sender;
     425{
     426    [self _setPath: [sender representedObject]];
    411427    if (![self _validateWithPreview: YES]) {
    412428        [[self menu] removeItem: sender];
Note: See TracChangeset for help on using the changeset viewer.