Skip to content

Commit

Permalink
SystemMenu: Rename PowerDialog => ShutdownDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed May 19, 2020
1 parent e5ea243 commit efb3a34
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Services/SystemMenu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(SOURCES
main.cpp
PowerDialog.cpp
ShutdownDialog.cpp
)

serenity_bin(SystemMenu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "ShutdownDialog.h"
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibGUI/BoxLayout.h>
Expand All @@ -34,33 +35,31 @@
#include <LibGUI/Widget.h>
#include <LibGfx/Font.h>

#include "PowerDialog.h"

struct PowerOption {
struct Option {
String title;
Vector<char const*> cmd;
bool enabled;
bool default_action;
};

static const Vector<PowerOption> options = {
static const Vector<Option> options = {
{ "Shut down", { "/bin/shutdown", "--now", nullptr }, true, true },
{ "Restart", { "/bin/reboot", nullptr }, true, false },
{ "Log out", {}, false, false },
{ "Sleep", {}, false, false },
};

Vector<char const*> PowerDialog::show()
Vector<char const*> ShutdownDialog::show()
{
auto rc = PowerDialog::construct()->exec();
if(rc == ExecResult::ExecOK)
auto rc = ShutdownDialog::construct()->exec();
if (rc == ExecResult::ExecOK)
return options[rc].cmd;

return {};
}

PowerDialog::PowerDialog()
: GUI::Dialog(nullptr)
ShutdownDialog::ShutdownDialog()
: Dialog(nullptr)
{
Gfx::Rect rect({ 0, 0, 180, 180 + ((static_cast<int>(options.size()) - 3) * 16) });
rect.center_within(GUI::Desktop::the().rect());
Expand Down Expand Up @@ -114,6 +113,6 @@ PowerDialog::PowerDialog()
cancel_button.set_text("Cancel");
}

PowerDialog::~PowerDialog()
ShutdownDialog::~ShutdownDialog()
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
*/

#include <AK/Vector.h>
#include <LibCore/Object.h>
#include <LibGUI/Dialog.h>

class PowerDialog : public GUI::Dialog {
C_OBJECT(PowerDialog)
class ShutdownDialog : public GUI::Dialog {
C_OBJECT(ShutdownDialog);

public:
static Vector<char const*> show();

private:
PowerDialog();
~PowerDialog();
ShutdownDialog();
virtual ~ShutdownDialog() override;

int m_selected_option { -1 };
};
4 changes: 2 additions & 2 deletions Services/SystemMenu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "PowerDialog.h"
#include "ShutdownDialog.h"
#include <AK/FileSystemPath.h>
#include <AK/QuickSort.h>
#include <LibCore/ConfigFile.h>
Expand Down Expand Up @@ -203,7 +203,7 @@ NonnullRefPtr<GUI::Menu> build_system_menu()
}));
system_menu->add_separator();
system_menu->add_action(GUI::Action::create("Exit...", [](auto&) {
Vector<char const*> command = PowerDialog::show();
auto command = ShutdownDialog::show();

if (command.size() == 0)
return;
Expand Down

0 comments on commit efb3a34

Please sign in to comment.