31 #include "annotationjobs.h"
32 #include <tdeio/scheduler.h>
35 using namespace KMail;
38 TDEIO::Slave* slave,
const KURL& url,
const TQString& entry,
39 const TQMap<TQString,TQString>& attributes )
41 TQByteArray packedArgs;
42 TQDataStream stream( packedArgs, IO_WriteOnly );
43 stream << (int)
'M' << (
int)
'S' << url << entry << attributes;
45 TDEIO::SimpleJob* job = TDEIO::special( url, packedArgs,
false );
46 TDEIO::Scheduler::assignJobToSlave( slave, job );
51 TDEIO::Slave* slave,
const KURL& url,
const TQString& entry,
52 const TQStringList& attributes )
54 TQByteArray packedArgs;
55 TQDataStream stream( packedArgs, IO_WriteOnly );
56 stream << (int)
'M' << (
int)
'G' << url << entry << attributes;
59 TDEIO::Scheduler::assignJobToSlave( slave, job );
63 AnnotationJobs::GetAnnotationJob::GetAnnotationJob(
const KURL& url,
const TQString& entry,
64 const TQByteArray &packedArgs,
65 bool showProgressInfo )
66 : TDEIO::SimpleJob( url, TDEIO::CMD_SPECIAL, packedArgs, showProgressInfo ),
69 connect(
this, TQ_SIGNAL(infoMessage(TDEIO::Job*,
const TQString&)),
70 TQ_SLOT(slotInfoMessage(TDEIO::Job*,
const TQString&)) );
73 void AnnotationJobs::GetAnnotationJob::slotInfoMessage( TDEIO::Job*,
const TQString& str )
76 TQStringList lst = TQStringList::split(
"\r", str );
77 while ( lst.count() >= 2 )
79 TQString name = lst.front(); lst.pop_front();
80 TQString value = lst.front(); lst.pop_front();
85 AnnotationJobs::MultiGetAnnotationJob::MultiGetAnnotationJob(
86 TDEIO::Slave* slave,
const KURL& url,
const TQStringList& entries,
bool showProgressInfo )
87 : TDEIO::Job( showProgressInfo ),
89 mUrl( url ), mEntryList( entries ), mEntryListIterator( mEntryList.begin() )
91 TQTimer::singleShot(0,
this, TQ_SLOT(slotStart()));
95 void AnnotationJobs::MultiGetAnnotationJob::slotStart()
97 if ( mEntryListIterator != mEntryList.end() ) {
98 TQStringList attributes;
99 attributes <<
"value";
100 TDEIO::Job* job =
getAnnotation( mSlave, mUrl, *mEntryListIterator, attributes );
107 void AnnotationJobs::MultiGetAnnotationJob::slotResult( TDEIO::Job *job )
109 if ( job->error() ) {
110 TDEIO::Job::slotResult( job );
113 subjobs.remove( job );
114 const TQString& entry = *mEntryListIterator;
117 GetAnnotationJob* getJob =
static_cast<GetAnnotationJob *
>( job );
118 const AnnotationList& lst = getJob->annotations();
119 for (
unsigned int i = 0 ; i < lst.size() ; ++ i ) {
121 if ( lst[i].name.startsWith(
"value." ) ) {
123 value = lst[i].value;
127 emit annotationResult( entry, value, found );
129 ++mEntryListIterator;
140 AnnotationJobs::MultiSetAnnotationJob::MultiSetAnnotationJob(
141 TDEIO::Slave* slave,
const KURL& url,
const AnnotationList& annotations,
bool showProgressInfo )
142 : TDEIO::Job( showProgressInfo ),
144 mUrl( url ), mAnnotationList( annotations ), mAnnotationListIterator( mAnnotationList.begin() )
146 TQTimer::singleShot(0,
this, TQ_SLOT(slotStart()));
150 void AnnotationJobs::MultiSetAnnotationJob::slotStart()
152 if ( mAnnotationListIterator != mAnnotationList.end() ) {
156 TQMap<TQString, TQString> attributes;
157 attributes.insert( attr.name, attr.value );
158 kdDebug() << k_funcinfo <<
" setting annotation " << attr.entry <<
" " << attr.name <<
" " << attr.value << endl;
159 TDEIO::Job* job =
setAnnotation( mSlave, mUrl, attr.entry, attributes );
166 void AnnotationJobs::MultiSetAnnotationJob::slotResult( TDEIO::Job *job )
168 if ( job->error() ) {
169 TDEIO::Job::slotResult( job );
172 subjobs.remove( job );
174 emit annotationChanged( attr.entry, attr.name, attr.value );
177 ++mAnnotationListIterator;
182 TDEIO::Slave* slave,
const KURL& url,
const AnnotationList& annotations )
188 AnnotationJobs::MultiUrlGetAnnotationJob::MultiUrlGetAnnotationJob( TDEIO::Slave* slave,
190 const TQStringList& paths,
191 const TQString& annotation )
192 : TDEIO::Job( false ),
196 mPathListIterator( mPathList.begin() ),
197 mAnnotation( annotation )
199 TQTimer::singleShot(0,
this, TQ_SLOT(slotStart()));
203 void AnnotationJobs::MultiUrlGetAnnotationJob::slotStart()
205 if ( mPathListIterator != mPathList.end() ) {
206 TQStringList attributes;
207 attributes <<
"value";
209 url.setPath( *mPathListIterator );
210 TDEIO::Job* job =
getAnnotation( mSlave, url, mAnnotation, attributes );
217 void AnnotationJobs::MultiUrlGetAnnotationJob::slotResult( TDEIO::Job *job )
219 if ( job->error() ) {
220 TDEIO::Job::slotResult( job );
223 subjobs.remove( job );
224 const TQString& path = *mPathListIterator;
225 GetAnnotationJob* getJob =
static_cast<GetAnnotationJob *
>( job );
226 const AnnotationList& lst = getJob->annotations();
227 for (
unsigned int i = 0 ; i < lst.size() ; ++ i ) {
228 kdDebug(5006) <<
"MultiURL: found annotation " << lst[i].name <<
" = " << lst[i].value <<
" for path: " << path << endl;
229 if ( lst[i].name.startsWith(
"value." ) ) {
230 mAnnotations.insert( path, lst[i].value );
239 TQMap<TQString, TQString> AnnotationJobs::MultiUrlGetAnnotationJob::annotations()
const
246 const TQStringList& paths,
247 const TQString& annotation )
253 #include "annotationjobs.moc"
for multiUrlGetAnnotation
TDEIO::SimpleJob * setAnnotation(TDEIO::Slave *slave, const KURL &url, const TQString &entry, const TQMap< TQString, TQString > &attributes)
Set an annotation entry (note that it can have multiple attributes)
MultiGetAnnotationJob * multiGetAnnotation(TDEIO::Slave *slave, const KURL &url, const TQStringList &entries)
Get multiple annotation entries Currently we assume we want to get the "value" for each,...
GetAnnotationJob * getAnnotation(TDEIO::Slave *slave, const KURL &url, const TQString &entry, const TQStringList &attributes)
Get an annotation entry.
MultiUrlGetAnnotationJob * multiUrlGetAnnotation(TDEIO::Slave *slave, const KURL &baseUrl, const TQStringList &paths, const TQString &annotation)
Get annotation entries for multiple folders.
MultiSetAnnotationJob * multiSetAnnotation(TDEIO::Slave *slave, const KURL &url, const AnnotationList &annotations)
Set multiple annotation entries.
One entry in the annotation list: attribute name and attribute value.