From 335968b70379b2d02bc0ce5e3b66d40666cde460 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 17 Jul 2017 18:00:32 +0200 Subject: 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 --- wayland/democompositor/apps/applistmodel.cpp | 18 ++++++++++++++++++ wayland/democompositor/apps/applistmodel.h | 2 ++ 2 files changed, 20 insertions(+) (limited to 'wayland') 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 +#include static QHash modelRoles() { @@ -111,6 +112,23 @@ QHash 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 roleNames() const Q_DECL_OVERRIDE; public Q_SLOTS: + bool addAndWatchDir(const QString& dirName); + void addFile(const QString& fileName); void addDir(const QString& dirName); -- cgit v1.2.3