mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-08 04:02:52 +00:00
Browser: Add close on finished checkbox to download widget
Let the user choose if they want the download widget to close when finished, also save the users choice for future downloads.
This commit is contained in:
parent
b4da228ea5
commit
29cce65d2f
Notes:
sideshowbarker
2024-07-18 12:17:55 +09:00
Author: https://github.com/metmo
Commit: 29cce65d2f
Pull-request: https://github.com/SerenityOS/serenity/pull/7636
Issue: https://github.com/SerenityOS/serenity/issues/7615
3 changed files with 18 additions and 1 deletions
|
@ -7,12 +7,14 @@
|
|||
#include "DownloadWidget.h"
|
||||
#include <AK/NumberFormat.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/FileStream.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/ImageWidget.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
|
@ -35,6 +37,9 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
m_destination_path = builder.to_string();
|
||||
}
|
||||
|
||||
auto browser_config = Core::ConfigFile::get_for_app("Browser");
|
||||
auto close_on_finish = browser_config->read_bool_entry("Preferences", "CloseDownloadWidgetOnFinish", false);
|
||||
|
||||
m_elapsed_timer.start();
|
||||
m_download = Web::ResourceLoader::the().protocol_client().start_request("GET", url);
|
||||
VERIFY(m_download);
|
||||
|
@ -82,6 +87,14 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
destination_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
destination_label.set_fixed_height(16);
|
||||
|
||||
m_close_on_finish_checkbox = add<GUI::CheckBox>("Close when finished");
|
||||
m_close_on_finish_checkbox->set_checked(close_on_finish);
|
||||
|
||||
m_close_on_finish_checkbox->on_checked = [&]() {
|
||||
auto browser_config = Core::ConfigFile::get_for_app("Browser");
|
||||
browser_config->write_bool_entry("Preferences", "CloseDownloadWidgetOnFinish", m_close_on_finish_checkbox->is_checked());
|
||||
};
|
||||
|
||||
auto& button_container = add<GUI::Widget>();
|
||||
auto& button_container_layout = button_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_container_layout.add_spacer();
|
||||
|
@ -156,6 +169,9 @@ void DownloadWidget::did_finish(bool success)
|
|||
window()->close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_close_on_finish_checkbox->is_checked())
|
||||
window()->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ private:
|
|||
RefPtr<GUI::Label> m_progress_label;
|
||||
RefPtr<GUI::Button> m_cancel_button;
|
||||
RefPtr<GUI::Button> m_close_button;
|
||||
RefPtr<GUI::CheckBox> m_close_on_finish_checkbox;
|
||||
OwnPtr<Core::OutputFileStream> m_output_file_stream;
|
||||
Core::ElapsedTimer m_elapsed_timer;
|
||||
};
|
||||
|
|
|
@ -57,7 +57,7 @@ URL url_from_user_input(const String& input)
|
|||
void Tab::start_download(const URL& url)
|
||||
{
|
||||
auto window = GUI::Window::construct(&this->window());
|
||||
window->resize(300, 150);
|
||||
window->resize(300, 170);
|
||||
window->set_title(String::formatted("0% of {}", url.basename()));
|
||||
window->set_resizable(false);
|
||||
window->set_main_widget<DownloadWidget>(url);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue