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

0001 /*
0002     SPDX-FileCopyrightText: 2017 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_SOURCEFORMATTERJOB_H
0008 #define KDEVPLATFORM_SOURCEFORMATTERJOB_H
0009 
0010 #include <QList>
0011 #include <QUrl>
0012 
0013 #include <KJob>
0014 
0015 #include <interfaces/istatus.h>
0016 
0017 
0018 namespace KDevelop
0019 {
0020 class SourceFormatterController;
0021 
0022 
0023 class SourceFormatterJob : public KJob, public IStatus
0024 {
0025     Q_OBJECT
0026     Q_INTERFACES( KDevelop::IStatus )
0027 
0028 public:
0029     explicit SourceFormatterJob(SourceFormatterController* sourceFormatterController);
0030 
0031 public: // KJob API
0032     void start() override;
0033 
0034 public: // KDevelop::IStatus API
0035     QString statusName() const override;
0036 
0037 public:
0038     void setFiles(const QList<QUrl>& fileList);
0039 
0040 protected: // KJob API
0041     bool doKill() override;
0042 
0043 Q_SIGNALS: // KDevelop::IStatus API
0044     void clearMessage(KDevelop::IStatus* status) override;
0045     void showMessage(KDevelop::IStatus* status, const QString& message, int timeout = 0) override;
0046     void showErrorMessage(const QString& message, int timeout) override;
0047     void hideProgress(KDevelop::IStatus* status) override;
0048     void showProgress(KDevelop::IStatus* status, int minimum, int maximum, int value) override;
0049 
0050 private:
0051     Q_INVOKABLE void doWork();
0052 
0053     void formatFile(const QUrl& url);
0054 
0055 private:
0056     SourceFormatterController* const m_sourceFormatterController;
0057 
0058     enum {
0059         WorkIdle,
0060         WorkFormat,
0061         WorkCancelled
0062     } m_workState;
0063 
0064     QList<QUrl> m_fileList;
0065     int m_fileIndex;
0066 };
0067 
0068 }
0069 
0070 #endif