1
0
Fork 0
forked from blue/squawk

account connect/disconnect now activate/deactivate, it's a bit less contraversial; async account password asking new concept

This commit is contained in:
Blue 2022-04-12 23:33:10 +03:00
parent 2c26c7e264
commit f64e5c2df0
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
13 changed files with 248 additions and 200 deletions

View file

@ -22,7 +22,7 @@
using namespace Core;
Account::Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, NetworkAccess* p_net, QObject* parent):
Account::Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, bool p_active, NetworkAccess* p_net, QObject* parent):
QObject(parent),
name(p_name),
archiveQueries(),
@ -44,6 +44,8 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
network(p_net),
passwordType(Shared::AccountPassword::plain),
pepSupport(false),
active(p_active),
notReadyPassword(false),
mh(new MessageHandler(this)),
rh(new RosterHandler(this)),
vh(new VCardHandler(this))
@ -89,13 +91,15 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
reconnectTimer->setSingleShot(true);
QObject::connect(reconnectTimer, &QTimer::timeout, this, &Account::onReconnectTimer);
// QXmppLogger* logger = new QXmppLogger(this);
// logger->setLoggingType(QXmppLogger::SignalLogging);
// client.setLogger(logger);
//
// QObject::connect(logger, &QXmppLogger::message, this, [](QXmppLogger::MessageType type, const QString& text){
// qDebug() << text;
// });
if (name == "Test") {
QXmppLogger* logger = new QXmppLogger(this);
logger->setLoggingType(QXmppLogger::SignalLogging);
client.setLogger(logger);
QObject::connect(logger, &QXmppLogger::message, this, [](QXmppLogger::MessageType type, const QString& text){
qDebug() << text;
});
}
}
Account::~Account()
@ -135,7 +139,12 @@ void Core::Account::connect()
reconnectTimer->stop();
}
if (state == Shared::ConnectionState::disconnected) {
client.connectToServer(config, presence);
if (notReadyPassword) {
emit needPassword();
} else {
client.connectToServer(config, presence);
}
} else {
qDebug("An attempt to connect an account which is already connected, skipping");
}
@ -205,12 +214,14 @@ void Core::Account::onClientStateChange(QXmppClient::State st)
void Core::Account::reconnect()
{
if (state == Shared::ConnectionState::connected && !reconnectScheduled) {
reconnectScheduled = true;
reconnectTimer->start(500);
client.disconnectFromServer();
} else {
qDebug() << "An attempt to reconnect account" << getName() << "which was not connected";
if (!reconnectScheduled) { //TODO define behavior if It was connection or disconnecting
if (state == Shared::ConnectionState::connected) {
reconnectScheduled = true;
reconnectTimer->start(500);
client.disconnectFromServer();
} else {
qDebug() << "An attempt to reconnect account" << getName() << "which was not connected";
}
}
}
@ -636,6 +647,19 @@ void Core::Account::onContactHistoryResponse(const std::list<Shared::Message>& l
emit responseArchive(contact->jid, list, last);
}
bool Core::Account::getActive() const {
return active;}
void Core::Account::setActive(bool p_active) {
if (active != p_active) {
active = p_active;
emit changed({
{"active", active}
});
}
}
QString Core::Account::getResource() const {
return config.resource();}
@ -673,7 +697,9 @@ void Core::Account::setName(const QString& p_name) {
name = p_name;}
void Core::Account::setPassword(const QString& p_password) {
config.setPassword(p_password);}
config.setPassword(p_password);
notReadyPassword = false;
}
void Core::Account::setServer(const QString& p_server) {
config.setDomain(p_server);}
@ -720,3 +746,7 @@ void Core::Account::renameContactRequest(const QString& jid, const QString& newN
rm->renameItem(jid, newName);
}
}
void Core::Account::invalidatePassword() {
notReadyPassword = true;}