mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Implement a setting for the tray icon (#108)
This commit is contained in:
parent
ddb23105f1
commit
84741adc16
4 changed files with 15 additions and 8 deletions
|
@ -66,6 +66,7 @@ protected:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void moveBack();
|
void moveBack();
|
||||||
|
void trayOptionChanged(bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Layouts
|
// Layouts
|
||||||
|
|
|
@ -94,6 +94,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
pageStack_->setCurrentWidget(chat_page_);
|
pageStack_->setCurrentWidget(chat_page_);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool)));
|
||||||
|
|
||||||
connect(trayIcon_,
|
connect(trayIcon_,
|
||||||
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||||
this,
|
this,
|
||||||
|
@ -113,6 +115,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
|
trayIcon_->setVisible(userSettings_->isTrayEnabled());
|
||||||
|
|
||||||
if (hasActiveUser()) {
|
if (hasActiveUser()) {
|
||||||
QString token = settings.value("auth/access_token").toString();
|
QString token = settings.value("auth/access_token").toString();
|
||||||
QString home_server = settings.value("auth/home_server").toString();
|
QString home_server = settings.value("auth/home_server").toString();
|
||||||
|
@ -253,7 +257,7 @@ MainWindow::showUserSettingsPage()
|
||||||
void
|
void
|
||||||
MainWindow::closeEvent(QCloseEvent *event)
|
MainWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
if (isVisible()) {
|
if (isVisible() && userSettings_->isTrayEnabled()) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,9 +123,6 @@ TrayIcon::TrayIcon(const QString &filename, QWidget *parent)
|
||||||
menu->addAction(quitAction_);
|
menu->addAction(quitAction_);
|
||||||
|
|
||||||
setContextMenu(menu);
|
setContextMenu(menu);
|
||||||
|
|
||||||
// We wait a little for the icon to load.
|
|
||||||
QTimer::singleShot(500, this, [=]() { show(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -32,7 +32,7 @@ void
|
||||||
UserSettings::load()
|
UserSettings::load()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
isTrayEnabled_ = settings.value("user/tray", true).toBool();
|
isTrayEnabled_ = settings.value("user/window/tray", true).toBool();
|
||||||
theme_ = settings.value("user/theme", "default").toString();
|
theme_ = settings.value("user/theme", "default").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,11 @@ UserSettings::save()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.beginGroup("user");
|
settings.beginGroup("user");
|
||||||
|
|
||||||
|
settings.beginGroup("window");
|
||||||
settings.setValue("tray", isTrayEnabled_);
|
settings.setValue("tray", isTrayEnabled_);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
settings.setValue("theme", theme());
|
settings.setValue("theme", theme());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
@ -122,8 +126,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||||
[=](const QString &text) { settings_->setTheme(text.toLower()); });
|
[=](const QString &text) { settings_->setTheme(text.toLower()); });
|
||||||
|
|
||||||
connect(trayToggle_, &Toggle::toggled, this, [=](bool isEnabled) {
|
connect(trayToggle_, &Toggle::toggled, this, [=](bool isDisabled) {
|
||||||
settings_->setTray(isEnabled);
|
settings_->setTray(!isDisabled);
|
||||||
|
emit trayOptionChanged(!isDisabled);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(backBtn_, &QPushButton::clicked, this, [=]() {
|
connect(backBtn_, &QPushButton::clicked, this, [=]() {
|
||||||
|
@ -136,5 +141,5 @@ void
|
||||||
UserSettingsPage::showEvent(QShowEvent *)
|
UserSettingsPage::showEvent(QShowEvent *)
|
||||||
{
|
{
|
||||||
themeCombo_->setCurrentIndex((settings_->theme() == "default" ? 0 : 1));
|
themeCombo_->setCurrentIndex((settings_->theme() == "default" ? 0 : 1));
|
||||||
trayToggle_->setState(settings_->isTrayEnabled());
|
trayToggle_->setState(!settings_->isTrayEnabled()); // Treats true as "off"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue