Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: svn://Zim.local/NanoFibre/trunk@619 6c154dfa-49ee-0310-9ea9-8312faa011d6
- Loading branch information
0 parents
commit 31159de
Showing
30 changed files
with
5,678 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Album.h | ||
// Fibre | ||
// | ||
// Created by Jonathan del Strother on 01/10/2006. | ||
// Copyright 2006 Best Before Media Ltd. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface Album : NSObject { | ||
NSMutableArray* tracks; | ||
|
||
UInt64 size; | ||
BOOL sizeCached; | ||
} | ||
|
||
-(void)addTrack:(NSDictionary*)track; | ||
-(NSString*)title; | ||
-(NSString*)artist; | ||
-(NSString*)sizeDescription; | ||
-(UInt64)byteSize; | ||
-(NSArray*)tracks; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// Album.m | ||
// Fibre | ||
// | ||
// Created by Jonathan del Strother on 01/10/2006. | ||
// Copyright 2006 Best Before Media Ltd. All rights reserved. | ||
// | ||
|
||
#import "Album.h" | ||
|
||
|
||
@implementation Album | ||
|
||
-(id)init | ||
{ | ||
self = [super init]; | ||
if (self) | ||
{ | ||
tracks = [[NSMutableArray alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
-(void)addTrack:(NSDictionary*)track | ||
{ | ||
[tracks addObject:track]; | ||
} | ||
-(NSString*)title | ||
{ | ||
return [[tracks objectAtIndex:0] objectForKey:@"Album"]; | ||
} | ||
-(NSString*)artist | ||
{ | ||
NSString* artist = [[tracks objectAtIndex:0] objectForKey:@"Album Artist"]; | ||
if (!artist || [artist isEqualToString:@""]) | ||
artist = [[tracks objectAtIndex:0] objectForKey:@"Artist"]; | ||
return artist; | ||
} | ||
-(UInt64)byteSize | ||
{ | ||
if (!sizeCached) | ||
{ | ||
size = 0; | ||
NSEnumerator* trackEnum = [tracks objectEnumerator]; | ||
NSDictionary* track; | ||
while(track = [trackEnum nextObject]) | ||
{ | ||
size += [[track objectForKey:@"Size"] intValue]; | ||
} | ||
sizeCached = YES; | ||
} | ||
return size; | ||
} | ||
-(NSString*)sizeDescription | ||
{ | ||
return [NSString stringWithFormat:@"%.2fMB", [self byteSize]/(float)(1024*1024)]; | ||
} | ||
|
||
|
||
+(NSString*)pathOfTrack:(NSDictionary*)track | ||
{ | ||
//Get the path, and replace percentage escapes (eg %20 -> ' ') | ||
NSString* location = [track objectForKey:@"Location"]; | ||
if (!location) return nil; | ||
|
||
NSString* encodedLocation = [location stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | ||
if (!encodedLocation) return nil; | ||
NSMutableString* path = [[encodedLocation mutableCopy] autorelease]; | ||
|
||
if ([path hasPrefix:@"http:"]) | ||
return nil; | ||
|
||
//Strip the protocol from the start of the string (eg 'file://') | ||
NSRange range = [path rangeOfString:@"//"]; | ||
if (range.location == NSNotFound) return nil; | ||
[path deleteCharactersInRange:NSMakeRange(0,range.location+range.length)]; | ||
|
||
//Strip the host from the start of the string (eg 'localhost') | ||
range = [path rangeOfString:@"/"]; | ||
if (range.location == NSNotFound) return nil; | ||
[path deleteCharactersInRange:NSMakeRange(0,range.location+range.length-1)]; | ||
|
||
return [[path copy] autorelease]; | ||
} | ||
|
||
-(NSArray*)tracks | ||
{ | ||
NSMutableArray* trackPaths = [NSMutableArray array]; | ||
nsenumerat(tracks, track) | ||
[trackPaths addObject:[Album pathOfTrack:track]]; | ||
|
||
return [[trackPaths copy] autorelease]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* AppController */ | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface AppController : NSObject | ||
{ | ||
IBOutlet NSArrayController *arrayController; | ||
IBOutlet NSTextField *sizeLabel; | ||
IBOutlet NSWindow *window; | ||
} | ||
- (IBAction)makePlaylist:(id)sender; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#import "AppController.h" | ||
#import "MusicLibrary.h" | ||
#import "HumanDiskSizeTransformer.h"; | ||
|
||
@implementation AppController | ||
|
||
+(void)initialize | ||
{ | ||
HumanDiskSizeTransformer* humanDiskSizeTransformer = [[HumanDiskSizeTransformer alloc] init]; | ||
[NSValueTransformer setValueTransformer:humanDiskSizeTransformer | ||
forName:@"HumanDiskSizeTransformer"]; | ||
[humanDiskSizeTransformer release]; | ||
} | ||
|
||
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification | ||
{ | ||
if ([[[NSProcessInfo processInfo] environment] objectForKey:@"fibreDaemon"]) | ||
{ | ||
[self makePlaylist:self]; | ||
[[NSApplication sharedApplication] terminate:self]; | ||
} | ||
else | ||
{ | ||
[window makeKeyAndOrderFront:self]; | ||
} | ||
} | ||
|
||
|
||
-(IBAction)makePlaylist:(id)sender | ||
{ | ||
[[MusicLibrary sharedLibrary] createFibrePlaylist]; | ||
} | ||
|
||
|
||
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication | ||
{ | ||
return YES; | ||
} | ||
|
||
|
||
@end |
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Prefix header for all source files of the 'Fibre' target in the 'Fibre' project | ||
// | ||
|
||
#ifdef __OBJC__ | ||
#import <Cocoa/Cocoa.h> | ||
|
||
#define nsenumerate_getEnumerator( TYPE, OBJ ) \ | ||
(TYPE)([OBJ isKindOfClass:[NSEnumerator class]] \ | ||
? OBJ \ | ||
: [OBJ performSelector:@selector(objectEnumerator)]) | ||
|
||
#define nsenumerate( CONTAINER, ITERATOR_TYPE, ITERATOR_SYMBOL ) \ | ||
for( ITERATOR_TYPE \ | ||
*enumerator = nsenumerate_getEnumerator(ITERATOR_TYPE*, CONTAINER), \ | ||
*ITERATOR_SYMBOL = [((NSEnumerator*) enumerator) nextObject]; \ | ||
ITERATOR_SYMBOL != nil; \ | ||
ITERATOR_SYMBOL = [((NSEnumerator*) enumerator) nextObject] ) | ||
|
||
#define nsenumerat( CONTAINER, ITERATOR_SYMBOL ) \ | ||
for( id \ | ||
enumerator = nsenumerate_getEnumerator(id, CONTAINER), \ | ||
ITERATOR_SYMBOL = [((NSEnumerator*) enumerator) nextObject]; \ | ||
ITERATOR_SYMBOL != nil; \ | ||
ITERATOR_SYMBOL = [((NSEnumerator*) enumerator) nextObject] ) | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// HumanDiskSizeTransformer.h | ||
// Fibre | ||
// | ||
// Created by Jonathan del Strother on 08/10/2006. | ||
// Copyright 2006 Best Before Media Ltd. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface HumanDiskSizeTransformer : NSValueTransformer { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// HumanDiskSizeTransformer.m | ||
// Fibre | ||
// | ||
// Created by Jonathan del Strother on 08/10/2006. | ||
// Copyright 2006 Best Before Media Ltd. All rights reserved. | ||
// | ||
|
||
#import "HumanDiskSizeTransformer.h" | ||
|
||
|
||
@implementation HumanDiskSizeTransformer | ||
|
||
+(Class)transformedValueClass; | ||
{ | ||
return [NSNumber class]; | ||
} | ||
|
||
+(BOOL)allowsReverseTransformation; | ||
{ | ||
return YES; | ||
} | ||
|
||
|
||
-(id)reverseTransformedValue:(id)value; // NSString -> NSNumber | ||
{ | ||
float size; | ||
|
||
if (value == nil) return nil; | ||
|
||
// Attempt to get a reasonable value from the | ||
// value object. | ||
if ([value isKindOfClass:[NSString class]]) | ||
{ | ||
NSString* strSize = [[[value lowercaseString] | ||
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] | ||
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"s"]]; | ||
|
||
if ([strSize hasSuffix:@"megabyte"]||[strSize hasSuffix:@"mb"]) | ||
size = [value floatValue]/1024; | ||
else //Assume we want gigabytes | ||
size = [value floatValue]; | ||
} | ||
else | ||
{ | ||
[NSException raise: NSInternalInconsistencyException | ||
format: @"Value (%@) needs to be a string", value]; | ||
} | ||
|
||
id returnValue = [NSNumber numberWithFloat:size]; | ||
NSLog(@"reverse transform : %@ -> %@", value, returnValue); | ||
|
||
return returnValue; | ||
} | ||
|
||
|
||
-(id)transformedValue:(id)value // NSNumber -> NSString | ||
{ | ||
float size; | ||
|
||
if (value == nil) return nil; | ||
|
||
// Attempt to get a reasonable value from the | ||
// value object. | ||
if ([value respondsToSelector: @selector(floatValue)]) { | ||
size = [value floatValue]; | ||
} else { | ||
[NSException raise: NSInternalInconsistencyException | ||
format: @"Value (%@) does not respond to -floatValue.", | ||
[value class]]; | ||
} | ||
|
||
id returnValue; | ||
if (size < 0.5) | ||
returnValue = [NSString stringWithFormat:@"%.0fMB", size*1024]; | ||
else | ||
returnValue = [NSString stringWithFormat:@"%0.3gGB", size]; | ||
|
||
NSLog(@"transform : %@ -> %@", value, returnValue); | ||
|
||
return returnValue; | ||
} | ||
|
||
@end |
Oops, something went wrong.