feat: add Wrapper of Gio (#13)

add Wrapper of Gio::File::query_info
add Wrapper of Gio::FileInfo::get_size
This commit is contained in:
kegechen 2019-08-01 19:59:08 +08:00 committed by GitHub
parent 41eb6531fe
commit 4123262258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 1 deletions

View File

@ -52,6 +52,7 @@ public:
QString basename() const; QString basename() const;
QString path() const; QString path() const;
QString uri() const; QString uri() const;
QExplicitlySharedDataPointer<DGioFileInfo> createFileInfo(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
QExplicitlySharedDataPointer<DGioFileInfo> createFileSystemInfo(QString attr = "*"); QExplicitlySharedDataPointer<DGioFileInfo> createFileSystemInfo(QString attr = "*");
QExplicitlySharedDataPointer<DGioFileIterator> createFileIterator(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); QExplicitlySharedDataPointer<DGioFileIterator> createFileIterator(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
void createFileIteratorAsync(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); void createFileIteratorAsync(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);

View File

@ -50,6 +50,7 @@ public:
// file info // file info
QString displayName() const; QString displayName() const;
DGioFileType fileType() const; DGioFileType fileType() const;
quint64 fileSize() const;
// filesystem info. // filesystem info.
bool fsReadOnly() const; bool fsReadOnly() const;

View File

@ -178,6 +178,32 @@ QString DGioFile::uri() const
return d->uri(); return d->uri();
} }
/*!
* \brief Gets the requested information about the file.
*
* Wrapper of Gio::File::query_info(const std::string& attributes = "*", FileQueryInfoFlags flags = FILE_QUERY_INFO_NONE).
*
* \return the created file info object, or nullptr if create failed.
*/
QExplicitlySharedDataPointer<DGioFileInfo> DGioFile::createFileInfo(QString attr, DGioFileQueryInfoFlags queryInfoFlags)
{
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) {
QExplicitlySharedDataPointer<DGioFileInfo> fileInfoPtr(new DGioFileInfo(gmmFileInfo.release()));
return fileInfoPtr;
}
} catch (const Glib::Error &error) {
qDebug() << QString::fromStdString(error.what().raw());
}
return QExplicitlySharedDataPointer<DGioFileInfo>(nullptr);
}
/*! /*!
* \brief Obtains information about the filesystem the file is on. * \brief Obtains information about the filesystem the file is on.
* *

View File

@ -115,6 +115,18 @@ DGioFileType DGioFileInfo::fileType() const
return static_cast<DGioFileType>(d->getGmmFileInfoInstance()->get_file_type()); return static_cast<DGioFileType>(d->getGmmFileInfoInstance()->get_file_type());
} }
/*!
* \brief DGioFileInfo::fileSize
* Wrapper of Gio::FileInfo::get_size()
* \return
*/
quint64 DGioFileInfo::fileSize() const
{
Q_D(const DGioFileInfo);
return static_cast<quint64>(d->getGmmFileInfoInstance()->get_size());
}
bool DGioFileInfo::fsReadOnly() const bool DGioFileInfo::fsReadOnly() const
{ {
Q_D(const DGioFileInfo); Q_D(const DGioFileInfo);

View File

@ -89,7 +89,17 @@ int main(int argc, char * argv[])
qDebug() << f->basename() << f->path() << f->uri(); qDebug() << f->basename() << f->path() << f->uri();
QExplicitlySharedDataPointer<DGioFileInfo> fi = f->createFileSystemInfo(); QExplicitlySharedDataPointer<DGioFileInfo> fi = f->createFileSystemInfo();
if (fi) { if (fi) {
qDebug() << fi->fsFreeBytes() << fi->fsUsedBytes() << fi->fsTotalBytes() << fi->displayName() << fi->displayName(); qDebug() << fi->fsFreeBytes() << fi->fsUsedBytes() << fi->fsTotalBytes() << fi->fileType() << fi->displayName();
}
delete f;
}
f = DGioFile::createFromPath("/home/mike/Desktop/1.png");
if (f) {
qDebug() << f->basename() << f->path() << f->uri();
QExplicitlySharedDataPointer<DGioFileInfo> fi = f->createFileInfo();
if (fi) {
qDebug() << fi->fileType() << fi->displayName() << fi->fileSize();
} }
delete f; delete f;
} }