calamares/src/libcalamares/Job.h

150 lines
4.6 KiB
C
Raw Normal View History

/* === This file is part of Calamares - <https://github.com/calamares> ===
*
[libcalamares] Update SPDX identifiers. Update CppJob.h Update CalamaresConfig.h.in Update DllMacro.h Update GlobalStorage.cpp Update GlobalStorage.h Update Job.cpp Update Job.h Update JobExample.cpp Update JobExample.h Update JobQueue.cpp Update CalamaresConfig.h.in Update CppJob.cpp Update CppJob.h Update DllMacro.h Update GlobalStorage.cpp Update GlobalStorage.h Update Job.cpp Update Job.h Update JobExample.cpp Update JobExample.h Update JobQueue.h Update ProcessJob.cpp Update ProcessJob.h Update PythonHelper.cpp Update PythonJob.cpp Update PythonJob.h Update PythonHelper.h Update PythonJobApi.cpp Update PythonJobApi.h Update Settings.cpp Update Settings.h Update GeoIPJSON.cpp Update GeoIPJSON.h Update GeoIPTests.cpp Update GeoIPTests.h Update GeoIPXML.cpp Update GeoIPXML.h Update Handler.cpp Update Handler.h Update Interface.cpp Update Interface.h Update test_geoip.cpp Update CountryData_p.cpp Update Label.cpp Update Label.h Update LabelModel.cpp Update LabelModel.h Update CountryData_p.cpp Update CountryData_p.cpp Update Lookup.cpp Update Lookup.h Update Tests.cpp Update Tests.h Update TimeZone.cpp Update TimeZone.h Update TranslatableConfiguration.cpp Update TranslatableConfiguration.h Update ZoneData_p.cxxtr Update cldr-extractor.py Update zone-extractor.py Update Actions.h Update Actions.h Update Descriptor.h Update InstanceKey.cpp Update Module.cpp Update Module.h Update Requirement.cpp Update RequirementsChecker.h Update RequirementsModel.cpp Update RequirementsModel.h Update Tests.cpp Update Manager.cpp Update Manager.h Update Tests.cpp Update FileSystem.cpp Update FileSystem.h Update KPMManager.cpp Update KPMManager.h Update KPMTests.cpp Update FileSystem.cpp Update FileSystem.cpp Update FileSystem.h Update KPMManager.cpp Update KPMManager.h Update Mount.cpp Update Mount.h Update PartitionIterator.cpp Update PartitionIterator.h Update PartitionIterator.h Update PartitionQuery.cpp Update PartitionQuery.h Update PartitionSize.cpp Update PartitionSize.h Update Sync.cpp Update Sync.h Update Tests.cpp Update Tests.h Update BoostPython.h Update CalamaresUtilsSystem.cpp Update CalamaresUtilsSystem.h Update CommandList.cpp Update CommandList.h Update Dirs.cpp Update Dirs.h Update Entropy.cpp Update Entropy.h Update Entropy.cpp Update Logger.cpp Update Logger.h Update NamedEnum.h Update NamedSuffix.h Update PluginFactory.cpp Update PluginFactory.h Update RAII.h Update RAII.h Update Retranslator.cpp Update Retranslator.h Update String.cpp Update String.h Update TestPaths.cpp Update Tests.cpp Update Tests.h Update UMask.cpp Update UMask.h Update Units.h Update Variant.cpp Update Variant.h Update Yaml.cpp Update Yaml.h Update moc-warnings.h
2020-05-30 16:15:03 +02:00
* SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
* SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
2014-06-27 15:34:05 +02:00
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
[libcalamares] Update SPDX identifiers. Update CppJob.h Update CalamaresConfig.h.in Update DllMacro.h Update GlobalStorage.cpp Update GlobalStorage.h Update Job.cpp Update Job.h Update JobExample.cpp Update JobExample.h Update JobQueue.cpp Update CalamaresConfig.h.in Update CppJob.cpp Update CppJob.h Update DllMacro.h Update GlobalStorage.cpp Update GlobalStorage.h Update Job.cpp Update Job.h Update JobExample.cpp Update JobExample.h Update JobQueue.h Update ProcessJob.cpp Update ProcessJob.h Update PythonHelper.cpp Update PythonJob.cpp Update PythonJob.h Update PythonHelper.h Update PythonJobApi.cpp Update PythonJobApi.h Update Settings.cpp Update Settings.h Update GeoIPJSON.cpp Update GeoIPJSON.h Update GeoIPTests.cpp Update GeoIPTests.h Update GeoIPXML.cpp Update GeoIPXML.h Update Handler.cpp Update Handler.h Update Interface.cpp Update Interface.h Update test_geoip.cpp Update CountryData_p.cpp Update Label.cpp Update Label.h Update LabelModel.cpp Update LabelModel.h Update CountryData_p.cpp Update CountryData_p.cpp Update Lookup.cpp Update Lookup.h Update Tests.cpp Update Tests.h Update TimeZone.cpp Update TimeZone.h Update TranslatableConfiguration.cpp Update TranslatableConfiguration.h Update ZoneData_p.cxxtr Update cldr-extractor.py Update zone-extractor.py Update Actions.h Update Actions.h Update Descriptor.h Update InstanceKey.cpp Update Module.cpp Update Module.h Update Requirement.cpp Update RequirementsChecker.h Update RequirementsModel.cpp Update RequirementsModel.h Update Tests.cpp Update Manager.cpp Update Manager.h Update Tests.cpp Update FileSystem.cpp Update FileSystem.h Update KPMManager.cpp Update KPMManager.h Update KPMTests.cpp Update FileSystem.cpp Update FileSystem.cpp Update FileSystem.h Update KPMManager.cpp Update KPMManager.h Update Mount.cpp Update Mount.h Update PartitionIterator.cpp Update PartitionIterator.h Update PartitionIterator.h Update PartitionQuery.cpp Update PartitionQuery.h Update PartitionSize.cpp Update PartitionSize.h Update Sync.cpp Update Sync.h Update Tests.cpp Update Tests.h Update BoostPython.h Update CalamaresUtilsSystem.cpp Update CalamaresUtilsSystem.h Update CommandList.cpp Update CommandList.h Update Dirs.cpp Update Dirs.h Update Entropy.cpp Update Entropy.h Update Entropy.cpp Update Logger.cpp Update Logger.h Update NamedEnum.h Update NamedSuffix.h Update PluginFactory.cpp Update PluginFactory.h Update RAII.h Update RAII.h Update Retranslator.cpp Update Retranslator.h Update String.cpp Update String.h Update TestPaths.cpp Update Tests.cpp Update Tests.h Update UMask.cpp Update UMask.h Update Units.h Update Variant.cpp Update Variant.h Update Yaml.cpp Update Yaml.h Update moc-warnings.h
2020-05-30 16:15:03 +02:00
*
2014-06-27 15:34:05 +02:00
*/
#ifndef CALAMARES_JOB_H
#define CALAMARES_JOB_H
#include "DllMacro.h"
#include <QList>
2014-06-27 15:34:05 +02:00
#include <QObject>
#include <QSharedPointer>
2014-06-27 15:34:05 +02:00
namespace Calamares
{
2014-06-27 15:34:05 +02:00
2014-07-08 19:20:04 +02:00
class DLLEXPORT JobResult
{
public:
/** @brief Distinguish classes of errors
*
* All "ok result" have errorCode 0 (NoError).
* Errors returned from job execution have values < 0.
* Errors before job execution, or not returned by the job execution
* itself, have values > 0.
*/
enum
{
NoError = 0,
GenericError = -1,
PythonUncaughtException = 1,
InvalidConfiguration = 2
};
// Can't copy, but you can keep a temporary
JobResult( const JobResult& rhs ) = delete;
JobResult( JobResult&& rhs );
virtual ~JobResult() {}
2014-07-08 19:20:04 +02:00
/** @brief Is this JobResult a success?
*
* Equivalent to errorCode() == 0, might be named isValid().
*/
virtual operator bool() const;
2014-07-08 19:20:04 +02:00
virtual QString message() const;
virtual void setMessage( const QString& message );
virtual QString details() const;
virtual void setDetails( const QString& details );
2014-07-08 19:20:04 +02:00
int errorCode() const { return m_number; }
/// @brief an "ok status" result
2014-07-09 19:08:53 +02:00
static JobResult ok();
/** @brief an "error" result resulting from the execution of the job
*
* The error code is set to GenericError.
*/
2014-07-09 19:08:53 +02:00
static JobResult error( const QString& message, const QString& details = QString() );
/** @brief an "internal error" meaning the job itself has a problem (usually for python)
*
* Pass in a suitable error code; using 0 (which would normally mean "ok") instead
* gives you a GenericError code.
*/
static JobResult internalError( const QString&, const QString& details, int errorCode );
2014-07-08 19:20:04 +02:00
protected:
explicit JobResult( const QString& message, const QString& details, int errorCode );
2014-07-08 19:20:04 +02:00
private:
QString m_message;
QString m_details;
int m_number;
2014-07-08 19:20:04 +02:00
};
2014-06-27 15:34:05 +02:00
class DLLEXPORT Job : public QObject
{
Q_OBJECT
public:
explicit Job( QObject* parent = nullptr );
virtual ~Job();
2020-01-25 01:10:04 +01:00
/** @brief The job's (relative) weight.
*
2020-01-25 01:10:04 +01:00
* The default implementation returns 1.0, which gives all jobs
* the same weight, so they advance the overall progress the same
* amount. This is nonsense, since some jobs take much longer than
* others; it's up to the individual jobs to say something about
* how much work is (relatively) done.
*/
2019-06-28 19:32:35 +02:00
virtual qreal getJobWeight() const;
/** @brief The human-readable name of this job
*
* This should be a very short statement of what the job does.
* For status and state information, see prettyStatusMessage().
*/
2014-07-10 12:06:23 +02:00
virtual QString prettyName() const = 0;
/** @brief a longer human-readable description of what the job will do
*
* This **may** be used by view steps to fill in the summary
* messages for the summary page; at present, only the *partition*
* module does so.
*
* The default implementation returns an empty string.
*/
2015-04-09 15:03:47 +02:00
virtual QString prettyDescription() const;
/** @brief A human-readable status for progress reporting
*
* This is called from the JobQueue when progress is made, and should
* return a not-too-long description of the job's status. This
* is made visible in the progress bar of the execution view step.
*/
virtual QString prettyStatusMessage() const;
2014-07-08 19:20:04 +02:00
virtual JobResult exec() = 0;
bool isEmergency() const { return m_emergency; }
void setEmergency( bool e ) { m_emergency = e; }
signals:
2014-07-23 12:04:27 +02:00
void progress( qreal percent );
private:
bool m_emergency = false;
2014-06-27 15:34:05 +02:00
};
using job_ptr = QSharedPointer< Job >;
using JobList = QList< job_ptr >;
} // namespace Calamares
2014-06-27 15:34:05 +02:00
#endif // CALAMARES_JOB_H