Diffstat (limited to 'noncore/net/opieirc/ircservertab.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 8b8771f..4be60ef 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp | |||
@@ -1,105 +1,114 @@ | |||
1 | #include <stdio.h> | 1 | #include <qpe/config.h> |
2 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
3 | #include "ircservertab.h" | 3 | #include "ircservertab.h" |
4 | 4 | ||
5 | IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | 5 | IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { |
6 | m_server = server; | 6 | m_server = server; |
7 | m_session = new IRCSession(&m_server); | 7 | m_session = new IRCSession(&m_server); |
8 | m_mainWindow = mainWindow; | 8 | m_mainWindow = mainWindow; |
9 | m_close = FALSE; | 9 | m_close = FALSE; |
10 | m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>"); | 10 | m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>"); |
11 | m_textview = new QTextView(this); | 11 | m_textview = new QTextView(this); |
12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | 12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); |
13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | 13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); |
14 | m_textview->setTextFormat(RichText); | 14 | m_textview->setTextFormat(RichText); |
15 | m_layout->add(m_textview); | 15 | m_layout->add(m_textview); |
16 | m_field = new QLineEdit(this); | 16 | m_field = new QLineEdit(this); |
17 | m_layout->add(m_field); | 17 | m_layout->add(m_field); |
18 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 18 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
19 | m_field->setFocus(); | 19 | m_field->setFocus(); |
20 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); | 20 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); |
21 | settingsChanged(); | ||
21 | } | 22 | } |
22 | 23 | ||
23 | void IRCServerTab::appendText(QString text) { | 24 | void IRCServerTab::appendText(QString text) { |
24 | /* not using append because it creates layout problems */ | 25 | /* not using append because it creates layout problems */ |
25 | m_textview->setText(m_textview->text() + text); | 26 | m_textview->setText(m_textview->text() + text); |
26 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 27 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
27 | } | 28 | } |
28 | 29 | ||
29 | IRCServerTab::~IRCServerTab() { | 30 | IRCServerTab::~IRCServerTab() { |
30 | delete m_session; | 31 | delete m_session; |
31 | } | 32 | } |
32 | 33 | ||
33 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { | 34 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { |
34 | m_channelTabs.remove(tab); | 35 | m_channelTabs.remove(tab); |
35 | } | 36 | } |
36 | 37 | ||
37 | void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { | 38 | void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { |
38 | m_queryTabs.remove(tab); | 39 | m_queryTabs.remove(tab); |
39 | } | 40 | } |
40 | 41 | ||
42 | void IRCServerTab::addQueryTab(IRCQueryTab *tab) { | ||
43 | m_queryTabs.append(tab); | ||
44 | } | ||
45 | |||
41 | QString IRCServerTab::title() { | 46 | QString IRCServerTab::title() { |
42 | return "Server"; | 47 | return "Server"; |
43 | } | 48 | } |
44 | 49 | ||
45 | IRCSession *IRCServerTab::session() { | 50 | IRCSession *IRCServerTab::session() { |
46 | return m_session; | 51 | return m_session; |
47 | } | 52 | } |
48 | 53 | ||
49 | IRCServer *IRCServerTab::server() { | 54 | IRCServer *IRCServerTab::server() { |
50 | return &m_server; | 55 | return &m_server; |
51 | } | 56 | } |
52 | 57 | ||
58 | void IRCServerTab::settingsChanged() { | ||
59 | m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); | ||
60 | } | ||
61 | |||
53 | void IRCServerTab::executeCommand(IRCTab *tab, QString line) { | 62 | void IRCServerTab::executeCommand(IRCTab *tab, QString line) { |
54 | QTextIStream stream(&line); | 63 | QTextIStream stream(&line); |
55 | QString command; | 64 | QString command; |
56 | stream >> command; | 65 | stream >> command; |
57 | command = command.upper().right(command.length()-1); | 66 | command = command.upper().right(command.length()-1); |
58 | 67 | ||
59 | if (command == "JOIN") { | 68 | if (command == "JOIN") { |
60 | QString channel; | 69 | QString channel; |
61 | stream >> channel; | 70 | stream >> channel; |
62 | if (channel.length() > 0 && channel.startsWith("#")) { | 71 | if (channel.length() > 0 && channel.startsWith("#")) { |
63 | m_session->join(channel); | 72 | m_session->join(channel); |
64 | } else { | 73 | } else { |
65 | tab->appendText("<font color=\"#ff0000\">Unknown channel format!</font><br>"); | 74 | tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); |
66 | } | 75 | } |
67 | } else if (command == "ME") { | 76 | } else if (command == "ME") { |
68 | QString text = line.right(line.length()-4); | 77 | QString text = line.right(line.length()-4); |
69 | if (text.length() > 0) { | 78 | if (text.length() > 0) { |
70 | if (tab->isA("IRCChannelTab")) { | 79 | if (tab->isA("IRCChannelTab")) { |
71 | tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); | 80 | tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); |
72 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); | 81 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); |
73 | } else if (tab->isA("IRCQueryTab")) { | 82 | } else if (tab->isA("IRCQueryTab")) { |
74 | tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); | 83 | tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); |
75 | m_session->sendAction(((IRCQueryTab *)tab)->person(), text); | 84 | m_session->sendAction(((IRCQueryTab *)tab)->person(), text); |
76 | } else { | 85 | } else { |
77 | tab->appendText("<font color=\"#ff0000\">Invalid tab for this command</font><br>"); | 86 | tab->appendText("<font color=\"" + m_errorColor + "\">Invalid tab for this command</font><br>"); |
78 | } | 87 | } |
79 | } | 88 | } |
80 | } else if (command == "MSG") { | 89 | } else if (command == "MSG") { |
81 | QString nickname; | 90 | QString nickname; |
82 | stream >> nickname; | 91 | stream >> nickname; |
83 | if (nickname.length() > 0) { | 92 | if (nickname.length() > 0) { |
84 | if (line.length() > 6 + nickname.length()) { | 93 | if (line.length() > 6 + nickname.length()) { |
85 | QString text = line.right(line.length()-nickname.length()-6); | 94 | QString text = line.right(line.length()-nickname.length()-6); |
86 | IRCPerson person; | 95 | IRCPerson person; |
87 | person.setNick(nickname); | 96 | person.setNick(nickname); |
88 | tab->appendText("><font color=\"#0000dd\">"+IRCOutput::toHTML(nickname)+"</font>< "+IRCOutput::toHTML(text)+"<br>"); | 97 | tab->appendText("<font color=\"" + m_textColor + "\">></font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(nickname)+"</font><font color=\"" + m_textColor + "\">< "+IRCOutput::toHTML(text)+"</font><br>"); |
89 | m_session->sendMessage(&person, text); | 98 | m_session->sendMessage(&person, text); |
90 | } | 99 | } |
91 | } | 100 | } |
92 | } else { | 101 | } else { |
93 | tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>"); | 102 | tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>"); |
94 | } | 103 | } |
95 | } | 104 | } |
96 | 105 | ||
97 | void IRCServerTab::processCommand() { | 106 | void IRCServerTab::processCommand() { |
98 | QString text = m_field->text(); | 107 | QString text = m_field->text(); |
99 | if (text.startsWith("/") && !text.startsWith("//")) { | 108 | if (text.startsWith("/") && !text.startsWith("//")) { |
100 | /* Command mode */ | 109 | /* Command mode */ |
101 | executeCommand(this, text); | 110 | executeCommand(this, text); |
102 | } | 111 | } |
103 | m_field->clear(); | 112 | m_field->clear(); |
104 | } | 113 | } |
105 | 114 | ||
@@ -154,90 +163,90 @@ void IRCServerTab::display(IRCOutput output) { | |||
154 | case OUTPUT_CONNCLOSE: | 163 | case OUTPUT_CONNCLOSE: |
155 | if (m_close) { | 164 | if (m_close) { |
156 | m_channelTabs.first(); | 165 | m_channelTabs.first(); |
157 | while (m_channelTabs.current() != 0) { | 166 | while (m_channelTabs.current() != 0) { |
158 | m_mainWindow->killTab(m_channelTabs.current()); | 167 | m_mainWindow->killTab(m_channelTabs.current()); |
159 | } | 168 | } |
160 | m_queryTabs.first(); | 169 | m_queryTabs.first(); |
161 | while (m_queryTabs.current() != 0) { | 170 | while (m_queryTabs.current() != 0) { |
162 | m_mainWindow->killTab(m_queryTabs.current()); | 171 | m_mainWindow->killTab(m_queryTabs.current()); |
163 | } | 172 | } |
164 | m_mainWindow->killTab(this); | 173 | m_mainWindow->killTab(this); |
165 | } else { | 174 | } else { |
166 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); | 175 | appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>"); |
167 | QListIterator<IRCChannelTab> it(m_channelTabs); | 176 | QListIterator<IRCChannelTab> it(m_channelTabs); |
168 | for (; it.current(); ++it) { | 177 | for (; it.current(); ++it) { |
169 | it.current()->appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); | 178 | it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>"); |
170 | } | 179 | } |
171 | } | 180 | } |
172 | break; | 181 | break; |
173 | case OUTPUT_SELFJOIN: { | 182 | case OUTPUT_SELFJOIN: { |
174 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | 183 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); |
175 | m_channelTabs.append(channeltab); | 184 | m_channelTabs.append(channeltab); |
176 | m_mainWindow->addTab(channeltab); | 185 | m_mainWindow->addTab(channeltab); |
177 | } | 186 | } |
178 | break; | 187 | break; |
179 | case OUTPUT_CHANPRIVMSG: { | 188 | case OUTPUT_CHANPRIVMSG: { |
180 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 189 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
181 | channelTab->appendText("<<font color=\"#0000dd\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font>> "+output.htmlMessage()+"<br>"); | 190 | channelTab->appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font><font color=\"" + m_textColor + "\">> " + output.htmlMessage()+"</font><br>"); |
182 | } | 191 | } |
183 | break; | 192 | break; |
184 | case OUTPUT_QUERYACTION: | 193 | case OUTPUT_QUERYACTION: |
185 | case OUTPUT_QUERYPRIVMSG: { | 194 | case OUTPUT_QUERYPRIVMSG: { |
186 | IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); | 195 | IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); |
187 | if (!queryTab) { | 196 | if (!queryTab) { |
188 | queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | 197 | queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); |
189 | m_queryTabs.append(queryTab); | 198 | m_queryTabs.append(queryTab); |
190 | m_mainWindow->addTab(queryTab); | 199 | m_mainWindow->addTab(queryTab); |
191 | } | 200 | } |
192 | queryTab->display(output); | 201 | queryTab->display(output); |
193 | } | 202 | } |
194 | break; | 203 | break; |
195 | case OUTPUT_SELFPART: { | 204 | case OUTPUT_SELFPART: { |
196 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 205 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
197 | if (channelTab) | 206 | if (channelTab) |
198 | m_mainWindow->killTab(channelTab); | 207 | m_mainWindow->killTab(channelTab); |
199 | } | 208 | } |
200 | break; | 209 | break; |
201 | case OUTPUT_SELFKICK: { | 210 | case OUTPUT_SELFKICK: { |
202 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); | 211 | appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); |
203 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 212 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
204 | if (channelTab) | 213 | if (channelTab) |
205 | m_mainWindow->killTab(channelTab); | 214 | m_mainWindow->killTab(channelTab); |
206 | } | 215 | } |
207 | break; | 216 | break; |
208 | case OUTPUT_CHANACTION: { | 217 | case OUTPUT_CHANACTION: { |
209 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 218 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
210 | channelTab->appendText("<font color=\"#cc0000\">"+output.htmlMessage()+"</font><br>"); | 219 | channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>"); |
211 | } | 220 | } |
212 | break; | 221 | break; |
213 | case OUTPUT_QUIT: { | 222 | case OUTPUT_QUIT: { |
214 | QString nick = ((IRCPerson *)output.getParam(0))->nick(); | 223 | QString nick = ((IRCPerson *)output.getParam(0))->nick(); |
215 | QListIterator<IRCChannelTab> it(m_channelTabs); | 224 | QListIterator<IRCChannelTab> it(m_channelTabs); |
216 | for (; it.current(); ++it) { | 225 | for (; it.current(); ++it) { |
217 | if (it.current()->list()->hasPerson(nick)) { | 226 | if (it.current()->list()->hasPerson(nick)) { |
218 | it.current()->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>"); | 227 | it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); |
219 | it.current()->list()->update(); | 228 | it.current()->list()->update(); |
220 | } | 229 | } |
221 | } | 230 | } |
222 | } | 231 | } |
223 | break; | 232 | break; |
224 | case OUTPUT_OTHERJOIN: | 233 | case OUTPUT_OTHERJOIN: |
225 | case OUTPUT_OTHERKICK: | 234 | case OUTPUT_OTHERKICK: |
226 | case OUTPUT_CHANPERSONMODE: | 235 | case OUTPUT_CHANPERSONMODE: |
227 | case OUTPUT_OTHERPART: { | 236 | case OUTPUT_OTHERPART: { |
228 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 237 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
229 | channelTab->appendText("<font color=\"#aa3e00\">"+output.htmlMessage()+"</font><br>"); | 238 | channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); |
230 | channelTab->list()->update(); | 239 | channelTab->list()->update(); |
231 | } | 240 | } |
232 | break; | 241 | break; |
233 | case OUTPUT_CTCP: | 242 | case OUTPUT_CTCP: |
234 | appendText("<font color=\"#00bb00\">" + output.htmlMessage() + "</font><br>"); | 243 | appendText("<font color=\"" + m_notificationColor + "\">" + output.htmlMessage() + "</font><br>"); |
235 | break; | 244 | break; |
236 | case OUTPUT_ERROR: | 245 | case OUTPUT_ERROR: |
237 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); | 246 | appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); |
238 | break; | 247 | break; |
239 | default: | 248 | default: |
240 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() + "</font><br>"); | 249 | appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>"); |
241 | break; | 250 | break; |
242 | } | 251 | } |
243 | } | 252 | } |