Merge pull request #4895 from thirtythreeforty/proper-switch-handling
Properly handle queue start/stop switch
This commit is contained in:
@@ -45,7 +45,7 @@ namespace
|
|||||||
struct NLParams {
|
struct NLParams {
|
||||||
BatchQueueListener* listener;
|
BatchQueueListener* listener;
|
||||||
int qsize;
|
int qsize;
|
||||||
bool queueEmptied;
|
bool queueRunning;
|
||||||
bool queueError;
|
bool queueError;
|
||||||
Glib::ustring queueErrorMessage;
|
Glib::ustring queueErrorMessage;
|
||||||
};
|
};
|
||||||
@@ -53,7 +53,7 @@ struct NLParams {
|
|||||||
int bqnotifylistenerUI (void* data)
|
int bqnotifylistenerUI (void* data)
|
||||||
{
|
{
|
||||||
NLParams* params = static_cast<NLParams*>(data);
|
NLParams* params = static_cast<NLParams*>(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;
|
delete params;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ void BatchQueue::addEntries (const std::vector<BatchQueueEntry*>& entries, bool
|
|||||||
saveBatchQueue ();
|
saveBatchQueue ();
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
notifyListener (false);
|
notifyListener (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatchQueue::saveBatchQueue ()
|
bool BatchQueue::saveBatchQueue ()
|
||||||
@@ -387,7 +387,7 @@ bool BatchQueue::loadBatchQueue ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
notifyListener (false);
|
notifyListener (true);
|
||||||
|
|
||||||
return !fd.empty ();
|
return !fd.empty ();
|
||||||
}
|
}
|
||||||
@@ -460,7 +460,7 @@ void BatchQueue::cancelItems (const std::vector<ThumbBrowserEntryBase*>& items)
|
|||||||
saveBatchQueue ();
|
saveBatchQueue ();
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
notifyListener (false);
|
notifyListener (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::headItems (const std::vector<ThumbBrowserEntryBase*>& items)
|
void BatchQueue::headItems (const std::vector<ThumbBrowserEntryBase*>& items)
|
||||||
@@ -640,7 +640,7 @@ void BatchQueue::error(const Glib::ustring& descr)
|
|||||||
if (listener) {
|
if (listener) {
|
||||||
NLParams* params = new NLParams;
|
NLParams* params = new NLParams;
|
||||||
params->listener = listener;
|
params->listener = listener;
|
||||||
params->queueEmptied = false;
|
params->queueRunning = false;
|
||||||
params->queueError = true;
|
params->queueError = true;
|
||||||
params->queueErrorMessage = descr;
|
params->queueErrorMessage = descr;
|
||||||
idle_register.add(bqnotifylistenerUI, params);
|
idle_register.add(bqnotifylistenerUI, params);
|
||||||
@@ -706,7 +706,6 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img)
|
|||||||
Glib::ustring processedParams = processing->savedParamsFile;
|
Glib::ustring processedParams = processing->savedParamsFile;
|
||||||
|
|
||||||
// delete from the queue
|
// delete from the queue
|
||||||
bool queueEmptied = false;
|
|
||||||
bool remove_button_set = false;
|
bool remove_button_set = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -718,9 +717,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img)
|
|||||||
fd.erase (fd.begin());
|
fd.erase (fd.begin());
|
||||||
|
|
||||||
// return next job
|
// return next job
|
||||||
if (fd.empty()) {
|
if (!fd.empty() && listener && listener->canStartNext ()) {
|
||||||
queueEmptied = true;
|
|
||||||
} else if (listener && listener->canStartNext ()) {
|
|
||||||
BatchQueueEntry* next = static_cast<BatchQueueEntry*>(fd[0]);
|
BatchQueueEntry* next = static_cast<BatchQueueEntry*>(fd[0]);
|
||||||
// tag it as selected and set sequence
|
// tag it as selected and set sequence
|
||||||
next->processing = true;
|
next->processing = true;
|
||||||
@@ -778,7 +775,8 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img)
|
|||||||
}
|
}
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
notifyListener (queueEmptied);
|
const bool queueRunning = processing;
|
||||||
|
notifyListener (queueRunning);
|
||||||
|
|
||||||
return processing ? processing->job : nullptr;
|
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) {
|
if (listener) {
|
||||||
@@ -983,7 +981,7 @@ void BatchQueue::notifyListener (bool queueEmptied)
|
|||||||
MYREADERLOCK(l, entryRW);
|
MYREADERLOCK(l, entryRW);
|
||||||
params->qsize = fd.size();
|
params->qsize = fd.size();
|
||||||
}
|
}
|
||||||
params->queueEmptied = queueEmptied;
|
params->queueRunning = queueRunning;
|
||||||
params->queueError = false;
|
params->queueError = false;
|
||||||
idle_register.add(bqnotifylistenerUI, params);
|
idle_register.add(bqnotifylistenerUI, params);
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ class BatchQueueListener
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BatchQueueListener() = default;
|
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;
|
virtual bool canStartNext() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ protected:
|
|||||||
Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format);
|
Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format);
|
||||||
Glib::ustring getTempFilenameForParams( const Glib::ustring &filename );
|
Glib::ustring getTempFilenameForParams( const Glib::ustring &filename );
|
||||||
bool saveBatchQueue ();
|
bool saveBatchQueue ();
|
||||||
void notifyListener (bool queueEmptied);
|
void notifyListener (bool queueRunning);
|
||||||
|
|
||||||
BatchQueueEntry* processing; // holds the currently processed image
|
BatchQueueEntry* processing; // holds the currently processed image
|
||||||
FileCatalog* fileCatalog;
|
FileCatalog* fileCatalog;
|
||||||
|
@@ -245,22 +245,24 @@ 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);
|
updateTab (qsize);
|
||||||
|
|
||||||
if (qsize == 0 || (qsize == 1 && !fdir->get_sensitive())) {
|
if (qsize == 0 || (qsize == 1 && queueRunning)) {
|
||||||
qStartStop->set_sensitive(false);
|
qStartStop->set_sensitive(false);
|
||||||
} else {
|
} else {
|
||||||
qStartStop->set_sensitive(true);
|
qStartStop->set_sensitive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queueEmptied || queueError) {
|
if (!queueRunning) {
|
||||||
stopBatchProc ();
|
stopBatchProc ();
|
||||||
fdir->set_sensitive (true);
|
fdir->set_sensitive (true);
|
||||||
fformat->set_sensitive (true);
|
fformat->set_sensitive (true);
|
||||||
|
|
||||||
SoundManager::playSoundAsync(options.sndBatchQueueDone);
|
if (qsize == 0) {
|
||||||
|
SoundManager::playSoundAsync(options.sndBatchQueueDone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queueError) {
|
if (queueError) {
|
||||||
@@ -284,6 +286,7 @@ void BatchQueuePanel::startBatchProc ()
|
|||||||
// Update switch when queue started programmatically
|
// Update switch when queue started programmatically
|
||||||
qStartStopConn.block (true);
|
qStartStopConn.block (true);
|
||||||
qStartStop->set_active(true);
|
qStartStop->set_active(true);
|
||||||
|
qStartStopState = true;
|
||||||
qStartStopConn.block (false);
|
qStartStopConn.block (false);
|
||||||
|
|
||||||
if (batchQueue->hasJobs()) {
|
if (batchQueue->hasJobs()) {
|
||||||
@@ -306,6 +309,7 @@ void BatchQueuePanel::stopBatchProc ()
|
|||||||
// Update switch when queue started programmatically
|
// Update switch when queue started programmatically
|
||||||
qStartStopConn.block (true);
|
qStartStopConn.block (true);
|
||||||
qStartStop->set_active(false);
|
qStartStop->set_active(false);
|
||||||
|
qStartStopState = false;
|
||||||
qStartStopConn.block (false);
|
qStartStopConn.block (false);
|
||||||
|
|
||||||
updateTab (batchQueue->getEntries().size());
|
updateTab (batchQueue->getEntries().size());
|
||||||
@@ -320,18 +324,6 @@ void BatchQueuePanel::addBatchQueueJobs(const std::vector<BatchQueueEntry*>& ent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatchQueuePanel::canStartNext ()
|
|
||||||
{
|
|
||||||
// GThreadLock lock;
|
|
||||||
if (qStartStop->get_active()) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
fdir->set_sensitive (true);
|
|
||||||
fformat->set_sensitive (true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BatchQueuePanel::saveOptions ()
|
void BatchQueuePanel::saveOptions ()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -340,6 +332,33 @@ void BatchQueuePanel::saveOptions ()
|
|||||||
options.procQueueEnabled = qAutoStart->get_active();
|
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 ()
|
void BatchQueuePanel::pathFolderButtonPressed ()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -369,23 +388,3 @@ void BatchQueuePanel::formatChanged(const Glib::ustring& format)
|
|||||||
{
|
{
|
||||||
options.saveFormatBatch = saveFormatPanel->getFormat();
|
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);
|
|
||||||
}
|
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#ifndef _BATCHQUEUEPANEL_
|
#ifndef _BATCHQUEUEPANEL_
|
||||||
#define _BATCHQUEUEPANEL_
|
#define _BATCHQUEUEPANEL_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include "batchqueue.h"
|
#include "batchqueue.h"
|
||||||
#include "saveformatpanel.h"
|
#include "saveformatpanel.h"
|
||||||
@@ -51,6 +53,8 @@ class BatchQueuePanel : public Gtk::VBox,
|
|||||||
Gtk::HBox* bottomBox;
|
Gtk::HBox* bottomBox;
|
||||||
Gtk::HBox* topBox;
|
Gtk::HBox* topBox;
|
||||||
|
|
||||||
|
std::atomic<bool> qStartStopState;
|
||||||
|
|
||||||
IdleRegister idle_register;
|
IdleRegister idle_register;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -60,22 +64,23 @@ public:
|
|||||||
void init (RTWindow* parent);
|
void init (RTWindow* parent);
|
||||||
|
|
||||||
void addBatchQueueJobs(const std::vector<BatchQueueEntry*>& entries , bool head = false);
|
void addBatchQueueJobs(const std::vector<BatchQueueEntry*>& entries , bool head = false);
|
||||||
|
void saveOptions ();
|
||||||
|
|
||||||
|
bool handleShortcutKey (GdkEventKey* event);
|
||||||
|
|
||||||
// batchqueuelistener interface
|
// 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();
|
bool canStartNext();
|
||||||
|
|
||||||
|
private:
|
||||||
void startBatchProc ();
|
void startBatchProc ();
|
||||||
void stopBatchProc ();
|
void stopBatchProc ();
|
||||||
void startOrStopBatchProc();
|
void startOrStopBatchProc();
|
||||||
|
|
||||||
void saveOptions ();
|
|
||||||
void pathFolderChanged ();
|
void pathFolderChanged ();
|
||||||
void pathFolderButtonPressed ();
|
void pathFolderButtonPressed ();
|
||||||
void formatChanged(const Glib::ustring& format) override;
|
void formatChanged(const Glib::ustring& format) override;
|
||||||
void updateTab (int qsize, int forceOrientation = 0); // forceOrientation=0: base on options / 1: horizontal / 2: vertical
|
void updateTab (int qsize, int forceOrientation = 0); // forceOrientation=0: base on options / 1: horizontal / 2: vertical
|
||||||
|
|
||||||
bool handleShortcutKey (GdkEventKey* event);
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user