From ea2ac1ddd74c1d97f094a4e56f2c038b5fef6351 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 2 Apr 2013 18:36:21 +0200 Subject: add some support for smilies --- fetchconfigaction.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 fetchconfigaction.cpp (limited to 'fetchconfigaction.cpp') diff --git a/fetchconfigaction.cpp b/fetchconfigaction.cpp new file mode 100644 index 0000000..8c0ac63 --- /dev/null +++ b/fetchconfigaction.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +#include "board.h" +#include "xmlrpcinterface.h" +#include "xmlrpcreply.h" +#include "fetchconfigaction.h" + +FetchConfigAction::FetchConfigAction(Board *board) : + Action(board) +{ +} + +bool FetchConfigAction::isSupersetOf(Action *action) const +{ + // If 'action' is also a fetch board config action then yes, this supersets 'action'. + return qobject_cast(action) != 0; +} + +void FetchConfigAction::execute() +{ + _call = _board->service()->asyncCall("get_config"); + connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall())); +} + +void FetchConfigAction::handleFinishedCall() +{ + XmlRpcReply result(_call); + if (result.isValid()) { + QVariantMap map = result; + QSqlDatabase db = _board->database(); + db.transaction(); + QSqlQuery query(db); + + // Let's add some of our config settings + map["last_config_fetch"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate); + map["tapasboard_db_version"] = Board::CURRENT_DB_VERSION; + + query.prepare("INSERT OR REPLACE INTO config (key, value) VALUES (:key, :value)"); + for (QVariantMap::iterator i = map.begin(); i != map.end(); i++) { + query.bindValue(":key", i.key()); + query.bindValue(":value", i.value().toString()); + if (!query.exec()) { + qWarning() << "Failed to set config key:" << i.key(); + } + } + db.commit(); + _board->notifyConfigChanged(); + } else { + qWarning() << "Could not fetch board configuration"; + // TODO emit error ... + } + emit finished(this); + _call->deleteLater(); +} -- cgit v1.2.3