History

properly wrap XMPP stuff with "#ifdef HAVE_XMPP"

Andrew Meadows committed 12 years ago

Commit 2ea10421 parent 7a191961 file · +38 −40Browse files

Showing the changes to interface/src/ui/ChatWindow.cpp (1 of 1 file). Show all

Unified · Split

interface/src/ui/ChatWindow.cpp+38−40
@@ -87,39 +87,13 @@ ChatWindow::ChatWindow(QWidget* parent) : · 86 unmodified lines
8787 }
8888 connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
8989 connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
90−#endif
90+#endif // HAVE_QXMPP
9191
9292 QDir mentionSoundsDir(Application::resourcesPath() + mentionSoundsPath);
9393 _mentionSounds = mentionSoundsDir.entryList(QDir::Files);
9494 _trayIcon.setIcon(QIcon( Application::resourcesPath() + "/images/hifi-logo.svg"));
9595 }
9696
97−void ChatWindow::notificationClicked() {
98− if (parentWidget()->isMinimized()) {
99− parentWidget()->showNormal();
100− }
101− if (isHidden()) {
102− show();
103− }
104−
105− // find last mention
106− int messageCount = ui->messagesVBoxLayout->count();
107− for (unsigned int i = messageCount; i > 0; i--) {
108− ChatMessageArea* area = (ChatMessageArea*)ui->messagesVBoxLayout->itemAt(i - 1)->widget();
109− QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
110− if (area->toPlainText().contains(usernameMention)) {
111− int top = area->geometry().top();
112− int height = area->geometry().height();
113−
114− QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
115− verticalScrollBar->setSliderPosition(top - verticalScrollBar->size().height() + height);
116− return;
117− }
118− }
119−
120− scrollToBottom();
121−}
122−
12397 ChatWindow::~ChatWindow() {
12498 #ifdef HAVE_QXMPP
12599 const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient();
@@ -128,7 +102,7 @@ ChatWindow::~ChatWindow() { · 2 unmodified lines
128102
129103 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
130104 disconnect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
131−#endif
105+#endif // HAVE_QXMPP
132106 delete ui;
133107 }
134108
@@ -147,10 +121,12 @@ void ChatWindow::showEvent(QShowEvent* event) { · 12 unmodified lines
147121 ui->messagePlainTextEdit->setFocus();
148122 }
149123
124+#ifdef HAVE_QXMPP
150125 const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient();
151126 if (xmppClient.isConnected()) {
152127 participantsChanged();
153128 }
129+#endif // HAVE_QXMPP
154130 }
155131
156132 bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
@@ -163,14 +139,14 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 6 unmodified lines
163139 (keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
164140 QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();
165141 if (!messageText.isEmpty()) {
166− #ifdef HAVE_QXMPP
142+#ifdef HAVE_QXMPP
167143 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
168144 QXmppMessage message;
169145 message.setTo(publicChatRoom->jid());
170146 message.setType(QXmppMessage::GroupChat);
171147 message.setBody(messageText);
172148 XmppClient::getInstance().getXMPPClient().sendPacket(message);
173− #endif
149+#endif // HAVE_QXMPP
174150 QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
175151 cursor.select(QTextCursor::Document);
176152 cursor.removeSelectedText();
@@ -187,13 +163,6 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 10 unmodified lines
187163 return FramelessDialog::eventFilter(sender, event);
188164 }
189165
190−#ifdef HAVE_QXMPP
191−QString ChatWindow::getParticipantName(const QString& participant) {
192− const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
193− return participant.right(participant.count() - 1 - publicChatRoom->jid().count());
194−}
195−#endif
196−
197166 void ChatWindow::addTimeStamp() {
198167 QTimeSpan timePassed = QDateTime::currentDateTime() - lastMessageStamp;
199168 int times[] = { timePassed.daysPart(), timePassed.hoursPart(), timePassed.minutesPart() };
@@ -246,7 +215,7 @@ void ChatWindow::connected() { · 46 unmodified lines
246215 #ifdef HAVE_QXMPP
247216 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
248217 connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
249−#endif
218+#endif // HAVE_QXMPP
250219 startTimerForTimeStamps();
251220 }
252221
@@ -257,6 +226,36 @@ void ChatWindow::timeout() { · 4 unmodified lines
257226 }
258227
259228 #ifdef HAVE_QXMPP
229+void ChatWindow::notificationClicked() {
230+ if (parentWidget()->isMinimized()) {
231+ parentWidget()->showNormal();
232+ }
233+ if (isHidden()) {
234+ show();
235+ }
236+
237+ // find last mention
238+ int messageCount = ui->messagesVBoxLayout->count();
239+ for (unsigned int i = messageCount; i > 0; i--) {
240+ ChatMessageArea* area = (ChatMessageArea*)ui->messagesVBoxLayout->itemAt(i - 1)->widget();
241+ QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
242+ if (area->toPlainText().contains(usernameMention)) {
243+ int top = area->geometry().top();
244+ int height = area->geometry().height();
245+
246+ QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
247+ verticalScrollBar->setSliderPosition(top - verticalScrollBar->size().height() + height);
248+ return;
249+ }
250+ }
251+
252+ scrollToBottom();
253+}
254+
255+QString ChatWindow::getParticipantName(const QString& participant) {
256+ const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
257+ return participant.right(participant.count() - 1 - publicChatRoom->jid().count());
258+}
260259
261260 void ChatWindow::error(QXmppClient::Error error) {
262261 ui->connectingToXMPPLabel->setText(QString::number(error));
@@ -363,8 +362,7 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 100 unmodified lines
363362 _trayIcon.showMessage(windowTitle(), message.body());
364363 }
365364 }
366−
367−#endif
365+#endif // HAVE_QXMPP
368366
369367 bool ChatWindow::isNearBottom() {
370368 QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();