Commits

Thijs Alkemade committed 9719321

Only show the "Voice chat" and "Video chat" items when the remote client supports them

Comments (0)

Files changed (2)

Source/AV/AIAudioChatPlugin.m

 #import <AIUtilities/AIImageAdditions.h>
 #import <AIUtilities/AIWindowAdditions.h>
 #import <Adium/AIListContact.h>
+#import <Adium/AIMetaContact.h>
+#import <Adium/AIAccountControllerProtocol.h>
 
 
 #define VOICE_CHAT_TITLE			[AILocalizedString(@"Voice chat",nil) stringByAppendingEllipsis]
 																	 action:@selector(openVideoChatWithContact:)
 															  keyEquivalent:@""] autorelease];
     [adium.menuController addContextualMenuItem:menuItem toLocation:Context_Contact_Action];
-	
 
 	
 	
 
 }
 
-
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
+{
+	AIListObject *listObject = adium.menuController.currentContextMenuObject;
+	
+	if (!listObject || ![listObject isKindOfClass:[AIListContact class]])
+		return FALSE;
+	
+	AIListContact *listContact = (AIListContact *)listObject;
+	AIListContact *preferredContact;
+	
+	if ([listContact isKindOfClass:[AIMetaContact class]]) {
+		preferredContact = [((AIMetaContact *)listContact) preferredContactWithCompatibleService:[adium.accountController firstServiceWithServiceID:@"Jabber"]];
+	} else {
+		preferredContact = listContact;
+	}
+	
+	PurpleAccount *account = [(CBPurpleAccount *)preferredContact.account purpleAccount];
+	PurpleBuddy *buddy = (account ? purple_find_buddy(account, [preferredContact.UID UTF8String]) : nil);
+	
+	if (!buddy)
+		return FALSE;
+	
+	if ([[menuItem title] isEqualToString:VIDEO_CHAT_TITLE]) {
+		PurpleMediaCaps caps = purple_prpl_get_media_caps(purple_buddy_get_account(buddy), purple_buddy_get_name(buddy));
+		return (caps & PURPLE_MEDIA_CAPS_AUDIO_VIDEO) == PURPLE_MEDIA_CAPS_AUDIO_VIDEO;
+	} else if ([[menuItem title] isEqualToString:VOICE_CHAT_TITLE]) {
+		PurpleMediaCaps caps = purple_prpl_get_media_caps(purple_buddy_get_account(buddy), purple_buddy_get_name(buddy));
+		return (caps & PURPLE_MEDIA_CAPS_AUDIO) == PURPLE_MEDIA_CAPS_AUDIO;
+	}
+	
+	return TRUE;
+}
 
 - (IBAction)openVoiceChatWithContact:(id)sender
-
 {
-	AIListContact *contactListObject = [adium.interfaceController selectedListObjectInContactList];
+	AIListContact *contactListObject = (AIListContact *)[adium.interfaceController selectedListObjectInContactList];
 	NSLog(@"Starting voice chat with %@", contactListObject.ownDisplayName); 
 	AIVoiceController *controller = [[AIVoiceController alloc] initWithWindowNibName:@"AIAudioChatPluginWindow"];
 	[controller showWindow:sender];
 }
 
 - (IBAction)openVideoChatWithContact:(id)sender
-
 {
-	AIListContact *contactListObject = [adium.interfaceController selectedListObjectInContactList];
+	AIListContact *contactListObject = (AIListContact *)[adium.interfaceController selectedListObjectInContactList];
 	NSLog(@"Starting voice chat with %@", contactListObject.ownDisplayName); 
 	AIVoiceController *controller = [[AIVoiceController alloc] initWithWindowNibName:@"AIAudioChatPluginWindow"];
 	[controller showWindow:sender];

Source/AV/AIVoiceController.m

 
 
 - (void)startVoiceCallWithBuddyContact:(AIListContact *)contact {
-	PurpleAccount *account = [(CBPurpleAccount *)contact.account purpleAccount];
 	AIListContact *preferredContact;
+	
 	if ([contact isKindOfClass:[AIMetaContact class]]) {
 		preferredContact = [((AIMetaContact *)contact) preferredContactWithCompatibleService:[adium.accountController firstServiceWithServiceID:@"Jabber"]];
 	} else {
 		preferredContact = contact;
 	}
+	
+	PurpleAccount *account = [(CBPurpleAccount *)preferredContact.account purpleAccount];
 	PurpleBuddy *buddy = (account ? purple_find_buddy(account, [preferredContact.UID UTF8String]) : nil);
 	[self startVoiceCallWithBuddy:buddy];
 }
 
 
 - (void)startVideoCallWithBuddyContact:(AIListContact *)contact {
-	PurpleAccount *account = [(CBPurpleAccount *)contact.account purpleAccount];
 	AIListContact *preferredContact;
+	
 	if ([contact isKindOfClass:[AIMetaContact class]]) {
 		preferredContact = [((AIMetaContact *)contact) preferredContactWithCompatibleService:[adium.accountController firstServiceWithServiceID:@"Jabber"]];
 	} else {
 		preferredContact = contact;
 	}
+	
+	PurpleAccount *account = [(CBPurpleAccount *)preferredContact.account purpleAccount];
 	PurpleBuddy *buddy = (account ? purple_find_buddy(account, [preferredContact.UID UTF8String]) : nil);
 	[self startVideoCallWithBuddy:buddy];
 }