5 // Created by Matt Meissner on 10/30/09.
6 // Copyright 2009 Matt Meissner. All rights reserved.
9 #import <Adium/AIStatus.h>
10 #import <Adium/AIHTMLDecoder.h>
12 #import "ESPurpleSIPEAccount.h"
15 #include "sipe-utils.h"
18 /* Status identifiers (see also: sipe_status_types()) */
19 #define SIPE_STATUS_ID_UNKNOWN purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) /* Unset (primitive) */
20 #define SIPE_STATUS_ID_OFFLINE purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) /* Offline (primitive) */
21 #define SIPE_STATUS_ID_AVAILABLE purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) /* Online */
22 /* PURPLE_STATUS_UNAVAILABLE: */
23 #define SIPE_STATUS_ID_BUSY "busy" /* Busy */
24 #define SIPE_STATUS_ID_DND "do-not-disturb" /* Do Not Disturb */
25 #define SIPE_STATUS_ID_ONPHONE "on-the-phone" /* On The Phone */
26 #define SIPE_STATUS_ID_INVISIBLE purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) /* Appear Offline */
27 /* PURPLE_STATUS_AWAY: */
28 #define SIPE_STATUS_ID_IDLE "idle" /* Idle/Inactive */
29 #define SIPE_STATUS_ID_BRB "be-right-back" /* Be Right Back */
30 #define SIPE_STATUS_ID_AWAY purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) /* Away (primitive) */
31 #define SIPE_STATUS_ID_LUNCH "out-to-lunch" /* Out To Lunch */
32 /* ??? PURPLE_STATUS_EXTENDED_AWAY */
33 /* ??? PURPLE_STATUS_MOBILE */
34 /* ??? PURPLE_STATUS_TUNE */
37 @implementation ESPurpleSIPEAccount
38 - (const char*)protocolPlugin
43 - (void)configurePurpleAccount
45 [super configurePurpleAccount];
47 NSLog(@"AccountName: %s\n", self.purpleAccountName ? self.purpleAccountName : "NULL");
48 NSLog(@"Account: %x\n", account);
49 NSLog(@"Port: %d\n", self.port);
50 NSLog(@"Server: %@\n", self.host);
52 purple_account_set_username(account, self.purpleAccountName);
54 if (self.host && [self.host length]) {
56 // TODO: figure out a better size for this!
58 sprintf(tmp, "%s:%d", [self.host UTF8String], self.port);
59 purple_account_set_string(account, "server", tmp);
61 // super-class already set this
65 // TODO: hook up the GUI to actually set this
66 purple_account_set_string(account, "transport", "tls");
69 - (const char *)purpleStatusIDForStatus:(AIStatus *)statusState
70 arguments:(NSMutableDictionary *)arguments
72 const char *statusID = NULL;
74 switch (statusState.statusType) {
75 case AIAvailableStatusType:
76 statusID = purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE);
78 case AIAwayStatusType:
79 statusID = purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY);
82 case AIInvisibleStatusType:
83 statusID = purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE);
86 case AIOfflineStatusType:
87 statusID = purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE);
95 #pragma mark File transfer
97 - (BOOL)canSendFolders
102 - (void)beginSendOfFileTransfer:(ESFileTransfer *)fileTransfer
104 [super _beginSendOfFileTransfer:fileTransfer];
107 - (void)acceptFileTransferRequest:(ESFileTransfer *)fileTransfer
109 [super acceptFileTransferRequest:fileTransfer];
112 - (void)rejectFileReceiveRequest:(ESFileTransfer *)fileTransfer
114 [super rejectFileReceiveRequest:fileTransfer];
117 - (void)cancelFileTransfer:(ESFileTransfer *)fileTransfer
119 [super cancelFileTransfer:fileTransfer];
122 #pragma mark Status Messages
124 - (NSString *)statusNameForPurpleBuddy:(PurpleBuddy *)buddy
126 NSString *statusName = nil;
127 PurplePresence *presence = purple_buddy_get_presence(buddy);
128 PurpleStatus *status = purple_presence_get_active_status(presence);
129 const char *purpleStatusID = purple_status_get_id(status);
131 if (!purpleStatusID) return nil;
133 if (!strcmp(purpleStatusID, jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_CHAT))) {
134 statusName = STATUS_NAME_FREE_FOR_CHAT;
136 } else if (!strcmp(purpleStatusID, jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_XA))) {
137 statusName = STATUS_NAME_EXTENDED_AWAY;
139 } else if (!strcmp(purpleStatusID, jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_DND))) {
140 statusName = STATUS_NAME_DND;
149 * @brief Status message for a contact
151 - (NSAttributedString *)statusMessageForPurpleBuddy:(PurpleBuddy *)buddy
153 PurplePresence *presence = purple_buddy_get_presence(buddy);
154 PurpleStatus *status = (presence ? purple_presence_get_active_status(presence) : NULL);
155 const char *message = (status ? purple_status_get_attr_string(status, "message") : NULL);
156 char *sipemessage = NULL;
157 NSString *statusMessage = nil;
158 struct sipe_account_data *sip;
159 struct sipe_buddy *sbuddy;
163 sip = (struct sipe_account_data *) buddy->account->gc->proto_data;
164 if (sip) //happens on pidgin exit
166 GList *keys = g_hash_table_get_keys(sip->buddies);
167 sbuddy = g_hash_table_lookup(sip->buddies, buddy->name);
169 if (!is_empty(sbuddy->activity) && !is_empty(sbuddy->annotation))
171 sipemessage = g_strdup_printf("%s. %s", sbuddy->activity, sbuddy->annotation);
173 else if (!is_empty(sbuddy->activity))
175 sipemessage = g_strdup(sbuddy->activity);
177 else if (!is_empty(sbuddy->annotation))
179 sipemessage = g_strdup(sbuddy->annotation);
185 // Get the plugin's status message for this buddy if they don't have a status message
186 if (!message && !sipemessage) {
187 PurplePluginProtocolInfo *prpl_info = self.protocolInfo;
189 if (prpl_info && prpl_info->status_text) {
190 char *status_text = (prpl_info->status_text)(buddy);
192 // Don't display "Offline" as a status message.
193 if (status_text && strcmp(status_text, _("Offline")) != 0) {
194 statusMessage = [NSString stringWithUTF8String:status_text];
199 } else if (sipemessage) {
200 statusMessage = [NSString stringWithUTF8String:sipemessage];
203 statusMessage = [NSString stringWithUTF8String:message];
206 return statusMessage ? [AIHTMLDecoder decodeHTML:statusMessage] : nil;