Utils: Add commonly used paths to AppInfo

Change-Id: Icfd7e549a1589aff13bfacfe6abd85e7e780b3c0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-07-25 10:26:33 +02:00
parent c325777477
commit 01b2938043
3 changed files with 57 additions and 2 deletions

View File

@@ -522,6 +522,38 @@ private:
ShowInGuiHandler *ShowInGuiHandler::instance = nullptr;
FilePath userPluginsRoot()
{
FilePath rootPath = FilePath::fromUserInput(
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
rootPath /= "data";
rootPath /= Core::Constants::IDE_SETTINGSVARIANT_STR;
rootPath /= QLatin1StringView(
HostOsInfo::isMacHost() ? Core::Constants::IDE_DISPLAY_NAME : Core::Constants::IDE_ID);
rootPath /= "plugins";
rootPath /= Core::Constants::IDE_VERSION_LONG;
return rootPath;
}
FilePath userResourcePath(const QString &settingsPath, const QString &appId)
{
const FilePath configDir = FilePath::fromUserInput(settingsPath).parentDir();
const FilePath urp = configDir / appId;
if (!urp.exists()) {
if (!urp.createDir())
qWarning() << "could not create" << urp;
}
return urp;
}
int main(int argc, char **argv)
{
Restarter restarter(argc, argv);
@@ -723,6 +755,14 @@ int main(int argc, char **argv)
info.revision = Constants::IDE_REVISION_STR;
info.revisionUrl = Constants::IDE_REVISION_URL;
info.userFileExtension = Constants::IDE_PROJECT_USER_FILE_EXTENSION;
const FilePath appDirPath = FilePath::fromUserInput(QApplication::applicationDirPath());
info.plugins = (appDirPath / RELATIVE_PLUGIN_PATH).cleanPath();
info.userPluginsRoot = userPluginsRoot();
info.resources = (appDirPath / RELATIVE_DATA_PATH).cleanPath();
info.userResources = userResourcePath(settings->fileName(), Constants::IDE_ID);
Utils::Internal::setAppInfo(info);
QTranslator translator;

View File

@@ -7,7 +7,7 @@ Q_GLOBAL_STATIC(Utils::AppInfo, sAppInfo)
namespace Utils {
Utils::AppInfo appInfo()
const Utils::AppInfo &appInfo()
{
return *sAppInfo;
}

View File

@@ -5,6 +5,8 @@
#include "utils_global.h"
#include "filepath.h"
#include <QString>
namespace Utils {
@@ -19,9 +21,22 @@ public:
QString revision;
QString revisionUrl;
QString userFileExtension;
FilePath plugins;
/*! Local plugin path: <localappdata>/plugins
where <localappdata> is e.g.
"%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later
"$XDG_DATA_HOME/data/QtProject/qtcreator" or "~/.local/share/data/QtProject/qtcreator" on Linux
"~/Library/Application Support/QtProject/Qt Creator" on Mac
*/
FilePath userPluginsRoot;
FilePath resources;
FilePath userResources;
};
QTCREATOR_UTILS_EXPORT AppInfo appInfo();
QTCREATOR_UTILS_EXPORT const AppInfo &appInfo();
namespace Internal {
QTCREATOR_UTILS_EXPORT void setAppInfo(const AppInfo &info);