File indexing completed on 2024-05-12 09:48:31
0001 /* 0002 SPDX-FileCopyrightText: 2001-2005, 2009 Otto Bruggeman <bruggie@gmail.com> 0003 SPDX-FileCopyrightText: 2001-2003 John Firebaugh <jfirebaugh@kde.org> 0004 SPDX-FileCopyrightText: 2004 Jeff Snyder <jeff@caffeinated.me.uk> 0005 SPDX-FileCopyrightText: 2007-2011 Kevin Kofler <kevin.kofler@chello.at> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef KOMPAREPART_H 0011 #define KOMPAREPART_H 0012 0013 #include <komparepartdebug.h> 0014 #include "kompareinterface.h" 0015 // Komparediff2 0016 #include <KompareDiff2/Kompare> 0017 // KF 0018 #include <kparts_version.h> 0019 #include <KParts/ReadWritePart> 0020 // Qt 0021 #include <QVariantList> 0022 0023 class QAction; 0024 class QPrinter; 0025 class QUrl; 0026 class QWidget; 0027 0028 class KPluginMetaData; 0029 0030 namespace Diff2 { 0031 class Difference; 0032 class DiffModel; 0033 class DiffModelList; 0034 class KompareModelList; 0035 } 0036 class DiffSettings; 0037 class ViewSettings; 0038 class KompareSplitter; 0039 class KompareView; 0040 0041 /** 0042 * This is a "Part". It does all the real work in a KPart 0043 * application. 0044 * 0045 * @short Main Part 0046 * @author John Firebaugh <jfirebaugh@kde.org> 0047 * @author Otto Bruggeman <bruggie@home.nl> 0048 * @version 0.3 0049 */ 0050 class KomparePart : public KParts::ReadWritePart, 0051 public KompareInterface 0052 { 0053 Q_OBJECT 0054 Q_INTERFACES(KompareInterface) 0055 public: 0056 enum Modus { 0057 ReadOnlyModus = 0, 0058 ReadWriteModus = 1 0059 }; 0060 0061 /** 0062 * Default constructor 0063 */ 0064 KomparePart(QWidget* parentWidget, QObject* parent, const KPluginMetaData& metaData, Modus modus); 0065 0066 /** 0067 * Destructor 0068 */ 0069 ~KomparePart() override; 0070 0071 // Sessionmanagement stuff, added to the kompare iface 0072 // because they are not in the Part class where they belong 0073 // Should be added when bic changes are allowed again (kde 4.0) 0074 int readProperties(KConfig* config) override; 0075 int saveProperties(KConfig* config) override; 0076 // this one is called when the shell_app is about to close. 0077 // we need it now to save the properties of the part when apps don't (can't) 0078 // use the readProperties and saveProperties methods 0079 bool queryClose() override; 0080 void setReadWrite(bool readWrite) override; 0081 0082 // Do we really want to expose this ??? 0083 const Diff2::KompareModelList* model() const { return m_modelList; }; 0084 0085 public: 0086 // Reimplemented from the KompareInterface 0087 /** 0088 * Open and parse the diff file at diffUrl. 0089 */ 0090 bool openDiff(const QUrl& diffUrl) override; 0091 0092 /** Added on request of Harald Fernengel */ 0093 bool openDiff(const QString& diffOutput) override; 0094 0095 /** Open and parse the diff3 file at diff3Url */ 0096 bool openDiff3(const QUrl& diff3URL) override; 0097 0098 /** Open and parse the file diff3Output with the output of diff3 */ 0099 bool openDiff3(const QString& diff3Output) override; 0100 0101 /** Compare, with diff, source with destination */ 0102 void compare(const QUrl& sourceFile, const QUrl& destinationFile) override; 0103 0104 /** Compare a Source file to a custom Destination string */ 0105 void compareFileString(const QUrl& sourceFile, const QString& destination) override; 0106 0107 /** Compare a custom Source string to a Destination file */ 0108 void compareStringFile(const QString& source, const QUrl& destinationFile) override; 0109 0110 /** Compare, with diff, source with destination */ 0111 void compareFiles(const QUrl& sourceFile, const QUrl& destinationFile) override; 0112 0113 /** Compare, with diff, source with destination */ 0114 void compareDirs(const QUrl& sourceDir, const QUrl& destinationDir) override; 0115 0116 /** Compare, with diff3, originalFile with changedFile1 and changedFile2 */ 0117 void compare3Files(const QUrl& originalFile, const QUrl& changedFile1, const QUrl& changedFile2) override; 0118 0119 /** This will show the file and the file with the diff applied */ 0120 void openFileAndDiff(const QUrl& file, const QUrl& diffFile) override; 0121 0122 /** This will show the directory and the directory with the diff applied */ 0123 void openDirAndDiff(const QUrl& dir, const QUrl& diffFile) override; 0124 0125 /** Reimplementing this because this one knows more about the real part then the interface */ 0126 void setEncoding(const QString& encoding) override; 0127 0128 // This is the interpart interface, it is signal and slot based so no "real" interface here 0129 // All you have to do is connect the parts from your application. 0130 // These just point to their counterpart in the KompareModelList or get called from their 0131 // counterpart in KompareModelList. 0132 Q_SIGNALS: 0133 void modelsChanged(const Diff2::DiffModelList* models); 0134 0135 void setSelection(const Diff2::DiffModel* model, const Diff2::Difference* diff); 0136 void setSelection(const Diff2::Difference* diff); 0137 0138 void selectionChanged(const Diff2::DiffModel* model, const Diff2::Difference* diff); 0139 void selectionChanged(const Diff2::Difference* diff); 0140 0141 void applyDifference(bool apply); 0142 void applyAllDifferences(bool apply); 0143 void applyDifference(const Diff2::Difference*, bool apply); 0144 0145 void configChanged(); 0146 0147 /* 0148 ** This is emitted when a difference is clicked in the kompare view. You can connect to 0149 ** it so you can use it to jump to this particular line in the editor in your app. 0150 */ 0151 void differenceClicked(int lineNumber); 0152 0153 // Stuff that can probably be removed by putting it in the part where it belongs in my opinion 0154 public Q_SLOTS: 0155 /** Save all destinations. */ 0156 bool saveAll(); 0157 0158 /** Save the results of a comparison as a diff file. */ 0159 void saveDiff(); 0160 0161 /** To enable printing, the part has the only interesting printable content so putting it here */ 0162 void slotFilePrint(); 0163 void slotFilePrintPreview(); 0164 0165 Q_SIGNALS: 0166 void appliedChanged(); 0167 void diffURLChanged(); 0168 void kompareInfo(Kompare::Info* info); 0169 void setStatusBarModelInfo(int modelIndex, int differenceIndex, int modelCount, int differenceCount, int appliedCount); 0170 // void setStatusBarText( const QString& text ); 0171 void diffString(const QString&); 0172 0173 protected: 0174 /** 0175 * This is the method that gets called when the file is opened, 0176 * when using openURL( const QUrl& ) or in our case also openDiff( const QUrl& ); 0177 * return true when everything went ok, false if there were problems 0178 */ 0179 bool openFile() override; 0180 // ... Uhm we return true without saving ??? 0181 bool saveFile() override { return true; }; 0182 0183 protected Q_SLOTS: 0184 void slotSetStatus(Kompare::Status status); 0185 void slotShowError(const QString& error); 0186 0187 void slotSwap(); 0188 void slotShowDiffstats(); 0189 void slotRefreshDiff(); 0190 void optionsPreferences(); 0191 0192 void updateActions(); 0193 void updateCaption(); 0194 void updateStatus(); 0195 void compareAndUpdateAll(); 0196 0197 void slotPaintRequested(QPrinter*); 0198 0199 private: 0200 void cleanUpTemporaryFiles(); 0201 void setupActions(Modus modus); 0202 bool isDirectory(const QUrl& url); 0203 // FIXME (like in cpp file not urgent) Replace with enum, cant find a proper 0204 // name now but it is private anyway so can not be used from outside 0205 bool fetchURL(const QUrl& url, bool isSource); 0206 0207 private Q_SLOTS: 0208 void onContextMenuRequested(const QPoint& pos); 0209 0210 private: 0211 // Uhm why were these static again ??? 0212 // Ah yes, so multiple instances of kompare use the 0213 // same settings after one of them changes them 0214 static ViewSettings* m_viewSettings; 0215 static DiffSettings* m_diffSettings; 0216 0217 Diff2::KompareModelList* m_modelList; 0218 0219 KompareView* m_view; 0220 KompareSplitter* m_splitter; 0221 0222 QAction* m_saveAll; 0223 QAction* m_saveDiff; 0224 QAction* m_swap; 0225 QAction* m_diffStats; 0226 QAction* m_diffRefresh; 0227 QAction* m_print; 0228 QAction* m_printPreview; 0229 0230 struct Kompare::Info m_info; 0231 }; 0232 0233 #endif // KOMPAREPART_H