1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Separate setting to show window on new message (without focusing window)

Setting to always notify on messages in group chats (like normal chats)
Check for mentioned name only triggers if name is not in the middle of other word
This commit is contained in:
novist 2015-01-21 13:10:41 +02:00
parent eade2969fe
commit 3bec2751e0
7 changed files with 109 additions and 42 deletions

View File

@ -136,7 +136,9 @@ void Settings::load()
currentProfile = s.value("currentProfile", "").toString();
autoAwayTime = s.value("autoAwayTime", 10).toInt();
checkUpdates = s.value("checkUpdates", false).toBool();
showWindow = s.value("showWindow", true).toBool();
showInFront = s.value("showInFront", false).toBool();
groupAlwaysNotify = s.value("groupAlwaysNotify", false).toBool();
fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool();
autoSaveEnabled = s.value("autoSaveEnabled", false).toBool();
globalAutoAcceptDir = s.value("globalAutoAcceptDir",
@ -290,7 +292,9 @@ void Settings::save(QString path, bool writeFriends)
s.setValue("currentProfile", currentProfile);
s.setValue("autoAwayTime", autoAwayTime);
s.setValue("checkUpdates", checkUpdates);
s.setValue("showWindow", showWindow);
s.setValue("showInFront", showInFront);
s.setValue("groupAlwaysNotify", groupAlwaysNotify);
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
s.setValue("compactLayout", compactLayout);
s.setValue("autoSaveEnabled", autoSaveEnabled);
@ -563,7 +567,17 @@ bool Settings::getShowInFront() const
void Settings::setShowInFront(bool newValue)
{
showInFront = newValue;
showInFront = newValue;
}
bool Settings::getGroupAlwaysNotify() const
{
return groupAlwaysNotify;
}
void Settings::setGroupAlwaysNotify(bool newValue)
{
groupAlwaysNotify = newValue;
}
QString Settings::getTranslation() const
@ -856,6 +870,16 @@ void Settings::setCheckUpdates(bool newValue)
checkUpdates = newValue;
}
bool Settings::getShowWindow() const
{
return showWindow;
}
void Settings::setShowWindow(bool newValue)
{
showWindow = newValue;
}
QByteArray Settings::getSplitterState() const
{
return splitterState;

View File

@ -115,9 +115,15 @@ public:
bool getCheckUpdates() const;
void setCheckUpdates(bool newValue);
bool getShowWindow() const;
void setShowWindow(bool newValue);
bool getShowInFront() const;
void setShowInFront(bool newValue);
bool getGroupAlwaysNotify() const;
void setGroupAlwaysNotify(bool newValue);
QPixmap getSavedAvatar(const QString& ownerId);
void saveAvatar(QPixmap& pic, const QString& ownerId);
@ -259,7 +265,9 @@ private:
bool lightTrayIcon;
bool useEmoticons;
bool checkUpdates;
bool showWindow;
bool showInFront;
bool groupAlwaysNotify;
bool forceTCP;

View File

@ -67,7 +67,9 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
bodyUI->useEmoticons->setChecked(Settings::getInstance().getUseEmoticons());
bodyUI->autoacceptFiles->setChecked(Settings::getInstance().getAutoSaveEnabled());
bodyUI->autoSaveFilesDir->setText(Settings::getInstance().getGlobalAutoAcceptDir());
bodyUI->showWindow->setChecked(Settings::getInstance().getShowWindow());
bodyUI->showInFront->setChecked(Settings::getInstance().getShowInFront());
bodyUI->groupAlwaysNotify->setChecked(Settings::getInstance().getGroupAlwaysNotify());
bodyUI->cbFauxOfflineMessaging->setChecked(Settings::getInstance().getFauxOfflineMessaging());
bodyUI->cbCompactLayout->setChecked(Settings::getInstance().getCompactLayout());
@ -125,7 +127,9 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
connect(bodyUI->lightTrayIcon, &QCheckBox::stateChanged, this, &GeneralForm::onSetLightTrayIcon);
connect(bodyUI->statusChanges, &QCheckBox::stateChanged, this, &GeneralForm::onSetStatusChange);
connect(bodyUI->autoAwaySpinBox, SIGNAL(editingFinished()), this, SLOT(onAutoAwayChanged()));
connect(bodyUI->showWindow, &QCheckBox::stateChanged, this, &GeneralForm::onShowWindowChanged);
connect(bodyUI->showInFront, &QCheckBox::stateChanged, this, &GeneralForm::onSetShowInFront);
connect(bodyUI->groupAlwaysNotify, &QCheckBox::stateChanged, this, &GeneralForm::onSetGroupAlwaysNotify);
connect(bodyUI->autoacceptFiles, &QCheckBox::stateChanged, this, &GeneralForm::onAutoAcceptFileChange);
if (bodyUI->autoacceptFiles->isChecked())
connect(bodyUI->autoSaveFilesDir, SIGNAL(clicked()), this, SLOT(onAutoSaveDirChange()));
@ -331,9 +335,19 @@ void GeneralForm::onCheckUpdateChanged()
Settings::getInstance().setCheckUpdates(bodyUI->checkUpdates->isChecked());
}
void GeneralForm::onShowWindowChanged()
{
Settings::getInstance().setShowWindow(bodyUI->showWindow->isChecked());
}
void GeneralForm::onSetShowInFront()
{
Settings::getInstance().setShowInFront(bodyUI->showInFront->isChecked());
Settings::getInstance().setShowInFront(bodyUI->showInFront->isChecked());
}
void GeneralForm::onSetGroupAlwaysNotify()
{
Settings::getInstance().setGroupAlwaysNotify(bodyUI->groupAlwaysNotify->isChecked());
}
void GeneralForm::onFauxOfflineMessaging()

View File

@ -54,7 +54,9 @@ private slots:
void onAutoAcceptFileChange();
void onAutoSaveDirChange();
void onCheckUpdateChanged();
void onShowWindowChanged();
void onSetShowInFront();
void onSetGroupAlwaysNotify();
void onFauxOfflineMessaging();
void onCompactLayout();
void onThemeColorChanged(int);

View File

@ -275,6 +275,13 @@
<string>Chat</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0">
<item row="3" column="0">
<widget class="QCheckBox" name="groupAlwaysNotify">
<property name="text">
<string>Group chats always notify</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="statusChanges">
<property name="text">
@ -294,6 +301,13 @@
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="showWindow">
<property name="text">
<string>Show window</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showInFront">
<property name="text">
@ -700,5 +714,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>showWindow</sender>
<signal>toggled(bool)</signal>
<receiver>showInFront</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>329</x>
<y>349</y>
</hint>
<hint type="destinationlabel">
<x>451</x>
<y>349</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -633,15 +633,15 @@ void Widget::hideMainForms()
void Widget::onUsernameChanged(const QString& newUsername, const QString& oldUsername)
{
ui->nameLabel->setText(oldUsername); // restore old username until Core tells us to set it
ui->nameLabel->setToolTip(oldUsername); // for overlength names
setUsername(oldUsername); // restore old username until Core tells us to set it
core->setUsername(newUsername);
}
void Widget::setUsername(const QString& username)
{
ui->nameLabel->setText(username);
ui->nameLabel->setToolTip(username); // for overlength names
ui->nameLabel->setToolTip(username); // for overlength names
nameMention = QRegExp("([^a-z]|^)" + QRegExp::escape(username) + "([^a-z]|$)", Qt::CaseInsensitive);
}
void Widget::onStatusMessageChanged(const QString& newStatusMessage, const QString& oldStatusMessage)
@ -806,25 +806,11 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
QDateTime timestamp = QDateTime::currentDateTime();
f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp, true);
if (isAction)
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp, true);
else
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp, true);
if (activeChatroomWidget != nullptr)
{
if ((static_cast<GenericChatroomWidget*>(f->getFriendWidget()) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
{
f->setEventFlag(true);
newMessageAlert(f->getFriendWidget());
}
}
else
{
f->setEventFlag(true);
newMessageAlert(f->getFriendWidget());
}
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, isAction ? "/me " + message : message,
f->getToxID().publicKey, timestamp, true);
f->setEventFlag(static_cast<GenericChatroomWidget*>(f->getFriendWidget()) != activeChatroomWidget);
newMessageAlert(f->getFriendWidget());
f->getFriendWidget()->updateStatusLight();
}
@ -839,17 +825,22 @@ void Widget::onReceiptRecieved(int friendId, int receipt)
void Widget::newMessageAlert(GenericChatroomWidget* chat)
{
bool inactiveWindow = isMinimized() || !isActiveWindow();
if (!inactiveWindow && activeChatroomWidget != nullptr && chat == activeChatroomWidget)
return;
QApplication::alert(this);
static QFile sndFile(":audio/notification.pcm");
if ((isMinimized() || !isActiveWindow()) && Settings::getInstance().getShowInFront())
if (Settings::getInstance().getShowWindow())
{
this->show();
showNormal();
activateWindow();
emit chat->chatroomWidgetClicked(chat);
show();
if (inactiveWindow && Settings::getInstance().getShowInFront())
setWindowState(Qt::WindowActive);
}
static QFile sndFile(":audio/notification.pcm");
static QByteArray sndData;
if (sndData.isEmpty())
{
sndFile.open(QIODevice::ReadOnly);
@ -953,24 +944,21 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
return;
ToxID author = Core::getInstance()->getGroupPeerToxID(groupnumber, peernumber);
QString name = core->getUsername();
bool targeted = (!author.isMine()) && message.contains(name, Qt::CaseInsensitive);
bool targeted = (!author.isMine()) && message.contains(nameMention);
if (targeted && !isAction)
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());
else
g->getChatForm()->addMessage(author, message, isAction, QDateTime::currentDateTime(), true);
if ((static_cast<GenericChatroomWidget*>(g->getGroupWidget()) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
{
g->setEventFlag(true);
if (targeted)
{
newMessageAlert(g->getGroupWidget());
g->setMentionedFlag(true); // useful for highlighting line or desktop notifications
}
g->getGroupWidget()->updateStatusLight();
}
g->setEventFlag(static_cast<GenericChatroomWidget*>(g->getGroupWidget()) != activeChatroomWidget);
if (targeted || Settings::getInstance().getGroupAlwaysNotify())
newMessageAlert(g->getGroupWidget());
if (targeted)
g->setMentionedFlag(true); // useful for highlighting line or desktop notifications
g->getGroupWidget()->updateStatusLight();
}
void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Change)

View File

@ -171,6 +171,7 @@ private:
Status beforeDisconnect = Status::Offline;
QTimer* idleTimer;
QTranslator* translator;
QRegExp nameMention;
};
void toxActivateEventHandler(const QByteArray& data);