From 4a765cc91fde51c1ff2fbc046fdcc4db4e57bff0 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Mon, 29 Oct 2018 10:52:06 -0500 Subject: [PATCH 1/4] Unify inconsistent notifyListener() logic Previously, this function required a `queueEmptied` bool, which I changed to `queueRunning`. But I goofed the logic on this bool; it should always be "is `processing` nullptr." --- rtgui/batchqueue.cc | 13 ++++++------- rtgui/batchqueue.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index a66fda153..6c42ef89f 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -229,7 +229,7 @@ void BatchQueue::addEntries (const std::vector& entries, bool saveBatchQueue (); redraw (); - notifyListener (true); + notifyListener (); } bool BatchQueue::saveBatchQueue () @@ -387,7 +387,7 @@ bool BatchQueue::loadBatchQueue () } redraw (); - notifyListener (true); + notifyListener (); return !fd.empty (); } @@ -460,7 +460,7 @@ void BatchQueue::cancelItems (const std::vector& items) saveBatchQueue (); redraw (); - notifyListener (true); + notifyListener (); } void BatchQueue::headItems (const std::vector& items) @@ -775,8 +775,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img) } redraw (); - const bool queueRunning = processing; - notifyListener (queueRunning); + notifyListener (); return processing ? processing->job : nullptr; } @@ -971,9 +970,9 @@ void BatchQueue::buttonPressed (LWButton* button, int actionCode, void* actionDa } } -void BatchQueue::notifyListener (bool queueRunning) +void BatchQueue::notifyListener () { - + const bool queueRunning = processing; if (listener) { NLParams* params = new NLParams; params->listener = listener; diff --git a/rtgui/batchqueue.h b/rtgui/batchqueue.h index 6b0e047cb..a922e5e1f 100644 --- a/rtgui/batchqueue.h +++ b/rtgui/batchqueue.h @@ -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 queueRunning); + void notifyListener (); BatchQueueEntry* processing; // holds the currently processed image FileCatalog* fileCatalog; From cc6cbe8347dcf9c03b21de203a6f18ed377ec7a5 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Thu, 1 Nov 2018 00:47:06 -0500 Subject: [PATCH 2/4] Distinguish between "desired" and "reported" batch queue state This allows the switch to both reflect the state of the queue and function as an input widget. --- rtgui/batchqueuepanel.cc | 74 +++++++++++++++++++++------------------- rtgui/batchqueuepanel.h | 3 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index 8da66183a..a2358a3b5 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -249,20 +249,13 @@ void BatchQueuePanel::queueSizeChanged(int qsize, bool queueRunning, bool queueE { updateTab (qsize); - if (qsize == 0 || (qsize == 1 && queueRunning)) { - qStartStop->set_sensitive(false); - } else { - qStartStop->set_sensitive(true); - } + setGuiFromBatchState(queueRunning, qsize); - if (!queueRunning) { - stopBatchProc (); - fdir->set_sensitive (true); - fformat->set_sensitive (true); + if (!queueRunning && qsize == 0 && queueShouldRun) { + // There was work, but it is all done now. + queueShouldRun = false; - if (qsize == 0) { - SoundManager::playSoundAsync(options.sndBatchQueueDone); - } + SoundManager::playSoundAsync(options.sndBatchQueueDone); } if (queueError) { @@ -273,8 +266,7 @@ void BatchQueuePanel::queueSizeChanged(int qsize, bool queueRunning, bool queueE void BatchQueuePanel::startOrStopBatchProc() { - bool state = qStartStop->get_state(); - if (state) { + if (qStartStop->get_state()) { startBatchProc(); } else { stopBatchProc(); @@ -283,22 +275,17 @@ void BatchQueuePanel::startOrStopBatchProc() void BatchQueuePanel::startBatchProc () { - // Update switch when queue started programmatically - qStartStopConn.block (true); - qStartStop->set_active(true); - qStartStopState = true; - qStartStopConn.block (false); - if (batchQueue->hasJobs()) { - fdir->set_sensitive (false); - fformat->set_sensitive (false); - if (batchQueue->getEntries().size() == 1) { - qStartStop->set_sensitive(false); - } + // Update the *desired* state of the queue, then launch it. The switch + // state is not updated here; it is changed by the queueSizeChanged() + // callback in response to the *reported* state. + queueShouldRun = true; + + // Don't need an update callback from the queue to know it is started: + setGuiFromBatchState(true, batchQueue->getEntries().size()); + saveOptions(); batchQueue->startProcessing (); - } else { - stopBatchProc (); } updateTab (batchQueue->getEntries().size()); @@ -306,20 +293,37 @@ void BatchQueuePanel::startBatchProc () void BatchQueuePanel::stopBatchProc () { - // Update switch when queue started programmatically - qStartStopConn.block (true); - qStartStop->set_active(false); - qStartStopState = false; - qStartStopConn.block (false); + // There is nothing much to do here except set the desired state, which the + // background queue thread must check. It will notify queueSizeChanged() + // when it stops. + queueShouldRun = false; updateTab (batchQueue->getEntries().size()); } +void BatchQueuePanel::setGuiFromBatchState(bool queueRunning, int qsize) +{ + // Change the GUI state in response to the reported queue state + if (qsize == 0 || (qsize == 1 && queueRunning)) { + qStartStop->set_sensitive(false); + } else { + qStartStop->set_sensitive(true); + } + + qStartStopConn.block(true); + qStartStop->set_active(queueRunning); + qStartStopConn.block(false); + + fdir->set_sensitive (!queueRunning); + fformat->set_sensitive (!queueRunning); +} + void BatchQueuePanel::addBatchQueueJobs(const std::vector& entries, bool head) { batchQueue->addEntries(entries, head); if (!qStartStop->get_active() && qAutoStart->get_active()) { + // Auto-start as if the user had pressed the qStartStop switch startBatchProc (); } } @@ -354,9 +358,9 @@ bool BatchQueuePanel::handleShortcutKey (GdkEventKey* 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; + // This function is called from the background BatchQueue thread. It + // cannot call UI functions; we keep the desired state in an atomic. + return queueShouldRun; } void BatchQueuePanel::pathFolderButtonPressed () diff --git a/rtgui/batchqueuepanel.h b/rtgui/batchqueuepanel.h index 74c9750e7..e21e01352 100644 --- a/rtgui/batchqueuepanel.h +++ b/rtgui/batchqueuepanel.h @@ -53,7 +53,7 @@ class BatchQueuePanel : public Gtk::VBox, Gtk::HBox* bottomBox; Gtk::HBox* topBox; - std::atomic qStartStopState; + std::atomic queueShouldRun; IdleRegister idle_register; @@ -76,6 +76,7 @@ private: void startBatchProc (); void stopBatchProc (); void startOrStopBatchProc(); + void setGuiFromBatchState(bool queueRunning, int qsize); void pathFolderChanged (); void pathFolderButtonPressed (); From cfb61f6fbfa17d4735bb495ddad9e1e9c7547bc4 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Thu, 1 Nov 2018 16:02:01 -0500 Subject: [PATCH 3/4] Notify GUI when batch starts Closes #4906 --- rtgui/batchqueue.cc | 2 ++ rtgui/batchqueuepanel.cc | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 6c42ef89f..6f09e25f1 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -597,6 +597,8 @@ void BatchQueue::startProcessing () // start batch processing rtengine::startBatchProcessing (next->job, this); queue_draw (); + + notifyListener(); } } } diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index a2358a3b5..57481ef1d 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -281,9 +281,6 @@ void BatchQueuePanel::startBatchProc () // callback in response to the *reported* state. queueShouldRun = true; - // Don't need an update callback from the queue to know it is started: - setGuiFromBatchState(true, batchQueue->getEntries().size()); - saveOptions(); batchQueue->startProcessing (); } From 424782e8d0546089121f4aa8274c6dd36347aeff Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Thu, 1 Nov 2018 16:02:35 -0500 Subject: [PATCH 4/4] Consolidate updateTab() calls --- rtgui/batchqueuepanel.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rtgui/batchqueuepanel.cc b/rtgui/batchqueuepanel.cc index 57481ef1d..923b6f786 100644 --- a/rtgui/batchqueuepanel.cc +++ b/rtgui/batchqueuepanel.cc @@ -247,8 +247,6 @@ void BatchQueuePanel::updateTab (int qsize, int forceOrientation) void BatchQueuePanel::queueSizeChanged(int qsize, bool queueRunning, bool queueError, const Glib::ustring& queueErrorMessage) { - updateTab (qsize); - setGuiFromBatchState(queueRunning, qsize); if (!queueRunning && qsize == 0 && queueShouldRun) { @@ -284,8 +282,6 @@ void BatchQueuePanel::startBatchProc () saveOptions(); batchQueue->startProcessing (); } - - updateTab (batchQueue->getEntries().size()); } void BatchQueuePanel::stopBatchProc () @@ -294,8 +290,6 @@ void BatchQueuePanel::stopBatchProc () // background queue thread must check. It will notify queueSizeChanged() // when it stops. queueShouldRun = false; - - updateTab (batchQueue->getEntries().size()); } void BatchQueuePanel::setGuiFromBatchState(bool queueRunning, int qsize) @@ -313,6 +307,8 @@ void BatchQueuePanel::setGuiFromBatchState(bool queueRunning, int qsize) fdir->set_sensitive (!queueRunning); fformat->set_sensitive (!queueRunning); + + updateTab(qsize); } void BatchQueuePanel::addBatchQueueJobs(const std::vector& entries, bool head)