]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/kloadmetadatathread.cpp
1 /*****************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2009 by Sebastian Trueg <trueg@kde.org> *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License version 2 as published by the Free Software Foundation. *
9 * This library 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; see the file COPYING.LIB. If not, write to *
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301, USA. *
18 *****************************************************************************/
20 #include "kloadmetadatathread_p.h"
23 #include <kconfiggroup.h>
27 #include <nepomuk/variant.h>
28 #include <nepomuk/resource.h>
30 KLoadMetaDataThread::KLoadMetaDataThread() :
42 KLoadMetaDataThread::~KLoadMetaDataThread()
46 void KLoadMetaDataThread::load(const KUrl::List
& urls
)
53 void KLoadMetaDataThread::cancelAndDelete()
55 connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
57 // Setting m_canceled to true will cancel KLoadMetaDataThread::run()
58 // as soon as possible. Afterwards the thread will delete itself
59 // asynchronously inside slotFinished().
62 void KLoadMetaDataThread::run()
64 KConfig
config("kmetainformationrc", KConfig::NoGlobals
);
65 KConfigGroup settings
= config
.group("Show");
68 unsigned int rating
= 0;
69 foreach (const KUrl
& url
, m_urls
) {
74 Nepomuk::Resource
file(url
);
75 m_files
.insert(url
, file
);
77 if (!first
&& (rating
!= file
.rating())) {
78 rating
= 0; // reset rating
80 rating
= file
.rating();
83 if (!first
&& (m_comment
!= file
.description())) {
84 m_comment
.clear(); // reset comment
86 m_comment
= file
.description();
89 if (!first
&& (m_tags
!= file
.tags())) {
90 m_tags
.clear(); // reset tags
95 if (first
&& (m_urls
.count() == 1)) {
96 // TODO: show shared meta information instead
97 // of not showing anything on multiple selections
98 QHash
<QUrl
, Nepomuk::Variant
> properties
= file
.properties();
99 QHash
<QUrl
, Nepomuk::Variant
>::const_iterator it
= properties
.constBegin();
100 while (it
!= properties
.constEnd()) {
101 Nepomuk::Types::Property
prop(it
.key());
102 if (settings
.readEntry(prop
.name(), true)) {
103 // TODO #1: use Nepomuk::formatValue(res, prop) if available
104 // instead of it.value().toString()
105 // TODO #2: using tunedLabel() is a workaround for KDE 4.3 (4.4?) until
106 // we get translated labels
107 m_metaInfoLabels
.append(tunedLabel(prop
.label()));
108 m_metaInfoValues
.append(formatValue(it
.value()));
118 int KLoadMetaDataThread::rating() const
123 QString
KLoadMetaDataThread::comment() const
128 QList
<Nepomuk::Tag
> KLoadMetaDataThread::tags() const
133 QList
<QString
> KLoadMetaDataThread::metaInfoLabels() const
135 return m_metaInfoLabels
;
138 QList
<QString
> KLoadMetaDataThread::metaInfoValues() const
140 return m_metaInfoValues
;
143 QMap
<KUrl
, Nepomuk::Resource
> KLoadMetaDataThread::files() const
148 void KLoadMetaDataThread::slotFinished()
153 QString
KLoadMetaDataThread::tunedLabel(const QString
& label
) const
156 const int labelLength
= label
.length();
157 if (labelLength
> 0) {
158 tunedLabel
.reserve(labelLength
);
159 tunedLabel
= label
[0].toUpper();
160 for (int i
= 1; i
< labelLength
; ++i
) {
161 if (label
[i
].isUpper() && !label
[i
- 1].isSpace() && !label
[i
- 1].isUpper()) {
163 tunedLabel
+= label
[i
].toLower();
165 tunedLabel
+= label
[i
];
169 return tunedLabel
+ ':';
173 // This is a short hack until we have a proper formatting facility in Nepomuk
174 // here we simply handle the most common formatting situations that do not look nice
175 // when using Nepomuk::Variant::toString()
176 QString
KLoadMetaDataThread::formatValue(const Nepomuk::Variant
& value
)
178 if (value
.isDateTime()) {
179 return KGlobal::locale()->formatDateTime( value
.toDateTime(), KLocale::FancyLongDate
);
181 else if (value
.isResource()) {
182 return value
.toResource().genericLabel();
184 else if (value
.isResourceList()) {
186 foreach(const Nepomuk::Resource
& res
, value
.toResourceList()) {
187 ll
<< res
.genericLabel();
189 return ll
.join(QLatin1String(";\n"));
192 return value
.toString();
196 #include "kloadmetadatathread_p.moc"