From 52c943ca0e5edfcbd82207a99593ae603654f3f2 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 26 Oct 2018 00:20:02 -0500 Subject: [PATCH 1/6] Mark BatchQueuePanel implementation functions as private --- rtgui/batchqueuepanel.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rtgui/batchqueuepanel.h b/rtgui/batchqueuepanel.h index 3f1da85ce..73cb3ba6e 100644 --- a/rtgui/batchqueuepanel.h +++ b/rtgui/batchqueuepanel.h @@ -60,22 +60,23 @@ public: void init (RTWindow* parent); void addBatchQueueJobs(const std::vector& entries , bool head = false); + void saveOptions (); + + bool handleShortcutKey (GdkEventKey* event); // batchqueuelistener interface void queueSizeChanged(int qsize, bool queueEmptied, bool queueError, const Glib::ustring& queueErrorMessage); bool canStartNext(); +private: void startBatchProc (); void stopBatchProc (); void startOrStopBatchProc(); - void saveOptions (); void pathFolderChanged (); void pathFolderButtonPressed (); void formatChanged(const Glib::ustring& format) override; void updateTab (int qsize, int forceOrientation = 0); // forceOrientation=0: base on options / 1: horizontal / 2: vertical - - bool handleShortcutKey (GdkEventKey* event); }; #endif From 7d5fe6d1c8c9e681e64522544055089933e4d2d6 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 26 Oct 2018 00:52:15 -0500 Subject: [PATCH 2/6] Reenable batch queue interface on queue length notification This removes the need for canStartNext() to do any UI updates. --- rtgui/batchqueue.cc | 24 +++++++++++------------- rtgui/batchqueue.h | 4 ++-- rtgui/batchqueuepanel.cc | 8 +++++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 1d52c96e6..191131352 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -45,7 +45,7 @@ namespace struct NLParams { BatchQueueListener* listener; int qsize; - bool queueEmptied; + bool queueRunning; bool queueError; Glib::ustring queueErrorMessage; }; @@ -53,7 +53,7 @@ struct NLParams { int bqnotifylistenerUI (void* data) { NLParams* params = static_cast(data); - params->listener->queueSizeChanged (params->qsize, params->queueEmptied, params->queueError, params->queueErrorMessage); + params->listener->queueSizeChanged (params->qsize, params->queueRunning, params->queueError, params->queueErrorMessage); delete params; return 0; } @@ -229,7 +229,7 @@ void BatchQueue::addEntries (const std::vector& entries, bool saveBatchQueue (); redraw (); - notifyListener (false); + notifyListener (true); } bool BatchQueue::saveBatchQueue () @@ -387,7 +387,7 @@ bool BatchQueue::loadBatchQueue () } redraw (); - notifyListener (false); + notifyListener (true); return !fd.empty (); } @@ -460,7 +460,7 @@ void BatchQueue::cancelItems (const std::vector& items) saveBatchQueue (); redraw (); - notifyListener (false); + notifyListener (true); } void BatchQueue::headItems (const std::vector& items) @@ -640,7 +640,7 @@ void BatchQueue::error(const Glib::ustring& descr) if (listener) { NLParams* params = new NLParams; params->listener = listener; - params->queueEmptied = false; + params->queueRunning = false; params->queueError = true; params->queueErrorMessage = descr; idle_register.add(bqnotifylistenerUI, params); @@ -706,7 +706,6 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img) Glib::ustring processedParams = processing->savedParamsFile; // delete from the queue - bool queueEmptied = false; bool remove_button_set = false; { @@ -718,9 +717,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img) fd.erase (fd.begin()); // return next job - if (fd.empty()) { - queueEmptied = true; - } else if (listener && listener->canStartNext ()) { + if (!fd.empty() && listener && listener->canStartNext ()) { BatchQueueEntry* next = static_cast(fd[0]); // tag it as selected and set sequence next->processing = true; @@ -778,7 +775,8 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img) } redraw (); - notifyListener (queueEmptied); + const bool queueRunning = (processing != nullptr); + notifyListener (queueRunning); return processing ? processing->job : nullptr; } @@ -973,7 +971,7 @@ void BatchQueue::buttonPressed (LWButton* button, int actionCode, void* actionDa } } -void BatchQueue::notifyListener (bool queueEmptied) +void BatchQueue::notifyListener (bool queueRunning) { if (listener) { @@ -983,7 +981,7 @@ void BatchQueue::notifyListener (bool queueEmptied) MYREADERLOCK(l, entryRW); params->qsize = fd.size(); } - params->queueEmptied = queueEmptied; + params->queueRunning = queueRunning; params->queueError = false; idle_register.add(bqnotifylistenerUI, params); } diff --git a/rtgui/batchqueue.h b/rtgui/batchqueue.h index 41c30da3f..6b0e047cb 100644 --- a/rtgui/batchqueue.h +++ b/rtgui/batchqueue.h @@ -31,7 +31,7 @@ class BatchQueueListener public: virtual ~BatchQueueListener() = default; - virtual void queueSizeChanged(int qsize, bool queueEmptied, bool queueError, const Glib::ustring& queueErrorMessage) = 0; + virtual void queueSizeChanged(int qsize, bool queueRunning, bool queueError, const Glib::ustring& queueErrorMessage) = 0; virtual bool canStartNext() = 0; }; @@ -93,7 +93,7 @@ protected: Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format); Glib::ustring getTempFilenameForParams( const Glib::ustring &filename ); bool saveBatchQueue (); - void notifyListener (bool queueEmptied); + void notifyListener (bool queueRunning); BatchQueueEntry* processing; // holds the currently processed image FileCatalog* fileCatalog; diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index 83a0f37ae..f572a6772 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -245,7 +245,7 @@ void BatchQueuePanel::updateTab (int qsize, int forceOrientation) } } -void BatchQueuePanel::queueSizeChanged(int qsize, bool queueEmptied, bool queueError, const Glib::ustring& queueErrorMessage) +void BatchQueuePanel::queueSizeChanged(int qsize, bool queueRunning, bool queueError, const Glib::ustring& queueErrorMessage) { updateTab (qsize); @@ -255,12 +255,14 @@ void BatchQueuePanel::queueSizeChanged(int qsize, bool queueEmptied, bool queueE qStartStop->set_sensitive(true); } - if (queueEmptied || queueError) { + if (!queueRunning) { stopBatchProc (); fdir->set_sensitive (true); fformat->set_sensitive (true); - SoundManager::playSoundAsync(options.sndBatchQueueDone); + if (qsize == 0) { + SoundManager::playSoundAsync(options.sndBatchQueueDone); + } } if (queueError) { From 09275b58269b3f3be6c53f600ada5c1cf488ca33 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 26 Oct 2018 00:53:39 -0500 Subject: [PATCH 3/6] Store qStartStop state in atomic for background thread Closes #4882. --- rtgui/batchqueuepanel.cc | 13 +++++-------- rtgui/batchqueuepanel.h | 4 ++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index f572a6772..b61f60ee7 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -286,6 +286,7 @@ void BatchQueuePanel::startBatchProc () // Update switch when queue started programmatically qStartStopConn.block (true); qStartStop->set_active(true); + qStartStopState = true; qStartStopConn.block (false); if (batchQueue->hasJobs()) { @@ -308,6 +309,7 @@ void BatchQueuePanel::stopBatchProc () // Update switch when queue started programmatically qStartStopConn.block (true); qStartStop->set_active(false); + qStartStopState = false; qStartStopConn.block (false); updateTab (batchQueue->getEntries().size()); @@ -324,14 +326,9 @@ void BatchQueuePanel::addBatchQueueJobs(const std::vector& ent bool BatchQueuePanel::canStartNext () { -// GThreadLock lock; - if (qStartStop->get_active()) { - return true; - } else { - fdir->set_sensitive (true); - fformat->set_sensitive (true); - return false; - } + // This function is called from the background BatchQueue thread. + // It cannot call UI functions, so grab the stored state of qStartStop. + return qStartStopState; } void BatchQueuePanel::saveOptions () diff --git a/rtgui/batchqueuepanel.h b/rtgui/batchqueuepanel.h index 73cb3ba6e..89b8d8910 100644 --- a/rtgui/batchqueuepanel.h +++ b/rtgui/batchqueuepanel.h @@ -19,6 +19,8 @@ #ifndef _BATCHQUEUEPANEL_ #define _BATCHQUEUEPANEL_ +#include + #include #include "batchqueue.h" #include "saveformatpanel.h" @@ -53,6 +55,8 @@ class BatchQueuePanel : public Gtk::VBox, IdleRegister idle_register; + std::atomic qStartStopState; + public: explicit BatchQueuePanel (FileCatalog* aFileCatalog); ~BatchQueuePanel(); From 8a6e0a7f1929839ef36e3c63d1f43680c8b17bad Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 26 Oct 2018 01:46:30 -0500 Subject: [PATCH 4/6] Cleanup from code review --- rtgui/batchqueue.cc | 2 +- rtgui/batchqueuepanel.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 191131352..a66fda153 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -775,7 +775,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img) } redraw (); - const bool queueRunning = (processing != nullptr); + const bool queueRunning = processing; notifyListener (queueRunning); return processing ? processing->job : nullptr; diff --git a/rtgui/batchqueuepanel.h b/rtgui/batchqueuepanel.h index 89b8d8910..a05d94fe3 100644 --- a/rtgui/batchqueuepanel.h +++ b/rtgui/batchqueuepanel.h @@ -53,10 +53,10 @@ class BatchQueuePanel : public Gtk::VBox, Gtk::HBox* bottomBox; Gtk::HBox* topBox; - IdleRegister idle_register; - std::atomic qStartStopState; + IdleRegister idle_register; + public: explicit BatchQueuePanel (FileCatalog* aFileCatalog); ~BatchQueuePanel(); From cb3cc6cad14b6229564f7efcac252b94495aa15d Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 26 Oct 2018 09:23:46 -0500 Subject: [PATCH 5/6] Fix permanently disabled button when stopping on next-to-last image --- rtgui/batchqueuepanel.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index b61f60ee7..1679d9365 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -249,7 +249,7 @@ void BatchQueuePanel::queueSizeChanged(int qsize, bool queueRunning, bool queueE { updateTab (qsize); - if (qsize == 0 || (qsize == 1 && !fdir->get_sensitive())) { + if (qsize == 0 || (qsize == 1 && queueRunning)) { qStartStop->set_sensitive(false); } else { qStartStop->set_sensitive(true); From 9a22e89125c4c9548fd7c5273fb88e1d393d77a9 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 26 Oct 2018 09:26:18 -0500 Subject: [PATCH 6/6] Cleanup: make impl function order match header, fix declaration var name --- rtgui/batchqueuepanel.cc | 54 ++++++++++++++++++++-------------------- rtgui/batchqueuepanel.h | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index 1679d9365..8da66183a 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -324,13 +324,6 @@ void BatchQueuePanel::addBatchQueueJobs(const std::vector& ent } } -bool BatchQueuePanel::canStartNext () -{ - // This function is called from the background BatchQueue thread. - // It cannot call UI functions, so grab the stored state of qStartStop. - return qStartStopState; -} - void BatchQueuePanel::saveOptions () { @@ -339,6 +332,33 @@ void BatchQueuePanel::saveOptions () options.procQueueEnabled = qAutoStart->get_active(); } +bool BatchQueuePanel::handleShortcutKey (GdkEventKey* event) +{ + bool ctrl = event->state & GDK_CONTROL_MASK; + + if (ctrl) { + switch(event->keyval) { + case GDK_KEY_s: + if (qStartStop->get_active()) { + stopBatchProc(); + } else { + startBatchProc(); + } + + return true; + } + } + + return batchQueue->keyPressed (event); +} + +bool BatchQueuePanel::canStartNext () +{ + // This function is called from the background BatchQueue thread. + // It cannot call UI functions, so grab the stored state of qStartStop. + return qStartStopState; +} + void BatchQueuePanel::pathFolderButtonPressed () { @@ -368,23 +388,3 @@ void BatchQueuePanel::formatChanged(const Glib::ustring& format) { options.saveFormatBatch = saveFormatPanel->getFormat(); } - -bool BatchQueuePanel::handleShortcutKey (GdkEventKey* event) -{ - bool ctrl = event->state & GDK_CONTROL_MASK; - - if (ctrl) { - switch(event->keyval) { - case GDK_KEY_s: - if (qStartStop->get_active()) { - stopBatchProc(); - } else { - startBatchProc(); - } - - return true; - } - } - - return batchQueue->keyPressed (event); -} diff --git a/rtgui/batchqueuepanel.h b/rtgui/batchqueuepanel.h index a05d94fe3..74c9750e7 100644 --- a/rtgui/batchqueuepanel.h +++ b/rtgui/batchqueuepanel.h @@ -69,7 +69,7 @@ public: bool handleShortcutKey (GdkEventKey* event); // batchqueuelistener interface - void queueSizeChanged(int qsize, bool queueEmptied, bool queueError, const Glib::ustring& queueErrorMessage); + void queueSizeChanged(int qsize, bool queueRunning, bool queueError, const Glib::ustring& queueErrorMessage); bool canStartNext(); private: