8688 【系统关机/注销】增加关机/注销提示

This commit is contained in:
zhaominyong 2022-06-10 16:28:29 +08:00
parent 7db0284459
commit 1746e5da40
2 changed files with 73 additions and 0 deletions

View File

@ -4,6 +4,12 @@
#include <QTimer>
#include <QDateTime>
#include <QDBusArgument>
#include <QDBusMessage>
#include <QDBusPendingReply>
#include <QDBusMessage>
#include <QDBusUnixFileDescriptor>
#include <QDBusConnection>
#include <mutex>
#include <sys/reboot.h>
#include <kysec/status.h>
@ -449,6 +455,11 @@ bool MyBackupManager::lock(int frontUid)
return false;
}
// 用于替换上面的文件锁的对应需求8688
// if (!inhibit())
// return false;
inhibit();
m_fdLockFile = lock_file_fd;
m_backupState = BackupState::PREPARING;
m_isActive = true;
@ -458,6 +469,63 @@ bool MyBackupManager::lock(int frontUid)
return true;
}
/**
* @brief session关机用dbus新接口Inhibit来替换锁文件的方式
* Inhibti函数有四个参数
what:shutdown()sleep shutdown:sleep
who:ukui-sessions
whypackage installing
mode:block()delay
使block
使ListInhibitors方法获取当前的inhibit锁
* @return
*/
bool MyBackupManager::inhibit()
{
QDBusMessage message;
message = QDBusMessage::createMethodCall("org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
QStringLiteral("Inhibit"));
QString why("The backup and restore tool is busy, please wait.");
// 区分中英文
QString locale = QLocale::system().name();
if (locale == "zh_CN") {
why = QString("备份还原工具正在忙碌,请稍等");
} else if (locale == "bo_CN") {
why = QString("གྲབས་ཉར་སོར་ཆུད་ལག་ཆ་བྲེལ་བཞིན་ཡོད་།ཏོག་ཙམ་སྒུག་རོགས་།");
}
// QVariantList({what, who, why, mode})
QVariantList args;
args << QString("shutdown:sleep");
args << QString("backup-daemon");
args << why;
args << QString("block");
message.setArguments(args);
QDBusPendingReply<QDBusUnixFileDescriptor> reply = QDBusConnection::systemBus().call(message);
if (!reply.isValid()) {
qDebug() << "inhibit faile!";
return false;
}
QDBusUnixFileDescriptor inhibitFileDescriptor = reply.value();
inhibitFileDescriptor.swap(m_inhibitFileDescriptor);
qDebug() << "inhibit success!";
return true;
}
void MyBackupManager::uninhibit()
{
if (!m_inhibitFileDescriptor.isValid()) {
return;
}
qDebug() << "uninhibit success!";
m_inhibitFileDescriptor = QDBusUnixFileDescriptor();
}
/**
* @brief
* @return bool
@ -469,6 +537,7 @@ bool MyBackupManager::unlock()
setKysecStatus(true);
Utils::unLockProgram(m_fdLockFile);
uninhibit();
m_fdLockFile = -1;
m_backupState = BackupState::BACKUP_STATE_INIT;

View File

@ -4,6 +4,7 @@
#include <QObject>
#include <QtDBus/QDBusVariant>
#include <QHash>
#include <QDBusUnixFileDescriptor>
#include "mythread.h"
#include "../common/mydefine.h"
#include "../common/spinlock_mutex.h"
@ -74,8 +75,10 @@ private slots:
private:
// 锁定
bool lock(int frontUid);
bool inhibit();
// 解锁
bool unlock();
void uninhibit();
// 自旋锁
spinlock_mutex m_mutex;
@ -85,6 +88,7 @@ private:
private:
// 锁文件描述符
int m_fdLockFile = -1;
QDBusUnixFileDescriptor m_inhibitFileDescriptor;
// 备份还原状态
BackupState m_backupState = BackupState::BACKUP_STATE_INIT;
// 是否活动的,兼容以前用的,和m_backupState的实际使用功能有重复