diff options
| author | Peter Penz <[email protected]> | 2010-03-13 13:38:40 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2010-03-13 13:38:40 +0000 |
| commit | 54a1499586d5395f0f4589ce6deb6431d02eb866 (patch) | |
| tree | ccbab754f09c2d2a98c1519267d0776e7e60b8a0 /src/panels/information/kmetadatamodel.cpp | |
| parent | a7f4541eb8c4d33e30ee733cc39b3d40b237e903 (diff) | |
Provide a KMetaDataModel for KMetaDataWidget.
This allows to extend the model with custom meta data (might e. g. be useful for Gwenview).
svn path=/trunk/KDE/kdebase/apps/; revision=1102749
Diffstat (limited to 'src/panels/information/kmetadatamodel.cpp')
| -rw-r--r-- | src/panels/information/kmetadatamodel.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/panels/information/kmetadatamodel.cpp b/src/panels/information/kmetadatamodel.cpp new file mode 100644 index 000000000..452156893 --- /dev/null +++ b/src/panels/information/kmetadatamodel.cpp @@ -0,0 +1,142 @@ +/***************************************************************************** + * Copyright (C) 2010 by Peter Penz <[email protected]> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License version 2 as published by the Free Software Foundation. * + * * + * This library 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 * + * Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public License * + * along with this library; see the file COPYING.LIB. If not, write to * + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301, USA. * + *****************************************************************************/ + +#include "kmetadatamodel.h" + +#include <kfileitem.h> +#include "kloadmetadatathread_p.h" +#include <kurl.h> + +class KMetaDataModel::Private +{ + +public: + Private(KMetaDataModel* parent); + ~Private(); + + void slotLoadingFinished(); + + QList<KFileItem> m_fileItems; +#ifdef HAVE_NEPOMUK + QMap<KUrl, Nepomuk::Variant> m_data; + + QList<KLoadMetaDataThread*> m_metaDataThreads; + KLoadMetaDataThread* m_latestMetaDataThread; +#endif + +private: + KMetaDataModel* const q; +}; + +KMetaDataModel::Private::Private(KMetaDataModel* parent) : + m_fileItems(), +#ifdef HAVE_NEPOMUK + m_data(), + m_metaDataThreads(), + m_latestMetaDataThread(0), +#endif + q(parent) +{ +} + +KMetaDataModel::Private::~Private() +{ +} + +KMetaDataModel::KMetaDataModel(QObject* parent) : + QObject(parent), + d(new Private(this)) +{ +} + +KMetaDataModel::~KMetaDataModel() +{ + delete d; +} + +void KMetaDataModel::Private::slotLoadingFinished() +{ +#ifdef HAVE_NEPOMUK + // The thread that has emitted the finished() signal + // will get deleted and removed from m_metaDataThreads. + const int threadsCount = m_metaDataThreads.count(); + for (int i = 0; i < threadsCount; ++i) { + KLoadMetaDataThread* thread = m_metaDataThreads[i]; + if (thread == q->sender()) { + m_metaDataThreads.removeAt(i); + if (thread != m_latestMetaDataThread) { + // Ignore data of older threads, as the data got + // obsolete by m_latestMetaDataThread. + thread->deleteLater(); + return; + } + } + } + + m_data = m_latestMetaDataThread->data(); + m_latestMetaDataThread->deleteLater(); +#endif + + emit q->loadingFinished(); +} + +void KMetaDataModel::setItems(const KFileItemList& items) +{ + d->m_fileItems = items; + +#ifdef HAVE_NEPOMUK + QList<KUrl> urls; + foreach (const KFileItem& item, items) { + const KUrl url = item.nepomukUri(); + if (url.isValid()) { + urls.append(url); + } + } + + // Cancel all threads that have not emitted a finished() signal. + // The deleting of those threads is done in slotLoadingFinished(). + foreach (KLoadMetaDataThread* thread, d->m_metaDataThreads) { + thread->cancel(); + } + + // create a new thread that will provide the meeta data for the items + d->m_latestMetaDataThread = new KLoadMetaDataThread(this); + connect(d->m_latestMetaDataThread, SIGNAL(finished()), this, SLOT(slotLoadingFinished())); + d->m_latestMetaDataThread->load(urls); + d->m_metaDataThreads.append(d->m_latestMetaDataThread); +#endif +} + +KFileItemList KMetaDataModel::items() const +{ + return d->m_fileItems; +} + +#ifdef HAVE_NEPOMUK +QMap<KUrl, Nepomuk::Variant> KMetaDataModel::data() const +{ + return d->m_data; +} + +QMap<KUrl, Nepomuk::Variant> KMetaDataModel::loadData() const +{ + return QMap<KUrl, Nepomuk::Variant>(); +} +#endif + +#include "kmetadatamodel.moc" |
