- public:
- SqliteStorage();
- virtual ~SqliteStorage();
-
- static void init();
-
- /* General */
-
- static bool isAvailable();
- static QString displayName();
-
- // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
-
- /* User handling */
-
- virtual UserId addUser(QString user, QString password);
- virtual void updateUser(UserId user, QString password);
- virtual UserId validateUser(QString user, QString password);
- virtual void delUser(UserId user);
-
- /* Buffer handling */
-
- virtual BufferId getBufferId(UserId user, QString network, QString buffer = "");
- virtual QList<BufferId> requestBuffers(UserId user, QDateTime since = QDateTime());
-
- /* Message handling */
-
- virtual MsgId logMessage(Message msg);
- virtual QList<Message> requestMsgs(BufferId buffer, int lastmsgs = -1, int offset = -1);
- virtual QList<Message> requestMsgs(BufferId buffer, QDateTime since, int offset = -1);
- virtual QList<Message> requestMsgRange(BufferId buffer, int first, int last);
-
- public slots:
- //! This is just for importing the old file-based backlog */
- /** This slot needs to be implemented in the storage backends.
- * It should first prepare (delete?) the database, then call initBackLogOld(UserId id).
- * If the importing was successful, backLogEnabledOld will be true afterwards.
- */
- void importOldBacklog();
-
- signals:
- void bufferIdUpdated(BufferId);
-
- protected:
-
- private:
- void initDb();
- void createBuffer(UserId user, QString network, QString buffer);
- QSqlQuery *logMessageQuery;
- QSqlQuery *addSenderQuery;
- QSqlQuery *getLastMessageIdQuery;
- QSqlQuery *requestMsgsQuery;
- QSqlQuery *requestMsgsOffsetQuery;
- QSqlQuery *requestMsgsSinceQuery;
- QSqlQuery *requestMsgsSinceOffsetQuery;
- QSqlQuery *requestMsgRangeQuery;
- QSqlQuery *createNetworkQuery;
- QSqlQuery *createBufferQuery;
- QSqlQuery *getBufferIdQuery;
+public:
+ SqliteStorage(QObject *parent = 0);
+ virtual ~SqliteStorage();
+
+public slots:
+ /* General */
+
+ bool isAvailable() const;
+ QString displayName() const;
+ QString description() const;
+
+ // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
+
+ /* User handling */
+
+ virtual UserId addUser(const QString &user, const QString &password);
+ virtual void updateUser(UserId user, const QString &password);
+ virtual void renameUser(UserId user, const QString &newName);
+ virtual UserId validateUser(const QString &user, const QString &password);
+ virtual UserId internalUser();
+ virtual void delUser(UserId user);
+ virtual void setUserSetting(UserId userId, const QString &settingName, const QVariant &data);
+ virtual QVariant getUserSetting(UserId userId, const QString &settingName, const QVariant &defaultData = QVariant());
+
+
+ /* Network handling */
+ virtual NetworkId createNetwork(UserId user, const NetworkInfo &info);
+ virtual bool updateNetwork(UserId user, const NetworkInfo &info);
+ virtual bool removeNetwork(UserId user, const NetworkId &networkId);
+ virtual QList<NetworkInfo> networks(UserId user);
+ virtual QList<NetworkId> connectedNetworks(UserId user);
+ virtual void setNetworkConnected(UserId user, const NetworkId &networkId, bool isConnected);
+
+ /* persistent channels */
+ virtual QHash<QString, QString> persistentChannels(UserId user, const NetworkId &networkId);
+ virtual void setChannelPersistent(UserId user, const NetworkId &networkId, const QString &channel, bool isJoined);
+ virtual void setPersistentChannelKey(UserId user, const NetworkId &networkId, const QString &channel, const QString &key);
+
+ /* Buffer handling */
+ virtual BufferInfo getBufferInfo(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer = "");
+ virtual BufferInfo getBufferInfo(UserId user, const BufferId &bufferId);
+ virtual QList<BufferInfo> requestBuffers(UserId user);
+ virtual QList<BufferId> requestBufferIdsForNetwork(UserId user, NetworkId networkId);
+ virtual bool removeBuffer(const UserId &user, const BufferId &bufferId);
+ virtual BufferId renameBuffer(const UserId &user, const NetworkId &networkId, const QString &newName, const QString &oldName);
+ virtual void setBufferLastSeenMsg(UserId user, const BufferId &bufferId, const MsgId &msgId);
+ virtual QHash<BufferId, MsgId> bufferLastSeenMsgIds(UserId user);
+
+ /* Message handling */
+
+ virtual MsgId logMessage(Message msg);
+ virtual QList<Message> requestMsgs(UserId user, BufferId bufferId, int limit = -1, int offset = -1);
+ virtual QList<Message> requestMsgs(UserId user, BufferId bufferId, QDateTime since, int offset = -1);
+ virtual QList<Message> requestMsgRange(UserId user, BufferId bufferId, int first, int last);
+
+protected:
+ inline virtual QString driverName() { return "QSQLITE"; }
+ inline virtual QString databaseName() { return backlogFile(); }
+ virtual int installedSchemaVersion();
+ bool safeExec(QSqlQuery &query, int retryCount = 0);
+
+private:
+ static QString backlogFile();
+ bool isValidNetwork(UserId user, const NetworkId &networkId);
+ bool isValidBuffer(const UserId &user, const BufferId &bufferId);
+ NetworkId getNetworkId(UserId user, const QString &network);
+ void createBuffer(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer);
+
+ static int _maxRetryCount;