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 <cacheimagedata.h>
21 #include <glib/gstdio.h>
23 CacheImageData::CacheImageData ()
24 : md5(""), supported(false), format(FT_Invalid
), rank(0), inTrash(false), recentlySaved(false),
25 timeValid(false), exifValid(false) {
28 int CacheImageData::load (const Glib::ustring
& fname
) {
30 Glib::KeyFile keyFile
;
33 if (!keyFile
.load_from_file (fname
))
36 if (keyFile
.has_group ("General")) {
37 if (keyFile
.has_key ("General", "MD5")) md5
= keyFile
.get_string ("General", "MD5");
38 if (keyFile
.has_key ("General", "Version")) version
= keyFile
.get_integer ("General", "Version");
39 if (keyFile
.has_key ("General", "Supported")) supported
= keyFile
.get_boolean ("General", "Supported");
40 if (keyFile
.has_key ("General", "Format")) format
= (ThFileType
)keyFile
.get_integer ("General", "Format");
41 if (keyFile
.has_key ("General", "Rank")) rank
= keyFile
.get_integer ("General", "Rank");
42 if (keyFile
.has_key ("General", "InTrash")) inTrash
= keyFile
.get_boolean ("General", "InTrash");
43 if (keyFile
.has_key ("General", "RecentlySaved")) recentlySaved
= keyFile
.get_boolean ("General", "RecentlySaved");
46 timeValid
= keyFile
.has_group ("DateTime");
49 if (keyFile
.has_key ("DateTime", "Year")) year
= keyFile
.get_integer ("DateTime", "Year");
50 if (keyFile
.has_key ("DateTime", "Month")) month
= keyFile
.get_integer ("DateTime", "Month");
51 if (keyFile
.has_key ("DateTime", "Day")) day
= keyFile
.get_integer ("DateTime", "Day");
52 if (keyFile
.has_key ("DateTime", "Hour")) hour
= keyFile
.get_integer ("DateTime", "Hour");
53 if (keyFile
.has_key ("DateTime", "Min")) min
= keyFile
.get_integer ("DateTime", "Min");
54 if (keyFile
.has_key ("DateTime", "Sec")) sec
= keyFile
.get_integer ("DateTime", "Sec");
55 if (keyFile
.has_key ("DateTime", "MSec")) msec
= keyFile
.get_integer ("DateTime", "MSec");
60 if (keyFile
.has_group ("ExifInfo")) {
62 if (keyFile
.has_key ("ExifInfo", "Valid")) exifValid
= keyFile
.get_boolean ("ExifInfo", "Valid");
65 if (keyFile
.has_key ("ExifInfo", "FNumber")) fnumber
= keyFile
.get_double ("ExifInfo", "FNumber");
66 if (keyFile
.has_key ("ExifInfo", "Shutter")) shutter
= keyFile
.get_double ("ExifInfo", "Shutter");
67 if (keyFile
.has_key ("ExifInfo", "FocalLen")) focalLen
= keyFile
.get_double ("ExifInfo", "FocalLen");
68 if (keyFile
.has_key ("ExifInfo", "ISO")) iso
= keyFile
.get_integer ("ExifInfo", "ISO");
70 if (keyFile
.has_key ("ExifInfo", "Lens")) lens
= keyFile
.get_string ("ExifInfo", "Lens");
71 if (keyFile
.has_key ("ExifInfo", "Camera")) camera
= keyFile
.get_string ("ExifInfo", "Camera");
74 if (format
==FT_Raw
&& keyFile
.has_group ("ExtraRawInfo")) {
75 if (keyFile
.has_key ("ExtraRawInfo", "ThumbImageType")) thumbImgType
= keyFile
.get_integer ("ExtraRawInfo", "ThumbImageType");
76 if (keyFile
.has_key ("ExtraRawInfo", "ThumbImageOffset")) thumbOffset
= keyFile
.get_integer ("ExtraRawInfo", "ThumbImageOffset");
89 int CacheImageData::save (const Glib::ustring
& fname
) {
91 Glib::KeyFile keyFile
;
94 keyFile
.load_from_file (fname
);
97 keyFile
.set_string ("General", "MD5", md5
);
98 keyFile
.set_integer ("General", "Version", options
.version
);
99 keyFile
.set_boolean ("General", "Supported", supported
);
100 keyFile
.set_integer ("General", "Format", format
);
101 keyFile
.set_integer ("General", "Rank", rank
);
102 keyFile
.set_boolean ("General", "InTrash", inTrash
);
103 keyFile
.set_boolean ("General", "RecentlySaved", recentlySaved
);
106 keyFile
.set_integer ("DateTime", "Year", year
);
107 keyFile
.set_integer ("DateTime", "Month", month
);
108 keyFile
.set_integer ("DateTime", "Day", day
);
109 keyFile
.set_integer ("DateTime", "Hour", hour
);
110 keyFile
.set_integer ("DateTime", "Min", min
);
111 keyFile
.set_integer ("DateTime", "Sec", sec
);
112 keyFile
.set_integer ("DateTime", "MSec", msec
);
115 keyFile
.set_boolean ("ExifInfo", "Valid", exifValid
);
117 keyFile
.set_double ("ExifInfo", "FNumber", fnumber
);
118 keyFile
.set_double ("ExifInfo", "Shutter", shutter
);
119 keyFile
.set_double ("ExifInfo", "FocalLen", focalLen
);
120 keyFile
.set_integer ("ExifInfo", "ISO", iso
);
122 keyFile
.set_string ("ExifInfo", "Lens", lens
);
123 keyFile
.set_string ("ExifInfo", "Camera", camera
);
125 if (format
==FT_Raw
) {
126 keyFile
.set_integer ("ExtraRawInfo", "ThumbImageType", thumbImgType
);
127 keyFile
.set_integer ("ExtraRawInfo", "ThumbImageOffset", thumbOffset
);
130 FILE *f
= g_fopen (fname
.c_str(), "wt");
134 fprintf (f
, "%s", keyFile
.to_data().c_str());