diff --git a/qmlUiKirigami/Main.qml b/qmlUiKirigami/Main.qml --- a/qmlUiKirigami/Main.qml +++ b/qmlUiKirigami/Main.qml @@ -28,6 +28,8 @@ Kirigami.ApplicationWindow { id: root header: Kirigami.ApplicationHeader {} + + property var intermediateFolders; /* * currentImage now stores the information related to the source model @@ -102,7 +104,7 @@ Koko.SortModel { id: imageFolderModel sourceModel: Koko.ImageFolderModel { - url: imagePathArgument + imagePath: imagePathArgument /** * makes sure that operation only occurs after the model is populated */ @@ -112,6 +114,8 @@ currentImage.index = indexForUrl(imagePathArgument) } } + + onIntermediateUrlsChanged: intermediateFolders = intermediateUrls; } /* * filterRole is an Item property exposed by the QSortFilterProxyModel @@ -195,4 +199,8 @@ albumView.model = imageFolderModel albumView.title = i18n("Folders") } + + onIntermediateFoldersChanged: { + console.log(intermediateFolders) + } } diff --git a/src/imagefoldermodel.h b/src/imagefoldermodel.h --- a/src/imagefoldermodel.h +++ b/src/imagefoldermodel.h @@ -46,16 +46,24 @@ * @property count Total number of rows */ Q_PROPERTY(int count READ count NOTIFY countChanged) + + Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged) + Q_PROPERTY(QStringList intermediateUrls READ intermediateUrls NOTIFY intermediateUrlsChanged) public: ImageFolderModel(QObject* parent=0); virtual ~ImageFolderModel(); QHash roleNames() const override; - void setUrl(QString& url); + void setUrl(const QString& url); QString url() const; + QString imagePath() const; + void setImagePath(QString &url); + + QStringList intermediateUrls() const; + QVariant data(const QModelIndex &index, int role) const; int count() const {return rowCount();} @@ -71,10 +79,13 @@ Q_SIGNALS: void countChanged(); void urlChanged(); + void imagePathChanged(); + void intermediateUrlsChanged(); private: QStringList m_mimeTypes; QString m_imagePath; + QStringList m_intermediateUrls; }; #endif // IMAGEFOLDERMODEL_H diff --git a/src/imagefoldermodel.cpp b/src/imagefoldermodel.cpp --- a/src/imagefoldermodel.cpp +++ b/src/imagefoldermodel.cpp @@ -76,35 +76,75 @@ return dirLister()->url().toString(); } -void ImageFolderModel::setUrl(QString& url) +void ImageFolderModel::setUrl(const QString& url) { Q_ASSERT( QUrl(url).isLocalFile()); - url = QUrl(url).path(); if (url.isEmpty()) { - QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); - Q_ASSERT(locations.size() > 1); - url = locations.first().append("/"); + return; } + if (dirLister()->url().path() == QUrl(url).path()) { + dirLister()->updateDirectory(url); + return; + } + + beginResetModel(); + dirLister()->openUrl(url); + endResetModel(); + emit urlChanged(); +} + +QString ImageFolderModel::imagePath() const +{ + return m_imagePath; +} + +void ImageFolderModel::setImagePath(QString &url) +{ + Q_ASSERT( QUrl(url).isLocalFile()); + + QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + + if(url.isEmpty()) { + Q_ASSERT(picturesLocations.size() > 1); + url = QUrl::fromLocalFile(picturesLocations.first().append("/")).toString(); + } + + url = QUrl(url).path(); + QString directoryUrl; + QStringList intermediateDirectories; if( QDir(url).exists()) { directoryUrl = QUrl::fromLocalFile(url).toString(); + setUrl(directoryUrl); } else { m_imagePath = url; directoryUrl = QUrl::fromLocalFile(url.left(url.lastIndexOf('/'))).toString(); } - if (dirLister()->url().path() == directoryUrl) { - dirLister()->updateDirectory(QUrl(directoryUrl)); - return; + // builds the logic here to find all the directory urls that it contains + if( directoryUrl.startsWith( QUrl::fromLocalFile(picturesLocations.first()).toString()) ) { + /** + * after this @directoryUrl will now have the part after "~/Pictures/" + */ + directoryUrl.remove( QUrl::fromLocalFile(picturesLocations.first()).toString() ); + intermediateDirectories = directoryUrl.split('/', QString::SkipEmptyParts); + directoryUrl = QUrl::fromLocalFile(picturesLocations.first()).toString().append('/'); } + m_intermediateUrls.append(directoryUrl); - beginResetModel(); - dirLister()->openUrl(QUrl(directoryUrl)); - endResetModel(); - emit urlChanged(); + foreach( QString intermediateDirectory, intermediateDirectories) { + directoryUrl.append( intermediateDirectory.append('/') ); + m_intermediateUrls.append(directoryUrl); + } + emit intermediateUrlsChanged(); +} + +QStringList ImageFolderModel::intermediateUrls() const +{ + return m_intermediateUrls; } int ImageFolderModel::indexForUrl(const QString &url) const