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"
14 #include "sipe-core.h"
17 #define SIPE_STATUS_ID_UNKNOWN purple_primitive_get_id_from_type(PURPLE_STATUS_UNSET) /* Unset (primitive) */
18 #define SIPE_STATUS_ID_OFFLINE purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE) /* Offline (primitive) */
19 #define SIPE_STATUS_ID_AVAILABLE purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE) /* Online */
20 /* PURPLE_STATUS_UNAVAILABLE: */
21 #define SIPE_STATUS_ID_BUSY "busy" /* Busy */
22 #define SIPE_STATUS_ID_BUSYIDLE "busyidle" /* BusyIdle */
23 #define SIPE_STATUS_ID_DND "do-not-disturb" /* Do Not Disturb */
24 #define SIPE_STATUS_ID_IN_MEETING "in-a-meeting" /* In a meeting */
25 #define SIPE_STATUS_ID_IN_CONF "in-a-conference" /* In a conference */
26 #define SIPE_STATUS_ID_ON_PHONE "on-the-phone" /* On the phone */
27 #define SIPE_STATUS_ID_INVISIBLE purple_primitive_get_id_from_type(PURPLE_STATUS_INVISIBLE) /* Appear Offline */
28 /* PURPLE_STATUS_AWAY: */
29 #define SIPE_STATUS_ID_IDLE "idle" /* Idle/Inactive */
30 #define SIPE_STATUS_ID_BRB "be-right-back" /* Be Right Back */
31 #define SIPE_STATUS_ID_AWAY purple_primitive_get_id_from_type(PURPLE_STATUS_AWAY) /* Away (primitive) */
32 /** Reuters status (user settable) */
33 #define SIPE_STATUS_ID_LUNCH "out-to-lunch" /* Out To Lunch */
34 /* ??? PURPLE_STATUS_EXTENDED_AWAY */
35 /* ??? PURPLE_STATUS_MOBILE */
36 /* ??? PURPLE_STATUS_TUNE */
39 @implementation ESPurpleSIPEAccount
40 - (const char*)protocolPlugin
46 - (void)configurePurpleAccount
48 NSLog(@"Configure account: %x\n", account);
50 [super configurePurpleAccount];
52 if (self.host && [self.host length]) {
54 // TODO: figure out a better size for this!
56 sprintf(tmp, "%s:%d", [self.host UTF8String], self.port);
57 purple_account_set_string(account, "server", tmp);
59 // super-class already set this
63 NSString *email = [self preferenceForKey:KEY_SIPE_EMAIL group:GROUP_ACCOUNT_STATUS];
64 NSString *emailURL = [self preferenceForKey:KEY_SIPE_EMAIL_URL group:GROUP_ACCOUNT_STATUS];
65 NSString *emailPass = [self preferenceForKey:KEY_SIPE_EMAIL_PASSWORD group:GROUP_ACCOUNT_STATUS];
66 if (email && [email length])
67 purple_account_set_string(account, "email", [email UTF8String]);
68 if (emailURL && [emailURL length])
69 purple_account_set_string(account, "email_url", [emailURL UTF8String]);
70 if (emailPass && [emailPass length])
71 purple_account_set_string(account, "email_password", [emailPass UTF8String]);
73 int ctype = [[self preferenceForKey:KEY_SIPE_CONNECTION_TYPE group:GROUP_ACCOUNT_STATUS] intValue];
77 case 0: ctypes = "auto"; break;
78 case 1: ctypes = "tcp"; break;
79 case 2: ctypes = "tls"; break;
81 purple_account_set_string(account, "transport", ctypes);
83 NSString *chatProxy = [self preferenceForKey:KEY_SIPE_GROUP_CHAT_PROXY group:GROUP_ACCOUNT_STATUS];
84 NSString *userAgent = [self preferenceForKey:KEY_SIPE_USER_AGENT group:GROUP_ACCOUNT_STATUS];
85 if (chatProxy && [chatProxy length])
86 purple_account_set_string(account, "groupchat_user", [chatProxy UTF8String]);
87 if (userAgent && [userAgent length])
88 purple_account_set_string(account, "useragent", [userAgent UTF8String]);
91 NSString *winLogin = [self preferenceForKey:KEY_SIPE_WINDOWS_LOGIN group:GROUP_ACCOUNT_STATUS];
93 NSString *completeUserName = [NSString stringWithUTF8String:[self purpleAccountName]];
95 if (winLogin && [winLogin length])
96 completeUserName = [NSString stringWithFormat:@"%@,%@",completeUserName, winLogin];
98 purple_account_set_username(account, [completeUserName UTF8String]);
100 const char *username = purple_account_get_username(account);
102 NSLog(@"AccountName: %s\n", username ? username : "NULL");
108 - (const char *)purpleStatusIDForStatus:(AIStatus *)statusState
109 arguments:(NSMutableDictionary *)arguments
111 const char *statusID = NULL;
113 switch (statusState.statusType) {
114 case AIAvailableStatusType:
115 statusID = SIPE_STATUS_ID_AVAILABLE;
117 case AIAwayStatusType:
118 statusID = SIPE_STATUS_ID_AWAY;
121 case AIInvisibleStatusType:
122 statusID = SIPE_STATUS_ID_INVISIBLE;
125 case AIOfflineStatusType:
126 statusID = SIPE_STATUS_ID_OFFLINE;
129 //If we didn't get a purple status type, request one from super
130 if (statusID == NULL) statusID = [super purpleStatusIDForStatus:statusState arguments:arguments];
137 #pragma mark File transfer
139 - (BOOL)canSendFolders
144 - (void)beginSendOfFileTransfer:(ESFileTransfer *)fileTransfer
146 [super _beginSendOfFileTransfer:fileTransfer];
149 - (void)acceptFileTransferRequest:(ESFileTransfer *)fileTransfer
151 [super acceptFileTransferRequest:fileTransfer];
154 - (void)rejectFileReceiveRequest:(ESFileTransfer *)fileTransfer
156 [super rejectFileReceiveRequest:fileTransfer];
159 - (void)cancelFileTransfer:(ESFileTransfer *)fileTransfer
161 [super cancelFileTransfer:fileTransfer];
164 #pragma mark Status Messages
166 - (NSString *)statusNameForPurpleBuddy:(PurpleBuddy *)buddy
168 NSString *statusName = nil;
169 PurplePresence *presence = purple_buddy_get_presence(buddy);
170 PurpleStatus *status = purple_presence_get_active_status(presence);
171 const char *purpleStatusID = purple_status_get_id(status);
173 if (!purpleStatusID) return nil;
175 if (!strcmp(purpleStatusID, jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_CHAT))) {
176 statusName = STATUS_NAME_FREE_FOR_CHAT;
178 } else if (!strcmp(purpleStatusID, jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_XA))) {
179 statusName = STATUS_NAME_EXTENDED_AWAY;
181 } else if (!strcmp(purpleStatusID, jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_DND))) {
182 statusName = STATUS_NAME_DND;
191 * @brief Status message for a contact
193 - (NSAttributedString *)statusMessageForPurpleBuddy:(PurpleBuddy *)buddy
195 PurplePresence *presence = purple_buddy_get_presence(buddy);
196 PurpleStatus *status = (presence ? purple_presence_get_active_status(presence) : NULL);
197 const char *message = (status ? purple_status_get_attr_string(status, "message") : NULL);
198 char *sipemessage = NULL;
199 NSString *statusMessage = nil;
201 // TODO: get sipe activity or annotation
203 // Get the plugin's status message for this buddy if they don't have a status message
204 if (!message && !sipemessage) {
205 PurplePluginProtocolInfo *prpl_info = self.protocolInfo;
207 if (prpl_info && prpl_info->status_text) {
208 char *status_text = (prpl_info->status_text)(buddy);
210 // Don't display "Offline" as a status message.
211 if (status_text && strcmp(status_text, _("Offline")) != 0) {
212 statusMessage = [NSString stringWithUTF8String:status_text];
217 } else if (sipemessage) {
218 statusMessage = [NSString stringWithUTF8String:sipemessage];
221 statusMessage = [NSString stringWithUTF8String:message];
224 return statusMessage ? [AIHTMLDecoder decodeHTML:statusMessage] : nil;