Diffstat (limited to 'noncore/net/opieirc/ircchanneltab.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp index ddd6cf1..f19e019 100644 --- a/noncore/net/opieirc/ircchanneltab.cpp +++ b/noncore/net/opieirc/ircchanneltab.cpp | |||
@@ -1,102 +1,115 @@ | |||
1 | #include <qpe/qpeapplication.h> | 1 | #include <qpe/qpeapplication.h> |
2 | #include <qpe/resource.h> | 2 | #include <qpe/resource.h> |
3 | #include <qcursor.h> | 3 | #include <qcursor.h> |
4 | #include <stdio.h> | ||
4 | #include <qhbox.h> | 5 | #include <qhbox.h> |
5 | #include "ircchanneltab.h" | 6 | #include "ircchanneltab.h" |
6 | #include "ircservertab.h" | 7 | #include "ircservertab.h" |
7 | 8 | ||
8 | IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | 9 | IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { |
9 | m_mainWindow = mainWindow; | 10 | m_mainWindow = mainWindow; |
10 | m_parentTab = parentTab; | 11 | m_parentTab = parentTab; |
11 | m_channel = channel; | 12 | m_channel = channel; |
12 | m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); | 13 | m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); |
13 | QHBox *hbox = new QHBox(this); | 14 | QHBox *hbox = new QHBox(this); |
14 | m_textview = new QTextView(hbox); | 15 | m_textview = new QTextView(hbox); |
15 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | 16 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); |
16 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | 17 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); |
17 | m_listVisible = TRUE; | 18 | m_listVisible = TRUE; |
18 | m_listButton = new QPushButton(">", m_textview); | 19 | m_listButton = new QPushButton(">", m_textview); |
19 | m_textview->setCornerWidget(m_listButton); | 20 | m_textview->setCornerWidget(m_listButton); |
20 | m_textview->setTextFormat(RichText); | 21 | m_textview->setTextFormat(RichText); |
21 | connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList())); | 22 | connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList())); |
22 | m_list = new IRCChannelList(m_channel, hbox); | 23 | m_list = new IRCChannelList(m_channel, hbox); |
23 | m_list->update(); | 24 | m_list->update(); |
24 | m_list->setMaximumWidth(LISTWIDTH); | 25 | m_list->setMaximumWidth(LISTWIDTH); |
25 | m_field = new QLineEdit(this); | 26 | m_field = new IRCHistoryLineEdit(this); |
26 | m_popup = new QPopupMenu(m_list); | 27 | m_popup = new QPopupMenu(m_list); |
28 | m_lines = 0; | ||
27 | /* Required so that embedded-style "right" clicks work */ | 29 | /* Required so that embedded-style "right" clicks work */ |
28 | QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold); | 30 | QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold); |
29 | connect(m_list, SIGNAL(mouseButtonPressed(int, QListBoxItem *, const QPoint&)), this, SLOT(mouseButtonPressed(int, QListBoxItem *, const QPoint &))); | 31 | connect(m_list, SIGNAL(mouseButtonPressed(int, QListBoxItem *, const QPoint&)), this, SLOT(mouseButtonPressed(int, QListBoxItem *, const QPoint &))); |
32 | |||
30 | /* Construct the popup menu */ | 33 | /* Construct the popup menu */ |
31 | QPopupMenu *ctcpMenu = new QPopupMenu(m_list); | 34 | QPopupMenu *ctcpMenu = new QPopupMenu(m_list); |
32 | m_popup->insertItem(Resource::loadPixmap("opieirc/ctcp"), tr("CTCP"), ctcpMenu); | 35 | m_popup->insertItem(Resource::loadPixmap("opieirc/ctcp"), tr("CTCP"), ctcpMenu); |
33 | m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery())); | 36 | m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery())); |
34 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing())); | 37 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing())); |
35 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion())); | 38 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion())); |
36 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois())); | 39 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois())); |
37 | 40 | ||
38 | m_layout->add(hbox); | 41 | m_layout->add(hbox); |
39 | hbox->show(); | 42 | hbox->show(); |
40 | m_layout->add(m_field); | 43 | m_layout->add(m_field); |
41 | m_field->setFocus(); | 44 | m_field->setFocus(); |
42 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 45 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
43 | settingsChanged(); | 46 | settingsChanged(); |
44 | } | 47 | } |
45 | 48 | ||
46 | void IRCChannelTab::appendText(QString text) { | 49 | void IRCChannelTab::appendText(QString text) { |
47 | /* not using append because it creates layout problems */ | 50 | /* not using append because it creates layout problems */ |
48 | m_textview->setText(m_textview->text() + text); | 51 | QString txt = m_textview->text() + text + "\n"; |
52 | if (m_maxLines > 0 && m_lines >= m_maxLines) { | ||
53 | int firstBreak = txt.find('\n'); | ||
54 | if (firstBreak != -1) { | ||
55 | txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); | ||
56 | } | ||
57 | } else { | ||
58 | m_lines++; | ||
59 | } | ||
60 | m_textview->setText(txt); | ||
49 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 61 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
50 | emit changed(this); | 62 | emit changed(this); |
51 | } | 63 | } |
52 | 64 | ||
53 | IRCChannelTab::~IRCChannelTab() { | 65 | IRCChannelTab::~IRCChannelTab() { |
54 | m_parentTab->removeChannelTab(this); | 66 | m_parentTab->removeChannelTab(this); |
55 | } | 67 | } |
56 | 68 | ||
57 | void IRCChannelTab::processCommand() { | 69 | void IRCChannelTab::processCommand() { |
58 | QString text = m_field->text(); | 70 | QString text = m_field->text(); |
59 | if (text.length()>0) { | 71 | if (text.length()>0) { |
60 | if (session()->isSessionActive()) { | 72 | if (session()->isSessionActive()) { |
61 | if (text.startsWith("/") && !text.startsWith("//")) { | 73 | if (text.startsWith("/") && !text.startsWith("//")) { |
62 | /* Command mode */ | 74 | /* Command mode */ |
63 | m_parentTab->executeCommand(this, text);; | 75 | m_parentTab->executeCommand(this, text);; |
64 | } else { | 76 | } else { |
65 | if (text.startsWith("//")) | 77 | if (text.startsWith("//")) |
66 | text = text.right(text.length()-1); | 78 | text = text.right(text.length()-1); |
67 | session()->sendMessage(m_channel, m_field->text()); | 79 | session()->sendMessage(m_channel, m_field->text()); |
68 | appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">> "+IRCOutput::toHTML(m_field->text())+"</font><br>"); | 80 | appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">> "+IRCOutput::toHTML(m_field->text())+"</font><br>"); |
69 | } | 81 | } |
70 | } else { | 82 | } else { |
71 | appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>"); | 83 | appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>"); |
72 | } | 84 | } |
73 | } | 85 | } |
74 | m_field->clear(); | 86 | m_field->clear(); |
75 | } | 87 | } |
76 | 88 | ||
77 | void IRCChannelTab::settingsChanged() { | 89 | void IRCChannelTab::settingsChanged() { |
78 | m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); | 90 | m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); |
91 | m_lines = 0; | ||
79 | } | 92 | } |
80 | 93 | ||
81 | void IRCChannelTab::toggleList() { | 94 | void IRCChannelTab::toggleList() { |
82 | if (m_listVisible) { | 95 | if (m_listVisible) { |
83 | m_list->setMaximumWidth(0); | 96 | m_list->setMaximumWidth(0); |
84 | m_listButton->setText("<"); | 97 | m_listButton->setText("<"); |
85 | } else { | 98 | } else { |
86 | m_list->setMaximumWidth(LISTWIDTH); | 99 | m_list->setMaximumWidth(LISTWIDTH); |
87 | m_listButton->setText(">"); | 100 | m_listButton->setText(">"); |
88 | } | 101 | } |
89 | m_listVisible = !m_listVisible; | 102 | m_listVisible = !m_listVisible; |
90 | } | 103 | } |
91 | 104 | ||
92 | void IRCChannelTab::mouseButtonPressed(int mouse, QListBoxItem *, const QPoint &point) { | 105 | void IRCChannelTab::mouseButtonPressed(int mouse, QListBoxItem *, const QPoint &point) { |
93 | switch (mouse) { | 106 | switch (mouse) { |
94 | case 1: | 107 | case 1: |
95 | break; | 108 | break; |
96 | case 2: | 109 | case 2: |
97 | m_popup->popup(point); | 110 | m_popup->popup(point); |
98 | break; | 111 | break; |
99 | }; | 112 | }; |
100 | } | 113 | } |
101 | 114 | ||
102 | void IRCChannelTab::popupQuery() { | 115 | void IRCChannelTab::popupQuery() { |