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
master
sniperbeamer 16 years ago
parent b8f59f9f04
commit 317397e063
  1. 18
      src/Application_X11.cpp
  2. 4
      src/Application_X11.h
  3. 4
      src/KpxConfig.h
  4. 9
      src/dialogs/AutoTypeDlg.cpp
  5. 1
      src/dialogs/AutoTypeDlg.h
  6. 9
      src/dialogs/SettingsDlg.cpp
  7. 2
      src/dialogs/SettingsDlg.h
  8. 42
      src/forms/SettingsDlg.ui
  9. 1
      src/keepassx.h
  10. 1
      src/main.cpp
  11. 62
      src/mainwindow.cpp
  12. 4
      src/mainwindow.h

@ -22,22 +22,18 @@
#include "lib/AutoType.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){
}
bool KeepassApplication::x11EventFilter(XEvent* event){
if (x11KeyEvent(event))
return 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 ){
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 ){
EventOccurred = true;
AutoType::performGlobal();
return true;
}
else
return false;
else{
return QApplication::x11EventFilter(event);
}
}

@ -28,7 +28,9 @@ class KeepassApplication : public QApplication
public:
KeepassApplication(int& argc, char** argv);
bool x11EventFilter(XEvent* event);
static bool x11KeyEvent(XEvent* event);
private:
static const unsigned int remove_invalid;
};
#endif // APPLICATION_X11_H

@ -83,6 +83,8 @@ public:
bool showPasswords(){return settings.value("Options/ShowPasswords",false).toBool();}
bool showPasswordsPasswordDlg(){return settings.value("Options/ShowPasswordsPasswordDlg",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 showSysTrayIcon(){return settings.value("Options/ShowSysTrayIcon",false).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 setShowPasswordsPasswordDlg(bool value){settings.setValue("Options/ShowPasswordsPasswordDlg",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 setShowSysTrayIcon(bool value){settings.setValue("Options/ShowSysTrayIcon",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());
}
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){
close();
QString err;

@ -29,6 +29,7 @@ class AutoTypeDlg : public QWidget, private Ui::AutoTypeDlg
protected:
void paintEvent(QPaintEvent* event);
void resizeEvent(QResizeEvent* event);
bool event(QEvent* event);
private slots:
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(Button_CustomizeEntryDetails,SIGNAL(clicked()),this,SLOT(OnCustomizeEntryDetails()));
connect(CheckBox_InactivityLock, SIGNAL(toggled(bool)), SLOT(OnInactivityLockChange(bool)));
#if !defined(AUTOTYPE)
Box_AutoType->setVisible(false);
@ -115,6 +116,8 @@ CSettingsDlg::CSettingsDlg(QWidget* parent):QDialog(parent,Qt::Dialog)
CheckBox_ShowPasswords->setChecked(config->showPasswords());
CheckBox_ShowPasswords_PasswordDlg->setChecked(config->showPasswordsPasswordDlg());
CheckBox_LockMinimize->setChecked(config->lockOnMinimize());
CheckBox_InactivityLock->setChecked(config->lockOnInactivity());
SpinBox_InacitivtyTime->setValue(config->lockAfterSec());
//Features
CheckBox_FeatureBookmarks->setChecked(config->featureBookmarks());
@ -221,6 +224,8 @@ void CSettingsDlg::apply(){
config->setShowPasswords(CheckBox_ShowPasswords->isChecked());
config->setShowPasswordsPasswordDlg(CheckBox_ShowPasswords_PasswordDlg->isChecked());
config->setLockOnMinimize(CheckBox_LockMinimize->isChecked());
config->setLockOnInactivity(CheckBox_InactivityLock->isChecked());
config->setLockAfterSec(SpinBox_InacitivtyTime->value());
//Features
config->setFeatureBookmarks(CheckBox_FeatureBookmarks->isChecked());
@ -321,6 +326,10 @@ void CSettingsDlg::OnCustomizeEntryDetails(){
dlg.exec();
}
void CSettingsDlg::OnInactivityLockChange(bool checked){
SpinBox_InacitivtyTime->setEnabled(checked);
}
#ifdef GLOBAL_AUTOTYPE
void CSettingsDlg::resetGlobalShortcut(){
AutoType::unregisterGlobalShortcut();

@ -44,7 +44,7 @@ class CSettingsDlg : public QDialog, public Ui_SettingsDialog
void OnMountDirBrowse();
void OnBrowserCmdBrowse();
void OnCustomizeEntryDetails();
void OnInactivityLockChange(bool checked);
#ifdef GLOBAL_AUTOTYPE
private slots:

@ -754,7 +754,7 @@
<item>
<widget class="QLabel" name="textLabel2" >
<property name="text" >
<string>Seconds</string>
<string>seconds</string>
</property>
</widget>
</item>
@ -767,6 +767,46 @@
</property>
</widget>
</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>
<spacer>
<property name="orientation" >

@ -99,6 +99,7 @@ extern QString DataDir;
extern bool TrActive;
extern QString DetailViewTemplate;
extern QPixmap *EntryIcons;
extern bool EventOccurred;
#endif //__cplusplus
#endif //KEEPASS_X_

@ -45,6 +45,7 @@ QString DataDir;
QString PluginLoadError;
bool TrActive;
QString DetailViewTemplate;
bool EventOccurred;
QPixmap* EntryIcons;
//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){
ShutingDown=false;
IsLocked=false;
EventOccurred=true;
inactivityCounter=0;
InUnLock=false;
unlockDlg=NULL;
db=NULL;
@ -87,6 +89,12 @@ KeepassMainWindow::KeepassMainWindow(const QString& ArgFile,bool ArgMin,bool Arg
LockedCentralWidget->setVisible(false);
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;
FileOpen=false;
@ -436,6 +444,7 @@ bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){
}
}
StatusBarGeneral->setText(tr("Ready"));
inactivityCounter = 0;
return true;
}
@ -1000,18 +1009,36 @@ void KeepassMainWindow::showEvent(QShowEvent* 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(){
CSettingsDlg dlg(this);
if(dlg.exec()==QDialog::Accepted){
EntryView->setAlternatingRowColors(config->alternatingRowColors());
SysTray->setVisible(config->showSysTrayIcon());
menuBookmarks->menuAction()->setVisible(config->featureBookmarks());
dlg.exec();
EntryView->setAlternatingRowColors(config->alternatingRowColors());
SysTray->setVisible(config->showSysTrayIcon());
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(){
AboutDialog dlg(this);
dlg.exec();
AboutDialog dlg(this);
dlg.exec();
}
//TODO Handbook
@ -1214,6 +1241,29 @@ void KeepassMainWindow::resetLock(){
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){
if(action==AddBookmarkAction){
AddBookmarkDlg dlg(this);

@ -78,11 +78,13 @@ class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{
void OnDetailViewUrlClicked(const QUrl& url);
void OnUnLockWorkspace();
void OnLockClose();
void OnInactivityTimer();
private:
void closeEvent(QCloseEvent* event);
void hideEvent(QHideEvent* event);
void showEvent(QShowEvent* event);
bool event(QEvent* event);
void setLock();
void resetLock();
SelectionState GroupSelection, EntrySelection;
@ -124,6 +126,8 @@ class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{
QList<int> lockGroup;
QDialog* unlockDlg;
QString currentFile;
int inactivityCounter;
QTimer* inactivityTimer;
};
#endif