mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibGUI, About: Implement system-wide W2k-esque About dialog
The new About dialog reads version information from /res/version.ini, which is generated at build time.
This commit is contained in:
parent
0d5b43552d
commit
e53fa97cfb
6 changed files with 74 additions and 87 deletions
|
@ -24,13 +24,9 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibGUI/AboutDialog.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGUI/Button.h>
|
|
||||||
#include <LibGUI/Desktop.h>
|
|
||||||
#include <LibGUI/Label.h>
|
|
||||||
#include <LibGUI/Window.h>
|
|
||||||
#include <LibGfx/Font.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
@ -55,73 +51,6 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
unveil(nullptr, nullptr);
|
unveil(nullptr, nullptr);
|
||||||
|
|
||||||
auto window = GUI::Window::construct();
|
GUI::AboutDialog::show("SerenityOS", nullptr, nullptr, Gfx::Bitmap::load_from_file("/res/icons/16x16/ladybug.png"));
|
||||||
window->set_title("About SerenityOS");
|
|
||||||
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/ladybug.png"));
|
|
||||||
Gfx::Rect window_rect { 0, 0, 224, 178 };
|
|
||||||
window_rect.center_within(GUI::Desktop::the().rect());
|
|
||||||
window->set_resizable(false);
|
|
||||||
window->set_rect(window_rect);
|
|
||||||
|
|
||||||
auto& outer_widget = window->set_main_widget<GUI::Widget>();
|
|
||||||
outer_widget.set_fill_with_background_color(true);
|
|
||||||
outer_widget.set_layout<GUI::VerticalBoxLayout>();
|
|
||||||
outer_widget.layout()->set_margins({ 8, 8, 8, 8 });
|
|
||||||
|
|
||||||
auto& inner_widget = outer_widget.add<GUI::Widget>();
|
|
||||||
inner_widget.set_layout<GUI::HorizontalBoxLayout>();
|
|
||||||
inner_widget.layout()->set_spacing(8);
|
|
||||||
|
|
||||||
auto& left_outer_container = inner_widget.add<GUI::Widget>();
|
|
||||||
left_outer_container.set_layout<GUI::HorizontalBoxLayout>();
|
|
||||||
|
|
||||||
auto& left_inner_container = left_outer_container.add<GUI::Widget>();
|
|
||||||
left_inner_container.set_layout<GUI::VerticalBoxLayout>();
|
|
||||||
left_inner_container.layout()->set_spacing(8);
|
|
||||||
left_inner_container.set_preferred_size(0, 50);
|
|
||||||
left_inner_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
|
||||||
|
|
||||||
auto& label = left_inner_container.add<GUI::Label>();
|
|
||||||
label.set_text_alignment(Gfx::TextAlignment::CenterRight);
|
|
||||||
label.set_font(Gfx::Font::default_bold_font());
|
|
||||||
label.set_text("SerenityOS");
|
|
||||||
label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
|
||||||
label.set_preferred_size(0, 11);
|
|
||||||
|
|
||||||
utsname uts;
|
|
||||||
int rc = uname(&uts);
|
|
||||||
ASSERT(rc == 0);
|
|
||||||
|
|
||||||
auto& version_label = left_inner_container.add<GUI::Label>();
|
|
||||||
version_label.set_text_alignment(Gfx::TextAlignment::CenterRight);
|
|
||||||
version_label.set_text(String::format("Version %s", uts.release));
|
|
||||||
version_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
|
||||||
version_label.set_preferred_size(0, 11);
|
|
||||||
|
|
||||||
auto& git_info_label = left_inner_container.add<GUI::Label>();
|
|
||||||
git_info_label.set_text_alignment(Gfx::TextAlignment::CenterRight);
|
|
||||||
git_info_label.set_text(String::format("%s@%s", GIT_BRANCH, GIT_COMMIT));
|
|
||||||
git_info_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
|
||||||
git_info_label.set_preferred_size(0, 11);
|
|
||||||
|
|
||||||
auto& right_container = inner_widget.add<GUI::Widget>();
|
|
||||||
right_container.set_layout<GUI::VerticalBoxLayout>();
|
|
||||||
|
|
||||||
auto& icon_label = right_container.add<GUI::Label>();
|
|
||||||
icon_label.set_icon(Gfx::Bitmap::load_from_file("/res/icons/buggie.png"));
|
|
||||||
icon_label.set_tooltip("Buggie");
|
|
||||||
icon_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
|
||||||
icon_label.set_preferred_size(icon_label.icon()->size());
|
|
||||||
|
|
||||||
auto& quit_button = outer_widget.add<GUI::Button>();
|
|
||||||
quit_button.set_text("Okay");
|
|
||||||
quit_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
|
||||||
quit_button.set_preferred_size(100, 20);
|
|
||||||
quit_button.on_click = [](auto) {
|
|
||||||
GUI::Application::the().quit(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
quit_button.set_focus(true);
|
|
||||||
window->show();
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
BIN
Base/res/brand-banner.png
Normal file
BIN
Base/res/brand-banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
BIN
Base/res/icons/buggie-about.png
Normal file
BIN
Base/res/icons/buggie-about.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -24,6 +24,8 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <LibCore/ConfigFile.h>
|
||||||
#include <LibGUI/AboutDialog.h>
|
#include <LibGUI/AboutDialog.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
|
@ -38,7 +40,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_icon(icon)
|
, m_icon(icon)
|
||||||
{
|
{
|
||||||
resize(230, 120);
|
resize(413, 315);
|
||||||
set_title(String::format("About %s", m_name.characters()));
|
set_title(String::format("About %s", m_name.characters()));
|
||||||
set_resizable(false);
|
set_resizable(false);
|
||||||
|
|
||||||
|
@ -47,21 +49,45 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
|
||||||
|
|
||||||
auto& widget = set_main_widget<Widget>();
|
auto& widget = set_main_widget<Widget>();
|
||||||
widget.set_fill_with_background_color(true);
|
widget.set_fill_with_background_color(true);
|
||||||
widget.set_layout<HorizontalBoxLayout>();
|
widget.set_layout<VerticalBoxLayout>();
|
||||||
|
widget.layout()->set_spacing(0);
|
||||||
|
|
||||||
auto& left_container = widget.add<Widget>();
|
auto& banner_label = widget.add<GUI::Label>();
|
||||||
|
banner_label.set_icon(Gfx::Bitmap::load_from_file("/res/brand-banner.png"));
|
||||||
|
banner_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||||
|
banner_label.set_preferred_size(banner_label.icon()->size());
|
||||||
|
|
||||||
|
auto& content_container = widget.add<Widget>();
|
||||||
|
content_container.set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
|
||||||
|
content_container.set_layout<HorizontalBoxLayout>();
|
||||||
|
|
||||||
|
auto& left_container = content_container.add<Widget>();
|
||||||
left_container.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
left_container.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||||
left_container.set_preferred_size(48, 0);
|
left_container.set_preferred_size(100, 0);
|
||||||
left_container.set_layout<VerticalBoxLayout>();
|
left_container.set_layout<VerticalBoxLayout>();
|
||||||
auto& icon_label = left_container.add<Label>();
|
left_container.layout()->set_margins({ 0, 12, 0, 0 });
|
||||||
icon_label.set_icon(m_icon);
|
|
||||||
icon_label.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
|
||||||
icon_label.set_preferred_size(40, 40);
|
|
||||||
left_container.layout()->add_spacer();
|
|
||||||
|
|
||||||
auto& right_container = widget.add<Widget>();
|
if (icon) {
|
||||||
|
auto& icon_wrapper = left_container.add<Widget>();
|
||||||
|
icon_wrapper.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||||
|
icon_wrapper.set_preferred_size(32, 48);
|
||||||
|
icon_wrapper.set_layout<VerticalBoxLayout>();
|
||||||
|
|
||||||
|
auto& icon_label = icon_wrapper.add<Label>();
|
||||||
|
icon_label.set_icon(m_icon);
|
||||||
|
icon_label.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||||
|
icon_label.set_preferred_size(32, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& buggie_label = left_container.add<Label>();
|
||||||
|
buggie_label.set_icon(Gfx::Bitmap::load_from_file("/res/icons/buggie-about.png"));
|
||||||
|
buggie_label.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||||
|
buggie_label.set_preferred_size(48, 104);
|
||||||
|
buggie_label.set_tooltip("Buggie!");
|
||||||
|
|
||||||
|
auto& right_container = content_container.add<Widget>();
|
||||||
right_container.set_layout<VerticalBoxLayout>();
|
right_container.set_layout<VerticalBoxLayout>();
|
||||||
right_container.layout()->set_margins({ 0, 4, 4, 4 });
|
right_container.layout()->set_margins({ 0, 12, 12, 8 });
|
||||||
|
|
||||||
auto make_label = [&](const StringView& text, bool bold = false) {
|
auto make_label = [&](const StringView& text, bool bold = false) {
|
||||||
auto& label = right_container.add<Label>(text);
|
auto& label = right_container.add<Label>(text);
|
||||||
|
@ -72,7 +98,10 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
|
||||||
label.set_font(Gfx::Font::default_bold_font());
|
label.set_font(Gfx::Font::default_bold_font());
|
||||||
};
|
};
|
||||||
make_label(m_name, true);
|
make_label(m_name, true);
|
||||||
make_label("SerenityOS");
|
// If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
|
||||||
|
if (m_name != "SerenityOS")
|
||||||
|
make_label("SerenityOS");
|
||||||
|
make_label(version_string());
|
||||||
make_label("\xC2\xA9 The SerenityOS developers");
|
make_label("\xC2\xA9 The SerenityOS developers");
|
||||||
|
|
||||||
right_container.layout()->add_spacer();
|
right_container.layout()->add_spacer();
|
||||||
|
@ -94,4 +123,25 @@ AboutDialog::~AboutDialog()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String AboutDialog::version_string() const
|
||||||
|
{
|
||||||
|
auto version_config = Core::ConfigFile::open("/res/version.ini");
|
||||||
|
auto major_version = version_config->read_entry("Version", "Major", "0");
|
||||||
|
auto minor_version = version_config->read_entry("Version", "Minor", "0");
|
||||||
|
auto git_version = version_config->read_entry("Version", "Git", "");
|
||||||
|
|
||||||
|
StringBuilder builder;
|
||||||
|
builder.append("Version ");
|
||||||
|
builder.append(major_version);
|
||||||
|
builder.append('.');
|
||||||
|
builder.append(minor_version);
|
||||||
|
|
||||||
|
if (git_version != "") {
|
||||||
|
builder.append(".g");
|
||||||
|
builder.append(git_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,14 +35,17 @@ class AboutDialog final : public Dialog {
|
||||||
public:
|
public:
|
||||||
virtual ~AboutDialog() override;
|
virtual ~AboutDialog() override;
|
||||||
|
|
||||||
static void show(const StringView& name, const Gfx::Bitmap* icon = nullptr, Window* parent_window = nullptr)
|
static void show(const StringView& name, const Gfx::Bitmap* icon = nullptr, Window* parent_window = nullptr, const Gfx::Bitmap* window_icon = nullptr)
|
||||||
{
|
{
|
||||||
auto dialog = AboutDialog::construct(name, icon, parent_window);
|
auto dialog = AboutDialog::construct(name, icon, parent_window);
|
||||||
|
if (window_icon)
|
||||||
|
dialog->set_icon(window_icon);
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AboutDialog(const StringView& name, const Gfx::Bitmap* icon = nullptr, Window* parent_window = nullptr);
|
AboutDialog(const StringView& name, const Gfx::Bitmap* icon = nullptr, Window* parent_window = nullptr);
|
||||||
|
String version_string() const;
|
||||||
|
|
||||||
String m_name;
|
String m_name;
|
||||||
RefPtr<Gfx::Bitmap> m_icon;
|
RefPtr<Gfx::Bitmap> m_icon;
|
||||||
|
|
|
@ -106,6 +106,11 @@ chmod 4750 mnt/bin/shutdown
|
||||||
|
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|
||||||
|
printf "writing version file... "
|
||||||
|
GIT_HASH=$( (git log --pretty=format:'%h' -n 1 | head -c 7) || true )
|
||||||
|
printf "[Version]\nMajor=1\nMinor=0\nGit=%s\n" "$GIT_HASH" > mnt/res/version.ini
|
||||||
|
echo "done"
|
||||||
|
|
||||||
printf "installing users... "
|
printf "installing users... "
|
||||||
mkdir -p mnt/root
|
mkdir -p mnt/root
|
||||||
mkdir -p mnt/home/anon
|
mkdir -p mnt/home/anon
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue