From: Michael J. Rubinsky Date: Mon, 15 Dec 2008 21:00:35 +0000 (-0500) Subject: Don't require a user to click a connect button. Automatically connect when a server X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=afc26a3fcee39da7b75c405f027a2b63da15c97e;p=horde.git Don't require a user to click a connect button. Automatically connect when a server is selected via the server combobox. --- diff --git a/iPhoto2Ansel/AnselExportController.h b/iPhoto2Ansel/AnselExportController.h index 30105d3f3..29662e994 100644 --- a/iPhoto2Ansel/AnselExportController.h +++ b/iPhoto2Ansel/AnselExportController.h @@ -39,7 +39,6 @@ extern NSString * const TURAnselServerPasswordKey; IBOutlet NSTextField *connectedLabel; IBOutlet NSProgressIndicator *spinner; IBOutlet NSImageView *defaultImageView; - IBOutlet NSButton *beginButton; IBOutlet NSButton *newGalleryButton; IBOutlet NSButton *newServerButton; @@ -79,7 +78,6 @@ extern NSString * const TURAnselServerPasswordKey; - (NSWindow *)window; // Actions -- (IBAction) doConnect: (id)sender; - (IBAction) showNewGallery: (id)sender; - (IBAction) doAddServer: (id)sender; - (IBAction) doCancelAddServer: (id)sender; diff --git a/iPhoto2Ansel/AnselExportController.m b/iPhoto2Ansel/AnselExportController.m index 9c82bc13e..81b23992f 100644 --- a/iPhoto2Ansel/AnselExportController.m +++ b/iPhoto2Ansel/AnselExportController.m @@ -13,7 +13,9 @@ #import "ImageResizer.h"; @interface AnselExportController (PrivateAPI) +- (void)doConnect; - (void)connect; +- (void)disconnect; - (void)postProgressStatus:(NSString *)status; - (void)privatePerformExport; - (void)runExport; @@ -89,31 +91,7 @@ NSString * const TURAnselServerPasswordKey = @"password"; } #pragma mark Actions -// Start the connection process. --(void)doConnect: (id)sender -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSDictionary *p = [[NSDictionary alloc] initWithObjects: [NSArray arrayWithObjects: - [currentServer objectForKey:TURAnselServerEndpointKey], - [currentServer objectForKey:TURAnselServerUsernameKey], - [currentServer objectForKey:TURAnselServerPasswordKey]] - forKeys: [NSArray arrayWithObjects:@"endpoint", @"username", @"password", nil]]; - // Create our controller - anselController = [[TURAnsel alloc] initWithConnectionParameters:p]; - [anselController setDelegate:self]; - - // Set up the galleryCombo - [galleryCombo setUsesDataSource:YES]; - [galleryCombo setDataSource:anselController]; - [galleryCombo setDelegate:self]; - [spinner startAnimation:self]; - // Detach to a new thread and do the actual login/retrieval of gallery list - [NSApplication detachDrawingThread: @selector(connect) - toTarget: self - withObject: nil]; - [p release]; - [pool release]; -} + // Put up the newGallerySheet NSPanel - (IBAction)showNewGallery: (id)sender @@ -153,6 +131,9 @@ NSString * const TURAnselServerPasswordKey = @"password"; // Save it to the userdefaults NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; [prefs setObject:anselServers forKey:TURAnselServersKey]; + + // ...and try to connect. + [self doConnect]; } - (IBAction)doCancelAddServer: (id)sender @@ -290,6 +271,42 @@ NSString * const TURAnselServerPasswordKey = @"password"; [galleryCombo setEnabled: YES]; } } + +// Make sure we clean up from any previous connection +-(void)disconnect +{ + [galleryCombo setDelegate: nil]; + [anselController release]; + + //TODO: update status/use notifications? +} + +// Start the connection process. +-(void)doConnect +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSDictionary *p = [[NSDictionary alloc] initWithObjects: [NSArray arrayWithObjects: + [currentServer objectForKey:TURAnselServerEndpointKey], + [currentServer objectForKey:TURAnselServerUsernameKey], + [currentServer objectForKey:TURAnselServerPasswordKey]] + forKeys: [NSArray arrayWithObjects:@"endpoint", @"username", @"password", nil]]; + // Create our controller + anselController = [[TURAnsel alloc] initWithConnectionParameters:p]; + [anselController setDelegate:self]; + + // Set up the galleryCombo + [galleryCombo setUsesDataSource:YES]; + [galleryCombo setDataSource:anselController]; + [galleryCombo setDelegate:self]; + [spinner startAnimation:self]; + // Detach to a new thread and do the actual login/retrieval of gallery list + [NSApplication detachDrawingThread: @selector(connect) + toTarget: self + withObject: nil]; + [p release]; + [pool release]; +} + // Runs in a new thread. - (void)connect { @@ -492,9 +509,10 @@ NSString * const TURAnselServerPasswordKey = @"password"; [theImage release]; [self canExport]; } else if ([notification object] == mServers) { - NSLog(@"Changed server selection"); + [self disconnect]; [currentServer release]; - currentServer = [anselServers objectAtIndex: [mServers indexOfSelectedItem]]; + currentServer = [anselServers objectAtIndex: [mServers indexOfSelectedItem]]; + [self doConnect]; } } @@ -511,7 +529,6 @@ NSString * const TURAnselServerPasswordKey = @"password"; { // Make sure we have a server configured, or throw up the dialog. if (![anselServers count]) { - NSLog(@"No servers!!"); [NSApp beginSheet: newServerSheet modalForWindow: [self window] modalDelegate: nil diff --git a/iPhoto2Ansel/English.lproj/Panel.nib/classes.nib b/iPhoto2Ansel/English.lproj/Panel.nib/classes.nib index e68e9eb3d..3765e66b2 100644 --- a/iPhoto2Ansel/English.lproj/Panel.nib/classes.nib +++ b/iPhoto2Ansel/English.lproj/Panel.nib/classes.nib @@ -75,6 +75,8 @@ NSButton newGallerySheet NSWindow + newServerButton + NSButton newServerSheet NSWindow password diff --git a/iPhoto2Ansel/English.lproj/Panel.nib/info.nib b/iPhoto2Ansel/English.lproj/Panel.nib/info.nib index 9003e369c..eff0405ba 100644 --- a/iPhoto2Ansel/English.lproj/Panel.nib/info.nib +++ b/iPhoto2Ansel/English.lproj/Panel.nib/info.nib @@ -10,8 +10,8 @@ 5 IBOpenObjects - 388 7 + 388 IBSystem Version 9F33 diff --git a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib index 72e41a568..349c9cbc7 100644 Binary files a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib and b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib differ