Skip to content

Commit

Permalink
album-artwork-assistant: work item queue is now persisted using Core …
Browse files Browse the repository at this point in the history
…Data

git-svn-id: svn+ssh://www.entropy.ch/Users/liyanage/Documents/svnroot/trunk/album-artwork-assistant@395 153f8dbc-cef0-0310-8e0e-ba1d6c9f8c6b
  • Loading branch information
liyanage committed Sep 15, 2008
1 parent 499b2ff commit 572352c
Show file tree
Hide file tree
Showing 15 changed files with 858 additions and 1,816 deletions.
8 changes: 7 additions & 1 deletion Album Artwork Assistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
1BAF15C70E33D8EF00A725F6 /* DDInvocationGrabber.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BAF15C30E33D8EF00A725F6 /* DDInvocationGrabber.m */; };
1BAF15C80E33D8EF00A725F6 /* NSObject+DDExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BAF15C40E33D8EF00A725F6 /* NSObject+DDExtensions.m */; };
1BAF16750E33F06B00A725F6 /* Album Artwork Assistant.scpt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1BAF16740E33F05B00A725F6 /* Album Artwork Assistant.scpt */; };
1BBD59EE0E5A2749005F235C /* TrackGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BBD59ED0E5A2749005F235C /* TrackGroup.m */; };
1BD13CAF0E46E457005DD669 /* amazon2plist.xslt in Resources */ = {isa = PBXBuildFile; fileRef = 1BD13CAE0E46E457005DD669 /* amazon2plist.xslt */; };
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
Expand Down Expand Up @@ -173,6 +174,8 @@
1BAF161B0E33E16800A725F6 /* NDComponentInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NDComponentInstance.h; path = "src-external/NDAppleScriptObjectProject/Classes/NDComponentInstance.h"; sourceTree = "<group>"; };
1BAF161C0E33E16800A725F6 /* NSString+NDCarbonUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+NDCarbonUtilities.h"; path = "src-external/NDAppleScriptObjectProject/Classes/NSString+NDCarbonUtilities.h"; sourceTree = "<group>"; };
1BAF16740E33F05B00A725F6 /* Album Artwork Assistant.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.scpt; name = "Album Artwork Assistant.scpt"; path = "extras/Album Artwork Assistant.scpt"; sourceTree = "<group>"; };
1BBD59EC0E5A2749005F235C /* TrackGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TrackGroup.h; path = src/TrackGroup.h; sourceTree = "<group>"; };
1BBD59ED0E5A2749005F235C /* TrackGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TrackGroup.m; path = src/TrackGroup.m; sourceTree = "<group>"; };
1BD13CAE0E46E457005DD669 /* amazon2plist.xslt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = amazon2plist.xslt; path = Resources/amazon2plist.xslt; sourceTree = "<group>"; };
1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -228,6 +231,7 @@
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
1B7656EA0E28C793004A20AE /* libicucore.dylib */,
1B8CF61A0E2BD4FD0084C323 /* Carbon.framework */,
1BAA29D70E2ABB3000B05717 /* Quartz.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
Expand Down Expand Up @@ -256,6 +260,8 @@
1B0B40750E4C2D64006CAE99 /* Models */ = {
isa = PBXGroup;
children = (
1BBD59EC0E5A2749005F235C /* TrackGroup.h */,
1BBD59ED0E5A2749005F235C /* TrackGroup.m */,
1B0B40470E4BB148006CAE99 /* Album Artwork Assistant.xcdatamodel */,
);
name = Models;
Expand Down Expand Up @@ -369,7 +375,6 @@
29B97317FDCFA39411CA2CEA /* Resources */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
1B7656EA0E28C793004A20AE /* libicucore.dylib */,
);
name = "Music Artwork";
sourceTree = "<group>";
Expand Down Expand Up @@ -509,6 +514,7 @@
1B6B77370E3540D800EA2035 /* QuickLookImageBrowserView.m in Sources */,
1B01E8290E4AD810009E8310 /* DataStore.m in Sources */,
1B0B40480E4BB148006CAE99 /* Album Artwork Assistant.xcdatamodel in Sources */,
1BBD59EE0E5A2749005F235C /* TrackGroup.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2,366 changes: 632 additions & 1,734 deletions English.lproj/MainMenu.xib

Large diffs are not rendered by default.

Binary file modified Models/Album Artwork Assistant.xcdatamodel/elements
Binary file not shown.
Binary file modified Models/Album Artwork Assistant.xcdatamodel/layout
Binary file not shown.
6 changes: 6 additions & 0 deletions src/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "IKImageBrowserFileUrlDataSource.h"
#import "DataStore.h"
#import "ImageSearchItem.h"
#import "TrackGroup.h"

#define DOUBLECLICK_ACTION_QUEUE 1
#define GOOGLE_IMAGE_RESULT_PAGE_COUNT 2
Expand All @@ -18,6 +19,7 @@
IBOutlet NSButton *processQueueButton;
IBOutlet QuickLookImageBrowserView *imageBrowser;
IBOutlet NSArrayController *queueController;
IBOutlet NSArrayController *groupsController;
NSArray *tracks;
NSString *albumTitle;
NSMutableArray *images;
Expand Down Expand Up @@ -61,10 +63,14 @@
- (void)setupDefaults;
- (void)setupNotifications;
- (id)makeTrackGroup;
- (NSUInteger)queueLength;
- (BOOL)isQueueEmpty;

- (NSData *)imageDataForItem:(ImageSearchItem *)item;
- (void)removeItemAtIndex:(int)index;
- (ImageSearchItem *)selectedImage;
- (void)removeCurrentItemAndWarn;

- (IBAction)debug:(id)sender;

@end
96 changes: 57 additions & 39 deletions src/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ @implementation AppDelegate
# pragma mark IBActions

- (IBAction)showExampleAppleScript:(id)sender {

NSString *path = [[NSBundle mainBundle] pathForResource:@"Example AppleScript" ofType:nil];
[[NSWorkspace sharedWorkspace] openFile:path];

NSLog(@"show example applescript %@", path);

}



- (IBAction)fetch:(id)sender {
[self startBusy:@"Fetching Tracks from iTunes"];
if (![self fetchITunesTrackList]) return;
Expand All @@ -51,14 +46,14 @@ - (IBAction)setAlbumArtwork:(id)sender {
[self performSelectorInBackground:@selector(setAlbumArtworkBackground:) withObject:sender];
}


- (void)setAlbumArtworkBackground:(id)sender {
UpdateOperation *uo = [self makeUpdateOperation];
if (!uo) return;
[uo main];
}



- (IBAction)findImages:(id)sender {
if ([albumTitle length] < 1) return;
[self clearImages];
Expand Down Expand Up @@ -97,7 +92,6 @@ - (BOOL)fetchITunesTrackList {

NSArray *trackData = [[ds stringValue] propertyList];
NSAssert(trackData, @"Unable to parse iTunes track list AppleScript");
// NSLog(@"array: %@", trackData);
[self setValue:trackData forKey:@"tracks"];
return YES;
}
Expand Down Expand Up @@ -223,24 +217,30 @@ - (UpdateOperation *)makeUpdateOperation {
NSData *imageData = [self imageDataForItem:item];
[self clearBusy];
if (!imageData) return nil;
UpdateOperation *uo = [[UpdateOperation alloc] initWithTracks:tracks imageItem:item statusDelegate:self];

UpdateOperation *uo = [[UpdateOperation alloc] initWithTracks:tracks imageData:imageData statusDelegate:self];
NSLog(@"tracksData: %@", tracks);
return uo;
}


- (UpdateOperation *)makeUpdateOperationForTrackGroup:(TrackGroup *)group {
return [[UpdateOperation alloc] initWithTracks:[group tracksData] imageData:[group imageData] statusDelegate:self];
}


- (ImageSearchItem *)selectedImage {
int index = [[imageBrowser selectionIndexes] firstIndex];
return [images objectAtIndex:index];
}



- (void)removeItemAtIndex:(int)index {
[images removeObjectAtIndex:index];
[[imageBrowser dd_invokeOnMainThread] reloadData];
}



- (NSData *)imageDataForItem:(ImageSearchItem *)item {
NSError *error;
NSData *imageData = [item dataError:&error];
Expand Down Expand Up @@ -278,16 +278,11 @@ - (IBAction)addToQueue:(id)sender {
}



- (IBAction)addToQueueBackground:(id)sender {
UpdateOperation *uo = [self makeUpdateOperation];
id trackGroup = [self makeTrackGroup];
if (!uo) return;
[queueController addObject:uo];
[self makeTrackGroup];
}



- (id)makeTrackGroup {

ImageSearchItem *item = [self selectedImage];
Expand All @@ -299,7 +294,6 @@ - (id)makeTrackGroup {
NSManagedObject *trackGroup = [NSEntityDescription
insertNewObjectForEntityForName:@"TrackGroup"
inManagedObjectContext:[dataStore managedObjectContext]];
//trackGroup = @"trackgroup title";

[trackGroup setValue:[[tracks objectAtIndex:0] valueForKey:@"trackalbum"] forKey:@"title"];
[trackGroup setValue:imageData forKey:@"imageData"];
Expand All @@ -311,24 +305,21 @@ - (id)makeTrackGroup {
insertNewObjectForEntityForName:@"Track"
inManagedObjectContext:[dataStore managedObjectContext]];

[aTrack setValue:[trackData valueForKey:@"id"] forKey:@"id"];
[aTrack setValue:[trackData valueForKey:@"name"] forKey:@"number"];
[aTrack setValue:[trackData valueForKey:@"number"] forKey:@"number"];
[aTrack setValue:[trackData valueForKey:@"album"] forKey:@"album"];
[aTrack setValue:[trackData valueForKey:@"artist"] forKey:@"artist"];
[aTrack setValue:[trackData valueForKey:@"containerid"] forKey:@"containerid"];
[aTrack setValue:[trackData valueForKey:@"trackid"] forKey:@"id"];
[aTrack setValue:[trackData valueForKey:@"trackname"] forKey:@"name"];
[aTrack setValue:[trackData valueForKey:@"tracknumber"] forKey:@"number"];
[aTrack setValue:[trackData valueForKey:@"trackalbum"] forKey:@"album"];
[aTrack setValue:[trackData valueForKey:@"trackartist"] forKey:@"artist"];
[aTrack setValue:[trackData valueForKey:@"trackcontainerid"] forKey:@"containerid"];

[groupTracks addObject:aTrack];
}

NSLog(@"groupTracks: %@", groupTracks);
NSLog(@"trackgroup: %@", trackGroup);
return trackGroup;
}




- (IBAction)processQueue:(id)sender {
if ([self isQueueProcessing]) {
[self setIsQueueProcessing:NO];
Expand All @@ -344,24 +335,38 @@ - (IBAction)processQueue:(id)sender {


- (void)processOneQueueEntry {
if (!([self isQueueProcessing] && [queue count] > 0)) {
if (!([self isQueueProcessing] && ![self isQueueEmpty])) {
[self setIsQueueProcessing:NO];
[self clearBusy];
[processQueueButton setState:NSOnState];
return;
}

[self setBusyMessage:@"Processing Queue 2"];
[[queue objectAtIndex:0] main];
[self willChangeValueForKey:@"queue"];
[queue removeObjectAtIndex:0];
[self didChangeValueForKey:@"queue"];
id trackGroup = [dataStore firstEntityNamed:@"TrackGroup"];
UpdateOperation *uo = [self makeUpdateOperationForTrackGroup:trackGroup];
[uo main];
if ([uo didComplete]) {
[dataStore deleteObject:trackGroup];
} else {
[self setIsQueueProcessing:NO];
}

[self performSelector:@selector(processOneQueueEntry) withObject:nil afterDelay:0.1];
}



- (NSUInteger)queueLength {
return [dataStore countForEntityNamed:@"TrackGroup"];
}


- (BOOL)isQueueEmpty {
return [self queueLength] < 1;
}



# pragma mark data binding methods

-(NSArray *)searchSuggestions {
Expand Down Expand Up @@ -400,28 +405,38 @@ - (void)cleanupString:(NSMutableString *)input {
- (void)awakeFromNib {
images = [NSMutableArray array];
[self setQueue:[NSMutableArray array]];

[self setDataStore:[[DataStore alloc] init]];

[self setupDefaults];
[self setupNotifications];

NSLog(@"datastore %@", [dataStore persistentStoreCoordinator]);
// force a fetch to get the count
// http://theocacao.com/document.page/305
[groupsController fetchWithRequest:nil merge:NO error:nil];
if ([[groupsController arrangedObjects] count] > 0) {
[queueDrawer open];
}

}


- (IBAction)debug:(id)sender {
}


# pragma mark setup methods

- (void)setupDefaults {
id sortDesc = [NSArchiver archivedDataWithRootObject:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"number" ascending:YES]]];
NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:DOUBLECLICK_ACTION_QUEUE], @"doubleClickAction",
[NSNumber numberWithFloat:0.4], @"imageBrowserZoom",
sortDesc, @"tracksSortDescriptors",
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}



- (void)setupNotifications {
// the AppleScript command object sends this notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fetch:) name:@"fetchiTunesAlbums" object:nil];
Expand All @@ -433,6 +448,7 @@ - (void)setupNotifications {
- (void)didPresentErrorWithRecovery:(BOOL)didRecover contextInfo:(void *)contextInfo {
}


# pragma mark StatusDelegateProtocol protocol methods

- (void)startBusy:(NSString *)message {
Expand All @@ -454,8 +470,6 @@ - (BOOL)displayErrorWithTitle:(NSString *)title message:(NSString *)message {
}




# pragma mark image browser IKImageBrowserDataSource protocol methods

- (id)imageBrowser:(IKImageBrowserView *)aBrowser itemAtIndex:(NSUInteger)index {
Expand All @@ -468,8 +482,6 @@ - (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView *)aBrowser {





# pragma mark image browser IKImageBrowserDelegate protocol methods

- (void)imageBrowserSelectionDidChange:(IKImageBrowserView *)aBrowser {
Expand All @@ -496,6 +508,12 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
return reply;
}

#pragma mark tracks table view delegate methods

- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex {
return NO;
}



@end
4 changes: 4 additions & 0 deletions src/DataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
- (NSString *)applicationName;
- (void)cleanup;
- (void)save;
- (NSUInteger)countForEntityNamed:(NSString *)name;
- (NSManagedObject *)firstEntityNamed:(NSString *)name;
- (NSFetchRequest *)fetchRequestForEntityNamed:(NSString *)name;
- (void)deleteObject:(NSManagedObject *)object;


@end
Loading

0 comments on commit 572352c

Please sign in to comment.