diff --git a/src/persistence/paths.cpp b/src/persistence/paths.cpp index d8b9a5053..33f71547d 100644 --- a/src/persistence/paths.cpp +++ b/src/persistence/paths.cpp @@ -11,6 +11,7 @@ namespace { const QLatin1Literal globalSettingsFile{"qtox.ini"}; +const QLatin1Literal logFile{"qtox.log"}; const QLatin1Literal profileFolder{"profiles"}; const QLatin1Literal themeFolder{"themes"}; const QLatin1Literal avatarsFolder{"avatars"}; @@ -134,6 +135,29 @@ QString Paths::getGlobalSettingsPath() const return path % QDir::separator() % globalSettingsFile; } +/** + * @brief Returns the path to the log file "qtox.log" + * @return The path to the folder. + */ +QString Paths::getLogFilePath() const +{ + QString path; + + if (portable) { + path = basePath; + } else { + path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + if (path.isEmpty()) { + qDebug() << "Can't find writable location for log file"; + return {}; + } + } + + // we assume a writeable path for portable mode + + return path % QDir::separator() % logFile; +} + /** * @brief Get the folder where profile specific information is stored, e.g. .ini * @return The path to the folder. diff --git a/src/persistence/paths.h b/src/persistence/paths.h index d666dcb4b..091e73973 100644 --- a/src/persistence/paths.h +++ b/src/persistence/paths.h @@ -17,6 +17,7 @@ public: bool isPortable() const; QString getGlobalSettingsPath() const; + QString getLogFilePath() const; QString getProfilesDir() const; QString getToxSaveDir() const; QString getAvatarsDir() const; diff --git a/test/persistence/paths_test.cpp b/test/persistence/paths_test.cpp index ef560ea8c..428cb6f34 100644 --- a/test/persistence/paths_test.cpp +++ b/test/persistence/paths_test.cpp @@ -41,6 +41,7 @@ private: namespace { const QLatin1Literal globalSettingsFile{"qtox.ini"}; +const QLatin1Literal logFile{"qtox.log"}; const QLatin1Literal profileFolder{"profiles"}; const QLatin1Literal themeFolder{"themes"}; const QLatin1Literal avatarsFolder{"avatars"}; @@ -112,10 +113,11 @@ void TestPaths::checkPathsNonPortable() const QString appData{QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)}; const QString appConfig{QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)}; - + const QString cache{QStandardPaths::writableLocation(QStandardPaths::CacheLocation)}; verifyqToxPath(paths->getProfilesDir(), appData, profileFolder % sep); verifyqToxPath(paths->getGlobalSettingsPath(), appConfig, globalSettingsFile); + verifyqToxPath(paths->getLogFilePath(), cache, logFile); verifyqToxPath(paths->getScreenshotsDir(), appData, screenshotsFolder % sep); verifyqToxPath(paths->getTransfersDir(), appData, transfersFolder % sep); @@ -153,6 +155,7 @@ void TestPaths::checkPathsPortable() verifyqToxPath(paths->getProfilesDir(), basePath, profileFolder % sep); verifyqToxPath(paths->getGlobalSettingsPath(), basePath, globalSettingsFile); + verifyqToxPath(paths->getLogFilePath(), basePath, logFile); verifyqToxPath(paths->getScreenshotsDir(), basePath, screenshotsFolder % sep); verifyqToxPath(paths->getTransfersDir(), basePath, transfersFolder % sep);