Skip to content

Commit

Permalink
LoginServer: Use new GML compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinesfilmroellchen committed Oct 3, 2023
1 parent d93970e commit ad98116
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
7 changes: 2 additions & 5 deletions Userland/Services/LoginServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ serenity_component(
TARGETS LoginServer
)

stringify_gml(LoginWindow.gml LoginWindowGML.h login_window_gml)
compile_gml(LoginWindow.gml LoginWindowGML.cpp)

set(SOURCES
LoginWindow.cpp
LoginWindowGML.cpp
main.cpp
)

set(GENERATED_SOURCES
LoginWindowGML.h
)

serenity_bin(LoginServer)
target_link_libraries(LoginServer PRIVATE LibCore LibGfx LibGUI LibMain)
12 changes: 7 additions & 5 deletions Userland/Services/LoginServer/LoginWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <LibGUI/Icon.h>
#include <LibGUI/Widget.h>
#include <Services/LoginServer/LoginWindow.h>
#include <Services/LoginServer/LoginWindowGML.h>
#include <Services/LoginServer/Widget.h>

namespace LoginServer {

LoginWindow::LoginWindow(GUI::Window* parent)
: GUI::Window(parent)
Expand All @@ -20,11 +22,9 @@ LoginWindow::LoginWindow(GUI::Window* parent)
set_closeable(false);
set_icon(GUI::Icon::default_icon("ladyball"sv).bitmap_for_size(16));

auto widget = set_main_widget<GUI::Widget>();
widget->load_from_gml(login_window_gml).release_value_but_fixme_should_propagate_errors();
auto widget = MUST(LoginServer::Widget::try_create());
set_main_widget(widget);
m_banner = *widget->find_descendant_of_type_named<GUI::ImageWidget>("banner");
m_banner->load_from_file("/res/graphics/brand-banner.png"sv);
m_banner->set_auto_resize(true);

m_username = *widget->find_descendant_of_type_named<GUI::TextBox>("username");
m_username->set_focus(true);
Expand All @@ -46,3 +46,5 @@ LoginWindow::LoginWindow(GUI::Window* parent)
m_fail_message->set_text({});
};
}

}
3 changes: 2 additions & 1 deletion Userland/Services/LoginServer/LoginWindow.gml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@GUI::Widget {
@LoginServer::Widget {
fill_with_background_color: true
layout: @GUI::VerticalBoxLayout {}

@GUI::ImageWidget {
name: "banner"
bitmap: "/res/graphics/brand-banner.png"
auto_resize: true
}

Expand Down
4 changes: 4 additions & 0 deletions Userland/Services/LoginServer/LoginWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <LibGUI/TextBox.h>
#include <LibGUI/Window.h>

namespace LoginServer {

class LoginWindow final : public GUI::Window {
C_OBJECT(LoginWindow);

Expand All @@ -37,3 +39,5 @@ class LoginWindow final : public GUI::Window {
RefPtr<GUI::Label> m_fail_message;
RefPtr<GUI::Button> m_log_in_button;
};

}
23 changes: 23 additions & 0 deletions Userland/Services/LoginServer/Widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibGUI/Widget.h>

namespace LoginServer {

class Widget : public GUI::Widget {
C_OBJECT_ABSTRACT(Widget)

public:
static ErrorOr<NonnullRefPtr<Widget>> try_create();

private:
Widget() = default;
};

}
4 changes: 2 additions & 2 deletions Userland/Services/LoginServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void child_process(Core::Account const& account)
exit(127);
}

static void login(Core::Account const& account, LoginWindow& window)
static void login(Core::Account const& account, LoginServer::LoginWindow& window)
{
pid_t pid = fork();
if (pid == 0)
Expand Down Expand Up @@ -73,7 +73,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil(nullptr, nullptr));

auto window = LoginWindow::construct();
auto window = LoginServer::LoginWindow::construct();
window->on_submit = [&]() {
auto username = window->username();
auto password = Core::SecretString::take_ownership(window->password().to_byte_buffer());
Expand Down

0 comments on commit ad98116

Please sign in to comment.