瀏覽代碼

UI/Qt: Implement download directory selection

Timothy Flynn 10 月之前
父節點
當前提交
4147d771a6
共有 3 個文件被更改,包括 15 次插入0 次删除
  1. 10 0
      Ladybird/Qt/Application.cpp
  2. 2 0
      Ladybird/Qt/Application.h
  3. 3 0
      Ladybird/Qt/Tab.cpp

+ 10 - 0
Ladybird/Qt/Application.cpp

@@ -12,6 +12,7 @@
 #include <Ladybird/Utilities.h>
 #include <LibCore/ArgsParser.h>
 #include <LibWebView/URL.h>
+#include <QFileDialog>
 #include <QFileOpenEvent>
 
 namespace Ladybird {
@@ -126,4 +127,13 @@ BrowserWindow& Application::new_window(Vector<URL::URL> const& initial_urls, Web
     return *window;
 }
 
+Optional<ByteString> Application::ask_user_for_download_folder() const
+{
+    auto path = QFileDialog::getExistingDirectory(nullptr, "Select download directory", QDir::homePath());
+    if (path.isNull())
+        return {};
+
+    return ak_byte_string_from_qstring(path);
+}
+
 }

+ 2 - 0
Ladybird/Qt/Application.h

@@ -46,6 +46,8 @@ private:
     virtual void create_platform_arguments(Core::ArgsParser&) override;
     virtual void create_platform_options(WebView::ChromeOptions&, WebView::WebContentOptions&) override;
 
+    virtual Optional<ByteString> ask_user_for_download_folder() const override;
+
     bool m_enable_qt_networking { false };
 
     TaskManagerWindow* m_task_manager_window { nullptr };

+ 3 - 0
Ladybird/Qt/Tab.cpp

@@ -481,6 +481,9 @@ Tab::Tab(BrowserWindow* window, RefPtr<WebView::WebContentClient> parent_client,
                 }
             })
             .when_rejected([this](auto const& error) {
+                if (error.is_errno() && error.code() == ECANCELED)
+                    return;
+
                 auto error_message = MUST(String::formatted("{}", error));
                 QMessageBox::warning(this, "Ladybird", qstring_from_ak_string(error_message));
             });