Skip to content

Commit

Permalink
Merge pull request #4 from merelabs/muddy
Browse files Browse the repository at this point in the history
Muddy
  • Loading branch information
bmin authored Feb 19, 2021
2 parents a5145fc + cce4121 commit 823de4f
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 80 deletions.
61 changes: 61 additions & 0 deletions mere-xdg-lib.pro
Original file line number Diff line number Diff line change
@@ -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})
}
}

28 changes: 14 additions & 14 deletions src/autostartdirectoryspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
#include <QDir>
#include <QDirIterator>

std::vector<std::string> Mere::XDG::AutostartDirectorySpec::autostartDirectories()
std::vector<std::string> Mere::XDG::AutostartDirectorySpec::directories()
{
std::vector<std::string> 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<std::string> configSearchDirectories = BaseDirectorySpec::configSearchDirectories();
for (std::string configSearchDirectory : configSearchDirectories)
const std::vector<std::string> 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::DesktopEntry> Mere::XDG::AutostartDirectorySpec::autostartApplications()
std::vector<Mere::XDG::DesktopEntry> Mere::XDG::AutostartDirectorySpec::applications()
{
std::vector<DesktopEntry> desktopEntries ;

std::vector<std::string> autostartDirectories = AutostartDirectorySpec::autostartDirectories();
std::vector<std::string> 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<QFileInfo> i(fileInfoList);
while (i.hasNext())
{
Expand All @@ -59,7 +59,7 @@ std::vector<Mere::XDG::DesktopEntry> 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);

Expand Down
10 changes: 5 additions & 5 deletions src/autostartdirectoryspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> autostartDirectories();
static std::vector<DesktopEntry> autostartApplications();
static std::vector<std::string> directories();
static std::vector<DesktopEntry> applications();

private:
static std::string autostarDirectory(const std::string &path);
static std::string directory(const std::string &path);
};

}
Expand Down
38 changes: 29 additions & 9 deletions src/basedirectoryspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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())
Expand All @@ -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()
Expand All @@ -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());

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -140,7 +146,21 @@ std::string Mere::XDG::BaseDirectorySpec::userCacheDirectory()
return cacheHome;
}

std::vector<std::string> 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<std::string> Mere::XDG::BaseDirectorySpec::dataDirectories()
{
std::vector<std::string> dirs;

Expand All @@ -162,7 +182,7 @@ std::vector<std::string> Mere::XDG::BaseDirectorySpec::dataSearchDirectories()
return dirs;
}

std::vector<std::string> Mere::XDG::BaseDirectorySpec::configSearchDirectories()
std::vector<std::string> Mere::XDG::BaseDirectorySpec::configDirectories()
{
std::vector<std::string> dirs;

Expand Down
32 changes: 21 additions & 11 deletions src/basedirectoryspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Mere
{
namespace XDG
{

static const char* SESSION_DESKTOP = "XDG_SESSION_DESKTOP";
static const char* CURRENT_DESKTOP = "XDG_CURRENT_DESKTOP";

Expand All @@ -26,17 +25,20 @@ 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";
static const char* CACHE_HOME = "$HOME/.cache";
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";
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -84,7 +90,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec
*
* @return
*/
static std::string userDataDirectory();
static std::string dataHome();

/**
* @brief userConfigDirectory
Expand All @@ -96,7 +102,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec
*
* @return
*/
static std::string userConfigDirectory();
static std::string configHome();

/**
* @brief userCacheDirectory
Expand All @@ -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
Expand All @@ -123,7 +133,7 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec
*
* @return
*/
static std::vector<std::string> dataSearchDirectories();
static std::vector<std::string> dataDirectories();

/**
* @brief configSearchDirectories
Expand All @@ -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<std::string> configSearchDirectories();
static std::vector<std::string> configDirectories();

private:
static unsigned int setupDesktopEnv();
Expand All @@ -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);
Expand All @@ -166,5 +177,4 @@ class MERE_XDG_LIB_SPEC BaseDirectorySpec
}
}


#endif // MERE_XDG_DIRECTORYSPEC_H
15 changes: 0 additions & 15 deletions src/desktopentry.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/desktopentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit 823de4f

Please sign in to comment.