| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_MOLEQUEUE_MOLEQUEUEMANAGER_H |
| 7 |
#define AVOGADRO_MOLEQUEUE_MOLEQUEUEMANAGER_H |
| 8 |
|
| 9 |
#include <QtCore/QObject> |
| 10 |
|
| 11 |
#include "molequeuequeuelistmodel.h" |
| 12 |
|
| 13 |
#include <avogadro/core/avogadrocore.h> |
| 14 |
|
| 15 |
#include "client/client.h" |
| 16 |
|
| 17 |
namespace Avogadro::MoleQueue { |
| 18 |
|
| 19 |
/** |
| 20 |
* @class MoleQueueManager molequeuemanager.h |
| 21 |
* <avogadro/molequeue/molequeuemanager.h> |
| 22 |
* @brief The MoleQueueManager class provides access to a MoleQueue server. |
| 23 |
* |
| 24 |
* This singleton class provides access to a single MoleQueue::Client instance |
| 25 |
* that can be used to communicate with the server. The available queues and |
| 26 |
* programs are cached in a MoleQueueQueueListModel (queueListModel()). The |
| 27 |
* connectIfNeeded convenience function can be used to ensure that the client |
| 28 |
* is connected before use. |
| 29 |
*/ |
| 30 |
class AVOGADROMOLEQUEUE_EXPORT MoleQueueManager : public QObject |
| 31 |
{ |
| 32 |
Q_OBJECT |
| 33 |
public: |
| 34 |
explicit MoleQueueManager(QObject* parent_ = nullptr); |
| 35 |
~MoleQueueManager() override = default; |
| 36 |
|
| 37 |
/** |
| 38 |
* @return The singleton instance. |
| 39 |
*/ |
| 40 |
static MoleQueueManager& instance(); |
| 41 |
|
| 42 |
/** |
| 43 |
* Test if the client is connected, and if not, attempt a connection. |
| 44 |
* @return True if the client is already connected or a new connection has |
| 45 |
* been successfully created. False if the new connection failed. |
| 46 |
*/ |
| 47 |
bool connectIfNeeded(); |
| 48 |
|
| 49 |
/** |
| 50 |
* @return A reference to the managed Client instance. |
| 51 |
* @{ |
| 52 |
*/ |
| 53 |
Client& client(); |
| 54 |
const Client& client() const; |
| 55 |
/** @} */ |
| 56 |
|
| 57 |
/** |
| 58 |
* @return A QAbstractItemModel subclass representing the queue/program tree. |
| 59 |
*/ |
| 60 |
MoleQueueQueueListModel& queueListModel(); |
| 61 |
|
| 62 |
public slots: |
| 63 |
/** |
| 64 |
* Request that the cached queue list is updated. |
| 65 |
* @return True if the request is send successfully. |
| 66 |
*/ |
| 67 |
bool requestQueueList(); |
| 68 |
|
| 69 |
signals: |
| 70 |
/** |
| 71 |
* Emitted when the internal queue list is updated. |
| 72 |
*/ |
| 73 |
void queueListUpdated(); |
| 74 |
|
| 75 |
private slots: |
| 76 |
void updateQueueModel(const QJsonObject& queueList); |
| 77 |
|
| 78 |
private: |
| 79 |
static MoleQueueManager* m_instance; |
| 80 |
Client m_client; |
| 81 |
MoleQueueQueueListModel m_queueModel; |
| 82 |
}; |
| 83 |
|
| 84 |
} // namespace Avogadro::MoleQueue |
| 85 |
|
| 86 |
#endif // AVOGADRO_MOLEQUEUE_MOLEQUEUEMANAGER_H |