|
@@ -14,6 +14,13 @@
|
|
|
#include <QTextStream>
|
|
|
|
|
|
#include <QDebug>
|
|
|
+#include <QAbstractItemModel>
|
|
|
+
|
|
|
+class ModelRelay : public QObject {
|
|
|
+ Q_OBJECT
|
|
|
+signals:
|
|
|
+ void countChanged();
|
|
|
+};
|
|
|
|
|
|
class FileReader : public QObject {
|
|
|
Q_OBJECT
|
|
@@ -56,17 +63,22 @@ int main(int argc, char *argv[])
|
|
|
QQmlApplicationEngine engine;
|
|
|
QThread scanningThread;
|
|
|
PictureModel *model = new PictureModel();
|
|
|
- const QString &artPath = settings.value("artPath","/blackhole/media/art").toString();
|
|
|
+ QString artPath = settings.value("artPath","/blackhole/media/art").toString();
|
|
|
+ QStringList extensions = settings.value("extensions", QStringList() << "jpg" << "png").toStringList();
|
|
|
+ settings.setValue("artPath", artPath);
|
|
|
+ settings.setValue("extensions", extensions);
|
|
|
|
|
|
- model->addSupportedExtension("jpg");
|
|
|
- model->addSupportedExtension("png");
|
|
|
+ model->setSupportedExtensions(extensions);
|
|
|
model->moveToThread(&scanningThread);
|
|
|
scanningThread.start();
|
|
|
-
|
|
|
QMetaObject::invokeMethod(model, "setModelRoot", Qt::QueuedConnection, Q_ARG(QString,artPath));
|
|
|
- settings.setValue("artPath", artPath);
|
|
|
+
|
|
|
+ ModelRelay modelRelay;
|
|
|
+ QObject::connect(model, &PictureModel::countChanged, &modelRelay, &ModelRelay::countChanged, Qt::QueuedConnection);
|
|
|
|
|
|
engine.rootContext()->setContextProperty("imageModel", model);
|
|
|
+ engine.rootContext()->setContextProperty("modelRelay", &modelRelay);
|
|
|
+
|
|
|
engine.rootContext()->setContextProperty("fileReader", new FileReader(&app));
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
|
|
|