Don't keep compiling/run if something failed.
[kdevelopdvcssupport.git] / plugins / teamwork / documentwrapper.h
blob6a4353364e74004dee72df4ee552dc8c84fc51c1
1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
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 ***************************************************************************/
14 #ifndef DOCUMENT_WRAPPER_H
15 #define DOCUMENT_WRAPPER_H
17 #include <QObject>
18 #include <QFile>
20 #include <KParts/MainWindow>
21 #include <map>
22 #include <string>
24 #include "lib/dynamictext/vectortimestamp.h"
25 #include "lib/dynamictext/flexibletextnotifier.h"
26 #include "lib/network/safesharedptr.h"
27 #include "lib/network/weaksafesharedptr.h"
28 #include "safelogger.h"
30 #include <autoconstructpointer.h>
31 #include "filesynchronizemessage.h"
33 namespace Teamwork {
34 class Logger;
35 typedef SafeSharedPtr<Logger> LoggerPointer;
38 namespace KTextEditor {
39 class Document;
40 class Range;
43 class FileSynchronize;
44 class DynamicText;
45 class QStandardItemModel;
46 class QModelIndex;
47 class QMenu;
48 class QVariant;
49 class DocumentWrapperTreeAction;
50 namespace KDevelop {
51 class IDocument;
53 class DocumentWrapperMessage;
54 class QDynamicText;
55 class FileCollaborationSession;
56 class LocalPatchSource;
57 class K3Process;
59 using namespace Teamwork;
61 typedef SafeSharedPtr<LocalPatchSource> LocalPatchSourcePointer;
62 typedef SharedPtr<QDynamicText, BoostSerializationNormal> QDynamicTextPointer;
64 class OutputFileWriter : public QObject {
65 Q_OBJECT
66 public:
67 OutputFileWriter( const QString& file );
68 bool failed() const;
69 public slots:
70 void receivedStdout(K3Process *proc, char *buffer, int buflen);
71 private:
72 QFile m_file;
73 bool m_failed;
76 ///A class that cares about the state of a document and it's history
77 class DocumentWrapper : public QObject, public SafeLogger, public Shared, public SumTree::FlexibleTextNotifier<std::string> {
78 Q_OBJECT
79 public:
80 ///If readFile is true, the file is read from disk. Else we wait for the file from the other side. May throw QString on error.
81 BIND_LIST_3( Messages, FileEditMessage, FileEditRejectMessage, FileSynchronize )
83 DocumentWrapper( uint id, const LoggerPointer& logger, QString fileName, uint ownIndex, bool readFile, FileCollaborationSession* session, bool fromBuffer );
85 QString fileName() const;
87 KDevelop::IDocument* document();
89 void updateTree( QModelIndex& i, QStandardItemModel* model );
91 void fillContextMenu( int var, QMenu* menu );
93 bool hadError() const;
95 QString text() const;
97 VectorTimestamp state() const;
99 const QDynamicText& dynamicText() const;
101 ///Returns an id that is unique within the wrapper's parent-session, and is equal on all collaborating peers.
102 uint id() const;
104 void processMessage( DocumentWrapperMessage* msg );
106 ///If the document-wrapper is dead, that means the it is not part of the session anymore
107 void setDead( bool dead );
109 bool dead() const;
110 ///This can be usedto completely disable the file(no editing is allowed anymore)
111 void setDisabled( bool disabled );
113 bool disabled() const;
115 QIcon icon() const;
117 bool synchronize( const UserPointer& user );
119 signals:
120 void publishEdit( const VectorTimestamp& state, const SimpleReplacement& replacement, DocumentWrapper* sender );
122 public slots:
123 void saveAsBufferFile();
124 LocalPatchSourcePointer saveAsPatch( bool addToList = true, bool edit = true );
126 private slots:
127 void remove();
128 void toggleEnabled();
129 void saveNewBuffer();
130 void manageDynamicText();
132 void stateChanged();
133 void documentDestroyed();
134 void textChanged ( KTextEditor::Document * document,
135 const KTextEditor::Range & oldRange,
136 const KTextEditor::Range & newRange );
137 void textRemoved ( KTextEditor::Document * document,
138 const KTextEditor::Range & range );
139 void textInserted ( KTextEditor::Document * document,
140 const KTextEditor::Range & range );
141 private:
142 ///Notifications from FlexibleText
143 virtual void notifyFlexibleTextErase( int position, int length );
144 virtual void notifyFlexibleTextInsert( int position, const std::string& text );
145 virtual void notifyFlexibleTextReplace( int position, int length, const std::string& replacement );
148 int receiveMessage( FileEditMessage* msg );
149 int receiveMessage( FileSynchronize* msg );
150 int receiveMessage( FileEditRejectMessage* msg );
151 int receiveMessage( MessageInterface* msg );
153 bool checkDocumentSync() const; ///Expensive, only for debugging
155 void fillDocumentText();
156 void openDocument( bool toForeground = false );
158 ///If fromBuffer is true, it is tried to get the content from an already open buffer (@todo)
159 void readFile( bool fromBuffer ) throw ( QString );
161 virtual std::string logPrefix();
163 QDynamicTextPointer m_text;
165 bool m_block;
167 bool m_realFile;
168 QString m_fileName; ///Relative path of the file(from project-dir)
169 KDevelop::IDocument* m_document;
170 WeakSharedPtr<FileCollaborationSession> m_session;
171 uint m_ownIndex;
172 uint m_id;
173 bool m_hadError, m_disabled, m_dead;
175 QString m_tempFile;
177 friend class DocumentWrapperTreeAction;
179 friend class MessageDispatcher< DocumentWrapper, Messages > ;
180 MessageDispatcher< DocumentWrapper, Messages > m_dispatcher;
183 typedef SharedPtr<DocumentWrapper> DocumentWrapperPointer;
185 #endif
187 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on