8688 【系统关机/注销】增加关机/注销提示
This commit is contained in:
parent
7db0284459
commit
1746e5da40
|
@ -4,6 +4,12 @@
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDBusArgument>
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusPendingReply>
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusUnixFileDescriptor>
|
||||||
|
#include <QDBusConnection>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
#include <kysec/status.h>
|
#include <kysec/status.h>
|
||||||
|
@ -449,6 +455,11 @@ bool MyBackupManager::lock(int frontUid)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 用于替换上面的文件锁的,对应需求8688
|
||||||
|
// if (!inhibit())
|
||||||
|
// return false;
|
||||||
|
inhibit();
|
||||||
|
|
||||||
m_fdLockFile = lock_file_fd;
|
m_fdLockFile = lock_file_fd;
|
||||||
m_backupState = BackupState::PREPARING;
|
m_backupState = BackupState::PREPARING;
|
||||||
m_isActive = true;
|
m_isActive = true;
|
||||||
|
@ -458,6 +469,63 @@ bool MyBackupManager::lock(int frontUid)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 阻止session关机用dbus新接口Inhibit来替换锁文件的方式
|
||||||
|
* Inhibti函数有四个参数,按顺序分别为:
|
||||||
|
what:需要阻止的是哪些过程,如关机、重启;可以输入的值有:”shutdown”(会同时阻止关机重启),”sleep”(会同时阻止睡眠休眠),需要同时阻止关机和睡眠可以输入 ”shutdown:sleep”
|
||||||
|
who:是谁要阻止,调用该接口的程序名,如”ukui-sessions”
|
||||||
|
why:阻止的原因,简单描述即可,如”package 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 解锁应用
|
* @brief 解锁应用
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -469,6 +537,7 @@ bool MyBackupManager::unlock()
|
||||||
setKysecStatus(true);
|
setKysecStatus(true);
|
||||||
|
|
||||||
Utils::unLockProgram(m_fdLockFile);
|
Utils::unLockProgram(m_fdLockFile);
|
||||||
|
uninhibit();
|
||||||
|
|
||||||
m_fdLockFile = -1;
|
m_fdLockFile = -1;
|
||||||
m_backupState = BackupState::BACKUP_STATE_INIT;
|
m_backupState = BackupState::BACKUP_STATE_INIT;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtDBus/QDBusVariant>
|
#include <QtDBus/QDBusVariant>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QDBusUnixFileDescriptor>
|
||||||
#include "mythread.h"
|
#include "mythread.h"
|
||||||
#include "../common/mydefine.h"
|
#include "../common/mydefine.h"
|
||||||
#include "../common/spinlock_mutex.h"
|
#include "../common/spinlock_mutex.h"
|
||||||
|
@ -74,8 +75,10 @@ private slots:
|
||||||
private:
|
private:
|
||||||
// 锁定
|
// 锁定
|
||||||
bool lock(int frontUid);
|
bool lock(int frontUid);
|
||||||
|
bool inhibit();
|
||||||
// 解锁
|
// 解锁
|
||||||
bool unlock();
|
bool unlock();
|
||||||
|
void uninhibit();
|
||||||
// 自旋锁
|
// 自旋锁
|
||||||
spinlock_mutex m_mutex;
|
spinlock_mutex m_mutex;
|
||||||
|
|
||||||
|
@ -85,6 +88,7 @@ private:
|
||||||
private:
|
private:
|
||||||
// 锁文件描述符
|
// 锁文件描述符
|
||||||
int m_fdLockFile = -1;
|
int m_fdLockFile = -1;
|
||||||
|
QDBusUnixFileDescriptor m_inhibitFileDescriptor;
|
||||||
// 备份还原状态
|
// 备份还原状态
|
||||||
BackupState m_backupState = BackupState::BACKUP_STATE_INIT;
|
BackupState m_backupState = BackupState::BACKUP_STATE_INIT;
|
||||||
// 是否活动的,兼容以前用的,和m_backupState的实际使用功能有重复
|
// 是否活动的,兼容以前用的,和m_backupState的实际使用功能有重复
|
||||||
|
|
Loading…
Reference in New Issue