forked from mirrors/gio-qt
feat: interfaces for fileinfo
This commit is contained in:
parent
72fe073e31
commit
c1e47429f1
3 changed files with 50 additions and 4 deletions
|
@ -51,6 +51,8 @@ public:
|
||||||
QString displayName() const;
|
QString displayName() const;
|
||||||
DGioFileType fileType() const;
|
DGioFileType fileType() const;
|
||||||
quint64 fileSize() const;
|
quint64 fileSize() const;
|
||||||
|
QString contentType() const;
|
||||||
|
QString iconString() const;
|
||||||
QStringList themedIconNames() const;
|
QStringList themedIconNames() const;
|
||||||
|
|
||||||
// filesystem info.
|
// filesystem info.
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
|
|
||||||
Glib::RefPtr<FileInfo> getGmmFileInfoInstance() const;
|
Glib::RefPtr<FileInfo> getGmmFileInfoInstance() const;
|
||||||
|
|
||||||
|
Glib::RefPtr<const Icon> icon() const;
|
||||||
bool getAttributeBoolean(const std::string &attribute) const;
|
bool getAttributeBoolean(const std::string &attribute) const;
|
||||||
quint64 getAttributeUint64(const std::string &attribute) const;
|
quint64 getAttributeUint64(const std::string &attribute) const;
|
||||||
QString getAttributeString(const std::string &attribute) const;
|
QString getAttributeString(const std::string &attribute) const;
|
||||||
|
@ -58,6 +59,11 @@ Glib::RefPtr<FileInfo> DGioFileInfoPrivate::getGmmFileInfoInstance() const
|
||||||
return m_gmmFileInfoPtr;
|
return m_gmmFileInfoPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Glib::RefPtr<const Icon> DGioFileInfoPrivate::icon() const
|
||||||
|
{
|
||||||
|
return getGmmFileInfoInstance()->get_icon();
|
||||||
|
}
|
||||||
|
|
||||||
bool DGioFileInfoPrivate::getAttributeBoolean(const std::string &attribute) const
|
bool DGioFileInfoPrivate::getAttributeBoolean(const std::string &attribute) const
|
||||||
{
|
{
|
||||||
return m_gmmFileInfoPtr->get_attribute_boolean(attribute);
|
return m_gmmFileInfoPtr->get_attribute_boolean(attribute);
|
||||||
|
@ -118,8 +124,10 @@ DGioFileType DGioFileInfo::fileType() const
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief DGioFileInfo::fileSize
|
* \brief DGioFileInfo::fileSize
|
||||||
|
*
|
||||||
* Wrapper of Gio::FileInfo::get_size()
|
* Wrapper of Gio::FileInfo::get_size()
|
||||||
* \return
|
*
|
||||||
|
* \return the file size in bytes.
|
||||||
*/
|
*/
|
||||||
quint64 DGioFileInfo::fileSize() const
|
quint64 DGioFileInfo::fileSize() const
|
||||||
{
|
{
|
||||||
|
@ -128,13 +136,48 @@ quint64 DGioFileInfo::fileSize() const
|
||||||
return static_cast<quint64>(d->getGmmFileInfoInstance()->get_size());
|
return static_cast<quint64>(d->getGmmFileInfoInstance()->get_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief get the file content type (MimeType).
|
||||||
|
*
|
||||||
|
* Wrapper of Gio::FileInfo::get_content_type()
|
||||||
|
*
|
||||||
|
* \return a single MimeType of the file, such as "text/plain".
|
||||||
|
*/
|
||||||
|
QString DGioFileInfo::contentType() const
|
||||||
|
{
|
||||||
|
Q_D(const DGioFileInfo);
|
||||||
|
|
||||||
|
return QString::fromStdString(d->getGmmFileInfoInstance()->get_content_type());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief DGioFileInfo::iconString
|
||||||
|
*
|
||||||
|
* Wrapper of Gio::FileInfo::get_icon() and then Gio::Icon::to_string().
|
||||||
|
*
|
||||||
|
* Notice the returned value can be in two different form:
|
||||||
|
*
|
||||||
|
* - a native path (such as "/path/to/my icon.png") without escaping if the file for icon is a native
|
||||||
|
* file. If the file is not native, the returned string is the result of g_file_get_uri()
|
||||||
|
* (such as "sftp://path/to/my%20icon.png").
|
||||||
|
*
|
||||||
|
* - a icon name if icon is a ThemedIcon with exactly one name, the encoding is simply the name (such as
|
||||||
|
* network-server), or a list of theme names (such as ". GThemedIcon text-plain text-x-generic text-plain-symbolic").
|
||||||
|
*
|
||||||
|
* \return the icon string as discribed above.
|
||||||
|
*/
|
||||||
|
QString DGioFileInfo::iconString() const
|
||||||
|
{
|
||||||
|
Q_D(const DGioFileInfo);
|
||||||
|
|
||||||
|
return QString::fromStdString(d->icon()->to_string());
|
||||||
|
}
|
||||||
|
|
||||||
QStringList DGioFileInfo::themedIconNames() const
|
QStringList DGioFileInfo::themedIconNames() const
|
||||||
{
|
{
|
||||||
Q_D(const DGioFileInfo);
|
Q_D(const DGioFileInfo);
|
||||||
|
|
||||||
Glib::RefPtr<const Icon> icon = d->getGmmFileInfoInstance()->get_icon();
|
return DGioPrivate::getThemedIconNames(d->icon());
|
||||||
|
|
||||||
return DGioPrivate::getThemedIconNames(icon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DGioFileInfo::fsReadOnly() const
|
bool DGioFileInfo::fsReadOnly() const
|
||||||
|
|
|
@ -31,6 +31,7 @@ void DGioSimpleFileInfoTest::testCase_RegularFile()
|
||||||
QCOMPARE(file->basename(), tmpFileInfo.fileName());
|
QCOMPARE(file->basename(), tmpFileInfo.fileName());
|
||||||
QCOMPARE(file->path(), tmpFileInfo.absoluteFilePath());
|
QCOMPARE(file->path(), tmpFileInfo.absoluteFilePath());
|
||||||
QCOMPARE(fi->fileSize(), tmpFileInfo.size());
|
QCOMPARE(fi->fileSize(), tmpFileInfo.size());
|
||||||
|
qDebug() << fi->iconString() << fi->contentType();
|
||||||
QVERIFY(fi->themedIconNames().contains("text-plain")); // is this check okay? better approach?
|
QVERIFY(fi->themedIconNames().contains("text-plain")); // is this check okay? better approach?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue