Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sounds: Changed sounds list from static array to function that searches ... #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions Classes/Dialogs/Preferences/PreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,43 @@ - (void)keyRecorderDidChangeKey:(KeyRecorder*)sender

- (NSArray*)availableSounds
{
static NSArray* ary;
if (!ary) {
ary = [[NSArray arrayWithObjects:@"-", @"Beep", @"Basso", @"Blow", @"Bottle", @"Frog", @"Funk", @"Glass", @"Hero", @"Morse", @"Ping", @"Pop", @"Purr", @"Sosumi", @"Submarine", @"Tink", nil] retain];
NSMutableSet * soundFiles = [NSMutableSet set];

NSFileManager * fm = [NSFileManager defaultManager];

NSString * SytemSoundFiles = @"/System/Library/Sounds";

NSString * RootLibrarySoundFiles = @"/Library/Sounds";

NSString * UserSoundFiles = @"~/Library/Sounds";

NSError* error = nil;

UserSoundFiles = [UserSoundFiles stringByExpandingTildeInPath];

for (NSString * file in [fm contentsOfDirectoryAtPath:RootLibrarySoundFiles error: &error])
{
if (![file isEqualToString:@".DS_Store"])
[soundFiles addObject:[file stringByDeletingPathExtension]];
}

for (NSString * file in [fm contentsOfDirectoryAtPath:SytemSoundFiles error: &error])
{
if (![file isEqualToString:@".DS_Store"])
[soundFiles addObject:[file stringByDeletingPathExtension]];
}

for (NSString * file in [fm contentsOfDirectoryAtPath:UserSoundFiles error: &error])
{
if (![file isEqualToString:@".DS_Store"])
[soundFiles addObject:[file stringByDeletingPathExtension]];
}

if(error != nil) {
NSLog(@"Error in reading files: %@", [error localizedDescription]);
}
return ary;

return [[soundFiles allObjects] sortedArrayUsingSelector:@selector(compare:)];
}

- (NSMutableArray*)sounds
Expand Down