]>
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 <kprotocolinfo.h>
29 #include <nepomuk/resource.h>
31 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 foreach (const KUrl
& url
, m_urls
) {
73 Nepomuk::Resource
file(url
);
74 m_files
.insert(url
, file
);
76 if (!first
&& (m_rating
!= file
.rating())) {
77 m_rating
= 0; // reset rating
79 m_rating
= file
.rating();
82 if (!first
&& (m_comment
!= file
.description())) {
83 m_comment
.clear(); // reset comment
85 m_comment
= file
.description();
88 if (!first
&& (m_tags
!= file
.tags())) {
89 m_tags
.clear(); // reset tags
94 if (first
&& (m_urls
.count() == 1)) {
95 // TODO: show shared meta information instead
96 // of not showing anything on multiple selections
97 QHash
<QUrl
, Nepomuk::Variant
> variants
= file
.properties();
98 QHash
<QUrl
, Nepomuk::Variant
>::const_iterator it
= variants
.constBegin();
99 while (it
!= variants
.constEnd()) {
100 Nepomuk::Types::Property
prop(it
.key());
101 if (settings
.readEntry(prop
.name(), true)) {
103 item
.name
= prop
.name();
104 item
.label
= tunedLabel(prop
.label());
105 item
.value
= formatValue(it
.value());
106 m_items
.append(item
);
116 int KLoadMetaDataThread::rating() const
121 QString
KLoadMetaDataThread::comment() const
126 QList
<Nepomuk::Tag
> KLoadMetaDataThread::tags() const
131 QList
<KLoadMetaDataThread::Item
> KLoadMetaDataThread::items() const
136 QMap
<KUrl
, Nepomuk::Resource
> KLoadMetaDataThread::files() const
141 void KLoadMetaDataThread::slotFinished()
146 QString
KLoadMetaDataThread::tunedLabel(const QString
& label
) const
149 const int labelLength
= label
.length();
150 if (labelLength
> 0) {
151 tunedLabel
.reserve(labelLength
);
152 tunedLabel
= label
[0].toUpper();
153 for (int i
= 1; i
< labelLength
; ++i
) {
154 if (label
[i
].isUpper() && !label
[i
- 1].isSpace() && !label
[i
- 1].isUpper()) {
156 tunedLabel
+= label
[i
].toLower();
158 tunedLabel
+= label
[i
];
162 return tunedLabel
+ ':';
165 QString
KLoadMetaDataThread::formatValue(const Nepomuk::Variant
& value
)
167 if (value
.isDateTime()) {
168 return KGlobal::locale()->formatDateTime(value
.toDateTime(), KLocale::FancyLongDate
);
171 if (value
.isResource() || value
.isResourceList()) {
173 foreach(const Nepomuk::Resource
& res
, value
.toResourceList()) {
174 if (KProtocolInfo::isKnownProtocol(res
.resourceUri())) {
175 links
<< QString::fromLatin1("<a href=\"%1\">%2</a>")
176 .arg(KUrl(res
.resourceUri()).url())
177 .arg(res
.genericLabel());
179 links
<< res
.genericLabel();
182 return links
.join(QLatin1String(";\n"));
185 return value
.toString();
188 #include "kloadmetadatathread_p.moc"