diff --git a/src/plugins/lua/bindings/qt.cpp b/src/plugins/lua/bindings/qt.cpp index fc929a84531..8b8cef7301a 100644 --- a/src/plugins/lua/bindings/qt.cpp +++ b/src/plugins/lua/bindings/qt.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace Lua::Internal { @@ -128,6 +129,34 @@ void setupQtModule() "ExeOther", QFileDevice::ExeOther ) ); + + qt["QStandardPaths"] = lua.create_table_with( + "StandardLocation", lua.create_table_with( + "DesktopLocation", QStandardPaths::DesktopLocation, + "DocumentsLocation", QStandardPaths::DocumentsLocation, + "FontsLocation", QStandardPaths::FontsLocation, + "ApplicationsLocation", QStandardPaths::ApplicationsLocation, + "MusicLocation", QStandardPaths::MusicLocation, + "MoviesLocation", QStandardPaths::MoviesLocation, + "PicturesLocation", QStandardPaths::PicturesLocation, + "TempLocation", QStandardPaths::TempLocation, + "HomeLocation", QStandardPaths::HomeLocation, + "AppLocalDataLocation", QStandardPaths::AppLocalDataLocation, + "CacheLocation", QStandardPaths::CacheLocation, + "GenericDataLocation", QStandardPaths::GenericDataLocation, + "RuntimeLocation", QStandardPaths::RuntimeLocation, + "ConfigLocation", QStandardPaths::ConfigLocation, + "DownloadLocation", QStandardPaths::DownloadLocation, + "GenericCacheLocation", QStandardPaths::GenericCacheLocation, + "GenericConfigLocation", QStandardPaths::GenericConfigLocation, + "AppDataLocation", QStandardPaths::AppDataLocation, + "AppConfigLocation", QStandardPaths::AppConfigLocation, + "PublicShareLocation", QStandardPaths::PublicShareLocation, + "TemplatesLocation", QStandardPaths::TemplatesLocation, + "StateLocation", QStandardPaths::StateLocation, + "GenericStateLocation", QStandardPaths::GenericStateLocation + ) + ); // clang-format on return qt; diff --git a/src/plugins/lua/bindings/utils.cpp b/src/plugins/lua/bindings/utils.cpp index dcea1688070..0937950dcc0 100644 --- a/src/plugins/lua/bindings/utils.cpp +++ b/src/plugins/lua/bindings/utils.cpp @@ -182,6 +182,34 @@ void setupUtilsModule() utils["FilePath"]["searchInPath_cb"] = utils["__searchInPath_cb__"]; utils["FilePath"]["searchInPath"] = wrap(utils["__searchInPath_cb__"]); + utils["standardLocations"] = [](QStandardPaths::StandardLocation location) { + const auto locationsStrings = QStandardPaths::standardLocations( + static_cast(location)); + + QList locationsPaths; + std::transform(locationsStrings.constBegin(), locationsStrings.constEnd(), + std::back_inserter(locationsPaths), &FilePath::fromString); + return locationsPaths; + }; + utils["standardLocation"] = + [](QStandardPaths::StandardLocation location) -> sol::optional { + const auto paths = QStandardPaths::standardLocations( + static_cast(location)); + if (paths.isEmpty()) + return sol::nullopt; + + return FilePath::fromString(paths.first()); + }; + utils["writableLocation"] = + [](QStandardPaths::StandardLocation location) -> sol::optional { + const auto path = QStandardPaths::writableLocation( + static_cast(location)); + if (path.isEmpty()) + return sol::nullopt; + + return FilePath::fromString(path); + }; + utils.new_usertype( "CommandLine", sol::call_constructor, diff --git a/src/plugins/lua/meta/qt.lua b/src/plugins/lua/meta/qt.lua index 3588dcf6038..0c819164c46 100644 --- a/src/plugins/lua/meta/qt.lua +++ b/src/plugins/lua/meta/qt.lua @@ -110,4 +110,33 @@ qt.QFileDevice = { } } +qt.QStandardPaths = { + ---@enum StandardLocation + StandardLocation = { + DesktopLocation = 0, + DocumentsLocation = 0, + FontsLocation = 0, + ApplicationsLocation = 0, + MusicLocation = 0, + MoviesLocation = 0, + PicturesLocation = 0, + TempLocation = 0, + HomeLocation = 0, + AppLocalDataLocation = 0, + CacheLocation = 0, + GenericDataLocation = 0, + RuntimeLocation = 0, + ConfigLocation = 0, + DownloadLocation = 0, + GenericCacheLocation = 0, + GenericConfigLocation = 0, + AppDataLocation = 0, + AppConfigLocation = 0, + PublicShareLocation = 0, + TemplatesLocation = 0, + StateLocation = 0, + GenericStateLocation = 0, + } +} + return qt diff --git a/src/plugins/lua/meta/utils.lua b/src/plugins/lua/meta/utils.lua index fe0fd376689..9e526370710 100644 --- a/src/plugins/lua/meta/utils.lua +++ b/src/plugins/lua/meta/utils.lua @@ -100,6 +100,21 @@ function utils.FilePath:permissions() end ---@param permissions Permission The complete OR-ed together combination of permissions for the file. function utils.FilePath:setPermissions() end +---Returns the list of paths for the given standard location. +---@param location StandardLocation The standard location to get paths for. +---@return [FilePath] The list of paths for the given standard location. +function utils.standardLocations(location) end + +---Returns the first available paths for the given standard location. +---@param location StandardLocation The standard location to get the path for. +---@return FilePath|nil The first available paths for the given standard location or nil if no location is available. +function utils.standardLocation(location) end + +---Returns the writable paths for the given standard location. +---@param location StandardLocation The standard location to get path for. +---@return FilePath|nil The writable paths for the given standard location or nil if no writable location is available. +function utils.writableLocation(location) end + ---@class CommandLine ---@field command FilePath The command to execute. ---@field arguments string[] The arguments to pass to the command.