summaryrefslogtreecommitdiffstats
path: root/wayland
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2017-07-17 18:00:32 +0200
committerHolger Freyther <holger+qt@freyther.de>2017-09-12 06:16:30 +0000
commit335968b70379b2d02bc0ce5e3b66d40666cde460 (patch)
tree714a6636c329c33197e0699d553ece91049e2802 /wayland
parent097cbe38ab5730d21f2c21eac9d3b56055c5ba36 (diff)
democompositor: Add method to scan and watch a directory
This will add files of a given directory and use a QFileSystemWatcher to check for changes and then re-scan it. It will return if the watching has started. Change-Id: I4d5021430fa400c648167fea37c45d7472ceb322 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'wayland')
-rw-r--r--wayland/democompositor/apps/applistmodel.cpp18
-rw-r--r--wayland/democompositor/apps/applistmodel.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/wayland/democompositor/apps/applistmodel.cpp b/wayland/democompositor/apps/applistmodel.cpp
index 10c4c15..8602588 100644
--- a/wayland/democompositor/apps/applistmodel.cpp
+++ b/wayland/democompositor/apps/applistmodel.cpp
@@ -53,6 +53,7 @@
#include "applog.h"
#include <QtCore/QDirIterator>
+#include <QtCore/QFileSystemWatcher>
static QHash<int, QByteArray> modelRoles()
{
@@ -111,6 +112,23 @@ QHash<int, QByteArray> AppListModel::roleNames() const
return m_roles;
}
+/*!
+ * Returns true if the directory can be watched
+ *
+ * Parse all JSON application files from the given directory
+ * and monitor it for changes.
+ */
+bool AppListModel::addAndWatchDir(const QString& dirName)
+{
+ auto watcher = new QFileSystemWatcher(this);
+ connect(watcher, &QFileSystemWatcher::directoryChanged, this, &AppListModel::addDir);
+ auto res = watcher->addPath(dirName);
+ addDir(dirName);
+
+ qCDebug(apps) << "addAndWatchDir" << dirName << "result: " << res;
+ return res;
+}
+
void AppListModel::addFile(const QString& fileName)
{
beginResetModel();
diff --git a/wayland/democompositor/apps/applistmodel.h b/wayland/democompositor/apps/applistmodel.h
index 1cd79b4..b177ece 100644
--- a/wayland/democompositor/apps/applistmodel.h
+++ b/wayland/democompositor/apps/applistmodel.h
@@ -79,6 +79,8 @@ public:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
public Q_SLOTS:
+ bool addAndWatchDir(const QString& dirName);
+
void addFile(const QString& fileName);
void addDir(const QString& dirName);