diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 8f3c37a4..9f408a73 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -569,7 +569,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) hasNotifications = true; } - if (hasNotifications) + if (hasNotifications && userSettings_->hasDesktopNotifications()) http::client()->notifications( 5, [this](const mtx::responses::Notifications &res, diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 1bc44e14..b41de3a9 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -38,6 +38,7 @@ UserSettings::load() { QSettings settings; 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(); isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool(); isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); @@ -94,6 +95,7 @@ UserSettings::save() settings.setValue("typing_notifications", isTypingNotificationsEnabled_); settings.setValue("read_receipts", isReadReceiptsEnabled_); settings.setValue("group_view", isGroupViewEnabled_); + settings.setValue("desktop_notifications", hasDesktopNotifications_); settings.setValue("theme", theme()); settings.endGroup(); } @@ -188,6 +190,15 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge receiptsLayout->addWidget(receiptsLabel); 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; scaleFactorOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); auto scaleFactorLabel = new QLabel(tr("Scale factor (requires restart)"), this); @@ -239,6 +250,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(typingLayout); mainLayout_->addLayout(receiptsLayout); + mainLayout_->addLayout(desktopLayout); mainLayout_->addWidget(new HorizontalLine(this)); #if defined(Q_OS_MAC) @@ -307,6 +319,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setReadReceipts(!isDisabled); }); + connect(desktopNotifications_, &Toggle::toggled, this, [this](bool isDisabled) { + settings_->setDesktopNotifications(!isDisabled); + }); + connect(backBtn_, &QPushButton::clicked, this, [this]() { settings_->save(); emit moveBack(); @@ -326,6 +342,7 @@ UserSettingsPage::showEvent(QShowEvent *) groupViewToggle_->setState(!settings_->isGroupViewEnabled()); typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); readReceipts_->setState(!settings_->isReadReceiptsEnabled()); + desktopNotifications_->setState(!settings_->hasDesktopNotifications()); } void diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index f6ecd9c7..db40e43b 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -44,19 +44,19 @@ public: { isTrayEnabled_ = state; save(); - }; + } void setStartInTray(bool state) { isStartInTrayEnabled_ = state; save(); - }; + } void setRoomOrdering(bool state) { isOrderingEnabled_ = state; save(); - }; + } void setGroupView(bool state) { @@ -65,7 +65,7 @@ public: isGroupViewEnabled_ = state; save(); - }; + } void setReadReceipts(bool state) { @@ -77,7 +77,13 @@ public: { isTypingNotificationsEnabled_ = state; save(); - }; + } + + void setDesktopNotifications(bool state) + { + hasDesktopNotifications_ = state; + save(); + } QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } bool isTrayEnabled() const { return isTrayEnabled_; } @@ -86,6 +92,7 @@ public: bool isGroupViewEnabled() const { return isGroupViewEnabled_; } bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; } + bool hasDesktopNotifications() const { return hasDesktopNotifications_; } signals: void groupViewStateChanged(bool state); @@ -98,6 +105,7 @@ private: bool isGroupViewEnabled_; bool isTypingNotificationsEnabled_; bool isReadReceiptsEnabled_; + bool hasDesktopNotifications_; }; class HorizontalLine : public QFrame @@ -142,6 +150,7 @@ private: Toggle *groupViewToggle_; Toggle *typingNotifications_; Toggle *readReceipts_; + Toggle *desktopNotifications_; QComboBox *themeCombo_; QComboBox *scaleFactorCombo_;