diff --git a/lib/contextmanager.cpp b/lib/contextmanager.cpp --- a/lib/contextmanager.cpp +++ b/lib/contextmanager.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace Gwenview { @@ -300,8 +301,29 @@ { GV_RETURN_IF_FAIL(url.isValid()); d->mUrlToSelect = url; - setCurrentDirUrl(url.adjusted(QUrl::RemoveFilename)); + setCurrentUrl(url); + + // Make sure that an url passed as command line argument is loaded + // and shown before a possibly long running dirlister on a slow + // network device is started. So start the dirlister after url is + // loaded or failed to load. + if (UrlUtils::urlIsFastLocalFile(url.adjusted(QUrl::RemoveFilename))) { + setCurrentDirUrl(url.adjusted(QUrl::RemoveFilename)); + } + else { + Document::Ptr doc = DocumentFactory::instance()->getCachedDocument(url); + connect(doc.data(), &Document::loaded, [this, url]() { + setCurrentDirUrl(url.adjusted(QUrl::RemoveFilename)); + }); + connect(doc.data(), &Document::loadingFailed, [this, url]() { + setCurrentDirUrl(url.adjusted(QUrl::RemoveFilename)); + }); + connect(doc.data(), &Document::downSampledImageReady, [this, url]() { + setCurrentDirUrl(url.adjusted(QUrl::RemoveFilename)); + }); + } + selectUrlToSelect(); }