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