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
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue