adium 4602:86168c4921da: Refactor ESTextAndButtonsWindowControll...

commits at adium.im commits at adium.im
Sun Jan 29 17:05:44 UTC 2012


details:	http://hg.adium.im/adium/rev/86168c4921da
revision:	4602:86168c4921da
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Sun Jan 29 18:04:23 2012 +0100

Refactor ESTextAndButtonsWindowController and ESEditStatusGroupWindowController to be acceptable to the static analyzer, and fix them leaking after closing the window.

diffs (431 lines):

diff -r 9b84840441d9 -r 86168c4921da Frameworks/Adium Framework/Source/ESTextAndButtonsWindowController.h
--- a/Frameworks/Adium Framework/Source/ESTextAndButtonsWindowController.h	Sun Jan 29 17:55:50 2012 +0100
+++ b/Frameworks/Adium Framework/Source/ESTextAndButtonsWindowController.h	Sun Jan 29 18:04:23 2012 +0100
@@ -57,28 +57,27 @@
 	BOOL				allowsCloseWithoutResponse; //Is it okay to close without clicking a button?
 }
 
-+ (id)showTextAndButtonsWindowWithTitle:(NSString *)inTitle
-						  defaultButton:(NSString *)inDefaultButton
-						alternateButton:(NSString *)inAlternateButton
-							otherButton:(NSString *)inOtherButton
-							suppression:(NSString *)inSuppression
-							   onWindow:(NSWindow *)parentWindow
-					  withMessageHeader:(NSString *)inMessageHeader
-							 andMessage:(NSAttributedString *)inMessage
-								  image:(NSImage *)inImage
-								 target:(id)inTarget
-							   userInfo:(id)inUserInfo __attribute__((objc_method_family(new)));
+- (id)initWithTitle:(NSString *)inTitle
+	  defaultButton:(NSString *)inDefaultButton
+	alternateButton:(NSString *)inAlternateButton
+		otherButton:(NSString *)inOtherButton
+		suppression:(NSString *)inSuppression
+  withMessageHeader:(NSString *)inMessageHeader
+		 andMessage:(NSAttributedString *)inMessage
+			  image:(NSImage *)inImage
+			 target:(id)inTarget
+		   userInfo:(id)inUserInfo;
 
-+ (id)showTextAndButtonsWindowWithTitle:(NSString *)inTitle
-						  defaultButton:(NSString *)inDefaultButton
-						alternateButton:(NSString *)inAlternateButton
-							otherButton:(NSString *)inOtherButton
-							   onWindow:(NSWindow *)parentWindow
-					  withMessageHeader:(NSString *)inMessageHeader
-							 andMessage:(NSAttributedString *)inMessage
-								 target:(id)inTarget
-							   userInfo:(id)inUserInfo __attribute__((objc_method_family(new)));
-+ (id)controller __attribute__((objc_method_family(new)));
+- (id)initWithTitle:(NSString *)inTitle
+	  defaultButton:(NSString *)inDefaultButton
+	alternateButton:(NSString *)inAlternateButton
+		otherButton:(NSString *)inOtherButton
+  withMessageHeader:(NSString *)inMessageHeader
+		 andMessage:(NSAttributedString *)inMessage
+			 target:(id)inTarget
+		   userInfo:(id)inUserInfo;
+
+- (void)showOnWindow:(NSWindow *)parentWindow __attribute__((ns_consumes_self));
 
 - (void)changeWindowToTitle:(NSString *)inTitle
 			  defaultButton:(NSString *)inDefaultButton
diff -r 9b84840441d9 -r 86168c4921da Frameworks/Adium Framework/Source/ESTextAndButtonsWindowController.m
--- a/Frameworks/Adium Framework/Source/ESTextAndButtonsWindowController.m	Sun Jan 29 17:55:50 2012 +0100
+++ b/Frameworks/Adium Framework/Source/ESTextAndButtonsWindowController.m	Sun Jan 29 18:04:23 2012 +0100
@@ -48,74 +48,77 @@
  *
  * @see AITextAndButtonsReturnCode
  *
- * @result A retained <tt>ESTextAndButtonsWindowController</tt> which will handle releasing itself when the window is finished.
+ * @result A initialized <tt>ESTextAndButtonsWindowController</tt>.
  */
-+ (id)showTextAndButtonsWindowWithTitle:(NSString *)inTitle
+- (id)initWithTitle:(NSString *)inTitle
+	  defaultButton:(NSString *)inDefaultButton
+	alternateButton:(NSString *)inAlternateButton
+		otherButton:(NSString *)inOtherButton
+		suppression:(NSString *)inSuppression
+  withMessageHeader:(NSString *)inMessageHeader
+		 andMessage:(NSAttributedString *)inMessage
+			  image:(NSImage *)inImage
+			 target:(id)inTarget
+		   userInfo:(id)inUserInfo
+{
+	if (self = [self init]) {
+		[self changeWindowToTitle:inTitle
+					defaultButton:inDefaultButton
+				  alternateButton:inAlternateButton
+					  otherButton:inOtherButton
+					  suppression:inSuppression
+				withMessageHeader:inMessageHeader
+					   andMessage:inMessage
+							image:inImage
+						   target:inTarget
+						 userInfo:inUserInfo];
+	}
+	
+	return self;
+}
+
+- (id)init
+{
+	if (self = [super initWithWindowNibName:TEXT_AND_BUTTONS_WINDOW_NIB]) {
+		
+	}
+	
+	return self;
+}
+
+- (void)showOnWindow:(NSWindow *)parentWindow
+{
+	if (parentWindow) {
+		[NSApp beginSheet:self.window
+		   modalForWindow:parentWindow
+			modalDelegate:self
+		   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+			  contextInfo:nil];
+		
+	} else {
+		[self show];
+	}
+}
+
+- (id)initWithTitle:(NSString *)inTitle
 						  defaultButton:(NSString *)inDefaultButton
 						alternateButton:(NSString *)inAlternateButton
 							otherButton:(NSString *)inOtherButton
-							suppression:(NSString *)inSuppression
-							   onWindow:(NSWindow *)parentWindow
-					  withMessageHeader:(NSString *)inMessageHeader
-							 andMessage:(NSAttributedString *)inMessage
-								  image:(NSImage *)inImage
-								 target:(id)inTarget
-							   userInfo:(id)inUserInfo
-{
-	ESTextAndButtonsWindowController	*controller;
-	
-	controller = [[self alloc] initWithWindowNibName:TEXT_AND_BUTTONS_WINDOW_NIB];
-	[controller changeWindowToTitle:inTitle
-					  defaultButton:inDefaultButton
-					alternateButton:inAlternateButton
-						otherButton:inOtherButton
-						suppression:inSuppression
-				  withMessageHeader:inMessageHeader
-						 andMessage:inMessage
-							  image:inImage
-							 target:inTarget
-						   userInfo:inUserInfo];
-	
-	if (parentWindow) {
-		[NSApp beginSheet:[controller window]
-		   modalForWindow:parentWindow
-			modalDelegate:controller
-		   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
-			  contextInfo:nil];
-
-	} else {
-		[controller show];
-	}
-	
-	return controller;
-}
-
-+ (id)showTextAndButtonsWindowWithTitle:(NSString *)inTitle
-						  defaultButton:(NSString *)inDefaultButton
-						alternateButton:(NSString *)inAlternateButton
-							otherButton:(NSString *)inOtherButton
-							   onWindow:(NSWindow *)parentWindow
 					  withMessageHeader:(NSString *)inMessageHeader
 							 andMessage:(NSAttributedString *)inMessage
 								 target:(id)inTarget
 							   userInfo:(id)inUserInfo
 {
-	return [self showTextAndButtonsWindowWithTitle:inTitle
-									 defaultButton:inDefaultButton
-								   alternateButton:inAlternateButton
-									   otherButton:inOtherButton
-									   suppression:nil
-										  onWindow:parentWindow
-								 withMessageHeader:inMessageHeader
-										andMessage:inMessage
-											 image:nil
-											target:inTarget
-										  userInfo:inUserInfo];
-}
-
-+ (id)controller
-{
-	return [[self alloc] initWithWindowNibName:TEXT_AND_BUTTONS_WINDOW_NIB];
+	return [self initWithTitle:inTitle
+				 defaultButton:inDefaultButton
+			   alternateButton:inAlternateButton
+				   otherButton:inOtherButton
+				   suppression:nil
+			 withMessageHeader:inMessageHeader
+					andMessage:inMessage
+						 image:nil
+						target:inTarget
+					  userInfo:inUserInfo];
 }
 
 /*!
@@ -273,6 +276,8 @@
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
 {
     [sheet orderOut:nil];
+	
+	[self autorelease];
 }
 
 /*!
diff -r 9b84840441d9 -r 86168c4921da Plugins/Purple Service/ESPurpleNotifyEmailController.m
--- a/Plugins/Purple Service/ESPurpleNotifyEmailController.m	Sun Jan 29 17:55:50 2012 +0100
+++ b/Plugins/Purple Service/ESPurpleNotifyEmailController.m	Sun Jan 29 18:04:23 2012 +0100
@@ -170,19 +170,19 @@
 	NSString *mailApplicationName = [self mailApplicationName];
 	
 	if (![[NSUserDefaults standardUserDefaults] boolForKey:@"AINoNewMailWindow"]) {
-		[ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:AILocalizedString(@"New Mail",nil)
-															  defaultButton:nil
-															alternateButton:(inURLString ? 
-																			 AILocalizedString(@"Open Mail in Browser",nil) :
-																			 nil)
-																otherButton:((mailApplicationName && [mailApplicationName length]) ?
-																			 [NSString stringWithFormat:AILocalizedString(@"Launch %@", nil), mailApplicationName] :
-																			 nil)
-																   onWindow:nil
-														  withMessageHeader:nil
-																 andMessage:inMessage
-																	 target:self
-																   userInfo:inURLString];
+		ESTextAndButtonsWindowController *textAndButtonsWindowController = [[ESTextAndButtonsWindowController alloc] initWithTitle:AILocalizedString(@"New Mail",nil)
+																													 defaultButton:nil
+																												   alternateButton:(inURLString ? 
+																																	AILocalizedString(@"Open Mail in Browser",nil) :
+																																	nil)
+																													   otherButton:((mailApplicationName && [mailApplicationName length]) ?
+																																	[NSString stringWithFormat:AILocalizedString(@"Launch %@", nil), mailApplicationName] :
+																																	nil)
+																												 withMessageHeader:nil
+																														andMessage:inMessage
+																															target:self
+																														  userInfo:inURLString];
+		[textAndButtonsWindowController showOnWindow:nil];
 	}
 	
 	//XXX - Hook this to the account for listobject
diff -r 9b84840441d9 -r 86168c4921da Plugins/Purple Service/ESPurpleRequestActionController.m
--- a/Plugins/Purple Service/ESPurpleRequestActionController.m	Sun Jan 29 17:55:50 2012 +0100
+++ b/Plugins/Purple Service/ESPurpleRequestActionController.m	Sun Jan 29 18:04:23 2012 +0100
@@ -92,15 +92,18 @@
 		 * If we have an attribMsg and a titleString, use the titleString as the window title.
 		 * If we just have the titleString (and no attribMsg), it is our message, and the window has no title.
 		 */
-		requestController = [[ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:title
+		requestController = [[ESTextAndButtonsWindowController alloc] initWithTitle:title
 																				   defaultButton:defaultButton
 																				 alternateButton:alternateButton
 																					 otherButton:otherButton
-																						onWindow:nil
 																			   withMessageHeader:messageHeader
 																					  andMessage:attributedMessage
 																						  target:self
-																						userInfo:infoDict] retain];
+																						userInfo:infoDict];
+		// We retain it once more, as showOnWindow will (eventually) do a release.
+		[requestController retain];
+		[requestController showOnWindow:nil];
+		
 		if ([infoDict objectForKey:@"Image"])
 			[requestController setImage:[infoDict objectForKey:@"Image"]];
 
diff -r 9b84840441d9 -r 86168c4921da Source/ESEditStatusGroupWindowController.h
--- a/Source/ESEditStatusGroupWindowController.h	Sun Jan 29 17:55:50 2012 +0100
+++ b/Source/ESEditStatusGroupWindowController.h	Sun Jan 29 18:04:23 2012 +0100
@@ -32,7 +32,8 @@
 	id								target;
 }
 
-+ (void)editStatusGroup:(AIStatusGroup *)inStatusGroup onWindow:(id)parentWindow notifyingTarget:(id)inTarget;
+- (void)showOnWindow:(NSWindow *)parentWindow __attribute__((ns_consumes_self));
+- (id)initWithStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget;
 
 - (IBAction)okay:(id)sender;
 - (IBAction)cancel:(id)sender;
diff -r 9b84840441d9 -r 86168c4921da Source/ESEditStatusGroupWindowController.m
--- a/Source/ESEditStatusGroupWindowController.m	Sun Jan 29 17:55:50 2012 +0100
+++ b/Source/ESEditStatusGroupWindowController.m	Sun Jan 29 18:04:23 2012 +0100
@@ -23,35 +23,28 @@
 
 @interface ESEditStatusGroupWindowController ()
 - (NSMenu *)groupWithStatusMenu;
-- (id)initWithWindowNibName:(NSString *)windowNibName forStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget;
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
 @end
 
 @implementation ESEditStatusGroupWindowController
 
-+ (void)editStatusGroup:(AIStatusGroup *)inStatusGroup onWindow:(id)parentWindow notifyingTarget:(id)inTarget
+- (void)showOnWindow:(NSWindow *)parentWindow
 {
-	ESEditStatusGroupWindowController *controller;
-
-	controller = [[self alloc] initWithWindowNibName:@"EditStatusGroup"
-									  forStatusGroup:inStatusGroup
-									 notifyingTarget:inTarget];
-
 	if (parentWindow) {
-		[NSApp beginSheet:[controller window]
+		[NSApp beginSheet:self.window
 		   modalForWindow:parentWindow
-			modalDelegate:controller
+			modalDelegate:self
 		   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
 			  contextInfo:nil];
 	} else {
-		[controller showWindow:nil];
-		[[controller window] makeKeyAndOrderFront:nil];
+		[self showWindow:nil];
+		[self.window makeKeyAndOrderFront:nil];
 	}
 }
 
-- (id)initWithWindowNibName:(NSString *)windowNibName forStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget
+- (id)initWithStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget
 {
-    if ((self = [super initWithWindowNibName:windowNibName])) {
+    if ((self = [super initWithWindowNibName:@"EditStatusGroup"])) {
 		target = inTarget;
 		statusGroup = (inStatusGroup ? [inStatusGroup retain] : [[AIStatusGroup alloc] init]);
 	}	
@@ -107,6 +100,8 @@
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
 {
     [sheet orderOut:nil];
+	
+	[self autorelease];
 }
 
 
diff -r 9b84840441d9 -r 86168c4921da Source/ESOTRUnknownFingerprintController.m
--- a/Source/ESOTRUnknownFingerprintController.m	Sun Jan 29 17:55:50 2012 +0100
+++ b/Source/ESOTRUnknownFingerprintController.m	Sun Jan 29 18:04:23 2012 +0100
@@ -98,17 +98,17 @@
 												  direction:AIIconNormal];
 	}
 	
-	[ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:AILocalizedString(@"OTR Fingerprint Verification",nil)
-														  defaultButton:acceptButton
-														alternateButton:denyButton
-															otherButton:AILocalizedString(@"Help", nil)
-															suppression:nil
-															   onWindow:nil
-													  withMessageHeader:nil
-															 andMessage:[AIHTMLDecoder decodeHTML:messageString]
-																  image:serviceImage
-																 target:self
-															   userInfo:responseInfo];	
+	ESTextAndButtonsWindowController *textAndButtonsWindowController = [[ESTextAndButtonsWindowController alloc] initWithTitle:AILocalizedString(@"OTR Fingerprint Verification",nil)
+																												 defaultButton:acceptButton
+																											   alternateButton:denyButton
+																												   otherButton:AILocalizedString(@"Help", nil)
+																												   suppression:nil
+																											 withMessageHeader:nil
+																													andMessage:[AIHTMLDecoder decodeHTML:messageString]
+																														 image:serviceImage
+																														target:self
+																													  userInfo:responseInfo];
+	[textAndButtonsWindowController showOnWindow:nil];
 }
 
 /*!
@@ -131,15 +131,15 @@
 				who,
 				who];
 			
-			[ESTextAndButtonsWindowController showTextAndButtonsWindowWithTitle:nil
+			ESTextAndButtonsWindowController *textAndButtonsWindowController = [[ESTextAndButtonsWindowController alloc] initWithTitle:nil
 																  defaultButton:nil
 																alternateButton:nil
 																	otherButton:nil
-																	   onWindow:window
 															  withMessageHeader:AILocalizedString(@"Fingerprint Help", nil)
 																	 andMessage:[[[NSAttributedString alloc] initWithString:message] autorelease]
 																		 target:self
-																	   userInfo:nil];	
+																	   userInfo:nil];
+			[textAndButtonsWindowController showOnWindow:window];
 			
 			//Don't close the original window if the help button is pressed
 			shouldCloseWindow = NO;
diff -r 9b84840441d9 -r 86168c4921da Source/ESStatusPreferences.m
--- a/Source/ESStatusPreferences.m	Sun Jan 29 17:55:50 2012 +0100
+++ b/Source/ESStatusPreferences.m	Sun Jan 29 18:04:23 2012 +0100
@@ -198,9 +198,9 @@
 										 notifyingTarget:self];
 			
 		} else if ([statusState isKindOfClass:[AIStatusGroup class]]) {
-			[ESEditStatusGroupWindowController editStatusGroup:(AIStatusGroup *)statusState
-													  onWindow:[[self view] window]
-											   notifyingTarget:self];			
+			ESEditStatusGroupWindowController *editStatusGroupWindowController = [[ESEditStatusGroupWindowController alloc] initWithStatusGroup:(AIStatusGroup *)statusState
+																																notifyingTarget:self];
+			[editStatusGroupWindowController showOnWindow:[[self view] window]];
 		}
 	}
 }
@@ -326,9 +326,9 @@
 
 - (IBAction)addGroup:(id)sender
 {
-	[ESEditStatusGroupWindowController editStatusGroup:nil
-											  onWindow:[[self view] window]
-									   notifyingTarget:self];
+	ESEditStatusGroupWindowController *editStatusGroupWindowController = [[ESEditStatusGroupWindowController alloc] initWithStatusGroup:nil
+																														notifyingTarget:self];
+	[editStatusGroupWindowController showOnWindow:[[self view] window]];
 }
 
 - (IBAction)addOrRemoveState:(id)sender
diff -r 9b84840441d9 -r 86168c4921da Source/GBQuestionHandlerPlugin.m
--- a/Source/GBQuestionHandlerPlugin.m	Sun Jan 29 17:55:50 2012 +0100
+++ b/Source/GBQuestionHandlerPlugin.m	Sun Jan 29 18:04:23 2012 +0100
@@ -118,7 +118,7 @@
 	{
 		NSDictionary *info = [errorQueue objectAtIndex:0];
 		if(currentAlert == nil)
-			currentAlert = [[ESTextAndButtonsWindowController controller] retain];
+			currentAlert = [[ESTextAndButtonsWindowController alloc] init];
 		[currentAlert changeWindowToTitle:[info objectForKey:@"Window Title"]
 							defaultButton:AILocalizedString(@"Next", @"Next Button")
 						  alternateButton:AILocalizedString(@"Dismiss All", @"Dismiss All Button")
@@ -137,7 +137,7 @@
 	{
 		NSDictionary *info = [questionQueue objectAtIndex:0];
 		if(currentAlert == nil)
-			currentAlert = [[ESTextAndButtonsWindowController controller] retain];
+			currentAlert = [[ESTextAndButtonsWindowController alloc] init];
 		[currentAlert changeWindowToTitle:[info objectForKey:@"Window Title"]
 							defaultButton:[info objectForKey:@"Default Button"]
 						  alternateButton:[info objectForKey:@"Alternate Button"]




More information about the commits mailing list