]>
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/resource.h>
29 KLoadMetaDataThread::KLoadMetaDataThread() :
40 KLoadMetaDataThread::~KLoadMetaDataThread()
44 void KLoadMetaDataThread::load(const KUrl::List
& urls
)
51 void KLoadMetaDataThread::cancelAndDelete()
53 connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
55 // Setting m_canceled to true will cancel KLoadMetaDataThread::run()
56 // as soon as possible. Afterwards the thread will delete itself
57 // asynchronously inside slotFinished().
60 void KLoadMetaDataThread::run()
62 KConfig
config("kmetainformationrc", KConfig::NoGlobals
);
63 KConfigGroup settings
= config
.group("Show");
66 unsigned int rating
= 0;
67 foreach (const KUrl
& url
, m_urls
) {
72 Nepomuk::Resource
file(url
);
73 m_files
.insert(url
, file
);
75 if (!first
&& (rating
!= file
.rating())) {
76 rating
= 0; // reset rating
78 rating
= file
.rating();
81 if (!first
&& (m_comment
!= file
.description())) {
82 m_comment
.clear(); // reset comment
84 m_comment
= file
.description();
87 if (!first
&& (m_tags
!= file
.tags())) {
88 m_tags
.clear(); // reset tags
93 if (first
&& (m_urls
.count() == 1)) {
94 // TODO: show shared meta information instead
95 // of not showing anything on multiple selections
96 QHash
<QUrl
, Nepomuk::Variant
> variants
= file
.properties();
97 QHash
<QUrl
, Nepomuk::Variant
>::const_iterator it
= variants
.constBegin();
98 while (it
!= variants
.constEnd()) {
99 Nepomuk::Types::Property
prop(it
.key());
100 if (settings
.readEntry(prop
.name(), true)) {
102 item
.name
= prop
.name();
103 item
.label
= tunedLabel(prop
.label());
104 item
.value
= formatValue(it
.value());
105 m_items
.append(item
);
115 int KLoadMetaDataThread::rating() const
120 QString
KLoadMetaDataThread::comment() const
125 QList
<Nepomuk::Tag
> KLoadMetaDataThread::tags() const
130 QList
<KLoadMetaDataThread::Item
> KLoadMetaDataThread::items() const
135 QMap
<KUrl
, Nepomuk::Resource
> KLoadMetaDataThread::files() const
140 void KLoadMetaDataThread::slotFinished()
145 QString
KLoadMetaDataThread::tunedLabel(const QString
& label
) const
148 const int labelLength
= label
.length();
149 if (labelLength
> 0) {
150 tunedLabel
.reserve(labelLength
);
151 tunedLabel
= label
[0].toUpper();
152 for (int i
= 1; i
< labelLength
; ++i
) {
153 if (label
[i
].isUpper() && !label
[i
- 1].isSpace() && !label
[i
- 1].isUpper()) {
155 tunedLabel
+= label
[i
].toLower();
157 tunedLabel
+= label
[i
];
161 return tunedLabel
+ ':';
164 QString
KLoadMetaDataThread::formatValue(const Nepomuk::Variant
& value
)
166 if (value
.isDateTime()) {
167 return KGlobal::locale()->formatDateTime(value
.toDateTime(), KLocale::FancyLongDate
);
168 } else if (value
.isResource()) {
169 return value
.toResource().genericLabel();
170 } else if (value
.isResourceList()) {
172 foreach(const Nepomuk::Resource
& res
, value
.toResourceList()) {
173 list
<< res
.genericLabel();
175 return list
.join(QLatin1String(";\n"));
177 return value
.toString();
181 #include "kloadmetadatathread_p.moc"