File indexing completed on 2024-10-06 10:24:24
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "managerdatapaths.h" 0008 #include "ruqola_debug.h" 0009 #include <QStandardPaths> 0010 0011 ManagerDataPaths::ManagerDataPaths() 0012 { 0013 initializePaths(); 0014 } 0015 0016 ManagerDataPaths *ManagerDataPaths::self() 0017 { 0018 static ManagerDataPaths s_self; 0019 return &s_self; 0020 } 0021 0022 QString ManagerDataPaths::accountAvatarConfigPath(const QString &accountName) const 0023 { 0024 const QString accountPath = accountConfigPath(accountName) + QStringLiteral("/avatar.conf"); 0025 return accountPath; 0026 } 0027 0028 QString ManagerDataPaths::accountConfigPath(const QString &accountName) const 0029 { 0030 const QString accountPath = path(ManagerDataPaths::PathType::Config, accountName); 0031 return accountPath; 0032 } 0033 0034 QString ManagerDataPaths::accountConfigFileName(const QString &accountName) const 0035 { 0036 const QString accountPath = accountConfigPath(accountName) + QStringLiteral("/ruqola.conf"); 0037 return accountPath; 0038 } 0039 0040 QString ManagerDataPaths::path(ManagerDataPaths::PathType type, const QString &accountName, const QString &subdirectory) const 0041 { 0042 QString path = mPathTypeHash.value(type); 0043 Q_ASSERT(!path.isEmpty()); 0044 if (!accountName.isEmpty()) { 0045 path += QLatin1Char('/') + accountName; 0046 } 0047 switch (type) { 0048 case Picture: 0049 case Video: 0050 path += QStringLiteral("/Ruqola/recordings"); 0051 break; 0052 case PreviewUrl: 0053 path += QStringLiteral("/PreviewUrl"); 0054 case Config: 0055 case Cache: 0056 break; 0057 } 0058 if (!subdirectory.isEmpty()) { 0059 path += QLatin1Char('/') + subdirectory; 0060 } 0061 return path; 0062 } 0063 0064 void ManagerDataPaths::initializePaths() 0065 { 0066 mPathTypeHash.insert(PathType::Config, QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); 0067 mPathTypeHash.insert(PathType::Cache, QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); 0068 mPathTypeHash.insert(PathType::Video, QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); 0069 mPathTypeHash.insert(PathType::Picture, QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); 0070 mPathTypeHash.insert(PathType::PreviewUrl, QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); 0071 qCDebug(RUQOLA_LOG) << "mPathTypeHash:" << mPathTypeHash; 0072 }