Don't keep compiling/run if something failed.
[kdevelopdvcssupport.git] / plugins / teamwork / conversationmanager.h
bloba75d251f8b24f1f5abb6b77a2ad887aab3a5744f
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 CONVERSATIONMANAGER_H
15 #define CONVERSATIONMANAGER_H
17 #include <QObject>
18 #include <QtCore/QPointer>
19 #include <QTime>
20 #include <ktexteditor/document.h>
21 #include <ktexteditor/smartcursor.h>
22 #include <ktexteditor/smartinterface.h>
23 #include "teamworkfwd.h"
24 #include "indocumentreference.h"
25 #include "messagehistorymanager.h"
26 #include "lib/network/crossmap.h"
27 #include "safelogger.h"
28 #include "ui_kdevteamwork_internalmessage.h"
31 class QStandardItemModel;
32 class TemporaryConversationConnector;
33 class KDevTeamworkClient;
34 class QTimer;
35 class InDocumentMessage;
37 namespace KDevelop {
38 class IDocument;
41 typedef SafeSharedPtr<InDocumentMessage, MessageSerialization> InDocumentMessagePointer;
43 ///This is a class that helps detecting when the document is deleted and then deleting the smartcursor, also it automatically creates the cursor. @todo replace with QOwnedPointer
44 class SmartCursorContainer {
45 QPointer<KTextEditor::Document> m_document;
46 KTextEditor::SmartCursor* m_smartCursor;
47 public:
48 SmartCursorContainer( KTextEditor::Document* doc = 0 ) : m_document( doc ), m_smartCursor( 0 ) {
49 if ( m_document ) {
50 KTextEditor::SmartInterface * smart =
51 qobject_cast<KTextEditor::SmartInterface*>( doc );
53 if ( smart )
54 m_smartCursor = smart->newSmartCursor();
57 KTextEditor::SmartCursor* operator -> () {
58 return m_smartCursor;
60 ~SmartCursorContainer() {
61 if ( m_smartCursor )
62 delete m_smartCursor;
63 m_smartCursor = 0;
65 KTextEditor::SmartCursor& operator *() {
66 return * m_smartCursor;
68 SmartCursorContainer( const SmartCursorContainer& rhs ) {
69 if ( &rhs == this )
70 return ;
71 if ( m_smartCursor && m_document )
72 delete m_smartCursor;
73 m_document = rhs.m_document;
74 m_smartCursor = rhs.m_smartCursor;
75 const_cast<SmartCursorContainer&>( rhs ).m_smartCursor = 0;
77 SmartCursorContainer& operator = ( const SmartCursorContainer& rhs ) {
78 if ( &rhs == this )
79 return * this;
80 if ( m_smartCursor && m_document )
81 delete m_smartCursor;
82 m_document = rhs.m_document;
83 m_smartCursor = rhs.m_smartCursor;
84 const_cast<SmartCursorContainer&>( rhs ).m_smartCursor = 0;
85 return *this;
88 operator bool() {
89 return m_document && m_smartCursor && m_smartCursor->isValid();
93 namespace KTextEditor {
94 class View;
95 class Cursor;
96 class SmartCursor;
98 class InDocumentMessage;
99 enum LogLevel;
100 class ConversationManager;
101 class QWidget;
102 class SmartCursor;
104 CROSSMAP_DEFINE_CONTAINER( QList )
106 struct OrderedDocumentMessage {
107 int position;
108 InDocumentMessagePointer message;
109 OrderedDocumentMessage( uint pos, const InDocumentMessagePointer& msg ) : position( pos ), message( msg ) {}
110 OrderedDocumentMessage() : position( 0 ), message( 0 ) {}
112 operator bool() const {
113 return ( bool ) message;
115 /*template<class Archive>
116 void serialize( Archive& arch, const uint version ) {
117 arch & position & message;
121 class InDocumentConversation : public QObject, public Shared, public SafeLogger {
122 Q_OBJECT
123 ///Order, message, file
124 BIND_LIST_3( Keys, InDocumentMessagePointer, int, QString )
125 typedef Utils::CrossMap< OrderedDocumentMessage, Keys > MessageSet;
126 public:
127 InDocumentConversation( InDocumentMessage* msg = 0 );
128 ~InDocumentConversation();
130 void addMessage( InDocumentMessage* msg );
132 template <class ArchType>
133 void load( ArchType& arch, unsigned int version );
135 template <class ArchType>
136 void save( ArchType& arch, unsigned int version ) const;
138 ConversationManager* manager() const;
140 void fillContextMenu( QMenu* menu, KDevTeamwork* teamwork, MessagePointer msg );
142 ///Returns true if the message belongs to this conversation
143 bool match( InDocumentMessage* msg ) const;
145 void setActive( bool );
147 UserPointer primaryUser();
149 public slots:
150 void userStateChanged( KDevTeamworkUserPointer );
151 void documentActivated( KDevelop::IDocument* document );
152 void verticalScrollPositionChanged ( KTextEditor::View *view, const KTextEditor::Cursor& newPos );
153 void cursorPositionChanged ( KTextEditor::View *view, const KTextEditor::Cursor& newPos );
154 void horizontalScrollPositionChanged ( KTextEditor::View *view );
155 void jumpTo();
156 void hide();
157 void sendMessage();
158 void gotReply( MessagePointer msg );
160 void messageClicked( const QModelIndex& );
161 void messageContextMenu ( const QPoint & );
162 void selectMessage( InDocumentMessagePointer msg );
164 void userInfo();
165 void log( const QString& str, LogLevel level = Info ) const;
166 void selectNearestMessage();
167 private slots:
168 void textChanged ( KTextEditor::Document * document, const KTextEditor::Range & oldRange, const KTextEditor::Range & newRange );
169 void textRemoved ( KTextEditor::Document * document, const KTextEditor::Range & range );
170 void textInserted ( KTextEditor::Document * document, const KTextEditor::Range & range );
172 void rangeDeleted();
173 private:
174 virtual std::string logPrefix();
176 InDocumentMessagePointer selectedMessage();
178 void documentActivated( KDevelop::IDocument* document, const InDocumentMessagePointer& msg );
180 void messageSelected( const MessagePointer& msg );
181 template <class ArchType>
182 void serial( ArchType& arch, unsigned int /*version*/ ) {
183 arch & m_documentName;
184 arch & m_line;
185 arch & m_active;
187 void pushMessage( const InDocumentMessagePointer& msg );
189 KTextEditor::Cursor currentDocCursor() const;
191 QString context() const;
192 void messageSendReady( bool success );
193 void addListItem( const QString& txt, const QString& icon = "error" );
194 SessionPointer session();
195 void fillUserBox();
196 void fillMessageModel();
197 void fillMessageToModel( const LockedSharedPtr<InDocumentMessage>& );
198 void setupWidget( QWidget* parent );
199 void embedInView( KTextEditor::View* view, KDevelop::IDocument* document, KTextEditor::Cursor position );
200 KTextEditor::Cursor findPositionInDocument( InDocumentMessagePointer::Locked l, KTextEditor::Cursor* endTarget = 0 );
201 void placeWidget( KTextEditor::View* view, const KTextEditor::Cursor* awayFrom = 0, bool forceShow = false );
203 string m_documentName;
204 int m_line;
205 int m_conversationId;
206 bool m_active;
207 uint m_messageCount;
209 //list<InDocumentMessagePointer> m_messages;
210 MessageSet m_messages;
212 QPointer<QWidget> m_widget;
213 Ui_InternalMessage m_widgets;
214 SmartCursorContainer m_smartCursor;
215 QAction* m_jumpToAction;
216 QAction* m_hideAction;
217 QAction* m_userInfoAction;
218 QStandardItemModel* m_messagesModel;
219 InDocumentMessagePointer m_sendingMessage;
220 SharedPtr<TemporaryConversationConnector> m_userConnector;
221 bool m_block;
223 QTimer* m_selectNearestMessageTimer;
225 QPointer<KTextEditor::Document> m_currentConnectedDocument;
227 KTextEditor::SmartRange* m_currentRange;
229 InDocumentReference::TextSearchInstance m_currentSearchInstance;
231 QTime m_lastSendTime;
232 public:
233 BOOST_SERIALIZATION_SPLIT_MEMBER()
236 typedef SharedPtr<InDocumentConversation> InDocumentConversationPointer;
238 class ConversationManager : public QObject {
239 Q_OBJECT
240 public:
242 ConversationManager( MessageManager* mng );
243 ~ConversationManager();
245 int processMessage( InDocumentMessage* msg );
247 static ConversationManager* instance() {
248 return m_instance;
251 void log( const QString& str, LogLevel level );
253 /* template <class ArchType>
254 void serialize( ArchType& arch, unsigned int ) {
255 arch & m_conversations;
258 MessageManager* manager() const {
259 return const_cast<MessageManager*>( m_manager );
262 ///Returns zero if the conversation does not exist.
263 InDocumentConversationPointer findConversation( const QString& context );
265 ///If the conversation does not exist, it is created.
266 InDocumentConversationPointer getConversation( InDocumentMessage* );
268 public slots:
269 void load();
270 void save();
271 void documentActivated( KDevelop::IDocument* document );
273 private:
274 static ConversationManager* m_instance;
275 typedef map<string, InDocumentConversationPointer> ConversationSet;
276 ConversationSet m_conversations; ///maps conversation-ids to conversations
277 MessageManager* m_manager;
278 static ConversationManager* globalManager;
281 #endif
283 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on