Added uint networkId() to BufferIds.
[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 "global.h"
27 #include "storage.h"
28
29 class QSqlQuery;
30
31 class SqliteStorage : public Storage {
32   Q_OBJECT
33
34   public:
35     SqliteStorage();
36     virtual ~SqliteStorage();
37
38     static void init();
39
40     /* General */
41
42     static bool isAvailable();
43     static QString displayName();
44
45     // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
46
47     /* User handling */
48
49     virtual UserId addUser(const QString &user, const QString &password);
50     virtual void updateUser(UserId user, const QString &password);
51     virtual void renameUser(UserId user, const QString &newName);
52     virtual UserId validateUser(const QString &user, const QString &password);
53     virtual void delUser(UserId user);
54
55     /* Network handling */
56     virtual uint getNetworkId(UserId user, const QString &network);
57
58     /* Buffer handling */
59     virtual BufferId getBufferId(UserId user, const QString &network, const QString &buffer = "");
60     virtual QList<BufferId> requestBuffers(UserId user, QDateTime since = QDateTime());
61
62     /* Message handling */
63
64     virtual MsgId logMessage(Message msg);
65     virtual QList<Message> requestMsgs(BufferId buffer, int lastmsgs = -1, int offset = -1);
66     virtual QList<Message> requestMsgs(BufferId buffer, QDateTime since, int offset = -1);
67     virtual QList<Message> requestMsgRange(BufferId buffer, int first, int last);
68
69   public slots:
70     //! This is just for importing the old file-based backlog */
71     /** This slot needs to be implemented in the storage backends.
72      *  It should first prepare (delete?) the database, then call initBackLogOld(UserId id).
73      *  If the importing was successful, backLogEnabledOld will be true afterwards.
74      */
75     void importOldBacklog();
76
77   signals:
78     void bufferIdUpdated(BufferId);
79
80   protected:
81
82   private:
83     void initDb();
84     void createBuffer(UserId user, const QString &network, const QString &buffer);
85     QSqlQuery *logMessageQuery;
86     QSqlQuery *addSenderQuery;
87     QSqlQuery *getLastMessageIdQuery;
88     QSqlQuery *requestMsgsQuery;
89     QSqlQuery *requestMsgsOffsetQuery;
90     QSqlQuery *requestMsgsSinceQuery;
91     QSqlQuery *requestMsgsSinceOffsetQuery;
92     QSqlQuery *requestMsgRangeQuery;
93     QSqlQuery *createNetworkQuery;
94     QSqlQuery *createBufferQuery;
95     QSqlQuery *getBufferIdQuery;
96 };
97
98
99 #endif