diff --git a/containments/desktop/plugins/folder/foldermodel.cpp b/containments/desktop/plugins/folder/foldermodel.cpp index 49cbbee6..9c87671e 100644 --- a/containments/desktop/plugins/folder/foldermodel.cpp +++ b/containments/desktop/plugins/folder/foldermodel.cpp @@ -134,17 +134,6 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent), connect(dirLister, &KCoreDirLister::started, this, std::bind(&FolderModel::setStatus, this, Status::Listing)); - void (KCoreDirLister::*myCompletedSignal)() = &KCoreDirLister::completed; - QObject::connect(dirLister, myCompletedSignal, this, [this] { - setStatus(Status::Ready); - emit listingCompleted(); - }); - - void (KCoreDirLister::*myCanceledSignal)() = &KCoreDirLister::canceled; - QObject::connect(dirLister, myCanceledSignal, this, [this] { - setStatus(Status::Canceled); - emit listingCanceled(); - }); m_dirModel = new KDirModel(this); m_dirModel->setDirLister(dirLister); @@ -155,8 +144,8 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent), * delay this via queued connection, such that the row is available and can be mapped * when we emit the move request */ - connect(this, &QAbstractItemModel::rowsInserted, - this, [this](const QModelIndex &parent, int first, int last) { + + auto rowsInserted = [this](const QModelIndex &parent, int first, int last) { for (int i = first; i <= last; ++i) { const auto idx = index(i, 0, parent); const auto url = itemForIndex(idx).url(); @@ -168,7 +157,28 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent), emit move(pos.x(), pos.y(), {url}); } } + }; + + connect(this, &QAbstractItemModel::rowsInserted, + this, rowsInserted); + + void (KCoreDirLister::*myCompletedSignal)() = &KCoreDirLister::completed; + QObject::connect(dirLister, myCompletedSignal, this, [this, rowsInserted] { + setSourceModel(m_dirModel); + if (rowCount() > 0) { + rowsInserted(QModelIndex(), 0, rowCount() -1); + } + setStatus(Status::Ready); + emit listingCompleted(); + }); + + void (KCoreDirLister::*myCanceledSignal)() = &KCoreDirLister::canceled; + QObject::connect(dirLister, myCanceledSignal, this, [this] { + setStatus(Status::Canceled); + emit listingCanceled(); }); + + /* * Dropped files may not actually show up as new files, e.g. when we overwrite * an existing file. Or files that fail to be listed by the dirLister, or... @@ -192,7 +202,6 @@ FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent), connect(m_selectionModel, &QItemSelectionModel::selectionChanged, this, &FolderModel::selectionChanged); - setSourceModel(m_dirModel); setSortLocaleAware(true); setFilterCaseSensitivity(Qt::CaseInsensitive);