File indexing completed on 2024-05-12 05:17:17
0001 /* 0002 SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "setquotajob.h" 0008 0009 #include "kimap_debug.h" 0010 #include <KLocalizedString> 0011 0012 #include "quotajobbase_p.h" 0013 #include "response_p.h" 0014 #include "session_p.h" 0015 0016 namespace KIMAP 0017 { 0018 class SetQuotaJobPrivate : public QuotaJobBasePrivate 0019 { 0020 public: 0021 SetQuotaJobPrivate(Session *session, const QString &name) 0022 : QuotaJobBasePrivate(session, name) 0023 { 0024 } 0025 ~SetQuotaJobPrivate() 0026 { 0027 } 0028 0029 QMap<QByteArray, qint64> setList; 0030 QByteArray root; 0031 }; 0032 } 0033 0034 using namespace KIMAP; 0035 0036 SetQuotaJob::SetQuotaJob(Session *session) 0037 : QuotaJobBase(*new SetQuotaJobPrivate(session, i18n("SetQuota"))) 0038 { 0039 } 0040 0041 SetQuotaJob::~SetQuotaJob() 0042 { 0043 } 0044 0045 void SetQuotaJob::doStart() 0046 { 0047 Q_D(SetQuotaJob); 0048 QByteArray s; 0049 s += '('; 0050 for (QMap<QByteArray, qint64>::ConstIterator it = d->setList.constBegin(), end = d->setList.constEnd(); it != end; ++it) { 0051 s += it.key() + ' ' + QByteArray::number(it.value()) + ' '; 0052 } 0053 if (d->setList.isEmpty()) { 0054 s += ')'; 0055 } else { 0056 s[s.length() - 1] = ')'; 0057 } 0058 0059 qCDebug(KIMAP_LOG) << "SETQUOTA " << '\"' + d->root + "\" " + s; 0060 // XXX: [alexmerry, 2010-07-24]: should d->root be quoted properly? 0061 d->tags << d->sessionInternal()->sendCommand("SETQUOTA", '\"' + d->root + "\" " + s); 0062 } 0063 0064 void SetQuotaJob::handleResponse(const Response &response) 0065 { 0066 Q_D(SetQuotaJob); 0067 if (handleErrorReplies(response) == NotHandled) { 0068 if (response.content.size() >= 4 && response.content[1].toString() == "QUOTA") { 0069 d->quota = d->readQuota(response.content[3]); 0070 } 0071 } 0072 } 0073 0074 void SetQuotaJob::setQuota(const QByteArray &resource, qint64 limit) 0075 { 0076 Q_D(SetQuotaJob); 0077 0078 d->setList[resource.toUpper()] = limit; 0079 } 0080 0081 void SetQuotaJob::setRoot(const QByteArray &root) 0082 { 0083 Q_D(SetQuotaJob); 0084 0085 d->root = root; 0086 } 0087 0088 QByteArray SetQuotaJob::root() const 0089 { 0090 Q_D(const SetQuotaJob); 0091 0092 return d->root; 0093 } 0094 0095 #include "moc_setquotajob.cpp"