kmail

quotajobs.cpp
1
31#include "quotajobs.h"
32#include <tdeio/scheduler.h>
33#include <kdebug.h>
34
35using namespace KMail;
36
37QuotaJobs::GetQuotarootJob* QuotaJobs::getQuotaroot(
38 TDEIO::Slave* slave, const KURL& url )
39{
40 TQByteArray packedArgs;
41 TQDataStream stream( packedArgs, IO_WriteOnly );
42 stream << (int)'Q' << (int)'R' << url;
43
44 GetQuotarootJob* job = new GetQuotarootJob( url, packedArgs, false );
45 TDEIO::Scheduler::assignJobToSlave( slave, job );
46 return job;
47}
48
49QuotaJobs::GetQuotarootJob::GetQuotarootJob( const KURL& url,
50 const TQByteArray &packedArgs,
51 bool showProgressInfo )
52 : TDEIO::SimpleJob( url, TDEIO::CMD_SPECIAL, packedArgs, showProgressInfo )
53{
54 connect( this, TQ_SIGNAL(infoMessage(TDEIO::Job*,const TQString&)),
55 TQ_SLOT(slotInfoMessage(TDEIO::Job*,const TQString&)) );
56}
57
58void QuotaJobs::GetQuotarootJob::slotInfoMessage( TDEIO::Job*, const TQString& str )
59{
60 // Parse the result
61 TQStringList results = TQStringList::split("\r", str);
62 TQStringList roots;
63 QuotaInfoList quotas;
64 if ( results.size() > 0 ) {
65 // the first line is the available roots
66 roots = TQStringList::split(" ", results.front() );
67 results.pop_front();
68 // the rest are pairs of root -> list of triplets
69 while ( results.size() > 0 ) {
70 TQString root = results.front(); results.pop_front();
71 // and the quotas
72 if ( results.size() > 0 ) {
73 TQStringList triplets = TQStringList::split(" ", results.front() );
74 results.pop_front();
75 while ( triplets.size() > 0 ) {
76 // there's always three, the label, current and max values
77 TQString name = triplets.front(); triplets.pop_front();
78 TQString current = triplets.front(); triplets.pop_front();
79 TQString max = triplets.front(); triplets.pop_front();
80 QuotaInfo info( name, root, current, max );
81 quotas.append( info );
82 }
83 }
84 }
85 }
86 if ( !quotas.isEmpty() ) {
87 emit quotaInfoReceived( quotas );
88 }
89 emit quotaRootResult( roots );
90}
91
93 TDEIO::Slave* slave, const KURL& url )
94{
95 GetStorageQuotaJob* job = new GetStorageQuotaJob( slave, url );
96 return job;
97}
98
99
100QuotaJobs::GetStorageQuotaJob::GetStorageQuotaJob( TDEIO::Slave* slave, const KURL& url )
101 : TDEIO::Job( false )
102{
103 TQByteArray packedArgs;
104 TQDataStream stream( packedArgs, IO_WriteOnly );
105 stream << (int)'Q' << (int)'R' << url;
106
108 new QuotaJobs::GetQuotarootJob( url, packedArgs, false );
109 connect(job, TQ_SIGNAL(quotaInfoReceived(const QuotaInfoList&)),
110 TQ_SLOT(slotQuotaInfoReceived(const QuotaInfoList&)));
111 connect(job, TQ_SIGNAL(quotaRootResult(const TQStringList&)),
112 TQ_SLOT(slotQuotarootResult(const TQStringList&)));
113 TDEIO::Scheduler::assignJobToSlave( slave, job );
114 addSubjob( job );
115}
116
117void QuotaJobs::GetStorageQuotaJob::slotQuotarootResult( const TQStringList& roots )
118{
119 Q_UNUSED(roots); // we only support one for now
120 if ( !mStorageQuotaInfo.isValid() && !error() ) {
121 // No error, so the account supports quota, but no usable info
122 // was transmitted => no quota set on the folder. Make the info
123 // valid, bit leave it empty.
124 mStorageQuotaInfo.setName( "STORAGE" );
125 }
126 if ( mStorageQuotaInfo.isValid() )
127 emit storageQuotaResult( mStorageQuotaInfo );
128}
129
130void QuotaJobs::GetStorageQuotaJob::slotQuotaInfoReceived( const QuotaInfoList& infos )
131{
132 QuotaInfoList::ConstIterator it( infos.begin() );
133 while ( it != infos.end() ) {
134 // FIXME we only use the first storage quota, for now
135 if ( it->name() == "STORAGE" && !mStorageQuotaInfo.isValid() ) {
136 mStorageQuotaInfo = *it;
137 }
138 ++it;
139 }
140}
141
143{
144 return mStorageQuotaInfo;
145}
146
147#include "quotajobs.moc"
void quotaInfoReceived(const QuotaInfoList &info)
Emitted when the server returns a list of quota infos for the specified mailbox.
void quotaRootResult(const TQStringList &roots)
Emitted when the server returns a (potentially empty) list of quota roots for the specified mailbox.
QuotaInfo storageQuotaInfo() const
Returns the storage quota info, if any, can be queried on result().
Definition: quotajobs.cpp:142
void storageQuotaResult(const QuotaInfo &info)
Emitted to indicate that storage quota information has been received.
GetStorageQuotaJob * getStorageQuota(TDEIO::Slave *slave, const KURL &url)
Get the storage quota for a mailbox, if there is one.
Definition: quotajobs.cpp:92
folderdiaquotatab.h
Definition: aboutdata.cpp:40