Copy-edit some methods of the batch queue to test usage of C++11's auto variables and lambda functions.
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "../rtengine/rt_math.h"
|
#include "../rtengine/rt_math.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -37,13 +38,13 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace rtengine;
|
using namespace rtengine;
|
||||||
|
|
||||||
BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(NULL), fileCatalog(aFileCatalog), sequence(0), listener(NULL)
|
BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(NULL), fileCatalog(aFileCatalog), sequence(0), listener(NULL),
|
||||||
|
pmenu (new Gtk::Menu ())
|
||||||
{
|
{
|
||||||
|
|
||||||
location = THLOC_BATCHQUEUE;
|
location = THLOC_BATCHQUEUE;
|
||||||
|
|
||||||
int p = 0;
|
int p = 0;
|
||||||
pmenu = new Gtk::Menu ();
|
|
||||||
|
|
||||||
pmenu->attach (*Gtk::manage(open = new Gtk::MenuItem (M("FILEBROWSER_POPUPOPENINEDITOR"))), 0, 1, p, p + 1);
|
pmenu->attach (*Gtk::manage(open = new Gtk::MenuItem (M("FILEBROWSER_POPUPOPENINEDITOR"))), 0, 1, p, p + 1);
|
||||||
p++;
|
p++;
|
||||||
@@ -79,9 +80,9 @@ BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(NULL), fileCatal
|
|||||||
cancel->add_accelerator ("activate", pmenu->get_accel_group(), GDK_Delete, (Gdk::ModifierType)0, Gtk::ACCEL_VISIBLE);
|
cancel->add_accelerator ("activate", pmenu->get_accel_group(), GDK_Delete, (Gdk::ModifierType)0, Gtk::ACCEL_VISIBLE);
|
||||||
|
|
||||||
open->signal_activate().connect(sigc::mem_fun(*this, &BatchQueue::openLastSelectedItemInEditor));
|
open->signal_activate().connect(sigc::mem_fun(*this, &BatchQueue::openLastSelectedItemInEditor));
|
||||||
cancel->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &BatchQueue::cancelItems), &selected));
|
cancel->signal_activate().connect (std::bind (&BatchQueue::cancelItems, this, selected));
|
||||||
head->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &BatchQueue::headItems), &selected));
|
head->signal_activate().connect (std::bind (&BatchQueue::headItems, this, selected));
|
||||||
tail->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &BatchQueue::tailItems), &selected));
|
tail->signal_activate().connect (std::bind (&BatchQueue::tailItems, this, selected));
|
||||||
selall->signal_activate().connect (sigc::mem_fun(*this, &BatchQueue::selectAll));
|
selall->signal_activate().connect (sigc::mem_fun(*this, &BatchQueue::selectAll));
|
||||||
|
|
||||||
setArrangement (ThumbBrowserBase::TB_Vertical);
|
setArrangement (ThumbBrowserBase::TB_Vertical);
|
||||||
@@ -99,20 +100,18 @@ BatchQueue::~BatchQueue ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fd.clear ();
|
fd.clear ();
|
||||||
|
|
||||||
delete pmenu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::resizeLoadedQueue()
|
void BatchQueue::resizeLoadedQueue()
|
||||||
{
|
{
|
||||||
// TODO: Check for Linux
|
|
||||||
#if PROTECT_VECTORS
|
#if PROTECT_VECTORS
|
||||||
MYWRITERLOCK(l, entryRW);
|
MYWRITERLOCK(l, entryRW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < fd.size(); i++) {
|
const auto height = getThumbnailHeight ();
|
||||||
fd.at(i)->resize(getThumbnailHeight());
|
|
||||||
}
|
for (const auto entry : fd)
|
||||||
|
entry->resize(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce the max size of a thumb, since thumb is processed synchronously on adding to queue
|
// Reduce the max size of a thumb, since thumb is processed synchronously on adding to queue
|
||||||
@@ -161,72 +160,63 @@ bool BatchQueue::keyPressed (GdkEventKey* event)
|
|||||||
openLastSelectedItemInEditor();
|
openLastSelectedItemInEditor();
|
||||||
return true;
|
return true;
|
||||||
} else if (event->keyval == GDK_Home) {
|
} else if (event->keyval == GDK_Home) {
|
||||||
headItems (&selected);
|
headItems (selected);
|
||||||
return true;
|
return true;
|
||||||
} else if (event->keyval == GDK_End) {
|
} else if (event->keyval == GDK_End) {
|
||||||
tailItems (&selected);
|
tailItems (selected);
|
||||||
return true;
|
return true;
|
||||||
} else if (event->keyval == GDK_Delete) {
|
} else if (event->keyval == GDK_Delete) {
|
||||||
cancelItems (&selected);
|
cancelItems (selected);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::addEntries ( std::vector<BatchQueueEntry*> &entries, bool head, bool save)
|
void BatchQueue::addEntries (const std::vector<BatchQueueEntry*>& entries, bool head, bool save)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// TODO: Check for Linux
|
|
||||||
#if PROTECT_VECTORS
|
#if PROTECT_VECTORS
|
||||||
MYWRITERLOCK(l, entryRW);
|
MYWRITERLOCK(l, entryRW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for( std::vector<BatchQueueEntry*>::iterator entry = entries.begin(); entry != entries.end(); entry++ ) {
|
for (const auto entry : entries) {
|
||||||
(*entry)->setParent (this);
|
|
||||||
|
|
||||||
// BatchQueueButtonSet HAVE TO be added before resizing to take them into account
|
entry->setParent (this);
|
||||||
BatchQueueButtonSet* bqbs = new BatchQueueButtonSet (*entry);
|
|
||||||
|
// BatchQueueButtonSet have to be added before resizing to take them into account
|
||||||
|
const auto bqbs = new BatchQueueButtonSet (entry);
|
||||||
bqbs->setButtonListener (this);
|
bqbs->setButtonListener (this);
|
||||||
(*entry)->addButtonSet (bqbs);
|
entry->addButtonSet (bqbs);
|
||||||
|
|
||||||
(*entry)->resize (getThumbnailHeight()); // batch queue might have smaller, restricted size
|
// batch queue might have smaller, restricted size
|
||||||
Glib::ustring tempFile = getTempFilenameForParams( (*entry)->filename );
|
entry->resize (getThumbnailHeight());
|
||||||
|
|
||||||
// recovery save
|
// recovery save
|
||||||
if( !(*entry)->params.save( tempFile ) ) {
|
const auto tempFile = getTempFilenameForParams (entry->filename);
|
||||||
(*entry)->savedParamsFile = tempFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*entry)->selected = false;
|
if (!entry->params.save (tempFile))
|
||||||
|
entry->savedParamsFile = tempFile;
|
||||||
|
|
||||||
if (!head) {
|
entry->selected = false;
|
||||||
fd.push_back (*entry);
|
|
||||||
} else {
|
|
||||||
std::vector<ThumbBrowserEntryBase*>::iterator pos;
|
|
||||||
|
|
||||||
for (pos = fd.begin(); pos != fd.end(); pos++)
|
// insert either at the end, or before the first non-processing entry
|
||||||
if (!(*pos)->processing) {
|
auto pos = fd.end ();
|
||||||
fd.insert (pos, *entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos == fd.end()) {
|
if (head)
|
||||||
fd.push_back (*entry);
|
pos = std::find_if (fd.begin (), fd.end (), [] (const ThumbBrowserEntryBase* fdEntry) { return !fdEntry->processing; });
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((*entry)->thumbnail) {
|
fd.insert (pos, entry);
|
||||||
(*entry)->thumbnail->imageEnqueued ();
|
|
||||||
}
|
if (entry->thumbnail)
|
||||||
|
entry->thumbnail->imageEnqueued ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (save) {
|
if (save)
|
||||||
saveBatchQueue( );
|
saveBatchQueue ();
|
||||||
}
|
|
||||||
|
|
||||||
redraw();
|
redraw ();
|
||||||
notifyListener (false);
|
notifyListener (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,107 +499,106 @@ int cancelItemUI (void* data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::cancelItems (std::vector<ThumbBrowserEntryBase*>* items)
|
void BatchQueue::cancelItems (const std::vector<ThumbBrowserEntryBase*>& items)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// TODO: Check for Linux
|
|
||||||
#if PROTECT_VECTORS
|
#if PROTECT_VECTORS
|
||||||
MYWRITERLOCK(l, entryRW);
|
MYWRITERLOCK(l, entryRW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < items->size(); i++) {
|
for (const auto item : items) {
|
||||||
BatchQueueEntry* entry = (BatchQueueEntry*)(*items)[i];
|
|
||||||
|
|
||||||
if (entry->processing) {
|
const auto entry = static_cast<BatchQueueEntry*> (item);
|
||||||
|
|
||||||
|
if (entry->processing)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ThumbBrowserEntryBase*>::iterator pos = std::find (fd.begin(), fd.end(), entry);
|
const auto pos = std::find (fd.begin (), fd.end (), entry);
|
||||||
|
|
||||||
if (pos != fd.end()) {
|
if (pos == fd.end ())
|
||||||
fd.erase (pos);
|
continue;
|
||||||
rtengine::ProcessingJob::destroy (entry->job);
|
|
||||||
|
|
||||||
if (entry->thumbnail) {
|
fd.erase (pos);
|
||||||
entry->thumbnail->imageRemovedFromQueue ();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_idle_add (cancelItemUI, entry);
|
rtengine::ProcessingJob::destroy (entry->job);
|
||||||
}
|
|
||||||
|
if (entry->thumbnail)
|
||||||
|
entry->thumbnail->imageRemovedFromQueue ();
|
||||||
|
|
||||||
|
g_idle_add (cancelItemUI, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < fd.size(); i++) {
|
for (const auto entry : fd)
|
||||||
fd[i]->selected = false;
|
entry->selected = false;
|
||||||
}
|
|
||||||
|
|
||||||
lastClicked = NULL;
|
lastClicked = nullptr;
|
||||||
selected.clear ();
|
selected.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBatchQueue( );
|
saveBatchQueue ();
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
notifyListener (false);
|
notifyListener (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::headItems (std::vector<ThumbBrowserEntryBase*>* items)
|
void BatchQueue::headItems (const std::vector<ThumbBrowserEntryBase*>& items)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// TODO: Check for Linux
|
|
||||||
#if PROTECT_VECTORS
|
#if PROTECT_VECTORS
|
||||||
MYWRITERLOCK(l, entryRW);
|
MYWRITERLOCK(l, entryRW);
|
||||||
#endif
|
#endif
|
||||||
|
for (auto item = items.rbegin(); item != items.rend(); ++item) {
|
||||||
|
|
||||||
for (int i = items->size() - 1; i >= 0; i--) {
|
const auto entry = static_cast<BatchQueueEntry*> (*item);
|
||||||
BatchQueueEntry* entry = (BatchQueueEntry*)(*items)[i];
|
|
||||||
|
|
||||||
if (entry->processing) {
|
if (entry->processing)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ThumbBrowserEntryBase*>::iterator pos = std::find (fd.begin(), fd.end(), entry);
|
const auto pos = std::find (fd.begin (), fd.end (), entry);
|
||||||
|
|
||||||
if (pos != fd.end() && pos != fd.begin()) {
|
if (pos == fd.end () || pos == fd.begin ())
|
||||||
fd.erase (pos);
|
continue;
|
||||||
|
|
||||||
// find the first item that is not under processing
|
fd.erase (pos);
|
||||||
for (pos = fd.begin(); pos != fd.end(); pos++)
|
|
||||||
if (!(*pos)->processing) {
|
// find the first item that is not under processing
|
||||||
fd.insert (pos, entry);
|
const auto newPos = std::find_if (fd.begin (), fd.end (), [] (const ThumbBrowserEntryBase* fdEntry) { return !fdEntry->processing; });
|
||||||
break;
|
|
||||||
}
|
fd.insert (newPos, entry);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveBatchQueue( );
|
|
||||||
|
saveBatchQueue ();
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueue::tailItems (std::vector<ThumbBrowserEntryBase*>* items)
|
void BatchQueue::tailItems (const std::vector<ThumbBrowserEntryBase*>& items)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// TODO: Check for Linux
|
|
||||||
#if PROTECT_VECTORS
|
#if PROTECT_VECTORS
|
||||||
MYWRITERLOCK(l, entryRW);
|
MYWRITERLOCK(l, entryRW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (size_t i = 0; i < items->size(); i++) {
|
for (const auto item : items) {
|
||||||
BatchQueueEntry* entry = (BatchQueueEntry*)(*items)[i];
|
|
||||||
|
|
||||||
if (entry->processing) {
|
const auto entry = static_cast<BatchQueueEntry*> (item);
|
||||||
|
|
||||||
|
if (entry->processing)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ThumbBrowserEntryBase*>::iterator pos = std::find (fd.begin(), fd.end(), entry);
|
const auto pos = std::find (fd.begin (), fd.end (), entry);
|
||||||
|
|
||||||
if (pos != fd.end()) {
|
if (pos == fd.end ())
|
||||||
fd.erase (pos);
|
continue;
|
||||||
fd.push_back (entry);
|
|
||||||
}
|
fd.erase (pos);
|
||||||
|
|
||||||
|
fd.push_back (entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveBatchQueue( );
|
|
||||||
|
saveBatchQueue ();
|
||||||
|
|
||||||
redraw ();
|
redraw ();
|
||||||
}
|
}
|
||||||
@@ -1034,11 +1023,11 @@ void BatchQueue::buttonPressed (LWButton* button, int actionCode, void* actionDa
|
|||||||
bqe.push_back (static_cast<BatchQueueEntry*>(actionData));
|
bqe.push_back (static_cast<BatchQueueEntry*>(actionData));
|
||||||
|
|
||||||
if (actionCode == 10) { // cancel
|
if (actionCode == 10) { // cancel
|
||||||
cancelItems (&bqe);
|
cancelItems (bqe);
|
||||||
} else if (actionCode == 8) { // to head
|
} else if (actionCode == 8) { // to head
|
||||||
headItems (&bqe);
|
headItems (bqe);
|
||||||
} else if (actionCode == 9) { // to tail
|
} else if (actionCode == 9) { // to tail
|
||||||
tailItems (&bqe);
|
tailItems (bqe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@ protected:
|
|||||||
Gtk::ImageMenuItem* tail;
|
Gtk::ImageMenuItem* tail;
|
||||||
Gtk::MenuItem* selall;
|
Gtk::MenuItem* selall;
|
||||||
Gtk::MenuItem* open;
|
Gtk::MenuItem* open;
|
||||||
Gtk::Menu* pmenu;
|
std::unique_ptr<Gtk::Menu> pmenu;
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::AccelGroup> pmaccelgroup;
|
Glib::RefPtr<Gtk::AccelGroup> pmaccelgroup;
|
||||||
|
|
||||||
@@ -72,10 +72,10 @@ public:
|
|||||||
BatchQueue (FileCatalog* aFileCatalog);
|
BatchQueue (FileCatalog* aFileCatalog);
|
||||||
~BatchQueue ();
|
~BatchQueue ();
|
||||||
|
|
||||||
void addEntries (std::vector<BatchQueueEntry*> &entries, bool head = false, bool save = true);
|
void addEntries (const std::vector<BatchQueueEntry*>& entries, bool head = false, bool save = true);
|
||||||
void cancelItems (std::vector<ThumbBrowserEntryBase*>* items);
|
void cancelItems (const std::vector<ThumbBrowserEntryBase*>& items);
|
||||||
void headItems (std::vector<ThumbBrowserEntryBase*>* items);
|
void headItems (const std::vector<ThumbBrowserEntryBase *>& items);
|
||||||
void tailItems (std::vector<ThumbBrowserEntryBase*>* items);
|
void tailItems (const std::vector<ThumbBrowserEntryBase *>& items);
|
||||||
void selectAll ();
|
void selectAll ();
|
||||||
void openItemInEditor(ThumbBrowserEntryBase* item);
|
void openItemInEditor(ThumbBrowserEntryBase* item);
|
||||||
void openLastSelectedItemInEditor();
|
void openLastSelectedItemInEditor();
|
||||||
|
Reference in New Issue
Block a user