mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:12:44 +00:00 
			
		
		
		
	 d0977ac566
			
		
	
	
		d0977ac566
		
	
	
	
	
		
			
			The Core::Version API now returns ErrorOr<String>, and the GUI::AboutDialog API was adjusted to accommodate this.
		
			
				
	
	
		
			74 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  * Copyright (c) 2022, the SerenityOS developers.
 | |
|  * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/StringBuilder.h>
 | |
| #include <LibGUI/AboutDialog.h>
 | |
| #include <LibGUI/AboutDialogGML.h>
 | |
| #include <LibGUI/BoxLayout.h>
 | |
| #include <LibGUI/Button.h>
 | |
| #include <LibGUI/ImageWidget.h>
 | |
| #include <LibGUI/Label.h>
 | |
| #include <LibGUI/Widget.h>
 | |
| #include <LibGfx/Font/Font.h>
 | |
| #include <LibGfx/Font/FontDatabase.h>
 | |
| 
 | |
| namespace GUI {
 | |
| 
 | |
| ErrorOr<NonnullRefPtr<AboutDialog>> AboutDialog::try_create(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window)
 | |
| {
 | |
|     auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AboutDialog(name, version, icon, parent_window)));
 | |
|     dialog->set_title(DeprecatedString::formatted("About {}", name));
 | |
| 
 | |
|     auto widget = TRY(dialog->set_main_widget<Widget>());
 | |
|     TRY(widget->load_from_gml(about_dialog_gml));
 | |
| 
 | |
|     auto icon_wrapper = widget->find_descendant_of_type_named<Widget>("icon_wrapper");
 | |
|     if (icon) {
 | |
|         icon_wrapper->set_visible(true);
 | |
|         auto icon_image = widget->find_descendant_of_type_named<ImageWidget>("icon");
 | |
|         icon_image->set_bitmap(icon);
 | |
|     } else {
 | |
|         icon_wrapper->set_visible(false);
 | |
|     }
 | |
| 
 | |
|     widget->find_descendant_of_type_named<GUI::Label>("name")->set_text(name.to_deprecated_string());
 | |
|     // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
 | |
|     widget->find_descendant_of_type_named<GUI::Label>("serenity_os")->set_visible(name != "SerenityOS");
 | |
|     widget->find_descendant_of_type_named<GUI::Label>("version")->set_text(version.to_deprecated_string());
 | |
| 
 | |
|     auto ok_button = widget->find_descendant_of_type_named<DialogButton>("ok_button");
 | |
|     ok_button->on_click = [dialog](auto) {
 | |
|         dialog->done(ExecResult::OK);
 | |
|     };
 | |
| 
 | |
|     return dialog;
 | |
| }
 | |
| 
 | |
| AboutDialog::AboutDialog(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window)
 | |
|     : Dialog(parent_window)
 | |
|     , m_name(move(name))
 | |
|     , m_version_string(move(version))
 | |
|     , m_icon(move(icon))
 | |
| {
 | |
|     resize(413, 204);
 | |
|     set_resizable(false);
 | |
| 
 | |
|     if (parent_window)
 | |
|         set_icon(parent_window->icon());
 | |
| }
 | |
| 
 | |
| ErrorOr<void> AboutDialog::show(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window, RefPtr<Gfx::Bitmap const> window_icon)
 | |
| {
 | |
|     auto dialog = TRY(AboutDialog::try_create(move(name), move(version), move(icon), parent_window));
 | |
|     if (window_icon)
 | |
|         dialog->set_icon(window_icon);
 | |
|     dialog->exec();
 | |
|     return {};
 | |
| }
 | |
| 
 | |
| }
 |