From 17896b1c82200aec05a7cd99b9694fb228ad04f0 Mon Sep 17 00:00:00 2001 From: Anton Karmanov Date: Wed, 9 May 2018 01:53:40 +0500 Subject: [PATCH] Start in tray (#319) --- include/UserSettingsPage.h | 9 +++++++++ src/UserSettingsPage.cc | 28 ++++++++++++++++++++++++++++ src/main.cc | 5 ++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/UserSettingsPage.h b/include/UserSettingsPage.h index a58020ce..177f1921 100644 --- a/include/UserSettingsPage.h +++ b/include/UserSettingsPage.h @@ -46,6 +46,12 @@ public: save(); }; + void setStartInTray(bool state) + { + isStartInTrayEnabled_ = state; + save(); + }; + void setRoomOrdering(bool state) { isOrderingEnabled_ = state; @@ -75,6 +81,7 @@ public: QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } bool isTrayEnabled() const { return isTrayEnabled_; } + bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } bool isOrderingEnabled() const { return isOrderingEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; } bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } @@ -86,6 +93,7 @@ signals: private: QString theme_; bool isTrayEnabled_; + bool isStartInTrayEnabled_; bool isOrderingEnabled_; bool isGroupViewEnabled_; bool isTypingNotificationsEnabled_; @@ -128,6 +136,7 @@ private: QSharedPointer settings_; Toggle *trayToggle_; + Toggle *startInTrayToggle_; Toggle *roomOrderToggle_; Toggle *groupViewToggle_; Toggle *typingNotifications_; diff --git a/src/UserSettingsPage.cc b/src/UserSettingsPage.cc index 198d8bf1..fe66c189 100644 --- a/src/UserSettingsPage.cc +++ b/src/UserSettingsPage.cc @@ -37,6 +37,7 @@ UserSettings::load() { QSettings settings; isTrayEnabled_ = settings.value("user/window/tray", 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(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); @@ -85,6 +86,7 @@ UserSettings::save() settings.beginGroup("window"); settings.setValue("tray", isTrayEnabled_); + settings.setValue("start_in_tray", isStartInTrayEnabled_); settings.endGroup(); settings.setValue("room_ordering", isOrderingEnabled_); @@ -140,6 +142,20 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge trayOptionLayout_->addWidget(trayLabel); trayOptionLayout_->addWidget(trayToggle_, 0, Qt::AlignBottom | Qt::AlignRight); + auto startInTrayOptionLayout_ = new QHBoxLayout; + startInTrayOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); + auto startInTrayLabel = new QLabel(tr("Start in tray"), this); + startInTrayToggle_ = new Toggle(this); + startInTrayToggle_->setActiveColor(QColor("#38A3D8")); + startInTrayToggle_->setInactiveColor(QColor("gray")); + if (!settings_->isTrayEnabled()) + startInTrayToggle_->setDisabled(true); + startInTrayLabel->setStyleSheet("font-size: 15px;"); + + startInTrayOptionLayout_->addWidget(startInTrayLabel); + startInTrayOptionLayout_->addWidget( + startInTrayToggle_, 0, Qt::AlignBottom | Qt::AlignRight); + auto orderRoomLayout = new QHBoxLayout; orderRoomLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); auto orderLabel = new QLabel(tr("Re-order rooms based on activity"), this); @@ -207,6 +223,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(trayOptionLayout_); mainLayout_->addWidget(new HorizontalLine(this)); + mainLayout_->addLayout(startInTrayOptionLayout_); + mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(orderRoomLayout); mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(groupViewLayout); @@ -228,9 +246,18 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) { settings_->setTray(!isDisabled); + if (isDisabled) { + startInTrayToggle_->setDisabled(true); + } else { + startInTrayToggle_->setEnabled(true); + } emit trayOptionChanged(!isDisabled); }); + connect(startInTrayToggle_, &Toggle::toggled, this, [this](bool isDisabled) { + settings_->setStartInTray(!isDisabled); + }); + connect(roomOrderToggle_, &Toggle::toggled, this, [this](bool isDisabled) { settings_->setRoomOrdering(!isDisabled); }); @@ -260,6 +287,7 @@ UserSettingsPage::showEvent(QShowEvent *) // FIXME: Toggle treats true as "off" trayToggle_->setState(!settings_->isTrayEnabled()); + startInTrayToggle_->setState(!settings_->isStartInTrayEnabled()); roomOrderToggle_->setState(!settings_->isOrderingEnabled()); groupViewToggle_->setState(!settings_->isGroupViewEnabled()); typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); diff --git a/src/main.cc b/src/main.cc index 82073454..bd3a212c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -160,7 +160,10 @@ main(int argc, char *argv[]) // Move the MainWindow to the center w.move(screenCenter(w.width(), w.height())); - w.show(); + + if (!settings.value("user/window/start_in_tray", false).toBool() || + !settings.value("user/window/tray", true).toBool()) + w.show(); QObject::connect(&app, &QApplication::aboutToQuit, &w, &MainWindow::saveCurrentWindowSize);