From 2ca8e6242e5acaab087ef9ff23976412123463c3 Mon Sep 17 00:00:00 2001 From: uncor3 Date: Tue, 7 Apr 2026 04:22:38 +0000 Subject: [PATCH] fix(gallery): implement dateTime --- src/photomodel.cpp | 39 ++++++++++----------------------------- src/photomodel.h | 1 - 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/photomodel.cpp b/src/photomodel.cpp index 99e1f5c..b35b00e 100644 --- a/src/photomodel.cpp +++ b/src/photomodel.cpp @@ -52,6 +52,7 @@ void PhotoModel::clear() endResetModel(); qDebug() << "Cleared PhotoModel data"; + // FIXME : bug we use the same loader on every device // FIXME: we shouldn't do this // QHashPrivate::Span>::hasNode // qhash.h 310 0x5555559d50e1 @@ -149,16 +150,19 @@ bool PhotoModel::populatePhotoPaths() } m_allPhotos.clear(); - QList photoPaths = m_device->afc_backend->list_dir(m_albumPath); + QMap photoPaths = + m_device->afc_backend->list_dir_with_creation_date(m_albumPath); + + for (auto it = photoPaths.constBegin(); it != photoPaths.constEnd(); ++it) { + const QString &fileName = it.key(); + const QVariant &creationDateVariant = it.value(); - for (const QString &fileName : photoPaths) { if (iDescriptor::Utils::isGalleryFile(fileName)) { PhotoInfo info; info.filePath = m_albumPath + "/" + fileName; info.fileName = fileName; info.thumbnailRequested = false; - info.fileType = determineFileType(fileName); - info.dateTime = extractDateTimeFromFile(info.filePath); + info.dateTime = creationDateVariant.toDateTime(); m_allPhotos.append(info); } } @@ -283,34 +287,11 @@ QStringList PhotoModel::getFilteredFilePaths() const return paths; } -// FIXME: -// Helper methods -QDateTime PhotoModel::extractDateTimeFromFile(const QString &filePath) const -{ - // AfcFileInfo info = {}; - // IdeviceFfiError *err = ServiceManager::safeAfcGetFileInfo( - // m_device, filePath.toUtf8().constData(), &info); - // if (!err && info.creation) { - // uint64_t creation_seconds = info.creation; - // QDateTime dateTime = - // QDateTime::fromSecsSinceEpoch(creation_seconds, Qt::UTC); - - // afc_file_info_free(&info); - // if (dateTime.isValid()) { - // return dateTime; - // } - // } - - return QDateTime::currentDateTime(); -} - PhotoInfo::FileType PhotoModel::determineFileType(const QString &fileName) const { - if (iDescriptor::Utils::isVideoFile(fileName)) { + if (iDescriptor::Utils::isVideoFile(fileName)) return PhotoInfo::Video; - } else { - return PhotoInfo::Image; - } + return PhotoInfo::Image; } void PhotoModel::setAlbumPath(const QString &albumPath) diff --git a/src/photomodel.h b/src/photomodel.h index 46093c9..3dd348b 100644 --- a/src/photomodel.h +++ b/src/photomodel.h @@ -101,7 +101,6 @@ private: void sortPhotos(QList &photos) const; bool matchesFilter(const PhotoInfo &info) const; - QDateTime extractDateTimeFromFile(const QString &filePath) const; PhotoInfo::FileType determineFileType(const QString &fileName) const; private slots: