30 #include "tdemessagebox.h"
31 #include "kmfolderimap.h"
32 #include "kmfoldercachedimap.h"
33 #include "kmacctimap.h"
34 #include "kmacctcachedimap.h"
35 #include "folderstorage.h"
37 #include "progressmanager.h"
38 using KPIM::ProgressManager;
42 #include <tdeio/scheduler.h>
43 #include <tdeio/job.h>
44 #include <tdeio/global.h>
45 #include <tdelocale.h>
47 #include <tqstylesheet.h>
51 using namespace KMail;
55 KPIM::ProgressItem* item )
56 : FolderJob( 0, tOther, (storage ? storage->folder() : 0) ),
57 mStorage( storage ), mAccount( account ), mType( type ),
58 mComplete( complete ),
59 mHonorLocalSubscription( false ), mPath( path ),
60 mParentProgressItem( item )
68 void ListJob::execute()
70 if ( mAccount->makeConnection() == ImapAccountBase::Error )
72 kdWarning(5006) <<
"ListJob - got no connection" << endl;
75 }
else if ( mAccount->makeConnection() == ImapAccountBase::Connecting )
78 kdDebug(5006) <<
"ListJob - waiting for connection" << endl;
79 connect( mAccount, TQ_SIGNAL( connectionResult(
int,
const TQString&) ),
84 if ( mPath.isEmpty() )
86 if ( mStorage && mStorage->
folderType() == KMFolderTypeImap ) {
87 mPath =
static_cast<KMFolderImap*
>(mStorage)->imapPath();
88 }
else if ( mStorage && mStorage->
folderType() == KMFolderTypeCachedImap ) {
89 mPath =
static_cast<KMFolderCachedImap*
>(mStorage)->imapPath();
91 kdError(5006) <<
"ListJob - no valid path and no folder given" << endl;
96 if ( mNamespace.isEmpty() && mStorage )
98 mNamespace = mAccount->namespaceForFolder( mStorage );
102 jd.total = 1; jd.done = 0;
103 jd.cancellable =
true;
104 jd.parent = mDestFolder;
105 jd.onlySubscribed = ( mType == ImapAccountBase::ListSubscribed ||
106 mType == ImapAccountBase::ListSubscribedNoCheck ||
107 mType == ImapAccountBase::ListFolderOnlySubscribed );
109 jd.curNamespace = mNamespace;
110 if ( mParentProgressItem )
112 TQString escapedStatus = mDestFolder ? TQStyleSheet::escape( mDestFolder->prettyURL() )
114 jd.progressItem = ProgressManager::createProgressItem(
116 "ListDir" + ProgressManager::getUniqueID(),
118 i18n(
"retrieving folders"),
120 mAccount->useSSL() || mAccount->useTLS() );
121 mParentProgressItem->setStatus( escapedStatus );
125 TQString ltype =
"LIST";
126 if ( mType == ImapAccountBase::ListSubscribed ||
127 mType == ImapAccountBase::ListFolderOnlySubscribed )
129 else if ( mType == ImapAccountBase::ListSubscribedNoCheck )
130 ltype =
"LSUBNOCHECK";
134 section =
";SECTION=COMPLETE";
135 else if ( mType == ImapAccountBase::ListFolderOnly ||
136 mType == ImapAccountBase::ListFolderOnlySubscribed )
137 section =
";SECTION=FOLDERONLY";
139 KURL url = mAccount->getUrl();
145 TDEIO::SimpleJob *job = TDEIO::listDir( url,
false );
146 TDEIO::Scheduler::assignJobToSlave( mAccount->slave(), job );
147 mAccount->insertJob( job, jd );
148 connect( job, TQ_SIGNAL(result(TDEIO::Job *)),
150 connect( job, TQ_SIGNAL(entries(TDEIO::Job *,
const TDEIO::UDSEntryList &)),
151 this, TQ_SLOT(
slotListEntries(TDEIO::Job *,
const TDEIO::UDSEntryList &)) );
156 Q_UNUSED( errorMsg );
160 if ( mParentProgressItem )
161 mParentProgressItem->setComplete();
168 ImapAccountBase::JobIterator it = mAccount->findJob( job );
169 if ( it == mAccount->jobsEnd() )
176 mAccount->handleJobError( job,
177 i18n(
"Error while listing folder %1: " ).arg((*it).path),
183 mSubfolderMimeTypes, mSubfolderAttributes, *it );
184 mAccount->removeJob( it );
191 ImapAccountBase::JobIterator it = mAccount->findJob( job );
192 if ( it == mAccount->jobsEnd() )
197 if( (*it).progressItem )
198 (*it).progressItem->setProgress( 50 );
203 for ( TDEIO::UDSEntryList::ConstIterator udsIt = uds.begin();
204 udsIt != uds.end(); udsIt++ )
206 mimeType = TQString();
207 attributes = TQString();
208 for ( TDEIO::UDSEntry::ConstIterator eIt = (*udsIt).begin();
209 eIt != (*udsIt).end(); eIt++ )
212 if ( (*eIt).m_uds == TDEIO::UDS_NAME )
214 else if ( (*eIt).m_uds == TDEIO::UDS_URL )
215 url = KURL((*eIt).m_str, 106);
216 else if ( (*eIt).m_uds == TDEIO::UDS_MIME_TYPE )
217 mimeType = (*eIt).m_str;
218 else if ( (*eIt).m_uds == TDEIO::UDS_EXTRA )
219 attributes = (*eIt).m_str;
221 if ( (mimeType ==
"inode/directory" || mimeType ==
"message/digest"
222 || mimeType ==
"message/directory")
223 && name !=
".." && (mAccount->hiddenFolders() || name.at(0) !=
'.') )
225 if ( mHonorLocalSubscription && mAccount->onlyLocallySubscribedFolders()
226 && !mAccount->locallySubscribedTo( url.path() ) ) {
232 if ( mSubfolderPaths.count() > 100 ||
233 mSubfolderPaths.findIndex(url.path()) == -1 )
235 mSubfolderNames.append( name );
236 mSubfolderPaths.append( url.path() );
237 mSubfolderMimeTypes.append( mimeType );
238 mSubfolderAttributes.append( attributes );
247 mHonorLocalSubscription = value;
252 return mHonorLocalSubscription;
255 #include "listjob.moc"