diff --git a/src/imagefoldermodel.h b/src/imagefoldermodel.h --- a/src/imagefoldermodel.h +++ b/src/imagefoldermodel.h @@ -53,7 +53,7 @@ QHash roleNames() const override; - void setUrl(const QString& url); + void setUrl(QString& url); QString url() const; QVariant data(const QModelIndex &index, int role) const; @@ -71,7 +71,7 @@ Q_SIGNALS: void countChanged(); void urlChanged(); - void showImageViewer(const QString &path); + void showImageViewer(int indexValue); private: QStringList m_mimeTypes; diff --git a/src/imagefoldermodel.cpp b/src/imagefoldermodel.cpp --- a/src/imagefoldermodel.cpp +++ b/src/imagefoldermodel.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -54,9 +54,6 @@ this, &ImageFolderModel::countChanged); connect(this, &QAbstractItemModel::modelReset, this, &ImageFolderModel::countChanged); - - connect(this, &ImageFolderModel::showImageViewer, - this, [this] (const QString path) {qDebug() << "will show image " << path;}); } ImageFolderModel::~ImageFolderModel() @@ -79,20 +76,23 @@ return dirLister()->url().toString(); } -void ImageFolderModel::setUrl(const QString& url) +void ImageFolderModel::setUrl(QString& url) { if (url.isEmpty()) { return; } + Q_ASSERT( QUrl(url).isLocalFile()); + url = QUrl(url).path(); + QString directoryUrl; - if( !QFileInfo(url).isDir()) { - m_imagePath = url; - directoryUrl = url.left(url.lastIndexOf('/')); - emit showImageViewer( m_imagePath); + if( QDir(url).exists()) { + directoryUrl = QUrl::fromLocalFile(url).toString(); } else { - directoryUrl = "file://" + url; + m_imagePath = url; + directoryUrl = QUrl::fromLocalFile(url.left(url.lastIndexOf('/'))).toString(); + emit showImageViewer( indexForUrl(m_imagePath)); } if (dirLister()->url().path() == directoryUrl) { diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -76,9 +76,13 @@ QUrl currentDirPath = QUrl::fromLocalFile(QDir::currentPath().append('/')); QUrl resolvedImagePath = parser.positionalArguments().isEmpty() - ? QUrl(locations.first().append('/')) + ? QUrl::fromLocalFile(locations.first().append('/')) : currentDirPath.resolved( parser.positionalArguments().first()); + if( !resolvedImagePath.isLocalFile()) { + resolvedImagePath = QUrl::fromLocalFile(locations.first().append('/')) ; + } + FileSystemTracker tracker; tracker.setFolder(locations.first()); tracker.moveToThread(&trackerThread);