Added: automatically lock database after inactivity (closes #1906699)
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@177 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
b8f59f9f04
commit
317397e063
|
@ -22,22 +22,18 @@
|
||||||
#include "lib/AutoType.h"
|
#include "lib/AutoType.h"
|
||||||
#include "lib/HelperX11.h"
|
#include "lib/HelperX11.h"
|
||||||
|
|
||||||
|
const unsigned int KeepassApplication::remove_invalid = ControlMask|ShiftMask|Mod1Mask|Mod5Mask|Mod4Mask;
|
||||||
|
|
||||||
KeepassApplication::KeepassApplication(int& argc, char** argv) : QApplication(argc, argv){
|
KeepassApplication::KeepassApplication(int& argc, char** argv) : QApplication(argc, argv){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeepassApplication::x11EventFilter(XEvent* event){
|
bool KeepassApplication::x11EventFilter(XEvent* event){
|
||||||
if (x11KeyEvent(event))
|
if (event->type==KeyPress && AutoType::shortcut.key!=0u && event->xkey.keycode==XKeysymToKeycode(event->xkey.display,HelperX11::getKeysym(AutoType::shortcut.key)) && (event->xkey.state&remove_invalid)==HelperX11::getShortcutModifierMask(AutoType::shortcut) && focusWidget()==NULL ){
|
||||||
return true;
|
EventOccurred = true;
|
||||||
else
|
|
||||||
return QApplication::x11EventFilter(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeepassApplication::x11KeyEvent(XEvent* event){
|
|
||||||
static const unsigned int remove_invalid = ControlMask|ShiftMask|Mod1Mask|Mod5Mask|Mod4Mask;
|
|
||||||
if (event->type==KeyPress && AutoType::shortcut.key!=0u && event->xkey.keycode==XKeysymToKeycode(event->xkey.display,HelperX11::getKeysym(AutoType::shortcut.key)) && (event->xkey.state&remove_invalid)==HelperX11::getShortcutModifierMask(AutoType::shortcut) && QApplication::focusWidget()==NULL ){
|
|
||||||
AutoType::performGlobal();
|
AutoType::performGlobal();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else{
|
||||||
return false;
|
return QApplication::x11EventFilter(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,9 @@ class KeepassApplication : public QApplication
|
||||||
public:
|
public:
|
||||||
KeepassApplication(int& argc, char** argv);
|
KeepassApplication(int& argc, char** argv);
|
||||||
bool x11EventFilter(XEvent* event);
|
bool x11EventFilter(XEvent* event);
|
||||||
static bool x11KeyEvent(XEvent* event);
|
|
||||||
|
private:
|
||||||
|
static const unsigned int remove_invalid;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPLICATION_X11_H
|
#endif // APPLICATION_X11_H
|
||||||
|
|
|
@ -83,6 +83,8 @@ public:
|
||||||
bool showPasswords(){return settings.value("Options/ShowPasswords",false).toBool();}
|
bool showPasswords(){return settings.value("Options/ShowPasswords",false).toBool();}
|
||||||
bool showPasswordsPasswordDlg(){return settings.value("Options/ShowPasswordsPasswordDlg",false).toBool();}
|
bool showPasswordsPasswordDlg(){return settings.value("Options/ShowPasswordsPasswordDlg",false).toBool();}
|
||||||
bool lockOnMinimize(){return settings.value("Options/LockOnMinimize",false).toBool();}
|
bool lockOnMinimize(){return settings.value("Options/LockOnMinimize",false).toBool();}
|
||||||
|
bool lockOnInactivity(){return settings.value("Options/LockOnInactivity",false).toBool();}
|
||||||
|
int lockAfterSec(){return settings.value("Options/LockAfterSec",30).toInt();}
|
||||||
bool showStatusbar(){return settings.value("UI/ShowStatusbar",true).toBool();}
|
bool showStatusbar(){return settings.value("UI/ShowStatusbar",true).toBool();}
|
||||||
bool showSysTrayIcon(){return settings.value("Options/ShowSysTrayIcon",false).toBool();}
|
bool showSysTrayIcon(){return settings.value("Options/ShowSysTrayIcon",false).toBool();}
|
||||||
bool showToolbar(){return settings.value("UI/ShowToolbar",true).toBool();}
|
bool showToolbar(){return settings.value("UI/ShowToolbar",true).toBool();}
|
||||||
|
@ -140,6 +142,8 @@ public:
|
||||||
void setShowPasswords(bool value){settings.setValue("Options/ShowPasswords",value);}
|
void setShowPasswords(bool value){settings.setValue("Options/ShowPasswords",value);}
|
||||||
void setShowPasswordsPasswordDlg(bool value){settings.setValue("Options/ShowPasswordsPasswordDlg",value);}
|
void setShowPasswordsPasswordDlg(bool value){settings.setValue("Options/ShowPasswordsPasswordDlg",value);}
|
||||||
void setLockOnMinimize(bool value){settings.setValue("Options/LockOnMinimize",value);}
|
void setLockOnMinimize(bool value){settings.setValue("Options/LockOnMinimize",value);}
|
||||||
|
void setLockOnInactivity(bool value){settings.setValue("Options/LockOnInactivity",value);}
|
||||||
|
void setLockAfterSec(int value){settings.setValue("Options/LockAfterSec",value);}
|
||||||
void setShowStatusbar(bool value){settings.setValue("UI/ShowStatusbar",value);}
|
void setShowStatusbar(bool value){settings.setValue("UI/ShowStatusbar",value);}
|
||||||
void setShowSysTrayIcon(bool value){settings.setValue("Options/ShowSysTrayIcon",value);}
|
void setShowSysTrayIcon(bool value){settings.setValue("Options/ShowSysTrayIcon",value);}
|
||||||
void setShowToolbar(bool value){settings.setValue("UI/ShowToolbar",value);}
|
void setShowToolbar(bool value){settings.setValue("UI/ShowToolbar",value);}
|
||||||
|
|
|
@ -87,6 +87,15 @@ void AutoTypeDlg::resizeEvent(QResizeEvent* event){
|
||||||
createBanner(&BannerPixmap,getPixmap("keepassx_large"),tr("Auto-Type"),width());
|
createBanner(&BannerPixmap,getPixmap("keepassx_large"),tr("Auto-Type"),width());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AutoTypeDlg::event(QEvent* event){
|
||||||
|
if (!EventOccurred){
|
||||||
|
int t = event->type();
|
||||||
|
if ( t>=QEvent::MouseButtonPress&&t<=QEvent::KeyRelease || t>=QEvent::HoverEnter&&t<=QEvent::HoverMove )
|
||||||
|
EventOccurred = true;
|
||||||
|
}
|
||||||
|
return QWidget::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
void AutoTypeDlg::itemSelected(QTreeWidgetItem* item){
|
void AutoTypeDlg::itemSelected(QTreeWidgetItem* item){
|
||||||
close();
|
close();
|
||||||
QString err;
|
QString err;
|
||||||
|
|
|
@ -29,6 +29,7 @@ class AutoTypeDlg : public QWidget, private Ui::AutoTypeDlg
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
void resizeEvent(QResizeEvent* event);
|
void resizeEvent(QResizeEvent* event);
|
||||||
|
bool event(QEvent* event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void itemSelected(QTreeWidgetItem* item);
|
void itemSelected(QTreeWidgetItem* item);
|
||||||
|
|
|
@ -50,6 +50,7 @@ CSettingsDlg::CSettingsDlg(QWidget* parent):QDialog(parent,Qt::Dialog)
|
||||||
connect(Radio_IntPlugin_Kde,SIGNAL(toggled(bool)),this,SLOT(OnIntPluginKde()));
|
connect(Radio_IntPlugin_Kde,SIGNAL(toggled(bool)),this,SLOT(OnIntPluginKde()));
|
||||||
|
|
||||||
connect(Button_CustomizeEntryDetails,SIGNAL(clicked()),this,SLOT(OnCustomizeEntryDetails()));
|
connect(Button_CustomizeEntryDetails,SIGNAL(clicked()),this,SLOT(OnCustomizeEntryDetails()));
|
||||||
|
connect(CheckBox_InactivityLock, SIGNAL(toggled(bool)), SLOT(OnInactivityLockChange(bool)));
|
||||||
|
|
||||||
#if !defined(AUTOTYPE)
|
#if !defined(AUTOTYPE)
|
||||||
Box_AutoType->setVisible(false);
|
Box_AutoType->setVisible(false);
|
||||||
|
@ -115,6 +116,8 @@ CSettingsDlg::CSettingsDlg(QWidget* parent):QDialog(parent,Qt::Dialog)
|
||||||
CheckBox_ShowPasswords->setChecked(config->showPasswords());
|
CheckBox_ShowPasswords->setChecked(config->showPasswords());
|
||||||
CheckBox_ShowPasswords_PasswordDlg->setChecked(config->showPasswordsPasswordDlg());
|
CheckBox_ShowPasswords_PasswordDlg->setChecked(config->showPasswordsPasswordDlg());
|
||||||
CheckBox_LockMinimize->setChecked(config->lockOnMinimize());
|
CheckBox_LockMinimize->setChecked(config->lockOnMinimize());
|
||||||
|
CheckBox_InactivityLock->setChecked(config->lockOnInactivity());
|
||||||
|
SpinBox_InacitivtyTime->setValue(config->lockAfterSec());
|
||||||
|
|
||||||
//Features
|
//Features
|
||||||
CheckBox_FeatureBookmarks->setChecked(config->featureBookmarks());
|
CheckBox_FeatureBookmarks->setChecked(config->featureBookmarks());
|
||||||
|
@ -221,6 +224,8 @@ void CSettingsDlg::apply(){
|
||||||
config->setShowPasswords(CheckBox_ShowPasswords->isChecked());
|
config->setShowPasswords(CheckBox_ShowPasswords->isChecked());
|
||||||
config->setShowPasswordsPasswordDlg(CheckBox_ShowPasswords_PasswordDlg->isChecked());
|
config->setShowPasswordsPasswordDlg(CheckBox_ShowPasswords_PasswordDlg->isChecked());
|
||||||
config->setLockOnMinimize(CheckBox_LockMinimize->isChecked());
|
config->setLockOnMinimize(CheckBox_LockMinimize->isChecked());
|
||||||
|
config->setLockOnInactivity(CheckBox_InactivityLock->isChecked());
|
||||||
|
config->setLockAfterSec(SpinBox_InacitivtyTime->value());
|
||||||
|
|
||||||
//Features
|
//Features
|
||||||
config->setFeatureBookmarks(CheckBox_FeatureBookmarks->isChecked());
|
config->setFeatureBookmarks(CheckBox_FeatureBookmarks->isChecked());
|
||||||
|
@ -321,6 +326,10 @@ void CSettingsDlg::OnCustomizeEntryDetails(){
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSettingsDlg::OnInactivityLockChange(bool checked){
|
||||||
|
SpinBox_InacitivtyTime->setEnabled(checked);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef GLOBAL_AUTOTYPE
|
#ifdef GLOBAL_AUTOTYPE
|
||||||
void CSettingsDlg::resetGlobalShortcut(){
|
void CSettingsDlg::resetGlobalShortcut(){
|
||||||
AutoType::unregisterGlobalShortcut();
|
AutoType::unregisterGlobalShortcut();
|
||||||
|
|
|
@ -44,7 +44,7 @@ class CSettingsDlg : public QDialog, public Ui_SettingsDialog
|
||||||
void OnMountDirBrowse();
|
void OnMountDirBrowse();
|
||||||
void OnBrowserCmdBrowse();
|
void OnBrowserCmdBrowse();
|
||||||
void OnCustomizeEntryDetails();
|
void OnCustomizeEntryDetails();
|
||||||
|
void OnInactivityLockChange(bool checked);
|
||||||
|
|
||||||
#ifdef GLOBAL_AUTOTYPE
|
#ifdef GLOBAL_AUTOTYPE
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -754,7 +754,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="textLabel2" >
|
<widget class="QLabel" name="textLabel2" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>Seconds</string>
|
<string>seconds</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -767,6 +767,46 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="CheckBox_InactivityLock" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Lock database after inactivity of</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="SpinBox_InacitivtyTime" >
|
||||||
|
<property name="enabled" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy" >
|
||||||
|
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize" >
|
||||||
|
<size>
|
||||||
|
<width>80</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximum" >
|
||||||
|
<number>50000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_Inactivity" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>seconds</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer>
|
<spacer>
|
||||||
<property name="orientation" >
|
<property name="orientation" >
|
||||||
|
|
|
@ -99,6 +99,7 @@ extern QString DataDir;
|
||||||
extern bool TrActive;
|
extern bool TrActive;
|
||||||
extern QString DetailViewTemplate;
|
extern QString DetailViewTemplate;
|
||||||
extern QPixmap *EntryIcons;
|
extern QPixmap *EntryIcons;
|
||||||
|
extern bool EventOccurred;
|
||||||
|
|
||||||
#endif //__cplusplus
|
#endif //__cplusplus
|
||||||
#endif //KEEPASS_X_
|
#endif //KEEPASS_X_
|
||||||
|
|
|
@ -45,6 +45,7 @@ QString DataDir;
|
||||||
QString PluginLoadError;
|
QString PluginLoadError;
|
||||||
bool TrActive;
|
bool TrActive;
|
||||||
QString DetailViewTemplate;
|
QString DetailViewTemplate;
|
||||||
|
bool EventOccurred;
|
||||||
|
|
||||||
QPixmap* EntryIcons;
|
QPixmap* EntryIcons;
|
||||||
//IIconTheme* IconLoader=NULL; //TODO plugins
|
//IIconTheme* IconLoader=NULL; //TODO plugins
|
||||||
|
|
|
@ -52,6 +52,8 @@ Export_KeePassX_Xml export_KeePassX_Xml;
|
||||||
KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,bool ArgMin,bool ArgLock,QWidget *parent, Qt::WFlags flags) :QMainWindow(parent,flags){
|
KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,bool ArgMin,bool ArgLock,QWidget *parent, Qt::WFlags flags) :QMainWindow(parent,flags){
|
||||||
ShutingDown=false;
|
ShutingDown=false;
|
||||||
IsLocked=false;
|
IsLocked=false;
|
||||||
|
EventOccurred=true;
|
||||||
|
inactivityCounter=0;
|
||||||
InUnLock=false;
|
InUnLock=false;
|
||||||
unlockDlg=NULL;
|
unlockDlg=NULL;
|
||||||
db=NULL;
|
db=NULL;
|
||||||
|
@ -88,6 +90,12 @@ KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,bool ArgMin,bool Arg
|
||||||
|
|
||||||
setupConnections();
|
setupConnections();
|
||||||
|
|
||||||
|
inactivityTimer = new QTimer(this);
|
||||||
|
inactivityTimer->setInterval(500);
|
||||||
|
connect(inactivityTimer, SIGNAL(timeout()), SLOT(OnInactivityTimer()));
|
||||||
|
if (config->lockOnInactivity() && config->lockAfterSec()!=0)
|
||||||
|
inactivityTimer->start();
|
||||||
|
|
||||||
bool showWindow=true;
|
bool showWindow=true;
|
||||||
FileOpen=false;
|
FileOpen=false;
|
||||||
if(!ArgFile.isEmpty()){
|
if(!ArgFile.isEmpty()){
|
||||||
|
@ -436,6 +444,7 @@ bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StatusBarGeneral->setText(tr("Ready"));
|
StatusBarGeneral->setText(tr("Ready"));
|
||||||
|
inactivityCounter = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1000,18 +1009,36 @@ void KeepassMainWindow::showEvent(QShowEvent* event){
|
||||||
QMainWindow::showEvent(event);
|
QMainWindow::showEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KeepassMainWindow::event(QEvent* event){
|
||||||
|
if (!EventOccurred){
|
||||||
|
int t = event->type();
|
||||||
|
if ( t>=QEvent::MouseButtonPress&&t<=QEvent::KeyRelease || t>=QEvent::HoverEnter&&t<=QEvent::HoverMove )
|
||||||
|
EventOccurred = true;
|
||||||
|
}
|
||||||
|
return QMainWindow::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
void KeepassMainWindow::OnExtrasSettings(){
|
void KeepassMainWindow::OnExtrasSettings(){
|
||||||
CSettingsDlg dlg(this);
|
CSettingsDlg dlg(this);
|
||||||
if(dlg.exec()==QDialog::Accepted){
|
dlg.exec();
|
||||||
|
|
||||||
EntryView->setAlternatingRowColors(config->alternatingRowColors());
|
EntryView->setAlternatingRowColors(config->alternatingRowColors());
|
||||||
SysTray->setVisible(config->showSysTrayIcon());
|
SysTray->setVisible(config->showSysTrayIcon());
|
||||||
menuBookmarks->menuAction()->setVisible(config->featureBookmarks());
|
menuBookmarks->menuAction()->setVisible(config->featureBookmarks());
|
||||||
|
|
||||||
|
EventOccurred = true;
|
||||||
|
if (config->lockOnInactivity() && config->lockAfterSec()!=0 && !inactivityTimer->isActive()){
|
||||||
|
inactivityCounter = 0;
|
||||||
|
inactivityTimer->start();
|
||||||
|
}
|
||||||
|
else if ((!config->lockOnInactivity() || config->lockAfterSec()==0) && inactivityTimer->isActive()){
|
||||||
|
inactivityTimer->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeepassMainWindow::OnHelpAbout(){
|
void KeepassMainWindow::OnHelpAbout(){
|
||||||
AboutDialog dlg(this);
|
AboutDialog dlg(this);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Handbook
|
//TODO Handbook
|
||||||
|
@ -1214,6 +1241,29 @@ void KeepassMainWindow::resetLock(){
|
||||||
IsLocked=false;
|
IsLocked=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeepassMainWindow::OnInactivityTimer(){
|
||||||
|
if (IsLocked || !FileOpen)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QWidgetList widgets = QApplication::topLevelWidgets();
|
||||||
|
for (int i=0; i<widgets.size(); i++){
|
||||||
|
if (widgets[i]->windowModality()==Qt::ApplicationModal){
|
||||||
|
inactivityCounter = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EventOccurred){
|
||||||
|
inactivityCounter = 0;
|
||||||
|
EventOccurred = false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
inactivityCounter++;
|
||||||
|
if (inactivityCounter*(inactivityTimer->interval()) >= config->lockAfterSec()*1000)
|
||||||
|
OnUnLockWorkspace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KeepassMainWindow::OnBookmarkTriggered(QAction* action){
|
void KeepassMainWindow::OnBookmarkTriggered(QAction* action){
|
||||||
if(action==AddBookmarkAction){
|
if(action==AddBookmarkAction){
|
||||||
AddBookmarkDlg dlg(this);
|
AddBookmarkDlg dlg(this);
|
||||||
|
|
|
@ -78,11 +78,13 @@ class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{
|
||||||
void OnDetailViewUrlClicked(const QUrl& url);
|
void OnDetailViewUrlClicked(const QUrl& url);
|
||||||
void OnUnLockWorkspace();
|
void OnUnLockWorkspace();
|
||||||
void OnLockClose();
|
void OnLockClose();
|
||||||
|
void OnInactivityTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent* event);
|
||||||
void hideEvent(QHideEvent* event);
|
void hideEvent(QHideEvent* event);
|
||||||
void showEvent(QShowEvent* event);
|
void showEvent(QShowEvent* event);
|
||||||
|
bool event(QEvent* event);
|
||||||
void setLock();
|
void setLock();
|
||||||
void resetLock();
|
void resetLock();
|
||||||
SelectionState GroupSelection, EntrySelection;
|
SelectionState GroupSelection, EntrySelection;
|
||||||
|
@ -124,6 +126,8 @@ class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{
|
||||||
QList<int> lockGroup;
|
QList<int> lockGroup;
|
||||||
QDialog* unlockDlg;
|
QDialog* unlockDlg;
|
||||||
QString currentFile;
|
QString currentFile;
|
||||||
|
int inactivityCounter;
|
||||||
|
QTimer* inactivityTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue