Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Start in tray #319

Merged
merged 5 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/UserSettingsPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class UserSettings : public QObject
save();
};

void setStartInTray(bool state)
{
isStartInTrayEnabled_ = state;
save();
};

void setRoomOrdering(bool state)
{
isOrderingEnabled_ = state;
Expand Down Expand Up @@ -75,6 +81,7 @@ class UserSettings : public QObject

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_; }
Expand All @@ -86,6 +93,7 @@ class UserSettings : public QObject
private:
QString theme_;
bool isTrayEnabled_;
bool isStartInTrayEnabled_;
bool isOrderingEnabled_;
bool isGroupViewEnabled_;
bool isTypingNotificationsEnabled_;
Expand Down Expand Up @@ -128,6 +136,7 @@ class UserSettingsPage : public QWidget
QSharedPointer<UserSettings> settings_;

Toggle *trayToggle_;
Toggle *startInTrayToggle_;
Toggle *roomOrderToggle_;
Toggle *groupViewToggle_;
Toggle *typingNotifications_;
Expand Down
28 changes: 28 additions & 0 deletions src/UserSettingsPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 4 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down