Proper check for rawzor libraries.
[rawtherapee-fixes.git] / rtgui / renamedlg.cc
blob5a000d3f82c76840d77a241b7d7e95fa23d3fc5d
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 <renamedlg.h>
20 #include <multilangmgr.h>
21 #include <options.h>
22 #include "config.h"
24 RenameDialog::RenameDialog (Gtk::Window* parent)
25 : Gtk::Dialog (M("FILEBROWSER_RENAMEDLGLABEL"), *parent, true, true), imageData(NULL), p(parent) {
27 Gtk::Table* names = Gtk::manage (new Gtk::Table (2, 2));
28 Gtk::Label* onlab = Gtk::manage (new Gtk::Label ("Current name:"));
29 Gtk::Label* nnlab = Gtk::manage (new Gtk::Label ("New name:"));
30 oldName = Gtk::manage (new Gtk::Label ("alma"));
31 newName = Gtk::manage (new Gtk::Entry ());
33 names->attach (*onlab, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
34 names->attach (*oldName, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2);
35 names->attach (*nnlab, 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
36 names->attach (*newName, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2);
38 get_vbox()->pack_start (*names, Gtk::PACK_SHRINK, 4);
40 Gtk::HBox* tbox = Gtk::manage (new Gtk::HBox());
41 useTmpl = Gtk::manage (new Gtk::CheckButton ("Use template:"));
42 templates = Gtk::manage (new Gtk::ComboBox ());
43 templateModel = Gtk::ListStore::create (templateColumns);
44 templates->set_model (templateModel);
45 templates->pack_start (templateColumns.tmplName);
47 tbox->pack_start (*useTmpl, Gtk::PACK_SHRINK, 4);
48 tbox->pack_start (*templates);
50 get_vbox()->pack_start (*tbox, Gtk::PACK_SHRINK, 4);
52 add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
53 add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
54 all = add_button ("All", RESPONSE_ALL);
56 newName->set_activates_default (true);
57 set_default_response (Gtk::RESPONSE_OK);
59 fillTemplateList ();
61 templates->set_row_separator_func (sigc::mem_fun(*this, &RenameDialog::rowSeparatorFunc));
62 templates->signal_changed().connect(sigc::mem_fun(*this, &RenameDialog::tmplSelectionChanged));
63 useTmpl->signal_toggled().connect( sigc::mem_fun(*this, &RenameDialog::useTemplToggled) );
65 useTmpl->set_active (options.renameUseTemplates);
67 show_all_children ();
70 void RenameDialog::initName (const Glib::ustring& iname, const CacheImageData* cid) {
72 imageData = cid;
73 oldName->set_text (iname);
74 newName->set_text (iname);
75 if (useTmpl->get_active () && isTemplSelected ())
76 newName->set_text (applyTemplate (iname, cid, getActiveTemplate()));
77 newName->select_region (0, newName->get_text().size());
80 Glib::ustring RenameDialog::getNewName () {
82 return newName->get_text ();
85 void RenameDialog::fillTemplateList () {
87 templateModel->clear ();
89 for (int i=0; i<options.renameTemplates.size(); i++) {
90 Gtk::TreeModel::iterator iter = templateModel->append ();
91 iter->set_value (templateColumns.tmplName, options.renameTemplates[i]);
92 iter->set_value (templateColumns.rowSeparator, false);
94 // append separator and the manage... item
95 Gtk::TreeModel::iterator iter = templateModel->append ();
96 iter->set_value (templateColumns.tmplName, Glib::ustring(""));
97 iter->set_value (templateColumns.rowSeparator, true);
98 iter = templateModel->append ();
99 iter->set_value (templateColumns.tmplName, Glib::ustring("Add/Del templates..."));
100 iter->set_value (templateColumns.rowSeparator, false);
103 bool RenameDialog::rowSeparatorFunc (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::iterator& iter) {
105 return iter->get_value (templateColumns.rowSeparator);
108 void RenameDialog::useTemplToggled () {
110 templates->set_sensitive (useTmpl->get_active ());
111 if (useTmpl->get_active () && isTemplSelected ()) {
112 all->set_sensitive (true);
113 newName->set_text (applyTemplate (oldName->get_text(), imageData, getActiveTemplate()));
115 else
116 all->set_sensitive (false);
117 newName->select_region (0, newName->get_text().size());
120 bool RenameDialog::isTemplSelected () {
122 Gtk::TreeModel::iterator iter = templates->get_active();
123 return iter && iter->get_value (templateColumns.tmplName)!="Add/Del templates...";
126 Glib::ustring RenameDialog::getActiveTemplate () {
128 Gtk::TreeModel::iterator iter = templates->get_active();
129 if (iter && iter->get_value (templateColumns.tmplName)!="Add/Del templates...")
130 return iter->get_value (templateColumns.tmplName);
131 else
132 return "";
135 void RenameDialog::tmplSelectionChanged () {
137 Gtk::TreeModel::iterator iter = templates->get_active();
138 if (iter && iter->get_value (templateColumns.tmplName)=="Add/Del templates...") {
139 RenameTemplateEditor* rte = new RenameTemplateEditor (p);
140 if (rte->run()==Gtk::RESPONSE_OK) {
141 fillTemplateList ();
143 delete rte;
144 // show add/del template dialog
146 else
147 useTemplToggled ();
150 RenameTemplateEditor::RenameTemplateEditor (Gtk::Window* parent)
151 : Gtk::Dialog ("Edit rename templates", *parent, true, true) {
153 list = Gtk::manage (new Gtk::ListViewText (1, false, Gtk::SELECTION_MULTIPLE));
154 list->set_headers_visible (false);
155 get_vbox ()->pack_start (*list);
157 Gtk::HBox* hb = Gtk::manage (new Gtk::HBox ());
158 templ = Gtk::manage (new Gtk::Entry ());
159 Gtk::Button* add = Gtk::manage (new Gtk::Button ());
160 Gtk::Button* del = Gtk::manage (new Gtk::Button ());
161 add->add (*Gtk::manage (new Gtk::Image (GET_DATA_PATH(argv0)+"/images/list-add12.png")));
162 del->add (*Gtk::manage (new Gtk::Image (GET_DATA_PATH(argv0)+"/images/list-remove12r.png")));
163 hb->pack_start (*templ);
164 hb->pack_start (*add, Gtk::PACK_SHRINK, 2);
165 hb->pack_start (*del, Gtk::PACK_SHRINK, 2);
167 get_vbox ()->pack_start (*hb, Gtk::PACK_SHRINK, 4);
169 add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
171 refreshTemplateList ();
173 add->signal_pressed().connect( sigc::mem_fun(*this, &RenameTemplateEditor::addPressed) );
174 del->signal_pressed().connect( sigc::mem_fun(*this, &RenameTemplateEditor::delPressed) );
176 show_all_children ();
178 set_size_request (-1, 250);
181 void RenameTemplateEditor::refreshTemplateList () {
183 list->clear_items ();
185 for (int i=0; i<options.renameTemplates.size(); i++)
186 list->append_text (options.renameTemplates[i]);
189 void RenameTemplateEditor::addPressed () {
191 if (templ->get_text()!="") {
192 options.renameTemplates.push_back (templ->get_text ());
193 refreshTemplateList ();
194 templ->set_text("");
198 void RenameTemplateEditor::delPressed () {
200 std::vector<int> sel = list->get_selected ();
201 for (int i=0; i<sel.size(); i++) {
202 Glib::ustring toDel = list->get_text (sel[i]);
203 std::vector<Glib::ustring>::iterator f = std::find (options.renameTemplates.begin(), options.renameTemplates.end(), toDel);
204 if (f!=options.renameTemplates.end())
205 options.renameTemplates.erase (f);
207 refreshTemplateList ();
210 Glib::ustring RenameDialog::applyTemplate (const Glib::ustring& oName, const CacheImageData* cid, const Glib::ustring& templ) {
212 return Glib::ustring ("szeva");