Permalink
Browse files

Better field behaviour, error messages, finding xml properly

git-svn-id: svn://Zim.local/NanoFibre/trunk@624 6c154dfa-49ee-0310-9ea9-8312faa011d6
  • Loading branch information...
1 parent 9535069 commit 2321365ef00c4c94ac9ac7cd1d1c57b13fd9850c @jdelStrother committed Nov 25, 2006
View
@@ -5,6 +5,7 @@
@interface AppController : NSObject
{
IBOutlet NSArrayController *arrayController;
+ IBOutlet NSTextField *sizeField;
IBOutlet NSTextField *sizeLabel;
IBOutlet NSWindow *window;
}
View
@@ -4,10 +4,17 @@
#import "MusicLibrary.h"
#import "HumanDiskSizeTransformer.h";
+@interface AppController(private)
+-(void)findITunesXML;
+@end
+
@implementation AppController
+(void)initialize
{
+ NSDictionary* defaults = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:3.5] forKey:@"maxSize"]; //3.5GB is about right for my 4GB nano...
+ [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
+
HumanDiskSizeTransformer* humanDiskSizeTransformer = [[HumanDiskSizeTransformer alloc] init];
[NSValueTransformer setValueTransformer:humanDiskSizeTransformer
forName:@"HumanDiskSizeTransformer"];
@@ -19,24 +26,43 @@ -(void)applicationDidFinishLaunching:(NSNotification *)aNotification
// If we're running in daemon mode, just make the changes and leave.
if ([[[NSProcessInfo processInfo] environment] objectForKey:@"fibreDaemon"])
{
- [self makePlaylist:self];
+ [[MusicLibrary sharedLibrary] createFibrePlaylist];
[[NSApplication sharedApplication] terminate:self];
}
else
{
+ [self findITunesXML];
[window makeKeyAndOrderFront:self];
}
}
+- (void)controlTextDidChange:(NSNotification *)aNotification
+{
+ //It's a bit silly setting up cocoa bindings for the size controls, only to manually set it here...
+ //However, I can't figure out a way of persuading it to update the label on every keystroke otherwise.
+ NSString* sizeString = [[[[aNotification userInfo] objectForKey:@"NSFieldEditor"] textStorage] string];
+ NSNumber* size = [[NSValueTransformer valueTransformerForName:@"HumanDiskSizeTransformer"] reverseTransformedValue:sizeString];
+ NSString* readableSize = [[NSValueTransformer valueTransformerForName:@"HumanDiskSizeTransformer"] transformedValue:size];
+ if (readableSize)
+ [sizeLabel setStringValue:readableSize];
+}
-(IBAction)makePlaylist:(id)sender
{
+ //Persuade the text field to end editing, so the size value is committed:
+ [sizeField selectText:self];
+
[[MusicLibrary sharedLibrary] createFibrePlaylist];
+
+ NSRunAlertPanel(@"Playlist Generated", @"Take a look in iTunes, you should have a NanoFibre playlist ready and waiting for your iPod syncing needs.", @"OK", nil, nil);
}
-(IBAction)installDaemon:(id)sender
{
+ //Persuade the text field to end editing, so the size value is committed:
+ [sizeField selectText:self];
+
if (NSRunAlertPanel(@"Install Daemon?",
@"This will install a daemon to /usr/local/bin, and a launch agent to ~/Library/LaunchAgents",
@"Install",@"Cancel",nil) == NSAlertDefaultReturn)
@@ -109,4 +135,44 @@ -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theAppli
}
+
+// This could use some love - it won't handle aliases etc.
+-(void)findITunesXML
+{
+ //Need to find the iTunes XML. Start by checking previous results:
+ BOOL libraryFound = NO;
+ NSString* pathToLibrary = [[NSUserDefaults standardUserDefaults] objectForKey:@"iTunesXMLPath"];
+ if (pathToLibrary && [[NSFileManager defaultManager] fileExistsAtPath:pathToLibrary])
+ return; //We're good to go
+
+
+ //OK, we don't know where it is. Check the obvious location:
+ pathToLibrary = [@"~/Music/iTunes/iTunes Music Library.xml" stringByExpandingTildeInPath];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:pathToLibrary])
+ libraryFound = YES;
+
+ //Still not found it? Ask the user to locate it:
+ if (!libraryFound)
+ {
+ NSOpenPanel* openPanel = [NSOpenPanel openPanel];
+ [openPanel setTitle:@"Open iTunes Library"];
+ [openPanel setMessage:@"Where is your iTunes Music Library XML?"];
+ int panelResult = [openPanel runModalForTypes:[NSArray arrayWithObject:@"xml"]];
+ if (panelResult == NSOKButton)
+ {
+ pathToLibrary = [openPanel filename];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:pathToLibrary])
+ libraryFound = YES;
+ }
+ }
+
+ if (libraryFound)
+ [[NSUserDefaults standardUserDefaults] setObject:pathToLibrary forKey:@"iTunesXMLPath"];
+ else
+ {
+ NSRunAlertPanel(@"Oh dear", @"We couldn't find your iTunes XML. Bad luck." ,@":(",nil,nil);
+ [[NSApplication sharedApplication] terminate:self];
+ }
+}
+
@end

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Binary file not shown.
View
@@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.0</string>
+ <string>1.1</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
View
@@ -114,7 +114,7 @@ -(void)dealloc
-(void)loadLibrary
{
// This isn't particularly robust : It doesn't handle music libraries in odd locations, or ones that are linked to the usual location with aliases.
- NSString* libraryPath = [@"~/Music/iTunes/iTunes Music Library.xml" stringByExpandingTildeInPath];
+ NSString* libraryPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"iTunesXMLPath"];
NSDictionary* xml = [NSDictionary dictionaryWithContentsOfFile:libraryPath];
@@ -33,7 +33,7 @@
isa = PBXContainerItemProxy;
containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
proxyType = 1;
- remoteGlobalIDString = FC0F29A60AE04CD700C72116 /* fibred */;
+ remoteGlobalIDString = FC0F29A60AE04CD700C72116;
remoteInfo = fibred;
};
/* End PBXContainerItemProxy section */

0 comments on commit 2321365

Please sign in to comment.