File indexing completed on 2024-05-12 04:38:56
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 /** 0008 * This is an internal header 0009 */ 0010 0011 #ifndef KDEVPLATFORM_VCSDIFFPATCHSOURCES_H 0012 #define KDEVPLATFORM_VCSDIFFPATCHSOURCES_H 0013 0014 #include <interfaces/ipatchsource.h> 0015 #include "vcs/vcsstatusinfo.h" 0016 0017 #include <vcs/vcsexport.h> 0018 0019 #include <QMap> 0020 #include <QUrl> 0021 0022 class KTextEdit; 0023 class KComboBox; 0024 class KJob; 0025 namespace KDevelop { 0026 class VcsCommitDialog; 0027 class IBasicVersionControl; 0028 class VcsDiff; 0029 } 0030 0031 class QWidget; 0032 0033 class VCSDiffUpdater { 0034 public: 0035 virtual ~VCSDiffUpdater(); 0036 virtual KDevelop::VcsDiff update() const = 0; 0037 virtual KDevelop::IBasicVersionControl* vcs() const = 0; 0038 virtual QUrl url() const = 0; 0039 }; 0040 0041 class KDEVPLATFORMVCS_EXPORT VCSStandardDiffUpdater : public VCSDiffUpdater { 0042 public: 0043 VCSStandardDiffUpdater(KDevelop::IBasicVersionControl* vcs, const QUrl& url); 0044 ~VCSStandardDiffUpdater() override; 0045 KDevelop::VcsDiff update() const override; 0046 KDevelop::IBasicVersionControl* vcs() const override { return m_vcs; } 0047 QUrl url() const override { return m_url; } 0048 private: 0049 KDevelop::IBasicVersionControl* m_vcs; 0050 QUrl m_url; 0051 }; 0052 0053 0054 class KDEVPLATFORMVCS_EXPORT VCSDiffPatchSource : public KDevelop::IPatchSource { 0055 Q_OBJECT 0056 public: 0057 /// The ownership of the updater is taken 0058 explicit VCSDiffPatchSource(VCSDiffUpdater* updater); 0059 explicit VCSDiffPatchSource(const KDevelop::VcsDiff& diff); 0060 ~VCSDiffPatchSource() override; 0061 0062 QUrl baseDir() const override ; 0063 0064 QUrl file() const override ; 0065 0066 QString name() const override ; 0067 0068 uint depth() const override ; 0069 0070 void update() override ; 0071 0072 bool isAlreadyApplied() const override { return true; } 0073 0074 QMap<QUrl, KDevelop::VcsStatusInfo::State> additionalSelectableFiles() const override ; 0075 0076 QUrl m_base, m_file; 0077 QString m_name; 0078 VCSDiffUpdater* m_updater; 0079 QList<KDevelop::VcsStatusInfo> m_infos; 0080 QMap<QUrl, KDevelop::VcsStatusInfo::State> m_selectable; 0081 private: 0082 void updateFromDiff(const KDevelop::VcsDiff& diff); 0083 uint m_depth = 0; 0084 }; 0085 0086 class KDEVPLATFORMVCS_EXPORT VCSCommitDiffPatchSource : public VCSDiffPatchSource { 0087 Q_OBJECT 0088 public: 0089 /// The ownership of the updater is taken 0090 explicit VCSCommitDiffPatchSource(VCSDiffUpdater* updater); 0091 ~VCSCommitDiffPatchSource() override ; 0092 0093 QStringList oldMessages() const; 0094 0095 bool canSelectFiles() const override ; 0096 0097 QWidget* customWidget() const override ; 0098 0099 QString finishReviewCustomText() const override ; 0100 0101 bool canCancel() const override; 0102 0103 void cancelReview() override; 0104 0105 bool finishReview(const QList<QUrl>& selection) override; 0106 QList<KDevelop::VcsStatusInfo> infos() const { return m_infos; } 0107 Q_SIGNALS: 0108 void reviewFinished(const QString& message, const QList<QUrl>& selection); 0109 void reviewCancelled(const QString& message); 0110 public: 0111 QPointer<QWidget> m_commitMessageWidget; 0112 QPointer<KTextEdit> m_commitMessageEdit; 0113 KDevelop::IBasicVersionControl* m_vcs; 0114 KComboBox* m_oldMessages; 0115 public Q_SLOTS: 0116 void addMessageToHistory(const QString& message); 0117 void oldMessageChanged(const QString&); 0118 void jobFinished(KJob*); 0119 }; 0120 0121 ///Sends the diff to the patch-review plugin. 0122 ///Returns whether the diff was shown successfully. 0123 bool KDEVPLATFORMVCS_EXPORT showVcsDiff(KDevelop::IPatchSource* vcsDiff); 0124 0125 #endif // KDEVPLATFORM_VCSDIFFPATCHSOURCES_H