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 SpotlightWindowController *spotlightWindowController;
|
||||
|
||||
NSString *totalTimeDisplay;
|
||||
|
||||
NSMutableArray *shuffleList;
|
||||
NSMutableArray *queueList;
|
||||
|
||||
NSString *totalTime;
|
||||
|
||||
PlaylistEntry *currentEntry;
|
||||
|
||||
BOOL shuffle;
|
||||
|
@ -39,9 +39,11 @@ typedef enum {
|
|||
}
|
||||
|
||||
@property(retain) PlaylistEntry *currentEntry;
|
||||
@property(retain) NSString *totalTime;
|
||||
|
||||
//Private Methods
|
||||
- (void)updateTotalTime;
|
||||
- (void)updatePlaylistIndexes;
|
||||
|
||||
|
||||
//PUBLIC METHODS
|
||||
|
@ -72,9 +74,6 @@ typedef enum {
|
|||
- (IBAction)searchByArtist:(id)sender;
|
||||
- (IBAction)searchByAlbum:(id)sender;
|
||||
|
||||
- (void)setTotalTimeDisplay:(NSString *)ttd;
|
||||
- (NSString *)totalTimeDisplay;
|
||||
|
||||
//FUN PLAYLIST MANAGEMENT STUFF!
|
||||
- (BOOL)next;
|
||||
- (BOOL)prev;
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
@implementation PlaylistController
|
||||
|
||||
@synthesize currentEntry;
|
||||
|
||||
#define SHUFFLE_HISTORY_SIZE 100
|
||||
@synthesize totalTime;
|
||||
|
||||
+ (void)initialize {
|
||||
NSValueTransformer *repeatNoneTransformer = [[[RepeatModeTransformer alloc] initWithMode:RepeatNone] autorelease];
|
||||
|
@ -77,6 +76,15 @@
|
|||
}
|
||||
|
||||
- (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;
|
||||
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
|
||||
didClickTableColumn:(NSTableColumn *)tableColumn
|
||||
{
|
||||
|
@ -191,41 +215,12 @@
|
|||
[urls release];
|
||||
}
|
||||
|
||||
[self updateTotalTime];
|
||||
|
||||
if (shuffle == YES)
|
||||
[self resetShuffleList];
|
||||
|
||||
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
|
||||
{
|
||||
return [entriesController undoManager];
|
||||
|
@ -235,8 +230,6 @@
|
|||
{
|
||||
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
||||
|
||||
[self updateTotalTime];
|
||||
|
||||
if (shuffle == YES)
|
||||
[self resetShuffleList];
|
||||
}
|
||||
|
@ -270,8 +263,6 @@
|
|||
|
||||
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
||||
|
||||
[self updateTotalTime];
|
||||
|
||||
if (shuffle == YES)
|
||||
[self resetShuffleList];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue