forked from blue/squawk
Shared namespace refactoring, enum class refactoring, going offline related crash fix
This commit is contained in:
parent
b309100f99
commit
ddfb3419cc
59 changed files with 1948 additions and 1695 deletions
|
@ -22,7 +22,7 @@ using namespace Models;
|
|||
|
||||
Models::AbstractParticipant::AbstractParticipant(Models::Item::Type p_type, const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
||||
Item(p_type, data, parentItem),
|
||||
availability(Shared::offline),
|
||||
availability(Shared::Availability::offline),
|
||||
lastActivity(data.value("lastActivity").toDateTime()),
|
||||
status(data.value("status").toString())
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ QVariant Models::AbstractParticipant::data(int column) const
|
|||
case 1:
|
||||
return lastActivity;
|
||||
case 2:
|
||||
return availability;
|
||||
return QVariant::fromValue(availability);
|
||||
case 3:
|
||||
return status;
|
||||
default:
|
||||
|
@ -91,15 +91,9 @@ void Models::AbstractParticipant::setAvailability(Shared::Availability p_avail)
|
|||
|
||||
void Models::AbstractParticipant::setAvailability(unsigned int avail)
|
||||
{
|
||||
if (avail <= Shared::availabilityHighest) {
|
||||
Shared::Availability state = static_cast<Shared::Availability>(avail);
|
||||
setAvailability(state);
|
||||
} else {
|
||||
qDebug("An attempt to set wrong state to the contact");
|
||||
}
|
||||
setAvailability(Shared::Global::fromInt<Shared::Availability>(avail));
|
||||
}
|
||||
|
||||
|
||||
void Models::AbstractParticipant::setLastActivity(const QDateTime& p_time)
|
||||
{
|
||||
if (lastActivity != p_time) {
|
||||
|
|
|
@ -21,8 +21,12 @@
|
|||
|
||||
|
||||
#include "item.h"
|
||||
#include "../../global.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/icons.h"
|
||||
#include "shared/global.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace Models {
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* pare
|
|||
resource(data.value("resource").toString()),
|
||||
error(data.value("error").toString()),
|
||||
avatarPath(data.value("avatarPath").toString()),
|
||||
state(Shared::disconnected),
|
||||
availability(Shared::offline)
|
||||
state(Shared::ConnectionState::disconnected),
|
||||
availability(Shared::Availability::offline)
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator sItr = data.find("state");
|
||||
if (sItr != data.end()) {
|
||||
|
@ -49,7 +49,7 @@ void Models::Account::setState(Shared::ConnectionState p_state)
|
|||
if (state != p_state) {
|
||||
state = p_state;
|
||||
changed(2);
|
||||
if (state == Shared::disconnected) {
|
||||
if (state == Shared::ConnectionState::disconnected) {
|
||||
toOfflineState();
|
||||
}
|
||||
}
|
||||
|
@ -57,22 +57,12 @@ void Models::Account::setState(Shared::ConnectionState 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;
|
||||
}
|
||||
setAvailability(Shared::Global::fromInt<Shared::Availability>(p_state));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
setState(Shared::Global::fromInt<Shared::ConnectionState>(p_state));
|
||||
}
|
||||
|
||||
Shared::Availability Models::Account::getAvailability() const
|
||||
|
@ -90,10 +80,10 @@ void Models::Account::setAvailability(Shared::Availability p_avail)
|
|||
|
||||
QIcon Models::Account::getStatusIcon(bool big) const
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
return Shared::availabilityIcon(availability, big);
|
||||
} else if (state == Shared::disconnected) {
|
||||
return Shared::availabilityIcon(Shared::offline, big);
|
||||
} else if (state == Shared::ConnectionState::disconnected) {
|
||||
return Shared::availabilityIcon(Shared::Availability::offline, big);
|
||||
} else {
|
||||
return Shared::connectionStateIcon(state);
|
||||
}
|
||||
|
@ -152,7 +142,7 @@ QVariant Models::Account::data(int column) const
|
|||
case 1:
|
||||
return server;
|
||||
case 2:
|
||||
return QCoreApplication::translate("Global", Shared::connectionStateNames[state].toLatin1());
|
||||
return Shared::Global::getName(state);
|
||||
case 3:
|
||||
return error;
|
||||
case 4:
|
||||
|
@ -160,7 +150,7 @@ QVariant Models::Account::data(int column) const
|
|||
case 5:
|
||||
return password;
|
||||
case 6:
|
||||
return QCoreApplication::translate("Global", Shared::availabilityNames[availability].toLatin1());
|
||||
return Shared::Global::getName(availability);
|
||||
case 7:
|
||||
return resource;
|
||||
case 8:
|
||||
|
@ -226,7 +216,7 @@ void Models::Account::setError(const QString& p_resource)
|
|||
|
||||
void Models::Account::toOfflineState()
|
||||
{
|
||||
setAvailability(Shared::offline);
|
||||
setAvailability(Shared::Availability::offline);
|
||||
Item::toOfflineState();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
#ifndef MODELS_ACCOUNT_H
|
||||
#define MODELS_ACCOUNT_H
|
||||
|
||||
#include "../../global.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/utils.h"
|
||||
#include "shared/icons.h"
|
||||
#include "shared/global.h"
|
||||
#include "item.h"
|
||||
#include <QVariant>
|
||||
#include <QIcon>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "accounts.h"
|
||||
#include "../../global.h"
|
||||
#include "shared/icons.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
Models::Contact::Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem):
|
||||
Item(Item::contact, data, parentItem),
|
||||
jid(p_jid),
|
||||
availability(Shared::offline),
|
||||
state(Shared::none),
|
||||
availability(Shared::Availability::offline),
|
||||
state(Shared::SubscriptionState::none),
|
||||
avatarState(Shared::Avatar::empty),
|
||||
presences(),
|
||||
messages(),
|
||||
|
@ -66,22 +66,12 @@ void Models::Contact::setJid(const QString p_jid)
|
|||
|
||||
void Models::Contact::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 contact " << jid;
|
||||
}
|
||||
setAvailability(Shared::Global::fromInt<Shared::Availability>(p_state));
|
||||
}
|
||||
|
||||
void Models::Contact::setState(unsigned int p_state)
|
||||
{
|
||||
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;
|
||||
}
|
||||
setState(Shared::Global::fromInt<Shared::SubscriptionState>(p_state));
|
||||
}
|
||||
|
||||
Shared::Availability Models::Contact::getAvailability() const
|
||||
|
@ -123,15 +113,15 @@ QVariant Models::Contact::data(int column) const
|
|||
case 1:
|
||||
return jid;
|
||||
case 2:
|
||||
return state;
|
||||
return QVariant::fromValue(state);
|
||||
case 3:
|
||||
return availability;
|
||||
return QVariant::fromValue(availability);
|
||||
case 4:
|
||||
return getMessagesCount();
|
||||
case 5:
|
||||
return getStatus();
|
||||
case 6:
|
||||
return static_cast<quint8>(getAvatarState());
|
||||
return QVariant::fromValue(getAvatarState());
|
||||
case 7:
|
||||
return getAvatarPath();
|
||||
default:
|
||||
|
@ -216,7 +206,7 @@ void Models::Contact::refresh()
|
|||
setAvailability(presence->getAvailability());
|
||||
setStatus(presence->getStatus());
|
||||
} else {
|
||||
setAvailability(Shared::offline);
|
||||
setAvailability(Shared::Availability::offline);
|
||||
setStatus("");
|
||||
}
|
||||
|
||||
|
@ -258,7 +248,7 @@ QIcon Models::Contact::getStatusIcon(bool big) const
|
|||
{
|
||||
if (getMessagesCount() > 0) {
|
||||
return Shared::icon("mail-message", big);
|
||||
} else if (state == Shared::both || state == Shared::to) {
|
||||
} else if (state == Shared::SubscriptionState::both || state == Shared::SubscriptionState::to) {
|
||||
return Shared::availabilityIcon(availability, big);;
|
||||
} else {
|
||||
return Shared::subscriptionStateIcon(state, big);
|
||||
|
@ -276,7 +266,7 @@ void Models::Contact::addMessage(const Shared::Message& data)
|
|||
// the only issue is to find out when the sender is gone offline
|
||||
Presence* pr = new Presence({});
|
||||
pr->setName(res);
|
||||
pr->setAvailability(Shared::invisible);
|
||||
pr->setAvailability(Shared::Availability::invisible);
|
||||
pr->setLastActivity(QDateTime::currentDateTimeUtc());
|
||||
presences.insert(res, pr);
|
||||
appendChild(pr);
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
|
||||
#include "item.h"
|
||||
#include "presence.h"
|
||||
#include "global.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/message.h"
|
||||
#include "shared/icons.h"
|
||||
#include "shared/global.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QIcon>
|
||||
#include <deque>
|
||||
|
|
|
@ -96,7 +96,7 @@ unsigned int Models::Group::getOnlineContacts() const
|
|||
|
||||
for (std::deque<Models::Item*>::const_iterator itr = childItems.begin(), end = childItems.end(); itr != end; ++itr) {
|
||||
Models::Contact* cnt = static_cast<Models::Contact*>(*itr);
|
||||
if (cnt->getAvailability() != Shared::offline) {
|
||||
if (cnt->getAvailability() != Shared::Availability::offline) {
|
||||
++amount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ Shared::Availability Models::Item::getAccountAvailability() const
|
|||
{
|
||||
const Account* acc = static_cast<const Account*>(getParentAccount());
|
||||
if (acc == 0) {
|
||||
return Shared::offline;
|
||||
return Shared::Availability::offline;
|
||||
}
|
||||
return acc->getAvailability();
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ Shared::ConnectionState Models::Item::getAccountConnectionState() const
|
|||
{
|
||||
const Account* acc = static_cast<const Account*>(getParentAccount());
|
||||
if (acc == 0) {
|
||||
return Shared::disconnected;
|
||||
return Shared::ConnectionState::disconnected;
|
||||
}
|
||||
return acc->getState();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <deque>
|
||||
|
||||
#include "../../global.h"
|
||||
#include "shared/enums.h"
|
||||
|
||||
namespace Models {
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "presence.h"
|
||||
#include "shared/icons.h"
|
||||
|
||||
Models::Presence::Presence(const QMap<QString, QVariant>& data, Item* parentItem):
|
||||
AbstractParticipant(Item::presence, data, parentItem),
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
#define MODELS_PRESENCE_H
|
||||
|
||||
#include "abstractparticipant.h"
|
||||
#include "../../global.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/message.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QIcon>
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
|
||||
#include "room.h"
|
||||
#include "shared/icons.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -194,15 +196,15 @@ QIcon Models::Room::getStatusIcon(bool big) const
|
|||
} else {
|
||||
if (autoJoin) {
|
||||
if (joined) {
|
||||
return Shared::connectionStateIcon(Shared::connected, big);
|
||||
return Shared::connectionStateIcon(Shared::ConnectionState::connected, big);
|
||||
} else {
|
||||
return Shared::connectionStateIcon(Shared::disconnected, big);
|
||||
return Shared::connectionStateIcon(Shared::ConnectionState::disconnected, big);
|
||||
}
|
||||
} else {
|
||||
if (joined) {
|
||||
return Shared::connectionStateIcon(Shared::connecting, big);
|
||||
return Shared::connectionStateIcon(Shared::ConnectionState::connecting, big);
|
||||
} else {
|
||||
return Shared::connectionStateIcon(Shared::error, big);
|
||||
return Shared::connectionStateIcon(Shared::ConnectionState::error, big);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
#include "item.h"
|
||||
#include "participant.h"
|
||||
#include "global.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/message.h"
|
||||
|
||||
namespace Models {
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
switch (item->type) {
|
||||
case Item::account: {
|
||||
Account* acc = static_cast<Account*>(item);
|
||||
result = QCoreApplication::translate("Global", Shared::availabilityNames[acc->getAvailability()].toLatin1());
|
||||
result = Shared::Global::getName(acc->getAvailability());
|
||||
}
|
||||
break;
|
||||
case Item::contact: {
|
||||
|
@ -193,18 +193,18 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
}
|
||||
str += tr("Jabber ID: ") + contact->getJid() + "\n";
|
||||
Shared::SubscriptionState ss = contact->getState();
|
||||
if (ss == Shared::both || ss == Shared::to) {
|
||||
if (ss == Shared::SubscriptionState::both || ss == Shared::SubscriptionState::to) {
|
||||
Shared::Availability av = contact->getAvailability();
|
||||
str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1());
|
||||
if (av != Shared::offline) {
|
||||
str += tr("Availability: ") + Shared::Global::getName(av);
|
||||
if (av != Shared::Availability::offline) {
|
||||
QString s = contact->getStatus();
|
||||
if (s.size() > 0) {
|
||||
str += "\n" + tr("Status: ") + s;
|
||||
}
|
||||
}
|
||||
str += "\n" + tr("Subscription: ") + QCoreApplication::translate("Global", Shared::subscriptionStateNames[ss].toLatin1());
|
||||
str += "\n" + tr("Subscription: ") + Shared::Global::getName(ss);
|
||||
} else {
|
||||
str += tr("Subscription: ") + QCoreApplication::translate("Global", Shared::subscriptionStateNames[ss].toLatin1());
|
||||
str += tr("Subscription: ") + Shared::Global::getName(ss);
|
||||
}
|
||||
|
||||
result = str;
|
||||
|
@ -218,7 +218,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
str += tr("New messages: ") + std::to_string(mc).c_str() + "\n";
|
||||
}
|
||||
Shared::Availability av = contact->getAvailability();
|
||||
str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1());
|
||||
str += tr("Availability: ") + Shared::Global::getName(av);
|
||||
QString s = contact->getStatus();
|
||||
if (s.size() > 0) {
|
||||
str += "\n" + tr("Status: ") + s;
|
||||
|
@ -231,18 +231,14 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
Participant* p = static_cast<Participant*>(item);
|
||||
QString str("");
|
||||
Shared::Availability av = p->getAvailability();
|
||||
str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1()) + "\n";
|
||||
str += tr("Availability: ") + Shared::Global::getName(av) + "\n";
|
||||
QString s = p->getStatus();
|
||||
if (s.size() > 0) {
|
||||
str += tr("Status: ") + s + "\n";
|
||||
}
|
||||
|
||||
str += tr("Affiliation: ") +
|
||||
QCoreApplication::translate("Global",
|
||||
Shared::affiliationNames[static_cast<unsigned int>(p->getAffiliation())].toLatin1()) + "\n";
|
||||
str += tr("Role: ") +
|
||||
QCoreApplication::translate("Global",
|
||||
Shared::roleNames[static_cast<unsigned int>(p->getRole())].toLatin1());
|
||||
str += tr("Affiliation: ") + Shared::Global::getName(p->getAffiliation()) + "\n";
|
||||
str += tr("Role: ") + Shared::Global::getName(p->getRole());
|
||||
|
||||
result = str;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
#include <map>
|
||||
#include <QVector>
|
||||
|
||||
#include "global.h"
|
||||
#include "shared/message.h"
|
||||
#include "shared/global.h"
|
||||
#include "accounts.h"
|
||||
#include "item.h"
|
||||
#include "account.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue