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/ircservertab.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/ircservertab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp new file mode 100644 index 0000000..1f377aa --- a/dev/null +++ b/noncore/net/opieirc/ircservertab.cpp | |||
@@ -0,0 +1,147 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "ircservertab.h" | ||
3 | |||
4 | IRCServerTab::IRCServerTab(IRCServer *server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | ||
5 | m_server = server; | ||
6 | m_session = new IRCSession(m_server); | ||
7 | m_mainWindow = mainWindow; | ||
8 | m_close = FALSE; | ||
9 | m_description->setText(tr("Connection to")+" <b>" + server->hostname() + ":" + QString::number(server->port()) + "</b>"); | ||
10 | m_textview = new QTextView(this); | ||
11 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | ||
12 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | ||
13 | m_layout->add(m_textview); | ||
14 | m_field = new QLineEdit(this); | ||
15 | m_layout->add(m_field); | ||
16 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | ||
17 | m_field->setFocus(); | ||
18 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); | ||
19 | } | ||
20 | |||
21 | void IRCServerTab::appendText(QString text) { | ||
22 | /* not using append because it creates layout problems */ | ||
23 | m_textview->setText(m_textview->text() + text); | ||
24 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | ||
25 | } | ||
26 | |||
27 | IRCServerTab::~IRCServerTab() { | ||
28 | QListIterator<IRCChannelTab> it(m_channelTabs); | ||
29 | for (; it.current(); ++it) { | ||
30 | m_mainWindow->killTab(it.current()); | ||
31 | } | ||
32 | delete m_session; | ||
33 | delete m_server; | ||
34 | } | ||
35 | |||
36 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { | ||
37 | m_channelTabs.remove(tab); | ||
38 | } | ||
39 | |||
40 | QString IRCServerTab::title() { | ||
41 | return "Server"; | ||
42 | } | ||
43 | |||
44 | IRCSession *IRCServerTab::session() { | ||
45 | return m_session; | ||
46 | } | ||
47 | |||
48 | IRCServer *IRCServerTab::server() { | ||
49 | return m_server; | ||
50 | } | ||
51 | |||
52 | void IRCServerTab::processCommand() { | ||
53 | m_field->clear(); | ||
54 | appendText("<font color=\"#ff0000\">Not supported yet</font><br>"); | ||
55 | } | ||
56 | |||
57 | void IRCServerTab::doConnect() { | ||
58 | m_session->beginSession(); | ||
59 | } | ||
60 | |||
61 | void IRCServerTab::remove() { | ||
62 | if (m_session->isSessionActive()) { | ||
63 | m_close = TRUE; | ||
64 | m_session->endSession(); | ||
65 | } else { | ||
66 | m_mainWindow->killTab(this); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { | ||
71 | QListIterator<IRCChannelTab> it(m_channelTabs); | ||
72 | |||
73 | for (; it.current(); ++it) { | ||
74 | if (it.current()->channel() == channel) | ||
75 | return it.current(); | ||
76 | } | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | void IRCServerTab::display(IRCOutput output) { | ||
81 | switch (output.type()) { | ||
82 | case OUTPUT_CONNCLOSE: | ||
83 | if (m_close) | ||
84 | m_mainWindow->killTab(this); | ||
85 | else | ||
86 | appendText("<font color=\"#0000dd\">" + output.message() +"</font><br>"); | ||
87 | break; | ||
88 | case OUTPUT_SELFJOIN: { | ||
89 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | ||
90 | m_channelTabs.append(channeltab); | ||
91 | m_mainWindow->addTab(channeltab); | ||
92 | } | ||
93 | break; | ||
94 | case OUTPUT_CHANPRIVMSG: { | ||
95 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
96 | channelTab->appendText("<<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>> "+output.message()+"<br>"); | ||
97 | } | ||
98 | break; | ||
99 | case OUTPUT_SELFPART: { | ||
100 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
101 | if (channelTab) | ||
102 | m_mainWindow->killTab(channelTab); | ||
103 | } | ||
104 | break; | ||
105 | case OUTPUT_SELFKICK: { | ||
106 | appendText("<font color=\"#ff0000\">" + output.message() + "</font><br>"); | ||
107 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
108 | if (channelTab) | ||
109 | m_mainWindow->killTab(channelTab); | ||
110 | } | ||
111 | break; | ||
112 | case OUTPUT_CHANACTION: { | ||
113 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
114 | channelTab->appendText("<font color=\"#cc0000\">"+output.message()+"</font><br>"); | ||
115 | } | ||
116 | break; | ||
117 | case OUTPUT_QUIT: { | ||
118 | QString nick = ((IRCPerson *)output.getParam(0))->nick(); | ||
119 | QListIterator<IRCChannelTab> it(m_channelTabs); | ||
120 | for (; it.current(); ++it) { | ||
121 | if (it.current()->list()->hasPerson(nick)) { | ||
122 | it.current()->appendText("<font color=\"#aa3e00\">"+output.message()+"</font><br>"); | ||
123 | it.current()->list()->update(); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | break; | ||
128 | case OUTPUT_OTHERJOIN: | ||
129 | case OUTPUT_OTHERKICK: | ||
130 | case OUTPUT_CHANPERSONMODE: | ||
131 | case OUTPUT_OTHERPART: { | ||
132 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | ||
133 | channelTab->appendText("<font color=\"#aa3e00\">"+output.message()+"</font><br>"); | ||
134 | channelTab->list()->update(); | ||
135 | } | ||
136 | break; | ||
137 | case OUTPUT_CTCP: | ||
138 | appendText("<font color=\"#00bb00\">" + output.message() + "</font><br>"); | ||
139 | break; | ||
140 | case OUTPUT_ERROR: | ||
141 | appendText("<font color=\"#ff0000\">" + output.message() + "</font><br>"); | ||
142 | break; | ||
143 | default: | ||
144 | appendText("<font color=\"#0000dd\">" + output.message() + "</font><br>"); | ||
145 | break; | ||
146 | } | ||
147 | } | ||