diff options
author | Alexander Golubev <fatzer2@gmail.com> | 2024-02-17 22:22:18 +0300 |
---|---|---|
committer | Alexander Golubev <fatzer2@gmail.com> | 2024-02-17 22:36:27 +0300 |
commit | 8c522cac3456c10c5937c98bb6866323639aff51 (patch) | |
tree | 1695c91a84c836ce8f9c5db1d38945be2ddb63c3 /src/gvcore/fileviewcontroller.cpp | |
parent | 6ca60fdaa34563e0eb1087df86ba4b8c8a85b1ad (diff) | |
download | gwenview-8c522cac3456c10c5937c98bb6866323639aff51.tar.gz gwenview-8c522cac3456c10c5937c98bb6866323639aff51.zip |
Load file metadata asynchronously
Synchronous load of metadata resulted in big delays when opening a
directory with substantial amount of files.
Closes: https://mirror.git.trinitydesktop.org/gitea/TDE/gwenview/issues/17
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
Diffstat (limited to 'src/gvcore/fileviewcontroller.cpp')
-rw-r--r-- | src/gvcore/fileviewcontroller.cpp | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/src/gvcore/fileviewcontroller.cpp b/src/gvcore/fileviewcontroller.cpp index 4426658..ffcb971 100644 --- a/src/gvcore/fileviewcontroller.cpp +++ b/src/gvcore/fileviewcontroller.cpp @@ -48,6 +48,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include <kurldrag.h> #include <tdeio/job.h> #include <tdeio/file.h> +#include <tdeio/metainfojob.h> // Local #include "archive.h" @@ -188,6 +189,9 @@ public: TQComboBox* mFilterComboBox; TQCheckBox* mShowFilterBarCheckBox; + TDEIO::MetaInfoJob* mMetaInfoJob; + KFileItemList mMetaInfoTodo; + void initFilterBar() { mFilterBar=new FilterBar(that); mFilterBar->setSizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Fixed); @@ -266,6 +270,7 @@ FileViewController::FileViewController(TQWidget* parent,TDEActionCollection* act d->initFilterBar(); d->initFilterCombo(); d->mStack=new TQWidgetStack(this); + d->mMetaInfoJob=NULL; TQVBoxLayout *layout=new TQVBoxLayout(this); layout->addWidget(d->mToolBar); @@ -470,6 +475,7 @@ FileViewController::~FileViewController() { FileViewConfig::setToDateFilter(d->mFilterBar->mToDateEdit->date()); FileViewConfig::writeConfig(); + stopMetaInfoUpdate(); delete mDirLister; delete d; } @@ -1022,6 +1028,12 @@ void FileViewController::dirListerDeleteItem(KFileItem* item) { if (!newShownItem) newShownItem=findPreviousImage(); } + // Remove item from metadata todo list and job's pending update lists + d->mMetaInfoTodo.remove(item); + if (d->mMetaInfoJob) { + d->mMetaInfoJob->removeItem(item); + } + currentFileView()->removeItem(item); if (shownItem==item) { @@ -1040,21 +1052,24 @@ void FileViewController::dirListerNewItems(const KFileItemList& items) { LOG(""); mThumbnailsNeedUpdate=true; currentFileView()->addItemList(items); + loadMetaInfo(items); } void FileViewController::dirListerRefreshItems(const KFileItemList& list) { LOG(""); - const KFileItem* item=currentFileView()->shownFileItem(); KFileItemListIterator it(list); for (; *it!=0L; ++it) { - currentFileView()->updateView(*it); - if (*it==item) { - emit shownFileItemRefreshed(item); - } + updateViewItem(*it); } } +void FileViewController::updateViewItem(const KFileItem *item) { + currentFileView()->updateView(item); + if (item==currentFileView()->shownFileItem()) { + emit shownFileItemRefreshed(item); + } +} void FileViewController::refreshItems(const KURL::List& urls) { LOG(""); @@ -1145,6 +1160,7 @@ void FileViewController::dirListerCanceled() { if (mMode!=FILE_LIST) { mFileThumbnailView->stopThumbnailUpdate(); } + stopMetaInfoUpdate(); browseToFileNameToSelect(); } @@ -1316,5 +1332,45 @@ KFileItem* FileViewController::findItemByFileName(const TQString& fileName) cons return 0L; } +//----------------------------------------------------------------------------- +// +// MetaInfo loading +// +//----------------------------------------------------------------------------- + +void FileViewController::loadMetaInfo(const KFileItemList& items) { + if(d->mMetaInfoTodo.isEmpty()) { + d->mMetaInfoTodo = items; + } else { + for(const auto& item: items) { + d->mMetaInfoTodo.append(item); + } + } + + if(!d->mMetaInfoJob) { + nextMetaInfoJob(); + } +} + +void FileViewController::nextMetaInfoJob() { + if( !d->mMetaInfoTodo.isEmpty() ) { + d->mMetaInfoJob = new TDEIO::MetaInfoJob(d->mMetaInfoTodo); + connect( d->mMetaInfoJob, TQ_SIGNAL(result(TDEIO::Job *)), + this, TQ_SLOT(nextMetaInfoJob()) ); + connect( d->mMetaInfoJob, TQ_SIGNAL( gotMetaInfo(const KFileItem *)), + this, TQ_SLOT(updateViewItem(const KFileItem *)) ); + d->mMetaInfoTodo.clear(); + } else { + d->mMetaInfoJob = NULL; + } +} + +void FileViewController::stopMetaInfoUpdate() { + d->mMetaInfoTodo.clear(); + if(d->mMetaInfoJob) { + d->mMetaInfoJob->kill(); + d->mMetaInfoJob = 0; + } +} } // namespace |