1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2009-08-08 7 * Description : an option to provide camera information to the parser 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 "cameranameoption.h" 25 26 // Qt includes 27 28 #include <QScopedPointer> 29 30 // KDE includes 31 32 #include <klocalizedstring.h> 33 34 // Local includes 35 36 #include "parser.h" 37 #include "dmetadata.h" 38 39 namespace Digikam 40 { 41 CameraNameOption()42CameraNameOption::CameraNameOption() 43 : Option(i18n("Camera"), 44 i18n("Add the camera name"), 45 QLatin1String("camera-photo")) 46 { 47 QString token(QLatin1String("[cam]")); 48 addToken(token, i18n("Camera name")); 49 50 QRegExp reg(escapeToken(token)); 51 reg.setMinimal(true); 52 setRegExp(reg); 53 } 54 parseOperation(ParseSettings & settings)55QString CameraNameOption::parseOperation(ParseSettings& settings) 56 { 57 QString result; 58 59 ItemInfo info = ItemInfo::fromUrl(settings.fileUrl); 60 61 if (!info.isNull()) 62 { 63 result = info.photoInfoContainer().make + QLatin1Char(' ') + info.photoInfoContainer().model; 64 } 65 else 66 { 67 // If ItemInfo is not available, read the information from the EXIF data 68 69 QString make; 70 QString model; 71 72 QScopedPointer<DMetadata> meta(new DMetadata(settings.fileUrl.toLocalFile())); 73 74 if (!meta->isEmpty()) 75 { 76 MetaEngine::MetaDataMap dataMap; 77 dataMap = meta->getExifTagsDataList(QStringList(), true); 78 79 foreach (const QString& key, dataMap.keys()) 80 { 81 if (key.toLower().contains(QLatin1String("exif.image.model"))) 82 { 83 model = dataMap[key]; 84 } 85 else if (key.toLower().contains(QLatin1String("exif.image.make"))) 86 { 87 make = dataMap[key]; 88 } 89 } 90 } 91 92 result = make + QLatin1Char(' ') + model; 93 } 94 95 return result.simplified(); 96 } 97 98 } // namespace Digikam 99