]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/kloadmetadatathread.cpp
1 /*****************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Library General Public *
6 * License version 2 as published by the Free Software Foundation. *
8 * This library is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
11 * Library General Public License for more details. *
13 * You should have received a copy of the GNU Library General Public License *
14 * along with this library; see the file COPYING.LIB. If not, write to *
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
16 * Boston, MA 02110-1301, USA. *
17 *****************************************************************************/
19 #include "kloadmetadatathread_p.h"
22 #include <kconfiggroup.h>
24 #include <nepomuk/variant.h>
26 KLoadMetaDataThread::KLoadMetaDataThread() :
38 KLoadMetaDataThread::~KLoadMetaDataThread()
42 void KLoadMetaDataThread::load(const KUrl::List
& urls
)
49 void KLoadMetaDataThread::cancelAndDelete()
51 connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
53 // Setting m_canceled to true will cancel KLoadMetaDataThread::run()
54 // as soon as possible. Afterwards the thread will delete itself
55 // asynchronously inside slotFinished().
58 void KLoadMetaDataThread::run()
60 KConfig
config("kmetainformationrc", KConfig::NoGlobals
);
61 KConfigGroup settings
= config
.group("Show");
64 unsigned int rating
= 0;
65 foreach (const KUrl
& url
, m_urls
) {
70 Nepomuk::Resource
file(url
);
71 m_files
.insert(url
, file
);
73 if (!first
&& (rating
!= file
.rating())) {
74 rating
= 0; // reset rating
76 rating
= file
.rating();
79 if (!first
&& (m_comment
!= file
.description())) {
80 m_comment
.clear(); // reset comment
82 m_comment
= file
.description();
85 if (!first
&& (m_tags
!= file
.tags())) {
86 m_tags
.clear(); // reset tags
91 if (first
&& (m_urls
.count() == 1)) {
92 // TODO: show shared meta information instead
93 // of not showing anything on multiple selections
94 QHash
<QUrl
, Nepomuk::Variant
> properties
= file
.properties();
95 QHash
<QUrl
, Nepomuk::Variant
>::const_iterator it
= properties
.constBegin();
96 while (it
!= properties
.constEnd()) {
97 Nepomuk::Types::Property
prop(it
.key());
98 if (settings
.readEntry(prop
.name(), true)) {
99 // TODO #1: use Nepomuk::formatValue(res, prop) if available
100 // instead of it.value().toString()
101 // TODO #2: using tunedLabel() is a workaround for KDE 4.3 (4.4?) until
102 // we get translated labels
103 m_metaInfoLabels
.append(tunedLabel(prop
.label()));
104 m_metaInfoValues
.append(it
.value().toString());
114 int KLoadMetaDataThread::rating() const
119 QString
KLoadMetaDataThread::comment() const
124 QList
<Nepomuk::Tag
> KLoadMetaDataThread::tags() const
129 QList
<QString
> KLoadMetaDataThread::metaInfoLabels() const
131 return m_metaInfoLabels
;
134 QList
<QString
> KLoadMetaDataThread::metaInfoValues() const
136 return m_metaInfoValues
;
139 QMap
<KUrl
, Nepomuk::Resource
> KLoadMetaDataThread::files() const
144 void KLoadMetaDataThread::slotFinished()
149 QString
KLoadMetaDataThread::tunedLabel(const QString
& label
) const
152 const int labelLength
= label
.length();
153 if (labelLength
> 0) {
154 tunedLabel
.reserve(labelLength
);
155 tunedLabel
= label
[0].toUpper();
156 for (int i
= 1; i
< labelLength
; ++i
) {
157 if (label
[i
].isUpper() && !label
[i
- 1].isSpace() && !label
[i
- 1].isUpper()) {
159 tunedLabel
+= label
[i
].toLower();
161 tunedLabel
+= label
[i
];
165 return tunedLabel
+ ':';
168 #include "kloadmetadatathread_p.moc"