Permalink
Browse files

query image browser selection on main thread to get rid of inconsistency

  • Loading branch information...
1 parent 0b47017 commit 6e20d91db7c3141c91925a94dbce568e28341e1e @liyanage committed Mar 30, 2009
Showing with 37 additions and 10 deletions.
  1. +1 −0 .gitignore
  2. +14 −0 Resources/release-notes.html
  3. +3 −2 readme.txt
  4. +1 −0 src/AppDelegate.h
  5. +18 −8 src/AppDelegate.m
View
@@ -1 +1,2 @@
/build
+*.DS_Store
@@ -57,6 +57,20 @@
<body>
+<a name="version-2.4"></a>
+<h1>Version 2.4</h1>
+
+<h2>English</h2>
+<ul>
+ <li>Fixes to improve stability.</li>
+</ul>
+
+<h2>Deutsch</h2>
+<ul>
+
+</ul>
+
+
<a name="version-2.3"></a>
<h1>Version 2.3</h1>
View
@@ -4,6 +4,7 @@ http://devworld.apple.com/DOCUMENTATION/DeveloperTools/Conceptual/IB_UserGuide/L
ibtool --previous-file Resources.r422/English.lproj/MainMenu.xib --incremental-file Resources.r422/German.lproj/MainMenu.xib --localize-incremental --write Resources/German.lproj/MainMenu.xib Resources/English.lproj/MainMenu.xib
+todo:
-
-
+- make affected track list editable
+- allow selection other than main library?
View
@@ -83,6 +83,7 @@
- (NSData *)imageDataForItem:(ImageSearchItem *)item;
- (void)removeItemAtIndex:(int)index;
- (ImageSearchItem *)selectedImage;
+- (NSUInteger)selectedImageIndex;
- (void)removeCurrentItemAndWarn;
- (IBAction)debug:(id)sender;
View
@@ -63,6 +63,7 @@ - (void)setAlbumArtworkBackground:(id)sender {
imageData = [io dataError:nil];
} else {
ImageSearchItem *item = [self selectedImage];
+ if (!item) return;
[self startBusy:NSLocalizedString(@"downloading_image", @"")];
imageData = [self imageDataForItem:item];
[self clearBusy];
@@ -92,15 +93,13 @@ - (void)prepareAlbumTrackName {
- (void)clearImages {
[images removeAllObjects];
-
// if we don't do this, file descriptors from HTTP connections pile up
// and crash the application sooner or later
[[NSGarbageCollector defaultCollector] collectExhaustively];
-
[self logProcessSize];
-
}
+
// http://miknight.blogspot.com/2005/11/resident-set-size-in-mac-os-x.html
- (void)logProcessSize {
struct task_basic_info t_info;
@@ -363,7 +362,12 @@ - (UpdateOperation *)makeUpdateOperationForTrackGroup:(TrackGroup *)group {
- (ImageSearchItem *)selectedImage {
- int index = [[imageBrowser selectionIndexes] firstIndex];
+ NSUInteger index = [self selectedImageIndex];
+ NSUInteger count = [images count];
+ if (index > count - 1) {
+ NSLog(@"[[imageBrowser selectionIndexes] firstIndex] is %d but image count is only %d", index, count);
+ return nil;
+ }
return [images objectAtIndex:index];
}
@@ -395,15 +399,19 @@ - (NSURL *)fileUrlForItemAtIndex:(int)index {
- (void)removeCurrentItemAndWarn {
- NSIndexSet *sel = [imageBrowser selectionIndexes];
- NSAssert(sel, @"imageBrowser selectionIndexes not nil");
- NSUInteger index = [sel firstIndex];
+ NSUInteger index = [self selectedImageIndex];
NSAssert2(index >= 0 && index < IMAGE_BROWSER_MAX_ITEMS, @"selectionIndexes firstIndex in valid range (0 <= %d < %d) ", index, IMAGE_BROWSER_MAX_ITEMS);
[self removeItemAtIndex:index];
[self displayErrorWithTitle:NSLocalizedString(@"image_unavailable_title", @"") message:NSLocalizedString(@"image_unavailable", @"")];
}
+- (NSUInteger)selectedImageIndex {
+ NSIndexSet *sel = [[imageBrowser dd_invokeOnMainThread] selectionIndexes];
+ NSUInteger index = [[sel dd_invokeOnMainThread] firstIndex];
+ return index;
+}
+
# pragma mark queue manipulation
@@ -425,7 +433,9 @@ - (IBAction)addToQueueBackground:(id)sender {
if (!data) return;
trackGroup = [self makeTrackGroupWithImageData:data];
} else {
- trackGroup = [self makeTrackGroupWithImageData:[self imageDataForItem:[self selectedImage]]];
+ ImageSearchItem *item = [self selectedImage];
+ if (!item) return;
+ trackGroup = [self makeTrackGroupWithImageData:[self imageDataForItem:item]];
}
if (!trackGroup) return;
[[dataStore dd_invokeOnMainThread] save];

0 comments on commit 6e20d91

Please sign in to comment.