Akonadi

collectionstatsfetchhandler.cpp
1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2006 Ingo Kloecker <[email protected]> *
3  * *
4  * SPDX-License-Identifier: LGPL-2.0-or-later *
5  ***************************************************************************/
6 
7 #include "collectionstatsfetchhandler.h"
8 
9 #include "akonadi.h"
10 #include "connection.h"
11 #include "global.h"
12 #include "handlerhelper.h"
13 #include "storage/collectionstatistics.h"
14 #include "storage/datastore.h"
15 
16 #include <private/scope_p.h>
17 
18 using namespace Akonadi;
19 using namespace Akonadi::Server;
20 
21 CollectionStatsFetchHandler::CollectionStatsFetchHandler(AkonadiServer &akonadi)
22  : Handler(akonadi)
23 {
24 }
25 
26 bool CollectionStatsFetchHandler::parseStream()
27 {
28  const auto &cmd = Protocol::cmdCast<Protocol::FetchCollectionStatsCommand>(m_command);
29 
30  const Collection col = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
31  if (!col.isValid()) {
32  return failureResponse(QStringLiteral("No status for this folder"));
33  }
34 
35  const auto stats = akonadi().collectionStatistics().statistics(col);
36  if (stats.count == -1) {
37  return failureResponse(QStringLiteral("Failed to query statistics."));
38  }
39 
40  Protocol::FetchCollectionStatsResponse resp;
41  resp.setCount(stats.count);
42  resp.setUnseen(stats.count - stats.read);
43  resp.setSize(stats.size);
44  return successResponse(std::move(resp));
45 }
Represents a collection of PIM items.
Definition: collection.h:61
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:39
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Sep 26 2022 04:03:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.