#
#
# add_file "src/model/InventoryWatcher.cpp"
# content [d70ebb30de4bc237cb3a2df7ec9756966ab1e04d]
#
# add_file "src/model/InventoryWatcher.h"
# content [0ddc4c5fcc764c4c6676d938aa7f3e56ff0f6428]
#
============================================================
--- src/model/InventoryWatcher.cpp d70ebb30de4bc237cb3a2df7ec9756966ab1e04d
+++ src/model/InventoryWatcher.cpp d70ebb30de4bc237cb3a2df7ec9756966ab1e04d
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Thomas Keller *
+ * address@hidden *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ ***************************************************************************/
+
+#include "InventoryWatcher.h"
+#include "InventoryItem.h"
+
+InventoryWatcher::InventoryWatcher(QObject * parent)
+ : QFileSystemWatcher(parent)
+{
+ connect(
+ this, SIGNAL(directoryChanged(const QString &)),
+ this, SLOT(pathChanged(const QString &))
+ );
+
+ connect(
+ this, SIGNAL(fileChanged(const QString &)),
+ this, SLOT(pathChanged(const QString &))
+ );
+}
+
+InventoryWatcher::~InventoryWatcher() {}
+
+void InventoryWatcher::setWorkspacePath(const WorkspacePath & wp)
+{
+ workspace = wp;
+}
+
+void InventoryWatcher::watchItems(const QModelIndexList & indexes)
+{
+ addPaths(pathsFromIndexes(indexes));
+}
+
+void InventoryWatcher::unwatchItems(const QModelIndexList & indexes)
+{
+ removePaths(pathsFromIndexes(indexes));
+}
+
+QStringList InventoryWatcher::pathsFromIndexes(const QModelIndexList & indexes)
+{
+ if (workspace.isEmpty()) QStringList();
+ QStringList paths;
+
+ foreach (QModelIndex idx, indexes)
+ {
+ if (!idx.isValid()) continue;
+ ModelItem * item = static_cast(idx.internalPointer());
+ I(item);
+ InventoryItem * invitem = reinterpret_cast(item);
+ if (!invitem) continue;
+ if (invitem->getFSType() == InventoryItem::None) continue;
+D(QString("processing %1").arg(invitem->getPath()));
+ paths.append(workspace + "/" + invitem->getPath());
+ }
+ return paths;
+}
+
+void InventoryWatcher::pathChanged(const QString & path)
+{
+ I(path.indexOf(workspace) != -1);
+ QString pathComponent = path.mid(path.indexOf(workspace) + workspace.length() + 1);
+ emit changedPath(pathComponent);
+}
+
============================================================
--- src/model/InventoryWatcher.h 0ddc4c5fcc764c4c6676d938aa7f3e56ff0f6428
+++ src/model/InventoryWatcher.h 0ddc4c5fcc764c4c6676d938aa7f3e56ff0f6428
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Thomas Keller *
+ * address@hidden *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ ***************************************************************************/
+
+#ifndef INVENTORY_WATCHER_H
+#define INVENTORY_WATCHER_H
+
+#include "vocab.h"
+#include
+#include
+
+class InventoryWatcher : public QFileSystemWatcher
+{
+ Q_OBJECT
+public:
+ InventoryWatcher(QObject *);
+ ~InventoryWatcher();
+
+signals:
+ void changedPath(const QString &);
+
+public slots:
+ void setWorkspacePath(const WorkspacePath &);
+ void watchItems(const QModelIndexList &);
+ void unwatchItems(const QModelIndexList &);
+
+private:
+ QStringList pathsFromIndexes(const QModelIndexList &);
+ WorkspacePath workspace;
+
+private slots:
+ void pathChanged(const QString &);
+};
+
+#endif
+