quotajobs.h
00001 00032 #ifndef QUOTAJOBS_H 00033 #define QUOTAJOBS_H 00034 00035 #include <tqvariant.h> 00036 00037 #include <kio/job.h> 00038 #include <klocale.h> 00039 #include <tqvaluevector.h> 00040 00041 #include <math.h> 00042 00043 #include "globalsettings.h" 00044 00045 namespace KMail { 00046 00047 // One quota entry consisting of a name, the quota root, 00048 // the current value and the maximal value 00049 class QuotaInfo { 00050 public : 00051 QuotaInfo() {} // for TQValueVector 00052 QuotaInfo( const TQString& _name, const TQString& _root, const TQVariant& _current, const TQVariant& _max ) 00053 : mName( _name ), mRoot( _root ), mCurrent( _current ),mMax( _max ) {} 00054 bool operator==( const QuotaInfo & other ) const { 00055 return mName == other.mName && mRoot == other.mRoot && mMax == other.mMax && mCurrent == other.mCurrent; 00056 } 00057 bool operator!=( const QuotaInfo & other ) const { 00058 return !(operator==(other) ); 00059 } 00060 bool isValid() const { return !mName.isEmpty(); } 00061 bool isEmpty() const { return mName.isEmpty() || ( mRoot.isEmpty() && !mCurrent.isValid() && !mMax.isValid() ); } 00062 00063 TQString name() const { return mName; } 00064 void setName( const TQString& n ) { mName = n; } 00065 TQString root() const { return mRoot; } 00066 void setRoot( const TQString& r ) { mRoot = r; } 00067 TQVariant max() const { return mMax; } 00068 void setMax( const TQVariant& m ) { mMax = m; } 00069 TQVariant current() const { return mCurrent; } 00070 void setCurrent( const TQVariant& c ) { mCurrent = c; } 00071 00072 TQString toString() const { 00073 if ( isValid() && !isEmpty() ) { 00074 readConfig(); 00075 int factor = static_cast<int> ( pow( 1000, mFactor ) ); 00076 return i18n("%1 of %2 %3 used").arg( mCurrent.toInt() / factor ) 00077 .arg( mMax.toInt() / factor ).arg( mUnits ); 00078 } 00079 return TQString(); 00080 } 00081 00082 private: 00083 void readConfig() const { 00084 if( GlobalSettings::self()->quotaUnit() == GlobalSettings::EnumQuotaUnit::KB ) 00085 { 00086 mUnits = i18n("KB"); 00087 mFactor = 0; 00088 } 00089 else if( GlobalSettings::self()->quotaUnit() == GlobalSettings::EnumQuotaUnit::MB ) 00090 { 00091 mUnits = i18n("MB"); 00092 mFactor = 1; 00093 } 00094 else if( GlobalSettings::self()->quotaUnit() == GlobalSettings::EnumQuotaUnit::GB ) 00095 { 00096 mUnits = i18n("GB"); 00097 mFactor = 2; 00098 } 00099 } 00100 00101 TQString mName; // e.g. STORAGE 00102 TQString mRoot; 00103 TQVariant mCurrent; 00104 TQVariant mMax; 00105 mutable TQString mUnits; //used by readConfig (const) privately and is modified 00106 mutable int mFactor; 00107 }; 00108 00109 typedef TQValueVector<QuotaInfo> QuotaInfoList; 00110 00118 namespace QuotaJobs { 00119 00120 class GetQuotarootJob; 00126 GetQuotarootJob* getQuotaroot( KIO::Slave* slave, const KURL& url ); 00127 00128 class GetStorageQuotaJob; 00134 GetStorageQuotaJob* getStorageQuota( KIO::Slave* slave, const KURL& url ); 00135 00137 class GetQuotarootJob : public KIO::SimpleJob 00138 { 00139 Q_OBJECT 00140 TQ_OBJECT 00141 public: 00142 GetQuotarootJob( const KURL& url, const TQByteArray &packedArgs, bool showProgressInfo ); 00143 00144 signals: 00149 void quotaRootResult( const TQStringList& roots ); 00150 00157 void quotaInfoReceived( const QuotaInfoList& info ); 00158 00159 protected slots: 00160 void slotInfoMessage( KIO::Job*, const TQString& ); 00161 }; 00162 00164 class GetStorageQuotaJob : public KIO::Job 00165 { 00166 Q_OBJECT 00167 TQ_OBJECT 00168 public: 00169 GetStorageQuotaJob( KIO::Slave* slave, const KURL& url ); 00170 00172 QuotaInfo storageQuotaInfo() const; 00173 00174 signals: 00180 void storageQuotaResult( const QuotaInfo& info ); 00181 00182 00183 protected slots: 00184 void slotQuotarootResult( const TQStringList& roots ); 00185 void slotQuotaInfoReceived( const QuotaInfoList& roots ); 00186 private: 00187 QuotaInfo mStorageQuotaInfo; 00188 }; 00189 00190 } // QuotaJobs namespace 00191 00192 } // KMail namespace 00193 00194 00195 #endif /* QUOTAJOBS_H */ 00196