Skip to content

Commit

Permalink
fix: Fix file name too long and unable to download files properly
Browse files Browse the repository at this point in the history
A file name that is too long will cause automatic deletion

Log: Limit the input length of the input box, automatically truncate the last digit if the length is too long

Bug: https://pms.uniontech.com/bug-view-259793.html
  • Loading branch information
yang233000 authored and Johnson-zs committed Jun 27, 2024
1 parent 99cc512 commit 782a19a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/plugins/filedialog/filedialogplugin-core/views/filedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,16 @@ bool FileDialog::hideOnAccept() const
return d->hideOnAccept;
}

QUrl FileDialog::getcurrenturl() const
{
return d->currentUrl;
}

bool FileDialog::checkFileSuffix(const QString &filename, QString &suffix)
{
return d->checkFileSuffix(filename, suffix);
}

void FileDialog::accept()
{
done(QDialog::Accepted);
Expand Down Expand Up @@ -913,6 +923,7 @@ void FileDialog::handleUrlChanged(const QUrl &url)
emit initialized();
dpfSlotChannel->push("dfmplugin_workspace", "slot_Model_SetNameFilter", internalWinId(), curNameFilters);
dpfSlotChannel->push("dfmplugin_workspace", "slot_View_SetAlwaysOpenInCurrentWindow", internalWinId());
d->currentUrl = url;
}

void FileDialog::onViewSelectionChanged(const quint64 windowID, const QItemSelection &selected, const QItemSelection &deselected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class FileDialog : public DFMBASE_NAMESPACE::FileManagerWindow
void setHideOnAccept(bool enable);
bool hideOnAccept() const;

QUrl getcurrenturl() const;
bool checkFileSuffix(const QString &filename, QString &suffix);
FileDialogStatusBar *statusBar() const;

Q_SIGNALS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class FileDialogPrivate : public QObject
QString currentInputName;
bool allowMixedSelection { false };
QFileDialog::Options options;
QUrl currentUrl;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ void FileDialogStatusBar::onWindowTitleChanged(const QString &title)
void FileDialogStatusBar::onFileNameTextEdited(const QString &text)
{
QString dstText = DFMBASE_NAMESPACE::FileUtils::preprocessingFileName(text);
QString suffix { "" };
mainWindow->checkFileSuffix(dstText, suffix);
int maxLength = NAME_MAX - suffix.length() - 1;
while (DFMBASE_NAMESPACE::FileUtils::getFileNameLength(mainWindow->getcurrenturl(), dstText) > maxLength) {
dstText.chop(1);
}
if (text != dstText) {
int currPos = fileNameEdit->lineEdit()->cursorPosition();
fileNameEdit->setText(dstText);
Expand Down

0 comments on commit 782a19a

Please sign in to comment.