forked from mirrors/gio-qt
feat: optional timeout parameter for DGioFile::createFileInfo.
This commit is contained in:
parent
48ed50bc3c
commit
1203a0f839
2 changed files with 21 additions and 4 deletions
|
@ -55,7 +55,7 @@ public:
|
|||
QString path() const;
|
||||
QString uri() const;
|
||||
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> createFileInfo(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> createFileInfo(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE, unsigned long timeout_msec = ULONG_MAX);
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> createFileSystemInfo(QString attr = "*");
|
||||
QExplicitlySharedDataPointer<DGioFileIterator> createFileIterator(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
|
||||
void createFileIteratorAsync(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
#include <giomm/fileenumerator.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWaitCondition>
|
||||
#include <QMutex>
|
||||
#include <QTime>
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include <dgiomountoperation.h>
|
||||
|
||||
using namespace Gio;
|
||||
|
@ -223,15 +227,28 @@ QString DGioFile::uri() const
|
|||
*
|
||||
* \return the created file info object, or nullptr if create failed.
|
||||
*/
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> DGioFile::createFileInfo(QString attr, DGioFileQueryInfoFlags queryInfoFlags)
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> DGioFile::createFileInfo(QString attr, DGioFileQueryInfoFlags queryInfoFlags, unsigned long timeout_msec)
|
||||
{
|
||||
Q_D(DGioFile);
|
||||
|
||||
try {
|
||||
unsigned int flagValue = queryInfoFlags;
|
||||
FileQueryInfoFlags flags = static_cast<FileQueryInfoFlags>(flagValue);
|
||||
Glib::RefPtr<FileInfo> gmmFileInfo = d->getGmmFileInstance()->query_info(attr.toStdString(), flags);
|
||||
if (gmmFileInfo) {
|
||||
Glib::RefPtr<FileInfo> gmmFileInfo;
|
||||
QWaitCondition cond;
|
||||
QtConcurrent::run([&] {
|
||||
QTime t;
|
||||
t.start();
|
||||
gmmFileInfo = d->getGmmFileInstance()->query_info(attr.toStdString(), flags);
|
||||
if (t.elapsed() < timeout_msec) {
|
||||
cond.wakeAll();
|
||||
}
|
||||
});
|
||||
QMutex m;
|
||||
m.lock();
|
||||
bool finished = cond.wait(&m, timeout_msec);
|
||||
m.unlock();
|
||||
if (finished && gmmFileInfo) {
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> fileInfoPtr(new DGioFileInfo(gmmFileInfo.release()));
|
||||
return fileInfoPtr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue