]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/kmetadatamodel.cpp
Remove connection to non-existent slot.
[dolphin.git] / src / panels / information / kmetadatamodel.cpp
1 /*****************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
3 * *
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. *
7 * *
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. *
12 * *
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 *****************************************************************************/
18
19 #include "kmetadatamodel.h"
20
21 #include <kfileitem.h>
22 #include "kloadmetadatathread_p.h"
23 #include <kurl.h>
24
25 class KMetaDataModel::Private
26 {
27
28 public:
29 Private(KMetaDataModel* parent);
30 ~Private();
31
32 void slotLoadingFinished();
33
34 QList<KFileItem> m_fileItems;
35 #ifdef HAVE_NEPOMUK
36 QHash<KUrl, Nepomuk::Variant> m_data;
37
38 QList<KLoadMetaDataThread*> m_metaDataThreads;
39 KLoadMetaDataThread* m_latestMetaDataThread;
40 #endif
41
42 private:
43 KMetaDataModel* const q;
44 };
45
46 KMetaDataModel::Private::Private(KMetaDataModel* parent) :
47 m_fileItems(),
48 #ifdef HAVE_NEPOMUK
49 m_data(),
50 m_metaDataThreads(),
51 m_latestMetaDataThread(0),
52 #endif
53 q(parent)
54 {
55 }
56
57 KMetaDataModel::Private::~Private()
58 {
59 }
60
61 KMetaDataModel::KMetaDataModel(QObject* parent) :
62 QObject(parent),
63 d(new Private(this))
64 {
65 }
66
67 KMetaDataModel::~KMetaDataModel()
68 {
69 delete d;
70 }
71
72 void KMetaDataModel::Private::slotLoadingFinished()
73 {
74 #ifdef HAVE_NEPOMUK
75 // The thread that has emitted the finished() signal
76 // will get deleted and removed from m_metaDataThreads.
77 const int threadsCount = m_metaDataThreads.count();
78 for (int i = 0; i < threadsCount; ++i) {
79 KLoadMetaDataThread* thread = m_metaDataThreads[i];
80 if (thread == q->sender()) {
81 m_metaDataThreads.removeAt(i);
82 if (thread != m_latestMetaDataThread) {
83 // Ignore data of older threads, as the data got
84 // obsolete by m_latestMetaDataThread.
85 thread->deleteLater();
86 return;
87 }
88 }
89 }
90
91 m_data = m_latestMetaDataThread->data();
92 m_latestMetaDataThread->deleteLater();
93 #endif
94
95 emit q->loadingFinished();
96 }
97
98 void KMetaDataModel::setItems(const KFileItemList& items)
99 {
100 d->m_fileItems = items;
101
102 #ifdef HAVE_NEPOMUK
103 QList<KUrl> urls;
104 foreach (const KFileItem& item, items) {
105 const KUrl url = item.nepomukUri();
106 if (url.isValid()) {
107 urls.append(url);
108 }
109 }
110
111 // Cancel all threads that have not emitted a finished() signal.
112 // The deleting of those threads is done in slotLoadingFinished().
113 foreach (KLoadMetaDataThread* thread, d->m_metaDataThreads) {
114 thread->cancel();
115 }
116
117 // create a new thread that will provide the meeta data for the items
118 d->m_latestMetaDataThread = new KLoadMetaDataThread(this);
119 connect(d->m_latestMetaDataThread, SIGNAL(finished()), this, SLOT(slotLoadingFinished()));
120 d->m_latestMetaDataThread->load(urls);
121 d->m_metaDataThreads.append(d->m_latestMetaDataThread);
122 #endif
123 }
124
125 QString KMetaDataModel::group(const KUrl& metaDataUri) const
126 {
127 QString group; // return value
128
129 const QString uri = metaDataUri.url();
130 if (uri == QLatin1String("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width")) {
131 group = QLatin1String("0sizeA");
132 } else if (uri == QLatin1String("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height")) {
133 group = QLatin1String("0sizeB");
134 }
135
136 return group;
137 }
138
139 KFileItemList KMetaDataModel::items() const
140 {
141 return d->m_fileItems;
142 }
143
144 #ifdef HAVE_NEPOMUK
145 QHash<KUrl, Nepomuk::Variant> KMetaDataModel::data() const
146 {
147 return d->m_data;
148 }
149
150 QHash<KUrl, Nepomuk::Variant> KMetaDataModel::loadData() const
151 {
152 return QHash<KUrl, Nepomuk::Variant>();
153 }
154 #endif
155
156 #include "kmetadatamodel.moc"