kmail

quotajobs.h
1 
32 #ifndef QUOTAJOBS_H
33 #define QUOTAJOBS_H
34 
35 #include <tqvariant.h>
36 
37 #include <tdeio/job.h>
38 #include <tdelocale.h>
39 #include <tqvaluevector.h>
40 
41 #include <math.h>
42 
43 #include "globalsettings.h"
44 
45 namespace KMail {
46 
47 // One quota entry consisting of a name, the quota root,
48 // the current value and the maximal value
49 class QuotaInfo {
50  public :
51  QuotaInfo() {} // for TQValueVector
52  QuotaInfo( const TQString& _name, const TQString& _root, const TQVariant& _current, const TQVariant& _max )
53  : mName( _name ), mRoot( _root ), mCurrent( _current ),mMax( _max ) {}
54  bool operator==( const QuotaInfo & other ) const {
55  return mName == other.mName && mRoot == other.mRoot && mMax == other.mMax && mCurrent == other.mCurrent;
56  }
57  bool operator!=( const QuotaInfo & other ) const {
58  return !(operator==(other) );
59  }
60  bool isValid() const { return !mName.isEmpty(); }
61  bool isEmpty() const { return mName.isEmpty() || ( mRoot.isEmpty() && !mCurrent.isValid() && !mMax.isValid() ); }
62 
63  TQString name() const { return mName; }
64  void setName( const TQString& n ) { mName = n; }
65  TQString root() const { return mRoot; }
66  void setRoot( const TQString& r ) { mRoot = r; }
67  TQVariant max() const { return mMax; }
68  void setMax( const TQVariant& m ) { mMax = m; }
69  TQVariant current() const { return mCurrent; }
70  void setCurrent( const TQVariant& c ) { mCurrent = c; }
71 
72  TQString toString() const {
73  if ( isValid() && !isEmpty() ) {
74  readConfig();
75  int factor = static_cast<int> ( pow( 1000, mFactor ) );
76  return i18n("%1 of %2 %3 used").arg( mCurrent.toInt() / factor )
77  .arg( mMax.toInt() / factor ).arg( mUnits );
78  }
79  return TQString();
80  }
81 
82  private:
83  void readConfig() const {
84  if( GlobalSettings::self()->quotaUnit() == GlobalSettings::EnumQuotaUnit::KB )
85  {
86  mUnits = i18n("KB");
87  mFactor = 0;
88  }
89  else if( GlobalSettings::self()->quotaUnit() == GlobalSettings::EnumQuotaUnit::MB )
90  {
91  mUnits = i18n("MB");
92  mFactor = 1;
93  }
94  else if( GlobalSettings::self()->quotaUnit() == GlobalSettings::EnumQuotaUnit::GB )
95  {
96  mUnits = i18n("GB");
97  mFactor = 2;
98  }
99  }
100 
101  TQString mName; // e.g. STORAGE
102  TQString mRoot;
103  TQVariant mCurrent;
104  TQVariant mMax;
105  mutable TQString mUnits; //used by readConfig (const) privately and is modified
106  mutable int mFactor;
107 };
108 
109 typedef TQValueVector<QuotaInfo> QuotaInfoList;
110 
118 namespace QuotaJobs {
119 
120 class GetQuotarootJob;
126 GetQuotarootJob* getQuotaroot( TDEIO::Slave* slave, const KURL& url );
127 
128 class GetStorageQuotaJob;
134 GetStorageQuotaJob* getStorageQuota( TDEIO::Slave* slave, const KURL& url );
135 
137 class GetQuotarootJob : public TDEIO::SimpleJob
138 {
139  TQ_OBJECT
140 
141 public:
142  GetQuotarootJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo );
143 
144 signals:
149  void quotaRootResult( const TQStringList& roots );
150 
157  void quotaInfoReceived( const QuotaInfoList& info );
158 
159 protected slots:
160  void slotInfoMessage( TDEIO::Job*, const TQString& );
161 };
162 
164 class GetStorageQuotaJob : public TDEIO::Job
165 {
166  TQ_OBJECT
167 
168 public:
169  GetStorageQuotaJob( TDEIO::Slave* slave, const KURL& url );
170 
172  QuotaInfo storageQuotaInfo() const;
173 
174 signals:
180  void storageQuotaResult( const QuotaInfo& info );
181 
182 
183 protected slots:
184  void slotQuotarootResult( const TQStringList& roots );
185  void slotQuotaInfoReceived( const QuotaInfoList& roots );
186 private:
187  QuotaInfo mStorageQuotaInfo;
188 };
189 
190 } // QuotaJobs namespace
191 
192 } // KMail namespace
193 
194 
195 #endif /* QUOTAJOBS_H */
196 
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
GetQuotarootJob * getQuotaroot(TDEIO::Slave *slave, const KURL &url)
Get the quotaroots for a mailbox.
Definition: quotajobs.cpp:37
folderdiaquotatab.h
Definition: aboutdata.cpp:40