From f98b1f635b65d1a504ac116c821a14a2accfc842 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 16 Jul 2019 21:25:50 +0200 Subject: [PATCH] SystemDialog: Add a new app for showing system dialogs. Currently this will be used by the WindowServer to show some dialogs. This is needed since WindowServer can't use LibGUI and reimplementing message box functionality inside WindowServer would be silly. :^) The only dialog supported in this initial version is --shutdown --- Applications/SystemDialog/Makefile | 8 +++++ Applications/SystemDialog/main.cpp | 49 ++++++++++++++++++++++++++++++ Kernel/build-root-filesystem.sh | 2 ++ Kernel/makeall.sh | 1 + 4 files changed, 60 insertions(+) create mode 100755 Applications/SystemDialog/Makefile create mode 100644 Applications/SystemDialog/main.cpp diff --git a/Applications/SystemDialog/Makefile b/Applications/SystemDialog/Makefile new file mode 100755 index 0000000000..1bd260a73f --- /dev/null +++ b/Applications/SystemDialog/Makefile @@ -0,0 +1,8 @@ +include ../../Makefile.common + +OBJS = \ + main.o + +APP = SystemDialog + +include ../Makefile.common diff --git a/Applications/SystemDialog/main.cpp b/Applications/SystemDialog/main.cpp new file mode 100644 index 0000000000..f5adbb09c0 --- /dev/null +++ b/Applications/SystemDialog/main.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int run_shutdown_dialog(int argc, char** argv); + +int main(int argc, char** argv) +{ + if (argc != 2) { + printf("usage: SystemDialog \n"); + return 0; + } + + if (String(argv[1]) == "--shutdown") + return run_shutdown_dialog(argc, argv); + + fprintf(stderr, "Unknown argument: %s\n", argv[1]); + return 1; +} + +int run_shutdown_dialog(int argc, char** argv) +{ + GApplication app(argc, argv); + + { + GMessageBox box("Shut down Serenity?", "Confirm Shutdown", GMessageBox::Type::Warning, GMessageBox::InputType::OkCancel); + auto result = box.exec(); + + if (result == GMessageBox::ExecOK) { + dbg() << "OK"; + int rc = execl("/bin/shutdown", "/bin/shutdown", "-n", nullptr); + if (rc < 0) { + perror("execl"); + return 1; + } + } else { + dbg() << "Cancel"; + return 0; + } + } + + return app.exec(); +} diff --git a/Kernel/build-root-filesystem.sh b/Kernel/build-root-filesystem.sh index b702d8b2ff..c8c0cd7dec 100755 --- a/Kernel/build-root-filesystem.sh +++ b/Kernel/build-root-filesystem.sh @@ -78,6 +78,7 @@ cp ../Applications/TextEditor/TextEditor mnt/bin/TextEditor cp ../Applications/PaintBrush/PaintBrush mnt/bin/PaintBrush cp ../Applications/QuickShow/QuickShow mnt/bin/QuickShow cp ../Applications/Piano/Piano mnt/bin/Piano +cp ../Applications/SystemDialog/SystemDialog mnt/bin/SystemDialog cp ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld cp ../Demos/HelloWorld2/HelloWorld2 mnt/bin/HelloWorld2 cp ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch @@ -110,6 +111,7 @@ ln -s TextEditor mnt/bin/te ln -s PaintBrush mnt/bin/pb ln -s QuickShow mnt/bin/qs ln -s Piano mnt/bin/pi +ln -s SystemDialog mnt/bin/sd echo "done" # Run local sync script, if it exists diff --git a/Kernel/makeall.sh b/Kernel/makeall.sh index b99e19e762..26be17f250 100755 --- a/Kernel/makeall.sh +++ b/Kernel/makeall.sh @@ -39,6 +39,7 @@ build_targets="$build_targets ../Applications/Downloader" build_targets="$build_targets ../Applications/PaintBrush" build_targets="$build_targets ../Applications/QuickShow" build_targets="$build_targets ../Applications/Piano" +build_targets="$build_targets ../Applications/SystemDialog" build_targets="$build_targets ../DevTools/VisualBuilder" build_targets="$build_targets ../Games/Minesweeper" build_targets="$build_targets ../Games/Snake"