File indexing completed on 2024-11-10 04:40:29
0001 /* 0002 SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "collectionstatisticsjob.h" 0008 0009 #include "collection.h" 0010 #include "collectionstatistics.h" 0011 #include "job_p.h" 0012 #include "private/protocol_p.h" 0013 #include "protocolhelper_p.h" 0014 0015 using namespace Akonadi; 0016 0017 class Akonadi::CollectionStatisticsJobPrivate : public JobPrivate 0018 { 0019 public: 0020 explicit CollectionStatisticsJobPrivate(CollectionStatisticsJob *parent) 0021 : JobPrivate(parent) 0022 { 0023 } 0024 0025 QString jobDebuggingString() const override 0026 { 0027 return QStringLiteral("Collection Statistic from collection Id %1").arg(mCollection.id()); 0028 } 0029 0030 Collection mCollection; 0031 CollectionStatistics mStatistics; 0032 }; 0033 0034 CollectionStatisticsJob::CollectionStatisticsJob(const Collection &collection, QObject *parent) 0035 : Job(new CollectionStatisticsJobPrivate(this), parent) 0036 { 0037 Q_D(CollectionStatisticsJob); 0038 0039 d->mCollection = collection; 0040 } 0041 0042 CollectionStatisticsJob::~CollectionStatisticsJob() 0043 { 0044 } 0045 0046 void CollectionStatisticsJob::doStart() 0047 { 0048 Q_D(CollectionStatisticsJob); 0049 0050 try { 0051 d->sendCommand(Protocol::FetchCollectionStatsCommandPtr::create(ProtocolHelper::entityToScope(d->mCollection))); 0052 } catch (const std::exception &e) { 0053 setError(Unknown); 0054 setErrorText(QString::fromUtf8(e.what())); 0055 emitResult(); 0056 return; 0057 } 0058 } 0059 0060 bool CollectionStatisticsJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) 0061 { 0062 Q_D(CollectionStatisticsJob); 0063 0064 if (!response->isResponse() || response->type() != Protocol::Command::FetchCollectionStats) { 0065 return Job::doHandleResponse(tag, response); 0066 } 0067 0068 d->mStatistics = ProtocolHelper::parseCollectionStatistics(Protocol::cmdCast<Protocol::FetchCollectionStatsResponse>(response)); 0069 return true; 0070 } 0071 0072 Collection CollectionStatisticsJob::collection() const 0073 { 0074 Q_D(const CollectionStatisticsJob); 0075 0076 return d->mCollection; 0077 } 0078 0079 CollectionStatistics Akonadi::CollectionStatisticsJob::statistics() const 0080 { 0081 Q_D(const CollectionStatisticsJob); 0082 0083 return d->mStatistics; 0084 } 0085 0086 #include "moc_collectionstatisticsjob.cpp"