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

@ -32,7 +32,8 @@ Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* pare
state(Shared::ConnectionState::disconnected),
availability(Shared::Availability::offline),
passwordType(Shared::AccountPassword::plain),
wasEverConnected(false)
wasEverConnected(false),
active(false)
{
QMap<QString, QVariant>::const_iterator sItr = data.find("state");
if (sItr != data.end()) {
@ -46,6 +47,10 @@ Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* pare
if (pItr != data.end()) {
setPasswordType(pItr.value().toUInt());
}
QMap<QString, QVariant>::const_iterator acItr = data.find("active");
if (acItr != data.end()) {
setActive(acItr.value().toBool());
}
}
Models::Account::~Account()
@ -176,6 +181,8 @@ QVariant Models::Account::data(int column) const
return avatarPath;
case 9:
return Shared::Global::getName(passwordType);
case 10:
return active;
default:
return QVariant();
}
@ -183,7 +190,7 @@ QVariant Models::Account::data(int column) const
int Models::Account::columnCount() const
{
return 10;
return 11;
}
void Models::Account::update(const QString& field, const QVariant& value)
@ -208,6 +215,8 @@ void Models::Account::update(const QString& field, const QVariant& value)
setAvatarPath(value.toString());
} else if (field == "passwordType") {
setPasswordType(value.toUInt());
} else if (field == "active") {
setActive(value.toBool());
}
}
@ -281,3 +290,16 @@ void Models::Account::setPasswordType(unsigned int pt)
{
setPasswordType(Shared::Global::fromInt<Shared::AccountPassword>(pt));
}
bool Models::Account::getActive() const
{
return active;
}
void Models::Account::setActive(bool p_active)
{
if (active != p_active) {
active = p_active;
changed(10);
}
}

View file

@ -58,6 +58,9 @@ namespace Models {
void setAvatarPath(const QString& path);
QString getAvatarPath() const;
void setActive(bool active);
bool getActive() const;
void setAvailability(Shared::Availability p_avail);
void setAvailability(unsigned int p_avail);
@ -91,6 +94,7 @@ namespace Models {
Shared::Availability availability;
Shared::AccountPassword passwordType;
bool wasEverConnected;
bool active;
protected slots:
void toOfflineState() override;

View file

@ -48,6 +48,10 @@ QVariant Models::Accounts::data (const QModelIndex& index, int role) const
answer = Shared::connectionStateIcon(accs[index.row()]->getState());
}
break;
case Qt::ForegroundRole:
if (!accs[index.row()]->getActive()) {
answer = qApp->palette().brush(QPalette::Disabled, QPalette::Text);
}
default:
break;
}

View file

@ -276,6 +276,18 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
break;
}
break;
case Qt::ForegroundRole:
switch (item->type) {
case Item::account: {
Account* acc = static_cast<Account*>(item);
if (!acc->getActive()) {
result = qApp->palette().brush(QPalette::Disabled, QPalette::Text);
}
}
break;
default:
break;
}
default:
break;
}