diff --git a/kded/ui/backendchooserwidget.h b/kded/ui/backendchooserwidget.h --- a/kded/ui/backendchooserwidget.h +++ b/kded/ui/backendchooserwidget.h @@ -30,13 +30,15 @@ BackendChooserWidget(); ~BackendChooserWidget(); - void addItem(const QByteArray &id, const QString &title); + void addItem(const QByteArray &id, const QString &title, int priority); PlasmaVault::Vault::Payload fields() const override; - QByteArray backendId(); + + void checkBackendAvailable(); private Q_SLOTS: void checkCurrentBackend(); + void showBackendSelector(); private: class Private; diff --git a/kded/ui/backendchooserwidget.cpp b/kded/ui/backendchooserwidget.cpp --- a/kded/ui/backendchooserwidget.cpp +++ b/kded/ui/backendchooserwidget.cpp @@ -36,6 +36,8 @@ bool vaultNameValid = false; bool backendValid = false; + QByteArray bestsBackend; + int bestBackendPrio = -1; void setVaultNameValid(bool valid) { @@ -60,24 +62,25 @@ { d->ui.setupUi(this); d->ui.textStatus->hide(); + d->ui.page2Layout->setRowStretch(1, 10); connect(d->ui.editVaultName, &QLineEdit::textChanged, this, [&] (const QString &vaultName) { d->setVaultNameValid(!vaultName.isEmpty()); }); connect(d->ui.comboBackend, static_cast(&QComboBox::activated), this, &BackendChooserWidget::checkCurrentBackend); -} + connect(d->ui.pickBackendButton, SIGNAL(clicked()), this, SLOT(showBackendSelector())); +} BackendChooserWidget::~BackendChooserWidget() { } - void BackendChooserWidget::checkCurrentBackend() { const auto backendId = d->ui.comboBackend->currentData().toString(); @@ -108,21 +111,45 @@ } - -void BackendChooserWidget::addItem(const QByteArray &id, const QString &title) +void BackendChooserWidget::showBackendSelector() { - d->ui.comboBackend->addItem(title, id); + d->ui.vaultEncryptionConfig->setCurrentWidget(d->ui.page2); checkCurrentBackend(); } +void BackendChooserWidget::addItem(const QByteArray &id, const QString &title, int priority) +{ + d->ui.comboBackend->addItem(title, id); + + if (priority > d->bestBackendPrio) { + const auto backend = PlasmaVault::Backend::instance(id); + Q_ASSERT(backend); // backend and UI out of sync. Its an assert since they both are part of the same .so + if (backend && AsynQt::await(backend->validateBackend())) { + d->bestBackendPrio = priority; + d->bestsBackend = id; + d->ui.backendName->setText(title); + d->setBackendValid(true); + } + } +} PlasmaVault::Vault::Payload BackendChooserWidget::fields() const { + QByteArray backend = d->bestsBackend; + if (d->ui.vaultEncryptionConfig->currentWidget() == d->ui.page2) + backend = d->ui.comboBackend->currentData().toByteArray(); + Q_ASSERT(!backend.isEmpty()); return { - { KEY_BACKEND, d->ui.comboBackend->currentData() }, + { KEY_BACKEND, backend}, { KEY_NAME, d->ui.editVaultName->text() } }; } +void BackendChooserWidget::checkBackendAvailable() +{ + if (d->bestsBackend.isEmpty()) { // in case there are no backends found at all + showBackendSelector(); // show the more helpful selector + } +} diff --git a/kded/ui/backendchooserwidget.ui b/kded/ui/backendchooserwidget.ui --- a/kded/ui/backendchooserwidget.ui +++ b/kded/ui/backendchooserwidget.ui @@ -6,12 +6,12 @@ 0 0 - 653 - 443 + 381 + 301 - - + + Vaul&t name: @@ -21,27 +21,10 @@ - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + - + Qt::Vertical @@ -57,60 +40,143 @@ - - - - Choose the encryption system you want to use for this vault: + + + + 0 - - - - - - - - - 200 - 0 - + + + + 0 - - - - - - Qt::Horizontal + + 0 - - - 40 - 20 - + + 0 - - - - - - - - QFrame::NoFrame - + + 0 + + + + + + + Backend: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Change + + + + + + + + + Qt::Vertical + + + + 20 + 283 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Choose the encryption system you want to use for this vault: + + + + + + + + + + 200 + 0 + + + + + + + + Qt::Horizontal + + + + 204 + 20 + + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + + + + + - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/kded/ui/vaultcreationwizard.cpp b/kded/ui/vaultcreationwizard.cpp --- a/kded/ui/vaultcreationwizard.cpp +++ b/kded/ui/vaultcreationwizard.cpp @@ -112,6 +112,12 @@ } }; + // to suggest the highest priority to the user as a starting value + QMap priorities = { + { "encfs", 1 }, + { "cryfs", 2 } + }; + template QPushButton *addDialogButton(const QString &icon, const QString &title, ClickHandler clickHandler) { @@ -150,8 +156,9 @@ // Loading the backends to the combo box for (const auto& key: logic.keys()) { - firstStepModule->addItem(key, key.translation()); + firstStepModule->addItem(key, key.translation(), priorities.value(key)); } + firstStepModule->checkBackendAvailable(); } void setCurrentModule(DialogDsl::DialogModule *module)