Don't keep compiling/run if something failed.
[kdevelopdvcssupport.git] / plugins / teamwork / messagehistorymanager.h
blob1d6a0a7ed2732720b5ef60d36f8540b3df6702f9
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 MESSAGEHISTORYMANAGER_H
15 #define MESSAGEHISTORYMANAGER_H
18 #include <QList>
19 #include <QMap>
21 #include <klockfile.h>
22 #include <kurl.h>
24 #include "lib/network/user.h"
25 #include "kdevteamwork_messages.h"
26 #include "teamworkfwd.h"
27 #include <nvp.h>
30 class QTimer;
31 class KDevTeamworkTextMessage;
33 typedef SafeSharedPtr<KDevTeamworkTextMessage, MessageSerialization> HistoryMessagePointer;
35 struct HistoryMessageDesc
37 UserIdentity user;
38 bool isIncoming;
39 HistoryMessagePointer message;
41 HistoryMessageDesc();
43 HistoryMessageDesc( const HistoryMessagePointer& msg );
45 template<class Archive>
46 void load( Archive& arch, const uint /*version*/ ) {
47 arch & NVP( user );
48 arch & NVP( isIncoming );
49 arch & NVP( message );
50 HistoryMessagePointer::Locked l = message;
51 if( l ) {
52 l->info().setIsIncoming( isIncoming );
56 template<class Archive>
57 void save( Archive& arch, const uint /*version*/ ) const {
58 arch & NVP( user );
59 arch & NVP( isIncoming );
60 arch & NVP( message );
63 operator bool() {
64 return (bool) message;
67 BOOST_SERIALIZATION_SPLIT_MEMBER()
70 struct HistoryGroupLocation {
71 string fileName;
72 uint offset;
74 template<class Archive>
75 void serialize( Archive& arch, const uint /*version*/ ) {
76 arch & fileName;
77 arch & offset;
82 class MessageHistoryManager : public QObject {
83 Q_OBJECT
84 public:
85 typedef QMap<Teamwork::UserIdentity, bool > UserSet;
88 MessageHistoryManager( Teamwork::LoggerPointer logger );
89 ~MessageHistoryManager();
91 void addMessage( KDevTeamworkTextMessage* msg );
93 ///Returns all matching messages. If user is zero, returns messages from/to all users. This is slow(always reads the messages from disk)
94 QList<HistoryMessagePointer> getMessages( const KDevTeamworkClientPointer& client, const QDate& from = QDate(), const QDate& until = QDate(), UserSet users = UserSet() );
96 HistoryMessagePointer getMessageFromId( Teamwork::UniqueMessageId id, const KDevTeamworkClientPointer& client );
98 signals:
99 void newMessage( HistoryMessagePointer msg ); ///This is emitted whenever a new message should be added to the history
101 private slots:
102 void writePending();
104 private:
105 HistoryMessagePointer fillMessageUser( const HistoryMessageDesc& message, const KDevTeamworkClientPointer& client );
107 QString lockFileName();
109 QList<HistoryMessagePointer> fillMessageUsers( const QList<HistoryMessageDesc>& messages, const KDevTeamworkClientPointer& client );
110 ///Reads out the messages of just one chunk(the messages that follow a single header)
111 void readMessages( const QString& file, uint offset, QList<HistoryMessageDesc>& messages ) throw(QString);
113 void readIndex( std::map<Teamwork::UniqueMessageId, HistoryGroupLocation>& index ) throw( QString);
115 void writeIndex( const std::map<Teamwork::UniqueMessageId, HistoryGroupLocation>& index ) throw( QString);
117 ///May throw QString
118 KUrl directory() throw(QString);
120 QTimer* m_pendingTimer;
121 QList< HistoryMessageDesc > m_pending;
122 Teamwork::LoggerPointer m_logger;
123 KLockFile::Ptr m_lockFile;
125 Teamwork::LoggerPrinter out( Teamwork::Logger::Level = Teamwork::Logger::Info );
127 Teamwork::LoggerPrinter err();
130 #endif
132 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on