rawTherapee/rtgui/profilestore.cc

132 lines
4.3 KiB
C++

/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "profilestore.h"
#include "options.h"
#include "toolpanel.h"
#include "../rtengine/safegtk.h"
ProfileStore profileStore;
using namespace rtengine;
using namespace rtengine::procparams;
extern Glib::ustring argv0;
ProfileStore::~ProfileStore () {
for (std::map<Glib::ustring,PartialProfile*>::iterator i = partProfiles.begin(); i!=partProfiles.end(); i++) {
if (i->second->pparams) delete i->second->pparams;
if (i->second->pedited) delete i->second->pedited;
delete i->second;
}
}
void ProfileStore::parseProfiles () {
// clear loaded profiles
for (std::map<Glib::ustring,PartialProfile*>::iterator i = partProfiles.begin(); i!=partProfiles.end(); i++) {
delete i->second->pparams;
delete i->second->pedited;
delete i->second;
}
partProfiles.clear ();
if (options.multiUser) {
Glib::ustring userPD = options.rtdir + "/" + options.profilePath;
if (!safe_file_test (userPD, Glib::FILE_TEST_IS_DIR))
safe_g_mkdir_with_parents (userPD, 511);
parseDir (userPD);
}
parseDir (argv0 + "/" + options.profilePath);
}
void ProfileStore::parseDir (const Glib::ustring& pdir) {
// reload the available profiles from the profile dir
if (pdir!="") {
// process directory
Glib::ustring dirname = pdir;
Glib::Dir* dir = NULL;
try {
dir = new Glib::Dir (dirname);
}
catch (const Glib::FileError& fe) {
return;
}
dirname = dirname + "/";
for (Glib::DirIterator i = dir->begin(); i!=dir->end(); ++i) {
Glib::ustring fname = dirname + *i;
Glib::ustring sname = *i;
// ignore directories
if (!safe_file_test (fname, Glib::FILE_TEST_IS_DIR)) {
int lastdot = sname.find_last_of ('.');
if (lastdot!=Glib::ustring::npos && lastdot<=sname.size()-4 && !sname.casefold().compare (lastdot, 4, paramFileExtension)) {
if( options.rtSettings.verbose )
printf ("Processing file %s...\n", fname.c_str());
Glib::ustring name = sname.substr(0,lastdot);
std::map<Glib::ustring,PartialProfile*>::iterator j = partProfiles.find(name);
if (j!=partProfiles.end()) {
j->second->deleteInstance();
delete j->second;
partProfiles.erase (j);
}
PartialProfile* pProf = new PartialProfile (true);
int res = pProf->load (fname);
if (!res && pProf->pparams->ppVersion>=220) {
partProfiles[name] = pProf;
}
else {
pProf->deleteInstance();
delete pProf;
}
}
}
}
delete dir;
}
}
PartialProfile* ProfileStore::getProfile (const Glib::ustring& profname) {
std::map<Glib::ustring, PartialProfile*>::iterator prof = partProfiles.find(profname);
if (prof != partProfiles.end())
return partProfiles[profname];
else
return NULL;
}
std::vector<Glib::ustring> ProfileStore::getProfileNames () {
std::vector<Glib::ustring> ret;
for (std::map<Glib::ustring,PartialProfile*>::iterator i = partProfiles.begin(); i!=partProfiles.end(); i++)
ret.push_back (i->first);
return ret;
}
ProcParams* ProfileStore::getDefaultProcParams (bool isRaw) {
PartialProfile* pProf = getProfile (isRaw ? options.defProfRaw : options.defProfImg);
if (!pProf) {
Glib::ustring profName = isRaw ? options.defProfRaw : options.defProfImg;
pProf = new PartialProfile (true);
partProfiles[profName] = pProf;
}
return pProf->pparams;
}