libqutim  0.3.2.0
history.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** qutIM - instant messenger
00004 **
00005 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
00006 **
00007 *****************************************************************************
00008 **
00009 ** $QUTIM_BEGIN_LICENSE$
00010 ** This program is free software: you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation, either version 3 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 ** See the GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program.  If not, see http://www.gnu.org/licenses/.
00022 ** $QUTIM_END_LICENSE$
00023 **
00024 ****************************************************************************/
00025 
00026 #ifndef HISTORY_H
00027 #define HISTORY_H
00028 
00029 #include "message.h"
00030 #include <QDateTime>
00031 
00032 namespace qutim_sdk_0_3
00033 {
00034     class ChatUnit;
00035     
00036 #ifdef EXPERIMENTAL_HISTORY_API 
00037     class HistoryRequestPrivate;
00038     class HistoryReplyPrivate;
00039     class HistoryRequest;
00040     
00041     class HistoryReply : public QObject
00042     {
00043         Q_OBJECT
00044         Q_DECLARE_PRIVATE(HistoryReply)
00045     public:
00046         HistoryReply();
00047         ~HistoryReply();
00048         
00049         HistoryRequest request() const;
00050         MessageList messages() const;
00051         int totalCount() const;
00052         int firstIndex() const;
00053         int lastIndex() const;
00054     signals:
00055         void ready();
00056     protected:
00057         void setMessages(const MessageList &messages);
00058         void setCount(int count);
00059         void setBoundaries(int first, int last);
00060     private:
00061         QScopedPointer<HistoryReplyPrivate> d_ptr;
00062     };
00063     
00064     class HistoryRequest
00065     {
00066     public:
00067         HistoryRequest(ChatUnit *unit);
00068         HistoryRequest(const HistoryRequest &other);
00069         ~HistoryRequest();
00070         HistoryRequest &operator =(const HistoryRequest &other);
00071 //      enum Type { MessagesCount,  };
00072         
00073         HistoryReply *send();
00074     private:
00075         QSharedDataPointer<HistoryRequestPrivate> d_ptr;
00076     };
00077 
00078     class LIBQUTIM_EXPORT HistoryEngine : public QObject
00079     {
00080         Q_OBJECT
00081     public:
00082         HistoryEngine();
00083         virtual ~HistoryEngine();
00084         virtual HistoryReply *store(const Message &msg) = 0;
00085         virtual HistoryReply *request(const HistoryRequest &rule) = 0;
00086     };
00087 #endif // EXPERIMENTAL_HISTORY_API  
00088     
00089     class LIBQUTIM_EXPORT History : public QObject
00090     {
00091         Q_OBJECT
00092     public:
00093         History();
00094         virtual ~History();
00095         static History *instance();
00096         virtual void store(const Message &message);
00097         virtual MessageList read(const ChatUnit *unit, const QDateTime &from, const QDateTime &to, int max_num);
00098         MessageList read(const ChatUnit *unit, const QDateTime &to, int max_num) { return read(unit, QDateTime(), to, max_num); }
00099         MessageList read(const ChatUnit *unit, int max_num) { return read(unit, QDateTime(), QDateTime::currentDateTime(), max_num); }
00100     public slots:
00101         virtual void showHistory(const ChatUnit *unit);
00102         virtual void virtual_hook(int id, void *data);
00103     };
00104 }
00105 
00106 #endif // HISTORY_H
00107