mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -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 <QMouseEvent>
|
||||
#include <QVBoxLayout>
|
||||
#include <qfilesystemwatcher.h>
|
||||
|
||||
VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(parent), folderWidget(nullptr)
|
||||
{
|
||||
|
|
@ -104,6 +105,33 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
|
|||
} else {
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <QCheckBox>
|
||||
#include <QFileSystemModel>
|
||||
#include <qfilesystemwatcher.h>
|
||||
|
||||
class VisualDeckStorageSearchWidget;
|
||||
class VisualDeckStorageSortWidget;
|
||||
|
|
@ -25,6 +26,7 @@ class VisualDeckStorageWidget final : public QWidget
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit VisualDeckStorageWidget(QWidget *parent);
|
||||
void addRecursiveWatch(QFileSystemWatcher &watcher, const QString &dirPath);
|
||||
void retranslateUi();
|
||||
|
||||
CardSizeWidget *cardSizeWidget;
|
||||
|
|
@ -68,6 +70,7 @@ private:
|
|||
QCheckBox *tagsOnWidgetsVisibilityCheckBox;
|
||||
QScrollArea *scrollArea;
|
||||
VisualDeckStorageFolderDisplayWidget *folderWidget;
|
||||
QFileSystemWatcher watcher;
|
||||
};
|
||||
|
||||
#endif // VISUAL_DECK_STORAGE_WIDGET_H
|
||||
|
|
|
|||
|
|
@ -162,6 +162,10 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
|||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
}
|
||||
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue