adium/adium
Clone
Summary
Browse
Changes
Graph
Removed some 10.7-- checks. Moved to 10.7.5.
2013-02-21, Adrian Godoroja
94b3acee0622
Removed some 10.7-- checks. Moved to 10.7.5.
/*
* 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 "AIIRCConsoleController.h"
#import <libpurple/irc.h>
@interface
AIIRCConsoleController
()
-
(
PurpleConnection
*
)
gc
;
@end
;
static
void
text_received_cb
(
PurpleConnection
*
gc
,
char
**
text
,
gpointer
this
)
{
AIIRCConsoleController
*
self
=
(
__bridge
AIIRCConsoleController
*
)
this
;
char
*
salvagedString
=
purple_utf8_salvage
(
*
text
);
if
(
!
this
||
[
self
gc
]
!=
gc
)
return
;
NSString
*
sstr
=
[[
NSString
stringWithUTF8String
:
salvagedString
]
stringByAppendingString
:
@"
\n
"
];
g_free
(
salvagedString
);
if
(
!
sstr
)
{
AILogWithSignature
(
@"Received a not valid utf8 string?"
);
return
;
}
NSAttributedString
*
astr
=
[[
NSAttributedString
alloc
]
initWithString
:
sstr
attributes
:[
NSDictionary
dictionaryWithObjectsAndKeys
:
[
NSFont
fontWithName
:
@"Courier"
size
:
12
],
NSFontAttributeName
,
nil
]];
[
self
appendToLog
:
astr
];
}
static
void
text_sent_cb
(
PurpleConnection
*
gc
,
char
**
text
,
gpointer
this
)
{
AIIRCConsoleController
*
self
=
(
__bridge
AIIRCConsoleController
*
)
this
;
char
*
salvagedString
=
purple_utf8_salvage
(
*
text
);
if
(
!
this
||
[
self
gc
]
!=
gc
)
return
;
NSString
*
sstr
=
[
NSString
stringWithUTF8String
:
salvagedString
];
g_free
(
salvagedString
);
if
(
!
sstr
)
{
AILogWithSignature
(
@"Sent a not valid utf8 string?"
);
return
;
}
NSAttributedString
*
astr
=
[[
NSAttributedString
alloc
]
initWithString
:
sstr
attributes
:[
NSDictionary
dictionaryWithObjectsAndKeys
:
[
NSColor
blueColor
],
NSForegroundColorAttributeName
,
[
NSFont
fontWithName
:
@"Courier"
size
:
12
],
NSFontAttributeName
,
nil
]];
[
self
appendToLog
:
astr
];
}
@implementation
AIIRCConsoleController
-
(
void
)
dealloc
{
purple_signals_disconnect_by_handle
((
__bridge
void
*
)(
self
));
}
-
(
IBAction
)
send:
(
id
)
sender
{
NSString
*
rawData
=
[
injectView
string
];
NSAssert
(
INT_MAX
>=
[
rawData
length
],
@"Sending more irc data value than libpurple can handle. Abort."
);
const
char
*
quote
=
[
rawData
UTF8String
];
irc_cmd_quote
([
self
gc
]
->
proto_data
,
NULL
,
NULL
,
&
quote
);
// remove from text field
[
super
send
:
sender
];
}
-
(
IBAction
)
showWindow:
(
id
)
sender
{
if
(
!
consoleWindow
)
{
[
super
showWindow
:
sender
];
//Connect to the signals for updating the window
PurplePlugin
*
irc
=
purple_find_prpl
(
"prpl-irc"
);
if
(
!
irc
)
AILog
(
@"Unable to locate irc prpl"
);
purple_signal_connect
(
irc
,
"irc-receiving-text"
,
(
__bridge
void
*
)(
self
),
PURPLE_CALLBACK
(
text_received_cb
),
(
__bridge
void
*
)(
self
));
purple_signal_connect
(
irc
,
"irc-sending-text"
,
(
__bridge
void
*
)(
self
),
PURPLE_CALLBACK
(
text_sent_cb
),
(
__bridge
void
*
)(
self
));
}
}
-
(
void
)
windowWillClose:
(
NSNotification
*
)
notification
{
//We don't need to watch the signals with the window closed
purple_signals_disconnect_by_handle
((
__bridge
void
*
)(
self
));
[
super
windowWillClose
:
notification
];
}
-
(
PurpleConnection
*
)
gc
{
return
gc
;
}
-
(
void
)
setPurpleConnection:
(
PurpleConnection
*
)
inGc
{
gc
=
inGc
;
}
@end