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;
togglePasswordOptions(false);
toggleExpireDateOptions(false);
toggleNoteOptions(false);
- _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
_ui->noteProgressIndicator->setVisible(false);
_ui->passwordProgressIndicator->setVisible(false);
delete _ui;
}
-void ShareLinkWidget::slotToggleShareLinkAnimation(bool start)
+void ShareLinkWidget::slotToggleShareLinkAnimation(const bool start)
{
_ui->sharelinkProgressIndicator->setVisible(start);
if (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)
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);
// 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
_shareLinkWidgetAction = new QWidgetAction(this);
_shareLinkWidgetAction->setDefaultWidget(_shareLinkDefaultWidget);
+ _shareLinkWidgetAction->setCheckable(true);
_linkContextMenu->addAction(_shareLinkWidgetAction);
// Adds permissions actions (radio button style)
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)
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
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()) {
// show sharing options
_ui->shareLinkToolButton->show();
- //TO DO
- //startAnimation(0, height());
-
customizeStyle();
}
-void ShareLinkWidget::setNote(const QString ¬e)
-{
- 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);
void ShareLinkWidget::slotExpireDateSet()
{
- slotToggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction->isChecked(), false);
+ toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction, false);
}
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());
}
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());
}
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();
}
{
slotToggleShareLinkAnimation(false);
- // TODO
- //startAnimation(height(), 0);
-
_linkShare.clear();
togglePasswordOptions(false);
toggleNoteOptions(false);
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()
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();
}
{
slotToggleShareLinkAnimation(message.isEmpty());
- showPasswordOptions(true);
if (!message.isEmpty()) {
_ui->errorLabel->setText(message);
_ui->errorLabel->show();
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({});
}
}
void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action)
{
- bool state = action->isChecked();
+ const auto state = action->isChecked();
SharePermissions perm = SharePermissionRead;
if (action == _addAnotherLinkAction) {
}
}
-void ShareLinkWidget::slotServerError(int code, const QString &message)
+void ShareLinkWidget::slotServerError(const int code, const QString &message)
{
slotToggleShareLinkAnimation(false);
void ShareLinkWidget::displayShareLinkLabel()
{
_shareLinkElidedLabel->clear();
- if(!_linkShare->getLabel().isEmpty()) {
+ if (!_linkShare->getLabel().isEmpty()) {
_shareLinkElidedLabel->setText(QString("(%1)").arg(_linkShare->getLabel()));
}
}