VPTissue Reference Manual
FileSystemWatcher.h
Go to the documentation of this file.
1 #ifndef WS_UTIL_FILESYSTEMWATCHER_H_INCLUDED
2 #define WS_UTIL_FILESYSTEMWATCHER_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <iostream>
23 #include <functional>
24 #include <QFileSystemWatcher>
25 
26 namespace SimShell {
27 namespace Ws {
28 namespace Util {
29 
36 class FileSystemWatcher : public QObject
37 {
38  Q_OBJECT
39 public:
44  FileSystemWatcher(const std::string& path, std::function<void()> callback)
45  : p(path),
46  c(callback),
47  active(false)
48  {
49  w.addPath(QString::fromStdString(p));
50 
51  SetActive(true);
52  }
53 
58  : p(move(other.p)),
59  c(move(other.c)),
60  active(false)
61  {
62  w.addPath(QString::fromStdString(p));
63 
64  SetActive(other.active);
65  }
66 
72  bool IsActive() const
73  {
74  return active;
75  }
76 
82  void SetActive(bool a)
83  {
84  if (active != a) {
85  if (a) {
86  connect(&w, SIGNAL(directoryChanged(const QString&)), this, SLOT(SLOT_Changed(const QString&)));
87  connect(&w, SIGNAL(fileChanged(const QString&)), this, SLOT(SLOT_Changed(const QString&)));
88  } else {
89  disconnect(&w, 0, 0, 0); // disconnect everything connected to w's signals.
90  }
91  active = a;
92  }
93  }
94 
95 private slots:
96  void SLOT_Changed(const QString& ) {
97  c();
98  }
99 
100 private:
101  QFileSystemWatcher w;
102  std::string p;
103  std::function<void()> c;
104  bool active;
105 };
106 
107 } // namespace
108 } // namespace
109 } // namespace
110 
111 #endif // end_of_inclde_guard
Utility class for being informed about changes to a file/directory on the filesystem.
void SetActive(bool a)
Set 'active' property, i.e.
FileSystemWatcher(FileSystemWatcher &&other)
Move constructor.
FileSystemWatcher(const std::string &path, std::function< void()> callback)
see the online Qt documentation
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
bool IsActive() const
Get 'active' property, i.e.