File indexing completed on 2024-05-12 05:17:24

0001 /*
0002     Copyright (c) 2009 Andras Mantia <amantia@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to the
0016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017     02110-1301, USA.
0018 */
0019 
0020 #include "quotajobbase.h"
0021 #include "quotajobbase_p.h"
0022 #include "message_p.h"
0023 #include "session_p.h"
0024 
0025 using namespace KIMAP2;
0026 
0027 QMap<QByteArray, QPair<qint64, qint64> > QuotaJobBasePrivate::readQuota(const Message::Part &content)
0028 {
0029     QMap<QByteArray, QPair<qint64, qint64> > quotaMap;
0030     QList<QByteArray> quotas = content.toList();
0031 
0032     int i = 0;
0033     while (i < quotas.size() - 2) {
0034         QByteArray resource = quotas[i].toUpper();
0035         qint64 usage = quotas[i + 1].toInt();
0036         qint64 limit = quotas[i + 2].toInt();
0037         quotaMap[resource] = qMakePair(usage, limit);
0038         i += 3;
0039     }
0040 
0041     return quotaMap;
0042 }
0043 
0044 QuotaJobBase::QuotaJobBase(Session *session)
0045     : Job(*new QuotaJobBasePrivate(session, "QuotaJobBase"))
0046 {
0047 }
0048 
0049 QuotaJobBase::QuotaJobBase(JobPrivate &dd)
0050     : Job(dd)
0051 {
0052 }
0053 
0054 QuotaJobBase::~QuotaJobBase()
0055 {
0056 }
0057 
0058 qint64 QuotaJobBase::usage(const QByteArray &resource)
0059 {
0060     Q_D(QuotaJobBase);
0061 
0062     QByteArray r = resource.toUpper();
0063 
0064     if (d->quota.contains(r)) {
0065         return d->quota[r].first;
0066     }
0067     return -1;
0068 }
0069 
0070 qint64 QuotaJobBase::limit(const QByteArray &resource)
0071 {
0072     Q_D(QuotaJobBase);
0073 
0074     QByteArray r = resource.toUpper();
0075 
0076     if (d->quota.contains(r)) {
0077         return d->quota[r].second;
0078     }
0079     return -1;
0080 }