• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

iSightを使ってBooklog,MediaMarkerインポート用CSVファイルを生成するアプリ


Commit MetaInfo

Revisiona5834c348c167ec8d93cd079dad2ed11fc4d76c9 (tree)
Time2011-03-01 23:43:02
Authormasakih <masakih@user...>
Commitermasakih

Log Message

[Mod] 登録データをCoreDataで保存するようにした。

Change Summary

Incremental Difference

--- a/BEApplicationDelegate.h
+++ b/BEApplicationDelegate.h
@@ -12,7 +12,13 @@
1212
1313 @interface BEApplicationDelegate : NSObject
1414 {
15+ NSPersistentStoreCoordinator *persistentStoreCoordinator;
16+ NSManagedObjectModel *managedObjectModel;
17+ NSManagedObjectContext *managedObjectContext;
18+
1519 BEMainWindowController *mainWindowContoller;
1620 }
1721
22+- (NSManagedObjectContext *)managedObjectContext;
23+
1824 @end
--- a/BEApplicationDelegate.m
+++ b/BEApplicationDelegate.m
@@ -10,6 +10,168 @@
1010
1111
1212 @implementation BEApplicationDelegate
13+/**
14+ Returns the support folder for the application, used to store the Core Data
15+ store file. This code uses a folder named "XspfManager" for
16+ the content, either in the NSApplicationSupportDirectory location or (if the
17+ former cannot be found), the system's temporary directory.
18+ */
19+
20+- (NSString *)applicationSupportFolder
21+{
22+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
23+ NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
24+ return [basePath stringByAppendingPathComponent:@"BooksExporter"];
25+}
26+
27+/**
28+ Creates, retains, and returns the managed object model for the application
29+ by merging all of the models found in the application bundle.
30+ */
31+
32+- (NSManagedObjectModel *)managedObjectModel
33+{
34+ if(managedObjectModel != nil) {
35+ return managedObjectModel;
36+ }
37+
38+ managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
39+ // HMLog(HMLogLevelDebug, @"ManagedObjectModel -> %@", managedObjectModel);
40+ return managedObjectModel;
41+}
42+
43+- (NSURL *)storeURL
44+{
45+ NSFileManager *fileManager;
46+ NSString *applicationSupportFolder = nil;
47+ NSURL *url;
48+
49+ fileManager = [NSFileManager defaultManager];
50+ applicationSupportFolder = [self applicationSupportFolder];
51+ if(![fileManager fileExistsAtPath:applicationSupportFolder isDirectory:NULL]) {
52+ [fileManager createDirectoryAtPath:applicationSupportFolder attributes:nil];
53+ }
54+
55+ url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"BooksExporter.qdb"]];
56+
57+ return url;
58+}
59+
60+/**
61+ Returns the persistent store coordinator for the application. This
62+ implementation will create and return a coordinator, having added the
63+ store for the application to it. (The folder for the store is created,
64+ if necessary.)
65+ */
66+
67+- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
68+{
69+ if(persistentStoreCoordinator != nil) {
70+ return persistentStoreCoordinator;
71+ }
72+
73+ NSError *error;
74+
75+ NSURL *url = [self storeURL];
76+
77+ persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
78+ if(!persistentStoreCoordinator) {
79+ NSLog(@"Could not create store coordinator");
80+ exit(-1);
81+ }
82+
83+ NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
84+ [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
85+ nil];
86+
87+ if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&error]){
88+ [[NSApplication sharedApplication] presentError:error];
89+ NSLog(@"Error -> %@", error);// localizedDescription]);
90+ }
91+
92+ return persistentStoreCoordinator;
93+}
94+
95+
96+/**
97+ Returns the managed object context for the application (which is already
98+ bound to the persistent store coordinator for the application.)
99+ */
100+
101+- (NSManagedObjectContext *)managedObjectContext
102+{
103+ if(managedObjectContext != nil) {
104+ return managedObjectContext;
105+ }
106+
107+ NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
108+ if(coordinator != nil) {
109+ managedObjectContext = [[NSManagedObjectContext alloc] init];
110+ [managedObjectContext setPersistentStoreCoordinator: coordinator];
111+ }
112+
113+ return managedObjectContext;
114+}
115+
116+
117+/**
118+ Performs the save action for the application, which is to send the save:
119+ message to the application's managed object context. Any encountered errors
120+ are presented to the user.
121+ */
122+
123+- (IBAction)saveAction:(id)sender
124+{
125+ NSError *error = nil;
126+ if(![[self managedObjectContext] save:&error]) {
127+ [[NSApplication sharedApplication] presentError:error];
128+ }
129+}
130+
131+
132+/**
133+ Implementation of the applicationShouldTerminate: method, used here to
134+ handle the saving of changes in the application managed object context
135+ before the application terminates.
136+ */
137+
138+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
139+{
140+ NSError *error;
141+ NSUInteger reply = NSTerminateNow;
142+
143+ if(managedObjectContext != nil) {
144+ if([managedObjectContext commitEditing]) {
145+ if([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
146+
147+ // This error handling simply presents error information in a panel with an
148+ // "Ok" button, which does not include any attempt at error recovery (meaning,
149+ // attempting to fix the error.) As a result, this implementation will
150+ // present the information to the user and then follow up with a panel asking
151+ // if the user wishes to "Quit Anyway", without saving the changes.
152+
153+ // Typically, this process should be altered to include application-specific
154+ // recovery steps.
155+
156+ BOOL errorResult = [[NSApplication sharedApplication] presentError:error];
157+
158+ if(errorResult == YES) {
159+ reply = NSTerminateCancel;
160+ } else {
161+
162+ NSInteger alertReturn = NSRunAlertPanel(nil, @"Could not save changes while quitting. Quit anyway?" , @"Quit anyway", @"Cancel", nil);
163+ if(alertReturn == NSAlertAlternateReturn) {
164+ reply = NSTerminateCancel;
165+ }
166+ }
167+ }
168+ } else {
169+ reply = NSTerminateCancel;
170+ }
171+ }
172+
173+ return reply;
174+}
13175
14176 - (void)applicationDidFinishLaunching:(id)notification
15177 {
--- a/BEBookInformation.h
+++ b/BEBookInformation.h
@@ -9,24 +9,24 @@
99 #import <Cocoa/Cocoa.h>
1010
1111
12-@interface BEBookInformation : NSObject
12+@interface BEBookInformation : NSManagedObject
1313 {
14- NSString *isbn;
15- NSString *category;
16- NSDate *registerDate;
17- NSArray *tags;
18- NSString *review;
19- NSNumber *rating;
20- NSNumber *status;
21- NSDate *readDate;
22-
23- NSString *title;
24- NSString *asin;
25- NSString *amazonISBN;
26- NSString *author;
27- NSString *manufacturer;
28- NSDate *publicationDate;
29-
14+// NSString *isbn;
15+// NSString *category;
16+// NSDate *registerDate;
17+// NSArray *tags;
18+// NSString *review;
19+// NSNumber *rating;
20+// NSNumber *status;
21+// NSDate *readDate;
22+//
23+// NSString *title;
24+// NSString *asin;
25+// NSString *amazonISBN;
26+// NSString *author;
27+// NSString *manufacturer;
28+// NSDate *publicationDate;
29+//
3030 BOOL exported;
3131 }
3232
--- a/BEBookInformation.m
+++ b/BEBookInformation.m
@@ -10,34 +10,65 @@
1010
1111
1212 @implementation BEBookInformation
13-@synthesize isbn;
14-@synthesize category;
15-@synthesize registerDate;
16-@synthesize tags;
17-@synthesize review;
18-@synthesize rating;
19-@synthesize status;
20-@synthesize readDate;
21-
22-@synthesize title;
23-@synthesize asin;
24-@synthesize amazonISBN;
25-@synthesize author;
26-@synthesize manufacturer;
27-@synthesize publicationDate;
28-
29-@synthesize exported;
13+@dynamic isbn;
14+@dynamic category;
15+@dynamic registerDate;
16+@dynamic tags;
17+@dynamic review;
18+@dynamic rating;
19+@dynamic status;
20+@dynamic readDate;
21+
22+@dynamic title;
23+@dynamic asin;
24+@dynamic amazonISBN;
25+@dynamic author;
26+@dynamic manufacturer;
27+@dynamic publicationDate;
28+
29+@dynamic exported;
30+
31+- (BOOL)primitiveExported
32+{
33+ return exported;
34+}
35+- (void)setPrimitiveExported:(BOOL)flag
36+{
37+ exported = flag;
38+}
39+- (BOOL)exported
40+{
41+ BOOL val;
42+ [self willAccessValueForKey:@"exported"];
43+ val = exported;
44+ [self didChangeValueForKey:@"exported"];
45+ return val;
46+}
47+- (void)setExported:(BOOL)flag
48+{
49+ [self willChangeValueForKey:@"exported"];
50+ exported = flag;
51+ [self didChangeValueForKey:@"exported"];
52+}
3053
3154 - (NSDate *)registerDate
3255 {
56+ [self willAccessValueForKey:@"registerDate"];
57+ NSDate *registerDate = [self primitiveValueForKey:@"registerDate"];
58+ [self didAccessValueForKey:@"registerDate"];
3359 if(registerDate) return registerDate;
3460 registerDate = [[NSDate dateWithTimeIntervalSinceNow:0.0] retain];
61+ [self setPrimitiveValue:registerDate forKey:@"registerDate"];
3562 return registerDate;
3663 }
3764 - (NSDate *)readDate
3865 {
66+ [self willAccessValueForKey:@"readDate"];
67+ NSDate *readDate = [self primitiveValueForKey:@"readDate"];
68+ [self didAccessValueForKey:@"readDate"];
3969 if(readDate) return readDate;
4070 readDate = [[NSDate dateWithTimeIntervalSinceNow:0.0] retain];
71+ [self setPrimitiveValue:readDate forKey:@"readDate"];
4172 return readDate;
4273 }
4374
@@ -48,7 +79,8 @@
4879 [formatter setDateFormat:@"yyyy-MM-dd"];
4980 date = [formatter dateFromString:date];
5081 }
51- [publicationDate autorelease];
52- publicationDate = [date retain];
82+ [self willChangeValueForKey:@"publicationDate"];
83+ [self setPrimitiveValue:date forKey:@"publicationDate"];
84+ [self didChangeValueForKey:@"publicationDate"];
5385 }
5486 @end
--- a/BEMainWindowController.m
+++ b/BEMainWindowController.m
@@ -24,6 +24,23 @@
2424 return self;
2525 }
2626
27+- (NSManagedObjectContext *)managedObjectContext
28+{
29+ return [[NSApp delegate] managedObjectContext];
30+}
31+
32+- (void)lookupBooks:(NSArray *)array
33+{
34+ [BEAmazonLookup setNameToBooks:array];
35+}
36+
37+- (void)awakeFromNib
38+{
39+ [books bind:NSManagedObjectContextBinding
40+ toObject:self
41+ withKeyPath:@"managedObjectContext"
42+ options:nil];
43+}
2744 - (void)openiSightContinous:(BOOL)flag
2845 {
2946 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
@@ -114,18 +131,22 @@
114131
115132 #pragma mark-
116133 #pragma mark Delegate
117-- (void)iSightWillClose {
134+- (void)iSightWillClose
135+{
118136 [[self window] makeKeyAndOrderFront:self];
119137 }
120-- (void)gotBarcode:(NSString *)barcode {
121-
122- BEBookInformation *book = [[[BEBookInformation alloc] init] autorelease];
138+- (void)gotBarcode:(NSString *)barcode
139+{
140+ BEBookInformation *book = [NSEntityDescription insertNewObjectForEntityForName:[books entityName]
141+ inManagedObjectContext:[books managedObjectContext]];
123142 book.isbn = barcode;
124- [books addObject:book];
125-
126143 if([self autoLookUp]) {
127- [BEAmazonLookup setNameToBooks:[books selectedObjects]];
144+ [BEAmazonLookup setNameToBooks:[NSArray arrayWithObject:book]];
128145 }
146+ [books performSelector:@selector(setSelectedObjects:)
147+ withObject:[NSArray arrayWithObject:book]
148+ afterDelay:0.0001];
149+ [books prepareContent];
129150 }
130151
131152 @end
Binary files /dev/null and b/BooksExporter.xcdatamodel/elements differ
Binary files /dev/null and b/BooksExporter.xcdatamodel/layout differ
--- a/BooksExporter.xcodeproj/project.pbxproj
+++ b/BooksExporter.xcodeproj/project.pbxproj
@@ -51,6 +51,7 @@
5151 F44EED9A131BD15300CAA969 /* BEBooklogBooksExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = F44EED99131BD15300CAA969 /* BEBooklogBooksExporter.m */; };
5252 F44EEE2B131BF48A00CAA969 /* BEMediaMarkerBooksExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = F44EEE2A131BF48A00CAA969 /* BEMediaMarkerBooksExporter.m */; };
5353 F4CD1387131D2384007788DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4CD1385131D2384007788DC /* MainMenu.xib */; };
54+ F4CD141F131D2ADF007788DC /* BooksExporter.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = F4CD141E131D2ADF007788DC /* BooksExporter.xcdatamodel */; };
5455 /* End PBXBuildFile section */
5556
5657 /* Begin PBXBuildRule section */
@@ -191,6 +192,7 @@
191192 F44EEE29131BF48A00CAA969 /* BEMediaMarkerBooksExporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BEMediaMarkerBooksExporter.h; sourceTree = "<group>"; };
192193 F44EEE2A131BF48A00CAA969 /* BEMediaMarkerBooksExporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BEMediaMarkerBooksExporter.m; sourceTree = "<group>"; };
193194 F4CD1386131D2384007788DC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
195+ F4CD141E131D2ADF007788DC /* BooksExporter.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; path = BooksExporter.xcdatamodel; sourceTree = "<group>"; };
194196 /* End PBXFileReference section */
195197
196198 /* Begin PBXFrameworksBuildPhase section */
@@ -376,6 +378,7 @@
376378 29B97314FDCFA39411CA2CEA /* BarcodeScanner */ = {
377379 isa = PBXGroup;
378380 children = (
381+ F4CD141B131D2A7B007788DC /* Models */,
379382 080E96DDFE201D6D7F000001 /* Classes */,
380383 29B97315FDCFA39411CA2CEA /* Other Sources */,
381384 29B97317FDCFA39411CA2CEA /* Resources */,
@@ -437,6 +440,14 @@
437440 name = BarcodeScanner;
438441 sourceTree = "<group>";
439442 };
443+ F4CD141B131D2A7B007788DC /* Models */ = {
444+ isa = PBXGroup;
445+ children = (
446+ F4CD141E131D2ADF007788DC /* BooksExporter.xcdatamodel */,
447+ );
448+ name = Models;
449+ sourceTree = "<group>";
450+ };
440451 /* End PBXGroup section */
441452
442453 /* Begin PBXHeadersBuildPhase section */
@@ -571,6 +582,7 @@
571582 F44EED8F131BD03300CAA969 /* BEBooksExporter.m in Sources */,
572583 F44EED9A131BD15300CAA969 /* BEBooklogBooksExporter.m in Sources */,
573584 F44EEE2B131BF48A00CAA969 /* BEMediaMarkerBooksExporter.m in Sources */,
585+ F4CD141F131D2ADF007788DC /* BooksExporter.xcdatamodel in Sources */,
574586 );
575587 runOnlyForDeploymentPostprocessing = 0;
576588 };
--- a/English.lproj/BEMainWindow.xib
+++ b/English.lproj/BEMainWindow.xib
@@ -11,7 +11,7 @@
1111 <string key="NS.object.0">823</string>
1212 </object>
1313 <array class="NSMutableArray" key="IBDocument.EditedObjectIDs">
14- <integer value="256"/>
14+ <integer value="2"/>
1515 </array>
1616 <array key="IBDocument.PluginDependencies">
1717 <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -474,7 +474,6 @@
474474 <int key="NSvFlags">-2147483392</int>
475475 <string key="NSFrame">{{1, 127}, {4, 15}}</string>
476476 <reference key="NSSuperview" ref="985328466"/>
477- <bool key="NSEnabled">YES</bool>
478477 <int key="NSsFlags">1</int>
479478 <reference key="NSTarget" ref="985328466"/>
480479 <string key="NSAction">_doScroller:</string>
@@ -498,7 +497,7 @@
498497 <string key="NSFrame">{{-2, 306}, {700, 320}}</string>
499498 <reference key="NSSuperview" ref="295446415"/>
500499 <reference key="NSNextKeyView" ref="1064630001"/>
501- <int key="NSsFlags">690</int>
500+ <int key="NSsFlags">562</int>
502501 <reference key="NSVScroller" ref="545356377"/>
503502 <reference key="NSHScroller" ref="849447547"/>
504503 <reference key="NSContentView" ref="1064630001"/>
@@ -1061,7 +1060,11 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA</b
10611060 </array>
10621061 <string key="NSObjectClassName">BEBookInformation</string>
10631062 <bool key="NSEditable">YES</bool>
1064- <object class="_NSManagedProxy" key="_NSManagedProxy"/>
1063+ <bool key="NSAutomaticallyPreparesContent">YES</bool>
1064+ <object class="_NSManagedProxy" key="_NSManagedProxy">
1065+ <string key="NSEntityName">BEBookInformation</string>
1066+ </object>
1067+ <bool key="_NSIsUsingManagedProxy">YES</bool>
10651068 <bool key="NSAvoidsEmptySelection">YES</bool>
10661069 <bool key="NSPreservesSelection">YES</bool>
10671070 <bool key="NSSelectsInsertedObjects">YES</bool>
@@ -1387,26 +1390,6 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA</b
13871390 </object>
13881391 <object class="IBConnectionRecord">
13891392 <object class="IBBindingConnection" key="connection">
1390- <string key="label">enabled: selection.title</string>
1391- <reference key="source" ref="452505"/>
1392- <reference key="destination" ref="1064620552"/>
1393- <object class="NSNibBindingConnector" key="connector">
1394- <reference key="NSSource" ref="452505"/>
1395- <reference key="NSDestination" ref="1064620552"/>
1396- <string key="NSLabel">enabled: selection.title</string>
1397- <string key="NSBinding">enabled</string>
1398- <string key="NSKeyPath">selection.title</string>
1399- <object class="NSDictionary" key="NSOptions">
1400- <string key="NS.key.0">NSValueTransformerName</string>
1401- <string key="NS.object.0">NSIsNotNil</string>
1402- </object>
1403- <int key="NSNibBindingConnectorVersion">2</int>
1404- </object>
1405- </object>
1406- <int key="connectionID">394</int>
1407- </object>
1408- <object class="IBConnectionRecord">
1409- <object class="IBBindingConnection" key="connection">
14101393 <string key="label">enabled: arrangedObjects.@count</string>
14111394 <reference key="source" ref="522098588"/>
14121395 <reference key="destination" ref="1064620552"/>
@@ -1437,6 +1420,26 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA</b
14371420 </object>
14381421 <int key="connectionID">400</int>
14391422 </object>
1423+ <object class="IBConnectionRecord">
1424+ <object class="IBBindingConnection" key="connection">
1425+ <string key="label">enabled: selection.registerDate</string>
1426+ <reference key="source" ref="452505"/>
1427+ <reference key="destination" ref="1064620552"/>
1428+ <object class="NSNibBindingConnector" key="connector">
1429+ <reference key="NSSource" ref="452505"/>
1430+ <reference key="NSDestination" ref="1064620552"/>
1431+ <string key="NSLabel">enabled: selection.registerDate</string>
1432+ <string key="NSBinding">enabled</string>
1433+ <string key="NSKeyPath">selection.registerDate</string>
1434+ <object class="NSDictionary" key="NSOptions">
1435+ <string key="NS.key.0">NSValueTransformerName</string>
1436+ <string key="NS.object.0">NSIsNotNil</string>
1437+ </object>
1438+ <int key="NSNibBindingConnectorVersion">2</int>
1439+ </object>
1440+ </object>
1441+ <int key="connectionID">401</int>
1442+ </object>
14401443 </array>
14411444 <object class="IBMutableOrderedSet" key="objectRecords">
14421445 <array key="orderedObjects">
@@ -2106,7 +2109,7 @@ AQABAAEAAQAB//+dkAEA//+PgAAE//+dkAEI//+dkAEMUERUAFBTVABQV1QAUFBUAAAAAAEAAAABA</b
21062109 <nil key="activeLocalization"/>
21072110 <dictionary class="NSMutableDictionary" key="localizations"/>
21082111 <nil key="sourceID"/>
2109- <int key="maxID">400</int>
2112+ <int key="maxID">401</int>
21102113 </object>
21112114 <object class="IBClassDescriber" key="IBDocument.Classes">
21122115 <array class="NSMutableArray" key="referencedPartialClassDescriptions">