diff --git a/gio-qt/CMakeLists.txt b/gio-qt/CMakeLists.txt index 208c410..bec0fca 100644 --- a/gio-qt/CMakeLists.txt +++ b/gio-qt/CMakeLists.txt @@ -10,6 +10,7 @@ set (QGIO_PUBLIC_HEADER_FILES dgiovolume.h dgiofile.h dgiofileinfo.h + dgioutils.h ) set (QGIO_PRIVATE_CPP_FILES @@ -19,6 +20,7 @@ set (QGIO_PRIVATE_CPP_FILES dgiovolume.cpp dgiofile.cpp dgiofileinfo.cpp + dgioutils.cpp ) # Library diff --git a/gio-qt/dgiofileinfo.cpp b/gio-qt/dgiofileinfo.cpp index c242fb7..98f1268 100644 --- a/gio-qt/dgiofileinfo.cpp +++ b/gio-qt/dgiofileinfo.cpp @@ -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 { Q_D(const DGioFileInfo); diff --git a/gio-qt/dgiofileinfo.h b/gio-qt/dgiofileinfo.h index b607ff0..9ef6e86 100644 --- a/gio-qt/dgiofileinfo.h +++ b/gio-qt/dgiofileinfo.h @@ -28,6 +28,7 @@ public: ~DGioFileInfo(); // file info + QString displayName() const; DGioFileType fileType() const; // filesystem info. diff --git a/gio-qt/dgioutils.cpp b/gio-qt/dgioutils.cpp new file mode 100644 index 0000000..09e0c76 --- /dev/null +++ b/gio-qt/dgioutils.cpp @@ -0,0 +1,56 @@ +#include "dgioutils.h" + +#include + +#include + +/*! + * \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(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 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()); +} diff --git a/gio-qt/dgioutils.h b/gio-qt/dgioutils.h new file mode 100644 index 0000000..2b37920 --- /dev/null +++ b/gio-qt/dgioutils.h @@ -0,0 +1,28 @@ +#ifndef DGIOUTILS_H +#define DGIOUTILS_H + +#include + +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 diff --git a/qgio-tools/main.cpp b/qgio-tools/main.cpp index fa2ce0b..7f315c6 100644 --- a/qgio-tools/main.cpp +++ b/qgio-tools/main.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -10,6 +11,10 @@ int main(int argc, char * argv[]) { + qDebug() << DGioUtils::systemDataDirs(); + + qDebug() << "----------------------"; + DGioFile * f = DGioFile::createFromPath("/media/wzc/aaaaaaaaaaaaaaaa"); if (f) { qDebug() << f->basename() << f->path() << f->uri();