Diffstat (limited to 'noncore/net/opieirc/ircservertab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 503a758..8b8771f 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp | |||
@@ -2,46 +2,51 @@ | |||
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_layout->add(m_textview); | 15 | m_layout->add(m_textview); |
15 | m_field = new QLineEdit(this); | 16 | m_field = new QLineEdit(this); |
16 | m_layout->add(m_field); | 17 | m_layout->add(m_field); |
17 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 18 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
18 | m_field->setFocus(); | 19 | m_field->setFocus(); |
19 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); | 20 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); |
20 | } | 21 | } |
21 | 22 | ||
22 | void IRCServerTab::appendText(QString text) { | 23 | void IRCServerTab::appendText(QString text) { |
23 | /* not using append because it creates layout problems */ | 24 | /* not using append because it creates layout problems */ |
24 | m_textview->setText(m_textview->text() + text); | 25 | m_textview->setText(m_textview->text() + text); |
25 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 26 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
26 | } | 27 | } |
27 | 28 | ||
28 | IRCServerTab::~IRCServerTab() { | 29 | IRCServerTab::~IRCServerTab() { |
29 | delete m_session; | 30 | delete m_session; |
30 | } | 31 | } |
31 | 32 | ||
32 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { | 33 | void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { |
33 | m_channelTabs.remove(tab); | 34 | m_channelTabs.remove(tab); |
34 | } | 35 | } |
35 | 36 | ||
37 | void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { | ||
38 | m_queryTabs.remove(tab); | ||
39 | } | ||
40 | |||
36 | QString IRCServerTab::title() { | 41 | QString IRCServerTab::title() { |
37 | return "Server"; | 42 | return "Server"; |
38 | } | 43 | } |
39 | 44 | ||
40 | IRCSession *IRCServerTab::session() { | 45 | IRCSession *IRCServerTab::session() { |
41 | return m_session; | 46 | return m_session; |
42 | } | 47 | } |
43 | 48 | ||
44 | IRCServer *IRCServerTab::server() { | 49 | IRCServer *IRCServerTab::server() { |
45 | return &m_server; | 50 | return &m_server; |
46 | } | 51 | } |
47 | 52 | ||
@@ -51,34 +56,48 @@ void IRCServerTab::executeCommand(IRCTab *tab, QString line) { | |||
51 | stream >> command; | 56 | stream >> command; |
52 | command = command.upper().right(command.length()-1); | 57 | command = command.upper().right(command.length()-1); |
53 | 58 | ||
54 | if (command == "JOIN") { | 59 | if (command == "JOIN") { |
55 | QString channel; | 60 | QString channel; |
56 | stream >> channel; | 61 | stream >> channel; |
57 | if (channel.length() > 0 && channel.startsWith("#")) { | 62 | if (channel.length() > 0 && channel.startsWith("#")) { |
58 | m_session->join(channel); | 63 | m_session->join(channel); |
59 | } else { | 64 | } else { |
60 | tab->appendText("<font color=\"#ff0000\">Unknown channel format!</font><br>"); | 65 | tab->appendText("<font color=\"#ff0000\">Unknown channel format!</font><br>"); |
61 | } | 66 | } |
62 | } else if (command == "ME") { | 67 | } else if (command == "ME") { |
63 | QString text = IRCOutput::toHTML(line.right(line.length()-4)); | 68 | QString text = line.right(line.length()-4); |
64 | if (text.length() > 0) { | 69 | if (text.length() > 0) { |
65 | if (tab->isA("IRCChannelTab")) { | 70 | if (tab->isA("IRCChannelTab")) { |
66 | tab->appendText("<font color=\"#cc0000\">*" + m_server.nick() + " " + text + "</font><br>"); | 71 | tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); |
67 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); | 72 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); |
68 | } else if (tab->isA("IRCQueryTab")) { | 73 | } else if (tab->isA("IRCQueryTab")) { |
74 | tab->appendText("<font color=\"#cc0000\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); | ||
75 | m_session->sendAction(((IRCQueryTab *)tab)->person(), text); | ||
69 | } else { | 76 | } else { |
70 | tab->appendText("<font color=\"#ff0000\">Invalid tab for this command</font><br>"); | 77 | tab->appendText("<font color=\"#ff0000\">Invalid tab for this command</font><br>"); |
71 | } | 78 | } |
72 | } | 79 | } |
80 | } else if (command == "MSG") { | ||
81 | QString nickname; | ||
82 | stream >> nickname; | ||
83 | if (nickname.length() > 0) { | ||
84 | if (line.length() > 6 + nickname.length()) { | ||
85 | QString text = line.right(line.length()-nickname.length()-6); | ||
86 | IRCPerson person; | ||
87 | person.setNick(nickname); | ||
88 | tab->appendText("><font color=\"#0000dd\">"+IRCOutput::toHTML(nickname)+"</font>< "+IRCOutput::toHTML(text)+"<br>"); | ||
89 | m_session->sendMessage(&person, text); | ||
90 | } | ||
91 | } | ||
73 | } else { | 92 | } else { |
74 | tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>"); | 93 | tab->appendText("<font color=\"#ff0000\">Unknown command</font><br>"); |
75 | } | 94 | } |
76 | } | 95 | } |
77 | 96 | ||
78 | void IRCServerTab::processCommand() { | 97 | void IRCServerTab::processCommand() { |
79 | QString text = m_field->text(); | 98 | QString text = m_field->text(); |
80 | if (text.startsWith("/") && !text.startsWith("//")) { | 99 | if (text.startsWith("/") && !text.startsWith("//")) { |
81 | /* Command mode */ | 100 | /* Command mode */ |
82 | executeCommand(this, text); | 101 | executeCommand(this, text); |
83 | } | 102 | } |
84 | m_field->clear(); | 103 | m_field->clear(); |
@@ -91,66 +110,95 @@ void IRCServerTab::doConnect() { | |||
91 | void IRCServerTab::remove() { | 110 | void IRCServerTab::remove() { |
92 | /* Close requested */ | 111 | /* Close requested */ |
93 | if (m_session->isSessionActive()) { | 112 | if (m_session->isSessionActive()) { |
94 | /* While there is a running session */ | 113 | /* While there is a running session */ |
95 | m_close = TRUE; | 114 | m_close = TRUE; |
96 | m_session->endSession(); | 115 | m_session->endSession(); |
97 | } else { | 116 | } else { |
98 | /* Session has previously been closed */ | 117 | /* Session has previously been closed */ |
99 | m_channelTabs.first(); | 118 | m_channelTabs.first(); |
100 | while (m_channelTabs.current() != 0) { | 119 | while (m_channelTabs.current() != 0) { |
101 | m_mainWindow->killTab(m_channelTabs.current()); | 120 | m_mainWindow->killTab(m_channelTabs.current()); |
102 | } | 121 | } |
122 | m_queryTabs.first(); | ||
123 | while (m_queryTabs.current() != 0) { | ||
124 | m_mainWindow->killTab(m_queryTabs.current()); | ||
125 | } | ||
103 | m_mainWindow->killTab(this); | 126 | m_mainWindow->killTab(this); |
104 | } | 127 | } |
105 | } | 128 | } |
106 | 129 | ||
107 | IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { | 130 | IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { |
108 | QListIterator<IRCChannelTab> it(m_channelTabs); | 131 | QListIterator<IRCChannelTab> it(m_channelTabs); |
109 | 132 | ||
110 | for (; it.current(); ++it) { | 133 | for (; it.current(); ++it) { |
111 | if (it.current()->channel() == channel) | 134 | if (it.current()->channel() == channel) |
112 | return it.current(); | 135 | return it.current(); |
113 | } | 136 | } |
114 | return 0; | 137 | return 0; |
115 | } | 138 | } |
116 | 139 | ||
140 | IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) { | ||
141 | QListIterator<IRCQueryTab> it(m_queryTabs); | ||
142 | |||
143 | for (; it.current(); ++it) { | ||
144 | if (it.current()->person()->nick() == person->nick()) | ||
145 | return it.current(); | ||
146 | } | ||
147 | return 0; | ||
148 | } | ||
149 | |||
117 | void IRCServerTab::display(IRCOutput output) { | 150 | void IRCServerTab::display(IRCOutput output) { |
118 | 151 | ||
119 | /* All messages to be displayed inside the GUI get here */ | 152 | /* All messages to be displayed inside the GUI get here */ |
120 | switch (output.type()) { | 153 | switch (output.type()) { |
121 | case OUTPUT_CONNCLOSE: | 154 | case OUTPUT_CONNCLOSE: |
122 | if (m_close) { | 155 | if (m_close) { |
123 | m_channelTabs.first(); | 156 | m_channelTabs.first(); |
124 | while (m_channelTabs.current() != 0) { | 157 | while (m_channelTabs.current() != 0) { |
125 | m_mainWindow->killTab(m_channelTabs.current()); | 158 | m_mainWindow->killTab(m_channelTabs.current()); |
126 | } | 159 | } |
160 | m_queryTabs.first(); | ||
161 | while (m_queryTabs.current() != 0) { | ||
162 | m_mainWindow->killTab(m_queryTabs.current()); | ||
163 | } | ||
127 | m_mainWindow->killTab(this); | 164 | m_mainWindow->killTab(this); |
128 | } else { | 165 | } else { |
129 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); | 166 | appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); |
130 | QListIterator<IRCChannelTab> it(m_channelTabs); | 167 | QListIterator<IRCChannelTab> it(m_channelTabs); |
131 | for (; it.current(); ++it) { | 168 | for (; it.current(); ++it) { |
132 | it.current()->appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); | 169 | it.current()->appendText("<font color=\"#0000dd\">" + output.htmlMessage() +"</font><br>"); |
133 | } | 170 | } |
134 | } | 171 | } |
135 | break; | 172 | break; |
136 | case OUTPUT_SELFJOIN: { | 173 | case OUTPUT_SELFJOIN: { |
137 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | 174 | IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); |
138 | m_channelTabs.append(channeltab); | 175 | m_channelTabs.append(channeltab); |
139 | m_mainWindow->addTab(channeltab); | 176 | m_mainWindow->addTab(channeltab); |
140 | } | 177 | } |
141 | break; | 178 | break; |
142 | case OUTPUT_CHANPRIVMSG: { | 179 | case OUTPUT_CHANPRIVMSG: { |
143 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 180 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
144 | channelTab->appendText("<<font color=\"#0000dd\">"+((IRCChannelPerson *)output.getParam(1))->person->nick()+"</font>> "+output.htmlMessage()+"<br>"); | 181 | channelTab->appendText("<<font color=\"#0000dd\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font>> "+output.htmlMessage()+"<br>"); |
182 | } | ||
183 | break; | ||
184 | case OUTPUT_QUERYACTION: | ||
185 | case OUTPUT_QUERYPRIVMSG: { | ||
186 | IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); | ||
187 | if (!queryTab) { | ||
188 | queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); | ||
189 | m_queryTabs.append(queryTab); | ||
190 | m_mainWindow->addTab(queryTab); | ||
191 | } | ||
192 | queryTab->display(output); | ||
145 | } | 193 | } |
146 | break; | 194 | break; |
147 | case OUTPUT_SELFPART: { | 195 | case OUTPUT_SELFPART: { |
148 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 196 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
149 | if (channelTab) | 197 | if (channelTab) |
150 | m_mainWindow->killTab(channelTab); | 198 | m_mainWindow->killTab(channelTab); |
151 | } | 199 | } |
152 | break; | 200 | break; |
153 | case OUTPUT_SELFKICK: { | 201 | case OUTPUT_SELFKICK: { |
154 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); | 202 | appendText("<font color=\"#ff0000\">" + output.htmlMessage() + "</font><br>"); |
155 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); | 203 | IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); |
156 | if (channelTab) | 204 | if (channelTab) |