Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon loading fixes #1142

Merged
merged 9 commits into from Oct 30, 2012
5 changes: 3 additions & 2 deletions Quicksilver/Code-QuickStepCore/QSIconLoader.h
Expand Up @@ -11,14 +11,16 @@
@interface QSIconLoader : NSObject {
NSArray *array;
BOOL loaderValid;
NSThread *loadThread;
BOOL isLoading;

NSRange loadRange;
NSRange newRange;
NSObject *delegate;
NSInteger modulation;
}
+ (id)loaderWithArray:(NSArray *)newArray;
+ (void)invalidateLoaderForDelegate:(id)delegate;

- (void)loadIconsInRange:(NSRange)range;
- (NSObject *)delegate;
- (void)setDelegate:(NSObject *)aDelegate;
Expand All @@ -28,5 +30,4 @@

- (NSInteger) modulation;
- (void)setModulation:(NSInteger)newModulation;
+ (void)invalidateLoaderForDelegate:(id)delegate;
@end
22 changes: 9 additions & 13 deletions Quicksilver/Code-QuickStepCore/QSIconLoader.m
Expand Up @@ -11,6 +11,7 @@ - (id)initWithArray:(NSArray *)newArray {
if (self = [super init]) {
array = [newArray retain];
loaderValid = YES;
isLoading = NO;
}
return self;
}
Expand All @@ -23,22 +24,18 @@ - (void)dealloc {
}

- (void)invalidate {
isLoading = NO;
loaderValid = NO;
}

- (void)loadIcons {
@autoreleasepool {

[[self retain] autorelease];
loadThread = [NSThread currentThread];
// [NSThread setThreadPriority:0.0];
NSArray *sourceArray = nil;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
BOOL rangeValid = NO;

NSUInteger i, j, m;
id <NSObject, QSObject> thisObject;
while (!(rangeValid) && loaderValid) {
isLoading = YES;
loadRange = newRange;
rangeValid = YES;
for (i = 0; i <= loadRange.length && loaderValid && rangeValid; i++) {
Expand All @@ -55,20 +52,19 @@ - (void)loadIcons {

if (![thisObject isKindOfClass:[NSNull class]] && ![thisObject iconLoaded]) {
[thisObject loadIcon];
[delegate iconLoader:self loadedIndex:m inArray:sourceArray];
[delegate iconLoader:self loadedIndex:m inArray:array];
}
rangeValid = NSEqualRanges(loadRange, newRange);
}
}
loadThread = nil;
}
isLoading = NO;
});
}

- (void)loadIconsInRange:(NSRange)range {
if (!NSEqualRanges(range, newRange) ) {
newRange = range;
//NSLog(@"%d, %d", range, NSMaxRange(range) );
if (!loadThread) [NSThread detachNewThreadSelector:@selector(loadIcons) toTarget:self withObject:nil];
[self loadIcons];
}
}

Expand Down Expand Up @@ -96,7 +92,7 @@ - (BOOL)cancelLoading:(NSNotification *)notif {
return YES;
}

- (BOOL)isLoading { return loadThread != nil; }
- (BOOL)isLoading { return isLoading; }

- (NSInteger) modulation { return modulation; }

Expand Down
3 changes: 0 additions & 3 deletions Quicksilver/Code-QuickStepCore/QSLibrarian.h
Expand Up @@ -23,8 +23,6 @@ extern QSLibrarian *QSLib; // Shared Instance
NSMutableSet *omittedIDs;
QSTask *scanTask;
QSTaskController *activityController;

NSOperationQueue *previewImageQueue;

NSMutableDictionary *catalogArrays; // Arrays for each leaf catalog entry (Entry)
NSMutableDictionary *typeArrays; // Type arrays (Type / Entry)
Expand Down Expand Up @@ -113,6 +111,5 @@ extern QSLibrarian *QSLib; // Shared Instance
- (void)initCatalog;
- (QSTask *)scanTask;
- (void)setScanTask:(QSTask *)value;
- (NSOperationQueue *)previewImageQueue;

@end
9 changes: 1 addition & 8 deletions Quicksilver/Code-QuickStepCore/QSLibrarian.m
Expand Up @@ -62,9 +62,7 @@ - (id)init {
scanTask = [[QSTask taskWithIdentifier:@"QSLibrarianScanTask"] retain];
[scanTask setName:@"Updating Catalog"];
[scanTask setIcon:[NSImage imageNamed:@"Catalog.icns"]];

previewImageQueue = [[NSOperationQueue alloc] init];
[previewImageQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];

//Initialize Variables
appSearchArrays = nil;
typeArrays = [[NSMutableDictionary dictionaryWithCapacity:1] retain];
Expand Down Expand Up @@ -211,7 +209,6 @@ - (void)dealloc {
[defaultSearchSet release];
[omittedIDs release];
[scanTask release];
[previewImageQueue release];
[activityController release];
[catalogArrays release];
[typeArrays release];
Expand Down Expand Up @@ -748,10 +745,6 @@ - (void)setScanTask:(QSTask *)value {
}
}

- (NSOperationQueue *)previewImageQueue {
return previewImageQueue;
}

@end

@implementation QSLibrarian (QSPlugInInfo)
Expand Down
8 changes: 3 additions & 5 deletions Quicksilver/Code-QuickStepCore/QSObject_FileHandling.m
Expand Up @@ -255,11 +255,9 @@ - (BOOL)loadIconForObject:(QSObject *)object {
// this has to be started after the temporary icon is set, so the preview icon
// wont be overwritten by the temporary icon
if ([theFiles count] == 1) {
// do complicated preview icon loading in separate thread
NSInvocationOperation *theOp = [[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(previewIcon:)
object:object] autorelease];
[[[QSLibrarian sharedInstance] previewImageQueue] addOperation:theOp];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self previewIcon:object];
});
}
return YES;
}
Expand Down
7 changes: 3 additions & 4 deletions Quicksilver/Code-QuickStepCore/QSObject_URLHandling.m
Expand Up @@ -137,10 +137,9 @@ - (BOOL)loadIconForObject:(QSObject *)object {

// For search URLs
if([object containsType:QSSearchURLType]) {
NSInvocationOperation *theOp = [[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(buildWebSearchIconForObject:)
object:object] autorelease];
[[[QSLibrarian sharedInstance] previewImageQueue] addOperation:theOp];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self buildWebSearchIconForObject:object];
});
return YES;
}

Expand Down
38 changes: 21 additions & 17 deletions Quicksilver/Code-QuickStepInterface/QSResultController.m
Expand Up @@ -267,16 +267,6 @@ -(void)rowModified:(NSInteger)index {

#pragma mark -
#pragma mark Icon Loading
- (BOOL)iconLoadValidForTable:(NSTableView *)table {
if (table == resultTable && !iconLoadValid) {
iconLoadValid = YES;
return NO;
} else if (table == resultChildTable && !childIconLoadValid) {
childIconLoadValid = YES;
return NO;
}
return YES;
}

- (void)iconLoader:(QSIconLoader *)loader loadedIndex:(NSInteger)m inArray:(NSArray *)array {
// NSLog(@"loaded");
Expand All @@ -290,11 +280,12 @@ - (void)iconLoader:(QSIconLoader *)loader loadedIndex:(NSInteger)m inArray:(NSAr
} else {
//NSLog(@"RogueLoader %d", m);
}
[table performSelectorOnMainThread:@selector(redisplayRows:) withObject:[NSIndexSet indexSetWithIndex:(m ? m : 0)] waitUntilDone:NO];
[table setNeedsDisplay:YES];
}

- (BOOL)iconsAreLoading {
return [resultIconLoader isLoading];
BOOL resultsIconLoading = [resultIconLoader isLoading];
return (resultsIconLoading ? YES : [resultChildIconLoader isLoading]);
}

- (QSIconLoader *)resultIconLoader {
Expand All @@ -314,9 +305,17 @@ - (void)setResultIconLoader:(QSIconLoader *)aResultIconLoader {
}
}

- (QSIconLoader *)resultChildIconLoader { return resultChildIconLoader; }
- (QSIconLoader *)resultChildIconLoader {
if (!resultChildIconLoader) {
[self setResultChildIconLoader:[QSIconLoader loaderWithArray:[selectedItem children]]];
[resultChildIconLoader setDelegate:self];
}
return [[resultChildIconLoader retain] autorelease];
}

- (void)setResultChildIconLoader:(QSIconLoader *)aResultChildIconLoader {
if (resultChildIconLoader != aResultChildIconLoader) {
[resultChildIconLoader invalidate];
[resultChildIconLoader release];
resultChildIconLoader = [aResultChildIconLoader retain];
}
Expand Down Expand Up @@ -390,15 +389,20 @@ - (void)updateSelectionInfo {
} else {
[self loadChildren];
}

}

/* Restart the icon loading for the children view */
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QSResultsShowChildren"]) {
[self setResultChildIconLoader:nil];
[[self resultChildIconLoader] loadIconsInRange:[resultChildTable rowsInRect:[resultChildTable visibleRect]]];
}
}

#pragma mark -
#pragma mark NSResponder
- (void)scrollWheel:(NSEvent *)theEvent {
[resultTable scrollWheel:theEvent];
}
//- (void)scrollWheel:(NSEvent *)theEvent {
// [resultTable scrollWheel:theEvent];
//}

- (void)keyDown:(NSEvent *)theEvent {
NSString *characters;
Expand Down
11 changes: 2 additions & 9 deletions Quicksilver/Code-QuickStepInterface/QSTableView.m
Expand Up @@ -5,11 +5,6 @@

#import "NSColor_QSModifications.h"

@interface NSTableView (SingleRowDisplay)
- (void)_setNeedsDisplayInRow:(NSInteger)fp8;
@end


@implementation QSTableView

//- (void)awakeFromNib {
Expand Down Expand Up @@ -132,11 +127,9 @@ - (void)setBackgroundColor:(NSColor *)color {


- (void)redisplayRows:(NSIndexSet *)indexes {
if ([self respondsToSelector:@selector(_setNeedsDisplayInRow:)])
[self _setNeedsDisplayInRow:[indexes firstIndex]];
// ***warning * incomplete
else [self setNeedsDisplay:YES];
[self setNeedsDisplay:YES];
}

- (NSMenu*)menuForEvent:(NSEvent*)evt {
// NSLog (@"event");
NSPoint point = [self convertPoint:[evt locationInWindow] fromView:NULL];
Expand Down