mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Merge pull request #545 from keepassxreboot/feature/lock-db-on-session-lock-#134
Lock database on ScreenSaver/SessionLock
This commit is contained in:
commit
c69a978589
@ -48,6 +48,10 @@ set(keepassx_SOURCES
|
||||
core/PasswordGenerator.cpp
|
||||
core/PassphraseGenerator.cpp
|
||||
core/SignalMultiplexer.cpp
|
||||
core/ScreenLockListener.cpp
|
||||
core/ScreenLockListener.h
|
||||
core/ScreenLockListenerPrivate.h
|
||||
core/ScreenLockListenerPrivate.cpp
|
||||
core/TimeDelta.cpp
|
||||
core/TimeInfo.cpp
|
||||
core/ToDbExporter.cpp
|
||||
@ -136,6 +140,24 @@ set(keepassx_SOURCES
|
||||
totp/totp.h
|
||||
totp/totp.cpp
|
||||
)
|
||||
if(APPLE)
|
||||
set(keepassx_SOURCES ${keepassx_SOURCES}
|
||||
core/ScreenLockListenerMac.h
|
||||
core/ScreenLockListenerMac.cpp
|
||||
)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set(keepassx_SOURCES ${keepassx_SOURCES}
|
||||
core/ScreenLockListenerDBus.h
|
||||
core/ScreenLockListenerDBus.cpp
|
||||
)
|
||||
endif()
|
||||
if(MINGW)
|
||||
set(keepassx_SOURCES ${keepassx_SOURCES}
|
||||
core/ScreenLockListenerWin.h
|
||||
core/ScreenLockListenerWin.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
set(keepassx_SOURCES_MAINEXE
|
||||
main.cpp
|
||||
@ -200,9 +222,16 @@ target_link_libraries(keepassx_core
|
||||
${GCRYPT_LIBRARIES}
|
||||
${GPGERROR_LIBRARIES}
|
||||
${ZLIB_LIBRARIES})
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(keepassx_core "-framework Foundation")
|
||||
endif()
|
||||
if (UNIX AND NOT APPLE)
|
||||
target_link_libraries(keepassx_core Qt5::DBus)
|
||||
endif()
|
||||
if(MINGW)
|
||||
target_link_libraries(keepassx_core Wtsapi32.lib)
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
include(GenerateProductVersion)
|
||||
|
@ -119,6 +119,7 @@ void Config::init(const QString& fileName)
|
||||
m_defaults.insert("security/lockdatabaseidle", false);
|
||||
m_defaults.insert("security/lockdatabaseidlesec", 240);
|
||||
m_defaults.insert("security/lockdatabaseminimize", false);
|
||||
m_defaults.insert("security/lockdatabasescreenlock", true);
|
||||
m_defaults.insert("security/passwordsrepeat", false);
|
||||
m_defaults.insert("security/passwordscleartext", false);
|
||||
m_defaults.insert("security/autotypeask", true);
|
||||
|
28
src/core/ScreenLockListener.cpp
Normal file
28
src/core/ScreenLockListener.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ScreenLockListener.h"
|
||||
#include "ScreenLockListenerPrivate.h"
|
||||
|
||||
ScreenLockListener::ScreenLockListener(QWidget* parent):
|
||||
QObject(parent){
|
||||
m_listener = ScreenLockListenerPrivate::instance(parent);
|
||||
connect(m_listener,SIGNAL(screenLocked()), this,SIGNAL(screenLocked()));
|
||||
}
|
||||
|
||||
ScreenLockListener::~ScreenLockListener(){
|
||||
}
|
38
src/core/ScreenLockListener.h
Normal file
38
src/core/ScreenLockListener.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SCREENLOCKLISTENER_H
|
||||
#define SCREENLOCKLISTENER_H
|
||||
#include <QWidget>
|
||||
|
||||
class ScreenLockListenerPrivate;
|
||||
|
||||
class ScreenLockListener : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScreenLockListener(QWidget* parent = nullptr);
|
||||
~ScreenLockListener();
|
||||
|
||||
signals:
|
||||
void screenLocked();
|
||||
|
||||
private:
|
||||
ScreenLockListenerPrivate* m_listener;
|
||||
};
|
||||
|
||||
#endif // SCREENLOCKLISTENER_H
|
87
src/core/ScreenLockListenerDBus.cpp
Normal file
87
src/core/ScreenLockListenerDBus.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ScreenLockListenerDBus.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget *parent):
|
||||
ScreenLockListenerPrivate(parent)
|
||||
{
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||
|
||||
sessionBus.connect(
|
||||
"org.freedesktop.ScreenSaver", // service
|
||||
"/org/freedesktop/ScreenSaver", // path
|
||||
"org.freedesktop.ScreenSaver", // interface
|
||||
"ActiveChanged", // signal name
|
||||
this, //receiver
|
||||
SLOT(freedesktopScreenSaver(bool)));
|
||||
|
||||
sessionBus.connect(
|
||||
"org.gnome.SessionManager", // service
|
||||
"/org/gnome/SessionManager/Presence", // path
|
||||
"org.gnome.SessionManager.Presence", // interface
|
||||
"StatusChanged", // signal name
|
||||
this, //receiver
|
||||
SLOT(gnomeSessionStatusChanged(uint)));
|
||||
|
||||
systemBus.connect(
|
||||
"org.freedesktop.login1", // service
|
||||
"/org/freedesktop/login1", // path
|
||||
"org.freedesktop.login1.Manager", // interface
|
||||
"PrepareForSleep", // signal name
|
||||
this, //receiver
|
||||
SLOT(logindPrepareForSleep(bool)));
|
||||
|
||||
sessionBus.connect(
|
||||
"com.canonical.Unity", // service
|
||||
"/com/canonical/Unity/Session", // path
|
||||
"com.canonical.Unity.Session", // interface
|
||||
"Locked", // signal name
|
||||
this, //receiver
|
||||
SLOT(unityLocked()));
|
||||
}
|
||||
|
||||
void ScreenLockListenerDBus::gnomeSessionStatusChanged(uint status)
|
||||
{
|
||||
if (status != 0) {
|
||||
emit screenLocked();
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenLockListenerDBus::logindPrepareForSleep(bool beforeSleep)
|
||||
{
|
||||
if (beforeSleep) {
|
||||
emit screenLocked();
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenLockListenerDBus::unityLocked()
|
||||
{
|
||||
emit screenLocked();
|
||||
}
|
||||
|
||||
void ScreenLockListenerDBus::freedesktopScreenSaver(bool status)
|
||||
{
|
||||
if (status) {
|
||||
emit screenLocked();
|
||||
}
|
||||
}
|
37
src/core/ScreenLockListenerDBus.h
Normal file
37
src/core/ScreenLockListenerDBus.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SCREENLOCKLISTENERDBUS_H
|
||||
#define SCREENLOCKLISTENERDBUS_H
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include "ScreenLockListenerPrivate.h"
|
||||
|
||||
class ScreenLockListenerDBus : public ScreenLockListenerPrivate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScreenLockListenerDBus(QWidget *parent = 0);
|
||||
|
||||
private slots:
|
||||
void gnomeSessionStatusChanged(uint status);
|
||||
void logindPrepareForSleep(bool beforeSleep);
|
||||
void unityLocked();
|
||||
void freedesktopScreenSaver(bool status);
|
||||
};
|
||||
|
||||
#endif // SCREENLOCKLISTENERDBUS_H
|
63
src/core/ScreenLockListenerMac.cpp
Normal file
63
src/core/ScreenLockListenerMac.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ScreenLockListenerMac.h"
|
||||
|
||||
#include <QMutexLocker>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
ScreenLockListenerMac* ScreenLockListenerMac::instance()
|
||||
{
|
||||
static QMutex mutex;
|
||||
QMutexLocker lock(&mutex);
|
||||
|
||||
static ScreenLockListenerMac* m_ptr = nullptr;
|
||||
if (m_ptr == nullptr) {
|
||||
m_ptr = new ScreenLockListenerMac();
|
||||
}
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
void ScreenLockListenerMac::notificationCenterCallBack(CFNotificationCenterRef, void*,
|
||||
CFStringRef, const void*,
|
||||
CFDictionaryRef)
|
||||
{
|
||||
instance()->onSignalReception();
|
||||
}
|
||||
|
||||
ScreenLockListenerMac::ScreenLockListenerMac(QWidget* parent)
|
||||
: ScreenLockListenerPrivate(parent)
|
||||
{
|
||||
CFNotificationCenterRef distCenter;
|
||||
CFStringRef screenIsLockedSignal = CFSTR("com.apple.screenIsLocked");
|
||||
distCenter = CFNotificationCenterGetDistributedCenter();
|
||||
if (nullptr == distCenter) {
|
||||
return;
|
||||
}
|
||||
|
||||
CFNotificationCenterAddObserver(distCenter,
|
||||
this,
|
||||
&ScreenLockListenerMac::notificationCenterCallBack,
|
||||
screenIsLockedSignal,
|
||||
nullptr,
|
||||
CFNotificationSuspensionBehaviorDeliverImmediately);
|
||||
}
|
||||
|
||||
void ScreenLockListenerMac::onSignalReception()
|
||||
{
|
||||
emit screenLocked();
|
||||
}
|
42
src/core/ScreenLockListenerMac.h
Normal file
42
src/core/ScreenLockListenerMac.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SCREENLOCKLISTENERMAC_H
|
||||
#define SCREENLOCKLISTENERMAC_H
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#include "ScreenLockListenerPrivate.h"
|
||||
|
||||
class ScreenLockListenerMac: public ScreenLockListenerPrivate {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static ScreenLockListenerMac* instance();
|
||||
static void notificationCenterCallBack(CFNotificationCenterRef center, void* observer,
|
||||
CFStringRef name, const void* object,
|
||||
CFDictionaryRef userInfo);
|
||||
|
||||
private:
|
||||
ScreenLockListenerMac(QWidget* parent = nullptr);
|
||||
void onSignalReception();
|
||||
|
||||
};
|
||||
|
||||
#endif // SCREENLOCKLISTENERMAC_H
|
44
src/core/ScreenLockListenerPrivate.cpp
Normal file
44
src/core/ScreenLockListenerPrivate.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ScreenLockListenerPrivate.h"
|
||||
#if defined(Q_OS_OSX)
|
||||
#include "ScreenLockListenerMac.h"
|
||||
#endif
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include "ScreenLockListenerDBus.h"
|
||||
#endif
|
||||
#if defined(Q_OS_WIN)
|
||||
#include "ScreenLockListenerWin.h"
|
||||
#endif
|
||||
|
||||
ScreenLockListenerPrivate::ScreenLockListenerPrivate(QWidget* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
ScreenLockListenerPrivate* ScreenLockListenerPrivate::instance(QWidget* parent)
|
||||
{
|
||||
#if defined(Q_OS_OSX)
|
||||
Q_UNUSED(parent);
|
||||
return ScreenLockListenerMac::instance();
|
||||
#elif defined(Q_OS_LINUX)
|
||||
return new ScreenLockListenerDBus(parent);
|
||||
#elif defined(Q_OS_WIN)
|
||||
return new ScreenLockListenerWin(parent);
|
||||
#endif
|
||||
}
|
36
src/core/ScreenLockListenerPrivate.h
Normal file
36
src/core/ScreenLockListenerPrivate.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SCREENLOCKLISTENERPRIVATE_H
|
||||
#define SCREENLOCKLISTENERPRIVATE_H
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
class ScreenLockListenerPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static ScreenLockListenerPrivate* instance(QWidget* parent = 0);
|
||||
|
||||
protected:
|
||||
ScreenLockListenerPrivate(QWidget* parent = 0);
|
||||
|
||||
signals:
|
||||
void screenLocked();
|
||||
};
|
||||
|
||||
#endif // SCREENLOCKLISTENERPRIVATE_H
|
91
src/core/ScreenLockListenerWin.cpp
Normal file
91
src/core/ScreenLockListenerWin.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ScreenLockListenerWin.h"
|
||||
#include <QApplication>
|
||||
#include <windows.h>
|
||||
#include <wtsapi32.h>
|
||||
|
||||
/*
|
||||
* See https://msdn.microsoft.com/en-us/library/windows/desktop/aa373196(v=vs.85).aspx
|
||||
* See https://msdn.microsoft.com/en-us/library/aa383841(v=vs.85).aspx
|
||||
* See https://blogs.msdn.microsoft.com/oldnewthing/20060104-50/?p=32783
|
||||
*/
|
||||
ScreenLockListenerWin::ScreenLockListenerWin(QWidget* parent)
|
||||
: ScreenLockListenerPrivate(parent)
|
||||
, QAbstractNativeEventFilter()
|
||||
{
|
||||
Q_ASSERT(parent != nullptr);
|
||||
// On windows, we need to register for platform specific messages and
|
||||
// install a message handler for them
|
||||
QCoreApplication::instance()->installNativeEventFilter(this);
|
||||
|
||||
// This call requests a notification from windows when a laptop is closed
|
||||
HPOWERNOTIFY hPnotify = RegisterPowerSettingNotification(
|
||||
reinterpret_cast<HWND>(parent->winId()),
|
||||
&GUID_LIDSWITCH_STATE_CHANGE, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
m_powerNotificationHandle = reinterpret_cast<void*>(hPnotify);
|
||||
|
||||
// This call requests a notification for session changes
|
||||
if (!WTSRegisterSessionNotification(
|
||||
reinterpret_cast<HWND>(parent->winId()),
|
||||
NOTIFY_FOR_THIS_SESSION)) {
|
||||
}
|
||||
}
|
||||
|
||||
ScreenLockListenerWin::~ScreenLockListenerWin()
|
||||
{
|
||||
HWND h= reinterpret_cast<HWND>(static_cast<QWidget*>(parent())->winId());
|
||||
WTSUnRegisterSessionNotification(h);
|
||||
|
||||
if (m_powernotificationhandle) {
|
||||
UnregisterPowerSettingNotification(reinterpret_cast<HPOWERNOTIFY>(m_powernotificationhandle));
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenLockListenerWin::nativeEventFilter(const QByteArray& eventType, void* message, long*)
|
||||
{
|
||||
if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG") {
|
||||
MSG* m = static_cast<MSG*>(message);
|
||||
if (m->message == WM_POWERBROADCAST) {
|
||||
if (m->wParam == PBT_POWERSETTINGCHANGE) {
|
||||
const POWERBROADCAST_SETTING* setting = reinterpret_cast<const POWERBROADCAST_SETTING*>(m->lParam);
|
||||
if (setting != nullptr && setting->PowerSetting == GUID_LIDSWITCH_STATE_CHANGE) {
|
||||
const DWORD* state = reinterpret_cast<const DWORD*>(&setting->Data);
|
||||
if (*state == 0) {
|
||||
emit screenLocked();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (m->wParam == PBT_APMSUSPEND) {
|
||||
emit screenLocked();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (m->message == WM_WTSSESSION_CHANGE) {
|
||||
if (m->wParam == WTS_CONSOLE_DISCONNECT) {
|
||||
emit screenLocked();
|
||||
return true;
|
||||
}
|
||||
if (m->wParam == WTS_SESSION_LOCK) {
|
||||
emit screenLocked();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
38
src/core/ScreenLockListenerWin.h
Normal file
38
src/core/ScreenLockListenerWin.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SCREENLOCKLISTENERWIN_H
|
||||
#define SCREENLOCKLISTENERWIN_H
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
|
||||
#include "ScreenLockListenerPrivate.h"
|
||||
|
||||
class ScreenLockListenerWin : public ScreenLockListenerPrivate, public QAbstractNativeEventFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScreenLockListenerWin(QWidget* parent = 0);
|
||||
~ScreenLockListenerWin();
|
||||
virtual bool nativeEventFilter(const QByteArray &eventType, void* message, long*) override;
|
||||
|
||||
private:
|
||||
void* m_powerNotificationHandle ;
|
||||
};
|
||||
|
||||
#endif // SCREENLOCKLISTENERWIN_H
|
@ -329,6 +329,9 @@ MainWindow::MainWindow()
|
||||
connect(m_ui->tabWidget, SIGNAL(messageTab(QString,MessageWidget::MessageType)), this, SLOT(displayTabMessage(QString, MessageWidget::MessageType)));
|
||||
connect(m_ui->tabWidget, SIGNAL(messageDismissTab()), this, SLOT(hideTabMessage()));
|
||||
|
||||
m_screenLockListener = new ScreenLockListener(this);
|
||||
connect(m_screenLockListener, SIGNAL(screenLocked()), SLOT(handleScreenLock()));
|
||||
|
||||
updateTrayIcon();
|
||||
|
||||
if (config()->hasAccessError()) {
|
||||
@ -959,3 +962,10 @@ void MainWindow::hideYubiKeyPopup()
|
||||
hideGlobalMessage();
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::handleScreenLock()
|
||||
{
|
||||
if (config()->get("security/lockdatabasescreenlock").toBool()){
|
||||
lockDatabasesAfterInactivity();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include "core/SignalMultiplexer.h"
|
||||
#include "core/ScreenLockListener.h"
|
||||
#include "gui/DatabaseWidget.h"
|
||||
#include "gui/Application.h"
|
||||
|
||||
@ -91,6 +92,7 @@ private slots:
|
||||
void lockDatabasesAfterInactivity();
|
||||
void repairDatabase();
|
||||
void hideTabMessage();
|
||||
void handleScreenLock();
|
||||
|
||||
private:
|
||||
static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0);
|
||||
@ -112,6 +114,7 @@ private:
|
||||
InactivityTimer* m_inactivityTimer;
|
||||
int m_countDefaultAttributes;
|
||||
QSystemTrayIcon* m_trayIcon;
|
||||
ScreenLockListener* m_screenLockListener;
|
||||
|
||||
Q_DISABLE_COPY(MainWindow)
|
||||
|
||||
|
@ -141,12 +141,14 @@ void SettingsWidget::loadSettings()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_secUi->clearClipboardCheckBox->setChecked(config()->get("security/clearclipboard").toBool());
|
||||
m_secUi->clearClipboardSpinBox->setValue(config()->get("security/clearclipboardtimeout").toInt());
|
||||
|
||||
m_secUi->lockDatabaseIdleCheckBox->setChecked(config()->get("security/lockdatabaseidle").toBool());
|
||||
m_secUi->lockDatabaseIdleSpinBox->setValue(config()->get("security/lockdatabaseidlesec").toInt());
|
||||
m_secUi->lockDatabaseMinimizeCheckBox->setChecked(config()->get("security/lockdatabaseminimize").toBool());
|
||||
m_secUi->lockDatabaseOnScreenLockCheckBox->setChecked(config()->get("security/lockdatabasescreenlock").toBool());
|
||||
|
||||
m_secUi->passwordCleartextCheckBox->setChecked(config()->get("security/passwordscleartext").toBool());
|
||||
m_secUi->passwordRepeatCheckBox->setChecked(config()->get("security/passwordsrepeat").toBool());
|
||||
@ -186,6 +188,7 @@ void SettingsWidget::saveSettings()
|
||||
config()->set("AutoTypeEntryTitleMatch",
|
||||
m_generalUi->autoTypeEntryTitleMatchCheckBox->isChecked());
|
||||
int currentLangIndex = m_generalUi->languageComboBox->currentIndex();
|
||||
|
||||
config()->set("GUI/Language", m_generalUi->languageComboBox->itemData(currentLangIndex).toString());
|
||||
|
||||
config()->set("GUI/ShowTrayIcon", m_generalUi->systrayShowCheckBox->isChecked());
|
||||
@ -206,6 +209,7 @@ void SettingsWidget::saveSettings()
|
||||
config()->set("security/lockdatabaseidle", m_secUi->lockDatabaseIdleCheckBox->isChecked());
|
||||
config()->set("security/lockdatabaseidlesec", m_secUi->lockDatabaseIdleSpinBox->value());
|
||||
config()->set("security/lockdatabaseminimize", m_secUi->lockDatabaseMinimizeCheckBox->isChecked());
|
||||
config()->set("security/lockdatabasescreenlock", m_secUi->lockDatabaseOnScreenLockCheckBox->isChecked());
|
||||
|
||||
config()->set("security/passwordscleartext", m_secUi->passwordCleartextCheckBox->isChecked());
|
||||
config()->set("security/passwordsrepeat", m_secUi->passwordRepeatCheckBox->isChecked());
|
||||
|
@ -28,7 +28,14 @@
|
||||
<property name="title">
|
||||
<string>Timeouts</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="clearClipboardCheckBox">
|
||||
<property name="text">
|
||||
<string>Clear clipboard after</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="clearClipboardSpinBox">
|
||||
<property name="enabled">
|
||||
@ -54,7 +61,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="lockDatabaseIdleCheckBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Lock databases after inactivity of</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="lockDatabaseIdleSpinBox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
@ -79,20 +99,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" alignment="Qt::AlignRight">
|
||||
<widget class="QCheckBox" name="clearClipboardCheckBox">
|
||||
<property name="text">
|
||||
<string>Clear clipboard after</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" alignment="Qt::AlignRight">
|
||||
<widget class="QCheckBox" name="lockDatabaseIdleCheckBox">
|
||||
<property name="text">
|
||||
<string>Lock databases after inactivity of</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -101,7 +107,21 @@
|
||||
<property name="title">
|
||||
<string>Convenience</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="lockDatabaseOnScreenLockCheckBox">
|
||||
<property name="text">
|
||||
<string>Lock databases when session is locked or lid is closed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="lockDatabaseMinimizeCheckBox">
|
||||
<property name="text">
|
||||
<string>Lock databases after minimizing the window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="passwordRepeatCheckBox">
|
||||
<property name="text">
|
||||
@ -116,13 +136,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="lockDatabaseMinimizeCheckBox">
|
||||
<property name="text">
|
||||
<string>Lock databases after minimizing the window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user