diff --git a/mere-xdg-lib.pro b/mere-xdg-lib.pro new file mode 100644 index 0000000..9120ad5 --- /dev/null +++ b/mere-xdg-lib.pro @@ -0,0 +1,61 @@ +QT = core + +CONFIG += c++11 +CONFIG += shared + +TARGET = mere-xdg +VERSION= 0.0.1 +TEMPLATE = lib + +DEFINES += LIB_CODE=\\\"xdg\\\" +DEFINES += LIB_NAME=\\\"$$TARGET\\\" +DEFINES += LIB_VERSION=\\\"$$VERSION\\\" +DEFINES += MERE_XDG_LIB + +SOURCES += \ + src/autostartdirectoryspec.cpp \ + src/basedirectoryspec.cpp \ + src/desktopentry.cpp \ + src/desktopentrydirectoryspec.cpp \ + src/desktopentryspec.cpp \ + src/icontheme.cpp \ + src/iconthemedirectoryspec.cpp \ + src/iconthemespec.cpp + +HEADERS += \ + src/autostartdirectoryspec.h \ + src/basedirectoryspec.h \ + src/desktopentry.h \ + src/desktopentrydirectoryspec.h \ + src/desktopentryspec.h \ + src/global.h \ + src/global.h \ + src/icontheme.h \ + src/iconthemedirectoryspec.h \ + src/iconthemespec.h + +INCLUDEPATH += /usr/local/include + +LIBS += -L/usr/local/lib + +LIBS += -lmere-utils + +# +# Install +# +unix { + target.path = /usr/local/lib + INSTALLS += target + + INSTALL_PREFIX = /usr/local/include/mere/xdg + for(header, HEADERS) { + sdir = $${dirname(header)} + sdir = $$replace(sdir, "src", "") + path = $${INSTALL_PREFIX}$${sdir} + + eval(headers_$${path}.files += $$header) + eval(headers_$${path}.path = $$path) + eval(INSTALLS *= headers_$${path}) + } +} + diff --git a/src/autostartdirectoryspec.cpp b/src/autostartdirectoryspec.cpp index 6f209de..228b863 100644 --- a/src/autostartdirectoryspec.cpp +++ b/src/autostartdirectoryspec.cpp @@ -8,39 +8,39 @@ #include #include -std::vector Mere::XDG::AutostartDirectorySpec::autostartDirectories() +std::vector Mere::XDG::AutostartDirectorySpec::directories() { std::vector autostartDirectories; - std::string userConfigHome = BaseDirectorySpec::userConfigDirectory(); + std::string userConfigHome = BaseDirectorySpec::configHome(); Mere::Utils::EnvUtils::expandEnvVar(userConfigHome); if (Mere::Utils::StringUtils::isNotBlank(userConfigHome)) - autostartDirectories.push_back( autostarDirectory(userConfigHome) ); + autostartDirectories.push_back( Mere::XDG::AutostartDirectorySpec::directory(userConfigHome) ); - const std::vector configSearchDirectories = BaseDirectorySpec::configSearchDirectories(); - for (std::string configSearchDirectory : configSearchDirectories) + const std::vector directories = BaseDirectorySpec::configDirectories(); + for (std::string directory : directories) { - Mere::Utils::EnvUtils::expandEnvVar(configSearchDirectory); + Mere::Utils::EnvUtils::expandEnvVar(directory); - if (Mere::Utils::StringUtils::isNotBlank(configSearchDirectory)) - autostartDirectories.push_back( autostarDirectory(configSearchDirectory) ); + if (Mere::Utils::StringUtils::isNotBlank(directory)) + autostartDirectories.push_back( Mere::XDG::AutostartDirectorySpec::directory(directory) ); } return autostartDirectories; } -std::vector Mere::XDG::AutostartDirectorySpec::autostartApplications() +std::vector Mere::XDG::AutostartDirectorySpec::applications() { std::vector desktopEntries ; - std::vector autostartDirectories = AutostartDirectorySpec::autostartDirectories(); + std::vector directories = AutostartDirectorySpec::directories(); - for(const std::string &autostartDirectory : autostartDirectories) + for(const std::string &directory : directories) { - QDir autostartDir(autostartDirectory.c_str()); + QDir dir(directory.c_str()); - QFileInfoList fileInfoList = autostartDir.entryInfoList(QDir::AllEntries); + QFileInfoList fileInfoList = dir.entryInfoList(QDir::AllEntries); QListIterator i(fileInfoList); while (i.hasNext()) { @@ -59,7 +59,7 @@ std::vector Mere::XDG::AutostartDirectorySpec::autostar return desktopEntries; } -std::string Mere::XDG::AutostartDirectorySpec::autostarDirectory(const std::string &path) +std::string Mere::XDG::AutostartDirectorySpec::directory(const std::string &path) { std::string autostartDirectory(path); diff --git a/src/autostartdirectoryspec.h b/src/autostartdirectoryspec.h index ae0ead6..996edc3 100644 --- a/src/autostartdirectoryspec.h +++ b/src/autostartdirectoryspec.h @@ -16,18 +16,18 @@ class MERE_XDG_LIB_SPEC AutostartDirectorySpec AutostartDirectorySpec() = default; public: /** - * @brief autostartDirectories + * @brief directories * - * Directories when system will search for 'Desktop Entry' files, and will be + * Directories where system will search for 'Desktop Entry' files, and will be * automatically launched during startup of the user's desktop environment after the user has logged in. * * @return */ - static std::vector autostartDirectories(); - static std::vector autostartApplications(); + static std::vector directories(); + static std::vector applications(); private: - static std::string autostarDirectory(const std::string &path); + static std::string directory(const std::string &path); }; } diff --git a/src/basedirectoryspec.cpp b/src/basedirectoryspec.cpp index 476ac6f..f6e7703 100644 --- a/src/basedirectoryspec.cpp +++ b/src/basedirectoryspec.cpp @@ -19,8 +19,10 @@ unsigned int Mere::XDG::BaseDirectorySpec::setupEnv() { int result = 0; + result += setupDesktopEnv(); result += setupDataHomeEnv(); result += setupConfigHomeEnv(); + result += setupIconHomeEnv(); result += setupDataDirsEnv(); result += setupConfigDirsEnv(); result += setupCacheHomeEnv(); @@ -34,7 +36,7 @@ unsigned int Mere::XDG::BaseDirectorySpec::setupEnvVar(const char* env, const ch std::string str(value); Mere::Utils::EnvUtils::expandEnvVar(str); - int result = setenv(env, value, 1); + int result = setenv(env, str.c_str(), 1); if (result != 0) return err; if (!std::ifstream(str).good()) @@ -56,12 +58,17 @@ unsigned int Mere::XDG::BaseDirectorySpec::setupDesktopEnv() unsigned int Mere::XDG::BaseDirectorySpec::setupDataHomeEnv() { - return BaseDirectorySpec::setupEnvVar(XDG::DATA_HOME, XDG::BaseDirectory::DATA_HOME, XDG::ErrorMask::DATA_HOME); + return setupEnvVar(XDG::DATA_HOME, XDG::BaseDirectory::DATA_HOME, XDG::ErrorMask::DATA_HOME); } unsigned int Mere::XDG::BaseDirectorySpec::setupConfigHomeEnv() { - return BaseDirectorySpec::setupEnvVar(XDG::CONFIG_HOME, XDG::BaseDirectory::CONFIG_HOME, XDG::ErrorMask::CONFIG_HOME); + return setupEnvVar(XDG::CONFIG_HOME, XDG::BaseDirectory::CONFIG_HOME, XDG::ErrorMask::CONFIG_HOME); +} + +unsigned int Mere::XDG::BaseDirectorySpec::setupIconHomeEnv() +{ + return setupEnvVar(XDG::ICON_HOME, XDG::BaseDirectory::ICON_HOME, XDG::ErrorMask::ICON_HOME); } unsigned int Mere::XDG::BaseDirectorySpec::setupDataDirsEnv() @@ -71,7 +78,6 @@ unsigned int Mere::XDG::BaseDirectorySpec::setupDataDirsEnv() std::string dataDirs(getenv(XDG::DATA_DIRS)); - // FIXME?? CHECK THIS if (!std::ifstream(dataDirs).good()) QDir().mkpath(dataDirs.c_str()); @@ -98,7 +104,7 @@ unsigned int Mere::XDG::BaseDirectorySpec::setupRuntimeDirEnv() return BaseDirectorySpec::setupEnvVar(XDG::RUNTIME_DIR, XDG::BaseDirectory::RUNTIME_DIR, XDG::ErrorMask::RUNTIME_DIR); } -std::string Mere::XDG::BaseDirectorySpec::userDataDirectory() +std::string Mere::XDG::BaseDirectorySpec::dataHome() { const char *home = getenv(XDG::DATA_HOME); @@ -112,7 +118,7 @@ std::string Mere::XDG::BaseDirectorySpec::userDataDirectory() return dataHome; } -std::string Mere::XDG::BaseDirectorySpec::userConfigDirectory() +std::string Mere::XDG::BaseDirectorySpec::configHome() { const char *home = getenv(XDG::CONFIG_HOME); @@ -126,7 +132,7 @@ std::string Mere::XDG::BaseDirectorySpec::userConfigDirectory() return configHome; } -std::string Mere::XDG::BaseDirectorySpec::userCacheDirectory() +std::string Mere::XDG::BaseDirectorySpec::cacheHome() { const char *home = getenv(XDG::CACHE_HOME); @@ -140,7 +146,21 @@ std::string Mere::XDG::BaseDirectorySpec::userCacheDirectory() return cacheHome; } -std::vector Mere::XDG::BaseDirectorySpec::dataSearchDirectories() +std::string Mere::XDG::BaseDirectorySpec::iconHome() +{ + const char *home = getenv(XDG::ICON_HOME); + + std::string iconHome( home ? home : XDG::BaseDirectory::ICON_HOME); + + Mere::Utils::EnvUtils::expandEnvVar(iconHome); + + if (!std::ifstream(iconHome).good()) + QDir().mkpath(iconHome.c_str()); + + return iconHome; +} + +std::vector Mere::XDG::BaseDirectorySpec::dataDirectories() { std::vector dirs; @@ -162,7 +182,7 @@ std::vector Mere::XDG::BaseDirectorySpec::dataSearchDirectories() return dirs; } -std::vector Mere::XDG::BaseDirectorySpec::configSearchDirectories() +std::vector Mere::XDG::BaseDirectorySpec::configDirectories() { std::vector dirs; diff --git a/src/basedirectoryspec.h b/src/basedirectoryspec.h index 0021570..98d844e 100644 --- a/src/basedirectoryspec.h +++ b/src/basedirectoryspec.h @@ -10,7 +10,6 @@ namespace Mere { namespace XDG { - static const char* SESSION_DESKTOP = "XDG_SESSION_DESKTOP"; static const char* CURRENT_DESKTOP = "XDG_CURRENT_DESKTOP"; @@ -26,8 +25,8 @@ namespace XDG namespace BaseDirectory { - static const char* SESSION_DESKTOP = "Mere"; - static const char* CURRENT_DESKTOP = "Mere"; + static const char* SESSION_DESKTOP = "mere"; + static const char* CURRENT_DESKTOP = "mere"; static const char* DATA_HOME = "$HOME/.local/share"; static const char* CONFIG_HOME = "$HOME/.config"; @@ -35,8 +34,11 @@ namespace XDG static const char* ICON_HOME = "$HOME/.icons"; static const char* DATA_DIRS = "/usr/local/share/:/usr/share/"; - static const char* CONFIG_DIRS = "/etc/xdg"; + // we made a bit change here; added /usr/local/etc/xdg + static const char* CONFIG_DIRS = "/usr/local/etc/xdg/:/etc/xdg/"; + + // where did we find this one, in which spec? static const char* RUNTIME_DIR = "/tmp/mere-$USER"; } @@ -66,9 +68,13 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec * Setup environments variables specified in XDG base directory specification. * - XDG_DATA_HOME * - XDG_CONFIG_HOME + * - XDG_CACHE_HOME * - XDG_DATA_DIRS * - XDG_CONFIG_DIRS - * - XDG_CONFIG_DIRS + * + * - XDG_ICON_HOME + * - XDG_SESSION_DESKTOP + * - XDG_CURRENT_DESKTOP * - XDG_RUNTIME_DIR * @return */ @@ -84,7 +90,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec * * @return */ - static std::string userDataDirectory(); + static std::string dataHome(); /** * @brief userConfigDirectory @@ -96,7 +102,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec * * @return */ - static std::string userConfigDirectory(); + static std::string configHome(); /** * @brief userCacheDirectory @@ -108,7 +114,11 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec * * @return */ - static std::string userCacheDirectory(); + static std::string cacheHome(); + + + // we did we get it? + static std::string iconHome(); /** * @brief dataSearchDirectories @@ -123,7 +133,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec * * @return */ - static std::vector dataSearchDirectories(); + static std::vector dataDirectories(); /** * @brief configSearchDirectories @@ -137,7 +147,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec * If $XDG_CONFIG_DIRS is either not set or empty, a value equal to /etc/xdg should be used. * @return */ - static std::vector configSearchDirectories(); + static std::vector configDirectories(); private: static unsigned int setupDesktopEnv(); @@ -158,6 +168,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec static unsigned int setupDataDirsEnv(); static unsigned int setupConfigDirsEnv(); static unsigned int setupCacheHomeEnv(); + static unsigned int setupIconHomeEnv(); static unsigned int setupRuntimeDirEnv(); static unsigned int setupEnvVar(const char *env, const char *value, unsigned int err); @@ -166,5 +177,4 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec } } - #endif // MERE_XDG_DIRECTORYSPEC_H diff --git a/src/desktopentry.cpp b/src/desktopentry.cpp index 3b20e94..b17640e 100644 --- a/src/desktopentry.cpp +++ b/src/desktopentry.cpp @@ -1,20 +1,5 @@ #include "desktopentry.h" -Mere::XDG::DesktopEntry::~DesktopEntry() -{ - -} - -Mere::XDG::DesktopEntry::DesktopEntry() -{ - -} - -Mere::XDG::DesktopEntry::DesktopEntry(const std::string &path) -{ - Q_UNUSED(path); -} - QVariant Mere::XDG::DesktopEntry::get(const Attribute &attribute) { auto find = m_attributes.find(attribute); diff --git a/src/desktopentry.h b/src/desktopentry.h index 48bbddf..84861a8 100644 --- a/src/desktopentry.h +++ b/src/desktopentry.h @@ -14,10 +14,7 @@ namespace XDG class MERE_XDG_LIB_SPEC DesktopEntry { public: - ~DesktopEntry(); - DesktopEntry(); - - explicit DesktopEntry(const std::string &path); + DesktopEntry() = default; enum Attribute { diff --git a/src/desktopentrydirectoryspec.cpp b/src/desktopentrydirectoryspec.cpp index af2effd..3671669 100644 --- a/src/desktopentrydirectoryspec.cpp +++ b/src/desktopentrydirectoryspec.cpp @@ -5,29 +5,29 @@ #include "mere/utils/stringutils.h" //static -std::vector Mere::XDG::DesktopEntryDirectorySpec::applicationDirectories() +std::vector Mere::XDG::DesktopEntryDirectorySpec::directories() { std::vector applicationDirectories; - std::string userDatHome = Mere::XDG::BaseDirectorySpec::userDataDirectory(); + std::string userDatHome = Mere::XDG::BaseDirectorySpec::dataHome(); Mere::Utils::EnvUtils::expandEnvVar(userDatHome); if (Mere::Utils::StringUtils::isNotBlank(userDatHome)) - applicationDirectories.push_back(applicationDirectory(userDatHome)); + applicationDirectories.push_back(directory(userDatHome)); - const std::vector dataSearchDirectories = BaseDirectorySpec::dataSearchDirectories(); + const std::vector dataSearchDirectories = BaseDirectorySpec::dataDirectories(); for(std::string dataSearchDirectory : dataSearchDirectories) { Mere::Utils::EnvUtils::expandEnvVar(dataSearchDirectory); if (Mere::Utils::StringUtils::isNotBlank(dataSearchDirectory)) - applicationDirectories.push_back(applicationDirectory(dataSearchDirectory)); + applicationDirectories.push_back(directory(dataSearchDirectory)); } return applicationDirectories; } //static -std::string Mere::XDG::DesktopEntryDirectorySpec::applicationDirectory(const std::string &path) +std::string Mere::XDG::DesktopEntryDirectorySpec::directory(const std::string &path) { std::string applicationDirectory(path); diff --git a/src/desktopentrydirectoryspec.h b/src/desktopentrydirectoryspec.h index fb4d662..46334f2 100644 --- a/src/desktopentrydirectoryspec.h +++ b/src/desktopentrydirectoryspec.h @@ -21,8 +21,8 @@ class MERE_XDG_LIB_SPEC DesktopEntryDirectorySpec * * @return */ - static std::vector applicationDirectories(); - static std::string applicationDirectory(const std::string &path); + static std::vector directories(); + static std::string directory(const std::string &path); }; } } diff --git a/src/iconthemedirectoryspec.cpp b/src/iconthemedirectoryspec.cpp index 0bcc26c..3679434 100644 --- a/src/iconthemedirectoryspec.cpp +++ b/src/iconthemedirectoryspec.cpp @@ -20,13 +20,13 @@ std::vector Mere::XDG::IconThemeDirectorySpec::baseDirectories() iconDirectories.push_back(userIconHome); // Not in specification - std::string userDataDirectory = BaseDirectorySpec::userDataDirectory(); + std::string userDataDirectory = BaseDirectorySpec::dataHome(); Mere::Utils::EnvUtils::expandEnvVar(userDataDirectory); if (Mere::Utils::StringUtils::isNotBlank(userDataDirectory)) iconDirectories.push_back(iconDirectory(userDataDirectory)); - const std::vector dataSearchDirectories = BaseDirectorySpec::dataSearchDirectories(); + const std::vector dataSearchDirectories = BaseDirectorySpec::dataDirectories(); for(std::string dataSearchDirectory : dataSearchDirectories) { Mere::Utils::EnvUtils::expandEnvVar(dataSearchDirectory); diff --git a/src/iconthemespec.cpp b/src/iconthemespec.cpp index 3f27191..f71abc4 100644 --- a/src/iconthemespec.cpp +++ b/src/iconthemespec.cpp @@ -9,16 +9,6 @@ #include #include -Mere::XDG::IconThemeSpec::~IconThemeSpec() -{ - -} - -Mere::XDG::IconThemeSpec::IconThemeSpec() -{ - -} - //static std::string Mere::XDG::IconThemeSpec::path(const std::string &icon) { diff --git a/src/iconthemespec.h b/src/iconthemespec.h index f05b6cb..611a4e1 100644 --- a/src/iconthemespec.h +++ b/src/iconthemespec.h @@ -22,9 +22,8 @@ typedef struct class MERE_XDG_LIB_SPEC IconThemeSpec { + IconThemeSpec() = default; public: - ~IconThemeSpec(); - explicit IconThemeSpec(); static std::string path(const std::string &icon); static std::string path(const std::string &icon, unsigned int size); static std::string path(const std::string &icon, unsigned int size, unsigned int scale);