Commit 20f288d9 authored by Pierre's avatar Pierre

Add a -[MLFile willDisplay] and -[MLFile willHide].

Call this when the data associated to that file are about to be displayed. This will increase the priority for any pending meta data fetching.
parent f5d78c1e
......@@ -45,6 +45,22 @@ extern NSString *kMLFileTypeTVShowEpisode;
@property (nonatomic, retain) NSSet* labels;
@property (nonatomic, retain) NSNumber* isOnDisk;
/**
* the data in this object are about to be put on screen
*
* If multiple MLFile object are processed, this
* increase the priority of the processing for this MLFile.
*/
- (void)willDisplay;
/**
* We don't display the data of this object on screen.
*
* This put back the eventually increased priority for this MLFile,
* to a default one.
* \see willDisplay
*/
- (void)didHide;
@end
......
......@@ -11,6 +11,7 @@
#import "MLShow.h"
#import "MLShowEpisode.h"
#import "MLMediaLibrary.h"
#import "MLThumbnailerQueue.h"
NSString *kMLFileTypeMovie = @"movie";
NSString *kMLFileTypeClip = @"clip";
......@@ -94,4 +95,14 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
@dynamic labels;
@dynamic isOnDisk;
- (void)willDisplay
{
[[MLThumbnailerQueue sharedThumbnailerQueue] setHighPriorityForFile:self];
}
- (void)didHide
{
[[MLThumbnailerQueue sharedThumbnailerQueue] setDefaultPriorityForFile:self];
}
@end
......@@ -11,10 +11,12 @@
@class MLFile;
@interface MLThumbnailerQueue : NSOperationQueue {
NSDictionary *_fileDescriptionToOperation;
}
+ (MLThumbnailerQueue *)sharedThumbnailerQueue;
- (void)addFile:(MLFile *)file;
- (void)setHighPriorityForFile:(MLFile *)file;
- (void)setDefaultPriorityForFile:(MLFile *)file;
- (void)stop;
- (void)resume;
......
......@@ -12,6 +12,7 @@
#import "MLFile.h"
#import <UIKit/UIKit.h>
@interface ThumbnailOperation : NSOperation <VLCMediaThumbnailerDelegate>
{
MLFile *_file;
......@@ -19,6 +20,10 @@
@property (retain,readwrite) MLFile *file;
@end
@interface MLThumbnailerQueue ()
- (void)didFinishOperation:(ThumbnailOperation *)op;
@end
@implementation ThumbnailOperation
@synthesize file=_file;
- (id)initWithFile:(MLFile *)file;
......@@ -41,6 +46,7 @@
VLCMediaThumbnailer *thumbnailer = [VLCMediaThumbnailer thumbnailerWithMedia:media andDelegate:self];
[thumbnailer fetchThumbnail];
[[MLThumbnailerQueue sharedThumbnailerQueue] setSuspended:YES]; // Balanced in -mediaThumbnailer:didFinishThumbnail
[[MLThumbnailerQueue sharedThumbnailerQueue] didFinishOperation:self];
[self retain]; // Balanced in -mediaThumbnailer:didFinishThumbnail:
}
- (void)main
......@@ -69,9 +75,37 @@
return shared;
}
- (id)init
{
self = [super init];
if (self != nil) {
_fileDescriptionToOperation = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)dealloc
{
[_fileDescriptionToOperation release];
[super dealloc];
}
static inline NSString *hashFromFile(MLFile *file)
{
return [NSString stringWithFormat:@"%p", [[file objectID] URIRepresentation]];
}
- (void)didFinishOperation:(ThumbnailOperation *)op
{
[_fileDescriptionToOperation setValue:nil forKey:hashFromFile(op.file)];
}
- (void)addFile:(MLFile *)file
{
[self addOperation:[[[ThumbnailOperation alloc] initWithFile:file] autorelease]];
ThumbnailOperation *op = [[ThumbnailOperation alloc] initWithFile:file];
[_fileDescriptionToOperation setValue:op forKey:hashFromFile(file)];
[self addOperation:op];
}
- (void)stop
......@@ -83,4 +117,16 @@
{
[self setMaxConcurrentOperationCount:1];
}
- (void)setHighPriorityForFile:(MLFile *)file
{
ThumbnailOperation *op = [_fileDescriptionToOperation objectForKey:hashFromFile(file)];
[op setQueuePriority:NSOperationQueuePriorityHigh];
}
- (void)setDefaultPriorityForFile:(MLFile *)file
{
ThumbnailOperation *op = [_fileDescriptionToOperation objectForKey:hashFromFile(file)];
[op setQueuePriority:NSOperationQueuePriorityNormal];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment