Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCamila <hello@camila.codes>2021-09-22 18:14:41 +0300
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>2021-10-28 15:59:28 +0300
commit72c91362f2d6e3e137c4c52d7856660a36f3bf33 (patch)
tree00520e6046284362c2689ccd62a172ea4db6f73e /src
parentc13668c0e944e806ff19a48d12bb4c53ef752b84 (diff)
Refactor ShareLinkWidget show/hide widgets functions.
- Remove unecessary call to setupUiOptions after saving share password. - Slot to create label: do not set it if nothing changed. - Refactor showPasswordOptions, toggle/PasswordOptions/ExpireDateOptions/NoteOptions. - Add const, auto and {} whenever possible. - Refactor slotToggleButtonAnimation => toggleButtonAnimation. Signed-off-by: Camila <hello@camila.codes>
Diffstat (limited to 'src')
-rw-r--r--src/gui/sharelinkwidget.cpp186
-rw-r--r--src/gui/sharelinkwidget.h24
2 files changed, 88 insertions, 122 deletions
diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp
index d0c422409..fcb8668c5 100644
--- a/src/gui/sharelinkwidget.cpp
+++ b/src/gui/sharelinkwidget.cpp
@@ -79,11 +79,10 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account,
connect(_ui->confirmPassword, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCreatePassword);
connect(_ui->confirmNote, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCreateNote);
connect(_ui->confirmExpirationDate, &QAbstractButton::clicked, this, &ShareLinkWidget::slotSetExpireDate);
- connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareLinkWidget::slotSetExpireDate);
_ui->errorLabel->hide();
- bool sharingPossible = true;
+ auto sharingPossible = true;
if (!_account->capabilities().sharePublicLink()) {
qCWarning(lcShareLink) << "Link shares have been disabled";
sharingPossible = false;
@@ -104,7 +103,6 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account,
togglePasswordOptions(false);
toggleExpireDateOptions(false);
toggleNoteOptions(false);
- _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
_ui->noteProgressIndicator->setVisible(false);
_ui->passwordProgressIndicator->setVisible(false);
@@ -123,7 +121,7 @@ ShareLinkWidget::~ShareLinkWidget()
delete _ui;
}
-void ShareLinkWidget::slotToggleShareLinkAnimation(bool start)
+void ShareLinkWidget::slotToggleShareLinkAnimation(const bool start)
{
_ui->sharelinkProgressIndicator->setVisible(start);
if (start) {
@@ -135,17 +133,17 @@ void ShareLinkWidget::slotToggleShareLinkAnimation(bool start)
}
}
-void ShareLinkWidget::slotToggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, bool optionEnabled, bool start)
+void ShareLinkWidget::toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction, const bool start)
{
- button->setVisible(optionEnabled && !start);
- progressIndicator->setVisible(start);
- if (start) {
- if (!progressIndicator->isAnimated()) {
- progressIndicator->startAnimation();
- }
+ if (!progressIndicator->isAnimated() && checkedAction->isChecked()) {
+ progressIndicator->startAnimation();
} else {
progressIndicator->stopAnimation();
}
+
+ const auto startAnimation = checkedAction->isChecked()? progressIndicator->isAnimated() : checkedAction->isChecked();
+ button->setVisible(!startAnimation && checkedAction->isChecked());
+ progressIndicator->setVisible(startAnimation && checkedAction->isChecked());
}
void ShareLinkWidget::setLinkShare(QSharedPointer<LinkShare> linkShare)
@@ -165,7 +163,6 @@ void ShareLinkWidget::focusPasswordLineEdit()
void ShareLinkWidget::setupUiOptions()
{
- connect(_linkShare.data(), &LinkShare::expireDateSet, this, &ShareLinkWidget::slotExpireDateSet);
connect(_linkShare.data(), &LinkShare::noteSet, this, &ShareLinkWidget::slotNoteSet);
connect(_linkShare.data(), &LinkShare::passwordSet, this, &ShareLinkWidget::slotPasswordSet);
connect(_linkShare.data(), &LinkShare::passwordSetError, this, &ShareLinkWidget::slotPasswordSetError);
@@ -174,7 +171,7 @@ void ShareLinkWidget::setupUiOptions()
// Prepare permissions check and create group action
const QDate expireDate = _linkShare.data()->getExpireDate().isValid() ? _linkShare.data()->getExpireDate() : QDate();
const SharePermissions perm = _linkShare.data()->getPermissions();
- bool checked = false;
+ auto checked = false;
auto *permissionsGroup = new QActionGroup(this);
// Prepare sharing menu
@@ -239,6 +236,7 @@ void ShareLinkWidget::setupUiOptions()
_shareLinkWidgetAction = new QWidgetAction(this);
_shareLinkWidgetAction->setDefaultWidget(_shareLinkDefaultWidget);
+ _shareLinkWidgetAction->setCheckable(true);
_linkContextMenu->addAction(_shareLinkWidgetAction);
// Adds permissions actions (radio button style)
@@ -257,7 +255,7 @@ void ShareLinkWidget::setupUiOptions()
if (_linkShare->getNote().isSimpleText() && !_linkShare->getNote().isEmpty()) {
_ui->textEdit_note->setText(_linkShare->getNote());
_noteLinkAction->setChecked(true);
- showNoteOptions(true);
+ toggleNoteOptions(true);
}
// Adds action to display password widget (check box)
@@ -267,7 +265,7 @@ void ShareLinkWidget::setupUiOptions()
if (_linkShare.data()->isPasswordSet()) {
_passwordProtectLinkAction->setChecked(true);
_ui->lineEdit_password->setPlaceholderText(QString::fromUtf8(passwordIsSetPlaceholder));
- showPasswordOptions(true);
+ togglePasswordOptions(true);
}
// If password is enforced then don't allow users to disable it
@@ -285,8 +283,11 @@ void ShareLinkWidget::setupUiOptions()
if (!expireDate.isNull()) {
_ui->calendar->setDate(expireDate);
_expirationDateLinkAction->setChecked(true);
- showExpireDateOptions(true);
+ toggleExpireDateOptions(true);
}
+ connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareLinkWidget::slotSetExpireDate);
+ connect(_linkShare.data(), &LinkShare::expireDateSet, this, &ShareLinkWidget::slotExpireDateSet);
+
// If expiredate is enforced do not allow disable and set max days
if (_account->capabilities().sharePublicLinkEnforceExpireDate()) {
@@ -321,32 +322,27 @@ void ShareLinkWidget::setupUiOptions()
// show sharing options
_ui->shareLinkToolButton->show();
- //TO DO
- //startAnimation(0, height());
-
customizeStyle();
}
-void ShareLinkWidget::setNote(const QString &note)
-{
- if (_linkShare) {
- slotToggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction->isChecked(), true);
- _ui->errorLabel->hide();
- _linkShare->setNote(note);
- }
-}
-
void ShareLinkWidget::slotCreateNote()
{
- setNote(_ui->textEdit_note->toPlainText());
+ const auto note = _ui->textEdit_note->toPlainText();
+ if (!_linkShare || _linkShare->getNote() == note || note.isEmpty()) {
+ return;
+ }
+
+ toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction, true);
+ _ui->errorLabel->hide();
+ _linkShare->setNote(note);
}
void ShareLinkWidget::slotNoteSet()
{
- slotToggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction->isChecked(), false);
+ toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction, false);
}
-void ShareLinkWidget::slotCopyLinkShare(bool clicked)
+void ShareLinkWidget::slotCopyLinkShare(const bool clicked)
{
Q_UNUSED(clicked);
@@ -355,7 +351,7 @@ void ShareLinkWidget::slotCopyLinkShare(bool clicked)
void ShareLinkWidget::slotExpireDateSet()
{
- slotToggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction->isChecked(), false);
+ toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction, false);
}
void ShareLinkWidget::slotSetExpireDate()
@@ -364,7 +360,7 @@ void ShareLinkWidget::slotSetExpireDate()
return;
}
- slotToggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction->isChecked(), true);
+ toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction, true);
_ui->errorLabel->hide();
_linkShare->setExpireDate(_ui->calendar->date());
}
@@ -375,7 +371,7 @@ void ShareLinkWidget::slotCreatePassword()
return;
}
- slotToggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction->isChecked(), true);
+ toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction, true);
_ui->errorLabel->hide();
emit createPassword(_ui->lineEdit_password->text());
}
@@ -389,27 +385,26 @@ void ShareLinkWidget::slotCreateShareLink(bool clicked)
void ShareLinkWidget::slotPasswordSet()
{
- slotToggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction->isChecked(), false);
+ toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction, false);
+
+ _ui->lineEdit_password->setText({});
- _ui->lineEdit_password->setText(QString());
if (_linkShare->isPasswordSet()) {
_ui->lineEdit_password->setEnabled(true);
_ui->lineEdit_password->setPlaceholderText(QString::fromUtf8(passwordIsSetPlaceholder));
} else {
- _ui->lineEdit_password->setPlaceholderText(QString());
+ _ui->lineEdit_password->setPlaceholderText({});
}
- setupUiOptions();
-
emit createPasswordProcessed();
}
-void ShareLinkWidget::slotPasswordSetError(int code, const QString &message)
+void ShareLinkWidget::slotPasswordSetError(const int code, const QString &message)
{
- slotToggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction->isChecked(), false);
+ toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction, false);
slotServerError(code, message);
- showPasswordOptions(true);
+ togglePasswordOptions(true);
_ui->lineEdit_password->setFocus();
emit createPasswordProcessed();
}
@@ -434,9 +429,6 @@ void ShareLinkWidget::slotDeleteShareFetched()
{
slotToggleShareLinkAnimation(false);
- // TODO
- //startAnimation(height(), 0);
-
_linkShare.clear();
togglePasswordOptions(false);
toggleNoteOptions(false);
@@ -444,25 +436,17 @@ void ShareLinkWidget::slotDeleteShareFetched()
emit deleteLinkShare();
}
-void ShareLinkWidget::showNoteOptions(bool show)
+void ShareLinkWidget::toggleNoteOptions(const bool enable)
{
- _ui->noteLabel->setVisible(show);
- _ui->textEdit_note->setVisible(show);
- _ui->confirmNote->setVisible(show);
-}
-
-
-void ShareLinkWidget::toggleNoteOptions(bool enable)
-{
- showNoteOptions(enable);
-
- if (enable) {
- _ui->textEdit_note->setFocus();
- } else {
- // 'deletes' note
- if (_linkShare)
- _linkShare->setNote(QString());
- }
+ _ui->noteLabel->setVisible(enable);
+ _ui->textEdit_note->setVisible(enable);
+ _ui->confirmNote->setVisible(enable);
+
+ _ui->textEdit_note->setText(enable && _linkShare ? _linkShare->getNote() : QString());
+
+ if (!enable && _linkShare && !_linkShare->getNote().isEmpty()) {
+ _linkShare->setNote({});
+ }
}
void ShareLinkWidget::slotAnimationFinished()
@@ -473,16 +457,20 @@ void ShareLinkWidget::slotAnimationFinished()
void ShareLinkWidget::slotCreateLabel()
{
- if (_linkShare) {
- slotToggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, true, true);
- _ui->errorLabel->hide();
- _linkShare->setLabel(_shareLinkEdit->text());
+ const auto labelText = _shareLinkEdit->text();
+ if (!_linkShare || _linkShare->getLabel() == labelText || labelText.isEmpty()) {
+ return;
}
+ _shareLinkWidgetAction->setChecked(true);
+ toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction, true);
+ _ui->errorLabel->hide();
+ _linkShare->setLabel(_shareLinkEdit->text());
}
void ShareLinkWidget::slotLabelSet()
{
- slotToggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, true, false);
+ _shareLinkWidgetAction->setChecked(false);
+ toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction, false);
displayShareLinkLabel();
}
@@ -498,7 +486,6 @@ void ShareLinkWidget::slotCreateShareRequiresPassword(const QString &message)
{
slotToggleShareLinkAnimation(message.isEmpty());
- showPasswordOptions(true);
if (!message.isEmpty()) {
_ui->errorLabel->setText(message);
_ui->errorLabel->show();
@@ -509,46 +496,31 @@ void ShareLinkWidget::slotCreateShareRequiresPassword(const QString &message)
togglePasswordOptions(true);
}
-void ShareLinkWidget::showPasswordOptions(bool show)
-{
- _ui->passwordLabel->setVisible(show);
- _ui->lineEdit_password->setVisible(show);
- _ui->confirmPassword->setVisible(show);
-}
-
-void ShareLinkWidget::togglePasswordOptions(bool enable)
+void ShareLinkWidget::togglePasswordOptions(const bool enable)
{
- showPasswordOptions(enable);
-
- if (enable) {
- _ui->lineEdit_password->setFocus();
- } else {
- // 'deletes' password
- if (_linkShare)
- _linkShare->setPassword(QString());
+ _ui->passwordLabel->setVisible(enable);
+ _ui->lineEdit_password->setVisible(enable);
+ _ui->confirmPassword->setVisible(enable);
+ _ui->lineEdit_password->setFocus();
+
+ if (!enable && _linkShare && _linkShare->isPasswordSet()) {
+ _linkShare->setPassword({});
}
}
-void ShareLinkWidget::showExpireDateOptions(bool show)
+void ShareLinkWidget::toggleExpireDateOptions(const bool enable)
{
- _ui->expirationLabel->setVisible(show);
- _ui->calendar->setVisible(show);
- _ui->confirmExpirationDate->setVisible(show);
-}
-
-void ShareLinkWidget::toggleExpireDateOptions(bool enable)
-{
- showExpireDateOptions(enable);
-
- if (enable) {
- const QDate date = QDate::currentDate().addDays(1);
- _ui->calendar->setDate(date);
- _ui->calendar->setMinimumDate(date);
- _ui->calendar->setFocus();
- } else {
- // 'deletes' expire date
- if (_linkShare)
- _linkShare->setExpireDate(QDate());
+ _ui->expirationLabel->setVisible(enable);
+ _ui->calendar->setVisible(enable);
+ _ui->confirmExpirationDate->setVisible(enable);
+
+ const auto date = enable ? _linkShare->getExpireDate() : QDate::currentDate().addDays(1);
+ _ui->calendar->setDate(date);
+ _ui->calendar->setMinimumDate(date);
+ _ui->calendar->setFocus();
+
+ if (!enable && _linkShare && _linkShare->getExpireDate().isValid()) {
+ _linkShare->setExpireDate({});
}
}
@@ -593,7 +565,7 @@ void ShareLinkWidget::slotContextMenuButtonClicked()
void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action)
{
- bool state = action->isChecked();
+ const auto state = action->isChecked();
SharePermissions perm = SharePermissionRead;
if (action == _addAnotherLinkAction) {
@@ -628,7 +600,7 @@ void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action)
}
}
-void ShareLinkWidget::slotServerError(int code, const QString &message)
+void ShareLinkWidget::slotServerError(const int code, const QString &message)
{
slotToggleShareLinkAnimation(false);
@@ -669,7 +641,7 @@ void ShareLinkWidget::customizeStyle()
void ShareLinkWidget::displayShareLinkLabel()
{
_shareLinkElidedLabel->clear();
- if(!_linkShare->getLabel().isEmpty()) {
+ if (!_linkShare->getLabel().isEmpty()) {
_shareLinkElidedLabel->setText(QString("(%1)").arg(_linkShare->getLabel()));
}
}
diff --git a/src/gui/sharelinkwidget.h b/src/gui/sharelinkwidget.h
index a6818fcad..531803c92 100644
--- a/src/gui/sharelinkwidget.h
+++ b/src/gui/sharelinkwidget.h
@@ -69,9 +69,9 @@ public:
public slots:
void slotDeleteShareFetched();
- void slotToggleShareLinkAnimation(bool start);
- void slotToggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, bool optionEnabled, bool start);
- void slotServerError(int code, const QString &message);
+ void slotToggleShareLinkAnimation(const bool start);
+ void toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction, const bool start);
+ void slotServerError(const int code, const QString &message);
void slotCreateShareRequiresPassword(const QString &message);
void slotStyleChanged();
@@ -80,7 +80,7 @@ private slots:
void slotCreatePassword();
void slotPasswordSet();
- void slotPasswordSetError(int code, const QString &message);
+ void slotPasswordSetError(const int code, const QString &message);
void slotCreateNote();
void slotNoteSet();
@@ -107,18 +107,12 @@ signals:
private:
void displayError(const QString &errMsg);
+
+ void togglePasswordOptions(const bool enable);
+ void toggleNoteOptions(const bool enable);
+ void toggleExpireDateOptions(const bool enable);
- void showPasswordOptions(bool show);
- void togglePasswordOptions(bool enable);
-
- void showNoteOptions(bool show);
- void toggleNoteOptions(bool enable);
- void setNote(const QString &note);
-
- void showExpireDateOptions(bool show);
- void toggleExpireDateOptions(bool enable);
-
- void slotCopyLinkShare(bool clicked);
+ void slotCopyLinkShare(const bool clicked);
/** Confirm with the user and then delete the share */
void confirmAndDeleteShare();