Commit 550d6076 authored by patrick pereira's avatar patrick pereira 🏃
Browse files

Add utils namespace


Signed-off-by: patrick pereira's avatarPatrick José Pereira <patrickelectric@gmail.com>
parent c6b7bdba
add_subdirectory(utils)
add_subdirectory(interfaces)
add_subdirectory(plugins)
add_subdirectory(app)
set(minuetutils_LIB_SRCS
xdgdatadirs.cpp
)
add_library(minuetutils
STATIC
${minuetutils_LIB_SRCS}
)
add_library(Minuet::Utils ALIAS minuetutils)
target_link_libraries(minuetutils
PRIVATE
Qt5::Core
)
#include <QDir>
#include <QFile>
#include "xdgdatadirs.h"
using namespace Utils;
QStringList Utils::getXdgDataDirs() {
const QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
if (xdgDataDirsEnv.isEmpty()) {
return {};
}
QStringList results;
const auto paths = xdgDataDirsEnv.splitRef(QLatin1Char(':'), QString::SkipEmptyParts);
// Normalize paths, skip relative paths
for (const auto &path : paths) {
if (!QDir::isAbsolutePath(path.toString()) || !QDir(path.toString()).exists()) {
continue;
}
results.append(path.toString());
}
return results;
}
#ifndef MINUET_UTILS_XDGDATADIRS
#define MINUET_UTILS_XDGDATADIRS
#include <QString>
namespace Utils {
/**
* @brief Get valid paths from XDG_DATA_DIRS environment variable
* Qt does not check XDG_DATA_DIRS for MACOS but KDE prefix.sh script sets it.
* If AppDataLocation fail, we should give a shot and check XDG env variable
*
* @return QStringList
*/
QStringList getXdgDataDirs();
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment