Proper check for rawzor libraries.
[rawtherapee-fixes.git] / rtgui / cacheimagedata.cc
blobb7e96ff8ccd84ff5b92c9ea5c4f5dc79f8312466
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 <cacheimagedata.h>
20 #include <vector>
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;
32 try {
33 if (!keyFile.load_from_file (fname))
34 return 1;
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");
48 if (timeValid) {
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");
58 exifValid = false;
60 if (keyFile.has_group ("ExifInfo")) {
61 exifValid = true;
62 if (keyFile.has_key ("ExifInfo", "Valid")) exifValid = keyFile.get_boolean ("ExifInfo", "Valid");
64 if (exifValid) {
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");
78 else {
79 rotate = 0;
80 thumbImgType = 0;
82 return 0;
84 catch (Glib::Error) {
85 return 1;
89 int CacheImageData::save (const Glib::ustring& fname) {
91 Glib::KeyFile keyFile;
93 try {
94 keyFile.load_from_file (fname);
95 } catch (...) {}
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);
105 if (timeValid) {
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);
116 if (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");
131 if (!f)
132 return 1;
133 else {
134 fprintf (f, "%s", keyFile.to_data().c_str());
135 fclose (f);
136 return 0;