feat: add legacy account selection dialog.

Signed-off-by: Camila Ayres <hello@camilasan.com>
This commit is contained in:
Rello 2025-06-24 21:34:42 +02:00 committed by Camila Ayres
parent ff5e8659d3
commit cb78bdd075
4 changed files with 119 additions and 14 deletions

View File

@ -153,6 +153,8 @@ set(client_SRCS
userinfo.cpp
vfsdownloaderrordialog.h
vfsdownloaderrordialog.cpp
legacyaccountselectiondialog.h
legacyaccountselectiondialog.cpp
accountstate.h
accountstate.cpp
addcertificatedialog.h

View File

@ -16,6 +16,7 @@
#include "libsync/cookiejar.h"
#include "libsync/theme.h"
#include "libsync/clientproxy.h"
#include "legacyaccountselectiondialog.h"
#include <QSettings>
#include <QDir>
@ -176,6 +177,7 @@ bool AccountManager::restoreFromLegacySettings()
auto wasLegacyImportDialogDisplayed = false;
const auto displayLegacyImportDialog = Theme::instance()->displayLegacyImportDialog();
QStringList selectedAccountIds;
// if the settings file could not be opened, the childKeys list is empty
// then try to load settings from a very old place
@ -215,25 +217,51 @@ bool AccountManager::restoreFromLegacySettings()
}
oCSettings->beginGroup(QLatin1String(accountsC));
const auto accountsListSize = oCSettings->childGroups().size();
oCSettings->endGroup();
const auto childGroups = oCSettings->childGroups();
const auto accountsListSize = childGroups.size();
oCSettings->endGroup(); //accountsC
if (const QFileInfo configFileInfo(configFile);
configFileInfo.exists() && configFileInfo.isReadable()) {
qCInfo(lcAccountManager) << "Migrate: checking old config " << configFile;
if (!forceLegacyImport() && accountsListSize > 0 && displayLegacyImportDialog) {
wasLegacyImportDialogDisplayed = true;
const auto importQuestion = accountsListSize > 1
? tr("%1 accounts were detected from a legacy desktop client.\n"
"Should the accounts be imported?").arg(QString::number(accountsListSize))
: tr("1 account was detected from a legacy desktop client.\n"
"Should the account be imported?");
const auto importMessageBox = new QMessageBox(QMessageBox::Question, tr("Legacy import"), importQuestion);
importMessageBox->addButton(tr("Import"), QMessageBox::AcceptRole);
const auto skipButton = importMessageBox->addButton(tr("Skip"), QMessageBox::DestructiveRole);
importMessageBox->exec();
if (importMessageBox->clickedButton() == skipButton) {
return false;
if (accountsListSize == 1) {
const auto importQuestion =
tr("An account was detected from a legacy desktop client.\n"
"Should the account be imported?");
QMessageBox importMessageBox(QMessageBox::Question, tr("Legacy import"), importQuestion);
importMessageBox.addButton(tr("Import"), QMessageBox::AcceptRole);
const auto skipButton = importMessageBox.addButton(tr("Skip"), QMessageBox::DestructiveRole);
importMessageBox.exec();
if (importMessageBox.clickedButton() == skipButton) {
return false;
}
selectedAccountIds = childGroups;
} else {
QVector<LegacyAccountSelectionDialog::AccountItem> accountsToDisplay;
oCSettings->beginGroup(QLatin1String(accountsC));
for (const auto &accId : childGroups) {
oCSettings->beginGroup(accId);
const auto displayName = oCSettings->value(QLatin1String(displayNameC)).toString();
const auto urlStr = oCSettings->value(QLatin1String(urlC)).toString();
oCSettings->endGroup(); //accId
const auto label = QString("%1 - %2").arg(displayName, urlStr);
accountsToDisplay.push_back({accId, label});
}
oCSettings->endGroup(); //accountsC
LegacyAccountSelectionDialog accountSelectionDialog(accountsToDisplay);
if (accountSelectionDialog.exec() != QDialog::Accepted) {
return false;
}
selectedAccountIds = accountSelectionDialog.selectedAccountIds();
if (selectedAccountIds.isEmpty()) {
return false;
}
}
} else {
selectedAccountIds = childGroups;
}
qCInfo(lcAccountManager) << "Copy settings" << oCSettings->allKeys().join(", ");
@ -264,7 +292,7 @@ bool AccountManager::restoreFromLegacySettings()
// Try to load the single account.
if (!settings->childKeys().isEmpty()) {
settings->beginGroup(accountsC);
const auto childGroups = settings->childGroups();
const auto childGroups = selectedAccountIds.isEmpty() ? settings->childGroups() : selectedAccountIds;
for (const auto &accountId : childGroups) {
settings->beginGroup(accountId);
const auto acc = loadAccountHelper(*settings);

View File

@ -0,0 +1,45 @@
#include "legacyaccountselectiondialog.h"
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QLabel>
#include <QVBoxLayout>
namespace OCC
{
LegacyAccountSelectionDialog::LegacyAccountSelectionDialog(const QVector<AccountItem> &accounts, QWidget *parent)
: QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(tr("Legacy import"));
auto layout = new QVBoxLayout(this);
layout->addWidget(new QLabel(tr("Select the accounts to import from the legacy configuration:"), this));
for (const auto &account : accounts) {
auto checkbox = new QCheckBox(account.label, this);
checkbox->setChecked(true);
layout->addWidget(checkbox);
_checkBoxes.insert(account.id, checkbox);
}
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
layout->addWidget(buttonBox);
}
QStringList LegacyAccountSelectionDialog::selectedAccountIds() const
{
QStringList selectedAccount;
for (auto it = _checkBoxes.constBegin(); it != _checkBoxes.constEnd(); ++it) {
if (it.value()->isChecked()) {
selectedAccount.push_back(it.key());
}
}
return selectedAccount;
}
} // namespace OCC

View File

@ -0,0 +1,30 @@
#pragma once
#include <QDialog>
#include <QMap>
#include <QStringList>
class QCheckBox;
namespace OCC
{
class LegacyAccountSelectionDialog : public QDialog
{
Q_OBJECT
public:
struct AccountItem {
QString id;
QString label;
};
explicit LegacyAccountSelectionDialog(const QVector<AccountItem> &accounts, QWidget *parent = nullptr);
[[nodiscard]] QStringList selectedAccountIds() const;
private:
QMap<QString, QCheckBox *> _checkBoxes;
};
} // namespace OCC