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 / adiumPurpleNotify.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 | /*
* 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 "ESPurpleNotifyEmailController.h"
#import "adiumPurpleNotify.h"
#import <AdiumLibpurple/SLPurpleCocoaAdapter.h>
#import <AIUtilities/AIObjectAdditions.h>
#import "AMPurpleSearchResultsController.h"
static void *adiumPurpleNotifyMessage(PurpleNotifyMsgType type, const char *title, const char *primary, const char *secondary)
{
AILog(@"adiumPurpleNotifyMessage: type: %i\n%s\n%s\n%s ",
type,
(title ? title : ""),
(primary ? primary : ""),
(secondary ? secondary : ""));
return ([[SLPurpleCocoaAdapter sharedInstance] handleNotifyMessageOfType:type
withTitle:title
primary:primary
secondary:secondary]);
}
static void *adiumPurpleNotifyEmails(PurpleConnection *gc, size_t count, gboolean detailed, const char **subjects, const char **froms, const char **tos, const char **urls)
{
// Don't notify that 0 emails are present.
if (!count)
return NULL;
//Values passed can be null
AIAccount *account = (PURPLE_CONNECTION_IS_VALID(gc) ?
accountLookup(purple_connection_get_account(gc)) :
nil);
return [ESPurpleNotifyEmailController handleNotifyEmailsForAccount:account
count:count
detailed:detailed
subjects:subjects
froms:froms
tos:tos
urls:urls];
}
static void *adiumPurpleNotifyEmail(PurpleConnection *gc, const char *subject, const char *from, const char *to, const char *url)
{
return adiumPurpleNotifyEmails(gc,
1,
TRUE,
(subject ? &subject : NULL),
(from ? &from : NULL),
(to ? &to : NULL),
(url ? &url : NULL));
}
static void *adiumPurpleNotifyFormatted(const char *title, const char *primary, const char *secondary, const char *text)
{
AILog(@"adiumPurpleNotifyFormatted: %s\n%s\n%s\n%s ",
(title ? title : ""),
(primary ? primary : ""),
(secondary ? secondary : ""),
(text ? text : ""));
return ([[SLPurpleCocoaAdapter sharedInstance] handleNotifyFormattedWithTitle:title
primary:primary
secondary:secondary
text:text]);
}
static void *adiumPurpleNotifySearchResults(PurpleConnection *gc, const char *title,
const char *primary, const char *secondary,
PurpleNotifySearchResults *results, gpointer user_data)
{
AILog(@"**** returning search results");
//This will be released in adiumPurpleNotifyClose()
return [[AMPurpleSearchResultsController alloc] initWithPurpleConnection:gc
title:(title ? [NSString stringWithUTF8String:title] : nil)
primaryText:(primary ? [NSString stringWithUTF8String:primary] : nil)
secondaryText:(secondary ? [NSString stringWithUTF8String:secondary] : nil)
searchResults:results
userData:user_data];
}
static void adiumPurpleNotifySearchResultsNewRows(PurpleConnection *gc,
PurpleNotifySearchResults *results,
void *data)
{
if([(id)data isKindOfClass:[AMPurpleSearchResultsController class]]) {
[(AMPurpleSearchResultsController*)data addResults:results];
}
}
static void *adiumPurpleNotifyUserinfo(PurpleConnection *gc, const char *who,
PurpleNotifyUserInfo *user_info)
{
if (PURPLE_CONNECTION_IS_VALID(gc)) {
PurpleAccount *account = purple_connection_get_account(gc);
PurpleBuddy *buddy = purple_find_buddy(account, who);
CBPurpleAccount *adiumAccount = accountLookup(account);
AIListContact *contact;
contact = contactLookupFromBuddy(buddy);
if (!contact) {
NSString *UID = [NSString stringWithUTF8String:purple_normalize(account, who)];
contact = [accountLookup(account) contactWithUID:UID];
}
[adiumAccount updateUserInfo:contact
withData:user_info];
}
return NULL;
}
static void *adiumPurpleNotifyUri(const char *uri)
{
AILogWithSignature(@"Opening URI %s",uri);
if (uri) {
NSString *passedURI = [NSString stringWithUTF8String:uri];
if ([passedURI hasPrefix:[NSString stringWithUTF8String:g_get_tmp_dir()]] ||
[passedURI hasPrefix:NSTemporaryDirectory()]) {
NSString *actualURI = passedURI;
if (![[passedURI pathExtension] length]) {
actualURI = [passedURI stringByAppendingPathExtension:@"htm"];
[[NSFileManager defaultManager] copyItemAtPath:passedURI
toPath:actualURI
error:NULL];
}
FSRef appRef;
//Open the HTML file with a web browser, not with an HTML editor
if (LSGetApplicationForURL((CFURLRef)[NSURL URLWithString:@"http://google.com"],
kLSRolesViewer,
&appRef,
NULL) != kLSApplicationNotFoundErr) {
FSRef urlRef;
if (FSPathMakeRef((UInt8 *)[actualURI fileSystemRepresentation], &urlRef, NULL) == noErr) {
LSLaunchFSRefSpec spec;
spec.appRef = &appRef;
spec.numDocs = 1;
spec.itemRefs = &urlRef;
spec.passThruParams = NULL;
spec.launchFlags = kLSLaunchDontAddToRecents | kLSLaunchAsync;
spec.asyncRefCon = NULL;
LSOpenFromRefSpec(&spec, NULL);
}
}
} else {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:passedURI]];
}
}
return NULL;
}
static void adiumPurpleNotifyClose(PurpleNotifyType type,void *uiHandle)
{
id ourHandle = uiHandle;
AILogWithSignature(@"Closing %p (%i)",ourHandle,type);
if ([ourHandle respondsToSelector:@selector(purpleRequestClose)]) {
[ourHandle performSelector:@selector(purpleRequestClose)];
[ourHandle release];
} else if ([ourHandle respondsToSelector:@selector(closeWindow:)]) {
[ourHandle performSelector:@selector(closeWindow:)
withObject:nil];
}
}
static PurpleNotifyUiOps adiumPurpleNotifyOps = {
adiumPurpleNotifyMessage,
adiumPurpleNotifyEmail,
adiumPurpleNotifyEmails,
adiumPurpleNotifyFormatted,
adiumPurpleNotifySearchResults,
adiumPurpleNotifySearchResultsNewRows,
adiumPurpleNotifyUserinfo,
adiumPurpleNotifyUri,
adiumPurpleNotifyClose
};
PurpleNotifyUiOps *adium_purple_notify_get_ui_ops(void)
{
return &adiumPurpleNotifyOps;
}
|