From 723e0e7f37636379f76008582dca459490b845f4 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Thu, 4 Apr 2013 00:25:54 +0200 Subject: add login support --- board.cpp | 11 ++++++++++- boardmodel.cpp | 1 - favoritesmodel.cpp | 10 ++++++++++ favoritesmodel.h | 4 +++- fetchforumsaction.cpp | 2 ++ loginaction.cpp | 4 ++-- xmlrpcinterface.cpp | 3 +++ 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/board.cpp b/board.cpp index 1a82a91..2cad565 100644 --- a/board.cpp +++ b/board.cpp @@ -7,6 +7,7 @@ #include "action.h" #include "fetchconfigaction.h" #include "fetchforumsaction.h" +#include "loginaction.h" #include "xmlrpcinterface.h" #include "board.h" @@ -138,7 +139,7 @@ QVariant Board::getLoginInfo(const QString &key) const void Board::login(const QString &username, const QString &password) { - // TODO + enqueueAction(new LoginAction(username, password, this)); } void Board::logout() @@ -255,6 +256,14 @@ void Board::notifyLogin(const QMap &info) _loginInfo = info; qDebug() << "Now logged in as" << _loginInfo["username"].toString(); emit loggedInChanged(); + if (getConfig("last_forums_fetch_logged_in") != "1") { + // Forum list is probably outdated, because we fetched it while + // we were logged out. + if (_iface->isAccessible()) { + qDebug() << "Fetching forums because of login"; + enqueueAction(new FetchForumsAction(this)); + } + } } else { // Double login? _loginInfo = info; diff --git a/boardmodel.cpp b/boardmodel.cpp index c8d8bd3..7454d6f 100644 --- a/boardmodel.cpp +++ b/boardmodel.cpp @@ -132,7 +132,6 @@ void BoardModel::reload() _query.clear(); if (_board && _forumId >= 0) { - qDebug() << "Reloading" << _board << _forumId; _query = QSqlQuery(_board->database()); _query.prepare("SELECT f1.forum_id,f1.forum_name,f1.logo_url,f1.description,f1.sub_only,f2.forum_name AS cat_name FROM forums f1 " "LEFT JOIN forums f2 ON f2.forum_id = f1.parent_id " diff --git a/favoritesmodel.cpp b/favoritesmodel.cpp index 5c0f51a..97c8c23 100644 --- a/favoritesmodel.cpp +++ b/favoritesmodel.cpp @@ -10,6 +10,8 @@ FavoritesModel::FavoritesModel(QObject *parent) : roles[NameRole] = QByteArray("title"); roles[LogoRole] = QByteArray("logo"); roles[BoardUrlRole] = QByteArray("boardUrl"); + roles[LoginUsernameRole] = QByteArray("loginUsername"); + roles[LoginPasswordRole] = QByteArray("loginPassword"); setRoleNames(roles); load(); @@ -41,6 +43,10 @@ QVariant FavoritesModel::data(const QModelIndex &index, int role) const return _boards[row].name; case BoardUrlRole: return _boards[row].url; + case LoginUsernameRole: + return _boards[row].username; + case LoginPasswordRole: + return _boards[row].password; } return QVariant(); @@ -56,6 +62,8 @@ void FavoritesModel::load() FavoriteBoard board; board.name = settings.value("name").toString(); board.url = settings.value("url").toUrl(); + board.username = settings.value("username").toString(); + board.password = settings.value("password").toString(); _boards.append(board); } settings.endArray(); @@ -70,6 +78,8 @@ void FavoritesModel::save() settings.setArrayIndex(i); settings.setValue("name", _boards[i].name); settings.setValue("url", _boards[i].url); + settings.setValue("username", _boards[i].username); + settings.setValue("password", _boards[i].password); } settings.endArray(); } diff --git a/favoritesmodel.h b/favoritesmodel.h index a18b1dc..e7c731c 100644 --- a/favoritesmodel.h +++ b/favoritesmodel.h @@ -14,7 +14,9 @@ public: NameRole = Qt::DisplayRole, LogoRole = Qt::DecorationRole, - BoardUrlRole = Qt::UserRole + BoardUrlRole = Qt::UserRole, + LoginUsernameRole, + LoginPasswordRole }; int rowCount(const QModelIndex &parent = QModelIndex()) const; diff --git a/fetchforumsaction.cpp b/fetchforumsaction.cpp index 53f1f12..c3b77cd 100644 --- a/fetchforumsaction.cpp +++ b/fetchforumsaction.cpp @@ -78,6 +78,8 @@ void FetchForumsAction::handleFinishedCall() _board->setConfig("last_forums_fetch", QDateTime::currentDateTimeUtc().toString(Qt::ISODate)); + _board->setConfig("last_forums_fetch_logged_in", + _board->loggedIn() ? "1" : "0"); db.commit(); _board->notifyForumsChanged(); } else { diff --git a/loginaction.cpp b/loginaction.cpp index 445b812..138c667 100644 --- a/loginaction.cpp +++ b/loginaction.cpp @@ -23,7 +23,7 @@ bool LoginAction::isSupersetOf(Action *action) const void LoginAction::execute() { - qDebug() << "Sending login call.."; + qDebug() << "Trying to login as" << _username; _call = _board->service()->asyncCall("login", _username.toUtf8(), _password.toUtf8()); _call->setParent(this); @@ -42,7 +42,7 @@ void LoginAction::handleFinishedCall() qWarning() << "Could not login to board as:" << _username; } } else { - qWarning() << "Could not fetch posts"; + qWarning() << "Could not login"; // TODO emit error ... } emit finished(this); diff --git a/xmlrpcinterface.cpp b/xmlrpcinterface.cpp index 4d55c8c..acda0f6 100644 --- a/xmlrpcinterface.cpp +++ b/xmlrpcinterface.cpp @@ -69,6 +69,9 @@ void XmlRpcInterface::encodeValue(QXmlStreamWriter *w, const QVariant &value) case QVariant::DateTime: w->writeTextElement("dateTime.iso8601", value.toDateTime().toString(Qt::ISODate)); break; + case QVariant::ByteArray: + w->writeTextElement("base64", value.toByteArray().toBase64()); + break; case QVariant::List: w->writeStartElement("array"); w->writeStartElement("data"); -- cgit v1.2.3