diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index d2d05fe94..744d6501a 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -43,6 +43,7 @@ set(client_UI_SRCS shareuserline.ui sslerrordialog.ui addcertificatedialog.ui + passwordinputdialog.ui proxyauthdialog.ui mnemonicdialog.ui wizard/flow2authwidget.ui @@ -92,6 +93,7 @@ set(client_SRCS openfilemanager.cpp owncloudgui.cpp owncloudsetupwizard.cpp + passwordinputdialog.cpp selectivesyncdialog.cpp settingsdialog.cpp sharedialog.cpp diff --git a/src/gui/passwordinputdialog.cpp b/src/gui/passwordinputdialog.cpp new file mode 100644 index 000000000..58a939f04 --- /dev/null +++ b/src/gui/passwordinputdialog.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) by Oleksandr Zolotov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "passwordinputdialog.h" +#include "ui_passwordinputdialog.h" + +namespace OCC { + +PasswordInputDialog::PasswordInputDialog(const QString &description, const QString &error, QWidget *parent) + : QDialog(parent) + , _ui(new Ui::PasswordInputDialog) +{ + _ui->setupUi(this); + + _ui->passwordLineEditLabel->setText(description); + _ui->passwordLineEditLabel->setVisible(!description.isEmpty()); + + _ui->labelErrorMessage->setText(error); + _ui->labelErrorMessage->setVisible(!error.isEmpty()); + + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); +} + +PasswordInputDialog::~PasswordInputDialog() = default; + +QString PasswordInputDialog::password() const +{ + return _ui->passwordLineEdit->text(); +} +} diff --git a/src/gui/passwordinputdialog.h b/src/gui/passwordinputdialog.h new file mode 100644 index 000000000..50528a252 --- /dev/null +++ b/src/gui/passwordinputdialog.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) by Oleksandr Zolotov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#pragma once + +#include + +namespace OCC { + +namespace Ui { +class PasswordInputDialog; +} + +class PasswordInputDialog : public QDialog +{ + Q_OBJECT + +public: + explicit PasswordInputDialog(const QString &description, const QString &error, QWidget *parent = nullptr); + ~PasswordInputDialog() override; + + QString password() const; + +private: + std::unique_ptr _ui; +}; + +} diff --git a/src/gui/passwordinputdialog.ui b/src/gui/passwordinputdialog.ui new file mode 100644 index 000000000..16b4b4e32 --- /dev/null +++ b/src/gui/passwordinputdialog.ui @@ -0,0 +1,115 @@ + + + OCC::PasswordInputDialog + + + Qt::WindowModal + + + + 0 + 0 + 276 + 125 + + + + + 0 + 0 + + + + Password for share required + + + false + + + true + + + + + + Please enter a password for your share: + + + + + + + + + + QLineEdit::Password + + + + + + + + + + true + + + color: rgb(118, 118, 118) + + + + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + OCC::PasswordInputDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + OCC::PasswordInputDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 6f5e2837d..6ecb579e5 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -17,6 +17,7 @@ #include "sharee.h" #include "sharelinkwidget.h" #include "shareusergroupwidget.h" +#include "passwordinputdialog.h" #include "sharemanager.h" @@ -359,26 +360,21 @@ void ShareDialog::slotCreatePasswordForLinkShareProcessed() } } -void ShareDialog::slotLinkShareRequiresPassword() +void ShareDialog::slotLinkShareRequiresPassword(const QString &message) { - bool ok = false; - QString password = QInputDialog::getText(this, - tr("Password for share required"), - tr("Please enter a password for your link share:"), - QLineEdit::Password, - QString(), - &ok); + const auto passwordInputDialog = new PasswordInputDialog(tr("Please enter a password for your link share:"), message, this); + passwordInputDialog->setWindowTitle(tr("Password for share required")); + passwordInputDialog->setAttribute(Qt::WA_DeleteOnClose); + passwordInputDialog->open(); - if (!ok) { - // The dialog was canceled so no need to do anything + connect(passwordInputDialog, &QDialog::finished, this, [this, passwordInputDialog](const int result) { + if (result == QDialog::Accepted && _manager) { + // Try to create the link share again with the newly entered password + _manager->createLinkShare(_sharePath, QString(), passwordInputDialog->password()); + return; + } emit toggleShareLinkAnimation(false); - return; - } - - if(_manager) { - // Try to create the link share again with the newly entered password - _manager->createLinkShare(_sharePath, QString(), password); - } + }); } void ShareDialog::slotDeleteShare() diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index 6431cb131..5e58480e0 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -66,7 +66,7 @@ private slots: void slotCreateLinkShare(); void slotCreatePasswordForLinkShare(const QString &password); void slotCreatePasswordForLinkShareProcessed(); - void slotLinkShareRequiresPassword(); + void slotLinkShareRequiresPassword(const QString &message); void slotAdjustScrollWidgetSize(); signals: