forked from mirrors/gio-qt
parent
fbe5ddfe93
commit
ce4a9dfb26
@ -10,6 +10,7 @@ set (QGIO_PUBLIC_HEADER_FILES
|
|||||||
dgiovolume.h
|
dgiovolume.h
|
||||||
dgiofile.h
|
dgiofile.h
|
||||||
dgiofileinfo.h
|
dgiofileinfo.h
|
||||||
|
dgioutils.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set (QGIO_PRIVATE_CPP_FILES
|
set (QGIO_PRIVATE_CPP_FILES
|
||||||
@ -19,6 +20,7 @@ set (QGIO_PRIVATE_CPP_FILES
|
|||||||
dgiovolume.cpp
|
dgiovolume.cpp
|
||||||
dgiofile.cpp
|
dgiofile.cpp
|
||||||
dgiofileinfo.cpp
|
dgiofileinfo.cpp
|
||||||
|
dgioutils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Library
|
# Library
|
||||||
|
@ -60,6 +60,28 @@ DGioFileInfo::~DGioFileInfo()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets a display name for a file.
|
||||||
|
*
|
||||||
|
* A display name is guaranteed to be in UTF8 and can thus be displayed in the UI.
|
||||||
|
*
|
||||||
|
* Wrapper of Gio::FileInfo::get_display_name(), internally it returns the
|
||||||
|
* G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute value.
|
||||||
|
*/
|
||||||
|
QString DGioFileInfo::displayName() const
|
||||||
|
{
|
||||||
|
Q_D(const DGioFileInfo);
|
||||||
|
|
||||||
|
return QString::fromStdString(d->getGmmFileInfoInstance()->get_display_name());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief DGioFileInfo::fileType
|
||||||
|
*
|
||||||
|
* Wrapper of Gio::FileInfo::get_file_type(), internally it returns the
|
||||||
|
* G_FILE_ATTRIBUTE_STANDARD_TYPE attribute value.
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
DGioFileType DGioFileInfo::fileType() const
|
DGioFileType DGioFileInfo::fileType() const
|
||||||
{
|
{
|
||||||
Q_D(const DGioFileInfo);
|
Q_D(const DGioFileInfo);
|
||||||
|
@ -28,6 +28,7 @@ public:
|
|||||||
~DGioFileInfo();
|
~DGioFileInfo();
|
||||||
|
|
||||||
// file info
|
// file info
|
||||||
|
QString displayName() const;
|
||||||
DGioFileType fileType() const;
|
DGioFileType fileType() const;
|
||||||
|
|
||||||
// filesystem info.
|
// filesystem info.
|
||||||
|
56
gio-qt/dgioutils.cpp
Normal file
56
gio-qt/dgioutils.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "dgioutils.h"
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include <glibmm/miscutils.h>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Get the full path by directory type.
|
||||||
|
*
|
||||||
|
* Wrapper of Glib::get_user_data_dir(), behavior similar to QStandardPaths::writableLocation(),
|
||||||
|
* but at least it has USER_DIRECTORY_TEMPLATES .
|
||||||
|
*
|
||||||
|
* On UNIX platforms this is determined using the mechanisms described in the
|
||||||
|
* [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
|
||||||
|
*/
|
||||||
|
QString DGioUtils::userSpecialDir(DGioUserDirectory userDirectory)
|
||||||
|
{
|
||||||
|
return QString::fromStdString(Glib::get_user_special_dir(static_cast<Glib::UserDirectory>(userDirectory)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Get an ordered list of base directories in which to access system-wide application data.
|
||||||
|
*
|
||||||
|
* Wrapper of Glib::get_system_data_dirs(), behavior similar (should be the same under UNIX) to
|
||||||
|
* QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).
|
||||||
|
*
|
||||||
|
* On UNIX platforms this is determined using the mechanisms described in the
|
||||||
|
* [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec)
|
||||||
|
* In this case the list of directories retrieved will be XDG_DATA_DIRS.
|
||||||
|
*/
|
||||||
|
QStringList DGioUtils::systemDataDirs()
|
||||||
|
{
|
||||||
|
std::vector<std::string> dirs = Glib::get_system_data_dirs();
|
||||||
|
QStringList lst;
|
||||||
|
|
||||||
|
for (auto dir : dirs) {
|
||||||
|
lst.append(QString::fromStdString(dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
return lst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Get a base directory in which to access application data such as icons that is customized for a particular user.
|
||||||
|
*
|
||||||
|
* Wrapper of Glib::get_user_data_dir(), behavior similar (should be the same under UNIX) to
|
||||||
|
* QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation).
|
||||||
|
*
|
||||||
|
* On UNIX platforms this is determined using the mechanisms described in the
|
||||||
|
* [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec).
|
||||||
|
* In this case the directory retrieved will be `XDG_DATA_HOME`.
|
||||||
|
*/
|
||||||
|
QString DGioUtils::userDataDir()
|
||||||
|
{
|
||||||
|
return QString::fromStdString(Glib::get_user_data_dir());
|
||||||
|
}
|
28
gio-qt/dgioutils.h
Normal file
28
gio-qt/dgioutils.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef DGIOUTILS_H
|
||||||
|
#define DGIOUTILS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
enum DGioUserDirectory
|
||||||
|
{
|
||||||
|
USER_DIRECTORY_DESKTOP,
|
||||||
|
USER_DIRECTORY_DOCUMENTS,
|
||||||
|
USER_DIRECTORY_DOWNLOAD,
|
||||||
|
USER_DIRECTORY_MUSIC,
|
||||||
|
USER_DIRECTORY_PICTURES,
|
||||||
|
USER_DIRECTORY_PUBLIC_SHARE,
|
||||||
|
USER_DIRECTORY_TEMPLATES,
|
||||||
|
USER_DIRECTORY_VIDEOS,
|
||||||
|
USER_N_DIRECTORIES
|
||||||
|
};
|
||||||
|
Q_ENUMS(DGioUserDirectory);
|
||||||
|
|
||||||
|
class DGioUtils
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString userSpecialDir(DGioUserDirectory userDirectory);
|
||||||
|
static QStringList systemDataDirs();
|
||||||
|
static QString userDataDir();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DGIOUTILS_H
|
@ -3,6 +3,7 @@
|
|||||||
#include <QExplicitlySharedDataPointer>
|
#include <QExplicitlySharedDataPointer>
|
||||||
|
|
||||||
#include <dgiofile.h>
|
#include <dgiofile.h>
|
||||||
|
#include <dgioutils.h>
|
||||||
#include <dgiomount.h>
|
#include <dgiomount.h>
|
||||||
#include <dgiovolume.h>
|
#include <dgiovolume.h>
|
||||||
#include <dgiovolumemanager.h>
|
#include <dgiovolumemanager.h>
|
||||||
@ -10,6 +11,10 @@
|
|||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
|
qDebug() << DGioUtils::systemDataDirs();
|
||||||
|
|
||||||
|
qDebug() << "----------------------";
|
||||||
|
|
||||||
DGioFile * f = DGioFile::createFromPath("/media/wzc/aaaaaaaaaaaaaaaa");
|
DGioFile * f = DGioFile::createFromPath("/media/wzc/aaaaaaaaaaaaaaaa");
|
||||||
if (f) {
|
if (f) {
|
||||||
qDebug() << f->basename() << f->path() << f->uri();
|
qDebug() << f->basename() << f->path() << f->uri();
|
||||||
|
Loading…
Reference in New Issue
Block a user