File indexing completed on 2024-06-02 05:19:01

0001 /*
0002  *  akonadicollectionsearch.h  -  Search Akonadi Collections
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2014-2022 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include <Akonadi/Collection>
0012 #include <Akonadi/Item>
0013 
0014 #include <QObject>
0015 #include <QMap>
0016 #include <QList>
0017 
0018 class KJob;
0019 namespace Akonadi
0020 {
0021 class CollectionFetchJob;
0022 class ItemFetchJob;
0023 class ItemDeleteJob;
0024 }
0025 
0026 /*=============================================================================
0027 = Class: AkonadiCollectionSearch
0028 = Fetches a list of all Akonadi collections which handle a specified mime type,
0029 = and then optionally fetches or deletes all Items from them with a given GID
0030 = or UID.
0031 =
0032 = Note that this class auto-deletes once it has emitted its completion signal.
0033 = Instances must therefore be created on the heap by operator new(), not on the
0034 = stack.
0035 =============================================================================*/
0036 class AkonadiCollectionSearch : public QObject
0037 {
0038     Q_OBJECT
0039 public:
0040     explicit AkonadiCollectionSearch(const QString& mimeType, const QString& gid = {}, const QString& uid = {}, bool remove = false);
0041 
0042 Q_SIGNALS:
0043     // Signal emitted if action is to fetch all collections for the mime type
0044     void collections(const Akonadi::Collection::List&);
0045     // Signal emitted if action is to fetch all items with the remote ID
0046     void items(const Akonadi::Item::List&);
0047     // Signal emitted if action is to delete all items with the remote ID
0048     void deleted(int count);
0049 
0050 private Q_SLOTS:
0051     void collectionFetchResult(KJob*);
0052     void itemFetchResult(KJob*);
0053     void itemDeleteResult(KJob*);
0054     void finish();
0055 
0056 private:
0057     QString                                mMimeType;
0058     QString                                mGid;
0059     QString                                mUid;
0060     QList<Akonadi::CollectionFetchJob*>    mCollectionJobs;
0061     QMap<Akonadi::ItemFetchJob*, Akonadi::Collection::Id>  mItemFetchJobs;
0062     QMap<Akonadi::ItemDeleteJob*, Akonadi::Collection::Id> mItemDeleteJobs;
0063     Akonadi::Collection::List              mCollections;
0064     Akonadi::Item::List                    mItems;
0065     int                                    mDeleteCount {0};
0066     bool                                   mDelete;
0067 };
0068 
0069 // vim: et sw=4: