File indexing completed on 2024-04-28 04:37:46

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003     SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDEVPLATFORM_VCSJOB_H
0009 #define KDEVPLATFORM_VCSJOB_H
0010 
0011 #include <outputview/outputjob.h>
0012 
0013 #include "vcsexport.h"
0014 
0015 class QVariant;
0016 
0017 namespace KDevelop
0018 {
0019 
0020 class IPlugin;
0021 class VcsJobPrivate;
0022 
0023 /**
0024  * This class provides an extension of KJob to get various VCS-specific
0025  * information about the job. This includes the type, the state
0026  * and the results provided by the job.
0027  *
0028  */
0029 class KDEVPLATFORMVCS_EXPORT VcsJob : public OutputJob
0030 {
0031     Q_OBJECT
0032 public:
0033     explicit VcsJob( QObject* parent = nullptr, OutputJobVerbosity verbosity = OutputJob::Verbose);
0034     ~VcsJob() override;
0035     /**
0036      * To easily check which type of job this is.
0037      *
0038      * @todo Check how this can be extended via plugins, maybe use QFlag? (not
0039      * QFlags!)
0040      */
0041     enum JobType
0042     {
0043         Unknown = -1    /**< Unknown job type (default)*/,
0044         Add = 0         /**< An add job */,
0045         Remove = 1      /**< A remove job */,
0046         Copy = 2        /**< A copy job */,
0047         Move = 3        /**< A move job */,
0048         Diff = 4        /**< A diff job */,
0049         Commit = 5      /**< A commit job */,
0050         Update = 6      /**< An update job */,
0051         Merge = 7       /**< A merge job */,
0052         Resolve = 8     /**< A resolve job */,
0053         Import = 9      /**< An import job */,
0054         Checkout = 10   /**< A checkout job */,
0055         Log = 11        /**< A log job */,
0056         Push = 12       /**< A push job */,
0057         Pull = 13       /**< A pull job */,
0058         Annotate = 14   /**< An annotate job */,
0059         Clone = 15      /**< A clone job */,
0060         Status = 16     /**< A status job */,
0061         Revert = 17     /**< A revert job */,
0062         Cat = 18        /**< A cat job */,
0063         Reset = 19      /**< A reset job */,
0064         Apply = 20      /**< An apply job */,
0065         UserType = 1000 /**< A custom job */
0066     };
0067 
0068     /**
0069      * Simple enum to define how the job finished.
0070      */
0071     enum JobStatus
0072     {
0073         JobRunning = 0    /**< The job is running */,
0074         JobSucceeded = 1  /**< The job succeeded */,
0075         JobCanceled = 2   /**< The job was cancelled */,
0076         JobFailed = 3     /**< The job failed */,
0077         JobNotStarted = 4 /**< The job is not yet started */
0078     };
0079 
0080     /**
0081      * This method will return all new results of the job. The actual data
0082      * type that is wrapped in the QVariant depends on the type of job.
0083      *
0084      * @note Results returned by a previous call to fetchResults are not
0085      * returned.
0086      */
0087     virtual QVariant fetchResults() = 0;
0088 
0089     /**
0090      * Find out in which state the job is. It can be running, canceled,
0091      * failed or finished
0092      *
0093      * @return the status of the job
0094      * @see JobStatus
0095      */
0096     virtual JobStatus status() const = 0;
0097 
0098     /**
0099      * Used to find out about the type of job.
0100      *
0101      * @return the type of job
0102      */
0103     JobType type() const;
0104 
0105     /**
0106      * Used to get at the version control plugin. The plugin
0107      * can be used to get one of the interfaces to execute
0108      * more vcs actions, depending on this job's results
0109      * (like getting a diff for an entry in a log)
0110      */
0111     virtual KDevelop::IPlugin* vcsPlugin() const = 0;
0112 
0113     /**
0114      * This can be used to set the type of the vcs job in subclasses.
0115      */
0116     void setType( JobType );
0117 
0118 Q_SIGNALS:
0119     /**
0120      * This signal is emitted when new results are available. Depending on
0121      * the plugin and the operation, it may be emitted only once when all
0122      * results are ready, or several times.
0123      */
0124     void resultsReady( KDevelop::VcsJob* );
0125 
0126 private Q_SLOTS:
0127     void delayedModelInitialize();
0128 
0129 private:
0130     const QScopedPointer<class VcsJobPrivate> d_ptr;
0131     Q_DECLARE_PRIVATE(VcsJob)
0132 };
0133 
0134 }
0135 
0136 #endif
0137