mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 16:32:16 -07:00
Filesystem watching.
This commit is contained in:
parent
2bf6ef959e
commit
df1aa46a81
3 changed files with 35 additions and 0 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <qfilesystemwatcher.h>
|
||||||
|
|
||||||
VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(parent), folderWidget(nullptr)
|
VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(parent), folderWidget(nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -104,6 +105,33 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
|
||||||
} else {
|
} else {
|
||||||
scrollArea->setWidget(databaseLoadIndicator);
|
scrollArea->setWidget(databaseLoadIndicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addRecursiveWatch(watcher, SettingsCache::instance().getDeckPath());
|
||||||
|
|
||||||
|
// Signals for changes
|
||||||
|
connect(&watcher, &QFileSystemWatcher::fileChanged, [this] {
|
||||||
|
qDebug() << "Modified a file";
|
||||||
|
if (scrollArea->widget() != databaseLoadIndicator) {
|
||||||
|
createRootFolderWidget();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(&watcher, &QFileSystemWatcher::directoryChanged, [this] {
|
||||||
|
qDebug() << "Modified a folder";
|
||||||
|
if (scrollArea->widget() != databaseLoadIndicator) {
|
||||||
|
createRootFolderWidget();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckStorageWidget::addRecursiveWatch(QFileSystemWatcher &watcher, const QString &dirPath)
|
||||||
|
{
|
||||||
|
QDir dir(dirPath);
|
||||||
|
watcher.addPath(dirPath); // Watch the root directory
|
||||||
|
|
||||||
|
for (const QFileInfo &entry : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||||
|
addRecursiveWatch(watcher, entry.absoluteFilePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckStorageWidget::showEvent(QShowEvent *event)
|
void VisualDeckStorageWidget::showEvent(QShowEvent *event)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
|
#include <qfilesystemwatcher.h>
|
||||||
|
|
||||||
class VisualDeckStorageSearchWidget;
|
class VisualDeckStorageSearchWidget;
|
||||||
class VisualDeckStorageSortWidget;
|
class VisualDeckStorageSortWidget;
|
||||||
|
|
@ -25,6 +26,7 @@ class VisualDeckStorageWidget final : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VisualDeckStorageWidget(QWidget *parent);
|
explicit VisualDeckStorageWidget(QWidget *parent);
|
||||||
|
void addRecursiveWatch(QFileSystemWatcher &watcher, const QString &dirPath);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
CardSizeWidget *cardSizeWidget;
|
CardSizeWidget *cardSizeWidget;
|
||||||
|
|
@ -68,6 +70,7 @@ private:
|
||||||
QCheckBox *tagsOnWidgetsVisibilityCheckBox;
|
QCheckBox *tagsOnWidgetsVisibilityCheckBox;
|
||||||
QScrollArea *scrollArea;
|
QScrollArea *scrollArea;
|
||||||
VisualDeckStorageFolderDisplayWidget *folderWidget;
|
VisualDeckStorageFolderDisplayWidget *folderWidget;
|
||||||
|
QFileSystemWatcher watcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VISUAL_DECK_STORAGE_WIDGET_H
|
#endif // VISUAL_DECK_STORAGE_WIDGET_H
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,10 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
||||||
lastFileName = fileName;
|
lastFileName = fileName;
|
||||||
lastFileFormat = fmt;
|
lastFileFormat = fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file.flush();
|
||||||
|
file.close();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue