From 963ad64d07aef86a30df26b5be76b2b8265ac941 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Mon, 28 Apr 2014 23:49:59 +0200 Subject: [PATCH] Fixed online user presence in chat window --- interface/src/Menu.cpp | 1 + interface/src/XmppClient.cpp | 1 + interface/src/XmppClient.h | 3 +++ interface/src/ui/ChatWindow.cpp | 19 ++++++++++++------- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index c2c0e9522f..77435cdf00 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -210,6 +210,7 @@ Menu::Menu() : connect(&xmppClient, SIGNAL(connected()), this, SLOT(toggleChat())); connect(&xmppClient, SIGNAL(disconnected()), this, SLOT(toggleChat())); + QDir::setCurrent(Application::resourcesPath()); // init chat window to listen chat _chatWindow = new ChatWindow(Application::getInstance()->getWindow()); #endif diff --git a/interface/src/XmppClient.cpp b/interface/src/XmppClient.cpp index 00abfeb703..7367993a3c 100644 --- a/interface/src/XmppClient.cpp +++ b/interface/src/XmppClient.cpp @@ -36,6 +36,7 @@ void XmppClient::xmppConnected() { _publicChatRoom = _xmppMUCManager.addRoom(DEFAULT_CHAT_ROOM); _publicChatRoom->setNickName(AccountManager::getInstance().getUsername()); _publicChatRoom->join(); + emit joinedPublicChatRoom(); } void XmppClient::xmppError(QXmppClient::Error error) { diff --git a/interface/src/XmppClient.h b/interface/src/XmppClient.h index 8af3204377..cbb06cf992 100644 --- a/interface/src/XmppClient.h +++ b/interface/src/XmppClient.h @@ -28,6 +28,9 @@ public: QXmppClient& getXMPPClient() { return _xmppClient; } const QXmppMucRoom* getPublicChatRoom() const { return _publicChatRoom; } +signals: + void joinedPublicChatRoom(); + private slots: void xmppConnected(); void xmppError(QXmppClient::Error error); diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index f7a27570bb..0300ec9202 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -32,6 +32,7 @@ const int NUM_MESSAGES_TO_TIME_STAMP = 20; const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)"); const QRegularExpression regexHifiLinks("([#@]\\S+)"); +const QString mentionSoundsPath("/sounds/mention/"); ChatWindow::ChatWindow(QWidget* parent) : FramelessDialog(parent, 0, POSITION_RIGHT), @@ -81,13 +82,13 @@ ChatWindow::ChatWindow(QWidget* parent) : ui->usersWidget->hide(); ui->messagesScrollArea->hide(); ui->messagePlainTextEdit->hide(); - connect(&xmppClient, SIGNAL(connected()), this, SLOT(connected())); + connect(&XmppClient::getInstance(), SIGNAL(joinedPublicChatRoom()), this, SLOT(connected())); } connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage))); connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked())); #endif - QDir mentionSoundsDir(Application::resourcesPath() + "/sounds/mention/"); + QDir mentionSoundsDir(Application::resourcesPath() + mentionSoundsPath); _mentionSounds = mentionSoundsDir.entryList(QDir::Files); } @@ -104,7 +105,7 @@ void ChatWindow::notificationClicked() { ChatWindow::~ChatWindow() { #ifdef HAVE_QXMPP const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); - disconnect(&xmppClient, SIGNAL(connected()), this, SLOT(connected())); + disconnect(&xmppClient, SIGNAL(joinedPublicChatRoom()), this, SLOT(connected())); disconnect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage))); const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); @@ -126,6 +127,11 @@ void ChatWindow::showEvent(QShowEvent* event) { if (!event->spontaneous()) { ui->messagePlainTextEdit->setFocus(); } + + const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); + if (xmppClient.isConnected()) { + participantsChanged(); + } } bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { @@ -221,7 +227,6 @@ void ChatWindow::connected() { #ifdef HAVE_QXMPP const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged())); - #endif startTimerForTimeStamps(); } @@ -325,12 +330,12 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { } QRegularExpression usernameMention("@(\\b" + AccountManager::getInstance().getUsername() + "\\b)"); - qDebug() << "message: " << message.body(); - if (isHidden() && message.body().contains(usernameMention)) { if (_effectPlayer.state() != QMediaPlayer::PlayingState) { // get random sound - QFileInfo inf = QFileInfo(Application::resourcesPath() + "/sounds/mention/" + _mentionSounds.at(rand() % _mentionSounds.size())); + QFileInfo inf = QFileInfo(Application::resourcesPath() + + mentionSoundsPath + + _mentionSounds.at(rand() % _mentionSounds.size())); _effectPlayer.setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); _effectPlayer.play(); }