forked from blue/squawk
Bugfixes, availabilities statuses support
This commit is contained in:
parent
e8eaced6e9
commit
a5d24c0e3a
18 changed files with 374 additions and 131 deletions
|
@ -1,19 +1,29 @@
|
|||
#include "account.h"
|
||||
#include <QDebug>
|
||||
|
||||
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()),
|
||||
state(data.value("state").toInt())
|
||||
state(Shared::disconnected),
|
||||
availability(Shared::offline)
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
Models::Account::~Account()
|
||||
{
|
||||
}
|
||||
|
||||
void Models::Account::setState(int p_state)
|
||||
void Models::Account::setState(Shared::ConnectionState p_state)
|
||||
{
|
||||
if (state != p_state) {
|
||||
state = p_state;
|
||||
|
@ -21,6 +31,51 @@ void Models::Account::setState(int p_state)
|
|||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString Models::Account::getLogin() const
|
||||
{
|
||||
return login;
|
||||
|
@ -36,7 +91,7 @@ QString Models::Account::getServer() const
|
|||
return server;
|
||||
}
|
||||
|
||||
int Models::Account::getState() const
|
||||
Shared::ConnectionState Models::Account::getState() const
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
@ -73,11 +128,13 @@ QVariant Models::Account::data(int column) const
|
|||
case 1:
|
||||
return server;
|
||||
case 2:
|
||||
return Shared::ConnectionStateNames[state];
|
||||
return Shared::connectionStateNames[state];
|
||||
case 3:
|
||||
return login;
|
||||
case 4:
|
||||
return password;
|
||||
case 5:
|
||||
return Shared::availabilityNames[availability];
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -85,7 +142,7 @@ QVariant Models::Account::data(int column) const
|
|||
|
||||
int Models::Account::columnCount() const
|
||||
{
|
||||
return 5;
|
||||
return 6;
|
||||
}
|
||||
|
||||
void Models::Account::update(const QString& field, const QVariant& value)
|
||||
|
@ -99,6 +156,8 @@ void Models::Account::update(const QString& field, const QVariant& value)
|
|||
} else if (field == "password") {
|
||||
setPassword(value.toString());
|
||||
} else if (field == "state") {
|
||||
setState(value.toInt());
|
||||
setState(value.toUInt());
|
||||
} else if (field == "availability") {
|
||||
setAvailability(value.toUInt());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue