2025-11-07 10:56:45 +08:00
|
|
|
#include "screenlockdetector.h"
|
2025-11-08 16:57:58 +08:00
|
|
|
|
2025-11-11 13:03:59 +08:00
|
|
|
#ifdef Q_OS_LINUX
|
2025-11-11 20:39:04 +08:00
|
|
|
#include "platform/screenlockdetector_linux.h"
|
2025-11-08 16:57:58 +08:00
|
|
|
#endif
|
|
|
|
|
|
2025-11-11 13:03:59 +08:00
|
|
|
#ifdef Q_OS_MAC
|
2025-11-11 20:39:04 +08:00
|
|
|
#include "platform/screenlockdetector_macos.h"
|
2025-11-08 16:57:58 +08:00
|
|
|
#endif
|
2025-11-07 10:56:45 +08:00
|
|
|
|
2025-11-11 13:03:59 +08:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
ScreenLockDetector::ScreenLockDetector(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
2025-11-11 13:03:59 +08:00
|
|
|
, m_detector(nullptr)
|
2025-11-07 10:56:45 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScreenLockDetector::~ScreenLockDetector()
|
|
|
|
|
{
|
2025-11-11 13:03:59 +08:00
|
|
|
if (m_detector) {
|
|
|
|
|
delete m_detector;
|
|
|
|
|
m_detector = nullptr;
|
2025-11-08 16:57:58 +08:00
|
|
|
}
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScreenLockDetector::isScreenLocked() const
|
|
|
|
|
{
|
2025-11-11 13:03:59 +08:00
|
|
|
if (m_detector) {
|
|
|
|
|
return m_detector->isScreenLocked();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScreenLockDetector::initialize()
|
|
|
|
|
{
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "=================================================";
|
2025-11-11 13:03:59 +08:00
|
|
|
qDebug() << "ScreenLockDetector: Creating platform-specific detector...";
|
2025-11-08 16:57:58 +08:00
|
|
|
qDebug() << "=================================================";
|
|
|
|
|
|
2025-11-11 13:03:59 +08:00
|
|
|
// 创建平台特定的检测器
|
|
|
|
|
m_detector = createPlatformDetector();
|
|
|
|
|
|
|
|
|
|
if (!m_detector) {
|
|
|
|
|
qWarning() << "Failed to create platform-specific detector";
|
|
|
|
|
qWarning() << "Current platform is not supported";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-11-08 16:57:58 +08:00
|
|
|
|
|
|
|
|
// 连接信号
|
2025-11-11 13:03:59 +08:00
|
|
|
connect(m_detector, &ScreenLockDetectorBase::screenLocked,
|
2025-11-08 16:57:58 +08:00
|
|
|
this, &ScreenLockDetector::screenLocked);
|
2025-11-11 13:03:59 +08:00
|
|
|
connect(m_detector, &ScreenLockDetectorBase::screenUnlocked,
|
2025-11-08 16:57:58 +08:00
|
|
|
this, &ScreenLockDetector::screenUnlocked);
|
2025-11-11 13:03:59 +08:00
|
|
|
connect(m_detector, &ScreenLockDetectorBase::lockStateChanged,
|
|
|
|
|
this, &ScreenLockDetector::lockStateChanged);
|
2025-11-08 16:57:58 +08:00
|
|
|
|
2025-11-11 13:03:59 +08:00
|
|
|
// 初始化检测器
|
|
|
|
|
bool success = m_detector->initialize();
|
2025-11-08 16:57:58 +08:00
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
qDebug() << "=================================================";
|
2025-11-11 13:03:59 +08:00
|
|
|
qDebug() << "ScreenLockDetector initialized successfully";
|
2025-11-08 16:57:58 +08:00
|
|
|
qDebug() << "=================================================";
|
|
|
|
|
} else {
|
2025-11-11 13:03:59 +08:00
|
|
|
qWarning() << "Failed to initialize platform-specific detector";
|
|
|
|
|
delete m_detector;
|
|
|
|
|
m_detector = nullptr;
|
2025-11-08 16:57:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
2025-11-11 13:03:59 +08:00
|
|
|
}
|
2025-11-08 16:57:58 +08:00
|
|
|
|
2025-11-11 13:03:59 +08:00
|
|
|
ScreenLockDetectorBase* ScreenLockDetector::createPlatformDetector()
|
|
|
|
|
{
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
qDebug() << "Platform detected: macOS";
|
|
|
|
|
return new ScreenLockDetectorMacOS(this);
|
2025-11-08 16:57:58 +08:00
|
|
|
#elif defined(Q_OS_LINUX)
|
2025-11-11 13:03:59 +08:00
|
|
|
qDebug() << "Platform detected: Linux";
|
|
|
|
|
return new ScreenLockDetectorLinux(this);
|
2025-11-08 16:57:58 +08:00
|
|
|
#else
|
2025-11-11 13:03:59 +08:00
|
|
|
qWarning() << "Platform not supported";
|
|
|
|
|
return nullptr;
|
2025-11-08 16:57:58 +08:00
|
|
|
#endif
|
2025-11-11 13:03:59 +08:00
|
|
|
}
|