Finishing the renaming of the BufferTreeView, since SVN doesn't allow
[quassel.git] / src / core / storage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC 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) 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 _STORAGE_H_
22 #define _STORAGE_H_
23
24 #include <QtCore>
25 #include <QSqlDatabase>
26
27 #include "message.h"
28
29 class Storage : public QObject {
30   Q_OBJECT
31
32   public:
33     Storage() {};
34     virtual ~Storage() {};
35
36   public slots:
37     /* General */
38
39     //! Check if the storage type is available.
40     /** A storage subclass should return true if it can be successfully used, i.e. if all
41      *  prerequisites are in place (e.g. we have an appropriate DB driver etc.).
42      * \return True if and only if the storage class can be successfully used.
43      */
44     static bool isAvailable() { return false; }
45
46     //! Returns the display name of the storage backend
47     /** \return A string that can be used by the GUI to describe the storage backend */
48     static QString displayName() { return ""; }
49
50     //! Setup the storage provider.
51     /** This prepares the storage provider (e.g. create tables, etc.) for use within Quassel.
52      *  \param settings   Hostname, port, username, password, ...
53      *  \return True if and only if the storage provider was initialized successfully.
54      */
55     virtual bool setup(const QVariantMap &settings = QVariantMap()) { return false; }
56     
57     //! Initialize the storage provider
58     /** \param settings   Hostname, port, username, password, ...  
59      *  \return True if and only if the storage provider was initialized successfully.
60      */
61     virtual bool init(const QVariantMap &settings = QVariantMap()) = 0;
62     
63     // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
64
65     /* User handling */
66
67     //! Add a new core user to the storage.
68     /** \param user     The username of the new user
69      *  \param password The cleartext password for the new user
70      *  \return The new user's UserId
71      */
72     virtual UserId addUser(const QString &user, const QString &password) = 0;
73
74     //! Update a core user's password.
75     /** \param user     The user's id
76      *  \param password The user's new password
77      */
78     virtual void updateUser(UserId user, const QString &password) = 0;
79
80     //! Rename a user
81     /** \param user     The user's id
82      *  \param newName  The user's new name
83      */
84     virtual void renameUser(UserId user, const QString &newName) = 0;
85
86     //! Validate a username with a given password.
87     /** \param user     The username to validate
88      *  \param password The user's alleged password
89      *  \return A valid UserId if the password matches the username; 0 else
90      */
91     virtual UserId validateUser(const QString &user, const QString &password) = 0;
92
93     //! Remove a core user from storage.
94     /** \param user     The userid to delete
95      */
96     virtual void delUser(UserId user) = 0;
97
98     /* Network handling */
99
100     //! Get the unique NetworkId of the network for a user.
101     /** \param user    The core user who owns this buffername
102      *  \param network The network name
103      *  \return The BufferInfo corresponding to the given network and buffer name, or 0 if not found
104      */
105     virtual uint getNetworkId(UserId user, const QString &network) = 0;
106
107     /* Buffer handling */
108
109     //! Get the unique BufferInfo for the given combination of network and buffername for a user.
110     /** \param user    The core user who owns this buffername
111      *  \param network The network name
112      *  \param buffer  The buffer name (if empty, the net's status buffer is returned)
113      *  \return The BufferInfo corresponding to the given network and buffer name, or 0 if not found
114      */
115     virtual BufferInfo getBufferInfo(UserId user, const QString &network, const QString &buffer = "") = 0;
116
117     //! Request a list of all buffers known to a user since a certain point in time.
118     /** This method is used to get a list of all buffers we have stored a backlog from.
119      *  Optionally, a QDateTime can be given, so that only buffers are listed that where active
120      *  since that point in time.
121      *  \param user  The user whose buffers we request
122      *  \param since If this is defined, older buffers will be ignored
123      *  \return A list of the BufferInfos for all buffers as requested
124      */
125     virtual QList<BufferInfo> requestBuffers(UserId user, QDateTime since = QDateTime()) = 0;
126
127     /* Message handling */
128
129     //! Store a Message in the backlog.
130     /** \param msg  The message object to be stored
131      *  \return The globally unique id for the stored message
132      */
133     virtual MsgId logMessage(Message msg) = 0;
134
135     //! Request a certain number (or all) messages stored in a given buffer.
136     /** \param buffer   The buffer we request messages from
137      *  \param lastmsgs The number of messages we would like to receive, or -1 if we'd like all messages from that buffername
138      *  \param offset   Do not return (but DO count) messages with MsgId >= offset, if offset >= 0
139      *  \return The requested list of messages
140      */
141     virtual QList<Message> requestMsgs(BufferInfo buffer, int lastmsgs = -1, int offset = -1) = 0;
142
143     //! Request messages stored in a given buffer since a certain point in time.
144     /** \param buffer   The buffer we request messages from
145      *  \param since    Only return messages newer than this point in time
146      *  \param offset   Do not return messages with MsgId >= offset, if offset >= 0
147      *  \return The requested list of messages
148      */
149     virtual QList<Message> requestMsgs(BufferInfo buffer, QDateTime since, int offset = -1) = 0;
150
151     //! Request a range of messages stored in a given buffer.
152     /** \param buffer   The buffer we request messages from
153      *  \param first    Return messages with first <= MsgId <= last
154      *  \param last     Return messages with first <= MsgId <= last
155      *  \return The requested list of messages
156      */
157     virtual QList<Message> requestMsgRange(BufferInfo buffer, int first, int last) = 0;
158
159   signals:
160     //! Sent when a new BufferInfo is created, or an existing one changed somehow.
161     void bufferInfoUpdated(BufferInfo);
162     //! Sent when a new user has been added
163     void userAdded(UserId, const QString &username);
164     //! Sent when a user has been renamed
165     void userRenamed(UserId, const QString &newname);
166     //! Sent when a user has been removed
167     void userRemoved(UserId);
168
169   public:
170     /* Exceptions */
171     struct AuthError : public Exception {};
172 };
173
174
175 #endif