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