- MessageTypes are now binary exclusive which allows easy checks with multimple condi...
[quassel.git] / src / core / sqlitestorage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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) version 3.                                           *
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 "abstractsqlstorage.h"
25
26 #include <QSqlDatabase>
27
28 class QSqlQuery;
29
30 class SqliteStorage : public AbstractSqlStorage {
31   Q_OBJECT
32
33 public:
34   SqliteStorage(QObject *parent = 0);
35   virtual ~SqliteStorage();
36
37 public slots:
38   /* General */
39   
40   bool isAvailable() const;
41   QString displayName() const;
42   QString description() const;
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 NetworkId createNetwork(UserId user, const NetworkInfo &info);
56   virtual bool updateNetwork(UserId user, const NetworkInfo &info);
57   virtual bool removeNetwork(UserId user, const NetworkId &networkId);
58   virtual QList<NetworkInfo> networks(UserId user);
59   
60   /* Buffer handling */
61   virtual BufferInfo getBufferInfo(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer = "");
62   virtual QList<BufferInfo> requestBuffers(UserId user, QDateTime since = QDateTime());
63   
64   /* Message handling */
65   
66   virtual MsgId logMessage(Message msg);
67   virtual QList<Message> requestMsgs(BufferInfo buffer, int lastmsgs = -1, int offset = -1);
68   virtual QList<Message> requestMsgs(BufferInfo buffer, QDateTime since, int offset = -1);
69   virtual QList<Message> requestMsgRange(BufferInfo buffer, int first, int last);
70
71 protected:
72   inline virtual QString driverName() { return "QSQLITE"; }
73   inline virtual QString databaseName() { return backlogFile(); }
74   virtual int installedSchemaVersion();
75   
76 private:
77   static QString backlogFile();
78   bool isValidNetwork(UserId user, const NetworkId &networkId);
79   NetworkId getNetworkId(UserId user, const QString &network);
80   void createBuffer(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer);
81 };
82
83 #endif