KompareDiff2

komparemodellist.h
1/*
2SPDX-FileCopyrightText: 2001-2003 John Firebaugh <jfirebaugh@kde.org>
3SPDX-FileCopyrightText: 2001-2005,2009 Otto Bruggeman <bruggie@gmail.com>
4SPDX-FileCopyrightText: 2007-2008 Kevin Kofler <kevin.kofler@chello.at>
5SPDX-FileCopyrightText: 2012 Jean -Nicolas Artaud <jeannicolasartaud@gmail.com>
6
7SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#ifndef KOMPAREDIFF2_KOMPAREMODELLIST_H
11#define KOMPAREDIFF2_KOMPAREMODELLIST_H
12
13#include <QObject>
14
15#include "diffmodel.h"
16#include "diffmodellist.h"
17#include "kompare.h"
18#include "komparediff2_export.h"
19
20class QAction;
21class QTemporaryFile;
22class QTextCodec;
24
25class DiffSettings;
26class KompareProcess;
27
28namespace Diff2
29{
30
31/**
32 * @class KompareModelList komparemodellist.h <KompareDiff2/KompareModelList>
33 *
34 * KompareModelList
35 */
36class KOMPAREDIFF2_EXPORT KompareModelList : public QObject
37{
38 Q_OBJECT
39public:
40#if KOMPAREDIFF2_ENABLE_DEPRECATED_SINCE(5, 4)
41 /// @deprecated Since 5.4, use the overload without widgetForKIO arg, widgetForKIO is unused
42 KOMPAREDIFF2_DEPRECATED_VERSION(5, 4, "Use KompareModelList constructor without widgetForKIO arg instead")
43 KompareModelList(DiffSettings* diffSettings, QWidget* widgetForKIO, QObject* parent, const char* name = nullptr, bool supportReadWrite = true);
44#endif
45 /// @since 5.4
46 KompareModelList(DiffSettings* diffSettings, QObject* parent, const char* name = nullptr, bool supportReadWrite = true);
47 ~KompareModelList() override;
48
49public:
50 void refresh();
51 // Swap source with destination and show differences
52 void swap();
53
54 /* Comparing methods */
55 bool compare();
56
57 bool compare(Kompare::Mode);
58
59 bool openDiff(const QString& diff);
60
61 bool openFileAndDiff();
62 bool openDirAndDiff();
63
64 bool saveDiff(const QString& url, QString directory, DiffSettings* diffSettings);
65 bool saveAll();
66
67 bool saveDestination(DiffModel* model);
68
69 void setEncoding(const QString& encoding);
70
71 void setReadWrite(bool isReadWrite);
72 bool isReadWrite() const;
73
74 QString recreateDiff() const;
75
76 // This parses the difflines and creates new models
77 int parseDiffOutput(const QString& diff);
78
79 // This open the difflines after parsing them
80 bool parseAndOpenDiff(const QString& diff);
81
82 // Call this to emit the signals to the rest of the "world" to show the diff
83 void show();
84
85 // This will blend the original URL (dir or file) into the diffmodel,
86 // this is like patching but with a twist
87 bool blendOriginalIntoModelList(const QString& localURL);
88
89 // This mode() method is superfluous now so FIXME
90 enum Kompare::Mode mode() const { return m_info->mode; };
91 const DiffModelList* models() const { return m_models; };
92
93 KActionCollection* actionCollection() const;
94 int modelCount() const;
95 int differenceCount() const;
96 int appliedCount() const;
97
98 const DiffModel* modelAt(int i) const { return m_models->at(i); };
99 DiffModel* modelAt(int i) { return m_models->at(i); };
100 int findModel(DiffModel* model) const { return m_models->indexOf(model); };
101
102 bool hasUnsavedChanges() const;
103
104 int currentModel() const { return m_models->indexOf(m_selectedModel); };
105 int currentDifference() const { return m_selectedModel ? m_selectedModel->findDifference(m_selectedDifference) : -1; };
106
107 const DiffModel* selectedModel() const { return m_selectedModel; };
108 const Difference* selectedDifference() const { return m_selectedDifference; };
109
110 void clear();
111
112private:
113 Diff2::DiffModel* firstModel();
114 Diff2::DiffModel* lastModel();
115 Diff2::DiffModel* prevModel();
116 Diff2::DiffModel* nextModel();
117
118 bool setSelectedModel(Diff2::DiffModel* model);
119
120 void updateModelListActions();
121
122protected:
123 bool blendFile(DiffModel* model, const QString& lines);
124
125Q_SIGNALS:
127 void setStatusBarModelInfo(int modelIndex, int differenceIndex, int modelCount, int differenceCount, int appliedCount);
128 void error(QString error);
129 void modelsChanged(const Diff2::DiffModelList* models);
130 void setSelection(const Diff2::DiffModel* model, const Diff2::Difference* diff);
131 void setSelection(const Diff2::Difference* diff);
132 void applyDifference(bool apply);
133 void applyAllDifferences(bool apply);
134 void applyDifference(const Diff2::Difference* diff, bool apply);
135 void diffString(const QString&);
136 void updateActions();
137
138public Q_SLOTS:
139 void slotSelectionChanged(const Diff2::DiffModel* model, const Diff2::Difference* diff);
140 void slotSelectionChanged(const Diff2::Difference* diff);
141
142 void slotApplyDifference(bool apply);
143 void slotApplyAllDifferences(bool apply);
144 void slotPreviousModel();
145 void slotNextModel();
146 void slotPreviousDifference();
147 void slotNextDifference();
148
149 void slotKompareInfo(struct Kompare::Info*);
150
151protected Q_SLOTS:
152 void slotDiffProcessFinished(bool success);
153 void slotWriteDiffOutput(bool success);
154
155 void slotActionApplyDifference();
156 void slotActionUnApplyDifference();
157 void slotActionApplyAllDifferences();
158 void slotActionUnapplyAllDifferences();
159
160 /** Save the currently selected destination in a multi-file diff,
161 or the single destination if a single file diff. */
162 void slotSaveDestination();
163
164private Q_SLOTS:
165 void slotDirectoryChanged(const QString&);
166 void slotFileChanged(const QString&);
167
168private: // Helper methods
169 bool isDirectory(const QString& url) const;
170 bool isDiff(const QString& mimetype) const;
171 QString readFile(const QString& fileName);
172
173 bool hasPrevModel() const;
174 bool hasNextModel() const;
175 bool hasPrevDiff() const;
176 bool hasNextDiff() const;
177
178 QStringList split(const QString& diff);
179 void setDepthAndApplied();
180
181private: // ### an exported class without a d pointer? Really? What about BC?
182 QTemporaryFile* m_diffTemp;
183 QUrl m_diffURL;
184
185 KompareProcess* m_diffProcess;
186
187 DiffSettings* m_diffSettings;
188
189 DiffModelList* m_models;
190
191 DiffModel* m_selectedModel;
192 Difference* m_selectedDifference;
193
194 int m_modelIndex;
195
196 struct Kompare::Info* m_info;
197
198 KActionCollection* m_actionCollection;
199 QAction* m_applyDifference;
200 QAction* m_unApplyDifference;
201 QAction* m_applyAll;
202 QAction* m_unapplyAll;
203 QAction* m_previousFile;
204 QAction* m_nextFile;
205 QAction* m_previousDifference;
206 QAction* m_nextDifference;
207
208 QAction* m_save;
209
210 QString m_encoding;
211 QTextCodec* m_textCodec;
212
213#if KOMPAREDIFF2_BUILD_DEPRECATED_SINCE(5, 4)
214 QT_WARNING_PUSH
215 QT_WARNING_DISABLE_CLANG("-Wunused-private-field")
216 // Unused, kept for ABI compatibility
217 QWidget* m_widgetForKIO;
218 QT_WARNING_POP
219 #endif
220
221 bool m_isReadWrite;
222};
223
224} // End of namespace Diff2
225
226#endif
A list of DiffModel.
A model describing the differences between two files.
Definition diffmodel.h:26
A difference.
Definition difference.h:124
The settings for a diff.
Q_SCRIPTABLE CaptureState status()
Diff2 namespace.
Status
State.
Definition kompare.h:79
Mode
Mode.
Definition kompare.h:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:10:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.