File indexing completed on 2024-09-08 03:44:45
0001 /* 0002 This file is part of Killbots. 0003 0004 SPDX-FileCopyrightText: 2007-2009 Parker Coates <coates@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "ruleset.h" 0010 0011 #include <KConfigGroup> 0012 #include "killbots_debug.h" 0013 0014 #include <QFileInfo> 0015 0016 const Killbots::Ruleset *Killbots::Ruleset::load(const QString &fileName) 0017 { 0018 const Ruleset *result = nullptr; 0019 if (!fileName.isEmpty()) { 0020 QString filePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("killbots/rulesets/") + fileName); 0021 if (!filePath.isEmpty()) { 0022 // Our only check for validity is that we can open the file as a config 0023 // file and that it contains a group named "KillbotsRuleset". 0024 KConfig configFile(filePath, KConfig::SimpleConfig); 0025 if (configFile.hasGroup(QStringLiteral("KillbotsRuleset"))) { 0026 result = new Ruleset(filePath); 0027 } 0028 } 0029 } 0030 if (!result) { 0031 qCDebug(KILLBOTS_LOG) << "Failed to load " << fileName; 0032 } 0033 0034 return result; 0035 } 0036 0037 Killbots::Ruleset::Ruleset(const QString &filePath) 0038 : RulesetBase(KSharedConfig::openConfig(filePath)) 0039 { 0040 m_filePath = filePath; 0041 QString untranslatedName = KConfigGroup(config(), QStringLiteral("KillbotsRuleset")).readEntryUntranslated("Name"); 0042 m_scoreGroupKey = untranslatedName.simplified().remove(QLatin1Char(' ')).toLatin1(); 0043 } 0044 0045 Killbots::Ruleset::~Ruleset() 0046 { 0047 } 0048 0049 QString Killbots::Ruleset::filePath() const 0050 { 0051 return m_filePath; 0052 } 0053 0054 QString Killbots::Ruleset::fileName() const 0055 { 0056 return QFileInfo(m_filePath).fileName(); 0057 } 0058 0059 QByteArray Killbots::Ruleset::scoreGroupKey() const 0060 { 0061 return m_scoreGroupKey; 0062 }