Skip to content

Commit

Permalink
Warn input errors on creating shared links (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
rumtid authored Jan 26, 2024
1 parent c5b77d2 commit 227a21f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
36 changes: 20 additions & 16 deletions src/filebrowser/sharedlink-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "utils/utils-mac.h"
#include "account.h"
#include "account-mgr.h"
#include "api/api-error.h"
#include "seafile-applet.h"
#include "filebrowser/file-browser-requests.h"


SharedLinkDialog::SharedLinkDialog(const QString& link, const QString &repo_id,
const QString &path_in_repo,
QWidget *parent)
Expand All @@ -21,7 +21,7 @@ SharedLinkDialog::SharedLinkDialog(const QString& link, const QString &repo_id,
Qt::WindowStaysOnTopHint);
QVBoxLayout *layout = new QVBoxLayout;

QLabel *password_label = new QLabel(tr("Password(At least 8 characters)"));
QLabel *password_label = new QLabel(tr("Password"));
layout->addWidget(password_label);

QHBoxLayout *passwd_hlayout = new QHBoxLayout;
Expand All @@ -32,8 +32,6 @@ SharedLinkDialog::SharedLinkDialog(const QString& link, const QString &repo_id,

password_editor_ = new QLineEdit;
passwd_hlayout->addWidget(password_editor_);
connect(password_editor_, &QLineEdit::textChanged, this,
&SharedLinkDialog::slotPasswordEditTextChanged);
password_editor_->setEchoMode(QLineEdit::Password);
layout->addLayout(passwd_hlayout);

Expand Down Expand Up @@ -129,26 +127,33 @@ void SharedLinkDialog::slotGenSharedLink()

CreateSharedLinkRequest *req = new CreateSharedLinkRequest(account, repo_id_, path_in_repo_, password, expire_days);

connect(req, &CreateSharedLinkRequest::success,
this, &SharedLinkDialog::slotGetSharedLink);
connect(req, SIGNAL(success(const QString&)),
this, SLOT(onCreateSharedLinkSuccess(const QString&)));
connect(req, SIGNAL(failed(const ApiError&)),
this, SLOT(onCreateSharedLinkFailed(const ApiError&)));
req->send();
}

void SharedLinkDialog::slotGetSharedLink(const QString& link)
void SharedLinkDialog::onCreateSharedLinkSuccess(const QString& link)
{
text_ = link;
editor_->setText(text_);
text_ = link;
editor_->setText(text_);
}


void SharedLinkDialog::slotPasswordEditTextChanged(const QString &text)
void SharedLinkDialog::onCreateSharedLinkFailed(const ApiError& error)
{
if (text.size() > 0 && text.size() < 8) {
generate_link_pushbutton_->setDisabled(true);
} else {
generate_link_pushbutton_->setEnabled(true);
if (error.type() != ApiError::HTTP_ERROR) {
seafApplet->warningBox(tr("Failed to generate share link: %1").arg(error.toString()));
return;
}

auto httpCode = error.httpErrorCode();
if (httpCode == 400) {
seafApplet->warningBox(tr("Failed to generate share link: Invalid input"));
return;
}

seafApplet->warningBox(tr("Failed to generate share link: %1").arg(error.toString()));
}

void SharedLinkDialog::slotShowPasswordCheckBoxClicked(int state)
Expand All @@ -159,4 +164,3 @@ void SharedLinkDialog::slotShowPasswordCheckBoxClicked(int state)
}
password_editor_ -> setEchoMode(QLineEdit::Password);
}

6 changes: 4 additions & 2 deletions src/filebrowser/sharedlink-dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <QDialog>

class QLineEdit;
class ApiError;

class SharedLinkDialog : public QDialog
{
Q_OBJECT
Expand All @@ -16,8 +18,8 @@ private slots:
void onCopyText();
void onDownloadStateChanged(int state);
void slotGenSharedLink();
void slotGetSharedLink(const QString& link);
void slotPasswordEditTextChanged(const QString& text);
void onCreateSharedLinkSuccess(const QString& link);
void onCreateSharedLinkFailed(const ApiError& error);
void slotShowPasswordCheckBoxClicked(int state);

private:
Expand Down

0 comments on commit 227a21f

Please sign in to comment.