Skip to content

Commit

Permalink
feat: use QT file dialog for downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Dec 14, 2024
1 parent 33ad940 commit 3a1bd3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/details/QCefViewPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma region stl_headers
#include <stdexcept>
#pragma endregion
#pragma endregion

#pragma region qt_headers
#include <QApplication>
Expand All @@ -14,14 +14,14 @@
#include <QPainter>
#include <QStyleOption>
#include <QWindow>
#pragma endregion
#pragma endregion

#pragma region cef_headers
#include <include/cef_app.h>
#include <include/cef_browser.h>
#include <include/cef_frame.h>
#include <include/cef_parser.h>
#pragma endregion
#pragma endregion

#include <CefViewCoreProtocol.h>

Expand Down Expand Up @@ -86,6 +86,7 @@ QCefViewPrivate::createCefBrowser(QCefView* view, const QString& url, const QCef
// OSR mode
windowInfo.SetAsWindowless(0);
} else {
windowInfo.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
// create CEF browser parent window
auto windowInitialSize = q_ptr->size();
if (setting) {
Expand Down Expand Up @@ -697,12 +698,9 @@ QCefViewPrivate::onFileDialog(CefBrowserHost::FileDialogMode mode,

// set initial folder
if (!default_file_path.empty() && mode == FILE_DIALOG_SAVE) {
QDir dir(QString::fromStdString(default_file_path.ToString()));
if (dir.exists()) {
dialog.setDirectory(dir);
} else {
dialog.setDirectory(QDir::homePath());
}
QFileInfo fileInfo(QString::fromStdString(default_file_path.ToString()));
dialog.setDirectory(fileInfo.dir());
dialog.selectFile(fileInfo.fileName());
}

// set accepted file types
Expand All @@ -719,7 +717,7 @@ QCefViewPrivate::onFileDialog(CefBrowserHost::FileDialogMode mode,
std::vector<CefString> file_paths;
auto selected_files = dialog.selectedFiles();
for (const auto& file : selected_files) {
file_paths.push_back(file.toStdString());
file_paths.push_back(QDir::toNativeSeparators(file).toStdString());
}

#if CEF_VERSION_MAJOR < 102
Expand Down
3 changes: 0 additions & 3 deletions src/details/handler/CCefClientDelegate_DialogHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ CCefClientDelegate::onFileDialog(CefRefPtr<CefBrowser> browser,
#endif
CefRefPtr<CefFileDialogCallback> callback)
{
#if defined(Q_OS_LINUX)
QMetaObject::invokeMethod(pCefViewPrivate_, [=]() {
pCefViewPrivate_->onFileDialog(mode,
title,
Expand All @@ -31,6 +30,4 @@ CCefClientDelegate::onFileDialog(CefRefPtr<CefBrowser> browser,
callback);
});
return true;
#endif
return false;
}

0 comments on commit 3a1bd3c

Please sign in to comment.