]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/kmetadatamodel.cpp
1 /*****************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 *****************************************************************************/
19 #include "kmetadatamodel.h"
21 #include <kfileitem.h>
22 #include "kloadmetadatathread_p.h"
25 class KMetaDataModel::Private
29 Private(KMetaDataModel
* parent
);
32 void slotLoadingFinished();
34 QList
<KFileItem
> m_fileItems
;
36 QHash
<KUrl
, Nepomuk::Variant
> m_data
;
38 QList
<KLoadMetaDataThread
*> m_metaDataThreads
;
39 KLoadMetaDataThread
* m_latestMetaDataThread
;
43 KMetaDataModel
* const q
;
46 KMetaDataModel::Private::Private(KMetaDataModel
* parent
) :
51 m_latestMetaDataThread(0),
57 KMetaDataModel::Private::~Private()
61 KMetaDataModel::KMetaDataModel(QObject
* parent
) :
67 KMetaDataModel::~KMetaDataModel()
72 void KMetaDataModel::Private::slotLoadingFinished()
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();
91 m_data
= m_latestMetaDataThread
->data();
92 m_latestMetaDataThread
->deleteLater();
95 emit q
->loadingFinished();
98 void KMetaDataModel::setItems(const KFileItemList
& items
)
100 d
->m_fileItems
= items
;
104 foreach (const KFileItem
& item
, items
) {
105 const KUrl url
= item
.nepomukUri();
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
) {
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
);
125 QString
KMetaDataModel::group(const KUrl
& metaDataUri
) const
127 QString group
; // return value
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");
139 KFileItemList
KMetaDataModel::items() const
141 return d
->m_fileItems
;
145 QHash
<KUrl
, Nepomuk::Variant
> KMetaDataModel::data() const
150 QHash
<KUrl
, Nepomuk::Variant
> KMetaDataModel::loadData() const
152 return QHash
<KUrl
, Nepomuk::Variant
>();
156 #include "kmetadatamodel.moc"