File indexing completed on 2024-04-28 05:43:55

0001 /*
0002     SPDX-FileCopyrightText: 2001-2003 John Firebaugh <jfirebaugh@kde.org>
0003     SPDX-FileCopyrightText: 2001-2005,2009 Otto Bruggeman <bruggie@gmail.com>
0004     SPDX-FileCopyrightText: 2007-2008 Kevin Kofler <kevin.kofler@chello.at>
0005     SPDX-FileCopyrightText: 2012 Jean -Nicolas Artaud <jeannicolasartaud@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef KOMPAREDIFF2_MODELLIST_H
0011 #define KOMPAREDIFF2_MODELLIST_H
0012 
0013 // lib
0014 #include "diffmodel.h"
0015 #include "diffmodellist.h"
0016 #include "info.h"
0017 #include "komparediff2_export.h"
0018 // Qt
0019 #include <QObject>
0020 // Std
0021 #include <memory>
0022 
0023 class KActionCollection;
0024 
0025 namespace KompareDiff2
0026 {
0027 class DiffSettings;
0028 class ModelListPrivate;
0029 
0030 /**
0031  * @class ModelList modellist.h <KompareDiff2/ModelList>
0032  *
0033  * ModelList
0034  */
0035 class KOMPAREDIFF2_EXPORT ModelList : public QObject
0036 {
0037     Q_OBJECT
0038 public:
0039     ModelList(DiffSettings *diffSettings, QObject *parent, bool supportReadWrite = true);
0040     ~ModelList() override;
0041 
0042 public:
0043     void refresh();
0044     // Swap source with destination and show differences
0045     void swap();
0046 
0047     /* Comparing methods */
0048     bool compare();
0049 
0050     bool compare(Mode);
0051 
0052     bool openDiff(const QString &diff);
0053 
0054     bool openFileAndDiff();
0055     bool openDirAndDiff();
0056 
0057     bool saveDiff(const QString &url, const QString &directory, DiffSettings *diffSettings);
0058     bool saveAll();
0059 
0060     bool saveDestination(DiffModel *model);
0061 
0062     void setEncoding(const QString &encoding);
0063 
0064     void setReadWrite(bool isReadWrite);
0065     bool isReadWrite() const;
0066 
0067     QString recreateDiff() const;
0068 
0069     // This parses the difflines and creates new models
0070     int parseDiffOutput(const QString &diff);
0071 
0072     // This open the difflines after parsing them
0073     bool parseAndOpenDiff(const QString &diff);
0074 
0075     // Call this to emit the signals to the rest of the "world" to show the diff
0076     void show();
0077 
0078     // This will blend the original URL (dir or file) into the diffmodel,
0079     // this is like patching but with a twist
0080     bool blendOriginalIntoModelList(const QString &localURL);
0081 
0082     // This mode() method is superfluous now so FIXME
0083     Mode mode() const;
0084     const DiffModelList *models() const;
0085 
0086     KActionCollection *actionCollection() const;
0087     int modelCount() const;
0088     int differenceCount() const;
0089     int appliedCount() const;
0090 
0091     const DiffModel *modelAt(int i) const;
0092     DiffModel *modelAt(int i);
0093     int findModel(DiffModel *model) const;
0094 
0095     bool hasUnsavedChanges() const;
0096 
0097     int currentModel() const;
0098     int currentDifference() const;
0099 
0100     const DiffModel *selectedModel() const;
0101     const Difference *selectedDifference() const;
0102 
0103     void clear();
0104 
0105 Q_SIGNALS:
0106     void status(KompareDiff2::Status status);
0107     void setStatusBarModelInfo(int modelIndex, int differenceIndex, int modelCount, int differenceCount, int appliedCount);
0108     void error(const QString &error);
0109     void modelsChanged(const KompareDiff2::DiffModelList *models);
0110     void setSelection(const KompareDiff2::DiffModel *model, const KompareDiff2::Difference *diff);
0111     void setSelection(const KompareDiff2::Difference *diff);
0112     void applyDifference(bool apply);
0113     void applyAllDifferences(bool apply);
0114     void applyDifference(const KompareDiff2::Difference *diff, bool apply);
0115     void diffString(const QString &);
0116     void updateActions();
0117 
0118 public Q_SLOTS:
0119     void slotSelectionChanged(const KompareDiff2::DiffModel *model, const KompareDiff2::Difference *diff);
0120     void slotSelectionChanged(const KompareDiff2::Difference *diff);
0121 
0122     void slotApplyDifference(bool apply);
0123     void slotApplyAllDifferences(bool apply);
0124     void slotPreviousModel();
0125     void slotNextModel();
0126     void slotPreviousDifference();
0127     void slotNextDifference();
0128 
0129     void slotKompareInfo(KompareDiff2::Info *);
0130 
0131 protected Q_SLOTS:
0132     void slotDiffProcessFinished(bool success);
0133     void slotWriteDiffOutput(bool success);
0134 
0135     void slotActionApplyDifference();
0136     void slotActionUnApplyDifference();
0137     void slotActionApplyAllDifferences();
0138     void slotActionUnapplyAllDifferences();
0139 
0140     /** Save the currently selected destination in a multi-file diff,
0141         or the single destination if a single file diff. */
0142     void slotSaveDestination();
0143 
0144 private:
0145     Q_DECLARE_PRIVATE(ModelList)
0146     std::unique_ptr<ModelListPrivate> const d_ptr;
0147 };
0148 
0149 } // End of namespace KompareDiff2
0150 
0151 #endif