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:
parent
2c26c7e264
commit
f64e5c2df0
13 changed files with 248 additions and 200 deletions
|
@ -107,7 +107,7 @@ void DialogQueue::onPropmtRejected()
|
|||
case none:
|
||||
break;
|
||||
case askPassword:
|
||||
emit squawk->responsePassword(currentSource, prompt->textValue());
|
||||
emit squawk->disconnectAccount(currentSource);
|
||||
break;
|
||||
}
|
||||
actionDone();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -234,29 +234,7 @@ void Squawk::newAccount(const QMap<QString, QVariant>& account)
|
|||
void Squawk::onComboboxActivated(int index)
|
||||
{
|
||||
Shared::Availability av = Shared::Global::fromInt<Shared::Availability>(index);
|
||||
if (av != Shared::Availability::offline) {
|
||||
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
||||
if (size > 0) {
|
||||
emit changeState(av);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
Models::Account* acc = rosterModel.accountsModel->getAccount(i);
|
||||
if (acc->getState() == Shared::ConnectionState::disconnected) {
|
||||
emit connectAccount(acc->getName());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_ui->comboBox->setCurrentIndex(static_cast<int>(Shared::Availability::offline));
|
||||
}
|
||||
} else {
|
||||
emit changeState(av);
|
||||
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
||||
for (int i = 0; i != size; ++i) {
|
||||
Models::Account* acc = rosterModel.accountsModel->getAccount(i);
|
||||
if (acc->getState() != Shared::ConnectionState::disconnected) {
|
||||
emit disconnectAccount(acc->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
emit changeState(av);
|
||||
}
|
||||
|
||||
void Squawk::changeAccount(const QString& account, const QMap<QString, QVariant>& data)
|
||||
|
@ -573,17 +551,12 @@ void Squawk::onRosterContextMenu(const QPoint& point)
|
|||
hasMenu = true;
|
||||
QString name = acc->getName();
|
||||
|
||||
if (acc->getState() != Shared::ConnectionState::disconnected) {
|
||||
QAction* con = contextMenu->addAction(Shared::icon("network-disconnect"), tr("Disconnect"));
|
||||
con->setEnabled(active);
|
||||
connect(con, &QAction::triggered, [this, name]() {
|
||||
emit disconnectAccount(name);
|
||||
});
|
||||
if (acc->getActive()) {
|
||||
QAction* con = contextMenu->addAction(Shared::icon("network-disconnect"), tr("Deactivate"));
|
||||
connect(con, &QAction::triggered, std::bind(&Squawk::disconnectAccount, this, name));
|
||||
} else {
|
||||
QAction* con = contextMenu->addAction(Shared::icon("network-connect"), tr("Connect"));
|
||||
connect(con, &QAction::triggered, [this, name]() {
|
||||
emit connectAccount(name);
|
||||
});
|
||||
QAction* con = contextMenu->addAction(Shared::icon("network-connect"), tr("Activate"));
|
||||
connect(con, &QAction::triggered, std::bind(&Squawk::connectAccount, this, name));
|
||||
}
|
||||
|
||||
QAction* card = contextMenu->addAction(Shared::icon("user-properties"), tr("VCard"));
|
||||
|
@ -591,11 +564,7 @@ void Squawk::onRosterContextMenu(const QPoint& point)
|
|||
connect(card, &QAction::triggered, std::bind(&Squawk::onActivateVCard, this, name, acc->getBareJid(), true));
|
||||
|
||||
QAction* remove = contextMenu->addAction(Shared::icon("edit-delete"), tr("Remove"));
|
||||
remove->setEnabled(active);
|
||||
connect(remove, &QAction::triggered, [this, name]() {
|
||||
emit removeAccount(name);
|
||||
});
|
||||
|
||||
connect(remove, &QAction::triggered, std::bind(&Squawk::removeAccount, this, name));
|
||||
}
|
||||
break;
|
||||
case Models::Item::contact: {
|
||||
|
@ -839,20 +808,16 @@ void Squawk::readSettings()
|
|||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("ui");
|
||||
|
||||
int avail;
|
||||
if (settings.contains("availability")) {
|
||||
int avail = settings.value("availability").toInt();
|
||||
m_ui->comboBox->setCurrentIndex(avail);
|
||||
emit stateChanged(Shared::Global::fromInt<Shared::Availability>(avail));
|
||||
|
||||
int size = settings.beginReadArray("connectedAccounts");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
emit connectAccount(settings.value("name").toString()); //TODO this is actually not needed, stateChanged event already connects everything you have
|
||||
} // need to fix that
|
||||
settings.endArray();
|
||||
avail = settings.value("availability").toInt();
|
||||
} else {
|
||||
avail = static_cast<int>(Shared::Availability::online);
|
||||
}
|
||||
settings.endGroup();
|
||||
m_ui->comboBox->setCurrentIndex(avail);
|
||||
|
||||
emit changeState(Shared::Global::fromInt<Shared::Availability>(avail));
|
||||
}
|
||||
|
||||
void Squawk::writeSettings()
|
||||
|
@ -867,19 +832,10 @@ void Squawk::writeSettings()
|
|||
settings.setValue("splitter", m_ui->splitter->saveState());
|
||||
|
||||
settings.setValue("availability", m_ui->comboBox->currentIndex());
|
||||
settings.beginWriteArray("connectedAccounts");
|
||||
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
||||
for (int i = 0; i < size; ++i) {
|
||||
Models::Account* acc = rosterModel.accountsModel->getAccount(i);
|
||||
if (acc->getState() != Shared::ConnectionState::disconnected) {
|
||||
settings.setArrayIndex(i);
|
||||
settings.setValue("name", acc->getName());
|
||||
}
|
||||
}
|
||||
settings.endArray();
|
||||
|
||||
settings.remove("roster");
|
||||
settings.beginGroup("roster");
|
||||
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
||||
for (int i = 0; i < size; ++i) {
|
||||
QModelIndex acc = rosterModel.index(i, 0, QModelIndex());
|
||||
Models::Account* account = rosterModel.accountsModel->getAccount(i);
|
||||
|
|
|
@ -53,6 +53,7 @@ QMap<QString, QVariant> Account::value() const
|
|||
map["name"] = m_ui->name->text();
|
||||
map["resource"] = m_ui->resource->text();
|
||||
map["passwordType"] = m_ui->passwordType->currentIndex();
|
||||
map["active"] = m_ui->active->isChecked();
|
||||
|
||||
return map;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>438</width>
|
||||
<height>342</height>
|
||||
<height>345</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -34,7 +34,7 @@
|
|||
<property name="verticalSpacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="login">
|
||||
<property name="toolTip">
|
||||
<string>Your account login</string>
|
||||
|
@ -44,14 +44,14 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="server">
|
||||
<property name="toolTip">
|
||||
<string>A server address of your account. Like 404.city or macaw.me</string>
|
||||
|
@ -61,21 +61,21 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="password">
|
||||
<property name="toolTip">
|
||||
<string>Password of your account</string>
|
||||
|
@ -97,14 +97,14 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="name">
|
||||
<property name="toolTip">
|
||||
<string>Just a name how would you call this account, doesn't affect anything</string>
|
||||
|
@ -114,14 +114,14 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Resource</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<item row="7" column="1">
|
||||
<widget class="QLineEdit" name="resource">
|
||||
<property name="toolTip">
|
||||
<string>A resource name like "Home" or "Work"</string>
|
||||
|
@ -131,17 +131,17 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Password storage</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="5" column="1">
|
||||
<widget class="QComboBox" name="passwordType"/>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
|
@ -157,6 +157,23 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Active</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="active">
|
||||
<property name="text">
|
||||
<string>enable</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -83,7 +83,8 @@ void Accounts::onEditButton()
|
|||
{"server", mAcc->getServer()},
|
||||
{"name", mAcc->getName()},
|
||||
{"resource", mAcc->getResource()},
|
||||
{"passwordType", QVariant::fromValue(mAcc->getPasswordType())}
|
||||
{"passwordType", QVariant::fromValue(mAcc->getPasswordType())},
|
||||
{"active", mAcc->getActive()}
|
||||
});
|
||||
acc->lockId();
|
||||
connect(acc, &Account::accepted, this, &Accounts::onAccountAccepted);
|
||||
|
@ -118,17 +119,17 @@ void Accounts::updateConnectButton()
|
|||
bool allConnected = true;
|
||||
for (int i = 0; i < selectionSize && allConnected; ++i) {
|
||||
const Models::Account* mAcc = model->getAccount(sm->selectedRows().at(i).row());
|
||||
allConnected = mAcc->getState() == Shared::ConnectionState::connected;
|
||||
allConnected = allConnected && mAcc->getActive();
|
||||
}
|
||||
if (allConnected) {
|
||||
toDisconnect = true;
|
||||
m_ui->connectButton->setText(tr("Disconnect"));
|
||||
m_ui->connectButton->setText(tr("Deactivate"));
|
||||
} else {
|
||||
toDisconnect = false;
|
||||
m_ui->connectButton->setText(tr("Connect"));
|
||||
m_ui->connectButton->setText(tr("Activate"));
|
||||
}
|
||||
} else {
|
||||
m_ui->connectButton->setText(tr("Connect"));
|
||||
m_ui->connectButton->setText(tr("Activate"));
|
||||
toDisconnect = false;
|
||||
m_ui->connectButton->setEnabled(false);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue