File indexing completed on 2025-03-09 03:57:06
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-05-22 0007 * Description : common information keys 0008 * 0009 * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "commonkeys.h" 0016 0017 // KDE includes 0018 0019 #include <klocalizedstring.h> 0020 0021 // Local includes 0022 0023 #include "albummanager.h" 0024 #include "coredbinfocontainers.h" 0025 #include "iteminfo.h" 0026 #include "itemcopyright.h" 0027 0028 namespace 0029 { 0030 static const QString KEY_DEFAULTCOMMENT(QLatin1String("DefaultComment")); 0031 static const QString KEY_DIMENSION(QLatin1String("Dimension")); 0032 static const QString KEY_FILESIZE(QLatin1String("FileSize")); 0033 static const QString KEY_FORMAT(QLatin1String("Format")); 0034 static const QString KEY_MEDIATYPE(QLatin1String("MediaType")); 0035 static const QString KEY_RATING(QLatin1String("Rating")); 0036 static const QString KEY_HEIGHT(QLatin1String("Height")); 0037 static const QString KEY_WIDTH(QLatin1String("Width")); 0038 static const QString KEY_ORIENTATION(QLatin1String("Orientation")); 0039 static const QString KEY_COLORDEPTH(QLatin1String("ColorDepth")); 0040 static const QString KEY_COLORMODEL(QLatin1String("ColorModel")); 0041 static const QString KEY_DEFAULTAUTHOR(QLatin1String("DefaultAuthor")); 0042 static const QString KEY_AUTHORS(QLatin1String("Authors")); 0043 static const QString KEY_TITLE(QLatin1String("Title")); 0044 static const QString KEY_TAGSLIST(QLatin1String("TagsList")); 0045 static const QString KEY_TAGSPATHLIST(QLatin1String("TagsPathList")); 0046 } 0047 0048 namespace Digikam 0049 { 0050 0051 CommonKeys::CommonKeys() 0052 : DbKeysCollection(i18n("Common File Information")) 0053 { 0054 addId(KEY_DEFAULTCOMMENT, i18n("Default comment of the image")); 0055 addId(KEY_DEFAULTAUTHOR, i18n("Default author of the image")); 0056 addId(KEY_DIMENSION, i18n("Image dimension")); 0057 addId(KEY_FILESIZE, i18n("Image file size")); 0058 addId(KEY_FORMAT, i18n("Format of the media file")); 0059 addId(KEY_MEDIATYPE, i18n("Type of the media file")); 0060 addId(KEY_RATING, i18n("Rating of the media file")); 0061 addId(KEY_HEIGHT, i18n("Height of the media file")); 0062 addId(KEY_WIDTH, i18n("Width of the media file")); 0063 addId(KEY_ORIENTATION, i18n("Image orientation")); 0064 addId(KEY_COLORDEPTH, i18n("Color depth (bits per channel)")); 0065 addId(KEY_COLORMODEL, i18n("Color model of the image")); 0066 addId(KEY_AUTHORS, i18n("A comma separated list of all authors")); 0067 addId(KEY_TITLE, i18n("Title of the image")); 0068 addId(KEY_TAGSLIST, i18n("A comma separated list of all tags")); 0069 addId(KEY_TAGSPATHLIST, i18n("A comma separated list of all tags with path")); 0070 } 0071 0072 QString CommonKeys::getDbValue(const QString& key, ParseSettings& settings) 0073 { 0074 ItemInfo info = ItemInfo::fromUrl(settings.fileUrl); 0075 ImageCommonContainer container = info.imageCommonContainer(); 0076 ItemCopyright copyright = info.imageCopyright(); 0077 QString result; 0078 0079 if (key == KEY_DEFAULTCOMMENT) 0080 { 0081 result = info.comment().simplified(); 0082 } 0083 else if (key == KEY_DEFAULTAUTHOR) 0084 { 0085 QStringList authors = copyright.author(); 0086 0087 if (!authors.isEmpty()) 0088 { 0089 result = authors.at(0); 0090 } 0091 } 0092 else if (key == KEY_AUTHORS) 0093 { 0094 QStringList authors = copyright.author(); 0095 0096 if (!authors.isEmpty()) 0097 { 0098 Q_FOREACH (const QString& author, authors) 0099 { 0100 // cppcheck-suppress useStlAlgorithm 0101 result += author + QLatin1Char(','); 0102 } 0103 } 0104 0105 if (result.endsWith(QLatin1Char(','))) 0106 { 0107 result.chop(1); 0108 } 0109 } 0110 else if (key == KEY_TITLE) 0111 { 0112 result = info.title().simplified(); 0113 } 0114 else if (key == KEY_TAGSLIST) 0115 { 0116 QList<int> tagIds = info.tagIds(); 0117 QStringList tags = AlbumManager::instance()->tagNames(tagIds); 0118 result = tags.join(QLatin1String(", ")); 0119 } 0120 else if (key == KEY_TAGSPATHLIST) 0121 { 0122 QList<int> tagIds = info.tagIds(); 0123 QStringList tags = AlbumManager::instance()->tagPaths(tagIds, false); 0124 result = tags.join(QLatin1String(", ")); 0125 } 0126 else if (key == KEY_DIMENSION) 0127 { 0128 QSize dimension = info.dimensions(); 0129 0130 if (dimension.isEmpty() || dimension.isNull() || !dimension.isValid()) 0131 { 0132 dimension.setWidth(0); 0133 dimension.setHeight(0); 0134 } 0135 0136 result = QString::fromUtf8("%1x%2").arg(dimension.width()).arg(dimension.height()); 0137 } 0138 else if (key == KEY_HEIGHT) 0139 { 0140 int height = container.height; 0141 0142 if (height < 0) 0143 { 0144 height = 0; 0145 } 0146 0147 result = QString::number(height); 0148 } 0149 else if (key == KEY_WIDTH) 0150 { 0151 int width = container.width; 0152 0153 if (width < 0) 0154 { 0155 width = 0; 0156 } 0157 0158 result = QString::number(width); 0159 } 0160 else if (key == KEY_FILESIZE) 0161 { 0162 result = QString::number(info.fileSize()); 0163 } 0164 else if (key == KEY_FORMAT) 0165 { 0166 result = info.format(); 0167 } 0168 else if (key == KEY_MEDIATYPE) 0169 { 0170 switch (info.category()) 0171 { 0172 case DatabaseItem::UndefinedCategory: 0173 result = QLatin1String("Undefined"); 0174 break; 0175 0176 case DatabaseItem::Image: 0177 result = QLatin1String("Image"); 0178 break; 0179 0180 case DatabaseItem::Video: 0181 result = QLatin1String("Video"); 0182 break; 0183 0184 case DatabaseItem::Audio: 0185 result = QLatin1String("Audio"); 0186 break; 0187 0188 case DatabaseItem::Other: 0189 default: 0190 result = QLatin1String("Other"); 0191 break; 0192 } 0193 } 0194 else if (key == KEY_RATING) 0195 { 0196 result = QString::number(info.rating()); 0197 } 0198 else if (key == KEY_ORIENTATION) 0199 { 0200 result = container.orientation; 0201 } 0202 else if (key == KEY_COLORDEPTH) 0203 { 0204 result = QString::number(container.colorDepth); 0205 } 0206 else if (key == KEY_COLORMODEL) 0207 { 0208 result = container.colorModel; 0209 } 0210 0211 result.replace(QLatin1Char('/'), QLatin1Char('_')); 0212 0213 return result; 0214 } 0215 0216 } // namespace Digikam