File indexing completed on 2024-11-17 05:10:23

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_P_H
0011 #define KOMPAREDIFF2_MODELLIST_P_H
0012 
0013 // lib
0014 #include "diffmodellist.h"
0015 #include "kompareprocess.h"
0016 // Qt
0017 #include <QFileInfo>
0018 #include <QTemporaryFile>
0019 #include <QUrl>
0020 // Std
0021 #include <memory>
0022 
0023 class KActionCollection;
0024 class QAction;
0025 class QTextCodec;
0026 
0027 namespace KompareDiff2
0028 {
0029 class DiffSettings;
0030 class DiffModelList;
0031 class DiffModel;
0032 class Difference;
0033 class Info;
0034 
0035 class ModelListPrivate
0036 {
0037 public:
0038     ModelListPrivate(DiffSettings *diffSettings, bool supportReadWrite);
0039     ~ModelListPrivate() = default;
0040 
0041 public: // Helper methods
0042     static bool isDirectory(const QString &url);
0043     static bool isDiff(const QString &mimetype);
0044 
0045     static QStringList split(const QString &diff);
0046 
0047     QString readFile(const QString &fileName);
0048 
0049     bool hasPrevModel() const;
0050     bool hasNextModel() const;
0051     bool hasPrevDiff() const;
0052     bool hasNextDiff() const;
0053 
0054     void setDepthAndApplied();
0055 
0056     DiffModel *firstModel();
0057     DiffModel *lastModel();
0058     DiffModel *prevModel();
0059     DiffModel *nextModel();
0060 
0061     bool setSelectedModel(DiffModel *model);
0062 
0063     void updateModelListActions();
0064 
0065     bool blendFile(DiffModel *model, const QString &lines);
0066 
0067 public:
0068     std::unique_ptr<QTemporaryFile> diffTemp;
0069     QUrl diffURL;
0070 
0071     std::unique_ptr<KompareProcess> diffProcess;
0072 
0073     DiffSettings *diffSettings;
0074 
0075     std::unique_ptr<DiffModelList> models;
0076 
0077     DiffModel *selectedModel = nullptr;
0078     Difference *selectedDifference = nullptr;
0079 
0080     int modelIndex = 0;
0081 
0082     Info *info = nullptr;
0083 
0084     KActionCollection *actionCollection;
0085     QAction *applyDifference;
0086     QAction *unApplyDifference;
0087     QAction *applyAll;
0088     QAction *unapplyAll;
0089     QAction *previousFile;
0090     QAction *nextFile;
0091     QAction *previousDifference;
0092     QAction *nextDifference;
0093 
0094     QAction *save;
0095 
0096     QString encoding;
0097     QTextCodec *textCodec = nullptr;
0098 
0099     bool isReadWrite;
0100 };
0101 
0102 inline ModelListPrivate::ModelListPrivate(DiffSettings *diffSettings, bool supportReadWrite)
0103     : diffSettings(diffSettings)
0104     , isReadWrite(supportReadWrite)
0105 {
0106 }
0107 
0108 inline bool ModelListPrivate::isDirectory(const QString &url)
0109 {
0110     QFileInfo fi(url);
0111     return fi.isDir();
0112 }
0113 
0114 inline bool ModelListPrivate::isDiff(const QString &mimeType)
0115 {
0116     return (mimeType == QLatin1String("text/x-patch"));
0117 }
0118 
0119 }
0120 
0121 #endif