diff options
Diffstat (limited to 'board.cpp')
-rw-r--r-- | board.cpp | 81 |
1 files changed, 80 insertions, 1 deletions
@@ -28,8 +28,25 @@ Board::Board(const QString& forumUrl, QObject *parent) : fetchForumsIfOutdated(); } +Board::~Board() +{ + QSqlDatabase::removeDatabase(_slug); +} + void Board::enqueueAction(Action *action) { + // Let's find if a duplicate action is in there already. + qDebug() << "Enqueing" << action; + + foreach (Action *a, _queue) { + if (a->isSupersetOf(action)) { + qDebug() << "Action superseded, ignoring"; + delete action; + return; + } + } + + // Otherwise, enqueue the action connect(action, SIGNAL(finished(Action*)), SLOT(handleActionFinished(Action*))); connect(action, SIGNAL(error(Action*,QString)), SLOT(handleActionError(Action*,QString))); @@ -95,6 +112,12 @@ void Board::notifyForumTopicsChanged(int forumId, int start, int end) emit forumTopicsChanged(forumId, start, end); } +void Board::notifyTopicPostsChanged(int topicId, int start, int end) +{ + qDebug() << "TopicPosts Changed" << topicId << start << end; + emit topicPostsChanged(topicId, start, end); +} + QString Board::createSlug(const QString &forumUrl) { static const QRegExp regexp("[^a-z0-9]+"); @@ -157,6 +180,58 @@ bool Board::initializeDb() return false; } + if (!q.exec("CREATE TABLE IF NOT EXISTS posts (forum_id INTEGER, topic_id INTEGER, post_id INTEGER PRIMARY KEY, post_title TEXT, post_content TEXT, post_author_id INTEGER, post_author_name TEXT, can_edit BOOL, icon_url TEXT, post_time TEXT, last_update_time TEXT)")) { + qWarning() << "Could not create posts table:" << q.lastError().text(); + return false; + } + if (!q.exec("CREATE INDEX IF NOT EXISTS posts_topic ON posts (topic_id)")) { + qWarning() << "Could not create posts_topic index:" << q.lastError().text(); + return false; + } + if (!q.exec("CREATE INDEX IF NOT EXISTS posts_time ON posts (post_time)")) { + qWarning() << "Could not create posts_time index:" << q.lastError().text(); + return false; + } + + return true; +} + +bool Board::eraseDb() +{ + QSqlQuery q(_db); + + if (!q.exec("DROP TABLE IF EXISTS config")) { + qWarning() << "Could not drop config table:" << q.lastError().text(); + return false; + } + if (!q.exec("DROP TABLE IF EXISTS forums")) { + qWarning() << "Could not drop forums table:" << q.lastError().text(); + return false; + } + if (!q.exec("DROP TABLE IF EXISTS topics")) { + qWarning() << "Could not drop topics table:" << q.lastError().text(); + return false; + } + if (!q.exec("DROP TABLE IF EXISTS posts")) { + qWarning() << "Could not drop posts table:" << q.lastError().text(); + return false; + } + if (!q.exec("VACUUM")) { + qWarning() << "Could not vacuum database:" << q.lastError().text(); + return false; + } + + return true; +} + +bool Board::cleanDb() +{ + QSqlQuery q(_db); + // TODO: Delete old posts from cache + if (!q.exec("VACUUM")) { + qWarning() << "Could not vacuum database:" << q.lastError().text(); + return false; + } return true; } @@ -210,7 +285,11 @@ void Board::fetchForumsIfOutdated() void Board::handleActionFinished(Action *action) { - removeFromActionQueue(action); + qDebug() << action << "finished"; + bool ok = removeFromActionQueue(action); + if (!ok) { + qWarning() << "Finished action not in queue"; + } } void Board::handleActionError(Action *action, const QString& message) |