]>
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 foreach (const KUrl
& url
, m_urls
) {
71 Nepomuk::Resource
file(url
);
72 m_files
.insert(url
, file
);
74 if (!first
&& (m_rating
!= file
.rating())) {
75 m_rating
= 0; // reset rating
77 m_rating
= file
.rating();
80 if (!first
&& (m_comment
!= file
.description())) {
81 m_comment
.clear(); // reset comment
83 m_comment
= file
.description();
86 if (!first
&& (m_tags
!= file
.tags())) {
87 m_tags
.clear(); // reset tags
92 if (first
&& (m_urls
.count() == 1)) {
93 // TODO: show shared meta information instead
94 // of not showing anything on multiple selections
95 QHash
<QUrl
, Nepomuk::Variant
> variants
= file
.properties();
96 QHash
<QUrl
, Nepomuk::Variant
>::const_iterator it
= variants
.constBegin();
97 while (it
!= variants
.constEnd()) {
98 Nepomuk::Types::Property
prop(it
.key());
99 if (settings
.readEntry(prop
.name(), true)) {
101 item
.name
= prop
.name();
102 item
.label
= tunedLabel(prop
.label());
103 item
.value
= formatValue(it
.value());
104 m_items
.append(item
);
114 int KLoadMetaDataThread::rating() const
119 QString
KLoadMetaDataThread::comment() const
124 QList
<Nepomuk::Tag
> KLoadMetaDataThread::tags() const
129 QList
<KLoadMetaDataThread::Item
> KLoadMetaDataThread::items() const
134 QMap
<KUrl
, Nepomuk::Resource
> KLoadMetaDataThread::files() const
139 void KLoadMetaDataThread::slotFinished()
144 QString
KLoadMetaDataThread::tunedLabel(const QString
& label
) const
147 const int labelLength
= label
.length();
148 if (labelLength
> 0) {
149 tunedLabel
.reserve(labelLength
);
150 tunedLabel
= label
[0].toUpper();
151 for (int i
= 1; i
< labelLength
; ++i
) {
152 if (label
[i
].isUpper() && !label
[i
- 1].isSpace() && !label
[i
- 1].isUpper()) {
154 tunedLabel
+= label
[i
].toLower();
156 tunedLabel
+= label
[i
];
160 return tunedLabel
+ ':';
163 QString
KLoadMetaDataThread::formatValue(const Nepomuk::Variant
& value
)
165 if (value
.isDateTime()) {
166 return KGlobal::locale()->formatDateTime(value
.toDateTime(), KLocale::FancyLongDate
);
167 } else if (value
.isResource()) {
168 return value
.toResource().genericLabel();
169 } else if (value
.isResourceList()) {
171 foreach(const Nepomuk::Resource
& res
, value
.toResourceList()) {
172 list
<< res
.genericLabel();
174 return list
.join(QLatin1String(";\n"));
176 return value
.toString();
180 #include "kloadmetadatathread_p.moc"