/* * 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 * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * RawTherapee is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ #pragma once #include #include #include "guiutils.h" #include "multilangmgr.h" #include "rtengine/rtengine.h" #undef THREAD_PRIORITY_NORMAL class PLDBridge final : public rtengine::ProgressListener { public: explicit PLDBridge(rtengine::ProgressListener* pb) : pl(pb) { } // ProgressListener interface void setProgress(double p) override { GThreadLock lock; pl->setProgress(p); } void setProgressStr(const Glib::ustring& str) override { GThreadLock lock; Glib::ustring progrstr; progrstr = M(str); pl->setProgressStr(progrstr); } void setProgressState(bool inProcessing) override { GThreadLock lock; pl->setProgressState(inProcessing); } void error(const Glib::ustring& descr) override { GThreadLock lock; pl->error(descr); } private: rtengine::ProgressListener* const pl; }; template class ProgressConnector { sigc::signal0 opStart; sigc::signal0 opEnd; T retval; Glib::Thread *workThread; static int emitEndSignalUI (void* data) { const sigc::signal0* lopEnd = reinterpret_cast*>(data); const int r = lopEnd->emit (); delete lopEnd; return r; } void workingThread () { retval = opStart.emit (); gdk_threads_add_idle(ProgressConnector::emitEndSignalUI, new sigc::signal0(opEnd)); workThread = nullptr; } public: ProgressConnector (): retval( 0 ), workThread( nullptr ) { } void startFunc (const sigc::slot0& startHandler, const sigc::slot0& endHandler ) { if( !workThread ) { opStart.connect (startHandler); opEnd.connect (endHandler); workThread = Glib::Thread::create(sigc::mem_fun(*this, &ProgressConnector::workingThread), 0, true, true, Glib::THREAD_PRIORITY_NORMAL); } } T returnValue() { return retval; } };