Serenity Operating System
at portability 113 lines 4.4 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <LibGUI/Application.h> 28#include <LibGUI/BoxLayout.h> 29#include <LibGUI/Button.h> 30#include <LibGUI/Desktop.h> 31#include <LibGUI/Label.h> 32#include <LibGUI/Window.h> 33#include <LibGfx/Font.h> 34#include <stdio.h> 35#include <sys/utsname.h> 36 37int main(int argc, char** argv) 38{ 39 if (pledge("stdio shared_buffer accept rpath unix cpath fattr", nullptr) < 0) { 40 perror("pledge"); 41 return 1; 42 } 43 44 GUI::Application app(argc, argv); 45 46 if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) { 47 perror("pledge"); 48 return 1; 49 } 50 51 if (unveil("/res", "r") < 0) { 52 perror("unveil"); 53 return 1; 54 } 55 56 unveil(nullptr, nullptr); 57 58 auto window = GUI::Window::construct(); 59 window->set_title("About SerenityOS"); 60 Gfx::Rect window_rect { 0, 0, 240, 180 }; 61 window_rect.center_within(GUI::Desktop::the().rect()); 62 window->set_resizable(false); 63 window->set_rect(window_rect); 64 65 auto widget = GUI::Widget::construct(); 66 window->set_main_widget(widget); 67 widget->set_fill_with_background_color(true); 68 widget->set_layout(make<GUI::VerticalBoxLayout>()); 69 widget->layout()->set_margins({ 0, 8, 0, 8 }); 70 widget->layout()->set_spacing(8); 71 72 auto icon_label = widget->add<GUI::Label>(); 73 icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/serenity.png")); 74 icon_label->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); 75 icon_label->set_preferred_size(icon_label->icon()->size()); 76 77 auto label = widget->add<GUI::Label>(); 78 label->set_font(Gfx::Font::default_bold_font()); 79 label->set_text("SerenityOS"); 80 label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); 81 label->set_preferred_size(0, 11); 82 83 utsname uts; 84 int rc = uname(&uts); 85 ASSERT(rc == 0); 86 87 auto version_label = widget->add<GUI::Label>(); 88 version_label->set_text(String::format("Version %s", uts.release)); 89 version_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); 90 version_label->set_preferred_size(0, 11); 91 92 auto git_info_label = widget->add<GUI::Label>(); 93 git_info_label->set_text(String::format("Built on %s@%s", GIT_BRANCH, GIT_COMMIT)); 94 git_info_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); 95 git_info_label->set_preferred_size(0, 11); 96 97 auto git_changes_label = widget->add<GUI::Label>(); 98 git_changes_label->set_text(String::format("Changes: %s", GIT_CHANGES)); 99 git_changes_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); 100 git_changes_label->set_preferred_size(0, 11); 101 102 auto quit_button = widget->add<GUI::Button>(); 103 quit_button->set_text("Okay"); 104 quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); 105 quit_button->set_preferred_size(100, 20); 106 quit_button->on_click = [](GUI::Button&) { 107 GUI::Application::the().quit(0); 108 }; 109 110 quit_button->set_focus(true); 111 window->show(); 112 return app.exec(); 113}