File indexing completed on 2024-05-12 05:12:45
0001 /* 0002 This file is part of Akonadi. 0003 0004 SPDX-FileCopyrightText: 2009 KDAB 0005 SPDX-FileContributor: Till Adam <adam@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include "libakonadiconsole_export.h" 0013 #include <QDateTime> 0014 #include <QList> 0015 #include <QObject> 0016 #include <QPair> 0017 0018 #include <memory> 0019 0020 class JobInfo 0021 { 0022 public: 0023 JobInfo() 0024 : parent(-1) 0025 , state(Initial) 0026 { 0027 } 0028 0029 bool operator==(const JobInfo &other) const 0030 { 0031 return name == other.name && parent == other.parent && type == other.type && timestamp == other.timestamp && state == other.state; 0032 } 0033 0034 QString name; 0035 int parent; 0036 QString type; 0037 QDateTime timestamp; 0038 QDateTime startedTimestamp; 0039 QDateTime endedTimestamp; 0040 enum JobState { Initial = 0, Running, Ended, Failed }; 0041 JobState state; 0042 QString error; 0043 QString debugString; 0044 QString stateAsString() const; 0045 }; 0046 0047 class JobTrackerPrivate; 0048 0049 class LIBAKONADICONSOLE_EXPORT JobTracker : public QObject 0050 { 0051 Q_OBJECT 0052 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Akonadi.JobTracker") 0053 0054 public: 0055 explicit JobTracker(const char *name, QObject *parent = nullptr); 0056 ~JobTracker() override; 0057 0058 QStringList sessions() const; 0059 0060 int idForSession(const QString &session) const; 0061 QString sessionForId(int id) const; 0062 0063 JobInfo info(int id) const; 0064 0065 /** 0066 * Returns the number of (sub)jobs of a session or another job. 0067 * (i.e. going down) 0068 */ 0069 int jobCount(int parentId) const; 0070 int jobIdAt(int childPos, int parentId) const; 0071 0072 /** 0073 * Returns the parent (job/session) ID for the given (job/session) ID, 0074 * or -1 if the ID has no parent. 0075 * (i.e. going up) 0076 */ 0077 int parentId(int id) const; 0078 0079 int rowForJob(int id, int parentId) const; 0080 0081 bool isEnabled() const; 0082 0083 void clear(); 0084 0085 Q_SIGNALS: 0086 /** Emitted when a job (or session) is about to be added to the tracker. 0087 * @param pos the position of the job or session relative to the parent 0088 * @param parentId the id of that parent. 0089 * This makes it easy for the model to find and update the right 0090 * part of the model, for efficiency. 0091 */ 0092 void aboutToAdd(int pos, int parentId); 0093 void added(); 0094 0095 /** Emitted when jobs (or sessiona) have been updated in the tracker. 0096 * The format is a list of pairs consisting of the position of the 0097 * job or session relative to the parent and the id of that parent. 0098 * This makes it easy for the model to find and update the right 0099 * part of the model, for efficiency. 0100 */ 0101 void updated(const QList<QPair<int, int>> &updates); 0102 0103 public Q_SLOTS: 0104 Q_SCRIPTABLE void jobCreated(const QString &session, const QString &jobName, const QString &parentJob, const QString &jobType, const QString &debugString); 0105 Q_SCRIPTABLE void jobStarted(const QString &jobName); 0106 Q_SCRIPTABLE void jobEnded(const QString &jobName, const QString &error); 0107 Q_SCRIPTABLE void setEnabled(bool on); 0108 void signalUpdates(); // public for the unittest 0109 0110 private: 0111 QList<int> childJobs(int parentId) const; 0112 int idForJob(const QString &job) const; 0113 0114 private: 0115 std::unique_ptr<JobTrackerPrivate> const d; 0116 };