File indexing completed on 2024-06-23 05:07:00
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2006 Ingo Kloecker <kloecker@kde.org> * 0003 * * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later * 0005 ***************************************************************************/ 0006 0007 #include "collectionstatsfetchhandler.h" 0008 0009 #include "akonadi.h" 0010 #include "connection.h" 0011 #include "global.h" 0012 #include "handlerhelper.h" 0013 #include "storage/collectionstatistics.h" 0014 #include "storage/datastore.h" 0015 0016 #include "private/scope_p.h" 0017 0018 using namespace Akonadi; 0019 using namespace Akonadi::Server; 0020 0021 CollectionStatsFetchHandler::CollectionStatsFetchHandler(AkonadiServer &akonadi) 0022 : Handler(akonadi) 0023 { 0024 } 0025 0026 bool CollectionStatsFetchHandler::parseStream() 0027 { 0028 const auto &cmd = Protocol::cmdCast<Protocol::FetchCollectionStatsCommand>(m_command); 0029 0030 const Collection col = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context()); 0031 if (!col.isValid()) { 0032 return failureResponse(QStringLiteral("No status for this folder")); 0033 } 0034 0035 const auto stats = akonadi().collectionStatistics().statistics(col); 0036 if (stats.count == -1) { 0037 return failureResponse(QStringLiteral("Failed to query statistics.")); 0038 } 0039 0040 Protocol::FetchCollectionStatsResponse resp; 0041 resp.setCount(stats.count); 0042 resp.setUnseen(stats.count - stats.read); 0043 resp.setSize(stats.size); 0044 return successResponse(std::move(resp)); 0045 }