File indexing completed on 2024-11-10 04:40:11

0001 /*
0002   SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QQueue>
0010 #include <QSharedPointer>
0011 
0012 #include "entitytreemodel.h"
0013 #include "job.h"
0014 
0015 #include "akonaditestfake_export.h"
0016 #include "fakeakonadiservercommand.h"
0017 #include "fakemonitor.h"
0018 #include "fakesession.h"
0019 
0020 using namespace Akonadi;
0021 
0022 class AKONADITESTFAKE_EXPORT FakeServerData : public QObject
0023 {
0024     Q_OBJECT
0025 public:
0026     FakeServerData(EntityTreeModel *model, FakeSession *session, FakeMonitor *monitor, QObject *parent = nullptr);
0027     FakeServerData(TagModel *model, FakeSession *session, FakeMonitor *monitor, QObject *parent = nullptr);
0028 
0029     void setCommands(const QList<FakeAkonadiServerCommand *> &list);
0030 
0031     Collection::Id nextCollectionId() const
0032     {
0033         return m_nextCollectionId++;
0034     }
0035     Item::Id nextItemId() const
0036     {
0037         return m_nextItemId++;
0038     }
0039     Tag::Id nextTagId() const
0040     {
0041         return m_nextTagId++;
0042     }
0043 
0044     QAbstractItemModel *model() const
0045     {
0046         return m_model;
0047     }
0048 
0049     void processNotifications();
0050 
0051 private Q_SLOTS:
0052     void jobAdded(qint64 fetchCollectionId);
0053     void jobAdded();
0054 
0055 private:
0056     bool returnCollections(Collection::Id fetchColId);
0057     void returnItems(Item::Id fetchColId);
0058     void returnEntities(Collection::Id fetchColId);
0059     void returnTags();
0060 
0061 private:
0062     QAbstractItemModel *m_model = nullptr;
0063 
0064     QList<FakeAkonadiServerCommand *> m_commandList;
0065     QQueue<FakeAkonadiServerCommand *> m_communicationQueue;
0066 
0067     mutable Collection::Id m_nextCollectionId;
0068     mutable Item::Id m_nextItemId;
0069     mutable Tag::Id m_nextTagId;
0070 };