receiving account owner vCard, displaying avatars in roster
This commit is contained in:
parent
64e33b6139
commit
dc1ec1c9d4
13 changed files with 358 additions and 64 deletions
|
@ -26,6 +26,7 @@ Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* pare
|
|||
server(data.value("server").toString()),
|
||||
resource(data.value("resource").toString()),
|
||||
error(data.value("error").toString()),
|
||||
avatarPath(data.value("avatarPath").toString()),
|
||||
state(Shared::disconnected),
|
||||
availability(Shared::offline)
|
||||
{
|
||||
|
@ -162,6 +163,8 @@ QVariant Models::Account::data(int column) const
|
|||
return QCoreApplication::translate("Global", Shared::availabilityNames[availability].toLatin1());
|
||||
case 7:
|
||||
return resource;
|
||||
case 8:
|
||||
return avatarPath;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -169,7 +172,7 @@ QVariant Models::Account::data(int column) const
|
|||
|
||||
int Models::Account::columnCount() const
|
||||
{
|
||||
return 8;
|
||||
return 9;
|
||||
}
|
||||
|
||||
void Models::Account::update(const QString& field, const QVariant& value)
|
||||
|
@ -190,6 +193,8 @@ void Models::Account::update(const QString& field, const QVariant& value)
|
|||
setResource(value.toString());
|
||||
} else if (field == "error") {
|
||||
setError(value.toString());
|
||||
} else if (field == "avatarPath") {
|
||||
setAvatarPath(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,3 +229,15 @@ void Models::Account::toOfflineState()
|
|||
setAvailability(Shared::offline);
|
||||
Item::toOfflineState();
|
||||
}
|
||||
|
||||
QString Models::Account::getAvatarPath()
|
||||
{
|
||||
return avatarPath;
|
||||
}
|
||||
|
||||
void Models::Account::setAvatarPath(const QString& path)
|
||||
{
|
||||
avatarPath = path;
|
||||
changed(8); //it's uncoditional because the path doesn't change when one avatar of the same type replaces another, sha1 sums checks are on the backend
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,9 @@ namespace Models {
|
|||
void setError(const QString& p_resource);
|
||||
QString getError() const;
|
||||
|
||||
void setAvatarPath(const QString& path);
|
||||
QString getAvatarPath();
|
||||
|
||||
void setAvailability(Shared::Availability p_avail);
|
||||
void setAvailability(unsigned int p_avail);
|
||||
Shared::Availability getAvailability() const;
|
||||
|
@ -67,6 +70,7 @@ namespace Models {
|
|||
QString server;
|
||||
QString resource;
|
||||
QString error;
|
||||
QString avatarPath;
|
||||
Shared::ConnectionState state;
|
||||
Shared::Availability availability;
|
||||
|
||||
|
|
|
@ -25,14 +25,26 @@ Models::Contact::Contact(const QString& p_jid ,const QMap<QString, QVariant> &da
|
|||
jid(p_jid),
|
||||
availability(Shared::offline),
|
||||
state(Shared::none),
|
||||
avatarState(Shared::Avatar::empty),
|
||||
presences(),
|
||||
messages(),
|
||||
childMessages(0)
|
||||
childMessages(0),
|
||||
status(),
|
||||
avatarPath()
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("state");
|
||||
if (itr != data.end()) {
|
||||
setState(itr.value().toUInt());
|
||||
}
|
||||
|
||||
itr = data.find("avatarState");
|
||||
if (itr != data.end()) {
|
||||
setAvatarState(itr.value().toUInt());
|
||||
}
|
||||
itr = data.find("avatarPath");
|
||||
if (itr != data.end()) {
|
||||
setAvatarPath(itr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
Models::Contact::~Contact()
|
||||
|
@ -100,7 +112,7 @@ void Models::Contact::setStatus(const QString& p_state)
|
|||
|
||||
int Models::Contact::columnCount() const
|
||||
{
|
||||
return 6;
|
||||
return 8;
|
||||
}
|
||||
|
||||
QVariant Models::Contact::data(int column) const
|
||||
|
@ -118,6 +130,10 @@ QVariant Models::Contact::data(int column) const
|
|||
return getMessagesCount();
|
||||
case 5:
|
||||
return getStatus();
|
||||
case 6:
|
||||
return static_cast<quint8>(getAvatarState());
|
||||
case 7:
|
||||
return getAvatarPath();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -142,6 +158,10 @@ void Models::Contact::update(const QString& field, const QVariant& value)
|
|||
setAvailability(value.toUInt());
|
||||
} else if (field == "state") {
|
||||
setState(value.toUInt());
|
||||
} else if (field == "avatarState") {
|
||||
setAvatarState(value.toUInt());
|
||||
} else if (field == "avatarPath") {
|
||||
setAvatarPath(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,3 +368,39 @@ Models::Contact::Contact(const Models::Contact& other):
|
|||
|
||||
refresh();
|
||||
}
|
||||
|
||||
QString Models::Contact::getAvatarPath() const
|
||||
{
|
||||
return avatarPath;
|
||||
}
|
||||
|
||||
Shared::Avatar Models::Contact::getAvatarState() const
|
||||
{
|
||||
return avatarState;
|
||||
}
|
||||
|
||||
void Models::Contact::setAvatarPath(const QString& path)
|
||||
{
|
||||
if (path != avatarPath) {
|
||||
avatarPath = path;
|
||||
changed(7);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::setAvatarState(Shared::Avatar p_state)
|
||||
{
|
||||
if (avatarState != p_state) {
|
||||
avatarState = p_state;
|
||||
changed(6);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::setAvatarState(unsigned int p_state)
|
||||
{
|
||||
if (p_state <= static_cast<quint8>(Shared::Avatar::valid)) {
|
||||
Shared::Avatar state = static_cast<Shared::Avatar>(p_state);
|
||||
setAvatarState(state);
|
||||
} else {
|
||||
qDebug() << "An attempt to set invalid avatar state" << p_state << "to the contact" << jid << ", skipping";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
QString getJid() const;
|
||||
Shared::Availability getAvailability() const;
|
||||
Shared::SubscriptionState getState() const;
|
||||
Shared::Avatar getAvatarState() const;
|
||||
QString getAvatarPath() const;
|
||||
QIcon getStatusIcon(bool big = false) const;
|
||||
|
||||
int columnCount() const override;
|
||||
|
@ -75,6 +77,9 @@ protected:
|
|||
void setAvailability(unsigned int p_state);
|
||||
void setState(Shared::SubscriptionState p_state);
|
||||
void setState(unsigned int p_state);
|
||||
void setAvatarState(Shared::Avatar p_state);
|
||||
void setAvatarState(unsigned int p_state);
|
||||
void setAvatarPath(const QString& path);
|
||||
void setJid(const QString p_jid);
|
||||
void setStatus(const QString& p_state);
|
||||
|
||||
|
@ -82,10 +87,12 @@ private:
|
|||
QString jid;
|
||||
Shared::Availability availability;
|
||||
Shared::SubscriptionState state;
|
||||
Shared::Avatar avatarState;
|
||||
QMap<QString, Presence*> presences;
|
||||
Messages messages;
|
||||
unsigned int childMessages;
|
||||
QString status;
|
||||
QString avatarPath;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ const Models::Item * Models::Item::parentItemConst() const
|
|||
|
||||
int Models::Item::columnCount() const
|
||||
{
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
QString Models::Item::getName() const
|
||||
|
|
|
@ -68,6 +68,9 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
if (index.column() != 0) {
|
||||
break;
|
||||
}
|
||||
switch (item->type) {
|
||||
case Item::group: {
|
||||
Group* gr = static_cast<Group*>(item);
|
||||
|
@ -91,26 +94,50 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
case Qt::DecorationRole:
|
||||
switch (item->type) {
|
||||
case Item::account: {
|
||||
quint8 col = index.column();
|
||||
Account* acc = static_cast<Account*>(item);
|
||||
result = acc->getStatusIcon(false);
|
||||
if (col == 0) {
|
||||
result = acc->getStatusIcon(false);
|
||||
} else if (col == 1) {
|
||||
QString path = acc->getAvatarPath();
|
||||
if (path.size() > 0) {
|
||||
result = QIcon(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Item::contact: {
|
||||
Contact* contact = static_cast<Contact*>(item);
|
||||
result = contact->getStatusIcon(false);
|
||||
quint8 col = index.column();
|
||||
if (col == 0) {
|
||||
result = contact->getStatusIcon(false);
|
||||
} else if (col == 1) {
|
||||
if (contact->getAvatarState() != Shared::Avatar::empty) {
|
||||
result = QIcon(contact->getAvatarPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Item::presence: {
|
||||
if (index.column() != 0) {
|
||||
break;
|
||||
}
|
||||
Presence* presence = static_cast<Presence*>(item);
|
||||
result = presence->getStatusIcon(false);
|
||||
}
|
||||
break;
|
||||
case Item::room: {
|
||||
if (index.column() != 0) {
|
||||
break;
|
||||
}
|
||||
Room* room = static_cast<Room*>(item);
|
||||
result = room->getStatusIcon(false);
|
||||
}
|
||||
break;
|
||||
case Item::participant: {
|
||||
if (index.column() != 0) {
|
||||
break;
|
||||
}
|
||||
Participant* p = static_cast<Participant*>(item);
|
||||
result = p->getStatusIcon(false);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue