Don't require a user to click a connect button. Automatically connect when a server
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 15 Dec 2008 21:00:35 +0000 (16:00 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 15 Dec 2008 22:53:30 +0000 (17:53 -0500)
is selected via the server combobox.

iPhoto2Ansel/AnselExportController.h
iPhoto2Ansel/AnselExportController.m
iPhoto2Ansel/English.lproj/Panel.nib/classes.nib
iPhoto2Ansel/English.lproj/Panel.nib/info.nib
iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib

index 30105d3..29662e9 100644 (file)
@@ -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;
index 9c82bc1..81b2399 100644 (file)
@@ -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
index e68e9eb..3765e66 100644 (file)
@@ -75,6 +75,8 @@
                                <string>NSButton</string>
                                <key>newGallerySheet</key>
                                <string>NSWindow</string>
+                               <key>newServerButton</key>
+                               <string>NSButton</string>
                                <key>newServerSheet</key>
                                <string>NSWindow</string>
                                <key>password</key>
index 9003e36..eff0405 100644 (file)
@@ -10,8 +10,8 @@
        <integer>5</integer>
        <key>IBOpenObjects</key>
        <array>
-               <integer>388</integer>
                <integer>7</integer>
+               <integer>388</integer>
        </array>
        <key>IBSystem Version</key>
        <string>9F33</string>
index 72e41a5..349c9cb 100644 (file)
Binary files a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib and b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib differ