1
0
Fork 0
forked from blue/squawk

hopefully end of refactoring of vcard to Info widget

This commit is contained in:
Blue 2023-02-20 21:12:32 +03:00
parent bf11d8a74e
commit e4a2728ef8
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
20 changed files with 268 additions and 1717 deletions

View file

@ -138,8 +138,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
}
}
Account::~Account()
{
Account::~Account() {
if (reconnectScheduled) {
reconnectScheduled = false;
reconnectTimer->stop();
@ -166,13 +165,10 @@ Account::~Account()
delete cm;
}
Shared::ConnectionState Core::Account::getState() const
{
return state;
}
Shared::ConnectionState Core::Account::getState() const {
return state;}
void Core::Account::connect()
{
void Core::Account::connect() {
if (reconnectScheduled) {
reconnectScheduled = false;
reconnectTimer->stop();
@ -194,16 +190,14 @@ void Core::Account::connect()
}
}
void Core::Account::onReconnectTimer()
{
void Core::Account::onReconnectTimer() {
if (reconnectScheduled) {
reconnectScheduled = false;
connect();
}
}
void Core::Account::disconnect()
{
void Core::Account::disconnect() {
if (reconnectScheduled) {
reconnectScheduled = false;
reconnectTimer->stop();
@ -219,8 +213,7 @@ void Core::Account::disconnect()
}
}
void Core::Account::onClientStateChange(QXmppClient::State st)
{
void Core::Account::onClientStateChange(QXmppClient::State st) {
switch (st) {
case QXmppClient::ConnectedState: {
if (state != Shared::ConnectionState::connected) {
@ -279,8 +272,7 @@ void Core::Account::onClientStateChange(QXmppClient::State st)
}
}
void Core::Account::reconnect()
{
void Core::Account::reconnect() {
if (!reconnectScheduled) { //TODO define behavior if It was connection or disconnecting
if (state == Shared::ConnectionState::connected) {
reconnectScheduled = true;
@ -292,8 +284,7 @@ void Core::Account::reconnect()
}
}
Shared::Availability Core::Account::getAvailability() const
{
Shared::Availability Core::Account::getAvailability() const {
if (state == Shared::ConnectionState::connected) {
QXmppPresence::AvailableStatusType pres = presence.availableStatusType();
return static_cast<Shared::Availability>(pres); //they are compatible;
@ -302,8 +293,7 @@ Shared::Availability Core::Account::getAvailability() const
}
}
void Core::Account::setAvailability(Shared::Availability avail)
{
void Core::Account::setAvailability(Shared::Availability avail) {
if (avail == Shared::Availability::offline) {
disconnect(); //TODO not sure how to do here - changing state may cause connection or disconnection
} else {
@ -323,23 +313,21 @@ void Core::Account::runDiscoveryService() {
}
void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
{
void Core::Account::onPresenceReceived(const QXmppPresence& p_presence) {
QString id = p_presence.from();
QStringList comps = id.split("/");
QString jid = comps.front().toLower();
QString resource = comps.back();
if (jid == getBareJid()) {
if (resource == getResource()) {
if (resource == getResource())
emit availabilityChanged(static_cast<Shared::Availability>(p_presence.availableStatusType()));
}
vh->handlePresenceOfMyAccountChange(p_presence);
} else {
RosterItem* item = rh->getRosterItem(jid);
if (item != 0) {
if (item != 0)
item->handlePresence(p_presence);
}
}
switch (p_presence.type()) {
@ -382,8 +370,7 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
}
}
void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMessage& msg)
{
void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMessage& msg) {
if (msg.id().size() > 0 && (msg.body().size() > 0 || msg.outOfBandUrl().size() > 0)) {
std::map<QString, QString>::const_iterator itr = archiveQueries.find(queryId);
if (itr != archiveQueries.end()) {
@ -395,17 +382,15 @@ void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMess
sMsg.setState(Shared::Message::State::sent);
QString oId = msg.replaceId();
if (oId.size() > 0) {
if (oId.size() > 0)
item->correctMessageInArchive(oId, sMsg);
} else {
else
item->addMessageToArchive(sMsg);
}
}
}
}
void Core::Account::requestArchive(const QString& jid, int count, const QString& before)
{
void Core::Account::requestArchive(const QString& jid, int count, const QString& before) {
qDebug() << "An archive request for " << jid << ", before " << before;
RosterItem* contact = rh->getRosterItem(jid);
@ -423,8 +408,7 @@ void Core::Account::requestArchive(const QString& jid, int count, const QString&
contact->requestHistory(count, before);
}
void Core::Account::onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at)
{
void Core::Account::onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at) {
RosterItem* contact = static_cast<RosterItem*>(sender());
QString to;
@ -468,8 +452,7 @@ void Core::Account::onContactNeedHistory(const QString& before, const QString& a
archiveQueries.insert(std::make_pair(q, contact->jid));
}
void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResultSetReply& resultSetReply, bool complete)
{
void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResultSetReply& resultSetReply, bool complete) {
std::map<QString, QString>::const_iterator itr = archiveQueries.find(queryId);
if (itr != archiveQueries.end()) {
QString jid = itr->second;
@ -484,14 +467,12 @@ void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResu
}
}
void Core::Account::onMamLog(QXmppLogger::MessageType type, const QString& msg)
{
void Core::Account::onMamLog(QXmppLogger::MessageType type, const QString& msg) {
qDebug() << "MAM MESSAGE LOG::";
qDebug() << msg;
}
void Core::Account::onClientError(QXmppClient::Error err)
{
void Core::Account::onClientError(QXmppClient::Error err) {
qDebug() << "Error";
QString errorText;
QString errorType;
@ -601,22 +582,18 @@ void Core::Account::onClientError(QXmppClient::Error err)
emit error(errorText);
}
void Core::Account::subscribeToContact(const QString& jid, const QString& reason)
{
if (state == Shared::ConnectionState::connected) {
void Core::Account::subscribeToContact(const QString& jid, const QString& reason) {
if (state == Shared::ConnectionState::connected)
rm->subscribe(jid, reason);
} else {
else
qDebug() << "An attempt to subscribe account " << name << " to contact " << jid << " but the account is not in the connected state, skipping";
}
}
void Core::Account::unsubscribeFromContact(const QString& jid, const QString& reason)
{
if (state == Shared::ConnectionState::connected) {
void Core::Account::unsubscribeFromContact(const QString& jid, const QString& reason) {
if (state == Shared::ConnectionState::connected)
rm->unsubscribe(jid, reason);
} else {
else
qDebug() << "An attempt to unsubscribe account " << name << " from contact " << jid << " but the account is not in the connected state, skipping";
}
}
void Core::Account::removeContactRequest(const QString& jid) {
@ -625,8 +602,7 @@ void Core::Account::removeContactRequest(const QString& jid) {
void Core::Account::addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups) {
rh->addContactRequest(jid, name, groups);}
void Core::Account::setRoomAutoJoin(const QString& jid, bool joined)
{
void Core::Account::setRoomAutoJoin(const QString& jid, bool joined) {
Conference* conf = rh->getConference(jid);
if (conf == 0) {
qDebug() << "An attempt to set auto join to the non existing room" << jid << "of the account" << getName() << ", skipping";
@ -636,8 +612,7 @@ void Core::Account::setRoomAutoJoin(const QString& jid, bool joined)
conf->setAutoJoin(joined);
}
void Core::Account::setRoomJoined(const QString& jid, bool joined)
{
void Core::Account::setRoomJoined(const QString& jid, bool joined) {
Conference* conf = rh->getConference(jid);
if (conf == 0) {
qDebug() << "An attempt to set joined to the non existing room" << jid << "of the account" << getName() << ", skipping";
@ -657,16 +632,14 @@ void Core::Account::discoverInfo(const QString& address, const QString& node) {
}
}
void Core::Account::setPepSupport(Shared::Support support)
{
void Core::Account::setPepSupport(Shared::Support support) {
if (support != pepSupport) {
pepSupport = support;
emit pepSupportChanged(pepSupport);
}
}
void Core::Account::handleDisconnection()
{
void Core::Account::handleDisconnection() {
setPepSupport(Shared::Support::unknown);
cm->setCarbonsEnabled(false);
rh->handleOffline();
@ -674,14 +647,13 @@ void Core::Account::handleDisconnection()
archiveQueries.clear();
}
void Core::Account::onContactHistoryResponse(const std::list<Shared::Message>& list, bool last)
{
void Core::Account::onContactHistoryResponse(const std::list<Shared::Message>& list, bool last) {
RosterItem* contact = static_cast<RosterItem*>(sender());
qDebug() << "Collected history for contact " << contact->jid << list.size() << "elements";
if (last) {
if (last)
qDebug() << "The response contains the first accounted message";
}
emit responseArchive(contact->jid, list, last);
}
@ -754,11 +726,17 @@ void Core::Account::resendMessage(const QString& jid, const QString& id) {
void Core::Account::replaceMessage(const QString& originalId, const Shared::Message& data) {
mh->sendMessage(data, false, originalId);}
void Core::Account::requestVCard(const QString& jid) {
vh->requestVCard(jid);}
void Core::Account::requestInfo(const QString& jid) {
//TODO switch case of what kind of entity this info request is about
//right now it could be only about myself or some contact
vh->requestVCard(jid);
}
void Core::Account::uploadVCard(const Shared::VCard& card) {
vh->uploadVCard(card);}
void Core::Account::updateInfo(const Shared::Info& info) {
//TODO switch case of what kind of entity this info update is about
//right now it could be only about myself
vh->uploadVCard(info.vcard);
}
QString Core::Account::getAvatarPath() const {
return vh->getAvatarPath();}