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