Skip to content

Commit

Permalink
refactor: Add Iterator initialization interface
Browse files Browse the repository at this point in the history
The dfmio Iterator is a gio Iterator created in hasnext. The dde-file-manager does not know when the initialization is complete. Now add a display call.

Log: Add Iterator initialization interface
  • Loading branch information
liyigang1 committed Jul 18, 2023
1 parent 397465d commit c74756e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/dfm-io/dfm-io/denumerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class DEnumerator : public QEnableSharedFromThis<DEnumerator>
DEnumeratorFuture *asyncIterator();
void startAsyncIterator();
bool isAsyncOver() const;
bool initEnumerator(const bool oneByone = true);

private:
QSharedPointer<DEnumeratorPrivate> d;
Expand Down
36 changes: 26 additions & 10 deletions src/dfm-io/dfm-io/denumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ bool DEnumeratorPrivate::checkFilter()
return ret;
}

FTS *DEnumeratorPrivate::openDirByfts()
bool DEnumeratorPrivate::openDirByfts()
{
FTS *fts { nullptr };
QString path = q->uri().path();
if (path != "/" && path.endsWith("/"))
path = path.left(path.length() - 1);
Expand All @@ -259,10 +258,10 @@ FTS *DEnumeratorPrivate::openDirByfts()
if (nullptr == fts) {
qWarning() << "fts_open open error : " << QString::fromLocal8Bit(strerror(errno));
error.setCode(DFMIOErrorCode::DFM_IO_ERROR_FTS_OPEN);
return nullptr;
return false;
}

return fts;
return true;
}

void DEnumeratorPrivate::insertSortFileInfoList(QList<QSharedPointer<DEnumerator::SortFileInfo>> &fileList, QList<QSharedPointer<DEnumerator::SortFileInfo>> &dirList, FTSENT *ent, FTS *fts, const QSet<QString> &hideList)
Expand Down Expand Up @@ -692,8 +691,10 @@ QList<QSharedPointer<DFileInfo>> DEnumerator::fileInfoList()

QList<QSharedPointer<DEnumerator::SortFileInfo>> DEnumerator::sortFileInfoList()
{
FTS *fts = d->openDirByfts();
if (!fts)
if (!d->fts)
d->openDirByfts();

if (!d->fts)
return {};

QList<QSharedPointer<DEnumerator::SortFileInfo>> listFile;
Expand All @@ -702,7 +703,7 @@ QList<QSharedPointer<DEnumerator::SortFileInfo>> DEnumerator::sortFileInfoList()
const QUrl &urlHidden = QUrl::fromLocalFile(d->uri.path() + "/.hidden");
hideList = DLocalHelper::hideListFromUrl(urlHidden);
while (1) {
FTSENT *ent = fts_read(fts);
FTSENT *ent = fts_read(d->fts);

if (ent == nullptr) {
break;
Expand All @@ -716,11 +717,11 @@ QList<QSharedPointer<DEnumerator::SortFileInfo>> DEnumerator::sortFileInfoList()
if (QString(ent->fts_path) == d->uri.path() || flag == FTS_DP)
continue;

d->insertSortFileInfoList(listFile, listDir, ent, fts, hideList);
d->insertSortFileInfoList(listFile, listDir, ent, d->fts, hideList);
}

fts_close(fts);
fts = nullptr;
fts_close(d->fts);
d->fts = nullptr;

if (d->isMixDirAndFile)
return listFile;
Expand Down Expand Up @@ -751,3 +752,18 @@ bool DEnumerator::isAsyncOver() const
{
return d->asyncOvered;
}

bool DEnumerator::initEnumerator(const bool oneByone)
{
if (d->async)
return true;

if (oneByone) {
if (d->inited)
return true;
return d->init();
}
if (d->fts)
return true;
return d->openDirByfts();
}
3 changes: 2 additions & 1 deletion src/dfm-io/dfm-io/private/denumerator_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DEnumeratorPrivate : public QObject, public QEnableSharedFromThis<DEnumera
void checkAndResetCancel();
void setErrorFromGError(GError *gerror);
bool checkFilter();
FTS *openDirByfts();
bool openDirByfts();
void insertSortFileInfoList(QList<QSharedPointer<DEnumerator::SortFileInfo>> &fileList,
QList<QSharedPointer<DEnumerator::SortFileInfo>> &dirList,
FTSENT *ent,
Expand Down Expand Up @@ -91,6 +91,7 @@ class DEnumeratorPrivate : public QObject, public QEnableSharedFromThis<DEnumera
ulong enumTimeout { 0 };
bool ftsCanceled { false };
std::atomic_bool inited { false };
FTS *fts { nullptr };
bool enumSubDir { false };
bool enumLinks { false };
std::atomic_bool async { false };
Expand Down

0 comments on commit c74756e

Please sign in to comment.