Merge pull request #6920 from sgilbertson/issue-6915-queue-template-improvements
Queue template improvements
This commit is contained in:
@@ -43,6 +43,59 @@
|
||||
using namespace std;
|
||||
using namespace rtengine;
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PATH_SEPARATOR '\\';
|
||||
#else
|
||||
#define PATH_SEPARATOR '/';
|
||||
#endif
|
||||
|
||||
namespace // local helper functions
|
||||
{
|
||||
// Look for N or -N in templateText at position ix, meaning "index from end" and "index from start".
|
||||
// For N, return Nth index from the end, and for -N return the Nth index from the start.
|
||||
// N is a digit 1 through 9. The returned value is not range-checked, so it may be >=numPathElements.
|
||||
// or negative. The caller performs any required range-checking.
|
||||
int decodePathIndex(unsigned int& ix, Glib::ustring& templateText, size_t numPathElements)
|
||||
{
|
||||
int pathIndex = static_cast<int>(numPathElements); // a value that means input was invalid
|
||||
bool fromStart = false;
|
||||
if (ix < templateText.size()) {
|
||||
if (templateText[ix] == '-') {
|
||||
fromStart = true; // minus sign means N is from the start rather than the end of the path
|
||||
ix++;
|
||||
}
|
||||
}
|
||||
if (ix < templateText.size()) {
|
||||
pathIndex = templateText[ix] - '1';
|
||||
if (!fromStart) {
|
||||
pathIndex = numPathElements - pathIndex - 1;
|
||||
}
|
||||
}
|
||||
return pathIndex;
|
||||
}
|
||||
|
||||
// Extract the initial characters from a canonical absolute path, and append
|
||||
// those to a path string. Initial characters are '/' for Unix/Linux paths and
|
||||
// '\\' or '//' for UNC paths. A single backslash is also accepted, for driveless
|
||||
// Windows paths.
|
||||
void appendAbsolutePathPrefix(Glib::ustring& path, const Glib::ustring& absolutePath)
|
||||
{
|
||||
if (absolutePath[0] == '/') {
|
||||
if (absolutePath.size() > 1 && absolutePath[1] == '/') {
|
||||
path += "//"; // Start of a Samba UNC path
|
||||
} else {
|
||||
path += '/'; // Start of a Unix/Linux path
|
||||
}
|
||||
} else if (absolutePath[0] == '\\') {
|
||||
if (absolutePath.size() > 1 && absolutePath[1] == '\\') {
|
||||
path += "\\\\"; // Start of a UNC path
|
||||
} else {
|
||||
path += '\\'; // Start of a Windows path that does not include a drive letter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCatalog(aFileCatalog), sequence(0), listener(nullptr)
|
||||
{
|
||||
|
||||
@@ -394,7 +447,7 @@ Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring &filenam
|
||||
timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
char mseconds[11];
|
||||
snprintf(mseconds, sizeof(mseconds), "%d", (int)(tv.tv_usec / 1000));
|
||||
snprintf(mseconds, sizeof(mseconds), "%d", static_cast<int>((tv.tv_usec / 1000)));
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
char stringTimestamp [80];
|
||||
@@ -561,12 +614,28 @@ void BatchQueue::openLastSelectedItemInEditor()
|
||||
{
|
||||
MYREADERLOCK(l, entryRW);
|
||||
|
||||
if (selected.size() > 0) {
|
||||
if (!selected.empty()) {
|
||||
openItemInEditor(selected.back());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BatchQueue::updateDestinationPathPreview()
|
||||
{
|
||||
MYWRITERLOCK(l, entryRW);
|
||||
|
||||
if (!selected.empty()) {
|
||||
auto& entry = *selected.at(0);
|
||||
int sequence = 0; // Sequence during subsequent queue processing can't be determined here
|
||||
Glib::ustring baseDestination = calcAutoFileNameBase(entry.filename, sequence);
|
||||
Glib::ustring destination = Glib::ustring::compose ("%1.%2", baseDestination, options.saveFormatBatch.format);
|
||||
|
||||
if (listener) {
|
||||
listener->setDestinationPreviewText(destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BatchQueue::openItemInEditor(ThumbBrowserEntryBase* item)
|
||||
{
|
||||
if (item) {
|
||||
@@ -811,7 +880,6 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img)
|
||||
Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileName, int sequence)
|
||||
{
|
||||
|
||||
std::vector<Glib::ustring> pa;
|
||||
std::vector<Glib::ustring> da;
|
||||
|
||||
for (size_t i = 0; i < origFileName.size(); i++) {
|
||||
@@ -829,29 +897,13 @@ Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileNam
|
||||
tok = tok + origFileName[i++];
|
||||
}
|
||||
|
||||
da.push_back (tok);
|
||||
}
|
||||
|
||||
if (origFileName[0] == '/') {
|
||||
pa.push_back ("/" + da[0]);
|
||||
} else if (origFileName[0] == '\\') {
|
||||
if (origFileName.size() > 1 && origFileName[1] == '\\') {
|
||||
pa.push_back ("\\\\" + da[0]);
|
||||
} else {
|
||||
pa.push_back ("/" + da[0]);
|
||||
if (i < origFileName.size()) { // omit the last token, which is the file name
|
||||
da.push_back (tok);
|
||||
}
|
||||
} else {
|
||||
pa.push_back (da[0]);
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < da.size(); i++) {
|
||||
pa.push_back (pa[i - 1] + "/" + da[i]);
|
||||
}
|
||||
|
||||
// for (int i=0; i<da.size(); i++)
|
||||
// printf ("da: %s\n", da[i].c_str());
|
||||
// for (int i=0; i<pa.size(); i++)
|
||||
// printf ("pa: %s\n", pa[i].c_str());
|
||||
// for (unsigned i=0; i<da.size(); i++)
|
||||
// printf ("da[%u]: \"%s\"\n", i, da[i].c_str());
|
||||
|
||||
// extracting filebase
|
||||
Glib::ustring filename;
|
||||
@@ -878,24 +930,50 @@ Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileNam
|
||||
if (options.savePathTemplate[ix] == '%') {
|
||||
ix++;
|
||||
|
||||
if (options.savePathTemplate[ix] == 'p') {
|
||||
if (options.savePathTemplate[ix] == 'P') {
|
||||
// insert path elements from given index to the end
|
||||
ix++;
|
||||
unsigned int i = options.savePathTemplate[ix] - '0';
|
||||
|
||||
if (i < pa.size()) {
|
||||
path = path + pa[pa.size() - i - 1] + '/';
|
||||
int n = decodePathIndex(ix, options.savePathTemplate, da.size());
|
||||
if (n < 0) {
|
||||
n = 0; // if too many elements specified, return all available elements
|
||||
}
|
||||
|
||||
if (n < static_cast<int>(da.size())) {
|
||||
if (n == 0) {
|
||||
appendAbsolutePathPrefix(path, origFileName);
|
||||
}
|
||||
for (unsigned int i = static_cast<unsigned int>(n); i < da.size(); i++) {
|
||||
path += da[i] + PATH_SEPARATOR;
|
||||
}
|
||||
}
|
||||
// If the next template character is a separator, skip it, because path already has one
|
||||
ix++;
|
||||
if (ix < options.savePathTemplate.size() && options.savePathTemplate[ix] != '/' && options.savePathTemplate[ix] != '\\') {
|
||||
ix--;
|
||||
}
|
||||
} else if (options.savePathTemplate[ix] == 'p') {
|
||||
// insert path elements from the start of the path up to the given index
|
||||
ix++;
|
||||
int n = decodePathIndex(ix, options.savePathTemplate, da.size());
|
||||
if (n >= 0) {
|
||||
appendAbsolutePathPrefix(path, origFileName);
|
||||
}
|
||||
for (unsigned int i=0; static_cast<int>(i) <= n && i < da.size(); i++) {
|
||||
path += da[i] + PATH_SEPARATOR;
|
||||
}
|
||||
// If the next template character is a separator, skip it, because path already has one
|
||||
ix++;
|
||||
if (ix < options.savePathTemplate.size() && options.savePathTemplate[ix] != '/' && options.savePathTemplate[ix] != '\\') {
|
||||
ix--;
|
||||
}
|
||||
} else if (options.savePathTemplate[ix] == 'd') {
|
||||
// insert a single directory name from the file's path
|
||||
ix++;
|
||||
unsigned i = options.savePathTemplate[ix] - '0';
|
||||
|
||||
if (i < da.size()) {
|
||||
path = path + da[da.size() - i - 1];
|
||||
int n = decodePathIndex(ix, options.savePathTemplate, da.size());
|
||||
if (n >= 0 && n < static_cast<int>(da.size())) {
|
||||
path += da[n];
|
||||
}
|
||||
} else if (options.savePathTemplate[ix] == 'f') {
|
||||
path = path + filename;
|
||||
path += filename;
|
||||
} else if (options.savePathTemplate[ix] == 'r') { // rank from pparams
|
||||
char rank;
|
||||
rtengine::procparams::ProcParams pparams;
|
||||
@@ -927,7 +1005,7 @@ Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileNam
|
||||
}
|
||||
|
||||
else {
|
||||
path = path + options.savePathTemplate[ix];
|
||||
path += options.savePathTemplate[ix];
|
||||
}
|
||||
|
||||
ix++;
|
||||
@@ -1021,3 +1099,8 @@ void BatchQueue::redrawNeeded (LWButton* button)
|
||||
GThreadLock lock;
|
||||
queue_draw ();
|
||||
}
|
||||
|
||||
void BatchQueue::selectionChanged()
|
||||
{
|
||||
updateDestinationPathPreview();
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ public:
|
||||
virtual ~BatchQueueListener() = default;
|
||||
virtual void queueSizeChanged(int qsize, bool queueRunning, bool queueError, const Glib::ustring& queueErrorMessage) = 0;
|
||||
virtual bool canStartNext() = 0;
|
||||
virtual void setDestinationPreviewText(const Glib::ustring& destinationPath) = 0;
|
||||
};
|
||||
|
||||
class FileCatalog;
|
||||
@@ -59,6 +60,7 @@ public:
|
||||
void selectAll ();
|
||||
void openItemInEditor(ThumbBrowserEntryBase* item);
|
||||
void openLastSelectedItemInEditor();
|
||||
void updateDestinationPathPreview();
|
||||
|
||||
void startProcessing ();
|
||||
|
||||
@@ -79,6 +81,7 @@ public:
|
||||
bool keyPressed (GdkEventKey* event) override;
|
||||
void buttonPressed (LWButton* button, int actionCode, void* actionData) override;
|
||||
void redrawNeeded (LWButton* button) override;
|
||||
void selectionChanged () override;
|
||||
|
||||
void setBatchQueueListener (BatchQueueListener* l)
|
||||
{
|
||||
|
@@ -108,6 +108,14 @@ BatchQueuePanel::BatchQueuePanel (FileCatalog* aFileCatalog) : parent(nullptr)
|
||||
#endif
|
||||
|
||||
odvb->pack_start (*hb3, Gtk::PACK_SHRINK, 4);
|
||||
destinationPreviewLabel = Gtk::manage (new Gtk::Label ());
|
||||
destinationPreviewLabel->set_tooltip_markup (M("QUEUE_DESTPREVIEW_TOOLTIP"));
|
||||
destinationPreviewLabel->set_selectable (true); // so users can copy the path to the clipboard
|
||||
destinationPreviewLabel->set_halign (Gtk::ALIGN_START);
|
||||
auto destinationPreviewScrolledWindow = Gtk::manage(new Gtk::ScrolledWindow ());
|
||||
destinationPreviewScrolledWindow->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
||||
destinationPreviewScrolledWindow->add (*destinationPreviewLabel);
|
||||
odvb->pack_start (*destinationPreviewScrolledWindow, Gtk::PACK_SHRINK);
|
||||
Gtk::RadioButton::Group g = useTemplate->get_group();
|
||||
useFolder->set_group (g);
|
||||
fdir->add (*odvb);
|
||||
@@ -122,6 +130,7 @@ BatchQueuePanel::BatchQueuePanel (FileCatalog* aFileCatalog) : parent(nullptr)
|
||||
outdirTemplate->set_text (options.savePathTemplate);
|
||||
useTemplate->set_active (options.saveUsePathTemplate);
|
||||
useFolder->set_active (!options.saveUsePathTemplate);
|
||||
destinationPreviewLabel->set_text (M("QUEUE_DESTPREVIEW_TITLE"));
|
||||
|
||||
// setup signal handlers
|
||||
outdirTemplate->signal_changed().connect (sigc::mem_fun(*this, &BatchQueuePanel::saveOptions));
|
||||
@@ -329,6 +338,7 @@ void BatchQueuePanel::saveOptions ()
|
||||
options.savePathTemplate = outdirTemplate->get_text();
|
||||
options.saveUsePathTemplate = useTemplate->get_active();
|
||||
options.procQueueEnabled = qAutoStart->get_active();
|
||||
batchQueue->updateDestinationPathPreview();
|
||||
}
|
||||
|
||||
bool BatchQueuePanel::handleShortcutKey (GdkEventKey* event)
|
||||
@@ -358,6 +368,11 @@ bool BatchQueuePanel::canStartNext ()
|
||||
return queueShouldRun;
|
||||
}
|
||||
|
||||
void BatchQueuePanel::setDestinationPreviewText(const Glib::ustring &destinationPath)
|
||||
{
|
||||
destinationPreviewLabel->set_text(destinationPath);
|
||||
}
|
||||
|
||||
void BatchQueuePanel::pathFolderButtonPressed ()
|
||||
{
|
||||
|
||||
@@ -381,9 +396,11 @@ void BatchQueuePanel::pathFolderButtonPressed ()
|
||||
void BatchQueuePanel::pathFolderChanged ()
|
||||
{
|
||||
options.savePathFolder = outdirFolder->get_filename();
|
||||
batchQueue->updateDestinationPathPreview();
|
||||
}
|
||||
|
||||
void BatchQueuePanel::formatChanged(const Glib::ustring& format)
|
||||
{
|
||||
options.saveFormatBatch = saveFormatPanel->getFormat();
|
||||
batchQueue->updateDestinationPathPreview();
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ class BatchQueuePanel : public Gtk::Box,
|
||||
Gtk::CheckButton* qAutoStart;
|
||||
|
||||
Gtk::Entry* outdirTemplate;
|
||||
Gtk::Label* destinationPreviewLabel;
|
||||
MyFileChooserButton* outdirFolder;
|
||||
Gtk::Button* outdirFolderButton;
|
||||
Gtk::RadioButton* useTemplate;
|
||||
@@ -72,6 +73,7 @@ public:
|
||||
// batchqueuelistener interface
|
||||
void queueSizeChanged(int qsize, bool queueRunning, bool queueError, const Glib::ustring& queueErrorMessage) override;
|
||||
bool canStartNext() override;
|
||||
void setDestinationPreviewText(const Glib::ustring& destinationPath) override;
|
||||
|
||||
private:
|
||||
void startBatchProc ();
|
||||
|
Reference in New Issue
Block a user