2
* Copyright (C) 2009 Anne-Marie Mahfouf <annma@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#include "metadata_engine.h"
26
#include <kfilemetainfo.h>
29
#include <Nepomuk/Resource>
30
#include <Nepomuk/ResourceManager>
31
#include <Nepomuk/Tag>
33
MetaDataEngine::MetaDataEngine(QObject* parent, const QVariantList& args) :
34
Plasma::DataEngine(parent, args)
38
MetaDataEngine::~MetaDataEngine()
42
void MetaDataEngine::init()
44
Nepomuk::ResourceManager::instance()->init();
47
bool MetaDataEngine::sourceRequestEvent(const QString &name)
49
updateSourceEvent(name);
53
bool MetaDataEngine::updateSourceEvent(const QString &name)
55
// Get picture general properties through KFileMetaInfo
56
const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest |
57
KFileMetaInfo::TechnicalInfo |
58
KFileMetaInfo::ContentInfo;
59
const KFileMetaInfo fileMetaInfo(name, QString(), flags);
60
if (fileMetaInfo.isValid()) {
61
const QHash<QString, KFileMetaInfoItem>& items = fileMetaInfo.items();
62
QHash<QString, KFileMetaInfoItem>::const_iterator it = items.constBegin();
63
const QHash<QString, KFileMetaInfoItem>::const_iterator end = items.constEnd();
66
const KFileMetaInfoItem& metaInfoItem = it.value();
67
const QVariant& value = metaInfoItem.value();
69
if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) {
70
if (labelText == i18nc("@label", "Size")) {
71
const QString s = QString::number(value.toDouble()/1024/1024, 'f', 2);
72
setData(name, labelText, QString::fromLatin1("%1 Mb").arg(s));
73
} else if (labelText == i18nc("@label", "Source Modified")) {
74
QVariant newValue = QVariant(value.toDateTime());
75
setData(name, labelText, newValue.toString());
77
setData(name, labelText, value.toString());
85
// Get picture tags through Nepomuk
86
QUrl uri = QUrl(name);
88
Nepomuk::Resource res( uri);
89
QList<Nepomuk::Tag> picTags = res.tags();
90
Q_FOREACH(const Nepomuk::Tag& tag, picTags) {
91
tags.append(tag.label() + ", ");
94
setData(name, "tags", tags);
95
// Get picture comment through Nepomuk
96
setData(name, "comment", res.description());
97
// Get picture rating through Nepomuk
98
setData(name, "rating", QString::number(res.rating()));
103
bool MetaDataEngine::convertMetaInfo(const QString& key, QString& text) const
110
// keys list, more can be added
111
static const MetaKey keys[] = {
112
{ "http://freedesktop.org/standards/xesam/1.0/core#cameraModel", i18nc("@label", "Model") },
113
{ "http://freedesktop.org/standards/xesam/1.0/core#focalLength", i18nc("@label", "Focal Length") },
114
{ "http://freedesktop.org/standards/xesam/1.0/core#mimeType", i18nc("@label", "Mime Type") },
115
{ "http://freedesktop.org/standards/xesam/1.0/core#cameraManufacturer", i18nc("@label", "Manufacturer") },
116
{ "http://freedesktop.org/standards/xesam/1.0/core#sourceModified", i18nc("@label", "Source Modified") },
117
{ "http://freedesktop.org/standards/xesam/1.0/core#orientation", i18nc("@label", "Orientation") },
118
{ "http://freedesktop.org/standards/xesam/1.0/core#flashUsed", i18nc("@label", "Flash Used") },
119
{ "http://freedesktop.org/standards/xesam/1.0/core#height", i18nc("@label", "Height") },
120
{ "http://freedesktop.org/standards/xesam/1.0/core#width", i18nc("@label", "Width") },
121
{ "http://freedesktop.org/standards/xesam/1.0/core#url", i18nc("@label", "Url") },
122
{ "http://freedesktop.org/standards/xesam/1.0/core#size", i18nc("@label", "Size") },
123
{ "http://freedesktop.org/standards/xesam/1.0/core#aperture", i18nc("@label", "Aperture") },
124
{ "http://freedesktop.org/standards/xesam/1.0/core#meteringMode", i18nc("@label", "Metering Mode") },
125
{ "http://freedesktop.org/standards/xesam/1.0/core#35mmEquivalent", i18nc("@label", "35mm Equivalent") },
126
{ "http://freedesktop.org/standards/xesam/1.0/core#fileExtension", i18nc("@label", "File Extension") },
127
{ "http://freedesktop.org/standards/xesam/1.0/core#name", i18nc("@label", "Name") },
128
{ "http://freedesktop.org/standards/xesam/1.0/core#exposureTime", i18nc("@label", "Exposure Time") }
131
// search if the key exists and get its value
133
int bottom = sizeof(keys) / sizeof(MetaKey) - 1;
134
while (top <= bottom) {
135
const int result = key.compare(keys[top].key);
137
text = keys[top].text;
146
K_EXPORT_PLASMA_DATAENGINE(metadata, MetaDataEngine)
148
#include "metadata_engine.moc"