Merged [21104]: Using NSBundle's methods properly rather than making up our own paths...
[adiumx.git] / Source / AdiumSoundSets.m
blobc05c28460cd5df3a3d40f40f0e9c761b17c37eb9
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "AdiumSoundSets.h"
18 #import "AISoundController.h"
19 #import "AISoundSet.h"
21 #define SOUNDSET_RESOURCE_PATH                  @"Sounds"
23 #define SOUND_PACK_PATHNAME                             @"AdiumSetPathname_Private"
24 #define SOUND_PACK_VERSION                              @"AdiumSetVersion"
25 #define SOUND_NAMES                                             @"Sounds"
26 #define SOUND_SET_PATH_EXTENSION                @"AdiumSoundSet"
28 @implementation AdiumSoundSets
30 /*!
31  * @brief Init
32  */
33 - (id)init {
34         if ((self = [super init])) {
35                 //Create a custom sounds directory ~/Library/Application Support/Adium 2.0/Sounds
36                 [adium createResourcePathForName:SOUNDSET_RESOURCE_PATH];
37         }
38         
39         return self;
42 /*!
43  * @brief Returns all available soundsets
44  *
45  * @return NSArray of AISoundSet objects
46  */
47 - (NSArray *)soundSets
49         NSFileManager   *mgr = [NSFileManager defaultManager];
50     NSMutableArray      *soundSets = [NSMutableArray array];
51         NSEnumerator    *pathEnumerator = [[adium resourcePathsForName:SOUNDSET_RESOURCE_PATH] objectEnumerator];
52     NSString            *path;
53         
54         while ((path = [pathEnumerator nextObject])) {
55                 NSEnumerator    *fileEnumerator = [[mgr directoryContentsAtPath:path] objectEnumerator];
56                 NSString                *file;
57                 
58                 while((file = [fileEnumerator nextObject])){
59                         if([[file pathExtension] caseInsensitiveCompare:SOUND_SET_PATH_EXTENSION] == NSOrderedSame){
60                                 NSString        *fullPath = [path stringByAppendingPathComponent:file];
61                                 AISoundSet      *soundSet = [AISoundSet soundSetWithContentsOfFile:fullPath];
62                                 if (soundSet) {
63                                         [soundSets addObject:soundSet];
64                                 }
65                         }
66                 }
67         }
68     
69     return soundSets;
72 @end