From fff0cc76efc7ee574e75172c72d18a9652ab99cf Mon Sep 17 00:00:00 2001 From: lordmulder Date: Wed, 14 May 2014 17:13:42 +0200 Subject: [PATCH] Minimize main window into the notification area ("systray"), when trying to close the program while we still have running jobs. --- src/model_preferences.cpp | 4 +++- src/model_preferences.h | 1 + src/win_main.cpp | 45 +++++++++++++++++++++++++++++++++++---- src/win_main.h | 3 +++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/model_preferences.cpp b/src/model_preferences.cpp index 23082f6..044538e 100644 --- a/src/model_preferences.cpp +++ b/src/model_preferences.cpp @@ -81,7 +81,7 @@ void PreferencesModel::initPreferences(PreferencesModel *preferences) INIT_VALUE(NoUpdateReminder, false); INIT_VALUE(AbortOnTimeout, true ); INIT_VALUE(SkipVersionTest, false); - + INIT_VALUE(NoSystrayWarning, false); } void PreferencesModel::loadPreferences(PreferencesModel *preferences) @@ -101,6 +101,7 @@ void PreferencesModel::loadPreferences(PreferencesModel *preferences) LOAD_VALUE_B(EnableSounds ); LOAD_VALUE_B(DisableWarnings ); LOAD_VALUE_B(NoUpdateReminder ); + LOAD_VALUE_B(NoSystrayWarning ); //Validation preferences->setProcessPriority(qBound(-2, preferences->getProcessPriority(), 2)); @@ -123,6 +124,7 @@ void PreferencesModel::savePreferences(PreferencesModel *preferences) STORE_VALUE(EnableSounds ); STORE_VALUE(DisableWarnings ); STORE_VALUE(NoUpdateReminder ); + STORE_VALUE(NoSystrayWarning ); settings.sync(); } diff --git a/src/model_preferences.h b/src/model_preferences.h index 6f24968..6ddf271 100644 --- a/src/model_preferences.h +++ b/src/model_preferences.h @@ -65,6 +65,7 @@ public: PREFERENCES_MAKE_B(NoUpdateReminder) PREFERENCES_MAKE_B(AbortOnTimeout) PREFERENCES_MAKE_B(SkipVersionTest) + PREFERENCES_MAKE_B(NoSystrayWarning) public: static void initPreferences(PreferencesModel *preferences); diff --git a/src/win_main.cpp b/src/win_main.cpp index 55058cd..cf18876 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include @@ -94,6 +95,7 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc) m_preferences(NULL), m_recentlyUsed(NULL), m_status(STATUS_PRE_INIT), + m_sysTray(new QSystemTrayIcon(this)), ui(new Ui::MainWindow()) { //Init the dialog, from the .ui file @@ -228,6 +230,11 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures, IPC *ipc) connect(ui->splitter, SIGNAL(splitterMoved(int, int)), this, SLOT(updateLabelPos())); updateLabelPos(); + //Init system tray icon + m_sysTray->setToolTip(this->windowTitle()); + m_sysTray->setIcon(this->windowIcon()); + connect(m_sysTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayActived())); + //Create corner widget QLabel *checkUp = new QLabel(ui->menubar); checkUp->setText(QString(" %1   ").arg(tr("Check for Updates"))); @@ -275,6 +282,7 @@ MainWindow::~MainWindow(void) VapourSynthCheckThread::unload(); AvisynthCheckThread::unload(); + delete m_sysTray; delete ui; } @@ -424,7 +432,12 @@ void MainWindow::moveButtonPressed(void) */ void MainWindow::pauseButtonPressed(bool checked) { - ENSURE_APP_IS_IDLE(); + if(m_status != STATUS_IDLE) + { + x264_beep(x264_beep_warning); + qWarning("Cannot perfrom this action at this time!"); + ui->buttonPauseJob->setChecked(!checked); + } if(checked) { @@ -1097,6 +1110,11 @@ void MainWindow::handleCommand(const int &command, const QStringList &args, cons return; } + if((!isVisible()) || m_sysTray->isVisible()) + { + sysTrayActived(); + } + x264_bring_to_front(this); #ifdef IPC_LOGGING @@ -1231,6 +1249,16 @@ void MainWindow::jobListKeyPressed(const int &tag) } } +/* + * System tray was activated + */ +void MainWindow::sysTrayActived(void) +{ + m_sysTray->hide(); + showNormal(); + x264_bring_to_front(this); +} + /////////////////////////////////////////////////////////////////////////////// // Event functions /////////////////////////////////////////////////////////////////////////////// @@ -1266,9 +1294,18 @@ void MainWindow::closeEvent(QCloseEvent *e) if(countRunningJobs() > 0) { e->ignore(); - m_status = STATUS_BLOCKED; - QMessageBox::warning(this, tr("Jobs Are Running"), tr("Sorry, can not exit while there still are running jobs!")); - m_status = STATUS_IDLE; + if(!m_preferences->getNoSystrayWarning()) + { + m_status = STATUS_BLOCKED; + if(QMessageBox::warning(this, tr("Jobs Are Running"), tr("You still have running jobs, application will be minimized to notification area!"), tr("OK"), tr("Don't Show Again")) == 1) + { + m_preferences->setNoSystrayWarning(true); + PreferencesModel::savePreferences(m_preferences); + } + m_status = STATUS_IDLE; + } + hide(); + m_sysTray->show(); return; } diff --git a/src/win_main.h b/src/win_main.h index 51dd242..f20b5ab 100644 --- a/src/win_main.h +++ b/src/win_main.h @@ -35,6 +35,7 @@ class RecentlyUsed; class InputEventFilter; class QModelIndex; class QLabel; +class QSystemTrayIcon; enum JobStatus; namespace Ui @@ -75,6 +76,7 @@ private: QLabel *m_label; IPC *const m_ipc; + QSystemTrayIcon *const m_sysTray; InputEventFilter *m_inputFilter_jobList; InputEventFilter *m_inputFilter_version; @@ -125,6 +127,7 @@ private slots: void showWebLink(void); void shutdownComputer(void); void startButtonPressed(void); + void sysTrayActived(void); void updateLabelPos(void); void versionLabelMouseClicked(const int &tag); };