summaryrefslogtreecommitdiff
path: root/loginaction.cpp
blob: 138c667eeb742a3ecad46a681c857cf2c283c2dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <QtCore/QDebug>

#include "board.h"
#include "xmlrpcinterface.h"
#include "xmlrpcreply.h"
#include "loginaction.h"

LoginAction::LoginAction(const QString &name, const QString &password, Board *board)
	: Action(board), _username(name), _password(password)
{
}

bool LoginAction::isSupersetOf(Action *action) const
{
	LoginAction *other = qobject_cast<LoginAction*>(action);
	if (other) {
		if (other->_username == _username && other->_password == _password) {
			return true;
		}
	}
	return false;
}

void LoginAction::execute()
{
	qDebug() << "Trying to login as" << _username;
	_call = _board->service()->asyncCall("login",
	                                     _username.toUtf8(), _password.toUtf8());
	_call->setParent(this);
	connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall()));
}

void LoginAction::handleFinishedCall()
{
	XmlRpcReply<QVariantMap> result(_call);
	if (result.isValid()) {
		QVariantMap map = result;
		bool login_ok = map["result"].toBool();
		if (login_ok) {
			_board->notifyLogin(map);
		} else {
			qWarning() << "Could not login to board as:" << _username;
		}
	} else {
		qWarning() << "Could not login";
		// TODO emit error ...
	}
	emit finished(this);
	_call->deleteLater();
}