mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
commit
10e6f81958
9 changed files with 78 additions and 9 deletions
BIN
interface/resources/sounds/mention/Mentioned A.wav
Normal file
BIN
interface/resources/sounds/mention/Mentioned A.wav
Normal file
Binary file not shown.
BIN
interface/resources/sounds/mention/Mentioned B.wav
Normal file
BIN
interface/resources/sounds/mention/Mentioned B.wav
Normal file
Binary file not shown.
BIN
interface/resources/sounds/mention/Mentioned C.wav
Normal file
BIN
interface/resources/sounds/mention/Mentioned C.wav
Normal file
Binary file not shown.
|
@ -215,6 +215,10 @@ Menu::Menu() :
|
||||||
toggleChat();
|
toggleChat();
|
||||||
connect(&xmppClient, SIGNAL(connected()), this, SLOT(toggleChat()));
|
connect(&xmppClient, SIGNAL(connected()), this, SLOT(toggleChat()));
|
||||||
connect(&xmppClient, SIGNAL(disconnected()), 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
|
#endif
|
||||||
|
|
||||||
QMenu* viewMenu = addMenu("View");
|
QMenu* viewMenu = addMenu("View");
|
||||||
|
|
|
@ -36,6 +36,7 @@ void XmppClient::xmppConnected() {
|
||||||
_publicChatRoom = _xmppMUCManager.addRoom(DEFAULT_CHAT_ROOM);
|
_publicChatRoom = _xmppMUCManager.addRoom(DEFAULT_CHAT_ROOM);
|
||||||
_publicChatRoom->setNickName(AccountManager::getInstance().getAccountInfo().getUsername());
|
_publicChatRoom->setNickName(AccountManager::getInstance().getAccountInfo().getUsername());
|
||||||
_publicChatRoom->join();
|
_publicChatRoom->join();
|
||||||
|
emit joinedPublicChatRoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmppClient::xmppError(QXmppClient::Error error) {
|
void XmppClient::xmppError(QXmppClient::Error error) {
|
||||||
|
|
|
@ -28,6 +28,9 @@ public:
|
||||||
QXmppClient& getXMPPClient() { return _xmppClient; }
|
QXmppClient& getXMPPClient() { return _xmppClient; }
|
||||||
const QXmppMucRoom* getPublicChatRoom() const { return _publicChatRoom; }
|
const QXmppMucRoom* getPublicChatRoom() const { return _publicChatRoom; }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void joinedPublicChatRoom();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void xmppConnected();
|
void xmppConnected();
|
||||||
void xmppError(QXmppClient::Error error);
|
void xmppError(QXmppClient::Error error);
|
||||||
|
|
|
@ -26,17 +26,23 @@
|
||||||
|
|
||||||
#include "ChatWindow.h"
|
#include "ChatWindow.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const int NUM_MESSAGES_TO_TIME_STAMP = 20;
|
const int NUM_MESSAGES_TO_TIME_STAMP = 20;
|
||||||
|
|
||||||
const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)");
|
const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)");
|
||||||
const QRegularExpression regexHifiLinks("([#@]\\S+)");
|
const QRegularExpression regexHifiLinks("([#@]\\S+)");
|
||||||
|
const QString mentionSoundsPath("/sounds/mention/");
|
||||||
|
const QString mentionRegex("@(\\b%1\\b)");
|
||||||
|
|
||||||
ChatWindow::ChatWindow(QWidget* parent) :
|
ChatWindow::ChatWindow(QWidget* parent) :
|
||||||
FramelessDialog(parent, 0, POSITION_RIGHT),
|
FramelessDialog(parent, 0, POSITION_RIGHT),
|
||||||
ui(new Ui::ChatWindow),
|
ui(new Ui::ChatWindow),
|
||||||
numMessagesAfterLastTimeStamp(0),
|
numMessagesAfterLastTimeStamp(0),
|
||||||
_mousePressed(false),
|
_mousePressed(false),
|
||||||
_mouseStartPosition()
|
_mouseStartPosition(),
|
||||||
|
_trayIcon(parent),
|
||||||
|
_effectPlayer()
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DeleteOnClose, false);
|
setAttribute(Qt::WA_DeleteOnClose, false);
|
||||||
|
|
||||||
|
@ -77,16 +83,47 @@ ChatWindow::ChatWindow(QWidget* parent) :
|
||||||
ui->usersWidget->hide();
|
ui->usersWidget->hide();
|
||||||
ui->messagesScrollArea->hide();
|
ui->messagesScrollArea->hide();
|
||||||
ui->messagePlainTextEdit->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(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
|
||||||
|
connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QDir mentionSoundsDir(Application::resourcesPath() + mentionSoundsPath);
|
||||||
|
_mentionSounds = mentionSoundsDir.entryList(QDir::Files);
|
||||||
|
_trayIcon.setIcon(QIcon( Application::resourcesPath() + "/images/hifi-logo.svg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatWindow::notificationClicked() {
|
||||||
|
if (parentWidget()->isMinimized()) {
|
||||||
|
parentWidget()->showNormal();
|
||||||
|
}
|
||||||
|
if (isHidden()) {
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// find last mention
|
||||||
|
int messageCount = ui->messagesVBoxLayout->count();
|
||||||
|
for (unsigned int i = messageCount; i > 0; i--) {
|
||||||
|
ChatMessageArea* area = (ChatMessageArea*)ui->messagesVBoxLayout->itemAt(i - 1)->widget();
|
||||||
|
QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
|
||||||
|
if (area->toPlainText().contains(usernameMention)) {
|
||||||
|
int top = area->geometry().top();
|
||||||
|
int height = area->geometry().height();
|
||||||
|
|
||||||
|
QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
|
||||||
|
verticalScrollBar->setSliderPosition(top - verticalScrollBar->size().height() + height);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatWindow::~ChatWindow() {
|
ChatWindow::~ChatWindow() {
|
||||||
#ifdef HAVE_QXMPP
|
#ifdef HAVE_QXMPP
|
||||||
const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient();
|
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)));
|
disconnect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
|
||||||
|
|
||||||
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
|
||||||
|
@ -105,9 +142,15 @@ void ChatWindow::keyPressEvent(QKeyEvent* event) {
|
||||||
|
|
||||||
void ChatWindow::showEvent(QShowEvent* event) {
|
void ChatWindow::showEvent(QShowEvent* event) {
|
||||||
FramelessDialog::showEvent(event);
|
FramelessDialog::showEvent(event);
|
||||||
|
|
||||||
if (!event->spontaneous()) {
|
if (!event->spontaneous()) {
|
||||||
ui->messagePlainTextEdit->setFocus();
|
ui->messagePlainTextEdit->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient();
|
||||||
|
if (xmppClient.isConnected()) {
|
||||||
|
participantsChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
|
bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
|
||||||
|
@ -304,6 +347,21 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
|
||||||
} else {
|
} else {
|
||||||
lastMessageStamp = QDateTime::currentDateTime();
|
lastMessageStamp = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
|
||||||
|
if (isHidden() && message.body().contains(usernameMention)) {
|
||||||
|
if (_effectPlayer.state() != QMediaPlayer::PlayingState) {
|
||||||
|
// get random sound
|
||||||
|
QFileInfo inf = QFileInfo(Application::resourcesPath() +
|
||||||
|
mentionSoundsPath +
|
||||||
|
_mentionSounds.at(rand() % _mentionSounds.size()));
|
||||||
|
_effectPlayer.setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
|
||||||
|
_effectPlayer.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
_trayIcon.show();
|
||||||
|
_trayIcon.showMessage(windowTitle(), message.body());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
#include <QMediaPlayer>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
@ -63,6 +65,9 @@ private:
|
||||||
QDateTime lastMessageStamp;
|
QDateTime lastMessageStamp;
|
||||||
bool _mousePressed;
|
bool _mousePressed;
|
||||||
QPoint _mouseStartPosition;
|
QPoint _mouseStartPosition;
|
||||||
|
QSystemTrayIcon _trayIcon;
|
||||||
|
QStringList _mentionSounds;
|
||||||
|
QMediaPlayer _effectPlayer;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void connected();
|
void connected();
|
||||||
|
@ -71,6 +76,7 @@ private slots:
|
||||||
void error(QXmppClient::Error error);
|
void error(QXmppClient::Error error);
|
||||||
void participantsChanged();
|
void participantsChanged();
|
||||||
void messageReceived(const QXmppMessage& message);
|
void messageReceived(const QXmppMessage& message);
|
||||||
|
void notificationClicked();
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -198,9 +198,6 @@ color: #0e7077</string>
|
||||||
<property name="indent">
|
<property name="indent">
|
||||||
<number>25</number>
|
<number>25</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
|
||||||
<cstring></cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -510,7 +507,7 @@ color: #0e7077</string>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="headLabel">
|
<widget class="QLabel" name="headLabel_3">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
@ -547,7 +544,7 @@ color: #0e7077</string>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout_1">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="snapshotLocationEdit">
|
<widget class="QLineEdit" name="snapshotLocationEdit">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -564,7 +561,7 @@ color: #0e7077</string>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer_1">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in a new issue