Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
ADD: file watcher API
Browse files Browse the repository at this point in the history
  • Loading branch information
anak10thn committed Apr 22, 2015
1 parent 3946e26 commit fd5e581
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,16 @@ QVariant fs::info(const QString &path){
QJsonDocument json_enc = QJsonDocument::fromVariant(map);
return json_enc.toVariant();
}

void fs::watcher(const QString &path){
QFileInfo PATH(path);
if(PATH.exists()){
WATCH.addPath(path);
connect(&WATCH,SIGNAL(fileChanged(QString)),this,SLOT(SLOT_WATCH(QString)));
connect(&WATCH,SIGNAL(directoryChanged(QString)),this,SLOT(SLOT_WATCH(QString)));
}
}

void fs::SLOT_WATCH(const QString &path){
emit watch(path);
}
6 changes: 5 additions & 1 deletion src/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QJsonArray>
#include <QJsonParseError>
#include <QDateTime>
#include <QFileSystemWatcher>
#include "ignjson.h"

class fs : public QObject
Expand All @@ -25,9 +26,10 @@ class fs : public QObject
public:
fs(QObject *parent = 0);
ignjson *json;
QFileSystemWatcher WATCH;

signals:

void watch(const QString &path);
public slots:
bool fileRemove(const QString& path);
QString appPath();
Expand All @@ -51,6 +53,8 @@ public slots:
QString saveFileDialog(const QVariant &config);
QStringList list(const QString &path);
QVariant info(const QString &path);
void watcher(const QString &path);
void SLOT_WATCH(const QString &path);
};

#endif // FS_H

1 comment on commit fd5e581

@anak10thn
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.