Showing the changes to interface/src/ui/ChatWindow.cpp (1 of 1 file). Show all
Unified · Split
| @@ -87,39 +87,13 @@ ChatWindow::ChatWindow(QWidget* parent) : · 86 unmodified lines | ||
| 87 | 87 | } |
| 88 | 88 | connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage))); |
| 89 | 89 | connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked())); |
| 90 | −#endif | |
| 90 | +#endif // HAVE_QXMPP | |
| 91 | 91 | |
| 92 | 92 | QDir mentionSoundsDir(Application::resourcesPath() + mentionSoundsPath); |
| 93 | 93 | _mentionSounds = mentionSoundsDir.entryList(QDir::Files); |
| 94 | 94 | _trayIcon.setIcon(QIcon( Application::resourcesPath() + "/images/hifi-logo.svg")); |
| 95 | 95 | } |
| 96 | 96 | |
| 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 | − | |
| 123 | 97 | ChatWindow::~ChatWindow() { |
| 124 | 98 | #ifdef HAVE_QXMPP |
| 125 | 99 | const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); |
| @@ -128,7 +102,7 @@ ChatWindow::~ChatWindow() { · 2 unmodified lines | ||
| 128 | 102 | |
| 129 | 103 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); |
| 130 | 104 | disconnect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged())); |
| 131 | −#endif | |
| 105 | +#endif // HAVE_QXMPP | |
| 132 | 106 | delete ui; |
| 133 | 107 | } |
| 134 | 108 | |
| @@ -147,10 +121,12 @@ void ChatWindow::showEvent(QShowEvent* event) { · 12 unmodified lines | ||
| 147 | 121 | ui->messagePlainTextEdit->setFocus(); |
| 148 | 122 | } |
| 149 | 123 | |
| 124 | +#ifdef HAVE_QXMPP | |
| 150 | 125 | const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); |
| 151 | 126 | if (xmppClient.isConnected()) { |
| 152 | 127 | participantsChanged(); |
| 153 | 128 | } |
| 129 | +#endif // HAVE_QXMPP | |
| 154 | 130 | } |
| 155 | 131 | |
| 156 | 132 | bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { |
| @@ -163,14 +139,14 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 6 unmodified lines | ||
| 163 | 139 | (keyEvent->modifiers() & Qt::ShiftModifier) == 0) { |
| 164 | 140 | QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed(); |
| 165 | 141 | if (!messageText.isEmpty()) { |
| 166 | − #ifdef HAVE_QXMPP | |
| 142 | +#ifdef HAVE_QXMPP | |
| 167 | 143 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); |
| 168 | 144 | QXmppMessage message; |
| 169 | 145 | message.setTo(publicChatRoom->jid()); |
| 170 | 146 | message.setType(QXmppMessage::GroupChat); |
| 171 | 147 | message.setBody(messageText); |
| 172 | 148 | XmppClient::getInstance().getXMPPClient().sendPacket(message); |
| 173 | − #endif | |
| 149 | +#endif // HAVE_QXMPP | |
| 174 | 150 | QTextCursor cursor = ui->messagePlainTextEdit->textCursor(); |
| 175 | 151 | cursor.select(QTextCursor::Document); |
| 176 | 152 | cursor.removeSelectedText(); |
| @@ -187,13 +163,6 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 10 unmodified lines | ||
| 187 | 163 | return FramelessDialog::eventFilter(sender, event); |
| 188 | 164 | } |
| 189 | 165 | |
| 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 | − | |
| 197 | 166 | void ChatWindow::addTimeStamp() { |
| 198 | 167 | QTimeSpan timePassed = QDateTime::currentDateTime() - lastMessageStamp; |
| 199 | 168 | int times[] = { timePassed.daysPart(), timePassed.hoursPart(), timePassed.minutesPart() }; |
| @@ -246,7 +215,7 @@ void ChatWindow::connected() { · 46 unmodified lines | ||
| 246 | 215 | #ifdef HAVE_QXMPP |
| 247 | 216 | const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); |
| 248 | 217 | connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged())); |
| 249 | −#endif | |
| 218 | +#endif // HAVE_QXMPP | |
| 250 | 219 | startTimerForTimeStamps(); |
| 251 | 220 | } |
| 252 | 221 | |
| @@ -257,6 +226,36 @@ void ChatWindow::timeout() { · 4 unmodified lines | ||
| 257 | 226 | } |
| 258 | 227 | |
| 259 | 228 | #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 | +} | |
| 260 | 259 | |
| 261 | 260 | void ChatWindow::error(QXmppClient::Error error) { |
| 262 | 261 | ui->connectingToXMPPLabel->setText(QString::number(error)); |
| @@ -363,8 +362,7 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 100 unmodified lines | ||
| 363 | 362 | _trayIcon.showMessage(windowTitle(), message.body()); |
| 364 | 363 | } |
| 365 | 364 | } |
| 366 | − | |
| 367 | −#endif | |
| 365 | +#endif // HAVE_QXMPP | |
| 368 | 366 | |
| 369 | 367 | bool ChatWindow::isNearBottom() { |
| 370 | 368 | QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar(); |