Akonadi

collectionstatisticsjob.cpp
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "collectionstatisticsjob.h"
21 
22 #include "collection.h"
23 #include "collectionstatistics.h"
24 #include "job_p.h"
25 #include "protocolhelper_p.h"
26 #include "private/protocol_p.h"
27 
28 using namespace Akonadi;
29 
30 class Akonadi::CollectionStatisticsJobPrivate : public JobPrivate
31 {
32 public:
33  CollectionStatisticsJobPrivate(CollectionStatisticsJob *parent)
34  : JobPrivate(parent)
35  {
36  }
37 
38  QString jobDebuggingString() const override
39  {
40  return QStringLiteral("Collection Statistic from collection Id %1").arg(mCollection.id());
41  }
42 
43  Collection mCollection;
44  CollectionStatistics mStatistics;
45 };
46 
48  : Job(new CollectionStatisticsJobPrivate(this), parent)
49 {
51 
52  d->mCollection = collection;
53 }
54 
56 {
57 }
58 
60 {
62 
63  try {
64  d->sendCommand(Protocol::FetchCollectionStatsCommandPtr::create(ProtocolHelper::entityToScope(d->mCollection)));
65  } catch (const std::exception &e) {
68  emitResult();
69  return;
70  }
71 }
72 
74 {
76 
77  if (!response->isResponse() || response->type() != Protocol::Command::FetchCollectionStats) {
78  return Job::doHandleResponse(tag, response);
79  }
80 
81  d->mStatistics = ProtocolHelper::parseCollectionStatistics(
82  Protocol::cmdCast<Protocol::FetchCollectionStatsResponse>(response));
83  return true;
84 }
85 
87 {
88  Q_D(const CollectionStatisticsJob);
89 
90  return d->mCollection;
91 }
92 
94 {
95  Q_D(const CollectionStatisticsJob);
96 
97  return d->mStatistics;
98 }
virtual bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
This method should be reimplemented in the concrete jobs in case you want to handle incoming data...
Definition: job.cpp:385
void emitResult()
Provides statistics information of a Collection.
Unknown error.
Definition: job.h:115
Represents a collection of PIM items.
Definition: collection.h:76
void setError(int errorCode)
~CollectionStatisticsJob() override
Destroys the collection statistics job.
Base class for all actions in the Akonadi storage.
Definition: job.h:93
void setErrorText(const QString &errorText)
bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override
This method should be reimplemented in the concrete jobs in case you want to handle incoming data...
QString fromUtf8(const char *str, int size)
CollectionStatistics statistics() const
Returns the fetched collection statistics.
Collection collection() const
Returns the corresponding collection, if the job was executed successfully, the collection is already...
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Job that fetches collection statistics from the Akonadi storage.
void doStart() override
This method must be reimplemented in the concrete jobs.
CollectionStatisticsJob(const Collection &collection, QObject *parent=nullptr)
Creates a new collection statistics job.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.