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 <profilestore.h>
23 ProfileStore profileStore
;
25 using namespace rtengine
;
26 using namespace rtengine::procparams
;
28 extern Glib::ustring argv0
;
30 void ProfileStore::parseProfiles () {
32 // clear loaded profiles
33 for (std::map
<Glib::ustring
,ProcParams
*>::iterator i
= pparams
.begin(); i
!=pparams
.end(); i
++)
37 if (options
.multiUser
) {
38 Glib::ustring userPD
= options
.rtdir
+ "/" + options
.profilePath
;
39 if (!Glib::file_test (userPD
, Glib::FILE_TEST_IS_DIR
))
40 g_mkdir_with_parents (userPD
.c_str(), 511);
43 parseDir (GET_DATA_PATH(argv0
) + "/" + options
.profilePath
);
46 void ProfileStore::parseDir (const Glib::ustring
& pdir
) {
48 // reload the available profiles from the profile dir
51 Glib::ustring dirname
= pdir
;
52 Glib::Dir
* dir
= NULL
;
54 dir
= new Glib::Dir (dirname
);
56 catch (const Glib::FileError
& fe
) {
59 dirname
= dirname
+ "/";
60 for (Glib::DirIterator i
= dir
->begin(); i
!=dir
->end(); ++i
) {
61 Glib::ustring fname
= dirname
+ *i
;
62 Glib::ustring sname
= *i
;
64 if (!Glib::file_test (fname
, Glib::FILE_TEST_IS_DIR
)) {
65 int lastdot
= sname
.find_last_of ('.');
66 if (lastdot
!=Glib::ustring::npos
&& lastdot
<=sname
.size()-4 && !sname
.casefold().compare (lastdot
, 4, ".pp2")) {
67 printf ("processing file %s...\n", fname
.c_str());
68 Glib::ustring name
= sname
.substr(0,lastdot
);
69 if (pparams
.find(name
)!=pparams
.end()) {
71 pparams
.erase (pparams
.find(name
));
73 ProcParams
* pp
= new ProcParams ();
74 int res
= pp
->load (fname
);
75 if (!res
&& pp
->version
>=220)
86 rtengine::procparams::ProcParams
* ProfileStore::getProfile (const Glib::ustring
& profname
) {
88 return pparams
[profname
];
91 std::vector
<Glib::ustring
> ProfileStore::getProfileNames () {
93 std::vector
<Glib::ustring
> ret
;
94 for (std::map
<Glib::ustring
,ProcParams
*>::iterator i
= pparams
.begin(); i
!=pparams
.end(); i
++)
95 ret
.push_back (i
->first
);
99 rtengine::procparams::ProcParams
* ProfileStore::getDefaultProcParams (bool isRaw
) {
102 return getProfile (options
.defProfImg
);
104 return getProfile (options
.defProfRaw
);