diff --git a/qmlUiKirigami/Main.qml b/qmlUiKirigami/Main.qml --- a/qmlUiKirigami/Main.qml +++ b/qmlUiKirigami/Main.qml @@ -102,14 +102,14 @@ Koko.SortModel { id: imageFolderModel sourceModel: Koko.ImageFolderModel { - url: imagePathArgument + url: imagePathArgument == "" ? "" : imagePathArgument[imagePathArgument.length -1] /** * makes sure that operation only occurs after the model is populated */ onRowsInserted: { - if( indexForUrl(imagePathArgument) != -1) { + if( indexForUrl(imagePathArgument[imagePathArgument.length -1]) != -1) { currentImage.model = this - currentImage.index = indexForUrl(imagePathArgument) + currentImage.index = indexForUrl(imagePathArgument[imagePathArgument.length -1]) } } } diff --git a/src/imagefoldermodel.cpp b/src/imagefoldermodel.cpp --- a/src/imagefoldermodel.cpp +++ b/src/imagefoldermodel.cpp @@ -81,21 +81,29 @@ Q_ASSERT( QUrl(url).isLocalFile()); url = QUrl(url).path(); + QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); if (url.isEmpty()) { - QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); Q_ASSERT(locations.size() > 1); url = locations.first().append("/"); } QString directoryUrl; - if( QDir(url).exists()) { + if (QDir(url).exists()) { directoryUrl = QUrl::fromLocalFile(url).toString(); } else { m_imagePath = url; directoryUrl = QUrl::fromLocalFile(url.left(url.lastIndexOf('/'))).toString(); } + /** + * Sets the url to ~/Pictures if the path is ~/Pictures path + * and leave it as it is, if it is foreign path + */ + if (directoryUrl.contains(QUrl::fromLocalFile(locations.first()).toString())) { + directoryUrl = QUrl::fromLocalFile(locations.first()).toString(); + } + if (dirLister()->url().path() == directoryUrl) { dirLister()->updateDirectory(QUrl(directoryUrl)); return; diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -83,6 +83,19 @@ resolvedImagePath = QUrl() ; } + QStringList directoryUrls; + if (!resolvedImagePath.isEmpty()) { + QString tempImagePath = resolvedImagePath.toString(); + directoryUrls << tempImagePath; + + if (resolvedImagePath.toString().startsWith(QUrl::fromLocalFile(locations.first()).toString())) { + while (tempImagePath != QUrl::fromLocalFile(locations.first()).toString()) { + tempImagePath = tempImagePath.left( tempImagePath.lastIndexOf('/')); + directoryUrls.prepend(tempImagePath); + } + } + } + FileSystemTracker tracker; tracker.setFolder(locations.first()); tracker.moveToThread(&trackerThread); @@ -101,7 +114,7 @@ QQmlContext* objectContext = engine.rootContext(); objectContext->setContextProperty("kokoProcessor", &processor); objectContext->setContextProperty("kokoConfig", &config); - objectContext->setContextProperty("imagePathArgument", resolvedImagePath.toString()); + objectContext->setContextProperty("imagePathArgument", directoryUrls); QString path; //we want different main files on desktop or mobile