summaryrefslogtreecommitdiff
path: root/Applications/SystemDialog/main.cpp
blob: 82d48cb1ddef971e44ce64c2e1860efecdb8b71d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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);

    {
        auto result = GMessageBox::show("Shut down Serenity?", "Confirm Shutdown", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel);

        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();
}