Proper check for rawzor libraries.
[rawtherapee-fixes.git] / rtgui / progressdialog.h
blob4539ee357d661d71c8b43ed75a12aac807502e78
1 /*
2 * This file is part of RawTherapee.
4 * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
6 * RawTherapee is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * RawTherapee is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _PROGRESSDIALOG_
20 #define _PROGRESSDIALOG_
22 #include <sigc++/sigc++.h>
23 #include <gtkmm.h>
24 #include <rtengine.h>
26 class PLDBridge : public rtengine::ProgressListener {
28 Gtk::Dialog* dialog;
29 Gtk::Label* label;
30 Gtk::ProgressBar* progBar;
32 public:
33 PLDBridge (Gtk::Dialog* d, Gtk::Label* l, Gtk::ProgressBar* pb)
34 : dialog(d), label(l), progBar(pb) {}
36 // progresslistener interface
37 void setProgress (double p) {
38 gdk_threads_enter ();
39 progBar->set_fraction (p);
40 gdk_threads_leave ();
42 void setProgressStr (Glib::ustring str) {
43 gdk_threads_enter ();
44 Glib::ustring progrstr;
45 if (str=="Decoding...")
46 progrstr = M("PROGRESSBAR_DECODING");
47 else if (str=="Ready.")
48 progrstr = M("PROGRESSBAR_READY");
49 else if (str=="Demosaicing...")
50 progrstr = M("PROGRESSBAR_DEMOSAICING");
51 else if (str=="Loading...")
52 progrstr = M("PROGRESSBAR_LOADING");
53 else if (str=="Loading PNG file...")
54 progrstr = M("PROGRESSBAR_LOADPNG");
55 else if (str=="Loading JPEG file...")
56 progrstr = M("PROGRESSBAR_LOADJPEG");
57 else if (str=="Loading TIFF file...")
58 progrstr = M("PROGRESSBAR_LOADTIFF");
59 else if (str=="Saving PNG file...")
60 progrstr = M("PROGRESSBAR_SAVEPNG");
61 else if (str=="Saving JPEG file...")
62 progrstr = M("PROGRESSBAR_SAVEJPEG");
63 else if (str=="Saving TIFF file...")
64 progrstr = M("PROGRESSBAR_SAVETIFF");
65 else if (str=="Processing...")
66 progrstr = M("PROGRESSBAR_PROCESSING");
67 else
68 progrstr = str;
70 label->set_text (progrstr);
71 gdk_threads_leave ();
73 void setProgressState (int state) {}
74 void error (Glib::ustring descr) {}
77 template<class T>
78 class ProgressDialog : public Gtk::Dialog {
80 sigc::signal0<T> operation;
81 T* retval;
82 Gtk::Label prLabel;
83 Gtk::ProgressBar prProgBar;
85 PLDBridge* pldBridge;
88 void workingThread () {
89 *retval = operation.emit ();
90 gdk_threads_enter ();
91 response (1);
92 gdk_threads_leave ();
95 public:
97 ProgressDialog (Glib::ustring label) : Gtk::Dialog (label, true) {
98 pldBridge = new PLDBridge (this, &prLabel, &prProgBar);
99 get_vbox()->pack_start (prLabel, Gtk::PACK_SHRINK, 4);
100 get_vbox()->pack_start (prProgBar, Gtk::PACK_SHRINK, 4);
101 set_size_request (300, -1);
102 show_all_children ();
105 ~ProgressDialog () {
106 delete pldBridge;
109 rtengine::ProgressListener* getProgressListener () { return pldBridge; }
111 void setFunc (const sigc::slot0<T>& slot, T* rv) {
112 retval = rv;
113 operation.connect (slot);
116 void start () {
117 Glib::Thread *thread = Glib::Thread::create(sigc::mem_fun(*this, &ProgressDialog<T>::workingThread), 0, true, true, Glib::THREAD_PRIORITY_NORMAL);
118 int x = run ();
119 if (x<0) {
120 gdk_threads_leave ();
121 thread->join ();
122 gdk_threads_enter ();
126 #endif