File indexing completed on 2024-03-24 04:51:51
0001 /* 0002 * SPDX-FileCopyrightText: 2021 George Florea Bănuș <georgefb899@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "global.h" 0008 0009 #include <QFileInfo> 0010 0011 Global *Global::instance() 0012 { 0013 static Global g; 0014 return &g; 0015 } 0016 0017 Global::Global() 0018 : m_config(KSharedConfig::openConfig(u"haruna/haruna.conf"_qs, KConfig::SimpleConfig, QStandardPaths::GenericConfigLocation)) 0019 , m_ccConfig(KSharedConfig::openConfig(u"haruna/custom-commands.conf"_qs, KConfig::SimpleConfig, QStandardPaths::GenericConfigLocation)) 0020 , m_rfConfig(KSharedConfig::openConfig(u"haruna/recent-files.conf"_qs, KConfig::SimpleConfig, QStandardPaths::GenericDataLocation)) 0021 , m_shortcutsConfig(KSharedConfig::openConfig(u"haruna/shortcuts.conf"_qs, KConfig::SimpleConfig, QStandardPaths::GenericConfigLocation)) 0022 { 0023 } 0024 0025 const QString Global::appConfigDirPath() 0026 { 0027 auto path = QStandardPaths::writableLocation(m_config->locationType()).append(u"/haruna"_qs); 0028 QFileInfo configFolder(path); 0029 if (configFolder.exists()) { 0030 return configFolder.absoluteFilePath(); 0031 } 0032 return QString(); 0033 } 0034 0035 const QString Global::appConfigFilePath(ConfigFile configFile) 0036 { 0037 switch (configFile) { 0038 case ConfigFile::Main: { 0039 auto path = QStandardPaths::writableLocation(m_config->locationType()).append(u"/"_qs); 0040 return path.append(m_config->name()); 0041 } 0042 case ConfigFile::CustomCommands: { 0043 auto path = QStandardPaths::writableLocation(m_ccConfig->locationType()).append(u"/"_qs); 0044 return path.append(m_ccConfig->name()); 0045 } 0046 case ConfigFile::RecentFiles: { 0047 auto path = QStandardPaths::writableLocation(m_rfConfig->locationType()).append(u"/"_qs); 0048 return path.append(m_rfConfig->name()); 0049 } 0050 case ConfigFile::Shortcuts: { 0051 auto path = QStandardPaths::writableLocation(m_shortcutsConfig->locationType()).append(u"/"_qs); 0052 return path.append(m_shortcutsConfig->name()); 0053 } 0054 default: 0055 return QString(); 0056 } 0057 } 0058 0059 #include "moc_global.cpp"