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