mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 00:35:08 +00:00
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
4 changed files with 60 additions and 0 deletions
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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue