55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#include "NavigationController.h"
|
|
|
|
#include <QDir>
|
|
#include <QDebug>
|
|
|
|
#include "../models/NavigationItemModel.h"
|
|
#include "../models/NavigationListModel.h"
|
|
|
|
///@todo impelement reaction to item's clicked signal; implement back navigation
|
|
NavigationController::NavigationController(QObject *parent) : QObject(parent),
|
|
mRootItem(new NavigationItemModel(this)),
|
|
mNavList(new NavigationListModel(this))
|
|
{
|
|
|
|
}
|
|
|
|
void NavigationController::init(const QString &rootPath)
|
|
{
|
|
auto rootDir = QDir(rootPath);
|
|
if(!rootDir.exists()) return;
|
|
mRootPath = rootPath;
|
|
|
|
///@todo recursively do the following for all subdirs
|
|
auto subDirsNames = rootDir.entryList(QDir::AllDirs);
|
|
qDebug() << subDirsNames;
|
|
for(const auto& name : subDirsNames){
|
|
if(name == "." || name == "..") continue;
|
|
auto item = new NavigationItemModel(mRootItem);
|
|
if(!item->setPath(mRootPath + name)) {
|
|
item->deleteLater();
|
|
continue;
|
|
}
|
|
mRootItem->appendChild(item);
|
|
|
|
}
|
|
// just for testing!
|
|
auto list = mRootItem->getChildren();
|
|
for (const auto& elem: list){
|
|
qDebug() << elem->getImageSource();
|
|
}
|
|
// end testing
|
|
|
|
mNavList->setModelItems(mRootItem->getChildren());
|
|
}
|
|
|
|
void NavigationController::setContext(QQmlContext *context)
|
|
{
|
|
mContext = context;
|
|
setContextProperties();
|
|
}
|
|
|
|
void NavigationController::setContextProperties()
|
|
{
|
|
mContext->setContextProperty("navigationList", mNavList);
|
|
}
|