forked from keepassx/keepassx
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR keepassx#56: Automatic reload on DB changes
- Loading branch information
Showing
10 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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/>. | ||
*/ | ||
|
||
#ifndef FILE_SYSTEM_WATCHER_H | ||
#define FILE_SYSTEM_WATCHER_H | ||
#include <QFileSystemWatcher> | ||
#include <QString> | ||
#include <QObject> | ||
|
||
|
||
class FileSystemWatcher : public QFileSystemWatcher | ||
{ | ||
Q_OBJECT ; | ||
|
||
public: | ||
FileSystemWatcher (); | ||
void watchFile( const QString & ); | ||
void stopWatching(); | ||
|
||
virtual ~FileSystemWatcher(); | ||
|
||
private: | ||
QString _file; | ||
|
||
private Q_SLOTS: | ||
void directoryChangedSlot ( const QString & ); | ||
void fileChangedSlot ( const QString & ); | ||
Q_SIGNALS: | ||
void fileChanged(); | ||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters