Merge pull request #9274 from sledgehammer999/tray_close_notification

Notify users on 1st time close/minimize to tray
This commit is contained in:
sledgehammer999 2018-08-11 00:13:41 +03:00 committed by GitHub
commit 9dd1049f24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 3 deletions

View file

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

View file

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

View file

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