Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PurpleSkypeAccount.m - github.com/EionRobb/skype4pidgin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 63738557fe90115f4adf67820d52b59def42e695 (plain)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//
//  PurpleSkypeAccount.m
//  Adium
//
//  Created by Eion Robb on 2007-10-14.
//

#import "PurpleSkypeAccount.h"
#import <Adium/AIHTMLDecoder.h>
#import <Adium/AIStatusControllerProtocol.h>
#import <Adium/AIContentMessage.h>
#import <Adium/AIContentControllerProtocol.h>
#import <AdiumLibpurple/SLPurpleCocoaAdapter.h>
#import <Adium/AISharedAdium.h>

char *skype_status_text(PurpleBuddy *buddy);
const char *skype_get_account_username(PurpleAccount *acct);

@implementation PurpleSkypeAccount

static SLPurpleCocoaAdapter *purpleThread = nil;

- (SLPurpleCocoaAdapter *)purpleThread
{
	//initialise libpurple in a safe way
	if (!purpleThread) {
		purpleThread = [[SLPurpleCocoaAdapter sharedInstance] retain];	
	}	
	return purpleThread;
}

- (const char*)protocolPlugin
{
#ifdef SKYPENET
	return "prpl-bigbrownchunx-skypenet";
#else
    return "prpl-bigbrownchunx-skype";
#endif
}

- (BOOL)disconnectOnFastUserSwitch
{
	return YES;
}

- (NSAttributedString *)statusMessageForPurpleBuddy:(PurpleBuddy *)buddy
{
	char *msg = (char *)skype_status_text(buddy);
	if (msg != NULL)
	{
		return [[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:msg]];
	}
	else
		return nil;
}

- (NSString *)statusNameForPurpleBuddy:(PurpleBuddy *)buddy
{
	//printf("statusNameForPurpleBuddy cb\n");
	if (!buddy)
		return nil;
	PurplePresence *presence = purple_buddy_get_presence(buddy);
	if (!presence)
		return nil;
	PurpleStatus *status = purple_presence_get_active_status(presence);
	if (!status)
		return nil;
		
	const gchar *status_id = purple_status_get_id(status);
	//printf("Buddy %s has status_id %s\n", buddy->name, status_id);
	if(g_str_equal(status_id, "ONLINE"))
		return STATUS_NAME_AVAILABLE;
	if(g_str_equal(status_id, "SKYPEME"))
		return STATUS_NAME_FREE_FOR_CHAT;
	if(g_str_equal(status_id, "AWAY"))
		return STATUS_NAME_AWAY;
	if(g_str_equal(status_id, "NA"))
		return STATUS_NAME_NOT_AVAILABLE;
	if(g_str_equal(status_id, "DND"))
		return STATUS_NAME_DND;
	if(g_str_equal(status_id, "INVISIBLE"))
		return STATUS_NAME_INVISIBLE;
	if(g_str_equal(status_id, "OFFLINE"))
		return STATUS_NAME_OFFLINE;
		
	BOOL show_skypeout_online = [[self preferenceForKey:KEY_SKYPE_SHOW_SKYPEOUT group:GROUP_ACCOUNT_STATUS] boolValue];
	//not sure what to do with SkypeOut people?
	if(g_str_equal(status_id, "SKYPEOUT"))
	{
		if (show_skypeout_online)
			return STATUS_NAME_AVAILABLE;
		else
			return STATUS_NAME_OFFLINE;
	}
	
	return STATUS_NAME_OFFLINE;
}

- (const char *)purpleStatusIDForStatus:(AIStatus *)statusState
							  arguments:(NSMutableDictionary *)arguments
{	
	if ([[statusState statusName] isEqualToString:STATUS_NAME_AVAILABLE])
		return "ONLINE";
	else if ([[statusState statusName] isEqualToString:STATUS_NAME_FREE_FOR_CHAT])
		return "SKYPEME";
	else if ([[statusState statusName] isEqualToString:STATUS_NAME_AWAY])
		return "AWAY";
	else if ([[statusState statusName] isEqualToString:STATUS_NAME_EXTENDED_AWAY])
		return "NA";
	else if ([[statusState statusName] isEqualToString:STATUS_NAME_DND])
		return "DND";
	else if ([[statusState statusName] isEqualToString:STATUS_NAME_INVISIBLE])
		return "INVISIBLE";
	else
		return "OFFLINE";
}

- (BOOL)connectivityBasedOnNetworkReachability
{
	return NO;
}

- (NSString *)connectionStringForStep:(NSInteger)step
{
	switch (step) {
		case 0:
			return @"Authorizing";
			break;
		case 1:
			return @"Initializing";
			break;
		case 2:
			return @"Silencing Skype";
			break;			
		case 3:
			return @"Connected";
			break;
	}

	return nil;
}
	
- (NSString *)encodedAttributedString:(NSAttributedString *)inAttributedString forListObject:(AIListObject *)inListObject
{
	/*if ([AIHTMLDecoder respondsToSelector:@selector(encodeHTML:headers:fontTags:includingColorTags:closeFontTags:styleTags:
													closeStyleTagsOnFontChange:encodeNonASCII:encodeSpaces:imagesPath:
													attachmentsAsText:onlyIncludeOutgoingImages:simpleTagsOnly:bodyBackground:
													allowJavascriptURLs:)])
	{*/
		NSString *temp = [AIHTMLDecoder encodeHTML:inAttributedString
							 headers:YES
							fontTags:NO
				  includingColorTags:NO
					   closeFontTags:NO
						   styleTags:NO
		  closeStyleTagsOnFontChange:NO
					  encodeNonASCII:NO
						encodeSpaces:NO
						  imagesPath:nil
				   attachmentsAsText:YES
		   onlyIncludeOutgoingImages:NO
					  simpleTagsOnly:YES
					  bodyBackground:NO
				 allowJavascriptURLs:NO];
		//printf("First encoder: %s\n", [temp cString]);
		return temp;
	/*} else {
		NSString *temp = [AIHTMLDecoder encodeHTML:inAttributedString
							 headers:YES
							fontTags:NO
				  includingColorTags:NO
					   closeFontTags:NO
						   styleTags:NO
		  closeStyleTagsOnFontChange:NO
					  encodeNonASCII:NO
						encodeSpaces:NO
						  imagesPath:nil
				   attachmentsAsText:YES
		   onlyIncludeOutgoingImages:NO
					  simpleTagsOnly:YES
					  bodyBackground:NO];
		printf("Second encoder: %s\n", [temp cString]);
		return temp;
	}*/
	/*return [AIHTMLDecoder encodeHTML:inAttributedString
					encodeFullString:YES];*/
}

/*
- (AIReconnectDelayType)shouldAttemptReconnectAfterDisconnectionError:(NSString **)disconnectionError
{
	//AIReconnectDelayType shouldAttemptReconnect = [super shouldAttemptReconnectAfterDisconnectionError:disconnectionError];

	if (disconnectionError && *disconnectionError) {
		if ([*disconnectionError rangeOfString:@"The password provided is incorrect"].location != NSNotFound) {
			[self setLastDisconnectionError:AILocalizedString(@"Incorrect username or password","Error message displayed when the server reports username or password as being incorrect.")];
			[self serverReportedInvalidPassword];
			shouldAttemptReconnect = AIReconnectImmediately;
		}
	}
	return AIReconnectNever;
	//return shouldAttemptReconnect;
}*/

- (void)autoReconnectAfterDelay:(NSTimeInterval)delay
{
	[super autoReconnectAfterDelay:5];
}

- (void)receivedIMChatMessage:(NSDictionary *)messageDict inChat:(AIChat *)chat
{
	PurpleMessageFlags flags = [[messageDict objectForKey:@"PurpleMessageFlags"] intValue];	
	//if its not a _SEND message let parent method deal with it
	if ((flags & PURPLE_MESSAGE_SEND) == 0) {
		return [super receivedIMChatMessage:messageDict
									 inChat:chat];
	}
	
	//otherwise, add this message from ourselves to the right IM window
	NSAttributedString *attributedMessage = [[adium contentController] decodedIncomingMessage:[messageDict objectForKey:@"Message"]
																				  fromContact:nil
																					onAccount:self];
	AIContentMessage *messageObject = [AIContentMessage messageInChat:chat
														   withSource:self
														  destination:self
																 date:[messageDict objectForKey:@"Date"]
															  message:attributedMessage
															autoreply:(flags & PURPLE_MESSAGE_AUTO_RESP) != 0];
	
	[[adium contentController] displayContentObject:messageObject
														 usingContentFilters:YES
																 immediately:NO];
}


- (BOOL)canSendOfflineMessageToContact:(AIListContact *)inContact
{
	//shortcut parent method
	return YES;
}

/*#ifndef SKYPENET
- (const char *)purpleAccountName
{
    printf("puprleAccountName\n");
	//override parent method to grab the actual account UID from skype
	const char *uid = (const char *)skype_get_account_username(NULL);
	if (!uid || !strlen(uid))
	{
		return "Skype";
	}
	return uid;
}

- (NSString *)formattedUID
{
	const char *uid = (const char *)skype_get_account_username(NULL);
    printf("formattedUID %s %x\n", uid, (guint)account);
	if (!uid || !strlen(uid))
	{
		return @"Skype";
	}
	//override parent method to grab the actual account UID from skype
	return [[NSString alloc] initWithUTF8String:uid];
}

- (NSString *)explicitFormattedUID
{
    printf("explicitFormattedUID %x\n", (guint)account);
    return [self formattedUID];
}
#endif*/

- (BOOL)shouldSetAliasesServerside
{
	return YES;
}

-(void)configurePurpleAccount{
	[super configurePurpleAccount];
	
	PurpleAccount *acct = [self purpleAccount];
	
	//purple_account_set_bool(account, "skypeout_online", TRUE);
	//purple_account_set_bool(account, "skype_sync", TRUE);
	//purple_account_set_bool(account, "check_for_updates", FALSE);
	//purple_account_set_bool(account, "skype_autostart", TRUE);
	//return;
	
	//Use this section of code once the account options page is set up
	BOOL skypeout_online = [[self preferenceForKey:KEY_SKYPE_SHOW_SKYPEOUT group:GROUP_ACCOUNT_STATUS] boolValue];
	purple_account_set_bool(acct, "skypeout_online", skypeout_online);
	
	BOOL skype_sync = [[self preferenceForKey:KEY_SKYPE_SYNC_OFFLINE group:GROUP_ACCOUNT_STATUS] boolValue];
	purple_account_set_bool(acct, "skype_sync", skype_sync);
	
	BOOL check_for_updates = [[self preferenceForKey:KEY_SKYPE_CHECK_FOR_UPDATES group:GROUP_ACCOUNT_STATUS] boolValue];
	purple_account_set_bool(acct, "check_for_updates", check_for_updates);
	
	BOOL skype_autostart = [[self preferenceForKey:KEY_SKYPE_AUTOSTART group:GROUP_ACCOUNT_STATUS] boolValue];
	purple_account_set_bool(acct, "skype_autostart", skype_autostart);
}

-(NSDictionary *) extractChatCreationDictionaryFromConversation:(PurpleConversation *)conv
{
	
	NSMutableDictionary *dict = [NSMutableDictionary dictionary];
	[dict setObject:[NSString stringWithUTF8String:purple_conversation_get_name(conv)] forKey:@"chat_id"];
	const char *pass = purple_conversation_get_data(conv, "password");
	if (pass)
		[dict setObject: [NSString stringWithUTF8String:pass] forKey:@"password"];
	return dict;
}

- (BOOL)groupChatsSupportTopic
{
	return YES;
}

@end