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>
(cherry picked from commit 8c522cac34)
pull/34/head
Alexander Golubev 9 months ago committed by Michele Calgaro
parent 8064b0ca87
commit 801c90b6c2
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -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

@ -174,6 +174,7 @@ private slots:
void toggleShowDotFiles();
void setSorting();
void updateSortMenu(TQDir::SortSpec);
void updateViewItem(const KFileItem *item);
// Dir lister slots
void dirListerDeleteItem(KFileItem* item);
@ -184,6 +185,11 @@ private slots:
void dirListerCanceled();
void dirListerCompleted();
// Metadata info loader jobs
void loadMetaInfo(const KFileItemList& items);
void nextMetaInfoJob();
void stopMetaInfoUpdate();
void openDropURLMenu(TQDropEvent*, KFileItem*);
void prefetchDone();

@ -30,7 +30,7 @@ namespace Gwenview {
namespace TimeUtils {
time_t getTime(const KFileItem* item) {
const KFileMetaInfo& info = item->metaInfo();
const KFileMetaInfo& info = item->metaInfo(/*autogen=*/false);
if (info.isValid()) {
TQVariant value = info.value("Date/time");
TQDateTime dt = value.toDateTime();

@ -29,7 +29,7 @@ namespace Gwenview {
namespace TimeUtils {
/**
* Returns the time of an item, using EXIF info if available
* Returns the time of an item, using EXIF info if available and already loaded
*/
time_t getTime(const KFileItem*);

Loading…
Cancel
Save