summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vella <nick@nxk.io>2020-05-24 14:26:33 +0000
committerAndreas Kling <kling@serenityos.org>2020-05-27 11:44:19 +0200
commite53fa97cfb71b29839ddda355374e36888e4e4f5 (patch)
tree5f49c79fd08092250371e7cf8af7f5ca1836e4ce
parent0d5b43552d4f049b2d353378e60bba8140f3c68b (diff)
downloadserenity-e53fa97cfb71b29839ddda355374e36888e4e4f5.zip
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.
-rw-r--r--Applications/About/main.cpp77
-rw-r--r--Base/res/brand-banner.pngbin0 -> 49918 bytes
-rw-r--r--Base/res/icons/buggie-about.pngbin0 -> 17630 bytes
-rw-r--r--Libraries/LibGUI/AboutDialog.cpp74
-rw-r--r--Libraries/LibGUI/AboutDialog.h5
-rwxr-xr-xMeta/build-root-filesystem.sh5
6 files changed, 74 insertions, 87 deletions
diff --git a/Applications/About/main.cpp b/Applications/About/main.cpp
index 336ccb6f00..c3fa95a3b5 100644
--- a/Applications/About/main.cpp
+++ b/Applications/About/main.cpp
@@ -24,13 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <LibGUI/AboutDialog.h>
#include <LibGUI/Application.h>
-#include <LibGUI/BoxLayout.h>
-#include <LibGUI/Button.h>
-#include <LibGUI/Desktop.h>
-#include <LibGUI/Label.h>
-#include <LibGUI/Window.h>
-#include <LibGfx/Font.h>
+#include <LibGfx/Bitmap.h>
#include <stdio.h>
#include <sys/utsname.h>
@@ -55,73 +51,6 @@ int main(int argc, char** argv)
unveil(nullptr, nullptr);
- auto window = GUI::Window::construct();
- 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();
+ GUI::AboutDialog::show("SerenityOS", nullptr, nullptr, Gfx::Bitmap::load_from_file("/res/icons/16x16/ladybug.png"));
return app.exec();
}
diff --git a/Base/res/brand-banner.png b/Base/res/brand-banner.png
new file mode 100644
index 0000000000..872cf0eee5
--- /dev/null
+++ b/Base/res/brand-banner.png
Binary files differ
diff --git a/Base/res/icons/buggie-about.png b/Base/res/icons/buggie-about.png
new file mode 100644
index 0000000000..9438ed31f4
--- /dev/null
+++ b/Base/res/icons/buggie-about.png
Binary files differ
diff --git a/Libraries/LibGUI/AboutDialog.cpp b/Libraries/LibGUI/AboutDialog.cpp
index e0fc528e18..aad6b05cc0 100644
--- a/Libraries/LibGUI/AboutDialog.cpp
+++ b/Libraries/LibGUI/AboutDialog.cpp
@@ -24,6 +24,8 @@
* 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/BoxLayout.h>
#include <LibGUI/Button.h>
@@ -38,7 +40,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
, m_name(name)
, m_icon(icon)
{
- resize(230, 120);
+ resize(413, 315);
set_title(String::format("About %s", m_name.characters()));
set_resizable(false);
@@ -47,21 +49,45 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
auto& widget = set_main_widget<Widget>();
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_preferred_size(48, 0);
+ left_container.set_preferred_size(100, 0);
left_container.set_layout<VerticalBoxLayout>();
- auto& icon_label = left_container.add<Label>();
- 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();
+ left_container.layout()->set_margins({ 0, 12, 0, 0 });
+
+ 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& right_container = widget.add<Widget>();
+ 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.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& 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());
};
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");
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();
+}
+
}
diff --git a/Libraries/LibGUI/AboutDialog.h b/Libraries/LibGUI/AboutDialog.h
index 562f404c17..a3528324f2 100644
--- a/Libraries/LibGUI/AboutDialog.h
+++ b/Libraries/LibGUI/AboutDialog.h
@@ -35,14 +35,17 @@ class AboutDialog final : public Dialog {
public:
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);
+ if (window_icon)
+ dialog->set_icon(window_icon);
dialog->exec();
}
private:
AboutDialog(const StringView& name, const Gfx::Bitmap* icon = nullptr, Window* parent_window = nullptr);
+ String version_string() const;
String m_name;
RefPtr<Gfx::Bitmap> m_icon;
diff --git a/Meta/build-root-filesystem.sh b/Meta/build-root-filesystem.sh
index 3ca54dbc84..ca7614d50c 100755
--- a/Meta/build-root-filesystem.sh
+++ b/Meta/build-root-filesystem.sh
@@ -106,6 +106,11 @@ chmod 4750 mnt/bin/shutdown
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... "
mkdir -p mnt/root
mkdir -p mnt/home/anon