Add @thirtythreeforty's std::function<>
variant (#4892)
Also convert `batchqueue.cc` where applicable.
This commit is contained in:
parent
1d0c128209
commit
00b62d2b65
@ -39,25 +39,6 @@
|
||||
using namespace std;
|
||||
using namespace rtengine;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct NLParams {
|
||||
BatchQueueListener* listener;
|
||||
int qsize;
|
||||
bool queueEmptied;
|
||||
bool queueError;
|
||||
Glib::ustring queueErrorMessage;
|
||||
};
|
||||
|
||||
bool bqnotifylistenerUI(NLParams* params)
|
||||
{
|
||||
params->listener->queueSizeChanged (params->qsize, params->queueEmptied, params->queueError, params->queueErrorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCatalog(aFileCatalog), sequence(0), listener(nullptr)
|
||||
{
|
||||
|
||||
@ -604,14 +585,13 @@ void BatchQueue::setProgress(double p)
|
||||
}
|
||||
|
||||
// No need to acquire the GUI, setProgressUI will do it
|
||||
const auto func =
|
||||
[](BatchQueue* bq) -> bool
|
||||
idle_register.add(
|
||||
[this]() -> bool
|
||||
{
|
||||
bq->redraw();
|
||||
redraw();
|
||||
return false;
|
||||
};
|
||||
|
||||
idle_register.add<BatchQueue>(func, this, false);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void BatchQueue::setProgressStr(const Glib::ustring& str)
|
||||
@ -636,12 +616,15 @@ void BatchQueue::error(const Glib::ustring& descr)
|
||||
}
|
||||
|
||||
if (listener) {
|
||||
NLParams* params = new NLParams;
|
||||
params->listener = listener;
|
||||
params->queueEmptied = false;
|
||||
params->queueError = true;
|
||||
params->queueErrorMessage = descr;
|
||||
idle_register.add<NLParams>(bqnotifylistenerUI, params, true);
|
||||
BatchQueueListener* const listener_copy = listener;
|
||||
|
||||
idle_register.add(
|
||||
[listener_copy, descr]() -> bool
|
||||
{
|
||||
listener_copy->queueSizeChanged(0, false, true, descr);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -975,15 +958,21 @@ void BatchQueue::notifyListener (bool queueEmptied)
|
||||
{
|
||||
|
||||
if (listener) {
|
||||
NLParams* params = new NLParams;
|
||||
params->listener = listener;
|
||||
BatchQueueListener* const listener_copy = listener;
|
||||
const std::size_t queue_size =
|
||||
[](MyRWMutex& mutex, const std::vector<ThumbBrowserEntryBase*>& fd) -> std::size_t
|
||||
{
|
||||
MYREADERLOCK(l, entryRW);
|
||||
params->qsize = fd.size();
|
||||
MYREADERLOCK(l, mutex);
|
||||
return fd.size();
|
||||
}(entryRW, fd);
|
||||
|
||||
idle_register.add(
|
||||
[listener_copy, queue_size, queueEmptied]() -> bool
|
||||
{
|
||||
listener_copy->queueSizeChanged(queue_size, queueEmptied, false, {});
|
||||
return false;
|
||||
}
|
||||
params->queueEmptied = queueEmptied;
|
||||
params->queueError = false;
|
||||
idle_register.add<NLParams>(bqnotifylistenerUI, params, true);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,19 @@ IdleRegister::~IdleRegister()
|
||||
destroy();
|
||||
}
|
||||
|
||||
void IdleRegister::add(std::function<bool ()> function, gint priority)
|
||||
{
|
||||
using Function = std::function<bool ()>;
|
||||
|
||||
const auto func =
|
||||
[](Function* function)
|
||||
{
|
||||
return (*function)();
|
||||
};
|
||||
|
||||
add<Function>(func, new Function(std::move(function)), true, priority);
|
||||
}
|
||||
|
||||
void IdleRegister::destroy()
|
||||
{
|
||||
mutex.lock();
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef __GUI_UTILS_
|
||||
#define __GUI_UTILS_
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
#include <gtkmm.h>
|
||||
@ -98,6 +99,7 @@ public:
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void add(std::function<bool ()> function, gint priority = G_PRIORITY_DEFAULT_IDLE);
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user