Fixed online user presence in chat window

This commit is contained in:
Stojce Slavkovski 2014-04-28 23:49:59 +02:00
parent 0073db4abd
commit 963ad64d07
4 changed files with 17 additions and 7 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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);

View file

@ -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();
}