Start in tray (#319)

This commit is contained in:
Anton Karmanov 2018-05-09 01:53:40 +05:00 committed by mujx
parent 7d809be79f
commit 17896b1c82
3 changed files with 41 additions and 1 deletions

View file

@ -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<UserSettings> settings_;
Toggle *trayToggle_;
Toggle *startInTrayToggle_;
Toggle *roomOrderToggle_;
Toggle *groupViewToggle_;
Toggle *typingNotifications_;

View file

@ -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<UserSettings> 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<UserSettings> 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<UserSettings> 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());

View file

@ -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);