cleanup code and fix pesky 'no such signal QObject::patchChanged
[kdevelop:kdevplatform.git] / plugins / patchreview / patchreview.h
1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
4
5 /***************************************************************************
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  ***************************************************************************/
13
14 #ifndef PATCHREVIEW_H
15 #define PATCHREVIEW_H
16
17 #include <QObject>
18 #include <QPointer>
19 #include <memory>
20 #include <qstandarditemmodel.h>
21 #include <interfaces/iplugin.h>
22 #include "localpatchsource.h"
23 #include "ui_patchreview.h"
24 #include <language/duchain/indexedstring.h>
25 #include <ktexteditor/movingrangefeedback.h>
26 #include "libdiff2/diffmodel.h"
27
28 class PatchReviewToolViewFactory;
29 class PatchReviewPlugin;
30
31 namespace KParts {
32 class Part;
33 }
34
35 class QDialog;
36
37 namespace Diff2 {
38 class KompareModelList;
39 class DiffModel;
40 class DiffModel;
41 }
42 namespace KTextEditor {
43 class Document;
44 class Range;
45 class MovingRange;
46 class Mark;
47 }
48 namespace Kompare {
49 class Info;
50 }
51 namespace KDevelop {
52 class IDocument;
53 }
54
55 ///Delete itself when the document(or textDocument), or Diff-Model is deleted.
56 class PatchHighlighter : public QObject {
57     Q_OBJECT
58 public:
59     PatchHighlighter( const Diff2::DiffModel* model, KDevelop::IDocument* doc, PatchReviewPlugin* plugin ) throw( QString );
60     ~PatchHighlighter();
61     KDevelop::IDocument* doc();
62     QList<KTextEditor::MovingRange*> ranges() const {
63       return m_differencesForRanges.keys();
64     }
65 private slots:
66     void documentDestroyed();
67     void aboutToDeleteMovingInterfaceContent(KTextEditor::Document*);
68 private:
69
70     void addLineMarker(KTextEditor::MovingRange* arg1, Diff2::Difference* arg2);
71     void removeLineMarker(KTextEditor::MovingRange* arg1, Diff2::Difference* arg2);
72   
73     KTextEditor::MovingRange* rangeForMark(KTextEditor::Mark mark);
74
75     void clear();
76     QSet<KTextEditor::MovingRange*> m_ranges;
77     QMap<KTextEditor::MovingRange*, Diff2::Difference*> m_differencesForRanges;
78     KDevelop::IDocument* m_doc;
79     PatchReviewPlugin* m_plugin;
80     const Diff2::DiffModel* m_model;
81 public slots:
82     void markToolTipRequested(KTextEditor::Document*,KTextEditor::Mark,QPoint,bool&);
83     void showToolTipForMark(QPoint arg1, KTextEditor::MovingRange* arg2, QPair< int, int > highlightMark = qMakePair(-1, -1));
84     bool isRemoval(Diff2::Difference*);
85     bool isInsertion(Diff2::Difference*);
86     void markClicked(KTextEditor::Document*,KTextEditor::Mark,bool&);
87     void textInserted(KTextEditor::Document*,KTextEditor::Range);
88 };
89
90 class DiffSettings;
91 class PatchReviewPlugin;
92
93 class PatchReviewToolView : public QWidget {
94     Q_OBJECT
95 public:
96     PatchReviewToolView( QWidget* parent, PatchReviewPlugin* plugin );
97     ~PatchReviewToolView();
98
99 signals:
100     void dialogClosed( PatchReviewToolView* );
101     void  stateChanged( PatchReviewToolView* );
102 private slots:
103
104     void fileDoubleClicked( const QModelIndex& i );
105
106     void nextHunk();
107     void prevHunk();
108
109     void patchChanged();
110
111     void updatePatchFromEdit();
112
113     void slotEditCommandChanged();
114
115     void slotEditFileNameChanged();
116
117     void finishReview();
118     
119 private:
120     void kompareModelChanged();
121
122     void showEditDialog();
123     ///Fills the editor views from m_editingPatch
124     void fillEditFromPatch();
125
126     Ui_EditPatch m_editPatch;
127
128     QTime m_lastDataTime;
129     QString m_lastTerminalData;
130
131     QPointer<KParts::Part> m_konsolePart;
132
133     bool m_reversed;
134
135     KUrl urlForFileModel(const Diff2::DiffModel* model);
136     
137     PatchReviewPlugin* m_plugin;
138     
139     QPointer<QWidget> m_customWidget;
140 public slots:
141     void documentActivated(KDevelop::IDocument*);
142     void patchSelectionChanged(int);
143 };
144
145 class PatchReviewPlugin : public KDevelop::IPlugin, public KDevelop::IPatchReview {
146     Q_OBJECT
147     Q_INTERFACES( KDevelop::IPatchReview )
148     
149 public:
150     PatchReviewPlugin(QObject *parent, const QVariantList & = QVariantList() );
151     ~PatchReviewPlugin();
152     virtual void unload();
153
154     QWidget* createToolView(QWidget* parent);
155
156     KDevelop::IPatchSource::Ptr patch() const {
157         return m_patch;
158     }
159
160     QList<KDevelop::IPatchSource::Ptr> knownPatches() const {
161       return m_knownPatches;
162     }
163
164     Diff2::KompareModelList* modelList() const {
165         return m_modelList.get();
166     }
167
168     void seekHunk( bool forwards, const KUrl& file = KUrl() );
169
170     KUrl diffFile();
171     
172     void setPatch(KDevelop::IPatchSource* patch);
173
174     void registerPatch(KDevelop::IPatchSource::Ptr patch);
175     
176     virtual void startReview(KDevelop::IPatchSource* patch, ReviewMode mode);
177     
178     void finishReview(QList<KUrl> selection);
179     
180 Q_SIGNALS:
181     void patchChanged();
182
183 public Q_SLOTS:
184     //Does parts of the review-starting that are problematic to do directly in startReview, as they may open dialogs etc.
185     void updateReview();
186     
187     void cancelReview();
188     void clearPatch(QObject* patch);
189     void notifyPatchChanged();
190     void highlightPatch();
191     void updateKompareModel();
192     void showPatch();
193     void forceUpdate();
194
195 private Q_SLOTS:
196     void documentClosed(KDevelop::IDocument*);
197     void textDocumentCreated(KDevelop::IDocument*);
198     void exporterSelected(QAction* action);
199     
200 private:
201   
202     QList<KDevelop::IPatchSource::Ptr> m_knownPatches;
203
204     void addHighlighting( const KUrl& file, KDevelop::IDocument* document = 0 );
205     void removeHighlighting( const KUrl& file = KUrl() );
206
207     KDevelop::IPatchSource::Ptr m_patch;
208
209     QTimer* m_updateKompareTimer;
210
211     PatchReviewToolViewFactory* m_factory;
212
213     #if 0
214     void determineState();
215     #endif
216
217     QPointer<DiffSettings> m_diffSettings;
218     std::auto_ptr<Kompare::Info> m_kompareInfo;
219     std::auto_ptr<Diff2::KompareModelList> m_modelList;
220     typedef QMap<KUrl, QPointer<PatchHighlighter> > HighlightMap;
221     HighlightMap m_highlighters;
222 };
223
224 #endif
225
226 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on