1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2010-05-22
7 * Description : common information keys
8 *
9 * Copyright (C) 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * ============================================================ */
23
24 #include "commonkeys.h"
25
26 // KDE includes
27
28 #include <klocalizedstring.h>
29
30 // Local includes
31
32 #include "albummanager.h"
33 #include "coredbinfocontainers.h"
34 #include "iteminfo.h"
35 #include "itemcopyright.h"
36
37 namespace
38 {
39 static const QString KEY_DEFAULTCOMMENT(QLatin1String("DefaultComment"));
40 static const QString KEY_DIMENSION(QLatin1String("Dimension"));
41 static const QString KEY_FILESIZE(QLatin1String("FileSize"));
42 static const QString KEY_FORMAT(QLatin1String("Format"));
43 static const QString KEY_MEDIATYPE(QLatin1String("MediaType"));
44 static const QString KEY_RATING(QLatin1String("Rating"));
45 static const QString KEY_HEIGHT(QLatin1String("Height"));
46 static const QString KEY_WIDTH(QLatin1String("Width"));
47 static const QString KEY_ORIENTATION(QLatin1String("Orientation"));
48 static const QString KEY_COLORDEPTH(QLatin1String("ColorDepth"));
49 static const QString KEY_COLORMODEL(QLatin1String("ColorModel"));
50 static const QString KEY_DEFAULTAUTHOR(QLatin1String("DefaultAuthor"));
51 static const QString KEY_AUTHORS(QLatin1String("Authors"));
52 static const QString KEY_TITLE(QLatin1String("Title"));
53 static const QString KEY_TAGSLIST(QLatin1String("TagsList"));
54 static const QString KEY_TAGSPATHLIST(QLatin1String("TagsPathList"));
55 }
56
57 namespace Digikam
58 {
59
CommonKeys()60 CommonKeys::CommonKeys()
61 : DbKeysCollection(i18n("Common File Information"))
62 {
63 addId(KEY_DEFAULTCOMMENT, i18n("Default comment of the image"));
64 addId(KEY_DEFAULTAUTHOR, i18n("Default author of the image"));
65 addId(KEY_DIMENSION, i18n("Image dimension"));
66 addId(KEY_FILESIZE, i18n("Image file size"));
67 addId(KEY_FORMAT, i18n("Format of the media file"));
68 addId(KEY_MEDIATYPE, i18n("Type of the media file"));
69 addId(KEY_RATING, i18n("Rating of the media file"));
70 addId(KEY_HEIGHT, i18n("Height of the media file"));
71 addId(KEY_WIDTH, i18n("Width of the media file"));
72 addId(KEY_ORIENTATION, i18n("Image orientation"));
73 addId(KEY_COLORDEPTH, i18n("Color depth (bits per channel)"));
74 addId(KEY_COLORMODEL, i18n("Color model of the image"));
75 addId(KEY_AUTHORS, i18n("A comma separated list of all authors"));
76 addId(KEY_TITLE, i18n("Title of the image"));
77 addId(KEY_TAGSLIST, i18n("A comma separated list of all tags"));
78 addId(KEY_TAGSPATHLIST, i18n("A comma separated list of all tags with path"));
79 }
80
getDbValue(const QString & key,ParseSettings & settings)81 QString CommonKeys::getDbValue(const QString& key, ParseSettings& settings)
82 {
83 ItemInfo info = ItemInfo::fromUrl(settings.fileUrl);
84 ImageCommonContainer container = info.imageCommonContainer();
85 ItemCopyright copyright = info.imageCopyright();
86 QString result;
87
88 if (key == KEY_DEFAULTCOMMENT)
89 {
90 result = info.comment().simplified();
91 }
92 else if (key == KEY_DEFAULTAUTHOR)
93 {
94 QStringList authors = copyright.author();
95
96 if (!authors.isEmpty())
97 {
98 result = authors.at(0);
99 }
100 }
101 else if (key == KEY_AUTHORS)
102 {
103 QStringList authors = copyright.author();
104
105 if (!authors.isEmpty())
106 {
107 foreach (const QString& author, authors)
108 {
109 result += author + QLatin1Char(',');
110 }
111 }
112
113 if (result.endsWith(QLatin1Char(',')))
114 {
115 result.chop(1);
116 }
117 }
118 else if (key == KEY_TITLE)
119 {
120 result = info.title().simplified();
121 }
122 else if (key == KEY_TAGSLIST)
123 {
124 QList<int> tagIds = info.tagIds();
125 QStringList tags = AlbumManager::instance()->tagNames(tagIds);
126 result = tags.join(QLatin1String(", "));
127 }
128 else if (key == KEY_TAGSPATHLIST)
129 {
130 QList<int> tagIds = info.tagIds();
131 QStringList tags = AlbumManager::instance()->tagPaths(tagIds, false);
132 result = tags.join(QLatin1String(", "));
133 }
134 else if (key == KEY_DIMENSION)
135 {
136 QSize dimension = info.dimensions();
137
138 if (dimension.isEmpty() || dimension.isNull() || !dimension.isValid())
139 {
140 dimension.setWidth(0);
141 dimension.setHeight(0);
142 }
143
144 result = QString::fromUtf8("%1x%2").arg(dimension.width()).arg(dimension.height());
145 }
146 else if (key == KEY_HEIGHT)
147 {
148 int height = container.height;
149
150 if (height < 0)
151 {
152 height = 0;
153 }
154
155 result = QString::number(height);
156 }
157 else if (key == KEY_WIDTH)
158 {
159 int width = container.width;
160
161 if (width < 0)
162 {
163 width = 0;
164 }
165
166 result = QString::number(width);
167 }
168 else if (key == KEY_FILESIZE)
169 {
170 result = QString::number(info.fileSize());
171 }
172 else if (key == KEY_FORMAT)
173 {
174 result = info.format();
175 }
176 else if (key == KEY_MEDIATYPE)
177 {
178 switch (info.category())
179 {
180 case DatabaseItem::UndefinedCategory:
181 result = QLatin1String("Undefined");
182 break;
183
184 case DatabaseItem::Image:
185 result = QLatin1String("Image");
186 break;
187
188 case DatabaseItem::Video:
189 result = QLatin1String("Video");
190 break;
191
192 case DatabaseItem::Audio:
193 result = QLatin1String("Audio");
194 break;
195
196 case DatabaseItem::Other:
197 default:
198 result = QLatin1String("Other");
199 break;
200 }
201 }
202 else if (key == KEY_RATING)
203 {
204 result = QString::number(info.rating());
205 }
206 else if (key == KEY_ORIENTATION)
207 {
208 result = container.orientation;
209 }
210 else if (key == KEY_COLORDEPTH)
211 {
212 result = QString::number(container.colorDepth);
213 }
214 else if (key == KEY_COLORMODEL)
215 {
216 result = container.colorModel;
217 }
218
219 result.replace(QLatin1Char('/'), QLatin1Char('_'));
220
221 return result;
222 }
223
224 } // namespace Digikam
225