From: Peter Penz Date: Sat, 13 Mar 2010 15:32:48 +0000 (+0000) Subject: Allow to specify a group for a meta data item. X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/6b9c4f7b45e07e93afadd50b4a0350ef901e8683?ds=sidebyside Allow to specify a group for a meta data item. The sorting of the meta data items is now done by the group. Within the group the sorting is done by their translated labels. svn path=/trunk/KDE/kdebase/apps/; revision=1102778 --- diff --git a/src/panels/information/kloadmetadatathread.cpp b/src/panels/information/kloadmetadatathread.cpp index ba4ebeda5..374cded70 100644 --- a/src/panels/information/kloadmetadatathread.cpp +++ b/src/panels/information/kloadmetadatathread.cpp @@ -51,7 +51,7 @@ void KLoadMetaDataThread::load(const KUrl::List& urls) start(); } -QMap KLoadMetaDataThread::data() const +QHash KLoadMetaDataThread::data() const { return m_data; } diff --git a/src/panels/information/kloadmetadatathread_p.h b/src/panels/information/kloadmetadatathread_p.h index be03d262f..d61d6012b 100644 --- a/src/panels/information/kloadmetadatathread_p.h +++ b/src/panels/information/kloadmetadatathread_p.h @@ -56,7 +56,7 @@ public: * valid results after the signal finished() has been * emitted. */ - QMap data() const; + QHash data() const; /** * Tells the thread that it should cancel as soon @@ -90,7 +90,7 @@ private: private: KMetaDataModel* m_model; - QMap m_data; + QHash m_data; KUrl::List m_urls; bool m_canceled; }; diff --git a/src/panels/information/kmetadatamodel.cpp b/src/panels/information/kmetadatamodel.cpp index 452156893..6a1898b1f 100644 --- a/src/panels/information/kmetadatamodel.cpp +++ b/src/panels/information/kmetadatamodel.cpp @@ -33,7 +33,7 @@ public: QList m_fileItems; #ifdef HAVE_NEPOMUK - QMap m_data; + QHash m_data; QList m_metaDataThreads; KLoadMetaDataThread* m_latestMetaDataThread; @@ -122,20 +122,34 @@ void KMetaDataModel::setItems(const KFileItemList& items) #endif } +QString KMetaDataModel::group(const KUrl& metaDataUri) const +{ + QString group; // return value + + const QString uri = metaDataUri.url(); + if (uri == QLatin1String("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width")) { + group = QLatin1String("0sizeA"); + } else if (uri == QLatin1String("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height")) { + group = QLatin1String("0sizeB"); + } + + return group; +} + KFileItemList KMetaDataModel::items() const { return d->m_fileItems; } #ifdef HAVE_NEPOMUK -QMap KMetaDataModel::data() const +QHash KMetaDataModel::data() const { return d->m_data; } -QMap KMetaDataModel::loadData() const +QHash KMetaDataModel::loadData() const { - return QMap(); + return QHash(); } #endif diff --git a/src/panels/information/kmetadatamodel.h b/src/panels/information/kmetadatamodel.h index 4b12563d3..ad8099dad 100644 --- a/src/panels/information/kmetadatamodel.h +++ b/src/panels/information/kmetadatamodel.h @@ -21,11 +21,10 @@ #include +#include #include -#include #include - #include #ifdef HAVE_NEPOMUK #define DISABLE_NEPOMUK_LEGACY @@ -64,6 +63,15 @@ public: void setItems(const KFileItemList& items); KFileItemList items() const; + /** + * @return Returns the name of the group the meta data indicated + * by \p metaDataUri belongs to. All meta data items are + * sorted by the group. Items within the group are sorted + * by their translated labels. The group name is not shown + * to the user interface and does not need to get translated. + */ + virtual QString group(const KUrl& metaDataUri) const; + #ifdef HAVE_NEPOMUK /** * @return Meta data for the items that have been set by @@ -71,7 +79,7 @@ public: * be invoked after the signal loadingFinished() has * been received (otherwise no data will be returned). */ - QMap data() const; + QHash data() const; protected: /** @@ -83,7 +91,7 @@ protected: * blocked if the operation takes longer. The default implementation * returns an empty list. */ - virtual QMap loadData() const; + virtual QHash loadData() const; #endif signals: diff --git a/src/panels/information/kmetadatawidget.cpp b/src/panels/information/kmetadatawidget.cpp index 996238509..d44637432 100644 --- a/src/panels/information/kmetadatawidget.cpp +++ b/src/panels/information/kmetadatawidget.cpp @@ -47,7 +47,6 @@ #include #include #include - #include #include "nepomukmassupdatejob_p.h" #include @@ -108,6 +107,7 @@ public: */ void startChangeDataJob(KJob* job); + QList sortedKeys(const QHash& data) const; QList resourceList() const; #endif @@ -369,27 +369,26 @@ void KMetaDataWidget::Private::slotLoadingFinished() // Show the remaining meta information as text. The number // of required rows may very. Existing rows are reused to // prevent flickering. - const KNfoTranslator& nfo = KNfoTranslator::instance(); int rowIndex = m_fixedRowCount; - QMap data = m_model->data(); - QMap::const_iterator it = data.constBegin(); - while (it != data.constEnd()) { - const KUrl key = it.key(); - const Nepomuk::Variant value = it.value(); - const QString itemLabel = nfo.translation(it.key()); + const QHash data = m_model->data(); + const QList keys = sortedKeys(data); + + foreach (const KUrl& key, keys) { + const Nepomuk::Variant value = data[key]; + const QString itemLabel = nfo.translation(key); bool appliedData = false; if (m_nepomukActivated) { - const QString key = it.key().url(); - if (key == QLatin1String("kfileitem#rating")) { + const QString keyString = key.url(); + if (keyString == QLatin1String("kfileitem#rating")) { m_ratingWidget->setRating(value.toInt()); appliedData = true; - } else if (key == QLatin1String("kfileitem#comment")) { + } else if (keyString == QLatin1String("kfileitem#comment")) { m_commentWidget->setText(value.toString()); appliedData = true; - } else if (key == QLatin1String("kfileitem#tags")) { + } else if (keyString == QLatin1String("kfileitem#tags")) { QList variants = value.toVariantList(); QList tags; foreach (const Nepomuk::Variant& variant, variants) { @@ -423,8 +422,6 @@ void KMetaDataWidget::Private::slotLoadingFinished() } ++rowIndex; } - - ++it; } // remove rows that are not needed anymore @@ -503,6 +500,38 @@ void KMetaDataWidget::Private::startChangeDataJob(KJob* job) job->start(); } +QList KMetaDataWidget::Private::sortedKeys(const QHash& data) const +{ + const KNfoTranslator& nfo = KNfoTranslator::instance(); + + // Create a map, where the translated label prefixed with the + // sort priority acts as key. The data of each entry is the URI + // of the data. By this the all URIs are sorted by the sort priority + // and sub sorted by the translated labels. + QMap map; + QHash::const_iterator hashIt = data.constBegin(); + while (hashIt != data.constEnd()) { + const KUrl uri = hashIt.key(); + + QString key = q->model()->group(uri); + key += nfo.translation(uri); + + map.insert(key, uri); + ++hashIt; + } + + // Apply the URIs from the map to the list that will get returned. + // The list will then be alphabetically ordered by the translated labels of the URIs. + QList list; + QMap::const_iterator mapIt = map.constBegin(); + while (mapIt != map.constEnd()) { + list.append(mapIt.value()); + ++mapIt; + } + + return list; +} + QList KMetaDataWidget::Private::resourceList() const { QList list; diff --git a/src/panels/information/kmetadatawidget.h b/src/panels/information/kmetadatawidget.h index 858f1998a..6f5c66041 100644 --- a/src/panels/information/kmetadatawidget.h +++ b/src/panels/information/kmetadatawidget.h @@ -25,8 +25,6 @@ #include #include -#include - class KMetaDataModel; class KUrl;