Automatic reload of a database when it get modified

When the database if modified by an other instance of KeePassX, KeePassX
detect it and reload automatically the database.
This commit is contained in:
Sebastien Fricker 2014-05-03 16:59:41 +02:00
parent e263c475c9
commit 7a8d4577f1
7 changed files with 162 additions and 0 deletions

View file

@ -0,0 +1,75 @@
/*
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
*
* 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 "FileSystemWatcher.h"
#include <QFile>
#include <QDir>
#include <QFileInfo>
FileSystemWatcher::FileSystemWatcher (): QFileSystemWatcher ( )
{
connect(this,SIGNAL( fileChanged ( const QString & )),
this,SLOT( fileChangedSlot ( const QString & )));
connect(this,SIGNAL( directoryChanged ( const QString & )),
this,SLOT( directoryChangedSlot ( const QString & )));
}
void FileSystemWatcher::watchFile(const QString &file)
{
_file=file;
if (!files().isEmpty())
removePaths(files());
if (!directories().isEmpty())
removePaths(directories());
QFileInfo fileInfo(file);
if (fileInfo.exists())
addPath(file);
QString filePath=fileInfo.absoluteDir().path();
QFileInfo filePathInfo(filePath);
if (filePathInfo.exists())
addPath(filePath);
}
void FileSystemWatcher::stopWatching()
{
watchFile( QString() );
}
void FileSystemWatcher::fileChangedSlot ( const QString & )
{
QFileInfo fileInfo(_file);
if ( fileInfo.exists() )
fileChanged();
}
void FileSystemWatcher::directoryChangedSlot ( const QString & )
{
if (!files().contains(_file))
{
QFileInfo fileInfo(_file);
if ( fileInfo.exists() )
{
addPath(_file);
fileChanged();
}
}
}
FileSystemWatcher::~FileSystemWatcher()
{
}