Modified total time to also used arrangedObject observing.
parent
a10898f4c9
commit
588fa5ddc6
File diff suppressed because it is too large
Load Diff
|
@ -27,11 +27,11 @@ typedef enum {
|
||||||
IBOutlet EntriesController *entriesController;
|
IBOutlet EntriesController *entriesController;
|
||||||
IBOutlet SpotlightWindowController *spotlightWindowController;
|
IBOutlet SpotlightWindowController *spotlightWindowController;
|
||||||
|
|
||||||
NSString *totalTimeDisplay;
|
|
||||||
|
|
||||||
NSMutableArray *shuffleList;
|
NSMutableArray *shuffleList;
|
||||||
NSMutableArray *queueList;
|
NSMutableArray *queueList;
|
||||||
|
|
||||||
|
NSString *totalTime;
|
||||||
|
|
||||||
PlaylistEntry *currentEntry;
|
PlaylistEntry *currentEntry;
|
||||||
|
|
||||||
BOOL shuffle;
|
BOOL shuffle;
|
||||||
|
@ -39,9 +39,11 @@ typedef enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
@property(retain) PlaylistEntry *currentEntry;
|
@property(retain) PlaylistEntry *currentEntry;
|
||||||
|
@property(retain) NSString *totalTime;
|
||||||
|
|
||||||
//Private Methods
|
//Private Methods
|
||||||
- (void)updateTotalTime;
|
- (void)updateTotalTime;
|
||||||
|
- (void)updatePlaylistIndexes;
|
||||||
|
|
||||||
|
|
||||||
//PUBLIC METHODS
|
//PUBLIC METHODS
|
||||||
|
@ -72,9 +74,6 @@ typedef enum {
|
||||||
- (IBAction)searchByArtist:(id)sender;
|
- (IBAction)searchByArtist:(id)sender;
|
||||||
- (IBAction)searchByAlbum:(id)sender;
|
- (IBAction)searchByAlbum:(id)sender;
|
||||||
|
|
||||||
- (void)setTotalTimeDisplay:(NSString *)ttd;
|
|
||||||
- (NSString *)totalTimeDisplay;
|
|
||||||
|
|
||||||
//FUN PLAYLIST MANAGEMENT STUFF!
|
//FUN PLAYLIST MANAGEMENT STUFF!
|
||||||
- (BOOL)next;
|
- (BOOL)next;
|
||||||
- (BOOL)prev;
|
- (BOOL)prev;
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
@implementation PlaylistController
|
@implementation PlaylistController
|
||||||
|
|
||||||
@synthesize currentEntry;
|
@synthesize currentEntry;
|
||||||
|
@synthesize totalTime;
|
||||||
#define SHUFFLE_HISTORY_SIZE 100
|
|
||||||
|
|
||||||
+ (void)initialize {
|
+ (void)initialize {
|
||||||
NSValueTransformer *repeatNoneTransformer = [[[RepeatModeTransformer alloc] initWithMode:RepeatNone] autorelease];
|
NSValueTransformer *repeatNoneTransformer = [[[RepeatModeTransformer alloc] initWithMode:RepeatNone] autorelease];
|
||||||
|
@ -77,6 +76,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||||
|
{
|
||||||
|
if ([keyPath isEqualToString:@"arrangedObjects"])
|
||||||
|
{
|
||||||
|
[self updatePlaylistIndexes];
|
||||||
|
[self updateTotalTime];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)updatePlaylistIndexes
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
NSArray *arranged = [self arrangedObjects];
|
NSArray *arranged = [self arrangedObjects];
|
||||||
|
@ -88,6 +96,22 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateTotalTime
|
||||||
|
{
|
||||||
|
double tt = 0;
|
||||||
|
ldiv_t hoursAndMinutes;
|
||||||
|
|
||||||
|
for (PlaylistEntry *pe in [self arrangedObjects]) {
|
||||||
|
if (!isnan(pe.length))
|
||||||
|
tt += pe.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sec = (int)(tt);
|
||||||
|
hoursAndMinutes = ldiv(sec/60, 60);
|
||||||
|
|
||||||
|
[self setTotalTime:[NSString stringWithFormat:@"%ld hours %ld minutes %d seconds", hoursAndMinutes.quot, hoursAndMinutes.rem, sec%60]];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)tableView:(NSTableView *)tableView
|
- (void)tableView:(NSTableView *)tableView
|
||||||
didClickTableColumn:(NSTableColumn *)tableColumn
|
didClickTableColumn:(NSTableColumn *)tableColumn
|
||||||
{
|
{
|
||||||
|
@ -191,41 +215,12 @@
|
||||||
[urls release];
|
[urls release];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self updateTotalTime];
|
|
||||||
|
|
||||||
if (shuffle == YES)
|
if (shuffle == YES)
|
||||||
[self resetShuffleList];
|
[self resetShuffleList];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateTotalTime
|
|
||||||
{
|
|
||||||
double tt = 0;
|
|
||||||
ldiv_t hoursAndMinutes;
|
|
||||||
|
|
||||||
for (PlaylistEntry *pe in [self arrangedObjects]) {
|
|
||||||
tt += pe.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sec = (int)(tt);
|
|
||||||
hoursAndMinutes = ldiv(sec/60, 60);
|
|
||||||
|
|
||||||
[self setTotalTimeDisplay:[NSString stringWithFormat:@"%ld hours %ld minutes %d seconds", hoursAndMinutes.quot, hoursAndMinutes.rem, sec%60]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setTotalTimeDisplay:(NSString *)ttd
|
|
||||||
{
|
|
||||||
[ttd retain];
|
|
||||||
[totalTimeDisplay release];
|
|
||||||
totalTimeDisplay = ttd;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)totalTimeDisplay;
|
|
||||||
{
|
|
||||||
return totalTimeDisplay;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSUndoManager *)undoManager
|
- (NSUndoManager *)undoManager
|
||||||
{
|
{
|
||||||
return [entriesController undoManager];
|
return [entriesController undoManager];
|
||||||
|
@ -235,8 +230,6 @@
|
||||||
{
|
{
|
||||||
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
||||||
|
|
||||||
[self updateTotalTime];
|
|
||||||
|
|
||||||
if (shuffle == YES)
|
if (shuffle == YES)
|
||||||
[self resetShuffleList];
|
[self resetShuffleList];
|
||||||
}
|
}
|
||||||
|
@ -270,8 +263,6 @@
|
||||||
|
|
||||||
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
||||||
|
|
||||||
[self updateTotalTime];
|
|
||||||
|
|
||||||
if (shuffle == YES)
|
if (shuffle == YES)
|
||||||
[self resetShuffleList];
|
[self resetShuffleList];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue