2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-08-12 16:45:27 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2020-08-25 16:05:56 +02:00
|
|
|
*
|
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
2014-06-27 15:34:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CALAMARES_JOBQUEUE_H
|
|
|
|
#define CALAMARES_JOBQUEUE_H
|
|
|
|
|
|
|
|
#include "DllMacro.h"
|
2019-05-07 15:51:23 +02:00
|
|
|
#include "Job.h"
|
2014-06-27 15:34:05 +02:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
namespace Calamares
|
|
|
|
{
|
2014-07-21 17:08:06 +02:00
|
|
|
class GlobalStorage;
|
2014-07-08 17:04:39 +02:00
|
|
|
class JobThread;
|
|
|
|
|
2014-06-27 15:34:05 +02:00
|
|
|
class DLLEXPORT JobQueue : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit JobQueue( QObject* parent = nullptr );
|
2014-07-21 17:08:06 +02:00
|
|
|
virtual ~JobQueue();
|
2014-06-27 16:21:45 +02:00
|
|
|
|
|
|
|
static JobQueue* instance();
|
|
|
|
|
2014-07-21 17:08:06 +02:00
|
|
|
GlobalStorage* globalStorage() const;
|
|
|
|
|
2020-08-12 16:45:27 +02:00
|
|
|
/** @brief Queues up jobs from a single module source
|
|
|
|
*
|
|
|
|
* The total weight of the jobs is spread out to fill the weight
|
|
|
|
* of the module.
|
|
|
|
*/
|
|
|
|
void enqueue( int moduleWeight, const JobList& jobs );
|
2020-08-20 22:28:52 +02:00
|
|
|
/** @brief Starts all the jobs that are enqueued.
|
|
|
|
*
|
|
|
|
* After this, isRunning() returns @c true until
|
|
|
|
* finished() is emitted.
|
|
|
|
*/
|
2014-07-08 17:04:39 +02:00
|
|
|
void start();
|
2014-06-27 16:21:45 +02:00
|
|
|
|
2020-03-24 15:14:38 +01:00
|
|
|
bool isRunning() const { return !m_finished; }
|
|
|
|
|
2014-06-27 16:21:45 +02:00
|
|
|
signals:
|
2020-08-28 14:24:06 +02:00
|
|
|
/** @brief Report progress of the whole queue, with a status message
|
|
|
|
*
|
|
|
|
* The @p percent is a value between 0.0 and 1.0 (100%) of the
|
|
|
|
* overall queue progress (not of the current job), while
|
|
|
|
* @p prettyName is the status message from the job -- often
|
|
|
|
* just the name of the job, but some jobs include more information.
|
|
|
|
*/
|
2014-07-23 10:58:08 +02:00
|
|
|
void progress( qreal percent, const QString& prettyName );
|
2020-08-28 14:24:06 +02:00
|
|
|
/** @brief Indicate that the queue is empty, after calling start()
|
|
|
|
*
|
|
|
|
* Emitted when the queue empties. The queue may also emit
|
|
|
|
* failed(), if something went wrong, but finished() is always
|
|
|
|
* the last one.
|
|
|
|
*/
|
2014-07-23 10:58:08 +02:00
|
|
|
void finished();
|
2020-08-28 14:24:06 +02:00
|
|
|
/** @brief A job in the queue failed.
|
|
|
|
*
|
|
|
|
* Contains the (already-translated) text from the job describing
|
|
|
|
* the failure.
|
|
|
|
*/
|
2014-07-10 14:46:08 +02:00
|
|
|
void failed( const QString& message, const QString& details );
|
2014-06-27 16:21:45 +02:00
|
|
|
|
2020-08-28 14:39:32 +02:00
|
|
|
/** @brief Reports the names of jobs in the queue.
|
|
|
|
*
|
|
|
|
* When jobs are added via enqueue(), or when the queue otherwise
|
|
|
|
* changes, the **names** of the jobs are reported. This is
|
|
|
|
* primarily for debugging purposes.
|
|
|
|
*/
|
|
|
|
void queueChanged( const QStringList& jobNames );
|
|
|
|
|
2020-09-03 15:39:04 +02:00
|
|
|
public slots:
|
|
|
|
/** @brief Implementation detail
|
|
|
|
*
|
|
|
|
* This is a private implementation detail for the job thread,
|
|
|
|
* which should not be called by other core.
|
|
|
|
*/
|
2020-08-20 22:28:52 +02:00
|
|
|
void finish();
|
|
|
|
|
2020-09-03 15:39:04 +02:00
|
|
|
private:
|
2014-06-27 16:21:45 +02:00
|
|
|
static JobQueue* s_instance;
|
2014-07-08 17:04:39 +02:00
|
|
|
|
|
|
|
JobThread* m_thread;
|
2014-07-21 17:08:06 +02:00
|
|
|
GlobalStorage* m_storage;
|
2020-03-24 15:14:38 +01:00
|
|
|
bool m_finished = true; ///< Initially, not running
|
2014-06-27 15:34:05 +02:00
|
|
|
};
|
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
} // namespace Calamares
|
2014-06-27 15:34:05 +02:00
|
|
|
|
2019-08-04 22:24:55 +02:00
|
|
|
#endif // CALAMARES_JOBQUEUE_H
|