Add option to disable typing notifications

fixes #131
This commit is contained in:
Konstantinos Sideris 2018-01-14 15:57:58 +02:00
parent c4fa8c844d
commit 4521837765
3 changed files with 52 additions and 5 deletions

View file

@ -61,10 +61,17 @@ public:
save(); save();
}; };
void setTypingNotifications(bool state)
{
isTypingNotificationsEnabled_ = state;
save();
};
QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; }
bool isTrayEnabled() const { return isTrayEnabled_; } bool isTrayEnabled() const { return isTrayEnabled_; }
bool isOrderingEnabled() const { return isOrderingEnabled_; } bool isOrderingEnabled() const { return isOrderingEnabled_; }
bool isGroupViewEnabled() const { return isGroupViewEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
signals: signals:
void groupViewStateChanged(bool state); void groupViewStateChanged(bool state);
@ -74,6 +81,7 @@ private:
bool isTrayEnabled_; bool isTrayEnabled_;
bool isOrderingEnabled_; bool isOrderingEnabled_;
bool isGroupViewEnabled_; bool isGroupViewEnabled_;
bool isTypingNotificationsEnabled_;
}; };
class HorizontalLine : public QFrame class HorizontalLine : public QFrame
@ -114,6 +122,7 @@ private:
Toggle *trayToggle_; Toggle *trayToggle_;
Toggle *roomOrderToggle_; Toggle *roomOrderToggle_;
Toggle *groupViewToggle_; Toggle *groupViewToggle_;
Toggle *typingNotifications_;
QComboBox *themeCombo_; QComboBox *themeCombo_;

View file

@ -155,6 +155,11 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
connect(room_list_, &RoomList::roomChanged, this, [=](const QString &roomid) { connect(room_list_, &RoomList::roomChanged, this, [=](const QString &roomid) {
QStringList users; QStringList users;
if (!userSettings_->isTypingNotificationsEnabled()) {
typingDisplay_->setUsers(users);
return;
}
if (typingUsers_.contains(roomid)) if (typingUsers_.contains(roomid))
users = typingUsers_[roomid]; users = typingUsers_[roomid];
@ -190,16 +195,25 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
}); });
connect(text_input_, &TextInputWidget::startedTyping, this, [=]() { connect(text_input_, &TextInputWidget::startedTyping, this, [=]() {
if (!userSettings_->isTypingNotificationsEnabled())
return;
typingRefresher_->start(); typingRefresher_->start();
client_->sendTypingNotification(current_room_); client_->sendTypingNotification(current_room_);
}); });
connect(text_input_, &TextInputWidget::stoppedTyping, this, [=]() { connect(text_input_, &TextInputWidget::stoppedTyping, this, [=]() {
if (!userSettings_->isTypingNotificationsEnabled())
return;
typingRefresher_->stop(); typingRefresher_->stop();
client_->removeTypingNotification(current_room_); client_->removeTypingNotification(current_room_);
}); });
connect(typingRefresher_, &QTimer::timeout, this, [=]() { connect(typingRefresher_, &QTimer::timeout, this, [=]() {
if (!userSettings_->isTypingNotificationsEnabled())
return;
client_->sendTypingNotification(current_room_); client_->sendTypingNotification(current_room_);
}); });
@ -773,6 +787,9 @@ ChatPage::removeInvite(const QString &room_id)
void void
ChatPage::updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids) ChatPage::updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids)
{ {
if (!userSettings_->isTypingNotificationsEnabled())
return;
QStringList users; QStringList users;
QSettings settings; QSettings settings;

View file

@ -20,6 +20,7 @@
#include <QDebug> #include <QDebug>
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QScrollArea>
#include <QSettings> #include <QSettings>
#include "Config.h" #include "Config.h"
@ -36,6 +37,7 @@ UserSettings::load()
isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); isTrayEnabled_ = settings.value("user/window/tray", true).toBool();
isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool(); isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool();
isGroupViewEnabled_ = settings.value("user/group_view", 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(); theme_ = settings.value("user/theme", "light").toString();
applyTheme(); applyTheme();
@ -83,6 +85,7 @@ UserSettings::save()
settings.endGroup(); settings.endGroup();
settings.setValue("room_ordering", isOrderingEnabled_); settings.setValue("room_ordering", isOrderingEnabled_);
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
settings.setValue("group_view", isGroupViewEnabled_); settings.setValue("group_view", isGroupViewEnabled_);
settings.setValue("theme", theme()); settings.setValue("theme", theme());
settings.endGroup(); settings.endGroup();
@ -152,9 +155,20 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
groupViewLayout->addWidget(groupViewLabel); groupViewLayout->addWidget(groupViewLabel);
groupViewLayout->addWidget(groupViewToggle_, 0, Qt::AlignBottom | Qt::AlignRight); 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; auto themeOptionLayout_ = new QHBoxLayout;
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); 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_ = new QComboBox(this);
themeCombo_->addItem("Light"); themeCombo_->addItem("Light");
themeCombo_->addItem("Dark"); themeCombo_->addItem("Dark");
@ -179,6 +193,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(groupViewLayout); mainLayout_->addLayout(groupViewLayout);
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(typingLayout);
mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(themeOptionLayout_); mainLayout_->addLayout(themeOptionLayout_);
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
@ -203,6 +219,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setGroupView(!isDisabled); settings_->setGroupView(!isDisabled);
}); });
connect(typingNotifications_, &Toggle::toggled, this, [=](bool isDisabled) {
settings_->setTypingNotifications(!isDisabled);
});
connect(backBtn_, &QPushButton::clicked, this, [=]() { connect(backBtn_, &QPushButton::clicked, this, [=]() {
settings_->save(); settings_->save();
emit moveBack(); emit moveBack();
@ -218,6 +238,7 @@ UserSettingsPage::showEvent(QShowEvent *)
trayToggle_->setState(!settings_->isTrayEnabled()); trayToggle_->setState(!settings_->isTrayEnabled());
roomOrderToggle_->setState(!settings_->isOrderingEnabled()); roomOrderToggle_->setState(!settings_->isOrderingEnabled());
groupViewToggle_->setState(!settings_->isGroupViewEnabled()); groupViewToggle_->setState(!settings_->isGroupViewEnabled());
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
} }
void void