diff options
| author | Peter Penz <[email protected]> | 2009-11-04 19:14:39 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2009-11-04 19:14:39 +0000 |
| commit | 565bd3bf23dfb9b139de089d3c4f8b57e124f7ee (patch) | |
| tree | f773c5af1ca34c76dee3e8b16569b66da04bca02 /src/panels/information/kloadmetadatathread.cpp | |
| parent | f5f2ccf8eec5abffb41255e487746881091ff8a1 (diff) | |
Don't call QThread::wait() in the destructor - in the worst case an issue in Nepomuk will block Dolphin for several seconds. Refactored the load-meta-data-thread in a way that the meta data widget does not require to wait for a result of the thread.
svn path=/trunk/KDE/kdebase/apps/; revision=1044848
Diffstat (limited to 'src/panels/information/kloadmetadatathread.cpp')
| -rw-r--r-- | src/panels/information/kloadmetadatathread.cpp | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/src/panels/information/kloadmetadatathread.cpp b/src/panels/information/kloadmetadatathread.cpp new file mode 100644 index 000000000..20575ac9b --- /dev/null +++ b/src/panels/information/kloadmetadatathread.cpp @@ -0,0 +1,168 @@ +/***************************************************************************** + * Copyright (C) 2009 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 "kloadmetadatathread_p.h" + +#include <kconfig.h> +#include <kconfiggroup.h> + +#include <nepomuk/variant.h> + +KLoadMetaDataThread::KLoadMetaDataThread() : + m_rating(0), + m_comment(), + m_tags(), + m_metaInfoLabels(), + m_metaInfoValues(), + m_files(), + m_urls(), + m_canceled(false) +{ +} + +KLoadMetaDataThread::~KLoadMetaDataThread() +{ +} + +void KLoadMetaDataThread::load(const KUrl::List& urls) +{ + m_urls = urls; + m_canceled = false; + start(); +} + +void KLoadMetaDataThread::cancelAndDelete() +{ + connect(this, SIGNAL(finished()), this, SLOT(slotFinished())); + m_canceled = true; + // Setting m_canceled to true will cancel KLoadMetaDataThread::run() + // as soon as possible. Afterwards the thread will delete itself + // asynchronously inside slotFinished(). +} + +void KLoadMetaDataThread::run() +{ + KConfig config("kmetainformationrc", KConfig::NoGlobals); + KConfigGroup settings = config.group("Show"); + + bool first = true; + unsigned int rating = 0; + foreach (const KUrl& url, m_urls) { + if (m_canceled) { + return; + } + + Nepomuk::Resource file(url); + m_files.insert(url, file); + + if (!first && (rating != file.rating())) { + rating = 0; // reset rating + } else if (first) { + rating = file.rating(); + } + + if (!first && (m_comment != file.description())) { + m_comment.clear(); // reset comment + } else if (first) { + m_comment = file.description(); + } + + if (!first && (m_tags != file.tags())) { + m_tags.clear(); // reset tags + } else if (first) { + m_tags = file.tags(); + } + + if (first && (m_urls.count() == 1)) { + // TODO: show shared meta information instead + // of not showing anything on multiple selections + QHash<QUrl, Nepomuk::Variant> properties = file.properties(); + QHash<QUrl, Nepomuk::Variant>::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + Nepomuk::Types::Property prop(it.key()); + if (settings.readEntry(prop.name(), true)) { + // TODO #1: use Nepomuk::formatValue(res, prop) if available + // instead of it.value().toString() + // TODO #2: using tunedLabel() is a workaround for KDE 4.3 (4.4?) until + // we get translated labels + m_metaInfoLabels.append(tunedLabel(prop.label())); + m_metaInfoValues.append(it.value().toString()); + } + ++it; + } + } + + first = false; + } +} + +int KLoadMetaDataThread::rating() const +{ + return m_rating; +} + +QString KLoadMetaDataThread::comment() const +{ + return m_comment; +} + +QList<Nepomuk::Tag> KLoadMetaDataThread::tags() const +{ + return m_tags; +} + +QList<QString> KLoadMetaDataThread::metaInfoLabels() const +{ + return m_metaInfoLabels; +} + +QList<QString> KLoadMetaDataThread::metaInfoValues() const +{ + return m_metaInfoValues; +} + +QMap<KUrl, Nepomuk::Resource> KLoadMetaDataThread::files() const +{ + return m_files; +} + +void KLoadMetaDataThread::slotFinished() +{ + deleteLater(); +} + +QString KLoadMetaDataThread::tunedLabel(const QString& label) const +{ + QString tunedLabel; + const int labelLength = label.length(); + if (labelLength > 0) { + tunedLabel.reserve(labelLength); + tunedLabel = label[0].toUpper(); + for (int i = 1; i < labelLength; ++i) { + if (label[i].isUpper() && !label[i - 1].isSpace() && !label[i - 1].isUpper()) { + tunedLabel += ' '; + tunedLabel += label[i].toLower(); + } else { + tunedLabel += label[i]; + } + } + } + return tunedLabel + ':'; +} + +#include "kloadmetadatathread_p.moc" |
