adium 4616:821851cc0b2e: Keep the NSConnection AIAdium creates a...

commits at adium.im commits at adium.im
Sun Jan 29 20:25:22 UTC 2012


details:	http://hg.adium.im/adium/rev/821851cc0b2e
revision:	4616:821851cc0b2e
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Sun Jan 29 21:24:57 2012 +0100

Keep the NSConnection AIAdium creates around, so the static analyzer can be happy about it.
Subject: adium 4617:2088de30d4fe: Refactored AINewContactWindowController to be acceptable to the static analyzer.

details:	http://hg.adium.im/adium/rev/2088de30d4fe
revision:	4617:2088de30d4fe
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Sun Jan 29 21:25:13 2012 +0100

Refactored AINewContactWindowController to be acceptable to the static analyzer.

diffs (205 lines):

diff -r 3a28d740babe -r 2088de30d4fe Source/AIAdium.h
--- a/Source/AIAdium.h	Sun Jan 29 21:00:22 2012 +0100
+++ b/Source/AIAdium.h	Sun Jan 29 21:25:13 2012 +0100
@@ -62,6 +62,7 @@
 	BOOL								completedApplicationLoad;
 	NSString							*advancedPrefsName;	
 	BOOL								isQuitting;
+	NSConnection						*connection;
 }
 
 - (IBAction)showAboutBox:(id)sender;
diff -r 3a28d740babe -r 2088de30d4fe Source/AIAdium.m
--- a/Source/AIAdium.m	Sun Jan 29 21:00:22 2012 +0100
+++ b/Source/AIAdium.m	Sun Jan 29 21:25:13 2012 +0100
@@ -262,7 +262,7 @@
 														  object:nil];
 	
 	//Broadcast our presence
-	NSConnection *connection = [[NSConnection alloc] init];
+	connection = [[NSConnection alloc] init];
 	[connection setRootObject:self];
 	[connection registerName:@"com.adiumX.adiumX"];
 
@@ -343,6 +343,8 @@
 {
 	//Take no action if we didn't complete the application load
 	if (!completedApplicationLoad) return;
+	
+	[connection release]; connection = nil;
 
 	isQuitting = YES;
 
diff -r 3a28d740babe -r 2088de30d4fe Source/AIContactListEditorPlugin.m
--- a/Source/AIContactListEditorPlugin.m	Sun Jan 29 21:00:22 2012 +0100
+++ b/Source/AIContactListEditorPlugin.m	Sun Jan 29 21:25:13 2012 +0100
@@ -221,10 +221,10 @@
 		inListObject = nil;
 	}
 	
-	[AINewContactWindowController promptForNewContactOnWindow:inWindow
-														 name:(inListObject ? inListObject.UID : nil)
-													  service:(inListObject ? [(AIListContact *)inListObject service] : nil)
-													  account:nil];
+	AINewContactWindowController *newContactWindowController = [[AINewContactWindowController alloc] initWithContactName:(inListObject ? inListObject.UID : nil)
+																												 service:(inListObject ? [(AIListContact *)inListObject service] : nil)
+																												 account:nil];
+	[newContactWindowController showOnWindow:inWindow];
 }
 
 /*!
@@ -237,10 +237,10 @@
 {
 	NSDictionary *userInfo = [notification userInfo];
 	if (userInfo) {
-		[AINewContactWindowController promptForNewContactOnWindow:nil
-															 name:[userInfo objectForKey:@"UID"]
-														  service:[userInfo objectForKey:@"AIService"]
-														  account:[userInfo objectForKey:@"AIAccount"]];
+		AINewContactWindowController *newContactWindowController = [[AINewContactWindowController alloc] initWithContactName:[userInfo objectForKey:@"UID"]
+																													 service:[userInfo objectForKey:@"AIService"]
+																													 account:[userInfo objectForKey:@"AIAccount"]];
+		[newContactWindowController showOnWindow:nil];
 	}
 }
 
diff -r 3a28d740babe -r 2088de30d4fe Source/AINewContactWindowController.h
--- a/Source/AINewContactWindowController.h	Sun Jan 29 21:00:22 2012 +0100
+++ b/Source/AINewContactWindowController.h	Sun Jan 29 21:25:13 2012 +0100
@@ -50,7 +50,8 @@
 	ABPerson						*person;
 }
 
-+ (void)promptForNewContactOnWindow:(NSWindow *)parentWindow name:(NSString *)contact service:(AIService *)inService  account:(AIAccount *)inAccount;
+- (id)initWithContactName:(NSString *)inName service:(AIService *)inService account:(AIAccount *)inAccount;
+- (void)showOnWindow:(NSWindow *)parentWindow __attribute__((ns_consumes_self));
 - (IBAction)cancel:(id)sender;
 - (IBAction)addContact:(id)sender;
 - (IBAction)searchInAB:(id)sender;
diff -r 3a28d740babe -r 2088de30d4fe Source/AINewContactWindowController.m
--- a/Source/AINewContactWindowController.m	Sun Jan 29 21:00:22 2012 +0100
+++ b/Source/AINewContactWindowController.m	Sun Jan 29 21:25:13 2012 +0100
@@ -37,7 +37,6 @@
 #define DEFAULT_GROUP_NAME		AILocalizedString(@"Contacts",nil)
 
 @interface AINewContactWindowController ()
-- (id)initWithWindowNibName:(NSString *)windowNibName contactName:(NSString *)inName service:(AIService *)inService  account:(AIAccount *)inAccount;
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
 
 - (void)buildGroupMenu;
@@ -62,41 +61,33 @@
  */
 @implementation AINewContactWindowController
 
-/*!
- * @brief Prompt for adding a new contact.
- *
- * @param parentWindow Window on which to show the prompt as a sheet. Pass nil for a panel prompt. 
- * @param inName Initial value for the contact name field
- * @param inService <tt>AIService</tt> for determining the initial service type selection
- * @param inAccount If non-nil, the one AIAccount which should be initially enabled for adding this contact
- */
-+ (void)promptForNewContactOnWindow:(NSWindow *)parentWindow name:(NSString *)inName service:(AIService *)inService account:(AIAccount *)inAccount
+- (void)showOnWindow:(NSWindow *)parentWindow
 {
-	AINewContactWindowController	*newContactWindow;
-	
-	newContactWindow = [[self alloc] initWithWindowNibName:ADD_CONTACT_PROMPT_NIB contactName:inName service:inService account:inAccount];
-	
 	if (parentWindow) {
 		[parentWindow makeKeyAndOrderFront:nil];
 		
-		[NSApp beginSheet:[newContactWindow window]
+		[NSApp beginSheet:self.window
 		   modalForWindow:parentWindow
-			modalDelegate:newContactWindow
+			modalDelegate:self
 		   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
 			  contextInfo:nil];
 	} else {
-		[newContactWindow showWindow:nil];
-		[[newContactWindow window] makeKeyAndOrderFront:nil];
+		[self showWindow:nil];
+		[self.window makeKeyAndOrderFront:nil];
 	}
 	
 }
 
 /*!
  * @brief Initialize
+ *
+ * @param inName Initial value for the contact name field
+ * @param inService <tt>AIService</tt> for determining the initial service type selection
+ * @param inAccount If non-nil, the one AIAccount which should be initially enabled for adding this contact
  */
-- (id)initWithWindowNibName:(NSString *)windowNibName contactName:(NSString *)inName service:(AIService *)inService account:(AIAccount *)inAccount
+- (id)initWithContactName:(NSString *)inName service:(AIService *)inService account:(AIAccount *)inAccount
 {
-    if ((self = [super initWithWindowNibName:windowNibName])) {
+    if ((self = [super initWithWindowNibName:ADD_CONTACT_PROMPT_NIB])) {
 		service = [inService retain];
 		initialAccount = [inAccount retain];
 		contactName = [inName retain];
@@ -111,6 +102,9 @@
  */
 - (void)dealloc
 {
+	[[AIContactObserverManager sharedManager] unregisterListObjectObserver:self];
+	[[NSNotificationCenter defaultCenter] removeObserver:self];
+	
 	[accounts release];
 	[contactName release];
 	[service release];
@@ -165,8 +159,8 @@
 - (void)windowWillClose:(id)sender
 {
 	[super windowWillClose:sender];
-	[[AIContactObserverManager sharedManager] unregisterListObjectObserver:self];
-	[[NSNotificationCenter defaultCenter] removeObserver:self];
+	
+	[self autorelease];
 }
 
 /*!
@@ -175,6 +169,8 @@
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
 {
     [sheet orderOut:nil];
+	
+	[self autorelease];
 }
 
 /*!
diff -r 3a28d740babe -r 2088de30d4fe Source/AIURLHandlerPlugin.m
--- a/Source/AIURLHandlerPlugin.m	Sun Jan 29 21:00:22 2012 +0100
+++ b/Source/AIURLHandlerPlugin.m	Sun Jan 29 21:25:13 2012 +0100
@@ -403,10 +403,10 @@
 				
 				jabberService = [adium.accountController firstServiceWithServiceID:@"Jabber"];
 				
-				[AINewContactWindowController promptForNewContactOnWindow:nil
-																	 name:[NSString stringWithFormat:@"%@@%@", [url user], [url host]]
-																  service:jabberService
-																  account:nil];
+				AINewContactWindowController *newContactWindowController = [[AINewContactWindowController alloc] initWithContactName:[NSString stringWithFormat:@"%@@%@", [url user], [url host]]
+																															 service:jabberService
+																															 account:nil];
+				[newContactWindowController showOnWindow:nil];
 			} else if ([query rangeOfString:@"remove"].location == 0
 					   || [query rangeOfString:@"unsubscribe"].location == 0) {
 				// xmpp:johndoe at jabber.org?remove
@@ -455,10 +455,10 @@
 			
 			if (contactName.length) {
 				if ([host isEqualToString:@"addContact"]) {
-					[AINewContactWindowController promptForNewContactOnWindow:nil
-																		 name:contactName
-																	  service:[adium.accountController firstServiceWithServiceID:serviceID]
-																	  account:nil];
+					AINewContactWindowController *newContactWindowController = [[AINewContactWindowController alloc] initWithContactName:contactName
+																																 service:[adium.accountController firstServiceWithServiceID:serviceID]
+																																 account:nil];
+					[newContactWindowController showOnWindow:nil];
 				} else if ([host isEqualToString:@"sendIM"]) {
 					[self _openChatToContactWithName:contactName
 										   onService:serviceID




More information about the commits mailing list