Proper check for rawzor libraries.
[rawtherapee-fixes.git] / rtgui / icmpanel.cc
blob25cad194636fa227d1759d9f958c74633ebeea98
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 #include <icmpanel.h>
20 #include <options.h>
21 #include <guiutils.h>
23 using namespace rtengine;
24 using namespace rtengine::procparams;
26 extern Options options;
28 ICMPanel::ICMPanel () : ToolPanel(), icmplistener(NULL), iunchanged(NULL) {
30 // set_border_width (4);
32 ipDialog = Gtk::manage (new Gtk::FileChooserButton (M("TP_ICM_INPUTDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_OPEN));
33 opDialog = Gtk::manage (new Gtk::FileChooserButton (M("TP_ICM_INPUTDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_OPEN));
35 Gtk::Label* ilab = Gtk::manage (new Gtk::Label ());
36 ilab->set_alignment (0.0, 0.5);
37 ilab->set_markup (Glib::ustring("<b>") + M("TP_ICM_INPUTPROFILE") + "</b>");
38 pack_start (*ilab, Gtk::PACK_SHRINK, 4);
40 iembedded = Gtk::manage (new Gtk::RadioButton (M("TP_ICM_INPUTEMBEDDED")));
41 pack_start (*iembedded, Gtk::PACK_SHRINK, 4);
43 icamera = Gtk::manage (new Gtk::RadioButton (M("TP_ICM_INPUTCAMERA")));
44 pack_start (*icamera, Gtk::PACK_SHRINK, 4);
46 ifromfile = Gtk::manage (new Gtk::RadioButton (M("TP_ICM_INPUTCUSTOM")+":"));
47 Gtk::HBox* ffbox = Gtk::manage (new Gtk::HBox ());
48 ffbox->pack_start (*ifromfile, Gtk::PACK_SHRINK);
49 ffbox->pack_start (*ipDialog);
51 pack_start (*ffbox, Gtk::PACK_SHRINK, 4);
53 opts = icamera->get_group();
54 iembedded->set_group (opts);
55 ifromfile->set_group (opts);
57 igamma = Gtk::manage (new Gtk::CheckButton (M("TP_ICM_GAMMABEFOREINPUT")));
58 igamma->set_sensitive (false);
59 pack_start (*igamma, Gtk::PACK_SHRINK, 4);
61 saveRef = Gtk::manage (new Gtk::Button (M("TP_ICM_SAVEREFERENCE")));
62 saveRef->set_image (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON)));
63 pack_start (*saveRef, Gtk::PACK_SHRINK, 4);
66 Gtk::HSeparator* hsep1 = Gtk::manage (new Gtk::HSeparator ());
67 pack_start (*hsep1, Gtk::PACK_SHRINK, 2);
69 Gtk::Label* wlab = Gtk::manage (new Gtk::Label ());
70 wlab->set_alignment (0.0, 0.5);
71 wlab->set_markup (Glib::ustring("<b>") + M("TP_ICM_WORKINGPROFILE") + "</b>");
73 pack_start (*wlab, Gtk::PACK_SHRINK, 4);
74 wnames = Gtk::manage (new Gtk::ComboBoxText ());
75 pack_start (*wnames, Gtk::PACK_SHRINK, 4);
77 Gtk::HSeparator* hsep2 = Gtk::manage (new Gtk::HSeparator ());
78 pack_start (*hsep2, Gtk::PACK_SHRINK, 2);
80 Gtk::Label* olab = Gtk::manage (new Gtk::Label ());
81 olab->set_alignment (0.0, 0.5);
82 olab->set_markup (Glib::ustring("<b>") + M("TP_ICM_OUTPUTPROFILE") + "</b>");
84 pack_start (*olab, Gtk::PACK_SHRINK, 4);
85 onames = Gtk::manage (new Gtk::ComboBoxText ());
86 pack_start (*onames, Gtk::PACK_SHRINK, 4);
88 std::vector<std::string> wpnames = rtengine::getWorkingProfiles ();
89 for (int i=0; i<wpnames.size(); i++)
90 wnames->append_text (wpnames[i]);
92 onames->append_text (M("TP_ICM_NOICM"));
93 onames->set_active (0);
95 std::vector<std::string> opnames = rtengine::getOutputProfiles ();
96 for (int i=0; i<opnames.size(); i++)
97 onames->append_text (opnames[i]);
99 wnames->set_active (0);
100 onames->set_active (0);
102 Gtk::FileFilter filter_icc;
103 filter_icc.set_name(M("TP_ICM_FILEDLGFILTERICM"));
104 filter_icc.add_pattern("*.icc");
105 filter_icc.add_pattern("*.icm");
106 filter_icc.add_pattern("*.ICC");
107 filter_icc.add_pattern("*.ICM");
108 Gtk::FileFilter filter_any;
109 filter_any.set_name(M("TP_ICM_FILEDLGFILTERANY"));
110 filter_any.add_pattern("*");
112 ipDialog->add_filter (filter_icc);
113 ipDialog->add_filter (filter_any);
114 opDialog->add_filter (filter_icc);
115 opDialog->add_filter (filter_any);
117 if (Glib::file_test (options.rtSettings.iccDirectory, Glib::FILE_TEST_IS_DIR)) {
118 ipDialog->set_current_folder (options.rtSettings.iccDirectory);
119 opDialog->set_current_folder (options.rtSettings.iccDirectory);
122 oldip = "";
124 wnames->signal_changed().connect( sigc::mem_fun(*this, &ICMPanel::wpChanged) );
125 onames->signal_changed().connect( sigc::mem_fun(*this, &ICMPanel::opChanged) );
126 icamera->signal_toggled().connect( sigc::mem_fun(*this, &ICMPanel::ipChanged) );
127 iembedded->signal_toggled().connect( sigc::mem_fun(*this, &ICMPanel::ipChanged) );
128 ifromfile->signal_toggled().connect( sigc::mem_fun(*this, &ICMPanel::ipChanged) );
129 ipc = ipDialog->signal_selection_changed().connect( sigc::mem_fun(*this, &ICMPanel::ipSelectionChanged) );
130 saveRef->signal_pressed().connect( sigc::mem_fun(*this, &ICMPanel::saveReferencePressed) );
132 show_all ();
135 void ICMPanel::read (const ProcParams* pp, const ParamsEdited* pedited) {
137 disableListener ();
139 ipc.block (true);
140 if (pp->icm.input == "(embedded)" || ((pp->icm.input == "(camera)" || pp->icm.input=="") && icamera->get_state()==Gtk::STATE_INSENSITIVE)) {
141 iembedded->set_active (true);
142 igamma->set_sensitive (false);
144 else if ((pp->icm.input == "(camera)" || pp->icm.input=="") && icamera->get_state()!=Gtk::STATE_INSENSITIVE) {
145 icamera->set_active (true);
146 igamma->set_sensitive (false);
148 else {
149 ifromfile->set_active (true);
150 oldip = pp->icm.input.substr(5);
151 ipDialog->set_filename (pp->icm.input.substr(5));
152 igamma->set_sensitive (true);
155 wnames->set_active_text (pp->icm.working);
156 if (pp->icm.output=="No ICM: sRGB output")
157 onames->set_active_text (M("TP_ICM_NOICM"));
158 else
159 onames->set_active_text (pp->icm.output);
161 if (onames->get_active_row_number()==-1)
162 onames->set_active_text (M("TP_ICM_NOICM"));
164 igamma->set_active (pp->icm.gammaOnInput);
166 if (pedited) {
167 iunchanged->set_active (!pedited->icm.input);
168 igamma->set_sensitive (false);
169 if (!pedited->icm.working)
170 wnames->set_active_text("(Unchanged)");
171 if (!pedited->icm.output)
172 onames->set_active_text("(Unchanged)");
175 ipc.block (false);
177 enableListener ();
180 void ICMPanel::write (ProcParams* pp, ParamsEdited* pedited) {
182 if (iembedded->get_active ())
183 pp->icm.input = "(embedded)";
184 else if (icamera->get_active ())
185 pp->icm.input = "(camera)";
186 else
187 pp->icm.input = "file:"+ipDialog->get_filename ();
189 pp->icm.working = wnames->get_active_text ();
191 if (onames->get_active_text()==M("TP_ICM_NOICM"))
192 pp->icm.output = "No ICM: sRGB output";
193 else
194 pp->icm.output = onames->get_active_text();
195 pp->icm.gammaOnInput = igamma->get_active ();
197 if (pedited) {
198 pedited->icm.input = !iunchanged->get_active ();
199 pedited->icm.working = wnames->get_active_text()!="(Unchanged)";
200 pedited->icm.output = onames->get_active_text()!="(Unchanged)";
201 pedited->icm.gammaOnInput = !ifromfile->get_active ();
205 void ICMPanel::wpChanged () {
207 if (listener)
208 listener->panelChanged (EvWProfile, wnames->get_active_text ());
211 void ICMPanel::ipChanged () {
213 std::string profname;
214 if (iembedded->get_active ()) {
215 profname = "(embedded)";
216 igamma->set_sensitive (false);
218 else if (icamera->get_active ()) {
219 profname = "(camera)";
220 igamma->set_sensitive (false);
222 else {
223 profname = ipDialog->get_filename ();
224 igamma->set_sensitive (true);
227 if (listener && profname!=oldip)
228 listener->panelChanged (EvIProfile, profname);
230 oldip = profname;
233 void ICMPanel::opChanged () {
235 if (listener)
236 listener->panelChanged (EvOProfile, onames->get_active_text());
239 void ICMPanel::setRaw (bool raw) {
241 disableListener ();
243 icamera->set_active (raw);
244 iembedded->set_active (!raw);
245 icamera->set_sensitive (raw);
246 iembedded->set_sensitive (!raw);
248 enableListener ();
251 void ICMPanel::ipSelectionChanged () {
253 if (ipDialog->get_filename () == "")
254 return;
255 else
256 ipChanged ();
259 void ICMPanel::saveReferencePressed () {
261 if (!icmplistener)
262 return;
263 Gtk::FileChooserDialog dialog(M("TP_ICM_SAVEREFERENCEDLGLABEL"), Gtk::FILE_CHOOSER_ACTION_SAVE);
265 dialog.add_button(Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL);
266 dialog.add_button(Gtk::StockID("gtk-save"), Gtk::RESPONSE_OK);
268 Gtk::FileFilter filter_jpg;
269 filter_jpg.set_name(M("SAVEDLG_JPGFILTER"));
270 filter_jpg.add_pattern("*.jpg");
271 dialog.add_filter(filter_jpg);
273 dialog.set_do_overwrite_confirmation (true);
275 if (dialog.run()==Gtk::RESPONSE_OK)
276 icmplistener->saveInputICCReference (dialog.get_filename());
279 void ICMPanel::setBatchMode (bool batchMode) {
281 ToolPanel::setBatchMode (batchMode);
282 iunchanged = Gtk::manage (new Gtk::RadioButton ("(Unchanged)"));
283 iunchanged->set_group (opts);
284 pack_start (*iunchanged, Gtk::PACK_SHRINK, 4);
285 reorder_child (*iunchanged, 5);
286 removeIfThere (this, saveRef);
287 onames->append_text ("(Unchanged)");
288 wnames->append_text ("(Unchanged)");