diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 9f8341c2e..a62068e8a 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -20,6 +20,7 @@ #include #include #include +#include FormMain *FormMain::s_instance; @@ -122,9 +123,9 @@ void FormMain::processExecutionMessage(const QString &message) { if (message == APP_IS_RUNNING) { if (SystemTrayIcon::isSystemTrayActivated()) { SystemTrayIcon::instance()->showMessage(APP_NAME, - tr("Application is already running."), - QSystemTrayIcon::Information, - TRAY_ICON_BUBBLE_TIMEOUT); + tr("Application is already running."), + QSystemTrayIcon::Information, + TRAY_ICON_BUBBLE_TIMEOUT); } display(); @@ -167,17 +168,21 @@ void FormMain::display() { QtSingleApplication::alert(this); } -void FormMain::onCommitData(QSessionManager &manager) { - Q_UNUSED(manager) - qDebug("OS asked application to commit its data."); +void FormMain::onCommitData(QSessionManager &manager) { + QFile("/home/martin/Dokumenty/aaa").open(QIODevice::ReadWrite); + + manager.release(); } void FormMain::onSaveState(QSessionManager &manager) { - Q_UNUSED(manager) - qDebug("OS asked application to save its state."); + QFile("/home/martin/Dokumenty/ccc").open(QIODevice::ReadWrite); + + manager.release(); } void FormMain::onAboutToQuit() { + QFile("/home/martin/Dokumenty/bbb").open(QIODevice::ReadWrite); + // Make sure that we obtain close lock // BEFORE even trying to quit the application. if (SystemFactory::getInstance()->applicationCloseLock()->tryLockForWrite(CLOSE_LOCK_TIMEOUT)) { @@ -325,22 +330,23 @@ void FormMain::loadWebBrowserMenu(int index) { m_ui->m_actionCloseCurrentTab->setEnabled(m_ui->m_tabWidget->tabBar()->tabType(index) == TabBar::Closable); } -void FormMain::closeEvent(QCloseEvent *event) { - if (SystemTrayIcon::isSystemTrayActivated()) { - if (Settings::instance()->value(APP_CFG_GUI, - "close_win_action", - 0).toInt() == 0) { - // User selected to minimize the application if its main - // window gets closed and tray icon is activated. - hide(); - event->ignore(); - } - else { - // User selected to quit the application if its main - // window gets closed and tray icon is activated. - qApp->quit(); +void FormMain::changeEvent(QEvent *event) { + switch (event->type()) { + case QEvent::WindowStateChange: { + if (SystemTrayIcon::isSystemTrayActivated()) { + if (this->windowState() & Qt::WindowMinimized) { + QTimer::singleShot(250, this, SLOT(hide())); + } + } + + break; } + + default: + break; } + + QMainWindow::changeEvent(event); } void FormMain::showAbout() { diff --git a/src/gui/formmain.h b/src/gui/formmain.h index 8b61ecff5..fccdaa374 100644 --- a/src/gui/formmain.h +++ b/src/gui/formmain.h @@ -46,7 +46,7 @@ class FormMain : public QMainWindow { void createConnections(); // Event handler reimplementations. - void closeEvent(QCloseEvent *event); + void changeEvent(QEvent *event); bool event(QEvent *event); // Sets up proper icons for this widget. @@ -87,6 +87,7 @@ class FormMain : public QMainWindow { void showAbout(); private: + bool m_quitting; Ui::FormMain *m_ui; QMenu *m_trayMenu; StatusBar *m_statusBar; diff --git a/src/gui/formsettings.cpp b/src/gui/formsettings.cpp index 4af02309b..e9e1e0e87 100755 --- a/src/gui/formsettings.cpp +++ b/src/gui/formsettings.cpp @@ -456,9 +456,6 @@ void FormSettings::loadInterface() { m_ui->m_radioTrayOff->setChecked(!settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()); - m_ui->m_cmbTrayClose->setCurrentIndex(settings->value(APP_CFG_GUI, - "close_win_action", - 0).toInt()); m_ui->m_checkHidden->setChecked(settings->value(APP_CFG_GUI, "start_hidden", false).toBool()); @@ -550,8 +547,6 @@ void FormSettings::saveInterface() { if (SystemTrayIcon::isSystemTrayAvailable()) { settings->setValue(APP_CFG_GUI, "use_tray_icon", m_ui->m_radioTrayOn->isChecked()); - settings->setValue(APP_CFG_GUI, "close_win_action", - m_ui->m_cmbTrayClose->currentIndex()); settings->setValue(APP_CFG_GUI, "start_hidden", m_ui->m_checkHidden->isChecked()); if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) { diff --git a/src/gui/formsettings.ui b/src/gui/formsettings.ui index 21c612b37..2bff3a2fd 100644 --- a/src/gui/formsettings.ui +++ b/src/gui/formsettings.ui @@ -17,7 +17,7 @@ - 0 + 2 @@ -51,8 +51,8 @@ 0 0 - 576 - 373 + 100 + 30 @@ -79,7 +79,7 @@ QTabWidget::North - 0 + 1 @@ -216,6 +216,9 @@ Tray icon + + QFormLayout::ExpandingFieldsGrow + @@ -233,28 +236,7 @@ - - - - When main window is closed, then - - - - - - - - hide it. - - - - - quit the application. - - - - - + Start application hidden @@ -802,38 +784,6 @@ - - m_radioTrayOn - toggled(bool) - m_lblTrayClose - setEnabled(bool) - - - 508 - 102 - - - 419 - 128 - - - - - m_radioTrayOn - toggled(bool) - m_cmbTrayClose - setEnabled(bool) - - - 508 - 102 - - - 678 - 128 - - - m_radioTrayOn toggled(bool)