From 4521837765b6eb27f86773594995f8f483690d92 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 14 Jan 2018 15:57:58 +0200 Subject: [PATCH] Add option to disable typing notifications fixes #131 --- include/UserSettingsPage.h | 9 +++++++++ src/ChatPage.cc | 17 +++++++++++++++++ src/UserSettingsPage.cc | 31 ++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/include/UserSettingsPage.h b/include/UserSettingsPage.h index 6c825a83..73f4b5e1 100644 --- a/include/UserSettingsPage.h +++ b/include/UserSettingsPage.h @@ -61,10 +61,17 @@ public: save(); }; + void setTypingNotifications(bool state) + { + isTypingNotificationsEnabled_ = state; + save(); + }; + QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } bool isTrayEnabled() const { return isTrayEnabled_; } bool isOrderingEnabled() const { return isOrderingEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; } + bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } signals: void groupViewStateChanged(bool state); @@ -74,6 +81,7 @@ private: bool isTrayEnabled_; bool isOrderingEnabled_; bool isGroupViewEnabled_; + bool isTypingNotificationsEnabled_; }; class HorizontalLine : public QFrame @@ -114,6 +122,7 @@ private: Toggle *trayToggle_; Toggle *roomOrderToggle_; Toggle *groupViewToggle_; + Toggle *typingNotifications_; QComboBox *themeCombo_; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 9bb90134..b2ffdfa7 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -155,6 +155,11 @@ ChatPage::ChatPage(QSharedPointer client, connect(room_list_, &RoomList::roomChanged, this, [=](const QString &roomid) { QStringList users; + if (!userSettings_->isTypingNotificationsEnabled()) { + typingDisplay_->setUsers(users); + return; + } + if (typingUsers_.contains(roomid)) users = typingUsers_[roomid]; @@ -190,16 +195,25 @@ ChatPage::ChatPage(QSharedPointer client, }); connect(text_input_, &TextInputWidget::startedTyping, this, [=]() { + if (!userSettings_->isTypingNotificationsEnabled()) + return; + typingRefresher_->start(); client_->sendTypingNotification(current_room_); }); connect(text_input_, &TextInputWidget::stoppedTyping, this, [=]() { + if (!userSettings_->isTypingNotificationsEnabled()) + return; + typingRefresher_->stop(); client_->removeTypingNotification(current_room_); }); connect(typingRefresher_, &QTimer::timeout, this, [=]() { + if (!userSettings_->isTypingNotificationsEnabled()) + return; + client_->sendTypingNotification(current_room_); }); @@ -773,6 +787,9 @@ ChatPage::removeInvite(const QString &room_id) void ChatPage::updateTypingUsers(const QString &roomid, const std::vector &user_ids) { + if (!userSettings_->isTypingNotificationsEnabled()) + return; + QStringList users; QSettings settings; diff --git a/src/UserSettingsPage.cc b/src/UserSettingsPage.cc index 17668c3d..cff29afd 100644 --- a/src/UserSettingsPage.cc +++ b/src/UserSettingsPage.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "Config.h" @@ -33,10 +34,11 @@ void UserSettings::load() { QSettings settings; - isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); - isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool(); - isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); - theme_ = settings.value("user/theme", "light").toString(); + isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); + isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool(); + isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); + isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); + theme_ = settings.value("user/theme", "light").toString(); applyTheme(); } @@ -83,6 +85,7 @@ UserSettings::save() settings.endGroup(); settings.setValue("room_ordering", isOrderingEnabled_); + settings.setValue("typing_notifications", isTypingNotificationsEnabled_); settings.setValue("group_view", isGroupViewEnabled_); settings.setValue("theme", theme()); settings.endGroup(); @@ -152,9 +155,20 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge groupViewLayout->addWidget(groupViewLabel); groupViewLayout->addWidget(groupViewToggle_, 0, Qt::AlignBottom | Qt::AlignRight); + auto typingLayout = new QHBoxLayout; + typingLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); + auto typingLabel = new QLabel(tr("Typing notifications"), this); + typingNotifications_ = new Toggle(this); + typingNotifications_->setActiveColor(QColor("#38A3D8")); + typingNotifications_->setInactiveColor(QColor("gray")); + typingLabel->setStyleSheet("font-size: 15px;"); + + typingLayout->addWidget(typingLabel); + typingLayout->addWidget(typingNotifications_, 0, Qt::AlignBottom | Qt::AlignRight); + auto themeOptionLayout_ = new QHBoxLayout; themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); - auto themeLabel_ = new QLabel(tr("App theme"), this); + auto themeLabel_ = new QLabel(tr("Theme"), this); themeCombo_ = new QComboBox(this); themeCombo_->addItem("Light"); themeCombo_->addItem("Dark"); @@ -179,6 +193,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(groupViewLayout); mainLayout_->addWidget(new HorizontalLine(this)); + mainLayout_->addLayout(typingLayout); + mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(themeOptionLayout_); mainLayout_->addWidget(new HorizontalLine(this)); @@ -203,6 +219,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setGroupView(!isDisabled); }); + connect(typingNotifications_, &Toggle::toggled, this, [=](bool isDisabled) { + settings_->setTypingNotifications(!isDisabled); + }); + connect(backBtn_, &QPushButton::clicked, this, [=]() { settings_->save(); emit moveBack(); @@ -218,6 +238,7 @@ UserSettingsPage::showEvent(QShowEvent *) trayToggle_->setState(!settings_->isTrayEnabled()); roomOrderToggle_->setState(!settings_->isOrderingEnabled()); groupViewToggle_->setState(!settings_->isGroupViewEnabled()); + typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); } void