2019-04-03 15:09:29 +00:00
|
|
|
#include "account.h"
|
2019-04-07 20:14:15 +00:00
|
|
|
#include <QDebug>
|
2019-04-03 15:09:29 +00:00
|
|
|
|
|
|
|
Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
|
|
|
Item(account, data, parentItem),
|
|
|
|
login(data.value("login").toString()),
|
|
|
|
password(data.value("password").toString()),
|
|
|
|
server(data.value("server").toString()),
|
2019-04-07 20:14:15 +00:00
|
|
|
state(Shared::disconnected),
|
|
|
|
availability(Shared::offline)
|
2019-04-03 15:09:29 +00:00
|
|
|
{
|
2019-04-07 20:14:15 +00:00
|
|
|
QMap<QString, QVariant>::const_iterator sItr = data.find("state");
|
|
|
|
if (sItr != data.end()) {
|
|
|
|
setState(sItr.value().toUInt());
|
|
|
|
}
|
|
|
|
QMap<QString, QVariant>::const_iterator aItr = data.find("availability");
|
|
|
|
if (aItr != data.end()) {
|
|
|
|
setAvailability(aItr.value().toUInt());
|
|
|
|
}
|
2019-04-03 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Models::Account::~Account()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-07 20:14:15 +00:00
|
|
|
void Models::Account::setState(Shared::ConnectionState p_state)
|
2019-04-03 15:09:29 +00:00
|
|
|
{
|
2019-04-03 18:15:36 +00:00
|
|
|
if (state != p_state) {
|
|
|
|
state = p_state;
|
2019-04-07 14:02:41 +00:00
|
|
|
changed(2);
|
2019-04-03 18:15:36 +00:00
|
|
|
}
|
2019-04-03 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 20:14:15 +00:00
|
|
|
void Models::Account::setAvailability(unsigned int p_state)
|
|
|
|
{
|
|
|
|
if (p_state <= Shared::availabilityHighest) {
|
|
|
|
Shared::Availability state = static_cast<Shared::Availability>(p_state);
|
|
|
|
setAvailability(state);
|
|
|
|
} else {
|
|
|
|
qDebug() << "An attempt to set invalid availability " << p_state << " to the account " << name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Models::Account::setState(unsigned int p_state)
|
|
|
|
{
|
|
|
|
if (p_state <= Shared::subscriptionStateHighest) {
|
|
|
|
Shared::ConnectionState state = static_cast<Shared::ConnectionState>(p_state);
|
|
|
|
setState(state);
|
|
|
|
} else {
|
|
|
|
qDebug() << "An attempt to set invalid subscription state " << p_state << " to the account " << name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Shared::Availability Models::Account::getAvailability() const
|
|
|
|
{
|
|
|
|
return availability;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Models::Account::setAvailability(Shared::Availability p_avail)
|
|
|
|
{
|
|
|
|
if (availability != p_avail) {
|
|
|
|
availability = p_avail;
|
|
|
|
changed(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon Models::Account::getStatusIcon() const
|
|
|
|
{
|
|
|
|
if (state == Shared::connected) {
|
|
|
|
return QIcon::fromTheme(Shared::availabilityThemeIcons[availability]);
|
|
|
|
} else if (state == Shared::disconnected) {
|
|
|
|
return QIcon::fromTheme(Shared::availabilityThemeIcons[Shared::offline]);
|
|
|
|
} else {
|
|
|
|
return QIcon::fromTheme(Shared::connectionStateThemeIcons[state]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-03 15:09:29 +00:00
|
|
|
QString Models::Account::getLogin() const
|
|
|
|
{
|
|
|
|
return login;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Models::Account::getPassword() const
|
|
|
|
{
|
|
|
|
return password;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Models::Account::getServer() const
|
|
|
|
{
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
2019-04-07 20:14:15 +00:00
|
|
|
Shared::ConnectionState Models::Account::getState() const
|
2019-04-03 15:09:29 +00:00
|
|
|
{
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Models::Account::setLogin(const QString& p_login)
|
|
|
|
{
|
2019-04-03 18:15:36 +00:00
|
|
|
if (login != p_login) {
|
|
|
|
login = p_login;
|
2019-04-07 14:02:41 +00:00
|
|
|
changed(3);
|
2019-04-03 18:15:36 +00:00
|
|
|
}
|
2019-04-03 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Models::Account::setPassword(const QString& p_password)
|
|
|
|
{
|
2019-04-03 18:15:36 +00:00
|
|
|
if (password != p_password) {
|
|
|
|
password = p_password;
|
2019-04-07 14:02:41 +00:00
|
|
|
changed(4);
|
2019-04-03 18:15:36 +00:00
|
|
|
}
|
2019-04-03 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Models::Account::setServer(const QString& p_server)
|
|
|
|
{
|
2019-04-03 18:15:36 +00:00
|
|
|
if (server != p_server) {
|
|
|
|
server = p_server;
|
2019-04-07 14:02:41 +00:00
|
|
|
changed(1);
|
2019-04-03 18:15:36 +00:00
|
|
|
}
|
2019-04-03 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Models::Account::data(int column) const
|
|
|
|
{
|
|
|
|
switch (column) {
|
|
|
|
case 0:
|
|
|
|
return Item::data(column);
|
|
|
|
case 1:
|
|
|
|
return server;
|
|
|
|
case 2:
|
2019-04-07 20:14:15 +00:00
|
|
|
return Shared::connectionStateNames[state];
|
2019-04-03 15:09:29 +00:00
|
|
|
case 3:
|
|
|
|
return login;
|
|
|
|
case 4:
|
|
|
|
return password;
|
2019-04-07 20:14:15 +00:00
|
|
|
case 5:
|
|
|
|
return Shared::availabilityNames[availability];
|
2019-04-03 15:09:29 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Models::Account::columnCount() const
|
|
|
|
{
|
2019-04-07 20:14:15 +00:00
|
|
|
return 6;
|
2019-04-03 15:09:29 +00:00
|
|
|
}
|
2019-04-03 18:15:36 +00:00
|
|
|
|
|
|
|
void Models::Account::update(const QString& field, const QVariant& value)
|
|
|
|
{
|
|
|
|
if (field == "name") {
|
|
|
|
setName(value.toString());
|
|
|
|
} else if (field == "server") {
|
|
|
|
setServer(value.toString());
|
|
|
|
} else if (field == "login") {
|
|
|
|
setLogin(value.toString());
|
|
|
|
} else if (field == "password") {
|
|
|
|
setPassword(value.toString());
|
|
|
|
} else if (field == "state") {
|
2019-04-07 20:14:15 +00:00
|
|
|
setState(value.toUInt());
|
|
|
|
} else if (field == "availability") {
|
|
|
|
setAvailability(value.toUInt());
|
2019-04-03 18:15:36 +00:00
|
|
|
}
|
|
|
|
}
|