kmail

quotajobs.h

Go to the documentation of this file.
00001 
00032 #ifndef QUOTAJOBS_H
00033 #define QUOTAJOBS_H
00034 
00035 #include <qvariant.h>
00036 
00037 #include <kio/job.h>
00038 #include <klocale.h>
00039 #include <qvaluevector.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 QValueVector
00052   QuotaInfo( const QString& _name, const QString& _root, const QVariant& _current, const QVariant& _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   QString name() const { return mName; }
00064   void setName( const QString& n ) { mName = n; }
00065   QString root() const { return mRoot; }
00066   void setRoot( const QString& r ) { mRoot = r; }
00067   QVariant max() const { return mMax; }
00068   void setMax( const QVariant& m ) { mMax = m; }
00069   QVariant current() const { return mCurrent; }
00070   void setCurrent( const QVariant& c ) { mCurrent = c; }
00071 
00072   QString 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 QString();
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   QString mName;  // e.g. STORAGE
00102   QString mRoot; 
00103   QVariant mCurrent;
00104   QVariant mMax;
00105   mutable QString mUnits; //used by readConfig (const) privately and is modified
00106   mutable int mFactor;
00107 };
00108 
00109 typedef QValueVector<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 public:
00141   GetQuotarootJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo );
00142 
00143 signals:
00148   void quotaRootResult( const QStringList& roots );
00149 
00156   void quotaInfoReceived( const QuotaInfoList& info );
00157 
00158 protected slots:
00159   void slotInfoMessage( KIO::Job*, const QString& );
00160 };
00161 
00163 class GetStorageQuotaJob : public KIO::Job
00164 {
00165   Q_OBJECT
00166 public:
00167   GetStorageQuotaJob( KIO::Slave* slave, const KURL& url );
00168 
00170   QuotaInfo storageQuotaInfo() const;
00171 
00172 signals:
00178   void storageQuotaResult( const QuotaInfo& info );
00179 
00180 
00181 protected slots:
00182   void slotQuotarootResult( const QStringList& roots );
00183   void slotQuotaInfoReceived( const QuotaInfoList& roots );
00184 private:
00185   QuotaInfo mStorageQuotaInfo;
00186 };
00187 
00188 } // QuotaJobs namespace
00189 
00190 } // KMail namespace
00191 
00192 
00193 #endif /* QUOTAJOBS_H */
00194