Fix memory leak when switching between servers after an export
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 17 May 2009 21:05:02 +0000 (17:05 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 17 May 2009 21:07:49 +0000 (17:07 -0400)
is made along with some UI tweaks

iPhoto2Ansel/AnselExportController.m
iPhoto2Ansel/English.lproj/Panel.nib/designable.nib
iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib
iPhoto2Ansel/TURAnsel.m
iPhoto2Ansel/TURAnselGallery.m

index a77dbb7..01de285 100644 (file)
@@ -106,10 +106,8 @@ NSString * const TURAnselServerPasswordKey = @"password";
 {
     [spinner startAnimation: self];
     [self setStatusText: @"Getting image list..."];
-    [browserData removeAllObjects];
     NSMutableArray *images = [currentGallery listImages];
     if ([images count] == 0) {
-        [browserView reloadData];
         //TODO: Show a panel showing there are no images? Or just disable the
         //      view gallery button?
 
@@ -148,6 +146,8 @@ NSString * const TURAnselServerPasswordKey = @"password";
 {
     [NSApp endSheet: mviewGallerySheet];
     [mviewGallerySheet orderOut: nil];
+    [browserData removeAllObjects];
+    [browserView reloadData];
 }
 
 // Put up the newGallerySheet NSPanel
@@ -208,10 +208,9 @@ NSString * const TURAnselServerPasswordKey = @"password";
         [self showNewServerSheet];
     } else if (![[[mServersPopUp selectedItem] title] isEqual:@"(None)"]) {
         // Connect to a server
-        if (currentServer == [[mServersPopUp selectedItem] representedObject]) {
-            return;
+        if (currentServer != nil) {
+            [self disconnect];
         }
-        [self disconnect];
         currentServer = [[mServersPopUp selectedItem] representedObject];
         [self doConnect];
     }
@@ -290,7 +289,8 @@ NSString * const TURAnselServerPasswordKey = @"password";
 }
 
 // These seem to be called when the plugin panel is actived/deactivated while
-// export screen is open, not when the plugin is finished.
+// export screen is open, not when the plugin is finished or the export window
+// is clsoed from the Cancel button
 - (void)viewWillBeActivated
 {
     [self canExport];
@@ -450,8 +450,10 @@ NSString * const TURAnselServerPasswordKey = @"password";
 // Make sure we clean up from any previous connection
 -(void)disconnect
 {
+    [galleryCombo deselectItemAtIndex: [galleryCombo indexOfSelectedItem]];
     [galleryCombo setDelegate: nil];
     [galleryCombo setDataSource: nil];
+    [galleryCombo reloadData];
     [galleryCombo setEnabled: NO];
     [mNewGalleryButton setEnabled: NO];
     [viewGallery setEnabled: NO];
@@ -476,14 +478,14 @@ NSString * const TURAnselServerPasswordKey = @"password";
     NSDictionary *p = [[NSDictionary alloc] initWithObjects: [NSArray arrayWithObjects:
                                                               [currentServer objectForKey:TURAnselServerEndpointKey],
                                                               [currentServer objectForKey:TURAnselServerUsernameKey],
-                                                              [currentServer objectForKey:TURAnselServerPasswordKey]]
+                                                              [currentServer objectForKey:TURAnselServerPasswordKey],
+                                                              nil]
                                                     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];
@@ -584,7 +586,6 @@ NSString * const TURAnselServerPasswordKey = @"password";
         NSString *imageDescription = [mExportMgr imageTitleAtIndex:i];
         NSArray *keywords = [mExportMgr imageKeywordsAtIndex: i];
         
-        NSLog(@"Keywords: %@", keywords);
         NSArray *keys = [[NSArray alloc] initWithObjects:
                          @"filename", @"description", @"data", @"type", @"tags", nil];
         
@@ -630,6 +631,8 @@ NSString * const TURAnselServerPasswordKey = @"password";
     // Need to do this ourselves since we aren't using iPhoto's progress bar.
     // Not really cancelling the export, but all this method does is close
     // the export interface and notify iPhoto that we are done.
+    [mServersPopUp selectItemAtIndex: 0];
+    [self disconnect];
     [mExportMgr cancelExportBeforeBeginning];
 }
 
@@ -717,8 +720,6 @@ NSString * const TURAnselServerPasswordKey = @"password";
     [self canExport];
     [viewGallery setEnabled: YES];
     [spinner stopAnimation: self];
-    // TODO: Check this. Assume we can set back to connected since we obviously
-    //       are connected if we're getting gallery info.
     [self setStatusText: @"Connected" withColor: [NSColor greenColor]];
 }
 
@@ -731,20 +732,37 @@ NSString * const TURAnselServerPasswordKey = @"password";
 }
 
 #pragma mark export notifications
+
+- (void)exportWindowWillClose: (NSNotification *)notification
+{
+    [mServersPopUp selectItemAtIndex: 0];
+    [self disconnect];    
+    [[NSNotificationCenter defaultCenter] removeObserver: self
+                                                    name: NSWindowWillCloseNotification
+                                                  object: nil];
+}
+
 - (void)exportWindowDidBecomeKey: (NSNotification *)notification
 {
-    // We only want to do this once...
+    
+    // Register for the close notification
+    [[NSNotificationCenter defaultCenter] addObserver: self
+                                             selector: @selector(exportWindowWillClose:)
+                                                 name: NSWindowWillCloseNotification 
+                                              object :nil];
+
+    // Only do this once
     [[NSNotificationCenter defaultCenter] removeObserver: self
-                                                    name: NSWindowDidBecomeKeyNotification 
+                                                    name: NSWindowDidBecomeKeyNotification
                                                   object: nil];
+
     [self updateServersPopupMenu];
-    
+
     // Register for notifications
     [[NSNotificationCenter defaultCenter] addObserver: self
                                              selector: @selector(NSPopUpWillPopUp:)
                                                  name:@"NSPopUpButtonWillPopUpNotification"
                                                object: nil];
-    
     if ([anselServers count] == 0) {
         [self showNewServerSheet];
     } else {
@@ -767,9 +785,9 @@ NSString * const TURAnselServerPasswordKey = @"password";
 
             [self doConnect];
         }
-
     }
 }
+
 - (void)sizeChoiceWillChange: (NSNotification *)notification
 {
     NSInteger newSize = [mSizePopUp selectedTag];
index 2942f73..51473bc 100644 (file)
@@ -2,14 +2,14 @@
 <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.02">
        <data>
                <int key="IBDocument.SystemTarget">1050</int>
-               <string key="IBDocument.SystemVersion">9G55</string>
+               <string key="IBDocument.SystemVersion">9J61</string>
                <string key="IBDocument.InterfaceBuilderVersion">672</string>
-               <string key="IBDocument.AppKitVersion">949.43</string>
+               <string key="IBDocument.AppKitVersion">949.46</string>
                <string key="IBDocument.HIToolboxVersion">353.00</string>
                <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
                        <bool key="EncodedWithXMLCoder">YES</bool>
+                       <integer value="137"/>
                        <integer value="577"/>
-                       <integer value="581"/>
                </object>
                <object class="NSArray" key="IBDocument.PluginDependencies">
                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                                                                                        <reference key="NSSuperview" ref="675618554"/>
                                                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                                                        <object class="NSComboBoxCell" key="NSCell" id="487568130">
-                                                                                                                               <int key="NSCellFlags">879885888</int>
+                                                                                                                               <int key="NSCellFlags">611450433</int>
                                                                                                                                <int key="NSCellFlags2">272630784</int>
                                                                                                                                <string key="NSContents"/>
                                                                                                                                <reference key="NSSupport" ref="1065031457"/>
                                                                                                                                <reference key="NSTextColor" ref="428586510"/>
                                                                                                                                <int key="NSVisibleItemCount">5</int>
                                                                                                                                <bool key="NSHasVerticalScroller">YES</bool>
+                                                                                                                               <bool key="NSUsesDataSource">YES</bool>
+                                                                                                                               <bool key="NSCompletes">YES</bool>
+                                                                                                                               <nil key="NSDataSource"/>
                                                                                                                                <reference key="NSDelegate" ref="553805234"/>
                                                                                                                                <object class="NSComboTableView" key="NSTableView" id="562062983">
                                                                                                                                        <reference key="NSNextResponder"/>
                                                                                                                                        <string key="NSAction">tableViewAction:</string>
                                                                                                                                        <int key="NSTvFlags">-767524864</int>
                                                                                                                                        <reference key="NSDelegate" ref="487568130"/>
-                                                                                                                                       <reference key="NSDataSource" ref="487568130"/>
                                                                                                                                        <reference key="NSTarget" ref="487568130"/>
                                                                                                                                        <int key="NSColumnAutoresizingStyle">1</int>
                                                                                                                                        <int key="NSDraggingSourceMaskForLocal">15</int>
                                                                                                                                        <bool key="NSAllowsTypeSelect">YES</bool>
                                                                                                                                </object>
                                                                                                                        </object>
+                                                                                                                       <nil key="NSDataSource"/>
                                                                                                                </object>
                                                                                                                <object class="NSTextField" id="530084779">
                                                                                                                        <reference key="NSNextResponder" ref="675618554"/>
index 7e0308b..206fbbe 100644 (file)
Binary files a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib and b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib differ
index be94d55..80d1f31 100644 (file)
@@ -247,7 +247,6 @@ objectValueForTableColumn:(NSTableColumn *)tc
 
     id galleries = [self callRPCMethod:@"images.listGalleries"
                             withParams:params];
-    NSLog(@"%@", galleries);
     if (state != TURAnselStateError) {
         state = TURAnselStateConnected;
         for (NSString *gal in galleries) {
index 3beabd6..4522b22 100644 (file)
 #pragma mark Overrides----------------------------------------------------------
 - (void)dealloc
 {
-    NSLog(@"TURAnselGallery dealloc called");
-    [galleryDescription release];
+    NSLog(@"TURAnselGallery dealloc called on Gallery %@", self);
     [anselController release];
     [galleryDefaultImageURL release];
-    [galleryDescription release];
     [imageList release];
     [super dealloc];
 }
 
 - (id)description 
 {
-    NSString *text = [NSString stringWithFormat:@"Description: %@ Id: %d has: %d images", galleryDescription, galleryId, galleryImageCount];
+    NSString *text = [NSString stringWithFormat:@"Description: %@ Id: %d has: %d images", galleryName, galleryId, galleryImageCount];
     return text;
 }