Ignore:
Timestamp:
Aug 7, 2006, 2:28:31 AM (16 years ago)
Author:
livings124
Message:

User can now choose the sound that plays.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PrefsController.m

    r734 r735  
    193193   
    194194    //set play sound
    195     [fPlayDownloadSoundCheck setState: [fDefaults boolForKey: @"PlayDownloadSound"]];
    196     [fPlaySeedingSoundCheck setState: [fDefaults boolForKey: @"PlaySeedingSound"]];
     195    NSMutableArray * sounds = [NSMutableArray array];
     196    NSEnumerator * soundEnumerator,
     197                * soundDirectoriesEnumerator = [[NSArray arrayWithObjects: @"System/Library/Sounds", @"Library/Sounds",
     198                        [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Sounds"], nil] objectEnumerator];
     199    NSString * soundPath, * sound;
     200   
     201    //get list of all sounds and sort alphabetically
     202    while ((soundPath = [soundDirectoriesEnumerator nextObject]))
     203        if (soundEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: soundPath])
     204            while ((sound = [soundEnumerator nextObject]))
     205            {
     206                sound = [sound stringByDeletingPathExtension];
     207                if ([NSSound soundNamed: sound])
     208                    [sounds addObject: sound];
     209            }
     210   
     211    [sounds sortUsingSelector: @selector(caseInsensitiveCompare:)];
     212   
     213    //set download sound
     214    [fDownloadSoundPopUp removeAllItems];
     215    [fDownloadSoundPopUp addItemsWithTitles: sounds];
     216   
     217    BOOL playDownloadSound = [fDefaults boolForKey: @"PlayDownloadSound"];
     218    [fPlayDownloadSoundCheck setState: playDownloadSound];
     219    [fDownloadSoundPopUp setEnabled: playDownloadSound];
     220   
     221    int downloadSoundIndex = [fDownloadSoundPopUp indexOfItemWithTitle: [fDefaults stringForKey: @"DownloadSound"]];
     222    if (downloadSoundIndex >= 0)
     223        [fDownloadSoundPopUp selectItemAtIndex: downloadSoundIndex];
     224    else
     225        [fDefaults setObject: [fDownloadSoundPopUp titleOfSelectedItem] forKey: @"DownloadSound"];
     226   
     227    //set seeding sound
     228    [fSeedingSoundPopUp removeAllItems];
     229    [fSeedingSoundPopUp addItemsWithTitles: sounds];
     230   
     231    BOOL playSeedingSound = [fDefaults boolForKey: @"PlaySeedingSound"];
     232    [fPlaySeedingSoundCheck setState: playSeedingSound];
     233    [fSeedingSoundPopUp setEnabled: playSeedingSound];
     234   
     235    int seedingSoundIndex = [fDownloadSoundPopUp indexOfItemWithTitle: [fDefaults stringForKey: @"SeedingSound"]];
     236    if (seedingSoundIndex >= 0)
     237        [fSeedingSoundPopUp selectItemAtIndex: seedingSoundIndex];
     238    else
     239        [fDefaults setObject: [fSeedingSoundPopUp titleOfSelectedItem] forKey: @"SeedingSound"];
    197240   
    198241    //set start setting
     
    517560- (void) setPlaySound: (id) sender
    518561{
     562    BOOL state = [sender state];
     563
    519564    if (sender == fPlayDownloadSoundCheck)
    520         [fDefaults setBool: [sender state] forKey: @"PlayDownloadSound"];
     565    {
     566        [fDownloadSoundPopUp setEnabled: state];
     567        [fDefaults setBool: state forKey: @"PlayDownloadSound"];
     568    }
    521569    else if (sender == fPlaySeedingSoundCheck)
    522         [fDefaults setBool: [sender state] forKey: @"PlaySeedingSound"];
     570    {
     571        [fSeedingSoundPopUp setEnabled: state];
     572        [fDefaults setBool: state forKey: @"PlaySeedingSound"];
     573    }
     574    else;
     575}
     576
     577- (void) setSound: (id) sender
     578{
     579    //play sound when selecting
     580    NSString * soundName = [sender titleOfSelectedItem];
     581    NSSound * sound;
     582    if ((sound = [NSSound soundNamed: soundName]))
     583        [sound play];
     584
     585    if (sender == fDownloadSoundPopUp)
     586        [fDefaults setObject: soundName forKey: @"DownloadSound"];
     587    else if (sender == fSeedingSoundPopUp)
     588        [fDefaults setObject: soundName forKey: @"SeedingSound"];
    523589    else;
    524590}
Note: See TracChangeset for help on using the changeset viewer.