iSightを使ってBooklog,MediaMarkerインポート用CSVファイルを生成するアプリ
Revision | e9e7cdedf9e5412fbce49efd2ba2a4a1ad8fdd63 (tree) |
---|---|
Time | 2011-04-10 09:11:52 |
Author | masakih <masakih@user...> |
Commiter | masakih |
[Mod] 開くサイトをUserDefaultsに保存するようにした。
@@ -37,10 +37,7 @@ static NSArray *attributes = nil; | ||
37 | 37 | while((aType = types[i++]) != NSUIntegerMax) { |
38 | 38 | // |
39 | 39 | BEExporterAttribute *attr = [[[BEExporterAttribute alloc] init] autorelease]; |
40 | - attr.type = aType; | |
41 | - // restore from UserDefaults | |
42 | -#warning MUST IMPLEMENT | |
43 | - | |
40 | + attr.type = aType; | |
44 | 41 | if(!attr.site) { |
45 | 42 | attr.site = [[BERegisterSite sites] objectAtIndex:0]; |
46 | 43 | } |
@@ -100,4 +97,12 @@ static NSArray *attributes = nil; | ||
100 | 97 | [aCoder encodeBool:isOpenAfterExport forKey:@"BEExpoterIsOpenAfterExport"]; |
101 | 98 | [aCoder encodeObject:site forKey:@"BEExporterSite"]; |
102 | 99 | } |
100 | + | |
101 | + | |
102 | +- (id)description | |
103 | +{ | |
104 | + return [NSString stringWithFormat: | |
105 | + @"Type->%d, open->%@, Site->%@", | |
106 | + type, isOpenAfterExport ? @"YES":@"NO", site]; | |
107 | +} | |
103 | 108 | @end |
@@ -12,6 +12,11 @@ | ||
12 | 12 | #import "BEExporterAttribute.h" |
13 | 13 | |
14 | 14 | |
15 | +@interface BEGeneralPreference (BEPrivate) | |
16 | +- (void)restoreAttributes; | |
17 | +- (void)setSelection:(id)newSelection; | |
18 | +@end | |
19 | + | |
15 | 20 | @implementation BEGeneralPreference |
16 | 21 | |
17 | 22 | - (id)init |
@@ -20,12 +25,8 @@ | ||
20 | 25 | if(self) { |
21 | 26 | [self setTitle:NSLocalizedString(@"General", @"General")]; |
22 | 27 | sites = [[BERegisterSite sites] retain]; |
23 | - attributes = [[BEExporterAttribute attribtues] retain]; | |
24 | - selection = [BEPreference preference].openSite; | |
25 | - if(!selection) { | |
26 | - selection = [attributes objectAtIndex:0]; | |
27 | - } | |
28 | - [selection retain]; | |
28 | + [self restoreAttributes]; | |
29 | + [self setSelection:[attributes objectAtIndex:0]]; | |
29 | 30 | } |
30 | 31 | return self; |
31 | 32 | } |
@@ -33,18 +34,56 @@ | ||
33 | 34 | { |
34 | 35 | [sites release]; |
35 | 36 | [attributes release]; |
36 | - [selection retain]; | |
37 | + [self setSelection:nil]; | |
37 | 38 | [super dealloc]; |
38 | 39 | } |
39 | 40 | |
41 | +- (void)restoreAttributes | |
42 | +{ | |
43 | + NSArray *stored = [BEPreference preference].attributes; | |
44 | + if(!stored) { | |
45 | + attributes = [[BEExporterAttribute attribtues] retain]; | |
46 | + return; | |
47 | + } | |
48 | + | |
49 | + NSArray *origin = [BEExporterAttribute attribtues]; | |
50 | + if([origin isEqual:stored]) { | |
51 | + attributes = [stored retain]; | |
52 | + return; | |
53 | + } | |
54 | + | |
55 | + NSMutableArray *array = [stored mutableCopy]; | |
56 | + for(id obj in origin) { | |
57 | + if(![array containsObject:obj]) { | |
58 | + [array addObject:obj]; | |
59 | + } | |
60 | + } | |
61 | + attributes = [[NSArray alloc] initWithArray:array]; | |
62 | +} | |
63 | + | |
64 | + | |
40 | 65 | - (void)setSelection:(id)newSelection |
41 | 66 | { |
42 | 67 | if(selection == newSelection) return; |
68 | + | |
69 | + if(selection) { | |
70 | + [selection removeObserver:self forKeyPath:@"isOpenAfterExport"]; | |
71 | + [selection removeObserver:self forKeyPath:@"site"]; | |
72 | + } | |
43 | 73 | id temp = selection; |
44 | 74 | selection = [newSelection retain]; |
45 | 75 | [temp release]; |
46 | 76 | |
47 | - [BEPreference preference].openSite = selection; | |
77 | + [selection addObserver:self forKeyPath:@"isOpenAfterExport" options:0 context:NULL]; | |
78 | + [selection addObserver:self forKeyPath:@"site" options:0 context:NULL]; | |
79 | +} | |
80 | +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context | |
81 | +{ | |
82 | + if(![keyPath isEqualToString:@"isOpenAfterExport"] && ![keyPath isEqualToString:@"site"]) { | |
83 | + return [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; | |
84 | + } | |
85 | + | |
86 | + [BEPreference preference].attributes = attributes; | |
48 | 87 | } |
49 | 88 | |
50 | 89 | - (NSString *)iconName |
@@ -12,13 +12,9 @@ | ||
12 | 12 | extern NSString *const BEOpenAfterExported; // NSNumber of BOOL. |
13 | 13 | extern NSString *const BEOpenSite; // BERegisterSite. |
14 | 14 | |
15 | - | |
16 | -@class BERegisterSite; | |
17 | - | |
18 | 15 | @interface BEPreference : NSObject |
19 | 16 | |
20 | 17 | + (BEPreference *)preference; |
21 | 18 | |
22 | -@property (getter=isOpenAfterExport) BOOL openAfterExport; | |
23 | -@property (nonatomic, retain) BERegisterSite *openSite; | |
19 | +@property (nonatomic, retain) NSArray *attributes; | |
24 | 20 | @end |
@@ -12,7 +12,7 @@ | ||
12 | 12 | NSString *const BEOpenAfterExported = @"openAfterExported"; |
13 | 13 | NSString *const BEOpenSite = @"targetSite"; |
14 | 14 | |
15 | - | |
15 | +static NSString *const BESiteOpenAttributes = @"SiteOpenAttributes"; | |
16 | 16 | |
17 | 17 | @implementation BEPreference |
18 | 18 | static BEPreference *sharedInstance = nil; |
@@ -36,25 +36,16 @@ static BEPreference *sharedInstance = nil; | ||
36 | 36 | [ud setObject:object forKey:key]; |
37 | 37 | } |
38 | 38 | |
39 | -- (BOOL)isOpenAfterExport | |
40 | -{ | |
41 | - id val = [self objectForKey:BEOpenAfterExported]; | |
42 | - return [val boolValue]; | |
43 | -} | |
44 | -- (void)setOpenAfterExport:(BOOL)flag | |
39 | +- (NSArray *)attributes | |
45 | 40 | { |
46 | - [self setObject:[NSNumber numberWithBool:flag] | |
47 | - forKey:BEOpenAfterExported]; | |
48 | -} | |
49 | - | |
50 | -- (BERegisterSite *)openSite | |
51 | -{ | |
52 | - id data = [self objectForKey:BEOpenSite]; | |
41 | + NSData *data = [self objectForKey:BESiteOpenAttributes]; | |
42 | + if(!data) return nil; | |
53 | 43 | return [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
54 | 44 | } |
55 | -- (void)setOpenSite:(BERegisterSite *)site | |
45 | +- (void)setAttributes:(NSArray *)attributes | |
56 | 46 | { |
57 | - id data = [NSKeyedArchiver archivedDataWithRootObject:site]; | |
58 | - [self setObject:data forKey:BEOpenSite]; | |
47 | + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:attributes]; | |
48 | + [self setObject:data forKey:BESiteOpenAttributes]; | |
59 | 49 | } |
50 | + | |
60 | 51 | @end |
@@ -130,4 +130,11 @@ static NSArray *sSites = nil; | ||
130 | 130 | [aCoder encodeObject:account forKey:@"account"]; |
131 | 131 | } |
132 | 132 | |
133 | +- (id)description | |
134 | +{ | |
135 | + return [NSString stringWithFormat: | |
136 | + @"Name->%@, Home->%@, Reg->%@, id->%@, ac->%@", | |
137 | + name, home, registerPage, needID, account]; | |
138 | +} | |
139 | + | |
133 | 140 | @end |