William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againadium / Plugins / Purple Service / ESPurpleMeanwhileAccount.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "ESPurpleMeanwhileAccount.h"
#import <Adium/AIAccountControllerProtocol.h>
#import <Adium/AIStatusControllerProtocol.h>
#import <Adium/AIListContact.h>
#import <Adium/AIStatus.h>
#import <Adium/ESFileTransfer.h>
extern const char *mwServiceAware_getText(void *, void *);
@implementation ESPurpleMeanwhileAccount
#ifndef MEANWHILE_NOT_AVAILABLE
#define MW_KEY_FORCE "force_login"
#define MW_KEY_FAKE_IT "fake_client_id"
#define MW_KEY_CLIENT "client_id_val"
#define MW_KEY_MAJOR "client_major"
#define MW_KEY_MINOR "client_minor"
- (const char*)protocolPlugin
{
return "prpl-meanwhile";
}
- (void)configurePurpleAccount
{
[super configurePurpleAccount];
purple_prefs_set_int(MW_PRPL_OPT_BLIST_ACTION, Meanwhile_CL_Load_And_Save);
purple_account_set_bool(account, MW_KEY_FORCE, [[self preferenceForKey:KEY_MEANWHILE_FORCE_LOGIN
group:GROUP_ACCOUNT_STATUS] boolValue]);
BOOL fakeIt = [[self preferenceForKey:KEY_MEANWHILE_FAKE_CLIENT_ID
group:GROUP_ACCOUNT_STATUS] boolValue];
purple_account_set_bool(account, MW_KEY_FAKE_IT, fakeIt);
if (fakeIt) {
NSInteger client;
if ((client = [[NSUserDefaults standardUserDefaults] integerForKey:@"AISametimeClient"]))
purple_account_set_int(account, MW_KEY_CLIENT, client);
NSInteger majorVersion;
if (!(majorVersion = [[NSUserDefaults standardUserDefaults] integerForKey:@"AISametimeMajorVersion"]))
majorVersion = 0x001e;
NSInteger minorVersion;
if (!(minorVersion = [[NSUserDefaults standardUserDefaults] integerForKey:@"AISametimeMinorVersion"]))
minorVersion = 0x196f;
purple_account_set_int(account, MW_KEY_MAJOR, majorVersion);
purple_account_set_int(account, MW_KEY_MINOR, minorVersion);
}
}
#pragma mark Status Messages
- (NSAttributedString *)statusMessageForPurpleBuddy:(PurpleBuddy *)b
{
NSString *statusMessageString;
NSAttributedString *statusMessage = nil;
const char *statusMessageText;
PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(b));
struct mwPurplePluginData *pd = ((struct mwPurplePluginData *)(gc->proto_data));
struct mwAwareIdBlock t = { mwAware_USER, (char *)purple_buddy_get_name(b), NULL };
statusMessageText = (const char *)mwServiceAware_getText(pd->srvc_aware, &t);
statusMessageString = (statusMessageText ? [NSString stringWithUTF8String:statusMessageText] : nil);
if (statusMessageString && [statusMessageString length]) {
statusMessage = [[[NSAttributedString alloc] initWithString:statusMessageString
attributes:nil] autorelease];
}
return statusMessage;
}
#pragma mark Status
- (NSString *)connectionStringForStep:(NSInteger)step
{
switch (step)
{
case 1:
return AILocalizedString(@"Connecting",nil);
break;
case 2:
return AILocalizedString(@"Sending Handshake",nil);
break;
case 3:
return AILocalizedString(@"Waiting for Handshake Acknowledgement",nil);
break;
case 4:
return AILocalizedString(@"Handshake Acknowledged; Sending Login",nil);
break;
case 5:
return AILocalizedString(@"Waiting for Login Acknowledgement",nil);
break;
case 6:
return AILocalizedString(@"Login Redirected",nil);
break;
case 7:
return AILocalizedString(@"Forcing Login",nil);
break;
case 8:
return AILocalizedString(@"Login Acknowledged",nil);
break;
case 9:
return AILocalizedString(@"Starting Services",nil);
break;
case 10:
return AILocalizedString(@"Connected",nil);
break;
}
return nil;
}
/*!
* @brief Return the purple status ID to be used for a status
*
* Most subclasses should override this method; these generic values may be appropriate for others.
*
* Active services provided nonlocalized status names. An AIStatus is passed to this method along with a pointer
* to the status message. This method should handle any status whose statusNname this service set as well as any statusName
* defined in AIStatusController.h (which will correspond to the services handled by Adium by default).
* It should also handle a status name not specified in either of these places with a sane default, most likely by loooking at
* statusState.statusType for a general idea of the status's type.
*
* @param statusState The status for which to find the purple status ID
* @param arguments Prpl-specific arguments which will be passed with the state. Message is handled automatically.
*
* @result The purple status ID
*/
- (const char *)purpleStatusIDForStatus:(AIStatus *)statusState
arguments:(NSMutableDictionary *)arguments
{
const char *statusID = NULL;
NSString *statusName = statusState.statusName;
NSString *statusMessageString = [statusState statusMessageString];
if (!statusMessageString) statusMessageString = @"";
switch (statusState.statusType) {
case AIAvailableStatusType:
statusID = "active";
break;
case AIAwayStatusType:
case AIInvisibleStatusType: //Meanwhile does not support invisibility
{
if (([statusName isEqualToString:STATUS_NAME_DND]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_DND]] == NSOrderedSame))
statusID = "dnd";
else
statusID = "away";
break;
}
case AIOfflineStatusType:
break;
}
//If we didn't get a purple status ID, request one from super
if (statusID == NULL) statusID = [super purpleStatusIDForStatus:statusState arguments:arguments];
return statusID;
}
#pragma mark Account Action Menu Items
- (NSString *)titleForAccountActionMenuLabel:(const char *)label
{
if (strcmp(label, "Import Sametime List...") == 0) {
return AILocalizedString(@"Import Sametime List...",nil);
} else if (strcmp(label, "Export Sametime List...") == 0) {
return AILocalizedString(@"Export Sametime List...",nil);
}
return [super titleForAccountActionMenuLabel:label];
}
#pragma mark File transfer
- (BOOL)canSendFolders
{
return NO;
}
- (void)beginSendOfFileTransfer:(ESFileTransfer *)fileTransfer
{
[super _beginSendOfFileTransfer:fileTransfer];
}
- (void)acceptFileTransferRequest:(ESFileTransfer *)fileTransfer
{
[super acceptFileTransferRequest:fileTransfer];
}
- (void)rejectFileReceiveRequest:(ESFileTransfer *)fileTransfer
{
[super rejectFileReceiveRequest:fileTransfer];
}
- (void)cancelFileTransfer:(ESFileTransfer *)fileTransfer
{
[super cancelFileTransfer:fileTransfer];
}
#endif /* #ifndef MEANWHILE_NOT_AVAILABLE */
@end
|