kmail
quotajobs.cppGo to the documentation of this file.00001
00031 #include "quotajobs.h"
00032 #include <kio/scheduler.h>
00033 #include <kdebug.h>
00034
00035 using namespace KMail;
00036
00037 QuotaJobs::GetQuotarootJob* QuotaJobs::getQuotaroot(
00038 KIO::Slave* slave, const KURL& url )
00039 {
00040 QByteArray packedArgs;
00041 QDataStream stream( packedArgs, IO_WriteOnly );
00042 stream << (int)'Q' << (int)'R' << url;
00043
00044 GetQuotarootJob* job = new GetQuotarootJob( url, packedArgs, false );
00045 KIO::Scheduler::assignJobToSlave( slave, job );
00046 return job;
00047 }
00048
00049 QuotaJobs::GetQuotarootJob::GetQuotarootJob( const KURL& url,
00050 const QByteArray &packedArgs,
00051 bool showProgressInfo )
00052 : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo )
00053 {
00054 connect( this, SIGNAL(infoMessage(KIO::Job*,const QString&)),
00055 SLOT(slotInfoMessage(KIO::Job*,const QString&)) );
00056 }
00057
00058 void QuotaJobs::GetQuotarootJob::slotInfoMessage( KIO::Job*, const QString& str )
00059 {
00060
00061 QStringList results = QStringList::split("\r", str);
00062 QStringList roots;
00063 QuotaInfoList quotas;
00064 if ( results.size() > 0 ) {
00065
00066 roots = QStringList::split(" ", results.front() );
00067 results.pop_front();
00068
00069 while ( results.size() > 0 ) {
00070 QString root = results.front(); results.pop_front();
00071
00072 if ( results.size() > 0 ) {
00073 QStringList triplets = QStringList::split(" ", results.front() );
00074 results.pop_front();
00075 while ( triplets.size() > 0 ) {
00076
00077 QString name = triplets.front(); triplets.pop_front();
00078 QString current = triplets.front(); triplets.pop_front();
00079 QString max = triplets.front(); triplets.pop_front();
00080 QuotaInfo info( name, root, current, max );
00081 quotas.append( info );
00082 }
00083 }
00084 }
00085 }
00086 if ( !quotas.isEmpty() ) {
00087 emit quotaInfoReceived( quotas );
00088 }
00089 emit quotaRootResult( roots );
00090 }
00091
00092 QuotaJobs::GetStorageQuotaJob* QuotaJobs::getStorageQuota(
00093 KIO::Slave* slave, const KURL& url )
00094 {
00095 GetStorageQuotaJob* job = new GetStorageQuotaJob( slave, url );
00096 return job;
00097 }
00098
00099
00100 QuotaJobs::GetStorageQuotaJob::GetStorageQuotaJob( KIO::Slave* slave, const KURL& url )
00101 : KIO::Job( false )
00102 {
00103 QByteArray packedArgs;
00104 QDataStream stream( packedArgs, IO_WriteOnly );
00105 stream << (int)'Q' << (int)'R' << url;
00106
00107 QuotaJobs::GetQuotarootJob *job =
00108 new QuotaJobs::GetQuotarootJob( url, packedArgs, false );
00109 connect(job, SIGNAL(quotaInfoReceived(const QuotaInfoList&)),
00110 SLOT(slotQuotaInfoReceived(const QuotaInfoList&)));
00111 connect(job, SIGNAL(quotaRootResult(const QStringList&)),
00112 SLOT(slotQuotarootResult(const QStringList&)));
00113 KIO::Scheduler::assignJobToSlave( slave, job );
00114 addSubjob( job );
00115 }
00116
00117 void QuotaJobs::GetStorageQuotaJob::slotQuotarootResult( const QStringList& roots )
00118 {
00119 Q_UNUSED(roots);
00120 if ( !mStorageQuotaInfo.isValid() && !error() ) {
00121
00122
00123
00124 mStorageQuotaInfo.setName( "STORAGE" );
00125 }
00126 if ( mStorageQuotaInfo.isValid() )
00127 emit storageQuotaResult( mStorageQuotaInfo );
00128 }
00129
00130 void QuotaJobs::GetStorageQuotaJob::slotQuotaInfoReceived( const QuotaInfoList& infos )
00131 {
00132 QuotaInfoList::ConstIterator it( infos.begin() );
00133 while ( it != infos.end() ) {
00134
00135 if ( it->name() == "STORAGE" && !mStorageQuotaInfo.isValid() ) {
00136 mStorageQuotaInfo = *it;
00137 }
00138 ++it;
00139 }
00140 }
00141
00142 QuotaInfo QuotaJobs::GetStorageQuotaJob::storageQuotaInfo() const
00143 {
00144 return mStorageQuotaInfo;
00145 }
00146
00147 #include "quotajobs.moc"
|