• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

KIMAP Library

getquotarootjob.cpp
00001 /*
00002     Copyright (c) 2009 Andras Mantia <amantia@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "getquotarootjob.h"
00021 
00022 #include <KDE/KLocale>
00023 #include <KDE/KDebug>
00024 
00025 #include "quotajobbase_p.h"
00026 #include "message_p.h"
00027 #include "session_p.h"
00028 #include "rfccodecs.h"
00029 
00030 namespace KIMAP
00031 {
00032   class GetQuotaRootJobPrivate : public QuotaJobBasePrivate
00033   {
00034     public:
00035       GetQuotaRootJobPrivate( Session *session, const QString& name ) : QuotaJobBasePrivate(session, name) { }
00036       ~GetQuotaRootJobPrivate() { }
00037 
00038       QString mailBox;
00039       QList<QByteArray> rootList;
00040       QMap< QByteArray, QMap<QByteArray, QPair<qint64, qint64> > > quotas;
00041   };
00042 }
00043 
00044 using namespace KIMAP;
00045 
00046 GetQuotaRootJob::GetQuotaRootJob( Session *session )
00047   : QuotaJobBase( *new GetQuotaRootJobPrivate(session, i18n("GetQuotaRoot")) )
00048 {
00049 }
00050 
00051 GetQuotaRootJob::~GetQuotaRootJob()
00052 {
00053 }
00054 
00055 void GetQuotaRootJob::doStart()
00056 {
00057   Q_D(GetQuotaRootJob);
00058   d->tags << d->sessionInternal()->sendCommand( "GETQUOTAROOT", '\"' + KIMAP::encodeImapFolderName( d->mailBox.toUtf8() ) + '\"');
00059 }
00060 
00061 void GetQuotaRootJob::handleResponse(const Message &response)
00062 {
00063   Q_D(GetQuotaRootJob);
00064   if (handleErrorReplies(response) == NotHandled) {
00065     if ( response.content.size() >= 3 ) {
00066       if (response.content[1].toString() == "QUOTAROOT" ) {
00067         d->rootList.clear();
00068         //some impls don't give the root a name which for us seems as if
00069         //there were no message part
00070         if ( response.content.size() == 3 ) {
00071           d->rootList.append("");
00072         } else {
00073           int i = 3;
00074           while ( i < response.content.size())
00075           {
00076             d->rootList.append(response.content[i].toString());
00077             i++;
00078           }
00079         }
00080       } else
00081       if (response.content[1].toString() == "QUOTA" ) {
00082         QByteArray rootName;
00083         int  quotaContentIndex = 3;
00084         //some impls don't give the root a name in the response
00085         if (response.content.size() == 3 ) {
00086           quotaContentIndex = 2;
00087         } else {
00088           rootName = response.content[2].toString();
00089         }       
00090 
00091         const QMap<QByteArray, QPair<qint64, qint64> >& quota = d->readQuota(response.content[quotaContentIndex]);
00092         if (d->quotas.contains(rootName)) {
00093           d->quotas[ rootName ].unite(quota);
00094         } else {
00095           d->quotas[ rootName ] = quota;
00096         }
00097       }
00098     }
00099   }
00100 }
00101 
00102 
00103 void GetQuotaRootJob::setMailBox(const QString& mailBox)
00104 {
00105   Q_D(GetQuotaRootJob);
00106 
00107   d->mailBox = mailBox;
00108 }
00109 
00110 QString GetQuotaRootJob::mailBox() const
00111 {
00112   Q_D(const GetQuotaRootJob);
00113 
00114   return d->mailBox;
00115 }
00116 
00117 QList<QByteArray> GetQuotaRootJob::roots() const
00118 {
00119   Q_D(const GetQuotaRootJob);
00120 
00121   return d->rootList;
00122 }
00123 
00124 qint64 GetQuotaRootJob::usage(const QByteArray &root, const QByteArray &resource) const
00125 {
00126   Q_D(const GetQuotaRootJob);
00127 
00128   QByteArray r = resource.toUpper();
00129 
00130   if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
00131     return d->quotas[root][r].first;
00132   }
00133 
00134   return -1;
00135 }
00136 
00137 qint64 GetQuotaRootJob::limit(const QByteArray &root, const QByteArray &resource) const
00138 {
00139   Q_D(const GetQuotaRootJob);
00140 
00141   QByteArray r = resource.toUpper();
00142 
00143   if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
00144     return d->quotas[root][r].second;
00145   }
00146 
00147   return -1;
00148 }
00149 
00150 QMap<QByteArray, qint64> GetQuotaRootJob::allUsages(const QByteArray &root) const
00151 {
00152   Q_D(const GetQuotaRootJob);
00153 
00154   QMap<QByteArray, qint64> result;
00155 
00156   if (d->quotas.contains(root)) {
00157     const QMap< QByteArray, QPair<qint64, qint64> > quota = d->quotas[root];
00158     QMapIterator<QByteArray, QPair<qint64, qint64> > it( quota );
00159     while ( it.hasNext() ) {
00160       it.next();
00161       result[it.key()] = it.value().first;
00162     }
00163   }
00164 
00165   return result;
00166 }
00167 
00168 QMap<QByteArray, qint64> GetQuotaRootJob::allLimits(const QByteArray &root) const
00169 {
00170   Q_D(const GetQuotaRootJob);
00171 
00172   QMap<QByteArray, qint64> result;
00173 
00174   if (d->quotas.contains(root)) {
00175     const QMap< QByteArray, QPair<qint64, qint64> > quota = d->quotas[root];
00176     QMapIterator<QByteArray, QPair<qint64, qint64> > it( quota );
00177     while ( it.hasNext() ) {
00178       it.next();
00179       result[it.key()] = it.value().second;
00180     }
00181   }
00182 
00183   return result;
00184 }
00185 
00186 #include "getquotarootjob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:32 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIMAP Library

Skip menu "KIMAP Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal