Diffstat (limited to 'noncore/net/opieirc/ircchanneltab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp index b6e3954..7610058 100644 --- a/noncore/net/opieirc/ircchanneltab.cpp +++ b/noncore/net/opieirc/ircchanneltab.cpp | |||
@@ -1,99 +1,102 @@ | |||
1 | #include <qpe/resource.h> | 1 | #include <qpe/resource.h> |
2 | #include <qwhatsthis.h> | 2 | #include <qwhatsthis.h> |
3 | #include <qhbox.h> | 3 | #include <qhbox.h> |
4 | #include "ircchanneltab.h" | 4 | #include "ircchanneltab.h" |
5 | #include "ircservertab.h" | 5 | #include "ircservertab.h" |
6 | 6 | ||
7 | IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | 7 | IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { |
8 | m_mainWindow = mainWindow; | 8 | m_mainWindow = mainWindow; |
9 | m_parentTab = parentTab; | 9 | m_parentTab = parentTab; |
10 | m_channel = channel; | 10 | m_channel = channel; |
11 | m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); | 11 | m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); |
12 | QHBox *hbox = new QHBox(this); | 12 | QHBox *hbox = new QHBox(this); |
13 | m_textview = new QTextView(hbox); | 13 | m_textview = new QTextView(hbox); |
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_listVisible = TRUE; | 16 | m_listVisible = TRUE; |
17 | m_listButton = new QPushButton(">", m_textview); | 17 | m_listButton = new QPushButton(">", m_textview); |
18 | m_listButton->setFlat( true ); | ||
18 | m_textview->setCornerWidget(m_listButton); | 19 | m_textview->setCornerWidget(m_listButton); |
19 | m_textview->setTextFormat(RichText); | 20 | m_textview->setTextFormat(RichText); |
20 | QWhatsThis::add(m_textview, tr("Channel discussion")); | 21 | QWhatsThis::add(m_textview, tr("Channel discussion")); |
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 IRCHistoryLineEdit(this); | 26 | m_field = new IRCHistoryLineEdit(this); |
26 | connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); | 27 | connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); |
27 | connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); | 28 | connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); |
28 | connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab())); | 29 | connect(m_field, SIGNAL(closeTab()), this, SLOT(remove())); |
29 | connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); | 30 | connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); |
30 | 31 | ||
31 | QWhatsThis::add(m_field, tr("Type your message here to participate in the channel discussion")); | 32 | QWhatsThis::add(m_field, tr("Type your message here to participate in the channel discussion")); |
32 | m_popup = new QPopupMenu(m_list); | 33 | m_popup = new QPopupMenu(m_list); |
33 | m_lines = 0; | 34 | m_lines = 0; |
34 | /* Required so that embedded-style "right" clicks work */ | 35 | /* Required so that embedded-style "right" clicks work */ |
35 | QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold); | 36 | QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold); |
36 | connect(m_list, SIGNAL(mouseButtonPressed(int,QListBoxItem*,const QPoint&)), this, SLOT(mouseButtonPressed(int,QListBoxItem*,const QPoint&))); | 37 | connect(m_list, SIGNAL(mouseButtonPressed(int,QListBoxItem*,const QPoint&)), this, SLOT(mouseButtonPressed(int,QListBoxItem*,const QPoint&))); |
37 | /* Construct the popup menu */ | 38 | /* Construct the popup menu */ |
38 | QPopupMenu *ctcpMenu = new QPopupMenu(m_list); | 39 | QPopupMenu *ctcpMenu = new QPopupMenu(m_list); |
39 | m_popup->insertItem(Resource::loadPixmap("opieirc/ctcp"), tr("CTCP"), ctcpMenu); | ||
40 | m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery())); | 40 | m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery())); |
41 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing())); | 41 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing())); |
42 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion())); | 42 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion())); |
43 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois())); | 43 | ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois())); |
44 | connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); | 44 | connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); |
45 | m_layout->add(hbox); | 45 | m_layout->add(hbox); |
46 | hbox->show(); | 46 | hbox->show(); |
47 | m_layout->add(m_field); | 47 | m_layout->add(m_field); |
48 | m_field->setFocus(); | 48 | m_field->setFocus(); |
49 | m_field->setActiveWindow(); | 49 | m_field->setActiveWindow(); |
50 | 50 | ||
51 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 51 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
52 | connect(m_list, SIGNAL(doubleClicked ( QListBoxItem * ) ), this, SLOT(popupQuery( QListBoxItem * ) )); | ||
52 | settingsChanged(); | 53 | settingsChanged(); |
53 | } | 54 | } |
54 | 55 | ||
55 | void IRCChannelTab::scrolling(){ | 56 | void IRCChannelTab::scrolling(){ |
56 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 57 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
57 | } | 58 | } |
58 | 59 | ||
59 | void IRCChannelTab::appendText(QString text) { | 60 | void IRCChannelTab::appendText(QString text) { |
60 | /* not using append because it creates layout problems */ | 61 | /* not using append because it creates layout problems */ |
61 | QString txt = m_textview->text() + text + "\n"; | 62 | QString txt = m_textview->text() + IRCTab::appendTimestamp( text ); |
62 | if (m_maxLines > 0 && m_lines >= m_maxLines) { | 63 | if (m_maxLines > 0 && m_lines >= m_maxLines) { |
63 | int firstBreak = txt.find('\n'); | 64 | int firstBreak = txt.find('\n'); |
64 | if (firstBreak != -1) { | 65 | if (firstBreak != -1) { |
65 | txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); | 66 | txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); |
66 | } | 67 | } |
67 | } else { | 68 | } else { |
68 | m_lines++; | 69 | m_lines++; |
69 | } | 70 | } |
70 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 71 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
71 | m_textview->setText(txt); | 72 | m_textview->setText(txt); |
72 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 73 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
73 | 74 | ||
74 | int p1, p2; | 75 | int p1, p2; |
75 | if ( (p1 = text.find("ping", 0, false) )!= -1 && (p2 = text.find( m_parentTab->server()->nick(), 0,false )) != -1 ) { | 76 | if ( text.contains( IRCMessageParser::tr("Received a CTCP PING from ") ) ) |
77 | emit ping( title() ); | ||
78 | else if ( (p1 = text.find("ping", 0, false) )!= -1 && (p2 = text.find( m_parentTab->server()->nick(), 0,false )) != -1 ) { | ||
76 | int col = text.findRev("color", -1, false); | 79 | int col = text.findRev("color", -1, false); |
77 | if ( col < p2 ) | 80 | if ( col < p2 ) |
78 | emit ping( title() ); | 81 | emit ping( title() ); |
79 | 82 | ||
80 | } | 83 | } |
81 | 84 | ||
82 | emit changed(this); | 85 | emit changed(this); |
83 | } | 86 | } |
84 | 87 | ||
85 | IRCChannelTab::~IRCChannelTab() { | 88 | IRCChannelTab::~IRCChannelTab() { |
86 | m_parentTab->removeChannelTab(this); | 89 | m_parentTab->removeChannelTab(this); |
87 | } | 90 | } |
88 | 91 | ||
89 | void IRCChannelTab::processCommand() { | 92 | void IRCChannelTab::processCommand() { |
90 | QString text = m_field->text(); | 93 | QString text = m_field->text(); |
91 | if (text.length()>0) { | 94 | if (text.length()>0) { |
92 | if (session()->isSessionActive()) { | 95 | if (session()->isSessionActive()) { |
93 | if (text.startsWith("/") && !text.startsWith("//")) { | 96 | if (text.startsWith("/") && !text.startsWith("//")) { |
94 | /* Command mode */ | 97 | /* Command mode */ |
95 | m_parentTab->executeCommand(this, text);; | 98 | m_parentTab->executeCommand(this, text);; |
96 | } else { | 99 | } else { |
97 | if (text.startsWith("//")) | 100 | if (text.startsWith("//")) |
98 | text = text.right(text.length()-1); | 101 | text = text.right(text.length()-1); |
99 | session()->sendMessage(m_channel, m_field->text()); | 102 | session()->sendMessage(m_channel, m_field->text()); |
@@ -111,62 +114,67 @@ void IRCChannelTab::settingsChanged() { | |||
111 | m_lines = 0; | 114 | m_lines = 0; |
112 | } | 115 | } |
113 | 116 | ||
114 | void IRCChannelTab::toggleList() { | 117 | void IRCChannelTab::toggleList() { |
115 | if (m_listVisible) { | 118 | if (m_listVisible) { |
116 | m_list->setMaximumWidth(0); | 119 | m_list->setMaximumWidth(0); |
117 | m_listButton->setText("<"); | 120 | m_listButton->setText("<"); |
118 | } else { | 121 | } else { |
119 | m_list->setMaximumWidth(LISTWIDTH); | 122 | m_list->setMaximumWidth(LISTWIDTH); |
120 | m_listButton->setText(">"); | 123 | m_listButton->setText(">"); |
121 | } | 124 | } |
122 | m_listVisible = !m_listVisible; | 125 | m_listVisible = !m_listVisible; |
123 | } | 126 | } |
124 | 127 | ||
125 | void IRCChannelTab::mouseButtonPressed(int mouse, QListBoxItem *, const QPoint &point) { | 128 | void IRCChannelTab::mouseButtonPressed(int mouse, QListBoxItem *, const QPoint &point) { |
126 | switch (mouse) { | 129 | switch (mouse) { |
127 | case 1: | 130 | case 1: |
128 | break; | 131 | break; |
129 | case 2: | 132 | case 2: |
130 | m_popup->popup(point); | 133 | m_popup->popup(point); |
131 | break; | 134 | break; |
132 | }; | 135 | }; |
133 | } | 136 | } |
134 | 137 | ||
135 | void IRCChannelTab::popupQuery() { | 138 | void IRCChannelTab::popupQuery( QListBoxItem *item) { |
136 | if (m_list->currentItem() != -1) { | 139 | if (item) { |
137 | IRCPerson *person = session()->getPerson(m_list->item(m_list->currentItem())->text()); | 140 | IRCPerson *person = session()->getPerson(item->text()); |
138 | if (person) { | 141 | if (person) { |
139 | IRCQueryTab *tab = m_parentTab->getTabForQuery(person); | 142 | IRCQueryTab *tab = m_parentTab->getTabForQuery(person); |
140 | if (!tab) { | 143 | if (!tab) { |
141 | tab = new IRCQueryTab(person, m_parentTab, m_mainWindow, (QWidget *)parent()); | 144 | tab = new IRCQueryTab(person, m_parentTab, m_mainWindow, (QWidget *)parent()); |
142 | m_parentTab->addQueryTab(tab); | 145 | m_parentTab->addQueryTab(tab); |
143 | m_mainWindow->addTab(tab); | 146 | m_mainWindow->addTab(tab); |
144 | } | 147 | } |
145 | } | 148 | } |
146 | } | 149 | } |
147 | } | 150 | } |
148 | 151 | ||
152 | void IRCChannelTab::popupQuery() { | ||
153 | if ( m_list->currentItem() != -1 ) | ||
154 | popupQuery( m_list->item(m_list->currentItem())); | ||
155 | } | ||
156 | |||
149 | void IRCChannelTab::popupPing() { | 157 | void IRCChannelTab::popupPing() { |
150 | //HAHA, no wonder these don't work | 158 | //HAHA, no wonder these don't work |
151 | } | 159 | } |
152 | 160 | ||
153 | void IRCChannelTab::popupVersion() { | 161 | void IRCChannelTab::popupVersion() { |
154 | } | 162 | } |
155 | 163 | ||
156 | void IRCChannelTab::popupWhois() { | 164 | void IRCChannelTab::popupWhois() { |
157 | } | 165 | } |
158 | 166 | ||
159 | QString IRCChannelTab::title() { | 167 | QString IRCChannelTab::title() { |
160 | return m_channel->channelname(); | 168 | return m_channel->channelname(); |
161 | } | 169 | } |
162 | 170 | ||
163 | IRCSession *IRCChannelTab::session() { | 171 | IRCSession *IRCChannelTab::session() { |
164 | return m_parentTab->session(); | 172 | return m_parentTab->session(); |
165 | } | 173 | } |
166 | 174 | ||
167 | void IRCChannelTab::remove() { | 175 | void IRCChannelTab::remove() { |
168 | if (session()->isSessionActive()) { | 176 | if (session()->isSessionActive()) { |
169 | session()->part(m_channel); | 177 | session()->part(m_channel); |
170 | } else { | 178 | } else { |
171 | m_mainWindow->killTab(this); | 179 | m_mainWindow->killTab(this); |
172 | } | 180 | } |