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
This commit is contained in:
parent
825ce53fd3
commit
f98b1f635b
Notes:
sideshowbarker
2024-07-19 13:14:01 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f98b1f635b6
4 changed files with 60 additions and 0 deletions
8
Applications/SystemDialog/Makefile
Executable file
8
Applications/SystemDialog/Makefile
Executable file
|
@ -0,0 +1,8 @@
|
|||
include ../../Makefile.common
|
||||
|
||||
OBJS = \
|
||||
main.o
|
||||
|
||||
APP = SystemDialog
|
||||
|
||||
include ../Makefile.common
|
49
Applications/SystemDialog/main.cpp
Normal file
49
Applications/SystemDialog/main.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GDesktop.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GMessageBox.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
static int run_shutdown_dialog(int argc, char** argv);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("usage: SystemDialog <type>\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();
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue