squawk/core/account.cpp

88 lines
2.0 KiB
C++
Raw Normal View History

2019-03-29 14:54:34 +00:00
#include "account.h"
using namespace Core;
2019-03-30 20:13:13 +00:00
Account::Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, QObject* parent):
2019-03-29 14:54:34 +00:00
QObject(parent),
2019-03-30 20:13:13 +00:00
name(p_name),
login(p_login),
server(p_server),
2019-03-29 14:54:34 +00:00
password(p_password),
client(),
state(Shared::disconnected)
2019-03-29 14:54:34 +00:00
{
QObject::connect(&client, SIGNAL(connected()), this, SLOT(onClientConnected()));
QObject::connect(&client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()));
2019-03-29 14:54:34 +00:00
}
Account::~Account()
{
}
2019-03-29 14:54:34 +00:00
Shared::ConnectionState Core::Account::getState() const
{
return state;
2019-03-29 14:54:34 +00:00
}
void Core::Account::connect()
{
if (state == Shared::disconnected) {
client.connectToServer(login + "@" + server, password);
state = Shared::connecting;
emit connectionStateChanged(state);
} else {
qDebug("An attempt to connect an account which is already connected, skipping");
}
}
void Core::Account::disconnect()
{
if (state != Shared::disconnected) {
client.disconnectFromServer();
state = Shared::disconnected;
emit connectionStateChanged(state);
}
}
void Core::Account::onClientConnected()
{
if (state == Shared::connecting) {
state = Shared::connected;
emit connectionStateChanged(state);
} else {
qDebug("Something weird had happened - xmpp client reported about successful connection but account wasn't in connecting state");
}
}
2019-04-02 15:46:18 +00:00
void Core::Account::onClientDisconnected()
{
if (state != Shared::disconnected) {
state = Shared::disconnected;
emit connectionStateChanged(state);
} else {
2019-04-03 18:15:36 +00:00
//qDebug("Something weird had happened - xmpp client reported about being disconnection but account was already in disconnected state");
}
}
QString Core::Account::getName() const
{
return name;
}
QString Core::Account::getLogin() const
{
return login;
}
QString Core::Account::getPassword() const
{
return password;
}
QString Core::Account::getServer() const
{
return server;
}