1 /***************************************************************************
2 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
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. *
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. *
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"
25 #include <nepomuk/tag.h>
26 #include <nepomuk/tools.h>
29 Nepomuk::MassUpdateJob::MassUpdateJob( QObject
* parent
)
34 setCapabilities( Killable
|Suspendable
);
35 connect( &m_processTimer
, SIGNAL( timeout() ),
36 this, SLOT( slotNext() ) );
40 Nepomuk::MassUpdateJob::~MassUpdateJob()
46 void Nepomuk::MassUpdateJob::setFiles( const KUrl::List
& urls
)
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
)
59 setTotalAmount( KJob::Files
, m_resources
.count() );
63 void Nepomuk::MassUpdateJob::setProperties( const QList
<QPair
<QUrl
,Nepomuk::Variant
> >& props
)
69 void Nepomuk::MassUpdateJob::start()
73 emit
description( this,
74 i18nc("@info:progress", "Changing annotations") );
76 m_processTimer
.start();
79 kDebug() << "Job has already been started";
84 bool Nepomuk::MassUpdateJob::doKill()
87 m_processTimer
.stop();
97 bool Nepomuk::MassUpdateJob::doSuspend()
99 m_processTimer
.stop();
104 bool Nepomuk::MassUpdateJob::doResume()
107 m_processTimer
.start();
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
);
125 setProcessedAmount( KJob::Files
, m_index
);
127 else if ( m_index
>= m_resources
.count() ) {
130 m_processTimer
.stop();
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
) ) ) );
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
) ) );
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
) ) );
163 #include "nepomukmassupdatejob.moc"