1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
5 /***************************************************************************
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. *
12 ***************************************************************************/
14 #ifndef COLLABORATIONMANAGER_H
15 #define COLLABORATIONMANAGER_H
17 #include "lib/network/safesharedptr.h"
18 #include "filecollaborationmessages.h"
19 #include "kdevteamwork.h"
23 #include "safelogger.h"
31 class QStandardItemModel
;
33 ///These helpers can be used to plug own actions into the tree-structure of the collaboration-manager. To get active, a CollaborationTreeActionPointer must be set as the UserData-entry in the model.
34 struct CollaborationTreeAction
: public Shared
{
35 virtual void fillContextMenu( QMenu
* menu
) = 0;
36 virtual void doubleClicked() {
38 virtual void clicked() {
42 ///This class will call a fillContextMenu-function in the targetet-class
43 template <class targetet
, class ValueType
= int>
44 struct StandardCollaborationTreeAction
: public CollaborationTreeAction
{
45 QPointer
<targetet
> target
;
48 StandardCollaborationTreeAction( targetet
* t
, const ValueType
& v
) : var( v
), target( t
) {}
49 StandardCollaborationTreeAction( targetet
* t
) : target( t
) {}
51 virtual void fillContextMenu( QMenu
* menu
) {
53 target
->fillContextMenu( var
, menu
);
58 typedef SharedPtr
< CollaborationTreeAction
> CollaborationTreeActionPointer
;
60 Q_DECLARE_METATYPE( CollaborationTreeActionPointer
)
62 using namespace Teamwork
;
64 class FileCollaborationManager
;
65 class FileCollaborationSession
;
66 typedef SharedPtr
<FileCollaborationSession
> FileCollaborationSessionPointer
;
70 class CollaborationManager
: public QObject
, public SafeLogger
{
73 CollaborationManager( KDevTeamwork
* tw
);
74 ~CollaborationManager();
77 void addCollaboratingUser( const UserPointer
& u
);
79 void removeCollaboratingUser( const UserPointer
& user
);
81 bool isCollaborating( const UserPointer
& user
);
85 void restorePartialProjectSession( const QDomElement
* el
);
87 void savePartialProjectSession( QDomElement
* el
);
89 void fillUserMenu( QMenu
* menu
, const UserPointer
& user
);
91 FileCollaborationManager
& fileCollaborationManager() ;
93 QStandardItemModel
* developersModel();
95 KDevTeamwork
* teamwork();
97 void fillCollaboratingUserMenu( QMenu
* menu
, const UserPointer
& user
);
98 void updateModel( QStandardItemModel
* model
);
101 void maybeContextMenu();
103 void collaboratingDeveloperClicked( const QModelIndex
& i
);
104 void collaboratingDeveloperDoubleClicked( const QModelIndex
& i
);
105 void collaboratingDeveloperContextMenu( const QPoint
& );
106 void uiCloseCollaboration();
107 void updateConnection( const TeamworkClientPointer
& );
108 void processMessage( const CollaborationMessagePointer
& );
109 void sessionStateChanged( const FileCollaborationSessionPointer
& session
);
111 void uiAcceptCollaboration();
112 void uiDenyCollaboration();
113 void uiRequestCollaboration();
116 void contextMenu( const QPoint
& pos
, const QModelIndex
& index
);
117 friend class ConnectionRequest
;
118 KDevTeamwork
* m_teamwork
;
120 <UserPointer
> UserSet
;
121 UserSet m_collaboratingUsers
;
122 AutoConstructPointer
<FileCollaborationManager
> m_fileCollaboration
;
123 QStandardItemModel
* m_developersModel
; ///Model for the collaborating-developers tree-view
124 auto_ptr
<QPersistentModelIndex
> m_contextMenuIndex
; ///Only used for the timer
126 QAction
* m_requestCollaborationAction
;
127 QAction
* m_closeCollaborationAction
;
128 QAction
* m_acceptConnectionAction
;
129 QAction
* m_denyConnectionAction
;
131 QTimer
* m_contextMenuTimer
;
137 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on