~threeve/ubuntuone-ios-files/polish-and-shine

« back to all changes in this revision

Viewing changes to Files/U1UTIMapper.m

Merged use-proper-uti-functions-duh branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
//  Copyright 2011 Canonical Ltd.
3
 
//      
4
 
//  This program is free software: you can redistribute it and/or modify it
5
 
//  under the terms of the GNU Affero General Public License version 3,
6
 
//  as published by the Free Software Foundation.
7
 
//      
8
 
//  This program is distributed in the hope that it will be useful, but
9
 
//  WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
//  MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
 
//  PURPOSE.  See the GNU Affero General Public License for more details.
12
 
//
13
 
//  You should have received a copy of the GNU Affero General Public License
14
 
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 
16
 
#import "U1UTIMapper.h"
17
 
 
18
 
@interface U1UTIMapper ()
19
 
@property (retain) NSDictionary *mappings;
20
 
@end
21
 
 
22
 
static U1UTIMapper *sharedU1UTIMapper = nil;
23
 
 
24
 
@implementation U1UTIMapper
25
 
 
26
 
@synthesize mappings;
27
 
 
28
 
+ (U1UTIMapper *)sharedU1UTIMapper;
29
 
{
30
 
        if (sharedU1UTIMapper == nil)
31
 
        {
32
 
                sharedU1UTIMapper = [[self alloc] init];
33
 
        }
34
 
        return sharedU1UTIMapper;
35
 
}
36
 
 
37
 
- (id)init;
38
 
{
39
 
        self = [super init];
40
 
        if (self == nil)
41
 
                return nil;
42
 
        self.mappings = [NSDictionary dictionaryWithContentsOfFile:
43
 
                                         [[NSBundle mainBundle] pathForResource:@"uti-mappings" ofType:@"plist"]];
44
 
        return self;
45
 
}
46
 
 
47
 
- (void)dealloc
48
 
{
49
 
        [mappings release];
50
 
    [super dealloc];
51
 
}
52
 
 
53
 
- (NSString *)humanReadableTypeForUTI:(NSString *)uti;
54
 
{
55
 
        return [[self.mappings objectForKey:uti] objectForKey:@"type"];
56
 
}
57
 
 
58
 
- (NSString *)extensionForUTI:(NSString *)uti;
59
 
{
60
 
        return [[self.mappings objectForKey:uti] objectForKey:@"extension"];
61
 
}
62
 
 
63
 
- (NSString *)MIMETypeForUTI:(NSString *)uti;
64
 
{
65
 
        return [[self.mappings objectForKey:uti] objectForKey:@"mimetype"];
66
 
}
67
 
 
68
 
@end