Adding skeleton for SqliteStorage.
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 21 May 2007 21:56:52 +0000 (21:56 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 21 May 2007 21:56:52 +0000 (21:56 +0000)
core/CMakeLists.txt
core/server.cpp
core/sqlitestorage.cpp [new file with mode: 0644]
core/sqlitestorage.h [new file with mode: 0644]
core/storage.cpp
core/storage.h

index c7adb95..fa1e53e 100644 (file)
@@ -1,6 +1,6 @@
-SET(core_SRCS core.cpp coreproxy.cpp server.cpp backlog.cpp)
+SET(core_SRCS core.cpp coreproxy.cpp server.cpp backlog.cpp storage.cpp sqlitestorage.cpp)
 SET(core_HDRS )
 SET(core_HDRS )
-SET(core_MOCS core.h coreproxy.h server.h backlog.h)
+SET(core_MOCS core.h coreproxy.h server.h backlog.h storage.h sqlitestorage.h)
 
 QT4_WRAP_CPP(_MOC ${core_MOCS})
 ADD_LIBRARY(core ${_MOC} ${core_SRCS} ${core_HDRS})
 
 QT4_WRAP_CPP(_MOC ${core_MOCS})
 ADD_LIBRARY(core ${_MOC} ${core_SRCS} ${core_HDRS})
index 44b85b4..f527226 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2005/06 by The Quassel Team                             *
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -738,6 +738,7 @@ void Server::handleServer001(QString prefix, QStringList params) {
 /* RPL_ISUPPORT */
 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
 void Server::handleServer005(QString prefix, QStringList params) {
 /* RPL_ISUPPORT */
 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
 void Server::handleServer005(QString prefix, QStringList params) {
+  qDebug() << prefix << params;
   params.removeLast();
   foreach(QString p, params) {
     QString key = p.section("=", 0, 0);
   params.removeLast();
   foreach(QString p, params) {
     QString key = p.section("=", 0, 0);
diff --git a/core/sqlitestorage.cpp b/core/sqlitestorage.cpp
new file mode 100644 (file)
index 0000000..882091e
--- /dev/null
@@ -0,0 +1,22 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "sqlitestorage.h"
+
diff --git a/core/sqlitestorage.h b/core/sqlitestorage.h
new file mode 100644 (file)
index 0000000..a3b63fe
--- /dev/null
@@ -0,0 +1,81 @@
+/***************************************************************************
+ *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef _SQLITESTORAGE_H_
+#define _SQLITESTORAGE_H_
+
+#include <QtCore>
+
+#include "global.h"
+#include "storage.h"
+
+class SqliteStorage : public Storage {
+  Q_OBJECT
+
+  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(QString user, QString password);
+    virtual UserId validateUser(QString user, QString password);
+    virtual void delUser(QString 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:
+};
+
+
+#endif
index 982415a..3c16dd3 100644 (file)
@@ -43,7 +43,7 @@ void Storage::importOldBacklog() {
 */
 
 // file name scheme: quassel-backlog-2006-29-10.bin
 */
 
 // file name scheme: quassel-backlog-2006-29-10.bin
-void Storage::initBackLogOld() {
+void Storage::initBackLogOld(UserId uid) {
   backLogDir = QDir(Global::quasselDir + "/backlog");
   if(!backLogDir.exists()) {
     qWarning(QString("Creating backlog directory \"%1\"...").arg(backLogDir.absolutePath()).toAscii());
   backLogDir = QDir(Global::quasselDir + "/backlog");
   if(!backLogDir.exists()) {
     qWarning(QString("Creating backlog directory \"%1\"...").arg(backLogDir.absolutePath()).toAscii());
@@ -100,9 +100,9 @@ void Storage::initBackLogOld() {
         QString text = QString::fromUtf8(m);
         BufferId id;
         if((f & Message::PrivMsg) && !(f & Message::Self)) {
         QString text = QString::fromUtf8(m);
         BufferId id;
         if((f & Message::PrivMsg) && !(f & Message::Self)) {
-          id = getBufferId(net, sender);
+          id = getBufferId(uid, net, sender);
         } else {
         } else {
-          id = getBufferId(net, target);
+          id = getBufferId(uid, net, target);
         }
         Message msg(QDateTime::fromTime_t(ts), id, (Message::Type)t, text, sender, f);
         //backLog[net].append(m);
         }
         Message msg(QDateTime::fromTime_t(ts), id, (Message::Type)t, text, sender, f);
         //backLog[net].append(m);
@@ -115,44 +115,3 @@ void Storage::initBackLogOld() {
 }
 
 
 }
 
 
-/** Log a core message (emitted via a displayMsg() signal) to the backlog file.
- * If a file for the current day does not exist, one will be created. Otherwise, messages will be appended.
- * The file header is the string defined by BACKLOG_STRING, followed by a quint8 specifying the format
- * version (BACKLOG_FORMAT). The rest is simply serialized Message objects.
- */
-void Storage::logMessageOld(QString net, Message msg) {
-  backLog[net].append(msg);
-  if(!logFileDirs.contains(net)) {
-    QDir dir(backLogDir.absolutePath() + "/" + net);
-    if(!dir.exists()) {
-      qWarning(QString("Creating backlog directory \"%1\"...").arg(dir.absolutePath()).toAscii());
-      if(!dir.mkpath(dir.absolutePath())) {
-        qWarning(QString("Could not create backlog directory!").toAscii());
-        return;
-      }
-    }
-    logFileDirs[net] = dir;
-    Q_ASSERT(!logFiles.contains(net) && !logStreams.contains(net));
-    if(!logFiles.contains(net)) logFiles[net] = new QFile();
-    if(!logStreams.contains(net)) logStreams[net] = new QDataStream();
-  }
-  if(!logFileDates[net].isValid() || logFileDates[net] < QDate::currentDate()) {
-    if(logFiles[net]->isOpen()) logFiles[net]->close();
-    logFileDates[net] = QDate::currentDate();
-  }
-  if(!logFiles[net]->isOpen()) {
-    logFiles[net]->setFileName(QString("%1/%2").arg(logFileDirs[net].absolutePath())
-        .arg(logFileDates[net].toString("'quassel-backlog-'yyyy-MM-dd'.bin'")));
-    if(!logFiles[net]->open(QIODevice::WriteOnly|QIODevice::Append|QIODevice::Unbuffered)) {
-      qWarning(QString("Could not open \"%1\" for writing: %2")
-          .arg(logFiles[net]->fileName()).arg(logFiles[net]->errorString()).toAscii());
-      return;
-    }
-    logStreams[net]->setDevice(logFiles[net]); logStreams[net]->setVersion(QDataStream::Qt_4_2);
-    if(!logFiles[net]->size()) *logStreams[net] << BACKLOG_STRING << (quint8)BACKLOG_FORMAT;
-  }
-  *logStreams[net] << msg;
-}
-
-
-
index 34ca0a8..c56cd4e 100644 (file)
@@ -24,6 +24,7 @@
 #include <QtCore>
 
 #include "global.h"
 #include <QtCore>
 
 #include "global.h"
+#include "message.h"
 
 class Storage : public QObject {
   Q_OBJECT
 
 class Storage : public QObject {
   Q_OBJECT
@@ -40,7 +41,7 @@ class Storage : public QObject {
      *  For anything like this, the constructor (which is called if and when we actually create an instance
      *  of the storage backend) is the right place.
      */
      *  For anything like this, the constructor (which is called if and when we actually create an instance
      *  of the storage backend) is the right place.
      */
-    virtual static void init() {};
+    static void init() {};
 
     /* General */
 
 
     /* General */
 
@@ -49,11 +50,11 @@ class Storage : public QObject {
      *  prerequisites are in place (e.g. we have an appropriate DB driver etc.).
      * \return True if and only if the storage class can be successfully used.
      */
      *  prerequisites are in place (e.g. we have an appropriate DB driver etc.).
      * \return True if and only if the storage class can be successfully used.
      */
-    virtual static bool isAvailable() = 0;
+    static bool isAvailable() { return false; }
 
     //! Returns the display name of the storage backend
     /** \return A string that can be used by the GUI to describe the storage backend */
 
     //! Returns the display name of the storage backend
     /** \return A string that can be used by the GUI to describe the storage backend */
-    virtual static QString displayName() = 0;
+    static QString displayName() { return ""; }
 
     // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
 
 
     // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
 
@@ -139,10 +140,10 @@ class Storage : public QObject {
   public slots:
     //! This is just for importing the old file-based backlog */
     /** This slot needs to be implemented in the storage backends.
   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().
+     *  It should first prepare (delete?) the database, then call initBackLogOld(UserId id).
      *  If the importing was successful, backLogEnabledOld will be true afterwards.
      */
      *  If the importing was successful, backLogEnabledOld will be true afterwards.
      */
-    void importOldBacklog() = 0;
+    virtual void importOldBacklog() = 0;
 
   signals:
     //! Sent if a new BufferId is created, or an existing one changed somehow.
 
   signals:
     //! Sent if a new BufferId is created, or an existing one changed somehow.
@@ -150,8 +151,7 @@ class Storage : public QObject {
 
   protected:
     // Old stuff, just for importing old file-based data
 
   protected:
     // Old stuff, just for importing old file-based data
-    void initBackLogOld();
-    void logMessageOld(QString net, Message);
+    void initBackLogOld(UserId id);
 
     bool backLogEnabledOld;
     QDir backLogDir;
 
     bool backLogEnabledOld;
     QDir backLogDir;
@@ -164,4 +164,4 @@ class Storage : public QObject {
 };
 
 
 };
 
 
-#endif
\ No newline at end of file
+#endif