From: Michael J. Rubinsky Date: Sun, 17 May 2009 21:05:02 +0000 (-0400) Subject: Fix memory leak when switching between servers after an export X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5a2fd345dd33fb57795864490cea95d4aa613e9a;p=horde.git Fix memory leak when switching between servers after an export is made along with some UI tweaks --- diff --git a/iPhoto2Ansel/AnselExportController.m b/iPhoto2Ansel/AnselExportController.m index a77dbb7e2..01de285ae 100644 --- a/iPhoto2Ansel/AnselExportController.m +++ b/iPhoto2Ansel/AnselExportController.m @@ -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]; diff --git a/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib b/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib index 2942f7325..51473bc3e 100644 --- a/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib +++ b/iPhoto2Ansel/English.lproj/Panel.nib/designable.nib @@ -2,14 +2,14 @@ 1050 - 9G55 + 9J61 672 - 949.43 + 949.46 353.00 YES + - YES @@ -1038,7 +1038,7 @@ YES - 879885888 + 611450433 272630784 @@ -1048,6 +1048,9 @@ 5 YES + YES + YES + @@ -1096,7 +1099,6 @@ tableViewAction: -767524864 - 1 15 @@ -1104,6 +1106,7 @@ YES + diff --git a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib index 7e0308bd5..206fbbe34 100644 Binary files a/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib and b/iPhoto2Ansel/English.lproj/Panel.nib/keyedobjects.nib differ diff --git a/iPhoto2Ansel/TURAnsel.m b/iPhoto2Ansel/TURAnsel.m index be94d5590..80d1f3111 100644 --- a/iPhoto2Ansel/TURAnsel.m +++ b/iPhoto2Ansel/TURAnsel.m @@ -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) { diff --git a/iPhoto2Ansel/TURAnselGallery.m b/iPhoto2Ansel/TURAnselGallery.m index 3beabd657..4522b2281 100644 --- a/iPhoto2Ansel/TURAnselGallery.m +++ b/iPhoto2Ansel/TURAnselGallery.m @@ -158,11 +158,9 @@ #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]; } @@ -176,7 +174,7 @@ - (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; }