We now have a current svn snapshot of libqxt in our contrib dir, and
[quassel.git] / src / core / sqlitestorage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _SQLITESTORAGE_H_
22 #define _SQLITESTORAGE_H_
23
24 #include <QCryptographicHash>
25
26 #include "storage.h"
27
28 class QSqlQuery;
29
30 class SqliteStorage : public Storage {
31   Q_OBJECT
32
33   public:
34     SqliteStorage();
35     virtual ~SqliteStorage();
36
37     static void init();
38
39     /* General */
40
41     static bool isAvailable();
42     static QString displayName();
43
44     // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
45
46     /* User handling */
47
48     virtual UserId addUser(const QString &user, const QString &password);
49     virtual void updateUser(UserId user, const QString &password);
50     virtual void renameUser(UserId user, const QString &newName);
51     virtual UserId validateUser(const QString &user, const QString &password);
52     virtual void delUser(UserId user);
53
54     /* Network handling */
55     virtual uint getNetworkId(UserId user, const QString &network);
56
57     /* Buffer handling */
58     virtual BufferInfo getBufferInfo(UserId user, const QString &network, const QString &buffer = "");
59     virtual QList<BufferInfo> requestBuffers(UserId user, QDateTime since = QDateTime());
60
61     /* Message handling */
62
63     virtual MsgId logMessage(Message msg);
64     virtual QList<Message> requestMsgs(BufferInfo buffer, int lastmsgs = -1, int offset = -1);
65     virtual QList<Message> requestMsgs(BufferInfo buffer, QDateTime since, int offset = -1);
66     virtual QList<Message> requestMsgRange(BufferInfo buffer, int first, int last);
67
68   public slots:
69     //! This is just for importing the old file-based backlog */
70     /** This slot needs to be implemented in the storage backends.
71      *  It should first prepare (delete?) the database, then call initBackLogOld(UserId id).
72      *  If the importing was successful, backLogEnabledOld will be true afterwards.
73      */
74     void importOldBacklog();
75
76   signals:
77     void bufferInfoUpdated(BufferInfo);
78
79   protected:
80
81   private:
82     void initDb();
83     void createBuffer(UserId user, const QString &network, const QString &buffer);
84     QSqlQuery *logMessageQuery;
85     QSqlQuery *addSenderQuery;
86     QSqlQuery *getLastMessageIdQuery;
87     QSqlQuery *requestMsgsQuery;
88     QSqlQuery *requestMsgsOffsetQuery;
89     QSqlQuery *requestMsgsSinceQuery;
90     QSqlQuery *requestMsgsSinceOffsetQuery;
91     QSqlQuery *requestMsgRangeQuery;
92     QSqlQuery *createNetworkQuery;
93     QSqlQuery *createBufferQuery;
94     QSqlQuery *getBufferInfoQuery;
95 };
96
97
98 #endif