]>
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>
24 #include <kfilemetainfo.h>
25 #include <kfilemetainfoitem.h>
28 #include <kprotocolinfo.h>
30 #include <nepomuk/resource.h>
32 KLoadMetaDataThread::KLoadMetaDataThread() :
43 KLoadMetaDataThread::~KLoadMetaDataThread()
47 void KLoadMetaDataThread::load(const KUrl::List
& urls
)
54 void KLoadMetaDataThread::cancelAndDelete()
56 connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
58 // Setting m_canceled to true will cancel KLoadMetaDataThread::run()
59 // as soon as possible. Afterwards the thread will delete itself
60 // asynchronously inside slotFinished().
63 void KLoadMetaDataThread::run()
65 KConfig
config("kmetainformationrc", KConfig::NoGlobals
);
66 KConfigGroup settings
= config
.group("Show");
69 foreach (const KUrl
& url
, m_urls
) {
74 Nepomuk::Resource
file(url
);
75 if (!file
.isValid()) {
79 m_files
.insert(url
, file
);
81 if (!first
&& (m_rating
!= file
.rating())) {
82 m_rating
= 0; // reset rating
84 m_rating
= file
.rating();
87 if (!first
&& (m_comment
!= file
.description())) {
88 m_comment
.clear(); // reset comment
90 m_comment
= file
.description();
93 if (!first
&& (m_tags
!= file
.tags())) {
94 m_tags
.clear(); // reset tags
99 if (first
&& (m_urls
.count() == 1)) {
100 // TODO: show shared meta information instead
101 // of not showing anything on multiple selections
102 QHash
<QUrl
, Nepomuk::Variant
> variants
= file
.properties();
103 QHash
<QUrl
, Nepomuk::Variant
>::const_iterator it
= variants
.constBegin();
104 while (it
!= variants
.constEnd()) {
105 Nepomuk::Types::Property
prop(it
.key());
106 if (settings
.readEntry(prop
.name(), true)) {
108 item
.name
= prop
.name();
109 item
.label
= tunedLabel(prop
.label());
110 item
.value
= formatValue(it
.value());
111 m_items
.append(item
);
116 if (variants
.isEmpty()) {
117 // TODO: The following code is just meant as temporary fallback to show
118 // non-indexed meta data.
119 KFileMetaInfo
metaInfo(m_urls
.first());
120 const QHash
<QString
, KFileMetaInfoItem
> metaInfoItems
= metaInfo
.items();
121 foreach (const KFileMetaInfoItem
& metaInfoItem
, metaInfoItems
) {
123 item
.name
= metaInfoItem
.name();
124 item
.label
= metaInfoItem
.name() + metaInfoItem
.prefix() + metaInfoItem
.suffix();
125 item
.value
= metaInfoItem
.value().toString();
126 m_items
.append(item
);
135 int KLoadMetaDataThread::rating() const
140 QString
KLoadMetaDataThread::comment() const
145 QList
<Nepomuk::Tag
> KLoadMetaDataThread::tags() const
150 QList
<KLoadMetaDataThread::Item
> KLoadMetaDataThread::items() const
155 QMap
<KUrl
, Nepomuk::Resource
> KLoadMetaDataThread::files() const
160 void KLoadMetaDataThread::slotFinished()
165 QString
KLoadMetaDataThread::tunedLabel(const QString
& label
) const
168 const int labelLength
= label
.length();
169 if (labelLength
> 0) {
170 tunedLabel
.reserve(labelLength
);
171 tunedLabel
= label
[0].toUpper();
172 for (int i
= 1; i
< labelLength
; ++i
) {
173 if (label
[i
].isUpper() && !label
[i
- 1].isSpace() && !label
[i
- 1].isUpper()) {
175 tunedLabel
+= label
[i
].toLower();
177 tunedLabel
+= label
[i
];
181 return tunedLabel
+ ':';
184 QString
KLoadMetaDataThread::formatValue(const Nepomuk::Variant
& value
)
186 if (value
.isDateTime()) {
187 return KGlobal::locale()->formatDateTime(value
.toDateTime(), KLocale::FancyLongDate
);
190 if (value
.isResource() || value
.isResourceList()) {
192 foreach(const Nepomuk::Resource
& res
, value
.toResourceList()) {
193 if (KProtocolInfo::isKnownProtocol(res
.resourceUri())) {
194 links
<< QString::fromLatin1("<a href=\"%1\">%2</a>")
195 .arg(KUrl(res
.resourceUri()).url())
196 .arg(res
.genericLabel());
198 links
<< res
.genericLabel();
201 return links
.join(QLatin1String(";\n"));
204 return value
.toString();
207 #include "kloadmetadatathread_p.moc"