┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorVishesh Handa <[email protected]>2014-02-06 20:29:09 +0100
committerVishesh Handa <[email protected]>2014-02-06 20:29:09 +0100
commit64afe7b22622f79b34aafd54501b08120ab2fc5c (patch)
tree125752b2bc33c5e9db84f197dced5d61a7d46e94 /src/kitemviews
parent2c20502c346d975bff854567c038bf0b78c3b857 (diff)
Port Dolphin to Baloo
Nepomuk is being replaced with Baloo
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp4
-rw-r--r--src/kitemviews/kfileitemmodel.h8
-rw-r--r--src/kitemviews/kfileitemmodelrolesupdater.cpp167
-rw-r--r--src/kitemviews/kfileitemmodelrolesupdater.h32
-rw-r--r--src/kitemviews/private/kbaloorolesprovider.cpp184
-rw-r--r--src/kitemviews/private/kbaloorolesprovider.h (renamed from src/kitemviews/private/knepomukrolesprovider.h)30
-rw-r--r--src/kitemviews/private/knepomukrolesprovider.cpp201
7 files changed, 280 insertions, 346 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index b3c56e1c6..734950257 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -673,7 +673,7 @@ QList<KFileItemModel::RoleInfo> KFileItemModel::rolesInformation()
// menus tries to put the actions into sub menus otherwise.
info.group = QString();
}
- info.requiresNepomuk = map[i].requiresNepomuk;
+ info.requiresBaloo = map[i].requiresBaloo;
info.requiresIndexer = map[i].requiresIndexer;
rolesInfo.append(info);
}
@@ -2081,7 +2081,7 @@ void KFileItemModel::emitSortProgress(int resolvedCount)
const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
{
static const RoleInfoMap rolesInfoMap[] = {
- // | role | roleType | role translation | group translation | requires Nepomuk | requires indexer
+ // | role | roleType | role translation | group translation | requires Baloo | requires indexer
{ 0, NoRole, 0, 0, 0, 0, false, false },
{ "text", NameRole, I18N_NOOP2_NOSTRIP("@label", "Name"), 0, 0, false, false },
{ "size", SizeRole, I18N_NOOP2_NOSTRIP("@label", "Size"), 0, 0, false, false },
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index 022429023..15f4b67d3 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -187,14 +187,14 @@ public:
{ QByteArray role;
QString translation;
QString group;
- bool requiresNepomuk;
+ bool requiresBaloo;
bool requiresIndexer;
};
/**
* @return Provides static information for all available roles that
* are supported by KFileItemModel. Some roles can only be
- * determined if Nepomuk is enabled and/or the Nepomuk
+ * determined if Baloo is enabled and/or the Baloo
* indexing is enabled.
*/
static QList<RoleInfo> rolesInformation();
@@ -287,7 +287,7 @@ private:
// User visible roles:
NoRole, NameRole, SizeRole, DateRole, PermissionsRole, OwnerRole,
GroupRole, TypeRole, DestinationRole, PathRole,
- // User visible roles available with Nepomuk:
+ // User visible roles available with Baloo:
CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole,
WordCountRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole,
CopiedFromRole,
@@ -432,7 +432,7 @@ private:
const char* const roleTranslation;
const char* const groupTranslationContext;
const char* const groupTranslation;
- const bool requiresNepomuk;
+ const bool requiresBaloo;
const bool requiresIndexer;
};
diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp
index f11d5a5d3..0865d40e7 100644
--- a/src/kitemviews/kfileitemmodelrolesupdater.cpp
+++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp
@@ -40,10 +40,11 @@
#include <algorithm>
-#ifdef HAVE_NEPOMUK
- #include "private/knepomukrolesprovider.h"
- #include <Nepomuk2/ResourceWatcher>
- #include <Nepomuk2/ResourceManager>
+#ifdef HAVE_BALOO
+ #include "private/kbaloorolesprovider.h"
+ #include <baloo/file.h>
+ #include <baloo/filefetchjob.h>
+ #include <baloo/filemonitor.h>
#endif
// #define KFILEITEMMODELROLESUPDATER_DEBUG
@@ -88,9 +89,8 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
m_recentlyChangedItems(),
m_changedItems(),
m_directoryContentsCounter(0)
- #ifdef HAVE_NEPOMUK
- , m_nepomukResourceWatcher(0),
- m_nepomukUriItems()
+ #ifdef HAVE_BALOO
+ , m_balooFileMonitor(0)
#endif
{
Q_ASSERT(model);
@@ -122,8 +122,8 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
m_resolvableRoles.insert("size");
m_resolvableRoles.insert("type");
m_resolvableRoles.insert("isExpandable");
-#ifdef HAVE_NEPOMUK
- m_resolvableRoles += KNepomukRolesProvider::instance().roles();
+#ifdef HAVE_BALOO
+ m_resolvableRoles += KBalooRolesProvider::instance().roles();
#endif
m_directoryContentsCounter = new KDirectoryContentsCounter(m_model, this);
@@ -262,34 +262,29 @@ void KFileItemModelRolesUpdater::setRoles(const QSet<QByteArray>& roles)
if (m_roles != roles) {
m_roles = roles;
-#ifdef HAVE_NEPOMUK
- if (Nepomuk2::ResourceManager::instance()->initialized()) {
- // Check whether there is at least one role that must be resolved
- // with the help of Nepomuk. If this is the case, a (quite expensive)
- // resolving will be done in KFileItemModelRolesUpdater::rolesData() and
- // the role gets watched for changes.
- const KNepomukRolesProvider& rolesProvider = KNepomukRolesProvider::instance();
- bool hasNepomukRole = false;
- QSetIterator<QByteArray> it(roles);
- while (it.hasNext()) {
- const QByteArray& role = it.next();
- if (rolesProvider.roles().contains(role)) {
- hasNepomukRole = true;
- break;
- }
+#ifdef HAVE_BALOO
+ // Check whether there is at least one role that must be resolved
+ // with the help of Baloo. If this is the case, a (quite expensive)
+ // resolving will be done in KFileItemModelRolesUpdater::rolesData() and
+ // the role gets watched for changes.
+ const KBalooRolesProvider& rolesProvider = KBalooRolesProvider::instance();
+ bool hasBalooRole = false;
+ QSetIterator<QByteArray> it(roles);
+ while (it.hasNext()) {
+ const QByteArray& role = it.next();
+ if (rolesProvider.roles().contains(role)) {
+ hasBalooRole = true;
+ break;
}
+ }
- if (hasNepomukRole && !m_nepomukResourceWatcher) {
- Q_ASSERT(m_nepomukUriItems.isEmpty());
-
- m_nepomukResourceWatcher = new Nepomuk2::ResourceWatcher(this);
- connect(m_nepomukResourceWatcher, SIGNAL(propertyChanged(Nepomuk2::Resource,Nepomuk2::Types::Property,QVariantList,QVariantList)),
- this, SLOT(applyChangedNepomukRoles(Nepomuk2::Resource,Nepomuk2::Types::Property)));
- } else if (!hasNepomukRole && m_nepomukResourceWatcher) {
- delete m_nepomukResourceWatcher;
- m_nepomukResourceWatcher = 0;
- m_nepomukUriItems.clear();
- }
+ if (hasBalooRole && !m_balooFileMonitor) {
+ m_balooFileMonitor = new Baloo::FileMonitor(this);
+ connect(m_balooFileMonitor, SIGNAL(fileMetaDataChanged(QString)),
+ this, SLOT(applyChangedBalooRoles(QString)));
+ } else if (!hasBalooRole && m_balooFileMonitor) {
+ delete m_balooFileMonitor;
+ m_balooFileMonitor = 0;
}
#endif
@@ -357,30 +352,19 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang
const bool allItemsRemoved = (m_model->count() == 0);
-#ifdef HAVE_NEPOMUK
- if (m_nepomukResourceWatcher) {
- // Don't let the ResourceWatcher watch for removed items
+#ifdef HAVE_BALOO
+ if (m_balooFileMonitor) {
+ // Don't let the FileWatcher watch for removed items
if (allItemsRemoved) {
- m_nepomukResourceWatcher->setResources(QList<Nepomuk2::Resource>());
- m_nepomukResourceWatcher->stop();
- m_nepomukUriItems.clear();
+ m_balooFileMonitor->clear();
} else {
- QList<Nepomuk2::Resource> newResources;
- const QList<Nepomuk2::Resource> oldResources = m_nepomukResourceWatcher->resources();
- foreach (const Nepomuk2::Resource& resource, oldResources) {
- const QUrl uri = resource.uri();
- const KUrl itemUrl = m_nepomukUriItems.value(uri);
+ QStringList newFileList;
+ foreach (const QString& itemUrl, m_balooFileMonitor->files()) {
if (m_model->index(itemUrl) >= 0) {
- newResources.append(resource);
- } else {
- m_nepomukUriItems.remove(uri);
+ newFileList.append(itemUrl);
}
}
- m_nepomukResourceWatcher->setResources(newResources);
- if (newResources.isEmpty()) {
- Q_ASSERT(m_nepomukUriItems.isEmpty());
- m_nepomukResourceWatcher->stop();
- }
+ m_balooFileMonitor->setFiles(newFileList);
}
}
#endif
@@ -708,14 +692,9 @@ void KFileItemModelRolesUpdater::resolveRecentlyChangedItems()
updateChangedItems();
}
-void KFileItemModelRolesUpdater::applyChangedNepomukRoles(const Nepomuk2::Resource& resource, const Nepomuk2::Types::Property& property)
+void KFileItemModelRolesUpdater::applyChangedBalooRoles(const QString& itemUrl)
{
-#ifdef HAVE_NEPOMUK
- if (!Nepomuk2::ResourceManager::instance()->initialized()) {
- return;
- }
-
- const KUrl itemUrl = m_nepomukUriItems.value(resource.uri());
+#ifdef HAVE_BALOO
const KFileItem item = m_model->fileItem(itemUrl);
if (item.isNull()) {
@@ -724,18 +703,34 @@ void KFileItemModelRolesUpdater::applyChangedNepomukRoles(const Nepomuk2::Resour
return;
}
- QHash<QByteArray, QVariant> data = rolesData(item);
+ Baloo::FileFetchJob* job = new Baloo::FileFetchJob(item.localPath());
+ connect(job, SIGNAL(finished(KJob*)), this, SLOT(applyChangedBalooRolesJobFinished(KJob*)));
+ job->setProperty("item", QVariant::fromValue(item));
+ job->start();
+#else
+#ifndef Q_CC_MSVC
+ Q_UNUSED(itemUrl);
+#endif
+#endif
+}
- const KNepomukRolesProvider& rolesProvider = KNepomukRolesProvider::instance();
- const QByteArray role = rolesProvider.roleForPropertyUri(property.uri());
- if (!role.isEmpty() && m_roles.contains(role)) {
- // Overwrite the changed role value with an empty QVariant, because the roles
+void KFileItemModelRolesUpdater::applyChangedBalooRolesJobFinished(KJob* kjob)
+{
+#ifdef HAVE_BALOO
+ const KFileItem item = kjob->property("item").value<KFileItem>();
+
+ const KBalooRolesProvider& rolesProvider = KBalooRolesProvider::instance();
+ QHash<QByteArray, QVariant> data;
+
+ foreach (const QByteArray& role, rolesProvider.roles()) {
+ // Overwrite all the role values with an empty QVariant, because the roles
// provider doesn't overwrite it when the property value list is empty.
// See bug 322348
data.insert(role, QVariant());
}
- QHashIterator<QByteArray, QVariant> it(rolesProvider.roleValues(resource, m_roles));
+ Baloo::FileFetchJob* job = static_cast<Baloo::FileFetchJob*>(kjob);
+ QHashIterator<QByteArray, QVariant> it(rolesProvider.roleValues(job->file(), m_roles));
while (it.hasNext()) {
it.next();
data.insert(it.key(), it.value());
@@ -747,10 +742,6 @@ void KFileItemModelRolesUpdater::applyChangedNepomukRoles(const Nepomuk2::Resour
m_model->setData(index, data);
connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
-#else
-#ifndef Q_CC_MSVC
- Q_UNUSED(resource);
-#endif
#endif
}
@@ -762,7 +753,6 @@ void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QStrin
if (getSizeRole || getIsExpandableRole) {
const int index = m_model->index(KUrl(path));
if (index >= 0) {
-
QHash<QByteArray, QVariant> data;
if (getSizeRole) {
@@ -1004,7 +994,7 @@ void KFileItemModelRolesUpdater::applySortRole(int index)
const QString path = item.localPath();
data.insert("size", m_directoryContentsCounter->countDirectoryContentsSynchronously(path));
} else {
- // Probably the sort role is a Nepomuk role - just determine all roles.
+ // Probably the sort role is a baloo role - just determine all roles.
data = rolesData(item);
}
@@ -1087,35 +1077,12 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte
data.insert("iconOverlays", item.overlays());
-#ifdef HAVE_NEPOMUK
- if (m_nepomukResourceWatcher) {
- const KNepomukRolesProvider& rolesProvider = KNepomukRolesProvider::instance();
- Nepomuk2::Resource resource(item.nepomukUri());
- QHashIterator<QByteArray, QVariant> it(rolesProvider.roleValues(resource, m_roles));
- while (it.hasNext()) {
- it.next();
- data.insert(it.key(), it.value());
- }
-
- QUrl uri = resource.uri();
- if (uri.isEmpty()) {
- // TODO: Is there another way to explicitly create a resource?
- // We need a resource to be able to track it for changes.
- resource.setRating(0);
- uri = resource.uri();
- }
- if (!uri.isEmpty() && !m_nepomukUriItems.contains(uri)) {
- m_nepomukResourceWatcher->addResource(resource);
-
- if (m_nepomukUriItems.isEmpty()) {
- m_nepomukResourceWatcher->start();
- }
-
- m_nepomukUriItems.insert(uri, item.url());
- }
+#ifdef HAVE_BALOO
+ if (m_balooFileMonitor) {
+ m_balooFileMonitor->addFile(item.localPath());
+ applyChangedBalooRoles(item.localPath());
}
#endif
-
return data;
}
diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h
index 19207575e..a9e979ae1 100644
--- a/src/kitemviews/kfileitemmodelrolesupdater.h
+++ b/src/kitemviews/kfileitemmodelrolesupdater.h
@@ -20,7 +20,7 @@
#ifndef KFILEITEMMODELROLESUPDATER_H
#define KFILEITEMMODELROLESUPDATER_H
-#include <config-nepomuk.h>
+#include <config-baloo.h>
#include <KFileItem>
#include <kitemviews/kitemmodelbase.h>
@@ -38,26 +38,10 @@ class KJob;
class QPixmap;
class QTimer;
-#ifdef HAVE_NEPOMUK
- namespace Nepomuk2
+#ifdef HAVE_BALOO
+ namespace Baloo
{
- class ResourceWatcher;
- class Resource;
- namespace Types
- {
- class Property;
- }
- }
-#else
- // Required for the slot applyChangedNepomukRoles() that
- // cannot be ifdefined due to moc.
- namespace Nepomuk2
- {
- class Resource;
- namespace Types
- {
- class Property;
- }
+ class FileMonitor;
}
#endif
@@ -216,7 +200,8 @@ private slots:
*/
void resolveRecentlyChangedItems();
- void applyChangedNepomukRoles(const Nepomuk2::Resource& resource, const Nepomuk2::Types::Property& property);
+ void applyChangedBalooRoles(const QString& file);
+ void applyChangedBalooRolesJobFinished(KJob* job);
void slotDirectoryContentsCountReceived(const QString& path, int count);
@@ -346,9 +331,8 @@ private:
KDirectoryContentsCounter* m_directoryContentsCounter;
-#ifdef HAVE_NEPOMUK
- Nepomuk2::ResourceWatcher* m_nepomukResourceWatcher;
- mutable QHash<QUrl, KUrl> m_nepomukUriItems;
+#ifdef HAVE_BALOO
+ Baloo::FileMonitor* m_balooFileMonitor;
#endif
};
diff --git a/src/kitemviews/private/kbaloorolesprovider.cpp b/src/kitemviews/private/kbaloorolesprovider.cpp
new file mode 100644
index 000000000..c0ae0c544
--- /dev/null
+++ b/src/kitemviews/private/kbaloorolesprovider.cpp
@@ -0,0 +1,184 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Peter Penz <[email protected]> *
+ * Copyright (C) 2013 by Vishesh Handa <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "kbaloorolesprovider.h"
+
+#include <KDebug>
+#include <KGlobal>
+#include <KLocale>
+
+#include <baloo/file.h>
+#include <kfilemetadata/propertyinfo.h>
+
+#include <QTime>
+#include <QMap>
+
+struct KBalooRolesProviderSingleton
+{
+ KBalooRolesProvider instance;
+};
+K_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider)
+
+
+KBalooRolesProvider& KBalooRolesProvider::instance()
+{
+ return s_balooRolesProvider->instance;
+}
+
+KBalooRolesProvider::~KBalooRolesProvider()
+{
+}
+
+QSet<QByteArray> KBalooRolesProvider::roles() const
+{
+ return m_roles;
+}
+
+QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& file,
+ const QSet<QByteArray>& roles) const
+{
+ QHash<QByteArray, QVariant> values;
+
+ int width = -1;
+ int height = -1;
+
+ QMapIterator<KFileMetaData::Property::Property, QVariant> it(file.properties());
+ while (it.hasNext()) {
+ it.next();
+
+ const KFileMetaData::PropertyInfo pi(it.key());
+ const QString property = pi.name();
+ const QByteArray role = roleForProperty(property);
+ if (role.isEmpty() || !roles.contains(role)) {
+ continue;
+ }
+
+ const QVariant value = it.value();
+
+ if (role == "imageSize") {
+ // Merge the two properties for width and height
+ // as one string into the "imageSize" role
+ if (property == QLatin1String("width")) {
+ width = value.toInt();
+ }
+ else if (property == QLatin1String("height")) {
+ height = value.toInt();
+ }
+
+ if (width >= 0 && height >= 0) {
+ QString widthAndHeight = QString::number(width);
+ widthAndHeight += QLatin1String(" x ");
+ widthAndHeight += QString::number(height);
+ values.insert(role, widthAndHeight);
+ }
+ } else if (role == "orientation") {
+ const QString orientation = orientationFromValue(value.toInt());
+ values.insert(role, orientation);
+ } else if (role == "duration") {
+ const QString duration = durationFromValue(value.toInt());
+ values.insert(role, duration);
+ } else {
+ values.insert(role, value.toString());
+ }
+ }
+
+ if (roles.contains("tags")) {
+ values.insert("tags", tagsFromValues(file.tags()));
+ }
+ if (roles.contains("rating")) {
+ values.insert("rating", QString::number(file.rating()));
+ }
+ if (roles.contains("comment")) {
+ values.insert("comment", file.userComment());
+ }
+
+ return values;
+}
+
+QByteArray KBalooRolesProvider::roleForProperty(const QString& property) const
+{
+ return m_roleForProperty.value(property);
+}
+
+KBalooRolesProvider::KBalooRolesProvider() :
+ m_roles(),
+ m_roleForProperty()
+{
+ struct PropertyInfo
+ {
+ const char* const property;
+ const char* const role;
+ };
+
+ // Mapping from the URIs to the KFileItemModel roles. Note that this must not be
+ // a 1:1 mapping: One role may contain several URI-values (e.g. the URIs for height and
+ // width of an image are mapped to the role "imageSize")
+ static const PropertyInfo propertyInfoList[] = {
+ { "rating", "rating" },
+ { "tag", "tags" },
+ { "comment", "comment" },
+ { "wordCount", "wordCount" },
+ { "lineCount", "lineCount" },
+ { "width", "imageSize" },
+ { "height", "imageSize" },
+ { "nexif.orientation", "orientation", },
+ { "artist", "artist" },
+ { "album", "album" },
+ { "duration", "duration" },
+ { "trackNumber", "track" }
+ // { "http://www.semanticdesktop.org/ontologies/2010/04/30/ndo#copiedFrom", "copiedFrom" }
+ };
+
+ for (unsigned int i = 0; i < sizeof(propertyInfoList) / sizeof(PropertyInfo); ++i) {
+ m_roleForProperty.insert(propertyInfoList[i].property, propertyInfoList[i].role);
+ m_roles.insert(propertyInfoList[i].role);
+ }
+}
+
+QString KBalooRolesProvider::tagsFromValues(const QStringList& values) const
+{
+ return values.join(", ");
+}
+
+QString KBalooRolesProvider::orientationFromValue(int value) const
+{
+ QString string;
+ switch (value) {
+ case 1: string = i18nc("@item:intable Image orientation", "Unchanged"); break;
+ case 2: string = i18nc("@item:intable Image orientation", "Horizontally flipped"); break;
+ case 3: string = i18nc("@item:intable image orientation", "180° rotated"); break;
+ case 4: string = i18nc("@item:intable image orientation", "Vertically flipped"); break;
+ case 5: string = i18nc("@item:intable image orientation", "Transposed"); break;
+ case 6: string = i18nc("@item:intable image orientation", "90° rotated"); break;
+ case 7: string = i18nc("@item:intable image orientation", "Transversed"); break;
+ case 8: string = i18nc("@item:intable image orientation", "270° rotated"); break;
+ default:
+ break;
+ }
+ return string;
+}
+
+QString KBalooRolesProvider::durationFromValue(int value) const
+{
+ QTime duration;
+ duration = duration.addSecs(value);
+ return duration.toString("hh:mm:ss");
+}
+
diff --git a/src/kitemviews/private/knepomukrolesprovider.h b/src/kitemviews/private/kbaloorolesprovider.h
index 68a4027e1..f1ad5c740 100644
--- a/src/kitemviews/private/knepomukrolesprovider.h
+++ b/src/kitemviews/private/kbaloorolesprovider.h
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (C) 2012 by Peter Penz <[email protected]> *
+ * Copyright (C) 2013 by Vishesh Handa <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -17,8 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef KNEPOMUKROLESPROVIDER_H
-#define KNEPOMUKROLESPROVIDER_H
+#ifndef KBALOO_ROLESPROVIDER_H
+#define KBALOO_ROLESPROVIDER_H
#include <libdolphin_export.h>
@@ -26,25 +27,24 @@
#include <QSet>
#include <QUrl>
-namespace Nepomuk2
-{
- class Resource;
+namespace Baloo {
+ class File;
}
/**
* @brief Allows accessing metadata of a file by providing KFileItemModel roles.
*
* Is a helper class for KFileItemModelRolesUpdater to retrieve roles that
- * are only accessible with Nepomuk.
+ * are only accessible with Baloo.
*/
-class LIBDOLPHINPRIVATE_EXPORT KNepomukRolesProvider
+class LIBDOLPHINPRIVATE_EXPORT KBalooRolesProvider
{
public:
- static KNepomukRolesProvider& instance();
- virtual ~KNepomukRolesProvider();
+ static KBalooRolesProvider& instance();
+ virtual ~KBalooRolesProvider();
/**
- * @return Roles that can be provided by KNepomukRolesProvider.
+ * @return Roles that can be provided by KBalooRolesProvider.
*/
QSet<QByteArray> roles() const;
@@ -52,13 +52,13 @@ public:
* @return Values for the roles \a roles that can be determined from the file
* with the URL \a url.
*/
- QHash<QByteArray, QVariant> roleValues(const Nepomuk2::Resource& resource,
+ QHash<QByteArray, QVariant> roleValues(const Baloo::File& file,
const QSet<QByteArray>& roles) const;
- QByteArray roleForPropertyUri(const QUrl& uri) const;
+ QByteArray roleForProperty(const QString& property) const;
protected:
- KNepomukRolesProvider();
+ KBalooRolesProvider();
private:
/**
@@ -81,9 +81,9 @@ private:
private:
QSet<QByteArray> m_roles;
- QHash<QUrl, QByteArray> m_roleForUri;
+ QHash<QString, QByteArray> m_roleForProperty;
- friend class KNepomukRolesProviderSingleton;
+ friend class KBalooRolesProviderSingleton;
};
#endif
diff --git a/src/kitemviews/private/knepomukrolesprovider.cpp b/src/kitemviews/private/knepomukrolesprovider.cpp
deleted file mode 100644
index e237f948f..000000000
--- a/src/kitemviews/private/knepomukrolesprovider.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2012 by Peter Penz <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#include "knepomukrolesprovider.h"
-
-#include <KDebug>
-#include <KGlobal>
-#include <KLocale>
-
-#include <Nepomuk2/Resource>
-#include <Nepomuk2/Tag>
-#include <Nepomuk2/Types/Property>
-#include <Nepomuk2/Variant>
-
-#include <QTime>
-
-struct KNepomukRolesProviderSingleton
-{
- KNepomukRolesProvider instance;
-};
-K_GLOBAL_STATIC(KNepomukRolesProviderSingleton, s_nepomukRolesProvider)
-
-
-KNepomukRolesProvider& KNepomukRolesProvider::instance()
-{
- return s_nepomukRolesProvider->instance;
-}
-
-KNepomukRolesProvider::~KNepomukRolesProvider()
-{
-}
-
-QSet<QByteArray> KNepomukRolesProvider::roles() const
-{
- return m_roles;
-}
-
-QHash<QByteArray, QVariant> KNepomukRolesProvider::roleValues(const Nepomuk2::Resource& resource,
- const QSet<QByteArray>& roles) const
-{
- if (!resource.isValid()) {
- return QHash<QByteArray, QVariant>();
- }
-
- QHash<QByteArray, QVariant> values;
-
- int width = -1;
- int height = -1;
-
- QHashIterator<QUrl, Nepomuk2::Variant> it(resource.properties());
- while (it.hasNext()) {
- it.next();
-
- const Nepomuk2::Types::Property property = it.key();
- const QByteArray role = roleForPropertyUri(property.uri());
- if (role.isEmpty() || !roles.contains(role)) {
- continue;
- }
-
- const Nepomuk2::Variant value = it.value();
-
- if (role == "imageSize") {
- // Merge the two Nepomuk properties for width and height
- // as one string into the "imageSize" role
- const QString uri = property.uri().toString();
- if (uri.endsWith(QLatin1String("#width"))) {
- width = value.toInt();
- } else if (uri.endsWith(QLatin1String("#height"))) {
- height = value.toInt();
- }
-
- if (width >= 0 && height >= 0) {
- const QString widthAndHeight = QString::number(width) +
- QLatin1String(" x ") +
- QString::number(height);
- values.insert(role, widthAndHeight);
- }
- } else if (role == "tags") {
- const QString tags = tagsFromValues(value.toStringList());
- values.insert(role, tags);
- } else if (role == "orientation") {
- const QString orientation = orientationFromValue(value.toInt());
- values.insert(role, orientation);
- } else if (role == "duration") {
- const QString duration = durationFromValue(value.toInt());
- values.insert(role, duration);
- } else if (value.isResource()) {
- const Nepomuk2::Resource resource = value.toResource();
- values.insert(role, resource.genericLabel());
- } else if (value.isResourceList()) {
- const QList<Nepomuk2::Resource> resList = value.toResourceList();
- QStringList strList;
- foreach (const Nepomuk2::Resource& res, resList) {
- strList << res.genericLabel();
- }
- values.insert(role, strList.join(QLatin1String(", ")));
- } else {
- values.insert(role, value.toString());
- }
- }
-
- return values;
-}
-
-QByteArray KNepomukRolesProvider::roleForPropertyUri(const QUrl& uri) const
-{
- return m_roleForUri.value(uri);
-}
-
-KNepomukRolesProvider::KNepomukRolesProvider() :
- m_roles(),
- m_roleForUri()
-{
- struct UriInfo
- {
- const char* const uri;
- const char* const role;
- };
-
- // Mapping from the URIs to the KFileItemModel roles. Note that this must not be
- // a 1:1 mapping: One role may contain several URI-values (e.g. the URIs for height and
- // width of an image are mapped to the role "imageSize")
- static const UriInfo uriInfoList[] = {
- { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#numericRating", "rating" },
- { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#hasTag", "tags" },
- { "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#description", "comment" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#wordCount", "wordCount" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#lineCount", "lineCount" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width", "imageSize" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height", "imageSize" },
- { "http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#orientation", "orientation", },
- { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#performer", "artist" },
- { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#musicAlbum", "album" },
- { "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#duration", "duration" },
- { "http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#trackNumber", "track" },
- { "http://www.semanticdesktop.org/ontologies/2010/04/30/ndo#copiedFrom", "copiedFrom" }
- };
-
- for (unsigned int i = 0; i < sizeof(uriInfoList) / sizeof(UriInfo); ++i) {
- m_roleForUri.insert(QUrl(uriInfoList[i].uri), uriInfoList[i].role);
- m_roles.insert(uriInfoList[i].role);
- }
-}
-
-QString KNepomukRolesProvider::tagsFromValues(const QStringList& values) const
-{
- QString tags;
-
- for (int i = 0; i < values.count(); ++i) {
- if (i > 0) {
- tags.append(QLatin1String(", "));
- }
-
- const Nepomuk2::Tag tag(values[i]);
- tags += tag.genericLabel();
- }
-
- return tags;
-}
-
-QString KNepomukRolesProvider::orientationFromValue(int value) const
-{
- QString string;
- switch (value) {
- case 1: string = i18nc("@item:intable Image orientation", "Unchanged"); break;
- case 2: string = i18nc("@item:intable Image orientation", "Horizontally flipped"); break;
- case 3: string = i18nc("@item:intable image orientation", "180° rotated"); break;
- case 4: string = i18nc("@item:intable image orientation", "Vertically flipped"); break;
- case 5: string = i18nc("@item:intable image orientation", "Transposed"); break;
- case 6: string = i18nc("@item:intable image orientation", "90° rotated"); break;
- case 7: string = i18nc("@item:intable image orientation", "Transversed"); break;
- case 8: string = i18nc("@item:intable image orientation", "270° rotated"); break;
- default:
- break;
- }
- return string;
-}
-
-QString KNepomukRolesProvider::durationFromValue(int value) const
-{
- QTime duration;
- duration = duration.addSecs(value);
- return duration.toString("hh:mm:ss");
-}
-