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
|
@ -30,7 +30,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
client(),
|
||||
config(),
|
||||
presence(),
|
||||
state(Shared::disconnected),
|
||||
state(Shared::ConnectionState::disconnected),
|
||||
groups(),
|
||||
cm(new QXmppCarbonManager()),
|
||||
am(new QXmppMamManager()),
|
||||
|
@ -182,9 +182,9 @@ Shared::ConnectionState Core::Account::getState() const
|
|||
|
||||
void Core::Account::connect()
|
||||
{
|
||||
if (state == Shared::disconnected) {
|
||||
if (state == Shared::ConnectionState::disconnected) {
|
||||
reconnectTimes = maxReconnectTimes;
|
||||
state = Shared::connecting;
|
||||
state = Shared::ConnectionState::connecting;
|
||||
client.connectToServer(config, presence);
|
||||
emit connectionStateChanged(state);
|
||||
} else {
|
||||
|
@ -195,19 +195,19 @@ void Core::Account::connect()
|
|||
void Core::Account::disconnect()
|
||||
{
|
||||
reconnectTimes = 0;
|
||||
if (state != Shared::disconnected) {
|
||||
if (state != Shared::ConnectionState::disconnected) {
|
||||
clearConferences();
|
||||
client.disconnectFromServer();
|
||||
state = Shared::disconnected;
|
||||
state = Shared::ConnectionState::disconnected;
|
||||
emit connectionStateChanged(state);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::onClientConnected()
|
||||
{
|
||||
if (state == Shared::connecting) {
|
||||
if (state == Shared::ConnectionState::connecting) {
|
||||
reconnectTimes = maxReconnectTimes;
|
||||
state = Shared::connected;
|
||||
state = Shared::ConnectionState::connected;
|
||||
dm->requestItems(getServer());
|
||||
dm->requestInfo(getServer());
|
||||
emit connectionStateChanged(state);
|
||||
|
@ -219,16 +219,16 @@ void Core::Account::onClientConnected()
|
|||
void Core::Account::onClientDisconnected()
|
||||
{
|
||||
clearConferences();
|
||||
if (state != Shared::disconnected) {
|
||||
if (state != Shared::ConnectionState::disconnected) {
|
||||
if (reconnectTimes > 0) {
|
||||
qDebug() << "Account" << name << "is reconnecting for" << reconnectTimes << "more times";
|
||||
--reconnectTimes;
|
||||
state = Shared::connecting;
|
||||
state = Shared::ConnectionState::connecting;
|
||||
client.connectToServer(config, presence);
|
||||
emit connectionStateChanged(state);
|
||||
} else {
|
||||
qDebug() << "Account" << name << "has been disconnected";
|
||||
state = Shared::disconnected;
|
||||
state = Shared::ConnectionState::disconnected;
|
||||
emit connectionStateChanged(state);
|
||||
}
|
||||
} else {
|
||||
|
@ -238,7 +238,7 @@ void Core::Account::onClientDisconnected()
|
|||
|
||||
void Core::Account::reconnect()
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
++reconnectTimes;
|
||||
client.disconnectFromServer();
|
||||
} else {
|
||||
|
@ -281,7 +281,7 @@ void Core::Account::onRosterReceived()
|
|||
void Core::Account::setReconnectTimes(unsigned int times)
|
||||
{
|
||||
maxReconnectTimes = times;
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
reconnectTimes = times;
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ void Core::Account::addedAccount(const QString& jid)
|
|||
if (newContact) {
|
||||
QMap<QString, QVariant> cData({
|
||||
{"name", re.name()},
|
||||
{"state", state}
|
||||
{"state", QVariant::fromValue(state)}
|
||||
});
|
||||
|
||||
Archive::AvatarInfo info;
|
||||
|
@ -427,7 +427,7 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
|
|||
|
||||
if (jid == myJid) {
|
||||
if (resource == getResource()) {
|
||||
emit availabilityChanged(p_presence.availableStatusType());
|
||||
emit availabilityChanged(static_cast<Shared::Availability>(p_presence.availableStatusType()));
|
||||
} else {
|
||||
if (!ownVCardRequestInProgress) {
|
||||
switch (p_presence.vCardUpdateType()) {
|
||||
|
@ -521,21 +521,25 @@ void Core::Account::setServer(const QString& p_server)
|
|||
|
||||
Shared::Availability Core::Account::getAvailability() const
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
QXmppPresence::AvailableStatusType pres = presence.availableStatusType();
|
||||
return static_cast<Shared::Availability>(pres); //they are compatible;
|
||||
} else {
|
||||
return Shared::offline;
|
||||
return Shared::Availability::offline;
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::setAvailability(Shared::Availability avail)
|
||||
{
|
||||
QXmppPresence::AvailableStatusType pres = static_cast<QXmppPresence::AvailableStatusType>(avail);
|
||||
|
||||
presence.setAvailableStatusType(pres);
|
||||
if (state != Shared::disconnected) { //TODO not sure how to do here - changing state may cause connection or disconnection
|
||||
client.setClientPresence(presence);
|
||||
if (avail == Shared::Availability::offline) {
|
||||
disconnect(); //TODO not sure how to do here - changing state may cause connection or disconnection
|
||||
} else {
|
||||
QXmppPresence::AvailableStatusType pres = static_cast<QXmppPresence::AvailableStatusType>(avail);
|
||||
|
||||
presence.setAvailableStatusType(pres);
|
||||
if (state != Shared::ConnectionState::disconnected) {
|
||||
client.setClientPresence(presence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,7 +628,7 @@ void Core::Account::sendMessage(Shared::Message data)
|
|||
QString jid = data.getPenPalJid();
|
||||
QString id = data.getId();
|
||||
RosterItem* ri = getRosterItem(jid);
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
QXmppMessage msg(getFullJid(), data.getTo(), data.getBody(), data.getThread());
|
||||
msg.setId(id);
|
||||
msg.setType(static_cast<QXmppMessage::Type>(data.getType())); //it is safe here, my type is compatible
|
||||
|
@ -660,7 +664,7 @@ void Core::Account::sendMessage(Shared::Message data)
|
|||
|
||||
void Core::Account::sendMessage(const Shared::Message& data, const QString& path)
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
QString url = network->getFileRemoteUrl(path);
|
||||
if (url.size() != 0) {
|
||||
sendMessageWithLocalUploadedFile(data, url);
|
||||
|
@ -727,9 +731,9 @@ bool Core::Account::handleChatMessage(const QXmppMessage& msg, bool outgoing, bo
|
|||
cnt = new Contact(jid, name);
|
||||
contacts.insert(std::make_pair(jid, cnt));
|
||||
outOfRosterContacts.insert(jid);
|
||||
cnt->setSubscriptionState(Shared::unknown);
|
||||
cnt->setSubscriptionState(Shared::SubscriptionState::unknown);
|
||||
emit addContact(jid, "", QMap<QString, QVariant>({
|
||||
{"state", Shared::unknown}
|
||||
{"state", QVariant::fromValue(Shared::SubscriptionState::unknown)}
|
||||
}));
|
||||
handleNewContact(cnt);
|
||||
}
|
||||
|
@ -963,7 +967,7 @@ void Core::Account::onContactGroupAdded(const QString& group)
|
|||
|
||||
QMap<QString, QVariant> cData({
|
||||
{"name", contact->getName()},
|
||||
{"state", contact->getSubscriptionState()}
|
||||
{"state", QVariant::fromValue(contact->getSubscriptionState())}
|
||||
});
|
||||
addToGroup(contact->jid, group);
|
||||
emit addContact(contact->jid, group, cData);
|
||||
|
@ -993,7 +997,7 @@ void Core::Account::onContactSubscriptionStateChanged(Shared::SubscriptionState
|
|||
{
|
||||
Contact* contact = static_cast<Contact*>(sender());
|
||||
QMap<QString, QVariant> cData({
|
||||
{"state", cstate},
|
||||
{"state", QVariant::fromValue(cstate)},
|
||||
});
|
||||
emit changeContact(contact->jid, cData);
|
||||
}
|
||||
|
@ -1031,7 +1035,7 @@ Shared::SubscriptionState Core::Account::castSubscriptionState(QXmppRosterIq::It
|
|||
{
|
||||
Shared::SubscriptionState state;
|
||||
if (qs == QXmppRosterIq::Item::NotSet) {
|
||||
state = Shared::unknown;
|
||||
state = Shared::SubscriptionState::unknown;
|
||||
} else {
|
||||
state = static_cast<Shared::SubscriptionState>(qs);
|
||||
}
|
||||
|
@ -1145,7 +1149,7 @@ void Core::Account::onClientError(QXmppClient::Error err)
|
|||
|
||||
void Core::Account::subscribeToContact(const QString& jid, const QString& reason)
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
rm->subscribe(jid, reason);
|
||||
} else {
|
||||
qDebug() << "An attempt to subscribe account " << name << " to contact " << jid << " but the account is not in the connected state, skipping";
|
||||
|
@ -1154,7 +1158,7 @@ void Core::Account::subscribeToContact(const QString& jid, const QString& reason
|
|||
|
||||
void Core::Account::unsubscribeFromContact(const QString& jid, const QString& reason)
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
rm->unsubscribe(jid, reason);
|
||||
} else {
|
||||
qDebug() << "An attempt to unsubscribe account " << name << " from contact " << jid << " but the account is not in the connected state, skipping";
|
||||
|
@ -1163,7 +1167,7 @@ void Core::Account::unsubscribeFromContact(const QString& jid, const QString& re
|
|||
|
||||
void Core::Account::removeContactRequest(const QString& jid)
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
std::set<QString>::const_iterator itr = outOfRosterContacts.find(jid);
|
||||
if (itr != outOfRosterContacts.end()) {
|
||||
outOfRosterContacts.erase(itr);
|
||||
|
@ -1179,7 +1183,7 @@ void Core::Account::removeContactRequest(const QString& jid)
|
|||
|
||||
void Core::Account::addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups)
|
||||
{
|
||||
if (state == Shared::connected) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
std::map<QString, QString>::const_iterator itr = queuedContacts.find(jid);
|
||||
if (itr != queuedContacts.end()) {
|
||||
qDebug() << "An attempt to add contact " << jid << " to account " << name << " but the account is already queued for adding, skipping";
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include <QXmppVCardManager.h>
|
||||
#include <QXmppMessageReceiptManager.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "shared.h"
|
||||
#include "contact.h"
|
||||
#include "conference.h"
|
||||
#include "networkaccess.h"
|
||||
|
@ -101,8 +101,8 @@ public slots:
|
|||
|
||||
signals:
|
||||
void changed(const QMap<QString, QVariant>& data);
|
||||
void connectionStateChanged(int);
|
||||
void availabilityChanged(int);
|
||||
void connectionStateChanged(Shared::ConnectionState);
|
||||
void availabilityChanged(Shared::Availability);
|
||||
void addGroup(const QString& name);
|
||||
void removeGroup(const QString& name);
|
||||
void addRoom(const QString& jid, const QMap<QString, QVariant>& data);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <QMimeDatabase>
|
||||
#include <QMimeType>
|
||||
|
||||
#include "global.h"
|
||||
#include "shared/message.h"
|
||||
#include "exception.h"
|
||||
#include <lmdb.h>
|
||||
#include <list>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
Core::Contact::Contact(const QString& pJid, const QString& account, QObject* parent):
|
||||
RosterItem(pJid, account, parent),
|
||||
groups(),
|
||||
subscriptionState(Shared::unknown)
|
||||
subscriptionState(Shared::SubscriptionState::unknown)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,9 @@
|
|||
#include <QXmppVCardIq.h>
|
||||
#include <QXmppPresence.h>
|
||||
|
||||
#include "../global.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/message.h"
|
||||
#include "shared/vcard.h"
|
||||
#include "archive.h"
|
||||
|
||||
namespace Core {
|
||||
|
|
|
@ -146,8 +146,8 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
|
|||
{"name", name},
|
||||
{"password", password},
|
||||
{"resource", resource},
|
||||
{"state", Shared::disconnected},
|
||||
{"offline", Shared::offline},
|
||||
{"state", QVariant::fromValue(Shared::ConnectionState::disconnected)},
|
||||
{"offline", QVariant::fromValue(Shared::Availability::offline)},
|
||||
{"error", ""},
|
||||
{"avatarPath", acc->getAvatarPath()}
|
||||
};
|
||||
|
@ -155,14 +155,11 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
|
|||
emit newAccount(map);
|
||||
}
|
||||
|
||||
void Core::Squawk::changeState(int p_state)
|
||||
void Core::Squawk::changeState(Shared::Availability p_state)
|
||||
{
|
||||
Shared::Availability avail;
|
||||
if (p_state < Shared::availabilityLowest && p_state > Shared::availabilityHighest) {
|
||||
qDebug("An attempt to set invalid availability to Squawk core, skipping");
|
||||
if (state != p_state) {
|
||||
state = p_state;
|
||||
}
|
||||
avail = static_cast<Shared::Availability>(p_state);
|
||||
state = avail;
|
||||
|
||||
for (std::deque<Account*>::iterator itr = accounts.begin(), end = accounts.end(); itr != end; ++itr) {
|
||||
(*itr)->setAvailability(state);
|
||||
|
@ -190,20 +187,20 @@ void Core::Squawk::disconnectAccount(const QString& account)
|
|||
itr->second->disconnect();
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountConnectionStateChanged(int state)
|
||||
void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_state)
|
||||
{
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
emit changeAccount(acc->getName(), {{"state", state}});
|
||||
emit changeAccount(acc->getName(), {{"state", QVariant::fromValue(p_state)}});
|
||||
|
||||
if (state == Shared::disconnected) {
|
||||
if (p_state == Shared::ConnectionState::disconnected) {
|
||||
bool equals = true;
|
||||
for (Accounts::const_iterator itr = accounts.begin(), end = accounts.end(); itr != end; itr++) {
|
||||
if ((*itr)->getState() != Shared::disconnected) {
|
||||
if ((*itr)->getState() != Shared::ConnectionState::disconnected) {
|
||||
equals = false;
|
||||
}
|
||||
}
|
||||
if (equals) {
|
||||
state = Shared::offline;
|
||||
if (equals && state != Shared::Availability::offline) {
|
||||
state = Shared::Availability::offline;
|
||||
emit stateChanged(state);
|
||||
}
|
||||
}
|
||||
|
@ -257,10 +254,10 @@ void Core::Squawk::onAccountRemovePresence(const QString& jid, const QString& na
|
|||
emit removePresence(acc->getName(), jid, name);
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountAvailabilityChanged(int state)
|
||||
void Core::Squawk::onAccountAvailabilityChanged(Shared::Availability state)
|
||||
{
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
emit changeAccount(acc->getName(), {{"availability", state}});
|
||||
emit changeAccount(acc->getName(), {{"availability", QVariant::fromValue(state)}});
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountChanged(const QMap<QString, QVariant>& data)
|
||||
|
@ -324,7 +321,7 @@ void Core::Squawk::modifyAccountRequest(const QString& name, const QMap<QString,
|
|||
Core::Account* acc = itr->second;
|
||||
Shared::ConnectionState st = acc->getState();
|
||||
|
||||
if (st != Shared::disconnected) {
|
||||
if (st != Shared::ConnectionState::disconnected) {
|
||||
acc->reconnect();
|
||||
}
|
||||
|
||||
|
@ -367,7 +364,7 @@ void Core::Squawk::removeAccountRequest(const QString& name)
|
|||
}
|
||||
|
||||
Account* acc = itr->second;
|
||||
if (acc->getState() != Shared::disconnected) {
|
||||
if (acc->getState() != Shared::ConnectionState::disconnected) {
|
||||
acc->disconnect();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
#include <deque>
|
||||
|
||||
#include "account.h"
|
||||
#include "../global.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/message.h"
|
||||
#include "shared/global.h"
|
||||
#include "networkaccess.h"
|
||||
|
||||
namespace Core
|
||||
|
@ -54,7 +56,7 @@ signals:
|
|||
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);
|
||||
void stateChanged(int state);
|
||||
void stateChanged(Shared::Availability state);
|
||||
void accountMessage(const QString& account, const Shared::Message& data);
|
||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list);
|
||||
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||
|
@ -79,7 +81,7 @@ public slots:
|
|||
void removeAccountRequest(const QString& name);
|
||||
void connectAccount(const QString& account);
|
||||
void disconnectAccount(const QString& account);
|
||||
void changeState(int state);
|
||||
void changeState(Shared::Availability state);
|
||||
void sendMessage(const QString& account, const Shared::Message& data);
|
||||
void sendMessage(const QString& account, const Shared::Message& data, const QString& path);
|
||||
void requestArchive(const QString& account, const QString& jid, int count, const QString& before);
|
||||
|
@ -112,8 +114,8 @@ private:
|
|||
void addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource);
|
||||
|
||||
private slots:
|
||||
void onAccountConnectionStateChanged(int state);
|
||||
void onAccountAvailabilityChanged(int state);
|
||||
void onAccountConnectionStateChanged(Shared::ConnectionState state);
|
||||
void onAccountAvailabilityChanged(Shared::Availability state);
|
||||
void onAccountChanged(const QMap<QString, QVariant>& data);
|
||||
void onAccountAddGroup(const QString& name);
|
||||
void onAccountError(const QString& text);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue