Add option to disable desktop notifications

fixes #388
pull/1/head
Konstantinos Sideris 6 years ago
parent 05547086fb
commit cebd8cbc19
  1. 2
      src/ChatPage.cpp
  2. 17
      src/UserSettingsPage.cpp
  3. 19
      src/UserSettingsPage.h

@ -569,7 +569,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
hasNotifications = true; hasNotifications = true;
} }
if (hasNotifications) if (hasNotifications && userSettings_->hasDesktopNotifications())
http::client()->notifications( http::client()->notifications(
5, 5,
[this](const mtx::responses::Notifications &res, [this](const mtx::responses::Notifications &res,

@ -38,6 +38,7 @@ UserSettings::load()
{ {
QSettings settings; QSettings settings;
isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); isTrayEnabled_ = settings.value("user/window/tray", true).toBool();
hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool();
isStartInTrayEnabled_ = settings.value("user/window/start_in_tray", false).toBool(); isStartInTrayEnabled_ = settings.value("user/window/start_in_tray", false).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();
@ -94,6 +95,7 @@ UserSettings::save()
settings.setValue("typing_notifications", isTypingNotificationsEnabled_); settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
settings.setValue("read_receipts", isReadReceiptsEnabled_); settings.setValue("read_receipts", isReadReceiptsEnabled_);
settings.setValue("group_view", isGroupViewEnabled_); settings.setValue("group_view", isGroupViewEnabled_);
settings.setValue("desktop_notifications", hasDesktopNotifications_);
settings.setValue("theme", theme()); settings.setValue("theme", theme());
settings.endGroup(); settings.endGroup();
} }
@ -188,6 +190,15 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
receiptsLayout->addWidget(receiptsLabel); receiptsLayout->addWidget(receiptsLabel);
receiptsLayout->addWidget(readReceipts_, 0, Qt::AlignBottom | Qt::AlignRight); receiptsLayout->addWidget(readReceipts_, 0, Qt::AlignBottom | Qt::AlignRight);
auto desktopLayout = new QHBoxLayout;
desktopLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto desktopLabel = new QLabel(tr("Desktop notifications"), this);
desktopLabel->setFont(font);
desktopNotifications_ = new Toggle(this);
desktopLayout->addWidget(desktopLabel);
desktopLayout->addWidget(desktopNotifications_, 0, Qt::AlignBottom | Qt::AlignRight);
auto scaleFactorOptionLayout = new QHBoxLayout; auto scaleFactorOptionLayout = new QHBoxLayout;
scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto scaleFactorLabel = new QLabel(tr("Scale factor (requires restart)"), this); auto scaleFactorLabel = new QLabel(tr("Scale factor (requires restart)"), this);
@ -239,6 +250,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(typingLayout); mainLayout_->addLayout(typingLayout);
mainLayout_->addLayout(receiptsLayout); mainLayout_->addLayout(receiptsLayout);
mainLayout_->addLayout(desktopLayout);
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
@ -307,6 +319,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setReadReceipts(!isDisabled); settings_->setReadReceipts(!isDisabled);
}); });
connect(desktopNotifications_, &Toggle::toggled, this, [this](bool isDisabled) {
settings_->setDesktopNotifications(!isDisabled);
});
connect(backBtn_, &QPushButton::clicked, this, [this]() { connect(backBtn_, &QPushButton::clicked, this, [this]() {
settings_->save(); settings_->save();
emit moveBack(); emit moveBack();
@ -326,6 +342,7 @@ UserSettingsPage::showEvent(QShowEvent *)
groupViewToggle_->setState(!settings_->isGroupViewEnabled()); groupViewToggle_->setState(!settings_->isGroupViewEnabled());
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
readReceipts_->setState(!settings_->isReadReceiptsEnabled()); readReceipts_->setState(!settings_->isReadReceiptsEnabled());
desktopNotifications_->setState(!settings_->hasDesktopNotifications());
} }
void void

@ -44,19 +44,19 @@ public:
{ {
isTrayEnabled_ = state; isTrayEnabled_ = state;
save(); save();
}; }
void setStartInTray(bool state) void setStartInTray(bool state)
{ {
isStartInTrayEnabled_ = state; isStartInTrayEnabled_ = state;
save(); save();
}; }
void setRoomOrdering(bool state) void setRoomOrdering(bool state)
{ {
isOrderingEnabled_ = state; isOrderingEnabled_ = state;
save(); save();
}; }
void setGroupView(bool state) void setGroupView(bool state)
{ {
@ -65,7 +65,7 @@ public:
isGroupViewEnabled_ = state; isGroupViewEnabled_ = state;
save(); save();
}; }
void setReadReceipts(bool state) void setReadReceipts(bool state)
{ {
@ -77,7 +77,13 @@ public:
{ {
isTypingNotificationsEnabled_ = state; isTypingNotificationsEnabled_ = state;
save(); save();
}; }
void setDesktopNotifications(bool state)
{
hasDesktopNotifications_ = 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_; }
@ -86,6 +92,7 @@ public:
bool isGroupViewEnabled() const { return isGroupViewEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; } bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; }
bool hasDesktopNotifications() const { return hasDesktopNotifications_; }
signals: signals:
void groupViewStateChanged(bool state); void groupViewStateChanged(bool state);
@ -98,6 +105,7 @@ private:
bool isGroupViewEnabled_; bool isGroupViewEnabled_;
bool isTypingNotificationsEnabled_; bool isTypingNotificationsEnabled_;
bool isReadReceiptsEnabled_; bool isReadReceiptsEnabled_;
bool hasDesktopNotifications_;
}; };
class HorizontalLine : public QFrame class HorizontalLine : public QFrame
@ -142,6 +150,7 @@ private:
Toggle *groupViewToggle_; Toggle *groupViewToggle_;
Toggle *typingNotifications_; Toggle *typingNotifications_;
Toggle *readReceipts_; Toggle *readReceipts_;
Toggle *desktopNotifications_;
QComboBox *themeCombo_; QComboBox *themeCombo_;
QComboBox *scaleFactorCombo_; QComboBox *scaleFactorCombo_;

Loading…
Cancel
Save