author | wazlaf <wazlaf> | 2002-09-10 23:12:17 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-09-10 23:12:17 (UTC) |
commit | d478be344e2ba383a1e38d2a1705de1cdbe2e838 (patch) (unidiff) | |
tree | 9daf7b496c74c695ed8bd72a6ccd321f770b043c /noncore/net/opieirc/ircsession.cpp | |
parent | 2d6c8bd7290b766c31c100cd2d66ef0d1d0c407c (diff) | |
download | opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.zip opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.tar.gz opie-d478be344e2ba383a1e38d2a1705de1cdbe2e838.tar.bz2 |
initial import of OpieIRC v0.1
Diffstat (limited to 'noncore/net/opieirc/ircsession.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircsession.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/noncore/net/opieirc/ircsession.cpp b/noncore/net/opieirc/ircsession.cpp new file mode 100644 index 0000000..b81038f --- a/dev/null +++ b/noncore/net/opieirc/ircsession.cpp | |||
@@ -0,0 +1,99 @@ | |||
1 | #include "ircsession.h" | ||
2 | #include "ircmessageparser.h" | ||
3 | #include "ircversion.h" | ||
4 | |||
5 | IRCSession::IRCSession(IRCServer *server) { | ||
6 | m_server = server; | ||
7 | m_connection = new IRCConnection(m_server); | ||
8 | m_parser = new IRCMessageParser(this); | ||
9 | connect(m_connection, SIGNAL(messageArrived(IRCMessage *)), this, SLOT(handleMessage(IRCMessage *))); | ||
10 | connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); | ||
11 | connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput))); | ||
12 | } | ||
13 | |||
14 | IRCSession::~IRCSession() { | ||
15 | delete m_parser; | ||
16 | delete m_connection; | ||
17 | } | ||
18 | |||
19 | void IRCSession::beginSession() { | ||
20 | m_connection->doConnect(); | ||
21 | } | ||
22 | |||
23 | void IRCSession::join(QString channelname) { | ||
24 | m_connection->sendLine("JOIN "+channelname); | ||
25 | } | ||
26 | |||
27 | void IRCSession::sendMessage(IRCPerson *person, QString message) { | ||
28 | m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message); | ||
29 | } | ||
30 | |||
31 | void IRCSession::sendMessage(IRCChannel *channel, QString message) { | ||
32 | m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message); | ||
33 | } | ||
34 | |||
35 | bool IRCSession::isSessionActive() { | ||
36 | return m_connection->isConnected(); | ||
37 | } | ||
38 | |||
39 | void IRCSession::endSession() { | ||
40 | if (m_connection->isLoggedIn()) | ||
41 | m_connection->sendLine("QUIT :" APP_VERSION); | ||
42 | else | ||
43 | m_connection->close(); | ||
44 | } | ||
45 | |||
46 | void IRCSession::part(IRCChannel *channel) { | ||
47 | m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION); | ||
48 | } | ||
49 | |||
50 | |||
51 | IRCChannel *IRCSession::getChannel(QString channelname) { | ||
52 | QListIterator<IRCChannel> it(m_channels); | ||
53 | for (; it.current(); ++it) { | ||
54 | if (it.current()->channelname() == channelname) { | ||
55 | return it.current(); | ||
56 | } | ||
57 | } | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | IRCPerson *IRCSession::getPerson(QString nickname) { | ||
62 | QListIterator<IRCPerson> it(m_people); | ||
63 | for (; it.current(); ++it) { | ||
64 | if (it.current()->nick() == nickname) { | ||
65 | return it.current(); | ||
66 | } | ||
67 | } | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) { | ||
72 | QListIterator<IRCChannel> it(m_channels); | ||
73 | for (; it.current(); ++it) { | ||
74 | if (it.current()->getPerson(person->nick()) != 0) { | ||
75 | channels.append(it.current()); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | void IRCSession::addPerson(IRCPerson *person) { | ||
81 | m_people.append(person); | ||
82 | } | ||
83 | |||
84 | void IRCSession::addChannel(IRCChannel *channel) { | ||
85 | m_channels.append(channel); | ||
86 | } | ||
87 | |||
88 | void IRCSession::removeChannel(IRCChannel *channel) { | ||
89 | m_channels.remove(channel); | ||
90 | } | ||
91 | |||
92 | void IRCSession::removePerson(IRCPerson *person) { | ||
93 | m_people.remove(person); | ||
94 | } | ||
95 | |||
96 | void IRCSession::handleMessage(IRCMessage *message) { | ||
97 | m_parser->parse(message); | ||
98 | } | ||
99 | |||