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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../../global.h"
|
||||
#include "item.h"
|
||||
#include <QVariant>
|
||||
#include <QIcon>
|
||||
|
||||
namespace Models {
|
||||
class Account : public Item {
|
||||
|
@ -11,8 +12,9 @@ namespace Models {
|
|||
explicit Account(const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
~Account();
|
||||
|
||||
void setState(int p_state);
|
||||
int getState() const;
|
||||
void setState(unsigned int p_state);
|
||||
void setState(Shared::ConnectionState p_state);
|
||||
Shared::ConnectionState getState() const;
|
||||
|
||||
void setLogin(const QString& p_login);
|
||||
QString getLogin() const;
|
||||
|
@ -23,6 +25,12 @@ namespace Models {
|
|||
void setPassword(const QString& p_password);
|
||||
QString getPassword() const;
|
||||
|
||||
void setAvailability(Shared::Availability p_avail);
|
||||
void setAvailability(unsigned int p_avail);
|
||||
Shared::Availability getAvailability() const;
|
||||
|
||||
QIcon getStatusIcon() const;
|
||||
|
||||
QVariant data(int column) const override;
|
||||
int columnCount() const override;
|
||||
|
||||
|
@ -32,7 +40,8 @@ namespace Models {
|
|||
QString login;
|
||||
QString password;
|
||||
QString server;
|
||||
int state;
|
||||
Shared::ConnectionState state;
|
||||
Shared::Availability availability;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ QVariant Models::Accounts::data (const QModelIndex& index, int role) const
|
|||
break;
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() == 2) {
|
||||
answer = QIcon::fromTheme(Shared::ConnectionStateThemeIcons[accs[index.row()]->getState()]);
|
||||
answer = QIcon::fromTheme(Shared::connectionStateThemeIcons[accs[index.row()]->getState()]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
#include "contact.h"
|
||||
#include <QDebug>
|
||||
|
||||
Models::Contact::Contact(const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
||||
Models::Contact::Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem):
|
||||
Item(Item::contact, data, parentItem),
|
||||
jid(data.value("jid").toString()),
|
||||
state(Shared::offline),
|
||||
jid(p_jid),
|
||||
availability(Shared::offline),
|
||||
state(Shared::none),
|
||||
presences()
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("state");
|
||||
if (itr != data.end()) {
|
||||
setState(itr.value().toUInt());
|
||||
}
|
||||
}
|
||||
|
||||
Models::Contact::~Contact()
|
||||
|
@ -26,22 +31,42 @@ void Models::Contact::setJid(const QString p_jid)
|
|||
}
|
||||
}
|
||||
|
||||
Shared::Availability Models::Contact::getState() const
|
||||
void Models::Contact::setAvailability(unsigned int p_state)
|
||||
{
|
||||
return 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 contact " << jid;
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::setState(Shared::Availability p_state)
|
||||
void Models::Contact::setState(unsigned int p_state)
|
||||
{
|
||||
if (state != p_state) {
|
||||
state = p_state;
|
||||
changed(2);
|
||||
if (p_state <= Shared::subscriptionStateHighest) {
|
||||
Shared::SubscriptionState state = static_cast<Shared::SubscriptionState>(p_state);
|
||||
setState(state);
|
||||
} else {
|
||||
qDebug() << "An attempt to set invalid subscription state " << p_state << " to the contact " << jid;
|
||||
}
|
||||
}
|
||||
|
||||
Shared::Availability Models::Contact::getAvailability() const
|
||||
{
|
||||
return availability;
|
||||
}
|
||||
|
||||
void Models::Contact::setAvailability(Shared::Availability p_state)
|
||||
{
|
||||
if (availability != p_state) {
|
||||
availability = p_state;
|
||||
changed(3);
|
||||
}
|
||||
}
|
||||
|
||||
int Models::Contact::columnCount() const
|
||||
{
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant Models::Contact::data(int column) const
|
||||
|
@ -56,6 +81,8 @@ QVariant Models::Contact::data(int column) const
|
|||
case 1:
|
||||
return jid;
|
||||
case 2:
|
||||
return availability;
|
||||
case 3:
|
||||
return state;
|
||||
default:
|
||||
return QVariant();
|
||||
|
@ -68,14 +95,10 @@ void Models::Contact::update(const QString& field, const QVariant& value)
|
|||
setName(value.toString());
|
||||
} else if (field == "jid") {
|
||||
setJid(value.toString());
|
||||
} else if (field == "availability") {
|
||||
setAvailability(value.toUInt());
|
||||
} else if (field == "state") {
|
||||
unsigned int iState = value.toUInt();
|
||||
if (iState <= Shared::availabilityHighest) {
|
||||
Shared::Availability state = static_cast<Shared::Availability>(iState);
|
||||
setState(state);
|
||||
} else {
|
||||
qDebug("An attempt to set wrong state to the contact");
|
||||
}
|
||||
setState(value.toUInt());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +146,9 @@ void Models::Contact::refresh()
|
|||
}
|
||||
|
||||
if (presence != 0) {
|
||||
setState(presence->getAvailability());
|
||||
setAvailability(presence->getAvailability());
|
||||
} else {
|
||||
setAvailability(Shared::offline);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,3 +169,25 @@ void Models::Contact::changed(int col)
|
|||
Item::changed(col);
|
||||
refresh();
|
||||
}
|
||||
|
||||
Shared::SubscriptionState Models::Contact::getState() const
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
void Models::Contact::setState(Shared::SubscriptionState p_state)
|
||||
{
|
||||
if (state != p_state) {
|
||||
state = p_state;
|
||||
changed(2);
|
||||
}
|
||||
}
|
||||
|
||||
QIcon Models::Contact::getStatusIcon() const
|
||||
{
|
||||
if (state == Shared::both) {
|
||||
return QIcon::fromTheme(Shared::availabilityThemeIcons[availability]);
|
||||
} else {
|
||||
return QIcon::fromTheme(Shared::subscriptionStateThemeIcons[state]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "presence.h"
|
||||
#include "../../global.h"
|
||||
#include <QMap>
|
||||
#include <QIcon>
|
||||
|
||||
namespace Models {
|
||||
|
||||
|
@ -12,12 +13,13 @@ class Contact : public Item
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Contact(const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
~Contact();
|
||||
|
||||
QString getJid() const;
|
||||
|
||||
Shared::Availability getState() const;
|
||||
Shared::Availability getAvailability() const;
|
||||
Shared::SubscriptionState getState() const;
|
||||
QIcon getStatusIcon() const;
|
||||
|
||||
int columnCount() const override;
|
||||
QVariant data(int column) const override;
|
||||
|
@ -35,12 +37,16 @@ protected:
|
|||
void _removeChild(int index) override;
|
||||
|
||||
protected:
|
||||
void setState(Shared::Availability p_state);
|
||||
void setAvailability(Shared::Availability p_state);
|
||||
void setAvailability(unsigned int p_state);
|
||||
void setState(Shared::SubscriptionState p_state);
|
||||
void setState(unsigned int p_state);
|
||||
void setJid(const QString p_jid);
|
||||
|
||||
private:
|
||||
QString jid;
|
||||
Shared::Availability state;
|
||||
Shared::Availability availability;
|
||||
Shared::SubscriptionState state;
|
||||
QMap<QString, Presence*> presences;
|
||||
};
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ QVariant Models::Item::data(int column) const
|
|||
void Models::Item::removeChild(int index)
|
||||
{
|
||||
emit childIsAboutToBeRemoved(this, index, index);
|
||||
removeChild(index);
|
||||
_removeChild(index);
|
||||
emit childRemoved();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,15 +62,4 @@ class Item : public QObject{
|
|||
|
||||
}
|
||||
|
||||
namespace Shared {
|
||||
static const std::deque<QString> AvailabilityIcons = {
|
||||
"im-user-online",
|
||||
"im-user-away",
|
||||
"im-user-away",
|
||||
"im-user-busy",
|
||||
"im-user-online",
|
||||
"im-user-offline"
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MODELS_ITEM_H
|
||||
|
|
|
@ -59,28 +59,17 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
switch (item->type) {
|
||||
case Item::account:{
|
||||
Account* acc = static_cast<Account*>(item);
|
||||
int state = acc->getState();
|
||||
switch (state) {
|
||||
case Shared::disconnected:
|
||||
result = QIcon::fromTheme("im-user-offline");
|
||||
break;
|
||||
case Shared::connecting:
|
||||
result = QIcon::fromTheme(Shared::ConnectionStateThemeIcons[state]);
|
||||
break;
|
||||
case Shared::connected:
|
||||
result = QIcon::fromTheme("im-user-online");
|
||||
break;
|
||||
}
|
||||
result = acc->getStatusIcon();
|
||||
}
|
||||
break;
|
||||
case Item::contact:{
|
||||
Contact* contact = static_cast<Contact*>(item);
|
||||
result = QIcon::fromTheme(Shared::AvailabilityIcons[contact->getState()]);
|
||||
result = contact->getStatusIcon();
|
||||
}
|
||||
break;
|
||||
case Item::presence:{
|
||||
Presence* presence = static_cast<Presence*>(item);
|
||||
result = QIcon::fromTheme(Shared::AvailabilityIcons[presence->getAvailability()]);
|
||||
result = QIcon::fromTheme(Shared::availabilityThemeIcons[presence->getAvailability()]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -247,7 +236,7 @@ void Models::Roster::addGroup(const QString& account, const QString& name)
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::addContact(const QString& account, const QString& jid, const QString& name, const QString& group)
|
||||
void Models::Roster::addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Item* parent;
|
||||
Account* acc;
|
||||
|
@ -257,7 +246,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
{
|
||||
std::map<QString, Account*>::iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
qDebug() << "An attempt to add a contact " << name << " to non existing account " << account << ", skipping";
|
||||
qDebug() << "An attempt to add a contact " << jid << " to non existing account " << account << ", skipping";
|
||||
return;
|
||||
}
|
||||
acc = itr->second;
|
||||
|
@ -268,7 +257,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
std::multimap<ElId, Contact*>::iterator eItr = contacts.upper_bound(id);
|
||||
while (itr != eItr) {
|
||||
if (itr->second->parentItem() == acc) {
|
||||
qDebug() << "An attempt to add a contact " << name << " ungrouped to non the account " << account << " for the second time, skipping";
|
||||
qDebug() << "An attempt to add a contact " << jid << " ungrouped to non the account " << account << " for the second time, skipping";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +265,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
} else {
|
||||
std::map<ElId, Item*>::iterator itr = groups.find({account, group});
|
||||
if (itr == groups.end()) {
|
||||
qDebug() << "An attempt to add a contact " << name << " to non existing group " << group << ", skipping";
|
||||
qDebug() << "An attempt to add a contact " << jid << " to non existing group " << group << ", skipping";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -287,7 +276,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
if (item->type == Item::contact) {
|
||||
Contact* ca = static_cast<Contact*>(item);
|
||||
if (ca->getJid() == jid) {
|
||||
qDebug() << "An attempt to add a contact " << name << " to the group " << group << " for the second time, skipping";
|
||||
qDebug() << "An attempt to add a contact " << jid << " to the group " << group << " for the second time, skipping";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +287,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
if (item->type == Item::contact) {
|
||||
Contact* ca = static_cast<Contact*>(item);
|
||||
if (ca->getJid() == jid) {
|
||||
qDebug() << "An attempt to add a already existing contact " << name << " to the group " << group << ", contact will be moved from ungrouped contacts of " << account;
|
||||
qDebug() << "An attempt to add a already existing contact " << jid << " to the group " << group << ", contact will be moved from ungrouped contacts of " << account;
|
||||
|
||||
parent->appendChild(ca);
|
||||
return;
|
||||
|
@ -307,7 +296,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
}
|
||||
|
||||
}
|
||||
contact = new Contact({{"name", name}, {"jid", jid}, {"state", 0}});
|
||||
contact = new Contact(jid, data);
|
||||
parent->appendChild(contact);
|
||||
contacts.insert(std::make_pair(id, contact));
|
||||
}
|
||||
|
@ -359,14 +348,16 @@ void Models::Roster::removeGroup(const QString& account, const QString& name)
|
|||
delete item;
|
||||
}
|
||||
|
||||
void Models::Roster::changeContact(const QString& account, const QString& jid, const QString& name)
|
||||
void Models::Roster::changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
ElId id(account, jid);
|
||||
std::multimap<ElId, Contact*>::iterator cBeg = contacts.lower_bound(id);
|
||||
std::multimap<ElId, Contact*>::iterator cEnd = contacts.upper_bound(id);
|
||||
|
||||
for (; cBeg != cEnd; ++cBeg) {
|
||||
cBeg->second->setName(name);
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
||||
cBeg->second->update(itr.key(), itr.value());;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,7 +421,7 @@ void Models::Roster::removeContact(const QString& account, const QString& jid, c
|
|||
|
||||
void Models::Roster::onChildChanged(Models::Item* item, int row, int col)
|
||||
{
|
||||
QModelIndex index = createIndex(row, col, item);
|
||||
QModelIndex index = createIndex(row, 0, item);
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ public:
|
|||
void updateAccount(const QString& account, const QString& field, const QVariant& value);
|
||||
void addGroup(const QString& account, const QString& name);
|
||||
void removeGroup(const QString& account, const QString& name);
|
||||
void addContact(const QString& account, const QString& jid, const QString& name, const QString& group);
|
||||
void addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data);
|
||||
void removeContact(const QString& account, const QString& jid, const QString& group);
|
||||
void removeContact(const QString& account, const QString& jid);
|
||||
void changeContact(const QString& account, const QString& jid, const QString& name);
|
||||
void changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data);
|
||||
void addPresence(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||
void removePresence(const QString& account, const QString& jid, const QString& name);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue