add more spacing
[personal-kdebase.git] / apps / dolphin / src / panels / information / nepomukmassupdatejob.cpp
blob5c883fd4b32153c5891a4a18ca5bc494560d2a9b
1 /***************************************************************************
2 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program 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 *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "nepomukmassupdatejob.h"
22 #include <klocale.h>
23 #include <kdebug.h>
25 #include <nepomuk/tag.h>
26 #include <nepomuk/tools.h>
29 Nepomuk::MassUpdateJob::MassUpdateJob( QObject* parent )
30 : KJob( parent ),
31 m_index( -1 )
33 kDebug();
34 setCapabilities( Killable|Suspendable );
35 connect( &m_processTimer, SIGNAL( timeout() ),
36 this, SLOT( slotNext() ) );
40 Nepomuk::MassUpdateJob::~MassUpdateJob()
42 kDebug();
46 void Nepomuk::MassUpdateJob::setFiles( const KUrl::List& urls )
48 m_resources.clear();
49 foreach( const KUrl &url, urls ) {
50 m_resources.append( Resource( url ) );
52 setTotalAmount( KJob::Files, m_resources.count() );
56 void Nepomuk::MassUpdateJob::setResources( const QList<Nepomuk::Resource>& rl )
58 m_resources = rl;
59 setTotalAmount( KJob::Files, m_resources.count() );
63 void Nepomuk::MassUpdateJob::setProperties( const QList<QPair<QUrl,Nepomuk::Variant> >& props )
65 m_properties = props;
69 void Nepomuk::MassUpdateJob::start()
71 if ( m_index < 0 ) {
72 kDebug();
73 emit description( this,
74 i18nc("@info:progress", "Changing annotations") );
75 m_index = 0;
76 m_processTimer.start();
78 else {
79 kDebug() << "Job has already been started";
84 bool Nepomuk::MassUpdateJob::doKill()
86 if ( m_index > 0 ) {
87 m_processTimer.stop();
88 m_index = -1;
89 return true;
91 else {
92 return false;
97 bool Nepomuk::MassUpdateJob::doSuspend()
99 m_processTimer.stop();
100 return true;
104 bool Nepomuk::MassUpdateJob::doResume()
106 if ( m_index > 0 ) {
107 m_processTimer.start();
108 return true;
110 else {
111 return false;
116 void Nepomuk::MassUpdateJob::slotNext()
118 if ( !isSuspended() ) {
119 if ( m_index < m_resources.count() ) {
120 Nepomuk::Resource& res = m_resources[m_index];
121 for ( int i = 0; i < m_properties.count(); ++i ) {
122 res.setProperty( m_properties[i].first, m_properties[i].second );
124 ++m_index;
125 setProcessedAmount( KJob::Files, m_index );
127 else if ( m_index >= m_resources.count() ) {
128 kDebug() << "done";
129 m_index = -1;
130 m_processTimer.stop();
131 emitResult();
137 Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::tagResources( const QList<Nepomuk::Resource>& rl, const QList<Nepomuk::Tag>& tags )
139 Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob();
140 job->setResources( rl );
141 job->setProperties( QList<QPair<QUrl,Nepomuk::Variant> >() << qMakePair( QUrl( Nepomuk::Resource::tagUri() ), Nepomuk::Variant( convertResourceList<Tag>( tags ) ) ) );
142 return job;
146 Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::rateResources( const QList<Nepomuk::Resource>& rl, int rating )
148 Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob();
149 job->setResources( rl );
150 job->setProperties( QList<QPair<QUrl,Nepomuk::Variant> >() << qMakePair( QUrl( Nepomuk::Resource::ratingUri() ), Nepomuk::Variant( rating ) ) );
151 return job;
155 Nepomuk::MassUpdateJob* Nepomuk::MassUpdateJob::commentResources( const QList<Nepomuk::Resource>& rl, const QString& comment )
157 Nepomuk::MassUpdateJob* job = new Nepomuk::MassUpdateJob();
158 job->setResources( rl );
159 job->setProperties( QList<QPair<QUrl,Nepomuk::Variant> >() << qMakePair( QUrl( Nepomuk::Resource::descriptionUri() ), Nepomuk::Variant( comment ) ) );
160 return job;
163 #include "nepomukmassupdatejob.moc"