diff --git a/qmlUiKirigami/Main.qml b/qmlUiKirigami/Main.qml --- a/qmlUiKirigami/Main.qml +++ b/qmlUiKirigami/Main.qml @@ -101,7 +101,9 @@ Koko.SortModel { id: imageFolderModel - sourceModel: Koko.ImageFolderModel {} + sourceModel: Koko.ImageFolderModel { + url: imagePathArgument + } /* * filterRole is an Item property exposed by the QSortFilterProxyModel */ diff --git a/qmlUiKirigami/desktopMain.qml b/qmlUiKirigami/desktopMain.qml --- a/qmlUiKirigami/desktopMain.qml +++ b/qmlUiKirigami/desktopMain.qml @@ -27,7 +27,4 @@ footer: Kirigami.ToolBarApplicationHeader { backButtonEnabled: false } - Component.onCompleted: { - console.log( imagePathArgument) - } } diff --git a/src/imagefoldermodel.h b/src/imagefoldermodel.h --- a/src/imagefoldermodel.h +++ b/src/imagefoldermodel.h @@ -71,9 +71,11 @@ Q_SIGNALS: void countChanged(); void urlChanged(); + void showImageViewer(const QString &path); private: QStringList m_mimeTypes; + QString m_imagePath; }; #endif // IMAGEFOLDERMODEL_H diff --git a/src/imagefoldermodel.cpp b/src/imagefoldermodel.cpp --- a/src/imagefoldermodel.cpp +++ b/src/imagefoldermodel.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -53,13 +54,9 @@ this, &ImageFolderModel::countChanged); connect(this, &QAbstractItemModel::modelReset, this, &ImageFolderModel::countChanged); - - //TODO: don't hardcode this - QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); - Q_ASSERT(locations.size() >= 1); - qDebug() << locations; - - setUrl("file://"+locations.first()); + + connect(this, &ImageFolderModel::showImageViewer, + this, [this] (const QString path) {qDebug() << "will show image " << path;}); } ImageFolderModel::~ImageFolderModel() @@ -87,13 +84,24 @@ if (url.isEmpty()) { return; } - if (dirLister()->url().path() == url) { - dirLister()->updateDirectory(QUrl(url)); + + QString directoryUrl; + + if( !QFileInfo(url).isDir()) { + m_imagePath = url; + directoryUrl = url.left(url.lastIndexOf('/')); + emit showImageViewer( m_imagePath); + } else { + directoryUrl = "file://" + url; + } + + if (dirLister()->url().path() == directoryUrl) { + dirLister()->updateDirectory(QUrl(directoryUrl)); return; } beginResetModel(); - dirLister()->openUrl(QUrl(url)); + dirLister()->openUrl(QUrl(directoryUrl)); endResetModel(); emit urlChanged(); } diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ if (parser.positionalArguments().size() > 1) { parser.showHelp(1); } - + if (parser.isSet("reset")) { KokoConfig config; config.reset(); @@ -73,6 +74,11 @@ Q_ASSERT(locations.size() >= 1); qDebug() << locations; + QUrl currentDirPath = QUrl::fromLocalFile(QDir::currentPath().append('/')); + QUrl resolvedImagePath = parser.positionalArguments().isEmpty() + ? QUrl(locations.first().append('/')) + : currentDirPath.resolved( parser.positionalArguments().first()); + FileSystemTracker tracker; tracker.setFolder(locations.first()); tracker.moveToThread(&trackerThread); @@ -91,7 +97,7 @@ QQmlContext* objectContext = engine.rootContext(); objectContext->setContextProperty("kokoProcessor", &processor); objectContext->setContextProperty("kokoConfig", &config); - objectContext->setContextProperty("imagePathArgument", parser.positionalArguments().isEmpty() ? QString() : parser.positionalArguments().first()); + objectContext->setContextProperty("imagePathArgument", resolvedImagePath.toString()); QString path; //we want different main files on desktop or mobile