From 136d287ae121eb8bfb1d9c5c0857cc5aa2fb507f Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 19 Sep 2014 10:20:49 -0400 Subject: Add support for detecting whether the running user has permission to shutdown/restart the system, and enable/disable those options in the logout menu appropriately. --- libLumina/LuminaOS-DragonFly.cpp | 5 +++++ libLumina/LuminaOS-FreeBSD.cpp | 7 +++++++ libLumina/LuminaOS-Linux.cpp | 5 +++++ libLumina/LuminaOS-OpenBSD.cpp | 5 +++++ libLumina/LuminaOS-template.cpp | 5 +++++ libLumina/LuminaOS.h | 2 ++ lumina-desktop/SystemWindow.cpp | 5 +++++ 7 files changed, 34 insertions(+) diff --git a/libLumina/LuminaOS-DragonFly.cpp b/libLumina/LuminaOS-DragonFly.cpp index 990bf9f7..6d59f0d7 100644 --- a/libLumina/LuminaOS-DragonFly.cpp +++ b/libLumina/LuminaOS-DragonFly.cpp @@ -131,6 +131,11 @@ void LOS::startMixerUtility(){ QProcess::startDetached("pc-mixer -notray"); } +//Check for user system permission (shutdown/restart) +bool LOS::userHasShutdownAccess(){ + return true; //not implemented yet +} + //System Shutdown void LOS::systemShutdown(){ //start poweroff sequence QProcess::startDetached("shutdown -p now"); diff --git a/libLumina/LuminaOS-FreeBSD.cpp b/libLumina/LuminaOS-FreeBSD.cpp index a078687d..97f465e2 100644 --- a/libLumina/LuminaOS-FreeBSD.cpp +++ b/libLumina/LuminaOS-FreeBSD.cpp @@ -132,6 +132,13 @@ void LOS::startMixerUtility(){ QProcess::startDetached("pc-mixer -notray"); } +//Check for user system permission (shutdown/restart) +bool LOS::userHasShutdownAccess(){ + //User needs to be a part of the operator group to be able to run the shutdown command + QStringList groups = LUtils::getCmdOutput("id -Gn").join(" ").split(" "); + return groups.contains("operator"); //not implemented yet +} + //System Shutdown void LOS::systemShutdown(){ //start poweroff sequence QProcess::startDetached("shutdown -p now"); diff --git a/libLumina/LuminaOS-Linux.cpp b/libLumina/LuminaOS-Linux.cpp index b7bb3685..af8c740f 100644 --- a/libLumina/LuminaOS-Linux.cpp +++ b/libLumina/LuminaOS-Linux.cpp @@ -114,6 +114,11 @@ void LOS::startMixerUtility(){ QProcess::startDetached("/usr/bin/pavucontrol"); } +//Check for user system permission (shutdown/restart) +bool LOS::userHasShutdownAccess(){ + return true; //not implemented yet +} + //System Shutdown void LOS::systemShutdown(){ //start poweroff sequence QProcess::startDetached("shutdown -h now"); diff --git a/libLumina/LuminaOS-OpenBSD.cpp b/libLumina/LuminaOS-OpenBSD.cpp index 770e3a3a..34ae713c 100644 --- a/libLumina/LuminaOS-OpenBSD.cpp +++ b/libLumina/LuminaOS-OpenBSD.cpp @@ -142,6 +142,11 @@ void LOS::startMixerUtility(){ //Not implemented yet for OpenBSD } +//Check for user system permission (shutdown/restart) +bool LOS::userHasShutdownAccess(){ + return true; //not implemented yet +} + //System Shutdown void LOS::systemShutdown(){ //start poweroff sequence QProcess::startDetached("shutdown -hp now"); diff --git a/libLumina/LuminaOS-template.cpp b/libLumina/LuminaOS-template.cpp index 0bfac22a..b975d5a1 100644 --- a/libLumina/LuminaOS-template.cpp +++ b/libLumina/LuminaOS-template.cpp @@ -64,6 +64,11 @@ void LOS::startMixerUtility(){ //not implemented yet } +//Check for user system permission (shutdown/restart) +bool LOS::userHasShutdownAccess(){ + return false; //not implemented yet +} + //System Shutdown void LOS::systemShutdown(){ //start poweroff sequence QProcess::startDetached("shutdown -p now"); diff --git a/libLumina/LuminaOS.h b/libLumina/LuminaOS.h index 6b755e03..f4fe8970 100644 --- a/libLumina/LuminaOS.h +++ b/libLumina/LuminaOS.h @@ -51,6 +51,8 @@ public: //Launch the graphical audio mixer utility static void startMixerUtility(); + //Check for user system permission (shutdown/restart) + static bool userHasShutdownAccess(); //System Shutdown static void systemShutdown(); //start poweroff sequence //System Restart diff --git a/lumina-desktop/SystemWindow.cpp b/lumina-desktop/SystemWindow.cpp index dc9dc488..10d44524 100644 --- a/lumina-desktop/SystemWindow.cpp +++ b/lumina-desktop/SystemWindow.cpp @@ -20,6 +20,11 @@ SystemWindow::SystemWindow() : QDialog(), ui(new Ui::SystemWindow){ connect(ui->tool_shutdown, SIGNAL(clicked()), this, SLOT(sysShutdown()) ); connect(ui->push_cancel, SIGNAL(clicked()), this, SLOT(sysCancel()) ); connect(ui->push_lock, SIGNAL(clicked()), this, SLOT(sysLock()) ); + //Disable the shutdown/restart buttons if necessary + if( !LOS::userHasShutdownAccess() ){ + ui->tool_restart->setEnabled(false); + ui->tool_shutdown->setEnabled(false); + } //Center this window on the screen QDesktopWidget desktop; this->move(desktop.screenGeometry().width()/2 - this->width()/2, desktop.screenGeometry().height()/2 - this->height()/2); -- cgit