adium 2180:7b29d466a157: Simplify and correct a few bugs in the ...

commits at adium.im commits at adium.im
Thu May 14 03:13:53 UTC 2009


details:	http://hg.adium.im/adium/rev/7b29d466a157
revision:	2180:7b29d466a157
author:		Zachary West <zacw at adium.im>
date:		Wed May 13 23:13:35 2009 -0400

Simplify and correct a few bugs in the always visibile logic.

Contacts in metas always return their meta's value, the property's value is set to the correct one (instead of…it's current visibility…*cry*), and we no longer observe the preference changes, which didn't appear to be working anyway.

diffstat:

 Frameworks/Adium Framework/Source/AIListContact.m |   9 +++
 Frameworks/Adium Framework/Source/AIListObject.h  |   1 -
 Frameworks/Adium Framework/Source/AIListObject.m  |  57 ++++++-------------
 3 files changed, 27 insertions(+), 40 deletions(-)

diffs (109 lines):

diff -r 5717bc0e5257 -r 7b29d466a157 Frameworks/Adium Framework/Source/AIListContact.m
--- a/Frameworks/Adium Framework/Source/AIListContact.m	Wed May 13 19:45:41 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIListContact.m	Wed May 13 23:13:35 2009 -0400
@@ -619,6 +619,15 @@
 	return pref;
 }
 
+- (BOOL)alwaysVisible
+{
+	if (self.metaContact) {
+		return self.metaContact.alwaysVisible;
+	}
+	
+	return [super alwaysVisible];
+}
+
 #pragma mark Status
 
 /*!
diff -r 5717bc0e5257 -r 7b29d466a157 Frameworks/Adium Framework/Source/AIListObject.h
--- a/Frameworks/Adium Framework/Source/AIListObject.h	Wed May 13 19:45:41 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIListObject.h	Wed May 13 23:13:35 2009 -0400
@@ -84,7 +84,6 @@
 	
 	NSString			*UID;
 	NSString			*internalObjectID;
-	BOOL				alwaysVisible;
 
 	//Grouping, Manual ordering
 	NSMutableSet *m_groups; //The AIContainingObjects that this object is in; currently always has only 1
diff -r 5717bc0e5257 -r 7b29d466a157 Frameworks/Adium Framework/Source/AIListObject.m
--- a/Frameworks/Adium Framework/Source/AIListObject.m	Wed May 13 19:45:41 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIListObject.m	Wed May 13 23:13:35 2009 -0400
@@ -81,31 +81,9 @@
 
 - (void)setupObservedValues
 {
-	[adium.preferenceController addObserver:self
-	 forKeyPath:@"Always Visible.Visible"
-	 ofObject:self
-	 options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial
-	 context:NULL];
-	
-	[self observeValueForKeyPath:@"Always Visible.Visible"
-						ofObject:nil
-						  change:nil
-						 context:NULL];	
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
-{
-	if ([keyPath hasSuffix:@"Visible"]) {
-		BOOL alwaysVisibleSelf = [[self preferenceForKey:@"Visible" group:PREF_GROUP_ALWAYS_VISIBLE] boolValue];
-		
-#warning AIListObject should not know of its subclass
-		// If we're in a meta contact, use the meta contact's preference for visibility.
-		if ([self isKindOfClass:[AIListContact class]]) {
-			alwaysVisibleSelf = [[((AIListContact *)self).parentContact preferenceForKey:@"Visible" group:PREF_GROUP_ALWAYS_VISIBLE] boolValue];
-		}
-
-		alwaysVisible = alwaysVisibleSelf;
-	}
+	[self setValue:[self preferenceForKey:@"Visible" group:PREF_GROUP_ALWAYS_VISIBLE]
+	   forProperty:AlwaysVisible
+			notify:NotifyNow];
 }
 
 //Identification -------------------------------------------------------------------------------------------------------
@@ -156,25 +134,26 @@
 /*!
  * @brief Sets if list object should always be visible
  */
-- (void)setAlwaysVisible:(BOOL)inVisible {
-	if (inVisible != alwaysVisible) {
-		[self setPreference:[NSNumber numberWithBool:inVisible] 
-					 forKey:@"Visible" 
-					  group:PREF_GROUP_ALWAYS_VISIBLE];
-		
-		[self setValue:[NSNumber numberWithBool:alwaysVisible]
-					   forProperty:AlwaysVisible
-					   notify:NotifyNow];
-		
-		[adium.contactController sortListObject:self];
-	}
+- (void)setAlwaysVisible:(BOOL)inVisible
+{
+	[self setPreference:[NSNumber numberWithBool:inVisible] 
+				 forKey:@"Visible" 
+				  group:PREF_GROUP_ALWAYS_VISIBLE];
+	
+	// This causes our container to update our visibility.
+	[self setValue:[NSNumber numberWithBool:inVisible]
+				   forProperty:AlwaysVisible
+				   notify:NotifyNow];
 }
 
 /*!
+ * @brief Should this object ignore visibility settings?
+ *
  * @returns If object should always be visible
  */
-- (BOOL)alwaysVisible {
-	return alwaysVisible;
+- (BOOL)alwaysVisible
+{
+	return [self boolValueForProperty:AlwaysVisible];
 }
 
 //Grouping / Ownership -------------------------------------------------------------------------------------------------


More information about the commits mailing list