forked from mirrors/gio-qt
parent
ce4a9dfb26
commit
31087054fa
12 changed files with 223 additions and 4 deletions
|
@ -11,6 +11,7 @@ set (QGIO_PUBLIC_HEADER_FILES
|
|||
dgiofile.h
|
||||
dgiofileinfo.h
|
||||
dgioutils.h
|
||||
dgiofileiterator.h
|
||||
)
|
||||
|
||||
set (QGIO_PRIVATE_CPP_FILES
|
||||
|
@ -21,6 +22,7 @@ set (QGIO_PRIVATE_CPP_FILES
|
|||
dgiofile.cpp
|
||||
dgiofileinfo.cpp
|
||||
dgioutils.cpp
|
||||
dgiofileiterator.cpp
|
||||
)
|
||||
|
||||
# Library
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#include "dgiofile.h"
|
||||
#include "dgiofileinfo.h"
|
||||
#include "dgiofileiterator.h"
|
||||
|
||||
#include <glibmm/refptr.h>
|
||||
|
||||
#include <giomm/init.h>
|
||||
#include <giomm/file.h>
|
||||
#include <giomm/fileenumerator.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -122,6 +124,13 @@ QString DGioFile::uri() const
|
|||
return d->uri();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Obtains information about the filesystem the file is on.
|
||||
*
|
||||
* Wrapper of Gio::File::query_filesystem_info("filesystem::*").
|
||||
*
|
||||
* \return the created file system info object, or nullptr if create failed.
|
||||
*/
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> DGioFile::createFileSystemInfo()
|
||||
{
|
||||
Q_D(DGioFile);
|
||||
|
@ -138,3 +147,37 @@ QExplicitlySharedDataPointer<DGioFileInfo> DGioFile::createFileSystemInfo()
|
|||
|
||||
return QExplicitlySharedDataPointer<DGioFileInfo>(nullptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the requested information about the files in a directory.
|
||||
*
|
||||
* Wrapper of Gio::File::enumerate_children()
|
||||
*
|
||||
* The attribute value is a string that specifies the file attributes that should be gathered.
|
||||
* It is not an error if its not possible to read a particular requested attribute from a file,
|
||||
* it just won't be set. attribute should be a comma-separated list of attribute or attribute
|
||||
* wildcards. The wildcard "*" means all attributes, and a wildcard like "standard::*" means all
|
||||
* attributes in the standard namespace. An example attribute query be "standard::*,owner::user".
|
||||
* The standard attributes are available as defines, like FILE_ATTRIBUTE_STANDARD_NAME.
|
||||
*
|
||||
* \param attr An attribute query string.
|
||||
* \param queryInfoFlags
|
||||
* \return the created DGioFileIterator object, or nullptr if failed.
|
||||
*/
|
||||
QExplicitlySharedDataPointer<DGioFileIterator> DGioFile::createFileIterator(QString attr, DGioFileQueryInfoFlags queryInfoFlags)
|
||||
{
|
||||
Q_D(DGioFile);
|
||||
|
||||
try {
|
||||
unsigned int flagValue = queryInfoFlags;
|
||||
FileQueryInfoFlags flags = static_cast<FileQueryInfoFlags>(flagValue);
|
||||
Glib::RefPtr<FileEnumerator> gmmFileEnumerator = d->getGmmFileInstance()->enumerate_children(attr.toStdString(), flags);
|
||||
QExplicitlySharedDataPointer<DGioFileIterator> fileIterPtr(new DGioFileIterator(gmmFileEnumerator.release()));
|
||||
|
||||
return fileIterPtr;
|
||||
} catch (const Glib::Error &error) {
|
||||
qDebug() << QString::fromStdString(error.what().raw());
|
||||
}
|
||||
|
||||
return QExplicitlySharedDataPointer<DGioFileIterator>(nullptr);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,16 @@ namespace Gio {
|
|||
class File;
|
||||
}
|
||||
|
||||
enum DGioFileQueryInfoFlag
|
||||
{
|
||||
FILE_QUERY_INFO_NONE = 0x0,
|
||||
FILE_QUERY_INFO_NOFOLLOW_SYMLINKS = (1 << 0)
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(DGioFileQueryInfoFlags, DGioFileQueryInfoFlag)
|
||||
|
||||
class DGioFileInfo;
|
||||
class DGioFileIterator;
|
||||
class DGioFilePrivate;
|
||||
class DGioFile : public QObject, public QSharedData
|
||||
{
|
||||
|
@ -24,6 +33,7 @@ public:
|
|||
QString path() const;
|
||||
QString uri() const;
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> createFileSystemInfo();
|
||||
QExplicitlySharedDataPointer<DGioFileIterator> createFileIterator(QString attr, DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE);
|
||||
|
||||
private:
|
||||
QScopedPointer<DGioFilePrivate> d_ptr;
|
||||
|
|
|
@ -13,6 +13,7 @@ public:
|
|||
|
||||
bool getAttributeBoolean(const std::string &attribute) const;
|
||||
quint64 getAttributeUint64(const std::string &attribute) const;
|
||||
QString getAttributeString(const std::string &attribute) const;
|
||||
|
||||
private:
|
||||
Glib::RefPtr<FileInfo> m_gmmFileInfoPtr;
|
||||
|
@ -46,6 +47,11 @@ quint64 DGioFileInfoPrivate::getAttributeUint64(const std::string &attribute) co
|
|||
return m_gmmFileInfoPtr->get_attribute_uint64(attribute);
|
||||
}
|
||||
|
||||
QString DGioFileInfoPrivate::getAttributeString(const std::string &attribute) const
|
||||
{
|
||||
return QString::fromStdString(m_gmmFileInfoPtr->get_attribute_string(attribute));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
DGioFileInfo::DGioFileInfo(FileInfo *gmmFileInfoInfoPtr, QObject *parent)
|
||||
|
|
72
gio-qt/dgiofileiterator.cpp
Normal file
72
gio-qt/dgiofileiterator.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "dgiofileiterator.h"
|
||||
#include "dgiofileinfo.h"
|
||||
|
||||
#include <glibmm/refptr.h>
|
||||
|
||||
#include <giomm/init.h>
|
||||
#include <giomm/file.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Gio;
|
||||
|
||||
class DGioFileIteratorPrivate
|
||||
{
|
||||
public:
|
||||
DGioFileIteratorPrivate(DGioFileIterator *qq, FileEnumerator *gmmFileEnumeratorPtr);
|
||||
|
||||
Glib::RefPtr<FileEnumerator> getGmmFileEnumeratorInstance() const;
|
||||
|
||||
private:
|
||||
Glib::RefPtr<FileEnumerator> m_gmmFileEnumeratorPtr;
|
||||
|
||||
DGioFileIterator *q_ptr;
|
||||
|
||||
Q_DECLARE_PUBLIC(DGioFileIterator)
|
||||
};
|
||||
|
||||
DGioFileIteratorPrivate::DGioFileIteratorPrivate(DGioFileIterator *qq, FileEnumerator *gmmFileEnumeratorPtr)
|
||||
: m_gmmFileEnumeratorPtr(gmmFileEnumeratorPtr)
|
||||
, q_ptr(qq)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Glib::RefPtr<FileEnumerator> DGioFileIteratorPrivate::getGmmFileEnumeratorInstance() const
|
||||
{
|
||||
return m_gmmFileEnumeratorPtr;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
DGioFileIterator::DGioFileIterator(FileEnumerator* gmmFileEnumeratorPtr, QObject *parent)
|
||||
: QObject(parent)
|
||||
, d_ptr(new DGioFileIteratorPrivate(this, gmmFileEnumeratorPtr))
|
||||
{
|
||||
// gmmFileEnumeratorPtr must be valid;
|
||||
Q_CHECK_PTR(gmmFileEnumeratorPtr);
|
||||
}
|
||||
|
||||
DGioFileIterator::~DGioFileIterator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> DGioFileIterator::next()
|
||||
{
|
||||
Q_D(DGioFileIterator);
|
||||
|
||||
try {
|
||||
// can return nullptr if there is no file left.
|
||||
Glib::RefPtr<FileInfo> gmmFileInfoPtr = d->getGmmFileEnumeratorInstance()->next_file();
|
||||
if (gmmFileInfoPtr) {
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> fileInfo(new DGioFileInfo(gmmFileInfoPtr.release()));
|
||||
return fileInfo;
|
||||
}
|
||||
} catch (const Glib::Error &error) {
|
||||
qDebug() << QString::fromStdString(error.what().raw());
|
||||
}
|
||||
|
||||
return QExplicitlySharedDataPointer<DGioFileInfo>(nullptr);
|
||||
}
|
28
gio-qt/dgiofileiterator.h
Normal file
28
gio-qt/dgiofileiterator.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef DGIOFILEITERATOR_H
|
||||
#define DGIOFILEITERATOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSharedData>
|
||||
|
||||
namespace Gio {
|
||||
class FileEnumerator;
|
||||
}
|
||||
|
||||
class DGioFileInfo;
|
||||
class DGioFileIteratorPrivate;
|
||||
class DGioFileIterator : public QObject, public QSharedData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DGioFileIterator(Gio::FileEnumerator *gmmFileEnumeratorPtr, QObject *parent = nullptr);
|
||||
~DGioFileIterator();
|
||||
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> next();
|
||||
|
||||
private:
|
||||
QScopedPointer<DGioFileIteratorPrivate> d_ptr;
|
||||
|
||||
Q_DECLARE_PRIVATE(DGioFileIterator)
|
||||
};
|
||||
|
||||
#endif // DGIOFILEITERATOR_H
|
|
@ -192,6 +192,31 @@ QStringList DGioMount::themedIconNames() const
|
|||
return iconNames;
|
||||
}
|
||||
|
||||
QStringList DGioMount::themedSymbolicIconNames() const
|
||||
{
|
||||
Q_D(const DGioMount);
|
||||
|
||||
QStringList iconNames;
|
||||
|
||||
Glib::RefPtr<const Icon> icon = d->getGmmMountInstance()->get_symbolic_icon();
|
||||
Glib::RefPtr<const ThemedIcon> themedIcon = Glib::RefPtr<const ThemedIcon>::cast_dynamic(icon);
|
||||
|
||||
if (themedIcon) {
|
||||
QStringList iconNames;
|
||||
char **names;
|
||||
char **iter;
|
||||
names = NULL;
|
||||
g_object_get(G_THEMED_ICON(themedIcon->gobj()), "names", &names, NULL);
|
||||
for (iter = names; *iter; iter++) {
|
||||
iconNames.append(QString(*iter));
|
||||
}
|
||||
g_strfreev(names);
|
||||
return iconNames;
|
||||
}
|
||||
|
||||
return iconNames;
|
||||
}
|
||||
|
||||
void DGioMount::unmount(bool forceUnmount)
|
||||
{
|
||||
Q_D(const DGioMount);
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
bool canUnmount() const;
|
||||
bool canEject() const;
|
||||
QStringList themedIconNames() const;
|
||||
QStringList themedSymbolicIconNames() const;
|
||||
|
||||
void unmount(bool forceUnmount = false);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ void DGioMountOperationPrivate::slot_askPassword(const Glib::ustring &message, c
|
|||
QString msg = QString::fromStdString(message.raw());
|
||||
QString defaultUser = QString::fromStdString(default_user.raw());
|
||||
QString defaultDomain = QString::fromStdString(default_domain.raw());
|
||||
DGioAskPasswordFlags askPasswordFlags = static_cast<DGioAskPasswordFlags>(flags);
|
||||
DGioAskPasswordFlags askPasswordFlags(static_cast<DGioAskPasswordFlag>(flags));
|
||||
|
||||
Q_EMIT q->askPassword(msg, defaultUser, defaultDomain, askPasswordFlags);
|
||||
}
|
||||
|
|
|
@ -54,3 +54,19 @@ QString DGioUtils::userDataDir()
|
|||
{
|
||||
return QString::fromStdString(Glib::get_user_data_dir());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the directory to use for temporary files.
|
||||
*
|
||||
* Wrapper of Glib::get_user_data_dir(), behavior similar (but not the same) to QDir::temp() or
|
||||
* QStandardPaths::writableLocation(QStandardPaths::TempLocation).
|
||||
*
|
||||
* This is found from inspecting the environment variables TMPDIR, TMP, and TEMP in that order. If none of those are defined
|
||||
* "/tmp" is returned on UNIX and "C:\\" on Windows.
|
||||
*
|
||||
* \return The directory to use for temporary files.
|
||||
*/
|
||||
QString DGioUtils::tmpDir()
|
||||
{
|
||||
return QString::fromStdString(Glib::get_tmp_dir());
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
static QString userSpecialDir(DGioUserDirectory userDirectory);
|
||||
static QStringList systemDataDirs();
|
||||
static QString userDataDir();
|
||||
static QString tmpDir();
|
||||
};
|
||||
|
||||
#endif // DGIOUTILS_H
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <dgiovolume.h>
|
||||
#include <dgiovolumemanager.h>
|
||||
#include <dgiofileinfo.h>
|
||||
#include <dgiofileiterator.h>
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
|
@ -15,19 +16,33 @@ int main(int argc, char * argv[])
|
|||
|
||||
qDebug() << "----------------------";
|
||||
|
||||
DGioFile * f = DGioFile::createFromPath("/media/wzc/aaaaaaaaaaaaaaaa");
|
||||
DGioFile *networkFile = DGioFile::createFromUri("network:///");
|
||||
if (networkFile) {
|
||||
QExplicitlySharedDataPointer<DGioFileIterator> iter = networkFile->createFileIterator("standard::*,mountable::can-mount");
|
||||
if (iter) {
|
||||
while (QExplicitlySharedDataPointer<DGioFileInfo> fi = iter->next()) {
|
||||
if (fi) {
|
||||
qDebug() << fi->displayName() << fi->fileType();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "----------------------";
|
||||
|
||||
DGioFile * f = DGioFile::createFromPath("/media/wzc/_dde_data");
|
||||
if (f) {
|
||||
qDebug() << f->basename() << f->path() << f->uri();
|
||||
QExplicitlySharedDataPointer<DGioFileInfo> fi = f->createFileSystemInfo();
|
||||
if (fi) {
|
||||
qDebug() << fi->fsFreeBytes() << fi->fsUsedBytes() << fi->fsTotalBytes();
|
||||
qDebug() << fi->fsFreeBytes() << fi->fsUsedBytes() << fi->fsTotalBytes() << fi->displayName() << fi->displayName();
|
||||
}
|
||||
delete f;
|
||||
}
|
||||
|
||||
qDebug() << "----------------------";
|
||||
|
||||
DGioMount * m = DGioMount::createFromPath("/media/wzc/aaaaaaaaaaaaaaaa");
|
||||
DGioMount * m = DGioMount::createFromPath("/media/wzc/_dde_data");
|
||||
if (m) {
|
||||
QExplicitlySharedDataPointer<DGioFile> f = m->getRootFile();
|
||||
QExplicitlySharedDataPointer<DGioFile> f2 = m->getDefaultLocationFile();
|
||||
|
|
Loading…
Reference in a new issue