summaryrefslogtreecommitdiff
path: root/fetchboardconfigaction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fetchboardconfigaction.cpp')
-rw-r--r--fetchboardconfigaction.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/fetchboardconfigaction.cpp b/fetchboardconfigaction.cpp
new file mode 100644
index 0000000..4d1cea2
--- /dev/null
+++ b/fetchboardconfigaction.cpp
@@ -0,0 +1,50 @@
+#include <QtCore/QDateTime>
+#include <QtCore/QDebug>
+#include <QtSql/QSqlQuery>
+
+#include "board.h"
+#include "xmlrpcinterface.h"
+#include "xmlrpcreply.h"
+#include "fetchboardconfigaction.h"
+
+FetchBoardConfigAction::FetchBoardConfigAction(Board *board) :
+ Action(board)
+{
+}
+
+void FetchBoardConfigAction::execute()
+{
+ _call = _board->service()->asyncCall("get_config");
+ connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall()));
+}
+
+void FetchBoardConfigAction::handleFinishedCall()
+{
+ XmlRpcReply<QVariantMap> result(_call);
+ if (result.isValid()) {
+ QVariantMap map = result;
+ QSqlDatabase db = _board->database();
+ db.transaction();
+ QSqlQuery query(db);
+ 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();
+ }
+ }
+ query.bindValue(":key", "last_config_fetch");
+ query.bindValue(":value", QDateTime::currentDateTimeUtc().toString(Qt::ISODate));
+ if (!query.exec()) {
+ qWarning() << "Failed to set last config fetch date";
+ }
+ db.commit();
+ _board->notifyConfigChanged();
+ } else {
+ qWarning() << "Could not fetch board configuration";
+ // TODO emit error ...
+ }
+ emit finished(this);
+ _call->deleteLater();
+}