Browse Source

Merge pull request #9274 from sledgehammer999/tray_close_notification

Notify users on 1st time close/minimize to tray
adaptive-webui-19844
sledgehammer999 6 years ago committed by GitHub
parent
commit
9dd1049f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/base/preferences.cpp
  2. 4
      src/base/preferences.h
  3. 18
      src/gui/mainwindow.cpp

22
src/base/preferences.cpp

@ -183,15 +183,35 @@ void Preferences::setMinimizeToTray(bool b) @@ -183,15 +183,35 @@ void Preferences::setMinimizeToTray(bool b)
setValue("Preferences/General/MinimizeToTray", b);
}
bool Preferences::minimizeToTrayNotified() const
{
return value("Preferences/General/MinimizeToTrayNotified", false).toBool();
}
void Preferences::setMinimizeToTrayNotified(bool b)
{
setValue("Preferences/General/MinimizeToTrayNotified", b);
}
bool Preferences::closeToTray() const
{
return value("Preferences/General/CloseToTray", false).toBool();
return value("Preferences/General/CloseToTray", true).toBool();
}
void Preferences::setCloseToTray(bool b)
{
setValue("Preferences/General/CloseToTray", b);
}
bool Preferences::closeToTrayNotified() const
{
return value("Preferences/General/CloseToTrayNotified", false).toBool();
}
void Preferences::setCloseToTrayNotified(bool b)
{
setValue("Preferences/General/CloseToTrayNotified", b);
}
#endif
bool Preferences::isToolbarDisplayed() const

4
src/base/preferences.h

@ -286,10 +286,14 @@ public: @@ -286,10 +286,14 @@ public:
#ifndef Q_OS_MAC
bool systrayIntegration() const;
void setSystrayIntegration(bool enabled);
bool minimizeToTrayNotified() const;
void setMinimizeToTrayNotified(bool b);
bool minimizeToTray() const;
void setMinimizeToTray(bool b);
bool closeToTray() const;
void setCloseToTray(bool b);
bool closeToTrayNotified() const;
void setCloseToTrayNotified(bool b);
TrayIcon::Style trayIconStyle() const;
void setTrayIconStyle(TrayIcon::Style style);
#endif

18
src/gui/mainwindow.cpp

@ -414,8 +414,13 @@ MainWindow::MainWindow(QWidget *parent) @@ -414,8 +414,13 @@ MainWindow::MainWindow(QWidget *parent)
}
else if (pref->startMinimized()) {
showMinimized();
if (pref->minimizeToTray())
if (pref->minimizeToTray()) {
hide();
if (!pref->minimizeToTrayNotified()) {
showNotificationBaloon(tr("qBittorrent is minimized to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));
pref->setMinimizeToTrayNotified(true);
}
}
}
}
else {
@ -1139,6 +1144,10 @@ void MainWindow::closeEvent(QCloseEvent *e) @@ -1139,6 +1144,10 @@ void MainWindow::closeEvent(QCloseEvent *e)
if (!m_forceExit && m_systrayIcon && goToSystrayOnExit && !this->isHidden()) {
hide();
e->accept();
if (!pref->closeToTrayNotified()) {
showNotificationBaloon(tr("qBittorrent is closed to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));
pref->setCloseToTrayNotified(true);
}
return;
}
#endif // Q_OS_MAC
@ -1208,7 +1217,8 @@ bool MainWindow::event(QEvent *e) @@ -1208,7 +1217,8 @@ bool MainWindow::event(QEvent *e)
// Now check to see if the window is minimised
if (isMinimized()) {
qDebug("minimisation");
if (m_systrayIcon && Preferences::instance()->minimizeToTray()) {
Preferences *const pref = Preferences::instance();
if (m_systrayIcon && pref->minimizeToTray()) {
qDebug() << "Has active window:" << (qApp->activeWindow() != nullptr);
// Check if there is a modal window
bool hasModalWindow = false;
@ -1223,6 +1233,10 @@ bool MainWindow::event(QEvent *e) @@ -1223,6 +1233,10 @@ bool MainWindow::event(QEvent *e)
qDebug("Minimize to Tray enabled, hiding!");
e->ignore();
QTimer::singleShot(0, this, &QWidget::hide);
if (!pref->minimizeToTrayNotified()) {
showNotificationBaloon(tr("qBittorrent is minimized to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));
pref->setMinimizeToTrayNotified(true);
}
return true;
}
}

Loading…
Cancel
Save