Commit 7f15ce92 authored by Kees vd Broek's avatar Kees vd Broek Committed by Ivan Čukić

Have a default backend (if one available)

Summary:
The creation of a new vault uses a wizard.

The first page of the wizard currently shows a combobox with 2 backends, with one semi-randomly selected by default.
The user is instructed to pick one.

Following the bugreport on one of the backend packages being scary to install on neon, I'm proposing we make the wizard a little more wizardly. But without losing any functionality. Users that want can still do all they can do now.

We make it easier for most users while not limiting the advanced ones.

BUG: 385971

Reviewers: ivan, #plasma

Subscribers: nicolasfella, ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8449
parent ff0c3a2b
......@@ -36,6 +36,8 @@ public:
bool vaultNameValid = false;
bool backendValid = false;
QByteArray bestsBackend;
int bestBackendPrio = -1;
void setVaultNameValid(bool valid)
{
......@@ -60,6 +62,7 @@ BackendChooserWidget::BackendChooserWidget()
{
d->ui.setupUi(this);
d->ui.textStatus->hide();
d->ui.page2Layout->setRowStretch(1, 10);
connect(d->ui.editVaultName, &QLineEdit::textChanged,
this, [&] (const QString &vaultName) {
......@@ -68,8 +71,9 @@ BackendChooserWidget::BackendChooserWidget()
connect(d->ui.comboBackend, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
this, &BackendChooserWidget::checkCurrentBackend);
}
connect(d->ui.pickBackendButton, SIGNAL(clicked()), this, SLOT(showBackendSelector()));
}
BackendChooserWidget::~BackendChooserWidget()
......@@ -77,7 +81,6 @@ BackendChooserWidget::~BackendChooserWidget()
}
void BackendChooserWidget::checkCurrentBackend()
{
const auto backendId = d->ui.comboBackend->currentData().toString();
......@@ -108,21 +111,45 @@ void BackendChooserWidget::checkCurrentBackend()
}
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
}
}
......@@ -30,13 +30,15 @@ public:
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;
......
......@@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>443</height>
<width>381</width>
<height>301</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="labelVaultName">
<property name="text">
<string>Vaul&amp;t name:</string>
......@@ -21,27 +21,10 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="editVaultName"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<item row="0" column="1">
<widget class="QLineEdit" name="editVaultName"/>
</item>
<item>
<item row="1" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -57,60 +40,143 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelEncryptionSystem">
<property name="text">
<string>Choose the encryption system you want to use for this vault:</string>
<item row="2" column="0" colspan="2">
<widget class="QStackedWidget" name="vaultEncryptionConfig">
<property name="currentIndex">
<number>0</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="comboBackend">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<property name="topMargin">
<number>0</number>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="rightMargin">
<number>0</number>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="textStatus">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Backend:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="backendName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pickBackendButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>283</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelEncryptionSystem">
<property name="text">
<string>Choose the encryption system you want to use for this vault:</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="page2Layout">
<item row="0" column="0">
<widget class="QComboBox" name="comboBackend">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>204</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2">
<widget class="QTextBrowser" name="textStatus">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
......
......@@ -112,6 +112,12 @@ public:
}
};
// to suggest the highest priority to the user as a starting value
QMap<QString, int> priorities = {
{ "encfs", 1 },
{ "cryfs", 2 }
};
template <typename ClickHandler>
QPushButton *addDialogButton(const QString &icon, const QString &title, ClickHandler clickHandler)
{
......@@ -150,8 +156,9 @@ public:
// 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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment