File indexing completed on 2024-05-12 05:17:25
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 "setquotajob.h" 0021 0022 #include "kimap_debug.h" 0023 0024 #include "quotajobbase_p.h" 0025 #include "message_p.h" 0026 #include "session_p.h" 0027 0028 namespace KIMAP2 0029 { 0030 class SetQuotaJobPrivate : public QuotaJobBasePrivate 0031 { 0032 public: 0033 SetQuotaJobPrivate(Session *session, const QString &name) : QuotaJobBasePrivate(session, name) { } 0034 ~SetQuotaJobPrivate() { } 0035 0036 QMap<QByteArray, qint64> setList; 0037 QByteArray root; 0038 }; 0039 } 0040 0041 using namespace KIMAP2; 0042 0043 SetQuotaJob::SetQuotaJob(Session *session) 0044 : QuotaJobBase(*new SetQuotaJobPrivate(session, "SetQuota")) 0045 { 0046 } 0047 0048 SetQuotaJob::~SetQuotaJob() 0049 { 0050 } 0051 0052 void SetQuotaJob::doStart() 0053 { 0054 Q_D(SetQuotaJob); 0055 QByteArray s; 0056 s += '('; 0057 for (QMap<QByteArray, qint64>::ConstIterator it = d->setList.constBegin(); it != d->setList.constEnd(); ++it) { 0058 s += it.key() + ' ' + QByteArray::number(it.value()) + ' '; 0059 } 0060 if (d->setList.isEmpty()) { 0061 s += ')'; 0062 } else { 0063 s[s.length() - 1] = ')'; 0064 } 0065 0066 qCDebug(KIMAP2_LOG) << "SETQUOTA " << '\"' + d->root + "\" " + s; 0067 //XXX: [alexmerry, 2010-07-24]: should d->root be quoted properly? 0068 d->sendCommand("SETQUOTA", '\"' + d->root + "\" " + s); 0069 } 0070 0071 void SetQuotaJob::handleResponse(const Message &response) 0072 { 0073 Q_D(SetQuotaJob); 0074 if (handleErrorReplies(response) == NotHandled) { 0075 if (response.content.size() >= 4 && 0076 response.content[1].toString() == "QUOTA") { 0077 d->quota = d->readQuota(response.content[3]); 0078 } 0079 } 0080 } 0081 0082 void SetQuotaJob::setQuota(const QByteArray &resource, qint64 limit) 0083 { 0084 Q_D(SetQuotaJob); 0085 0086 d->setList[resource.toUpper()] = limit; 0087 } 0088 0089 void SetQuotaJob::setRoot(const QByteArray &root) 0090 { 0091 Q_D(SetQuotaJob); 0092 0093 d->root = root; 0094 } 0095 0096 QByteArray SetQuotaJob::root() const 0097 { 0098 Q_D(const SetQuotaJob); 0099 0100 return d->root; 0101 }