WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZFileSystemWatcher.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2015 Bob Dinitto
4  *
5  * Filename: ZFileSystemWatcher.h
6  * Created on: 10/26/2015
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #ifndef ZFILESYSTEMWATCHER_H
26 #define ZFILESYSTEMWATCHER_H
27 
28 #include <QObject>
29 #include <QMutex>
30 #include <QFileSystemWatcher>
31 #include <QMap>
32 #include <QStringList>
33 #include "zglobal.h"
34 
35 
36 namespace Zbl
37 {
38 
50 class ZFileSystemWatcher : public QObject
51 {
52  Q_OBJECT
53 public:
54 
55  typedef QMap<QString, int> zFileWatcherMap;
56 
57  explicit ZFileSystemWatcher(QObject *parent = nullptr);
58 
63  static void registerType();
64 
82 
83  Q_INVOKABLE bool addPath(const QString &file);
84  Q_INVOKABLE QStringList addPaths(const QStringList &files);
85  Q_INVOKABLE bool removePath(const QString &file);
86  Q_INVOKABLE QStringList removePaths(const QStringList &files);
87 
88  Q_INVOKABLE QStringList files() const;
89  Q_INVOKABLE QStringList directories() const;
90 
92  void setRestoreDeletedFiles(bool restoreFiles);
93 
94 signals:
95 
96  void fileChanged(const QString &path);
97 
98  void directoryChanged(const QString &path);
99 
100 public slots:
101 
102 
103 protected:
104 
105  void onFileChanged(const QString& path);
106 
107  bool waitForFileCreation(const QString &path);
108 
109  QFileSystemWatcher m_watcher;
110 
111  zFileWatcherMap m_paths;
112 
113  QMutex m_lock;
114 
116 
118 
119 };
120 
121 } // Zbl
122 
123 #endif // ZFILESYSTEMWATCHER_H
bool waitForFileCreation(const QString &path)
This class wraps QFileSystemWatcher and adds path reference counting.
bool restoreDeletedFiles
When true ZFileSystemWatcher will wait for deleted files to be restored.
Q_INVOKABLE QStringList removePaths(const QStringList &files)
Q_INVOKABLE QStringList directories() const
void onFileChanged(const QString &path)
#define ZBL_DECLARE_LOGGED_OBJECT
Definition: zglobal.h:94
Q_INVOKABLE bool removePath(const QString &file)
Q_INVOKABLE bool addPath(const QString &file)
void setRestoreDeletedFiles(bool restoreFiles)
Q_INVOKABLE QStringList addPaths(const QStringList &files)
ZFileSystemWatcher(QObject *parent=nullptr)
Definition: ZAndGate.cpp:6
static void registerType()
Registers ZFileSystemWatcher as a QML type.
Q_INVOKABLE QStringList files() const
QMap< QString, int > zFileWatcherMap
QFileSystemWatcher m_watcher
void fileChanged(const QString &path)
void directoryChanged(const QString &path)