Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn input errors on creating shared links #1511

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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