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

fix(ui): Added option to hide message sender and contents

This commit is contained in:
Monsterovich 2019-05-23 00:44:26 +02:00
parent 1bbe210c25
commit 3b305dd05a
8 changed files with 92 additions and 13 deletions

View File

@ -154,6 +154,7 @@ void Settings::loadGlobal()
autoAwayTime = s.value("autoAwayTime", 10).toInt();
checkUpdates = s.value("checkUpdates", true).toBool();
notifySound = s.value("notifySound", true).toBool(); // note: notifySound and busySound UI elements are now under UI settings
notifyHide = s.value("notifyHide", false).toBool();
busySound = s.value("busySound", false).toBool(); // page, but kept under General in settings file to be backwards compatible
fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool();
autoSaveEnabled = s.value("autoSaveEnabled", false).toBool();
@ -435,6 +436,7 @@ void Settings::saveGlobal()
s.setValue("autoAwayTime", autoAwayTime);
s.setValue("checkUpdates", checkUpdates);
s.setValue("notifySound", notifySound);
s.setValue("notifyHide", notifyHide);
s.setValue("busySound", busySound);
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
s.setValue("autoSaveEnabled", autoSaveEnabled);
@ -1005,6 +1007,22 @@ void Settings::setNotifySound(bool newValue)
}
}
bool Settings::getNotifyHide() const
{
QMutexLocker locker{&bigLock};
return notifyHide;
}
void Settings::setNotifyHide(bool newValue)
{
QMutexLocker locker{&bigLock};
if (newValue != notifyHide) {
notifyHide = newValue;
emit notifyHideChanged(notifyHide);
}
}
bool Settings::getBusySound() const
{
QMutexLocker locker{&bigLock};

View File

@ -181,6 +181,7 @@ signals:
void makeToxPortableChanged(bool enabled);
void busySoundChanged(bool enabled);
void notifySoundChanged(bool enabled);
void notifyHideChanged(bool enabled);
void groupAlwaysNotifyChanged(bool enabled);
void translationChanged(const QString& translation);
void toxmeInfoChanged(const QString& info);
@ -337,6 +338,9 @@ public:
bool getNotifySound() const;
void setNotifySound(bool newValue);
bool getNotifyHide() const;
void setNotifyHide(bool newValue);
bool getBusySound() const;
void setBusySound(bool newValue);
@ -620,6 +624,7 @@ private:
bool desktopNotify;
bool showWindow;
bool notifySound;
bool notifyHide;
bool busySound;
bool groupAlwaysNotify;
bool nameColors;

View File

@ -42,3 +42,17 @@ void DesktopNotify::notifyMessagePixmap(const QString title, const QString messa
createNotification(title, message, new_icon);
}
void DesktopNotify::notifyMessageSimple(const MessageType type)
{
QString message;
switch (type) {
case MSG_FRIEND: message = tr("New message"); break;
case MSG_FRIEND_FILE: message = tr("Incoming file transfer"); break;
case MSG_FRIEND_REQUEST: message = tr("Friend request received"); break;
case MSG_GROUP: message = tr("New group message"); break;
case MSG_GROUP_INVITE: message = tr("Group invite"); break;
default: break;
}
createNotification(message, {}, snoreIcon);
}

View File

@ -12,9 +12,18 @@ class DesktopNotify : public QObject
public:
DesktopNotify();
enum MessageType {
MSG_FRIEND = 0,
MSG_FRIEND_FILE,
MSG_FRIEND_REQUEST,
MSG_GROUP,
MSG_GROUP_INVITE
};
public slots:
void notifyMessage(const QString title, const QString message);
void notifyMessagePixmap(const QString title, const QString message, QPixmap avatar);
void notifyMessageSimple(const MessageType type);
private:
void createNotification(const QString& title, const QString &text, Snore::Icon &icon);

View File

@ -391,3 +391,9 @@ void UserInterfaceForm::on_useNameColors_stateChanged(int value)
{
Settings::getInstance().setEnableGroupChatsColor(value);
}
void UserInterfaceForm::on_notifyHide_stateChanged(int value)
{
Settings::getInstance().setNotifyHide(value);
}

View File

@ -51,6 +51,7 @@ private slots:
void on_notify_stateChanged();
void on_desktopNotify_stateChanged();
void on_notifySound_stateChanged();
void on_notifyHide_stateChanged(int);
void on_busySound_stateChanged();
void on_showWindow_stateChanged();
void on_groupOnlyNotfiyWhenMentioned_stateChanged();
@ -60,7 +61,6 @@ private slots:
void on_cbGroupchatPosition_stateChanged();
void on_themeColorCBox_currentIndexChanged(int);
void on_cbShowIdenticons_stateChanged();
void on_txtChatFont_currentFontChanged(const QFont& f);
void on_txtChatFontSize_valueChanged(int arg1);
void on_useNameColors_stateChanged(int value);

View File

@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>650</width>
<height>892</height>
<height>950</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,0,0,0">
@ -221,6 +221,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="notifyHide">
<property name="text">
<string>Hide message sender and contents</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -1381,11 +1381,16 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString text, bo
widget->updateStatusLight();
ui->friendList->trackWidget(widget);
#if DESKTOP_NOTIFICATIONS
QString title = f->getDisplayedName();
if (file) {
title += " - " + tr("File sent");
const Settings& s = Settings::getInstance();
if (s.getNotifyHide()) {
notifier.notifyMessageSimple(file ? DesktopNotify::MSG_FRIEND_FILE : DesktopNotify::MSG_FRIEND);
} else {
QString title = f->getDisplayedName();
if (file) {
title += " - " + tr("File sent");
}
notifier.notifyMessagePixmap(title, text, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
}
notifier.notifyMessagePixmap(title, text, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
#endif
if (contentDialog == nullptr) {
@ -1425,12 +1430,17 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk,
g->setEventFlag(true);
widget->updateStatusLight();
#if DESKTOP_NOTIFICATIONS
Friend *f = FriendList::findFriend(authorPk);
QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")";
if (!f) {
notifier.notifyMessage(title, message);
const Settings& s = Settings::getInstance();
if (s.getNotifyHide()) {
notifier.notifyMessageSimple(DesktopNotify::MSG_GROUP);
} else {
notifier.notifyMessagePixmap(title, message, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
Friend *f = FriendList::findFriend(authorPk);
QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")";
if (!f) {
notifier.notifyMessage(title, message);
} else {
notifier.notifyMessagePixmap(title, message, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
}
}
#endif
@ -1507,7 +1517,12 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
friendRequestsUpdate();
newMessageAlert(window(), isActiveWindow(), true, true);
#if DESKTOP_NOTIFICATIONS
notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message);
const Settings& s = Settings::getInstance();
if (s.getNotifyHide()) {
notifier.notifyMessageSimple(DesktopNotify::MSG_FRIEND_REQUEST);
} else {
notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message);
}
#endif
}
}
@ -1746,7 +1761,12 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
groupInvitesUpdate();
newMessageAlert(window(), isActiveWindow(), true, true);
#if DESKTOP_NOTIFICATIONS
notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
const Settings& s = Settings::getInstance();
if (s.getNotifyHide()) {
notifier.notifyMessageSimple(DesktopNotify::MSG_GROUP_INVITE);
} else {
notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
}
#endif
}
} else {