iSightを使ってBooklog,MediaMarkerインポート用CSVファイルを生成するアプリ
Revision | 51917f07f6a13303b7b54c84e74c07500fe2782f (tree) |
---|---|
Time | 2011-03-01 21:18:18 |
Author | masakih <masakih@user...> |
Commiter | masakih |
[New] booklog形式でのエクスポートに対応。
@@ -7,8 +7,82 @@ | ||
7 | 7 | // |
8 | 8 | |
9 | 9 | #import "BEBooklogBooksExporter.h" |
10 | -#import "MyBookInformation.h" | |
10 | +#import "BEBookInformation.h" | |
11 | 11 | |
12 | 12 | |
13 | 13 | @implementation BEBooklogBooksExporter |
14 | +NSString *normalizeString(NSString *string) | |
15 | +{ | |
16 | + if(!string) return @""; | |
17 | + if([string isKindOfClass:[NSAttributedString class]]) { | |
18 | + string = [(NSAttributedString *)string string]; | |
19 | + } | |
20 | + return string; | |
21 | +} | |
22 | +- (NSString *)statusNameWithBook:(BEBookInformation *)book | |
23 | +{ | |
24 | + NSString *result = nil; | |
25 | + switch([book.status intValue]) { | |
26 | + case 0: | |
27 | + result = @"-"; | |
28 | + break; | |
29 | + case 1: | |
30 | + result = NSLocalizedString(@"Want read", @"Want read"); | |
31 | + break; | |
32 | + case 2: | |
33 | + result = NSLocalizedString(@"Now reading", @"Now reading"); | |
34 | + break; | |
35 | + case 3: | |
36 | + result = NSLocalizedString(@"Already read", @"Already read"); | |
37 | + break; | |
38 | + case 4: | |
39 | + result = NSLocalizedString(@"Stack", @"Stack"); | |
40 | + break; | |
41 | + default: | |
42 | + return @""; | |
43 | + } | |
44 | + return result; | |
45 | +} | |
46 | +- (BOOL)exportToURL:(NSURL *)url | |
47 | +{ | |
48 | + NSMutableArray *array = [NSMutableArray array]; | |
49 | + NSDateFormatter *dateFormatter01 = [[[NSDateFormatter alloc] init] autorelease]; | |
50 | + [dateFormatter01 setDateFormat:@"YYYY-MM-dd' 'HH':'mm':'ss"]; | |
51 | + NSDateFormatter *dateFormatter02 = [[[NSDateFormatter alloc] init] autorelease]; | |
52 | + [dateFormatter02 setDateFormat:@"YYYY"]; | |
53 | + for(BEBookInformation *book in books) { | |
54 | + NSString *line = [NSString stringWithFormat: | |
55 | + @"%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@", | |
56 | + normalizeString(book.asin), | |
57 | + normalizeString(book.isbn), | |
58 | + normalizeString(book.title), | |
59 | + normalizeString(book.author), | |
60 | + normalizeString(book.manufacturer), | |
61 | + normalizeString([dateFormatter02 stringFromDate:book.publicationDate]), | |
62 | + normalizeString(@"Books"), | |
63 | + normalizeString(book.category), | |
64 | + normalizeString([book.rating stringValue]), | |
65 | + normalizeString(book.review), | |
66 | + normalizeString([self statusNameWithBook:book]), | |
67 | + normalizeString([dateFormatter01 stringFromDate:book.readDate]), | |
68 | + normalizeString([dateFormatter01 stringFromDate:book.registerDate])]; | |
69 | + [array addObject:line]; | |
70 | + } | |
71 | + if([array count] == 0) return NO; | |
72 | + | |
73 | + NSString *lines = [array componentsJoinedByString:@"\r\n"]; | |
74 | + NSError *error = nil; | |
75 | + BOOL isOK = NO; | |
76 | + isOK = [lines writeToURL:url atomically:YES encoding:NSShiftJISStringEncoding error:&error]; | |
77 | + if(!isOK) { | |
78 | + NSString *errorString = nil; | |
79 | + if(error) { | |
80 | + errorString = [error localizedDescription]; | |
81 | + } | |
82 | + NSLog(@"Error exporting -> %@", errorString); | |
83 | + return NO; | |
84 | + } | |
85 | + return YES; | |
86 | +} | |
87 | + | |
14 | 88 | @end |
@@ -9,6 +9,7 @@ | ||
9 | 9 | #import "BEBooksExporter.h" |
10 | 10 | |
11 | 11 | #import "BEBooklogBooksExporter.h" |
12 | +#import "BEMediaMarkerBooksExporter.h" | |
12 | 13 | |
13 | 14 | |
14 | 15 | @implementation BEBooksExporter |
@@ -21,6 +22,9 @@ | ||
21 | 22 | case 0: |
22 | 23 | createClass = [BEBooklogBooksExporter class]; |
23 | 24 | break; |
25 | + case 1: | |
26 | + createClass = [BEMediaMarkerBooksExporter class]; | |
27 | + break; | |
24 | 28 | } |
25 | 29 | |
26 | 30 | if(!createClass) return nil; |
@@ -317,8 +317,6 @@ | ||
317 | 317 | children = ( |
318 | 318 | F44EEB4A131A7E0F00CAA969 /* Base64EncDec.h */, |
319 | 319 | F44EEB4B131A7E0F00CAA969 /* Base64EncDec.m */, |
320 | - F44EEAD3131A5ECE00CAA969 /* BEAmazonLookup.h */, | |
321 | - F44EEAD4131A5ECE00CAA969 /* BEAmazonLookup.m */, | |
322 | 320 | 05B708550D12DA11004E1545 /* MyBarcodeScanner.h */, |
323 | 321 | 05B708560D12DA11004E1545 /* MyBarcodeScanner.m */, |
324 | 322 | 05B708530D12D9F3004E1545 /* SampleCIView.h */, |
@@ -330,6 +328,8 @@ | ||
330 | 328 | 05FC63710DF401F80087B320 /* Old Sequence Grabber */, |
331 | 329 | 05D5F68A0AFB9AF7005A12B0 /* MyGraphView.h */, |
332 | 330 | 05D5F68B0AFB9AF7005A12B0 /* MyGraphView.m */, |
331 | + F44EEAD3131A5ECE00CAA969 /* BEAmazonLookup.h */, | |
332 | + F44EEAD4131A5ECE00CAA969 /* BEAmazonLookup.m */, | |
333 | 333 | F44EEAB2131A562F00CAA969 /* BEBookInformation.h */, |
334 | 334 | F44EEAB3131A562F00CAA969 /* BEBookInformation.m */, |
335 | 335 | F44EEB17131A752500CAA969 /* BEAmazonSignatureGenerator.h */, |