LibCore: Add Music, Pictures and Videos user directory helpers

This commit is contained in:
Bastiaan van der Plaat 2024-01-29 19:18:53 +01:00 committed by Jelle Raaijmakers
parent f4d5ff9ed9
commit c8dc77a552
Notes: sideshowbarker 2024-07-17 03:30:41 +09:00
2 changed files with 49 additions and 0 deletions

View file

@ -36,6 +36,9 @@ ByteString StandardPaths::home_directory()
ByteString StandardPaths::desktop_directory()
{
if (auto* desktop_directory = getenv("XDG_DESKTOP_DIR"))
return LexicalPath::canonicalized_path(desktop_directory);
StringBuilder builder;
builder.append(home_directory());
builder.append("/Desktop"sv);
@ -44,6 +47,9 @@ ByteString StandardPaths::desktop_directory()
ByteString StandardPaths::documents_directory()
{
if (auto* documents_directory = getenv("XDG_DOCUMENTS_DIR"))
return LexicalPath::canonicalized_path(documents_directory);
StringBuilder builder;
builder.append(home_directory());
builder.append("/Documents"sv);
@ -52,12 +58,52 @@ ByteString StandardPaths::documents_directory()
ByteString StandardPaths::downloads_directory()
{
if (auto* downloads_directory = getenv("XDG_DOWNLOAD_DIR"))
return LexicalPath::canonicalized_path(downloads_directory);
StringBuilder builder;
builder.append(home_directory());
builder.append("/Downloads"sv);
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
ByteString StandardPaths::music_directory()
{
if (auto* music_directory = getenv("XDG_MUSIC_DIR"))
return LexicalPath::canonicalized_path(music_directory);
StringBuilder builder;
builder.append(home_directory());
builder.append("/Music"sv);
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
ByteString StandardPaths::pictures_directory()
{
if (auto* pictures_directory = getenv("XDG_PICTURES_DIR"))
return LexicalPath::canonicalized_path(pictures_directory);
StringBuilder builder;
builder.append(home_directory());
builder.append("/Pictures"sv);
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
ByteString StandardPaths::videos_directory()
{
if (auto* videos_directory = getenv("XDG_VIDEOS_DIR"))
return LexicalPath::canonicalized_path(videos_directory);
StringBuilder builder;
builder.append(home_directory());
#if defined(AK_OS_MACOS)
builder.append("/Movies"sv);
#else
builder.append("/Videos"sv);
#endif
return LexicalPath::canonicalized_path(builder.to_byte_string());
}
ByteString StandardPaths::config_directory()
{
if (auto* config_directory = getenv("XDG_CONFIG_HOME"))

View file

@ -18,6 +18,9 @@ public:
static ByteString desktop_directory();
static ByteString documents_directory();
static ByteString downloads_directory();
static ByteString music_directory();
static ByteString pictures_directory();
static ByteString videos_directory();
static ByteString tempfile_directory();
static ByteString config_directory();
static ByteString data_directory();