diff --git a/src/main.cpp b/src/main.cpp index 463f8f62f..1492ac842 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,7 +129,8 @@ int main(int argc, char *argv[]) sodium_init(); // For the auto-updater #ifdef LOG_TO_FILE - QString logFileDir = Settings::getInstance().getSettingsDirPath(); + QString logFileDir = Settings::getInstance().getAppCacheDirPath(); + QDir(logFileDir).mkpath("."); logFileStream.reset(new QTextStream); logFileFile.reset(new QFile(logFileDir + "qtox.log")); diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 477e6fed5..3667f11d1 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -553,6 +553,45 @@ QString Settings::getSettingsDirPath() #endif } +QString Settings::getAppDataDirPath() +{ + QMutexLocker locker{&bigLock}; + if (makeToxPortable) + return QString(".")+QDir::separator(); + + // workaround for https://bugreports.qt-project.org/browse/QTBUG-38845 +#ifdef Q_OS_WIN + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator() + + "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox")+QDir::separator(); +#elif defined(Q_OS_OSX) + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator() + + "Library" + QDir::separator() + "Application Support" + QDir::separator() + "Tox")+QDir::separator(); +#else + // TODO: change QStandardPaths::DataLocation to AppDataLocation when upgrate Qt to 5.4+ + // For now we need support Qt 5.3, so we use deprecated DataLocation + // BTW, it's not a big deal since for linux AppDataLocation and DataLocation are equal + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::DataLocation))+QDir::separator(); +#endif +} + +QString Settings::getAppCacheDirPath() +{ + QMutexLocker locker{&bigLock}; + if (makeToxPortable) + return QString(".")+QDir::separator(); + + // workaround for https://bugreports.qt-project.org/browse/QTBUG-38845 +#ifdef Q_OS_WIN + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator() + + "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox")+QDir::separator(); +#elif defined(Q_OS_OSX) + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator() + + "Library" + QDir::separator() + "Application Support" + QDir::separator() + "Tox")+QDir::separator(); +#else + return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))+QDir::separator(); +#endif +} + const QList& Settings::getDhtServerList() const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 69b48888b..2ce8e970e 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -44,6 +44,8 @@ public: static Settings& getInstance(); static void destroyInstance(); QString getSettingsDirPath(); ///< The returned path ends with a directory separator + QString getAppDataDirPath(); ///< The returned path ends with a directory separator + QString getAppCacheDirPath(); ///< The returned path ends with a directory separator void createSettingsDir(); ///< Creates a path to the settings dir, if it doesn't already exist void createPersonal(QString basename); ///< Write a default personal .ini settings file for a profile diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 4fd3fb6fb..2ea304933 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -774,7 +774,7 @@ void ChatForm::doScreenshot() connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken, this, &ChatForm::onScreenshotTaken); screenshotGrabber->showGrabber(); // Create dir for screenshots - QDir(Settings::getInstance().getSettingsDirPath()).mkdir("screenshots"); + QDir(Settings::getInstance().getAppDataDirPath()).mkpath("screenshots"); } void ChatForm::onScreenshotTaken(const QPixmap &pixmap) { @@ -783,7 +783,7 @@ void ChatForm::onScreenshotTaken(const QPixmap &pixmap) { // Windows has to be supported, thus filename can't have `:` in it :/ // Format should be: `qTox_Screenshot_yyyy-MM-dd HH-mm-ss.zzz.png` QString filepath = QString("%1screenshots%2qTox_Screenshot_%3.png") - .arg(Settings::getInstance().getSettingsDirPath()) + .arg(Settings::getInstance().getAppDataDirPath()) .arg(QDir::separator()) .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH-mm-ss.zzz"));