Diffstat (limited to 'noncore/net/opieirc/ircservertab.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 97 |
1 files changed, 93 insertions, 4 deletions
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 5aa447f..1d9520a 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp | |||
@@ -13,27 +13,33 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa | |||
13 | m_textview = new QTextView(this); | 13 | m_textview = new QTextView(this); |
14 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | 14 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); |
15 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | 15 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); |
16 | m_textview->setTextFormat(RichText); | 16 | m_textview->setTextFormat(RichText); |
17 | QWhatsThis::add(m_textview, tr("Server messages")); | 17 | QWhatsThis::add(m_textview, tr("Server messages")); |
18 | m_layout->add(m_textview); | 18 | m_layout->add(m_textview); |
19 | m_field = new IRCHistoryLineEdit(this); | 19 | m_field = new IRCHistoryLineEdit(this); |
20 | QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help")); | 20 | QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help")); |
21 | m_layout->add(m_field); | 21 | m_layout->add(m_field); |
22 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 22 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
23 | m_field->setFocus(); | 23 | m_field->setFocus(); |
24 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); | 24 | connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); |
25 | connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); | ||
25 | settingsChanged(); | 26 | settingsChanged(); |
26 | } | 27 | } |
27 | 28 | ||
29 | void IRCServerTab::scrolling(){ | ||
30 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | ||
31 | } | ||
32 | |||
33 | |||
28 | void IRCServerTab::appendText(QString text) { | 34 | void IRCServerTab::appendText(QString text) { |
29 | /* not using append because it creates layout problems */ | 35 | /* not using append because it creates layout problems */ |
30 | QString txt = m_textview->text() + text + "\n"; | 36 | QString txt = m_textview->text() + text + "\n"; |
31 | if (m_maxLines > 0 && m_lines >= m_maxLines) { | 37 | if (m_maxLines > 0 && m_lines >= m_maxLines) { |
32 | int firstBreak = txt.find('\n'); | 38 | int firstBreak = txt.find('\n'); |
33 | if (firstBreak != -1) { | 39 | if (firstBreak != -1) { |
34 | txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); | 40 | txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); |
35 | } | 41 | } |
36 | } else { | 42 | } else { |
37 | m_lines++; | 43 | m_lines++; |
38 | } | 44 | } |
39 | m_textview->setText(txt); | 45 | m_textview->setText(txt); |
@@ -55,74 +61,157 @@ void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { | |||
55 | 61 | ||
56 | void IRCServerTab::addQueryTab(IRCQueryTab *tab) { | 62 | void IRCServerTab::addQueryTab(IRCQueryTab *tab) { |
57 | m_queryTabs.append(tab); | 63 | m_queryTabs.append(tab); |
58 | } | 64 | } |
59 | 65 | ||
60 | QString IRCServerTab::title() { | 66 | QString IRCServerTab::title() { |
61 | return "Server"; | 67 | return "Server"; |
62 | } | 68 | } |
63 | 69 | ||
64 | IRCSession *IRCServerTab::session() { | 70 | IRCSession *IRCServerTab::session() { |
65 | return m_session; | 71 | return m_session; |
66 | } | 72 | } |
73 | /* | ||
74 | QString *IRCServerTab::mynick() { | ||
75 | return (*m_server->nick()); | ||
76 | } */ | ||
67 | 77 | ||
68 | IRCServer *IRCServerTab::server() { | 78 | IRCServer *IRCServerTab::server() { |
69 | return &m_server; | 79 | return &m_server; |
70 | } | 80 | } |
71 | 81 | ||
72 | void IRCServerTab::settingsChanged() { | 82 | void IRCServerTab::settingsChanged() { |
73 | m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); | 83 | m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); |
74 | m_lines = 0; | 84 | m_lines = 0; |
75 | } | 85 | } |
76 | 86 | ||
77 | void IRCServerTab::executeCommand(IRCTab *tab, QString line) { | 87 | void IRCServerTab::executeCommand(IRCTab *tab, QString line) { |
78 | QTextIStream stream(&line); | 88 | QTextIStream stream(&line); |
79 | QString command; | 89 | QString command; |
80 | stream >> command; | 90 | stream >> command; |
81 | command = command.upper().right(command.length()-1); | 91 | command = command.upper().right(command.length()-1); |
82 | 92 | ||
83 | if (command == "JOIN") { | 93 | //JOIN |
94 | if (command == "JOIN" || command == "J") { | ||
84 | QString channel; | 95 | QString channel; |
85 | stream >> channel; | 96 | stream >> channel; |
86 | if (channel.length() > 0 && (channel.startsWith("#") || channel.startsWith("+"))) { | 97 | if (channel.length() > 0 && (channel.startsWith("#") || channel.startsWith("+"))) { |
87 | m_session->join(channel); | 98 | m_session->join(channel); |
88 | } else { | 99 | } else { |
89 | tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); | 100 | tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); |
90 | } | 101 | } |
91 | } else if (command == "ME") { | 102 | } |
103 | |||
104 | //KICK | ||
105 | else if (command == "KICK"){ | ||
106 | QString nickname; | ||
107 | stream >> nickname; | ||
108 | if (nickname.length() > 0) { | ||
109 | if (line.length() > 7 + nickname.length()) { | ||
110 | QString text = line.right(line.length()-nickname.length()-7); | ||
111 | IRCPerson person; | ||
112 | person.setNick(nickname); | ||
113 | m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text); | ||
114 | } else { | ||
115 | IRCPerson person; | ||
116 | person.setNick(nickname); | ||
117 | m_session->kick(((IRCChannelTab *)tab)->channel(), &person); | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | |||
122 | else if (command == "OP"){ | ||
123 | QString nickname; | ||
124 | stream >> nickname; | ||
125 | if (nickname.length() > 0) { | ||
126 | if (line.length() > 7 + nickname.length()) { | ||
127 | QString text = line.right(line.length()-nickname.length()-7); | ||
128 | IRCPerson person; | ||
129 | person.setNick(nickname); | ||
130 | m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text); | ||
131 | } else { | ||
132 | IRCPerson person; | ||
133 | person.setNick(nickname); | ||
134 | m_session->kick(((IRCChannelTab *)tab)->channel(), &person); | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | |||
139 | //SEND MODES | ||
140 | else if (command == "MODE"){ | ||
141 | QString text = line.right(line.length()-6); | ||
142 | if (text.length() > 0) { | ||
143 | m_session->mode(text); | ||
144 | } else { | ||
145 | tab->appendText("<font color=\"" + m_errorColor + "\">/mode channel {[+|-]|o|p|s|i|t|n|b|v} [limit] [user] [ban mask]<br>/mode nickname {[+|-]|i|w|s|o}</font><br>"); | ||
146 | } | ||
147 | } | ||
148 | //SEND RAW MESSAGE TO SERVER, COMPLETELY UNCHECKED - anything in the RFC...or really anything you want | ||
149 | else if (command == "RAW"){ | ||
150 | QString text = line.right(line.length()-5); | ||
151 | if (text.length() > 0) { | ||
152 | m_session->raw(text); | ||
153 | } | ||
154 | } | ||
155 | else if (command == "SUSPEND"){ | ||
156 | QString text = line.right(line.length()-9); | ||
157 | if (text.upper() == "ON") { | ||
158 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | ||
159 | } | ||
160 | else if (text.upper() == "OFF"){ | ||
161 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; | ||
162 | } else { | ||
163 | tab->appendText("<font color=\"" + m_errorColor + "\">Line: "+ line +"</font><br>Text: "+text); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | else if (command == "QUIT"){ | ||
168 | QString text = line.right(line.length()-6); | ||
169 | if (text.length() > 0) { | ||
170 | m_session->quit(text); | ||
171 | } else { | ||
172 | m_session->quit(); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | //SEND ACTION | ||
177 | else if (command == "ME") { | ||
92 | QString text = line.right(line.length()-4); | 178 | QString text = line.right(line.length()-4); |
93 | if (text.length() > 0) { | 179 | if (text.length() > 0) { |
94 | if (tab->isA("IRCChannelTab")) { | 180 | if (tab->isA("IRCChannelTab")) { |
95 | tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); | 181 | tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); |
96 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); | 182 | m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); |
97 | } else if (tab->isA("IRCQueryTab")) { | 183 | } else if (tab->isA("IRCQueryTab")) { |
98 | tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); | 184 | tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); |
99 | m_session->sendAction(((IRCQueryTab *)tab)->person(), text); | 185 | m_session->sendAction(((IRCQueryTab *)tab)->person(), text); |
100 | } else { | 186 | } else { |
101 | tab->appendText("<font color=\"" + m_errorColor + "\">Invalid tab for this command</font><br>"); | 187 | tab->appendText("<font color=\"" + m_errorColor + "\">Invalid tab for this command</font><br>"); |
102 | } | 188 | } |
103 | } | 189 | } |
104 | } else if (command == "MSG") { | 190 | } |
191 | //SEND PRIVMSG | ||
192 | else if (command == "MSG") { | ||
105 | QString nickname; | 193 | QString nickname; |
106 | stream >> nickname; | 194 | stream >> nickname; |
107 | if (nickname.length() > 0) { | 195 | if (nickname.length() > 0) { |
108 | if (line.length() > 6 + nickname.length()) { | 196 | if (line.length() > 6 + nickname.length()) { |
109 | QString text = line.right(line.length()-nickname.length()-6); | 197 | QString text = line.right(line.length()-nickname.length()-6); |
110 | IRCPerson person; | 198 | IRCPerson person; |
111 | person.setNick(nickname); | 199 | person.setNick(nickname); |
112 | tab->appendText("<font color=\"" + m_textColor + "\">></font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(nickname)+"</font><font color=\"" + m_textColor + "\">< "+IRCOutput::toHTML(text)+"</font><br>"); | 200 | tab->appendText("<font color=\"" + m_textColor + "\">></font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(nickname)+"</font><font color=\"" + m_textColor + "\">< "+IRCOutput::toHTML(text)+"</font><br>"); |
113 | m_session->sendMessage(&person, text); | 201 | m_session->sendMessage(&person, text); |
114 | } | 202 | } |
115 | } | 203 | } |
116 | } else { | 204 | } |
205 | else { | ||
117 | tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>"); | 206 | tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>"); |
118 | } | 207 | } |
119 | } | 208 | } |
120 | 209 | ||
121 | void IRCServerTab::processCommand() { | 210 | void IRCServerTab::processCommand() { |
122 | QString text = m_field->text(); | 211 | QString text = m_field->text(); |
123 | if (text.startsWith("/") && !text.startsWith("//")) { | 212 | if (text.startsWith("/") && !text.startsWith("//")) { |
124 | /* Command mode */ | 213 | /* Command mode */ |
125 | executeCommand(this, text); | 214 | executeCommand(this, text); |
126 | } | 215 | } |
127 | m_field->clear(); | 216 | m_field->clear(); |
128 | } | 217 | } |