From 411cb1470c20c4bfd4275e0481844cb360956b51 Mon Sep 17 00:00:00 2001 From: Oliver Duis Date: Fri, 3 Dec 2010 19:23:43 +0100 Subject: [PATCH] Open batch result file with OS default program; See issue #372 --- rtgui/batchqueue.cc | 11 ++++++++--- rtgui/batchqueue.h | 4 ++-- rtgui/editorpanel.cc | 4 ++++ rtgui/filebrowser.cc | 9 +++++++++ rtgui/filebrowser.h | 2 ++ rtgui/thumbnail.cc | 26 +++++++++++++++++++++++++- rtgui/thumbnail.h | 2 ++ 7 files changed, 52 insertions(+), 6 deletions(-) diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index af730d1dd..221103efa 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -292,7 +292,8 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) { Glib::ustring fname; SaveFormat saveFormat; if (processing->outFileName=="") { // auto file name - fname = obtainFileName (processing->filename); + Glib::ustring s = calcAutoFileNameBase (processing->filename); + fname = autoCompleteFileName (s, options.saveFormat.format); saveFormat = options.saveFormat; } else { // use the save-as filename with automatic completion for uniqueness @@ -300,6 +301,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) { saveFormat = processing->saveFormat; } //printf ("fname=%s, %s\n", fname.c_str(), removeExtension(fname).c_str()); + if (img && fname!="") { int err = 0; if (saveFormat.format=="tif") @@ -333,6 +335,7 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) { delete processing; processing = NULL; fd.erase (fd.begin()); + // return next job if (fd.size()==0) { if (listener) @@ -371,7 +374,9 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img) { return processing ? processing->job : NULL; } -Glib::ustring BatchQueue::obtainFileName (const Glib::ustring& origFileName) { +// Calculates automatic filename of processed batch entry, but just the base name +// example output: "c:\out\converted\dsc0121" +Glib::ustring BatchQueue::calcAutoFileNameBase (const Glib::ustring& origFileName) { std::vector pa; std::vector da; @@ -445,7 +450,7 @@ Glib::ustring BatchQueue::obtainFileName (const Glib::ustring& origFileName) { else path = Glib::build_filename (options.savePathFolder, filename); - return autoCompleteFileName (path, options.saveFormat.format); + return path; } Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format) { diff --git a/rtgui/batchqueue.h b/rtgui/batchqueue.h index 629b556e2..f8a6ca5d6 100644 --- a/rtgui/batchqueue.h +++ b/rtgui/batchqueue.h @@ -1,7 +1,6 @@ /* * This file is part of RawTherapee. * - * Copyright (c) 2004-2010 Gabor Horvath * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -54,7 +53,6 @@ class BatchQueue : public ThumbBrowserBase, BatchQueueListener* listener; - Glib::ustring obtainFileName (const Glib::ustring& origFileName); Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format); Glib::ustring getTempFilenameForParams( const Glib::ustring filename ); bool saveBatchQueue( ); @@ -81,6 +79,8 @@ class BatchQueue : public ThumbBrowserBase, void setBatchQueueListener (BatchQueueListener* l) { listener = l; } void notifyListener (); bool loadBatchQueue (); + + static Glib::ustring calcAutoFileNameBase (const Glib::ustring& origFileName); }; #endif diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 406effe40..fea40e84e 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -672,6 +672,10 @@ bool EditorPanel::handleShortcutKey (GdkEventKey* event) { case GDK_F: iarea->imageArea->zoomPanel->zoomFitClicked(); return true; + + case GDK_F5: + openThm->openBatchResultDefaultViewer(); + return true; } } else { diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index b7cb61da3..3b72f7ea4 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -392,6 +392,11 @@ void FileBrowser::partPasteProfile () { partialPasteDlg.hide (); } +void FileBrowser::openBatchResultDefaultViewer () { + if (selected.size()==1) + ((FileBrowserEntry*)selected[0])->thumbnail->openBatchResultDefaultViewer(); +} + bool FileBrowser::keyPressed (GdkEventKey* event) { if ((event->keyval==GDK_C || event->keyval==GDK_c) && event->state & GDK_CONTROL_MASK) { @@ -422,6 +427,10 @@ bool FileBrowser::keyPressed (GdkEventKey* event) { menuItemActivated (selall); return true; } + else if (event->keyval==GDK_F5) { + openBatchResultDefaultViewer (); + return true; + } return false; } diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index 822039293..507453eef 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -113,6 +113,8 @@ class FileBrowser : public ThumbBrowserBase, public LWButtonListener { void pasteProfile (); void partPasteProfile (); + void openBatchResultDefaultViewer (); + void redrawNeeded (ThumbBrowserEntryBase* entry); void thumbRearrangementNeeded (); void _thumbRearrangementNeeded (); diff --git a/rtgui/thumbnail.cc b/rtgui/thumbnail.cc index 4e3b92740..0e9879143 100644 --- a/rtgui/thumbnail.cc +++ b/rtgui/thumbnail.cc @@ -1,7 +1,6 @@ /* * This file is part of RawTherapee. * - * Copyright (c) 2004-2010 Gabor Horvath * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +28,7 @@ #include #include #include +#include using namespace rtengine::procparams; @@ -503,3 +503,27 @@ void Thumbnail::removeThumbnailListener (ThumbnailListener* tnl) { } } +// Calculates the standard filename for the automatically named batch result +// and opens it in OS default viewer +// Return: Success? +bool Thumbnail::openBatchResultDefaultViewer() { + Glib::ustring openFName = Glib::ustring::compose ("%1.%2", BatchQueue::calcAutoFileNameBase(fname), options.saveFormat.format); + + printf ("Try opening %s\n", openFName.c_str()); + + if (Glib::file_test (openFName, Glib::FILE_TEST_EXISTS)) { + +#ifdef WIN32 + ShellExecute(NULL, "open", openFName.c_str(), NULL, NULL, SW_SHOWMAXIMIZED); + return true; +#else + // TODO: Add more OSes here + printf("Automatic opening not supported on this OS\n"); + return false; +#endif + + } else { + printf("File not found\n"); + return false; + } +} \ No newline at end of file diff --git a/rtgui/thumbnail.h b/rtgui/thumbnail.h index 6c7e8aec2..a42d79e1a 100644 --- a/rtgui/thumbnail.h +++ b/rtgui/thumbnail.h @@ -127,6 +127,8 @@ class Thumbnail { void updateCache (); void saveThumbnail (); + + bool openBatchResultDefaultViewer(); };