adium 3039:5da4ba3a19c3: Store protocol info in the AIMedia itse...

commits at adium.im commits at adium.im
Thu Dec 10 06:30:02 UTC 2009


details:	http://hg.adium.im/adium/rev/5da4ba3a19c3
revision:	3039:5da4ba3a19c3
author:		Zachary West <zacw at adium.im>
date:		Thu Dec 10 01:29:55 2009 -0500

Store protocol info in the AIMedia itself; the protocol's job is to manage it. Adds some AIAccount methods to handle media events that it might need to handle.

diffs (513 lines):

diff -r f599fa0d98d5 -r 5da4ba3a19c3 Frameworks/Adium Framework/Source/AIAccount.h
--- a/Frameworks/Adium Framework/Source/AIAccount.h	Thu Dec 10 00:55:54 2009 -0500
+++ b/Frameworks/Adium Framework/Source/AIAccount.h	Thu Dec 10 01:29:55 2009 -0500
@@ -97,6 +97,39 @@
 	- (void)cancelFileTransfer:(ESFileTransfer *)fileTransfer;
 @end
 
+ at class AIMedia;
+
+//Support for media
+ at protocol AIAccount_Media
+/*!
+ * @brief Set the hold state for media.
+ *
+ * @param hold If the media's state should be hold
+ */
+- (void)media:(AIMedia *)media setHold:(BOOL)hold;
+
+/*!
+ * @brief Set the mute state for media.
+ *
+ * @param mute If the media's state should be mute
+ */
+- (void)media:(AIMedia *)media setMute:(BOOL)mute;
+
+/*!
+ * @brief Set the pause state for media.
+ *
+ * @param pause If the media's state should be pause
+ */
+- (void)media:(AIMedia *)media setPause:(BOOL)pause;
+
+/*!
+ * @brief Close a media
+ *
+ * @param media The AIMedia to close
+ */
+- (void)closeMedia:(AIMedia *)media;
+ at end
+
 /*!
  * @protocol AIAccount_Privacy
  * @brief Support for privacy settings
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Frameworks/Adium Framework/Source/AIMedia.h
--- a/Frameworks/Adium Framework/Source/AIMedia.h	Thu Dec 10 00:55:54 2009 -0500
+++ b/Frameworks/Adium Framework/Source/AIMedia.h	Thu Dec 10 01:29:55 2009 -0500
@@ -6,11 +6,25 @@
 //  Copyright 2009  . All rights reserved.
 //
 
-#import <Cocoa/Cocoa.h>
+#import <Adium/AIMediaControllerProtocol.h>
 
+ at class AIListContact, AIAccount;
 
 @interface AIMedia : NSObject {
-
+	AIAccount		*account;
+	AIListContact	*listContact;
+	id				protocolInfo;
+	
+	AIMediaState	mediaState;
 }
 
+ at property (assign, nonatomic) id protocolInfo;
+
+ at property (readwrite, nonatomic) AIMediaState mediaState;
+ at property (readwrite, retain, nonatomic) AIAccount *account;
+ at property (readwrite, retain, nonatomic) AIListContact *listContact;
+
++ (AIMedia *)mediaWithContact:(AIListContact *)inListContact
+					onAccount:(AIAccount *)inAccount;
+
 @end
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Frameworks/Adium Framework/Source/AIMedia.m
--- a/Frameworks/Adium Framework/Source/AIMedia.m	Thu Dec 10 00:55:54 2009 -0500
+++ b/Frameworks/Adium Framework/Source/AIMedia.m	Thu Dec 10 01:29:55 2009 -0500
@@ -7,8 +7,50 @@
 //
 
 #import "AIMedia.h"
+#import <Adium/AIAccount.h>
+#import <Adium/AIListContact.h>
 
+ at interface AIMedia()
+- (id)initWithContact:(AIListContact *)inListContact
+			  onAccount:(AIAccount *)inAccount;
+ at end
 
 @implementation AIMedia
 
++ (AIMedia *)mediaWithContact:(AIListContact *)inListContact
+					onAccount:(AIAccount *)inAccount
+{
+	return [[[self alloc] initWithContact:inListContact
+								onAccount:inAccount] autorelease];
+}
+
+ at synthesize listContact, mediaState, account, protocolInfo;
+
+- (id)initWithContact:(AIListContact *)inListContact
+			  onAccount:(AIAccount *)inAccount
+{
+	if ((self = [super init])) {
+		self.account = inAccount;
+		self.listContact = inListContact;
+		self.mediaState = AIMediaStateWaiting;
+	}
+	
+	return self;
+}
+
+- (void)dealloc
+{
+	[account release];
+	[listContact release];
+	
+	[super dealloc];
+}
+
+- (void)setMediaState:(AIMediaState)inMediaState
+{
+	mediaState = inMediaState;
+	
+	[adium.mediaController media:self didSetState:inMediaState];
+}
+
 @end
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Frameworks/Adium Framework/Source/AIMediaControllerProtocol.h
--- a/Frameworks/Adium Framework/Source/AIMediaControllerProtocol.h	Thu Dec 10 00:55:54 2009 -0500
+++ b/Frameworks/Adium Framework/Source/AIMediaControllerProtocol.h	Thu Dec 10 01:29:55 2009 -0500
@@ -15,11 +15,6 @@
 	AIMediaStateRejected,		/* Rejected call */
 } AIMediaState;
 
-typedef enum {
-	AIMediaPropertyMedia = 1,	/* A pointer to the PurpleMedia* */
-	AIMediaPropertyScreenName	/* The screen name of the user */
-} AIMediaProperty;
-
 @class AIMedia, AIListContact, AIAccount;
 
 @protocol AIMediaController <AIController>
@@ -31,4 +26,6 @@
 
 - (void)showMedia:(AIMedia *)media;
 
+- (void)media:(AIMedia *)media didSetState:(AIMediaState)state;
+
 @end
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Plugins/Purple Service/CBPurpleAccount.h
--- a/Plugins/Purple Service/CBPurpleAccount.h	Thu Dec 10 00:55:54 2009 -0500
+++ b/Plugins/Purple Service/CBPurpleAccount.h	Thu Dec 10 01:29:55 2009 -0500
@@ -63,8 +63,7 @@
 - (AIService *)_serviceForUID:(NSString *)contactUID;
 - (void)unregisteredAccount:(BOOL)success;
 
-/* CBPurpleAccount odes not implement AIAccount_Files; however, all subclasses which do use the same code.
-	The superclass therefore has the code and declares the methods here. */
+#pragma mark Subclass-reuse but not declared
 	//Instructs the account to accept a file transfer request
 - (void)acceptFileTransferRequest:(ESFileTransfer *)fileTransfer;
 	//Instructs the account to reject a file receive request
@@ -72,6 +71,34 @@
 	//Instructs the account to cancel a file transfer in progress
 - (void)cancelFileTransfer:(ESFileTransfer *)fileTransfer;
 
+/*!
+ * @brief Set the hold state for media.
+ *
+ * @param hold If the media's state should be hold
+ */
+- (void)media:(AIMedia *)media setHold:(BOOL)hold;
+
+/*!
+ * @brief Set the mute state for media.
+ *
+ * @param mute If the media's state should be mute
+ */
+- (void)media:(AIMedia *)media setMute:(BOOL)mute;
+
+/*!
+ * @brief Set the pause state for media.
+ *
+ * @param pause If the media's state should be pause
+ */
+- (void)media:(AIMedia *)media setPause:(BOOL)pause;
+
+/*!
+ * @brief Close a media
+ *
+ * @param media The AIMedia to close
+ */
+- (void)closeMedia:(AIMedia *)media;
+
 	//Private (for subclasses only) file transfer methods
 - (PurpleXfer *)newOutgoingXferForFileTransfer:(ESFileTransfer *)fileTransfer;
 - (void)_beginSendOfFileTransfer:(ESFileTransfer *)fileTransfer;
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Plugins/Purple Service/CBPurpleAccount.m
--- a/Plugins/Purple Service/CBPurpleAccount.m	Thu Dec 10 00:55:54 2009 -0500
+++ b/Plugins/Purple Service/CBPurpleAccount.m	Thu Dec 10 01:29:55 2009 -0500
@@ -58,6 +58,8 @@
 #import <AIUtilities/AIMutableStringAdditions.h>
 #import <AIUtilities/AISystemNetworkDefaults.h>
 #import <Adium/AdiumAuthorization.h>
+#import <Adium/AIMedia.h>
+#import <Adium/AIMediaControllerProtocol.h>
 
 #import "ESiTunesPlugin.h"
 #import "AMPurpleTuneTooltip.h"
@@ -1760,6 +1762,55 @@
 	}	
 }
 
+#pragma mark Media
+/*!
+ * @brief Set the hold state for media.
+ *
+ * @param hold If the media's state should be hold
+ */
+- (void)media:(AIMedia *)media setHold:(BOOL)hold
+{
+	purple_media_stream_info((PurpleMedia *)media.protocolInfo,
+							 hold ? PURPLE_MEDIA_INFO_HOLD : PURPLE_MEDIA_INFO_UNHOLD,
+							 NULL, NULL, TRUE);
+}
+
+/*!
+ * @brief Set the mute state for media.
+ *
+ * @param mute If the media's state should be mute
+ */
+- (void)media:(AIMedia *)media setMute:(BOOL)mute
+{
+	purple_media_stream_info((PurpleMedia *)media.protocolInfo,
+							 mute ? PURPLE_MEDIA_INFO_MUTE : PURPLE_MEDIA_INFO_UNMUTE,
+							 NULL, NULL, TRUE);
+}
+
+/*!
+ * @brief Set the pause state for media.
+ *
+ * @param pause If the media's state should be pause
+ */
+- (void)media:(AIMedia *)media setPause:(BOOL)pause
+{
+	purple_media_stream_info((PurpleMedia *)media.protocolInfo,
+							 pause ? PURPLE_MEDIA_INFO_PAUSE : PURPLE_MEDIA_INFO_UNPAUSE,
+							 NULL, NULL, TRUE);	
+}
+
+/*!
+ * @brief Close a media
+ *
+ * @param media The AIMedia to close
+ */
+- (void)closeMedia:(AIMedia *)media
+{
+	purple_media_stream_info((PurpleMedia *)media.protocolInfo,
+							 PURPLE_MEDIA_INFO_HANGUP,
+							 NULL, NULL, TRUE);
+}
+
 //Account Connectivity -------------------------------------------------------------------------------------------------
 #pragma mark Connect
 //Connect this account (Our password should be in the instance variable 'password' all ready for us)
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Plugins/Purple Service/ESPurpleJabberAccount.h
--- a/Plugins/Purple Service/ESPurpleJabberAccount.h	Thu Dec 10 00:55:54 2009 -0500
+++ b/Plugins/Purple Service/ESPurpleJabberAccount.h	Thu Dec 10 01:29:55 2009 -0500
@@ -32,7 +32,7 @@
 
 @class AMXMLConsoleController, AMPurpleJabberServiceDiscoveryBrowsing, AMPurpleJabberAdHocServer;
 
- at interface ESPurpleJabberAccount : CBPurpleAccount <AIAccount_Files> {
+ at interface ESPurpleJabberAccount : CBPurpleAccount <AIAccount_Files, AIAccount_Media> {
     AMXMLConsoleController *xmlConsoleController;
 	AMPurpleJabberServiceDiscoveryBrowsing *discoveryBrowserController;
 	
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Plugins/Purple Service/adiumPurpleMedia.m
--- a/Plugins/Purple Service/adiumPurpleMedia.m	Thu Dec 10 00:55:54 2009 -0500
+++ b/Plugins/Purple Service/adiumPurpleMedia.m	Thu Dec 10 01:29:55 2009 -0500
@@ -25,25 +25,6 @@
 #include <libpurple/media-gst.h>
 #include <gst/interfaces/xoverlay.h>
 
-
-
-
-#define ADIUM_TYPE_MEDIA            (adium_media_get_type())
-#define ADIUM_MEDIA(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), ADIUM_TYPE_MEDIA, AdiumMedia))
-#define ADIUM_MEDIA_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), ADIUM_TYPE_MEDIA, AdiumMediaClass))
-#define ADIUM_IS_MEDIA(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), ADIUM_TYPE_MEDIA))
-#define ADIUM_IS_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), ADIUM_TYPE_MEDIA))
-#define ADIUM_MEDIA_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), ADIUM_TYPE_MEDIA, AdiumMediaClass))
-
-typedef struct _AdiumMedia AdiumMedia;
-typedef struct _AdiumMediaClass AdiumMediaClass;
-typedef struct _AdiumMediaPrivate AdiumMediaPrivate;
-
-struct _AdiumMediaClass
-{
-	GtkWindowClass parent_class;
-};
-
 struct _AdiumMedia
 {
 	GtkWindow parent;
@@ -80,121 +61,6 @@
 	PurpleMediaSessionType request_type;
 };
 
-#define ADIUM_MEDIA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), ADIUM_TYPE_MEDIA, AdiumMediaPrivate))
-
-static void adium_media_class_init (AdiumMediaClass *klass);
-static void adium_media_init (AdiumMedia *media);
-static void adium_media_dispose (GObject *object);
-static void adium_media_finalize (GObject *object);
-static void adium_media_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
-static void adium_media_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-static void adium_media_set_state(AdiumMedia *gtkmedia, AdiumMediaState state);
-
-static GtkWindowClass *parent_class = NULL;
-
-
-#if 0
-enum {
-	LAST_SIGNAL
-};
-static guint adium_media_signals[LAST_SIGNAL] = {0};
-#endif
-
-enum {
-	PROP_0,
-	PROP_MEDIA,
-	PROP_SCREENNAME
-};
-
-static GType
-adium_media_get_type(void)
-{
-	static GType type = 0;
-
-	if (type == 0) {
-		static const GTypeInfo info = {
-			sizeof(AdiumMediaClass),
-			NULL,
-			NULL,
-			(GClassInitFunc) adium_media_class_init,
-			NULL,
-			NULL,
-			sizeof(AdiumMedia),
-			0,
-			(GInstanceInitFunc) adium_media_init,
-			NULL
-		};
-		type = g_type_register_static(GTK_TYPE_WINDOW, "AdiumMedia", &info, 0);
-	}
-	return type;
-}
-
-
-static void
-adium_media_class_init (AdiumMediaClass *klass)
-{
-	GObjectClass *gobject_class = (GObjectClass*)klass;
-/*	GtkContainerClass *container_class = (GtkContainerClass*)klass; */
-	parent_class = g_type_class_peek_parent(klass);
-
-	gobject_class->dispose = adium_media_dispose;
-	gobject_class->finalize = adium_media_finalize;
-	gobject_class->set_property = adium_media_set_property;
-	gobject_class->get_property = adium_media_get_property;
-
-	g_object_class_install_property(gobject_class, PROP_MEDIA,
-			g_param_spec_object("media",
-			"PurpleMedia",
-			"The PurpleMedia associated with this media.",
-			PURPLE_TYPE_MEDIA,
-			G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
-	g_object_class_install_property(gobject_class, PROP_SCREENNAME,
-			g_param_spec_string("screenname",
-			"Screenname",
-			"The screenname of the user this session is with.",
-			NULL,
-			G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
-
-	g_type_class_add_private(klass, sizeof(AdiumMediaPrivate));
-}
-
-static void
-adium_media_hold_toggled(GtkToggleButton *toggle, AdiumMedia *media)
-{
-	purple_media_stream_info(media->priv->media,
-			gtk_toggle_button_get_active(toggle) ?
-			PURPLE_MEDIA_INFO_HOLD : PURPLE_MEDIA_INFO_UNHOLD,
-			NULL, NULL, TRUE);
-}
-
-static void
-adium_media_mute_toggled(GtkToggleButton *toggle, AdiumMedia *media)
-{
-	purple_media_stream_info(media->priv->media,
-			gtk_toggle_button_get_active(toggle) ?
-			PURPLE_MEDIA_INFO_MUTE : PURPLE_MEDIA_INFO_UNMUTE,
-			NULL, NULL, TRUE);
-}
-
-static void
-adium_media_pause_toggled(GtkToggleButton *toggle, AdiumMedia *media)
-{
-	purple_media_stream_info(media->priv->media,
-			gtk_toggle_button_get_active(toggle) ?
-			PURPLE_MEDIA_INFO_PAUSE : PURPLE_MEDIA_INFO_UNPAUSE,
-			NULL, NULL, TRUE);
-}
-
-static gboolean
-adium_media_delete_event_cb(GtkWidget *widget,
-		GdkEvent *event, AdiumMedia *media)
-{
-	if (media->priv->media)
-		purple_media_stream_info(media->priv->media,
-				PURPLE_MEDIA_INFO_HANGUP, NULL, NULL, TRUE);
-	return FALSE;
-}
-
 #ifdef HAVE_X11
 static int
 adium_x_error_handler(Display *display, XErrorEvent *event)
@@ -877,6 +743,8 @@
 	
 	AIMedia *adiumMedia = [adium.mediaController mediaWithContact:contact onAccount:adiumAccount];
 
+	adiumMedia.protocolInfo = media;
+	
 	if (purple_media_is_initiator(media, NULL, NULL) == TRUE) {
 		[adium.mediaController showMedia:adiumMedia];
 	}
@@ -1042,5 +910,5 @@
 	purple_media_manager_set_active_element(manager, default_video_src);
 	purple_media_manager_set_active_element(manager, default_video_sink);
 	purple_media_manager_set_active_element(manager, default_audio_src);
-	purple_media_manager_set_active_element(manager, default_audio_sink)
+	purple_media_manager_set_active_element(manager, default_audio_sink);
 }
\ No newline at end of file
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Source/AIMediaController.h
--- a/Source/AIMediaController.h	Thu Dec 10 00:55:54 2009 -0500
+++ b/Source/AIMediaController.h	Thu Dec 10 01:29:55 2009 -0500
@@ -9,7 +9,7 @@
 #import <Adium/AIMediaControllerProtocol.h>
 
 @interface AIMediaController : NSObject <AIMediaController> {
-
+	NSMutableArray *openMedias;
 }
 
 @end
diff -r f599fa0d98d5 -r 5da4ba3a19c3 Source/AIMediaController.m
--- a/Source/AIMediaController.m	Thu Dec 10 00:55:54 2009 -0500
+++ b/Source/AIMediaController.m	Thu Dec 10 01:29:55 2009 -0500
@@ -8,27 +8,38 @@
 
 #import "AIMediaController.h"
 
+#import <Adium/AIMedia.h>
 
 @implementation AIMediaController
 - (void)controllerDidLoad
 {
-	
+	openMedias = [[NSMutableArray alloc] init];
 }
 
 - (void)controllerWillClose
 {
-	
+	[openMedias release]; openMedias = nil;
 }
 
 - (AIMedia *)mediaWithContact:(AIListContact *)contact
 					onAccount:(AIAccount *)account
 {
-	return nil;
+	AIMedia *media = [AIMedia mediaWithContact:contact onAccount:account];
+	
+	[openMedias addObject:media];
+	
+	return media;
 }
 
 - (AIMedia *)existingMediaWithContact:(AIListContact *)contact
 							onAccount:(AIAccount *)account
 {
+	for (AIMedia *media in openMedias) {
+		if (media.account == account && media.listContact == contact) {
+			return media;
+		}
+	}
+	
 	return nil;
 }
 
@@ -37,4 +48,9 @@
 	
 }
 
+- (void)media:(AIMedia *)media didSetState:(AIMediaState)state
+{
+	
+}
+
 @end




More information about the commits mailing list