From 6e6f2d46c03b255062c8fdb6f64f0e587445a6ef Mon Sep 17 00:00:00 2001
From: myshow <296570182@qq.com>
Date: Thu, 3 Dec 2020 11:05:51 +0800
Subject: [PATCH] fix-poweroff

---
 ukui-session/sessiondbusadaptor.h | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/ukui-session/sessiondbusadaptor.h b/ukui-session/sessiondbusadaptor.h
index c005702..4da2b55 100644
--- a/ukui-session/sessiondbusadaptor.h
+++ b/ukui-session/sessiondbusadaptor.h
@@ -21,6 +21,7 @@
 #define SESSIONDBUSADAPTOR_H
 
 #include <QtDBus>
+#include <QMessageBox>
 #include "../tools/ukuipower.h"
 #include "modulemanager.h"
 
@@ -54,7 +55,16 @@ public slots:
 
     bool canPowerOff()
     {
-        return mPower->canAction(UkuiPower::PowerShutdown);
+        QProcess p;
+        p.start("bash", QStringList() <<"-c" << "who | wc -l");
+        p.waitForFinished();
+        QString ret = p.readAllStandardOutput();
+        int user = ret.toInt();
+        if (user > 1)
+            return false;
+        else
+            return true;
+        // return mPower->canAction(UkuiPower::PowerShutdown);
     }
 
     Q_NOREPLY void logout()
@@ -74,10 +84,19 @@ public slots:
     Q_NOREPLY void powerOff()
     {
         if(mPower->canAction(UkuiPower::PowerShutdown)){
-            mManager->logout(false);
-            mPower->doAction(UkuiPower::PowerShutdown);
+            // mManager->logout(false);
+            // mPower->doAction(UkuiPower::PowerShutdown);
+            QProcess::execute("shutdown -h now");
+            // QProcess::execute("poweroff");
+        }
+        else {
+            //弹框提示无法生效?
+            QMessageBox msg;
+            msg.setWindowTitle(tr("Error"));
+            msg.setText(tr("The computer could not be shut down!"));
+            msg.addButton(tr("Ok"), QMessageBox::AcceptRole);
+            msg.exec();
         }
-        //QCoreApplication::exit(0);
     }
 
 //    QDBusVariant listModules()
-- 
2.29.2.windows.2

