mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-12 00:11:37 -04:00
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:
parent
e263c475c9
commit
7a8d4577f1
7 changed files with 162 additions and 0 deletions
75
src/core/FileSystemWatcher.cpp
Normal file
75
src/core/FileSystemWatcher.cpp
Normal 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()
|
||||
{
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue