Fixed closing events.

This commit is contained in:
Martin Rotter 2014-01-12 19:41:13 +01:00
parent a9391c1ce4
commit 50cb0ba105
4 changed files with 38 additions and 86 deletions

View File

@ -20,6 +20,7 @@
#include <QRect> #include <QRect>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QReadWriteLock> #include <QReadWriteLock>
#include <QTimer>
FormMain *FormMain::s_instance; FormMain *FormMain::s_instance;
@ -122,9 +123,9 @@ void FormMain::processExecutionMessage(const QString &message) {
if (message == APP_IS_RUNNING) { if (message == APP_IS_RUNNING) {
if (SystemTrayIcon::isSystemTrayActivated()) { if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->showMessage(APP_NAME, SystemTrayIcon::instance()->showMessage(APP_NAME,
tr("Application is already running."), tr("Application is already running."),
QSystemTrayIcon::Information, QSystemTrayIcon::Information,
TRAY_ICON_BUBBLE_TIMEOUT); TRAY_ICON_BUBBLE_TIMEOUT);
} }
display(); display();
@ -167,17 +168,21 @@ void FormMain::display() {
QtSingleApplication::alert(this); QtSingleApplication::alert(this);
} }
void FormMain::onCommitData(QSessionManager &manager) { void FormMain::onCommitData(QSessionManager &manager) {
Q_UNUSED(manager) QFile("/home/martin/Dokumenty/aaa").open(QIODevice::ReadWrite);
qDebug("OS asked application to commit its data.");
manager.release();
} }
void FormMain::onSaveState(QSessionManager &manager) { void FormMain::onSaveState(QSessionManager &manager) {
Q_UNUSED(manager) QFile("/home/martin/Dokumenty/ccc").open(QIODevice::ReadWrite);
qDebug("OS asked application to save its state.");
manager.release();
} }
void FormMain::onAboutToQuit() { void FormMain::onAboutToQuit() {
QFile("/home/martin/Dokumenty/bbb").open(QIODevice::ReadWrite);
// Make sure that we obtain close lock // Make sure that we obtain close lock
// BEFORE even trying to quit the application. // BEFORE even trying to quit the application.
if (SystemFactory::getInstance()->applicationCloseLock()->tryLockForWrite(CLOSE_LOCK_TIMEOUT)) { 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); m_ui->m_actionCloseCurrentTab->setEnabled(m_ui->m_tabWidget->tabBar()->tabType(index) == TabBar::Closable);
} }
void FormMain::closeEvent(QCloseEvent *event) { void FormMain::changeEvent(QEvent *event) {
if (SystemTrayIcon::isSystemTrayActivated()) { switch (event->type()) {
if (Settings::instance()->value(APP_CFG_GUI, case QEvent::WindowStateChange: {
"close_win_action", if (SystemTrayIcon::isSystemTrayActivated()) {
0).toInt() == 0) { if (this->windowState() & Qt::WindowMinimized) {
// User selected to minimize the application if its main QTimer::singleShot(250, this, SLOT(hide()));
// window gets closed and tray icon is activated. }
hide(); }
event->ignore();
} break;
else {
// User selected to quit the application if its main
// window gets closed and tray icon is activated.
qApp->quit();
} }
default:
break;
} }
QMainWindow::changeEvent(event);
} }
void FormMain::showAbout() { void FormMain::showAbout() {

View File

@ -46,7 +46,7 @@ class FormMain : public QMainWindow {
void createConnections(); void createConnections();
// Event handler reimplementations. // Event handler reimplementations.
void closeEvent(QCloseEvent *event); void changeEvent(QEvent *event);
bool event(QEvent *event); bool event(QEvent *event);
// Sets up proper icons for this widget. // Sets up proper icons for this widget.
@ -87,6 +87,7 @@ class FormMain : public QMainWindow {
void showAbout(); void showAbout();
private: private:
bool m_quitting;
Ui::FormMain *m_ui; Ui::FormMain *m_ui;
QMenu *m_trayMenu; QMenu *m_trayMenu;
StatusBar *m_statusBar; StatusBar *m_statusBar;

View File

@ -456,9 +456,6 @@ void FormSettings::loadInterface() {
m_ui->m_radioTrayOff->setChecked(!settings->value(APP_CFG_GUI, m_ui->m_radioTrayOff->setChecked(!settings->value(APP_CFG_GUI,
"use_tray_icon", "use_tray_icon",
true).toBool()); 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, m_ui->m_checkHidden->setChecked(settings->value(APP_CFG_GUI,
"start_hidden", "start_hidden",
false).toBool()); false).toBool());
@ -550,8 +547,6 @@ void FormSettings::saveInterface() {
if (SystemTrayIcon::isSystemTrayAvailable()) { if (SystemTrayIcon::isSystemTrayAvailable()) {
settings->setValue(APP_CFG_GUI, "use_tray_icon", settings->setValue(APP_CFG_GUI, "use_tray_icon",
m_ui->m_radioTrayOn->isChecked()); 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", settings->setValue(APP_CFG_GUI, "start_hidden",
m_ui->m_checkHidden->isChecked()); m_ui->m_checkHidden->isChecked());
if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) { if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {

View File

@ -17,7 +17,7 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings"> <widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="m_pageGeneral"> <widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5"> <layout class="QFormLayout" name="formLayout_5">
@ -51,8 +51,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>576</width> <width>100</width>
<height>373</height> <height>30</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -79,7 +79,7 @@
<enum>QTabWidget::North</enum> <enum>QTabWidget::North</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="m_tabIconSkin"> <widget class="QWidget" name="m_tabIconSkin">
<attribute name="title"> <attribute name="title">
@ -216,6 +216,9 @@
<string>Tray icon</string> <string>Tray icon</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="m_radioTrayOff"> <widget class="QRadioButton" name="m_radioTrayOff">
<property name="text"> <property name="text">
@ -233,28 +236,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0" colspan="2">
<widget class="QLabel" name="m_lblTrayClose">
<property name="text">
<string>When main window is closed, then</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_cmbTrayClose">
<item>
<property name="text">
<string>hide it.</string>
</property>
</item>
<item>
<property name="text">
<string>quit the application.</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkHidden"> <widget class="QCheckBox" name="m_checkHidden">
<property name="text"> <property name="text">
<string>Start application hidden</string> <string>Start application hidden</string>
@ -802,38 +784,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal>
<receiver>m_lblTrayClose</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>508</x>
<y>102</y>
</hint>
<hint type="destinationlabel">
<x>419</x>
<y>128</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal>
<receiver>m_cmbTrayClose</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>508</x>
<y>102</y>
</hint>
<hint type="destinationlabel">
<x>678</x>
<y>128</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>m_radioTrayOn</sender> <sender>m_radioTrayOn</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>