2 * Copyright 2007-2009 Parker Coates <parker.coates@gmail.com>
4 * This file is part of Killbots.
6 * Killbots is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * Killbots is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Killbots. If not, see <http://www.gnu.org/licenses/>.
22 #include <KDE/KConfigGroup>
24 #include <KDE/KStandardDirs>
26 #include <QtCore/QFileInfo>
28 Killbots::Ruleset
* Killbots::Ruleset::load( const QString
& fileName
)
32 if ( !fileName
.isEmpty() )
34 QString filePath
= KStandardDirs::locate( "ruleset", fileName
);
35 if ( !filePath
.isEmpty() )
37 // Our only check for validity is that we can open the file as a config
38 // file and that it contains a group named "KillbotsRuleset".
39 KConfig
configFile( filePath
, KConfig::SimpleConfig
);
40 if ( configFile
.hasGroup("KillbotsRuleset") )
41 result
= new Ruleset( filePath
);
46 kDebug() << "Failed to load " << fileName
;
52 Killbots::Ruleset
* Killbots::Ruleset::loadDefault()
54 return load("default.desktop");
58 Killbots::Ruleset::Ruleset( const QString
& filePath
)
59 : RulesetBase( filePath
)
61 m_filePath
= filePath
;
62 QString untranslatedName
= KConfigGroup( config(), "KillbotsRuleset").readEntryUntranslated("Name");
63 m_scoreGroupKey
= untranslatedName
.simplified().remove(' ').toLatin1();
67 Killbots::Ruleset::~Ruleset()
72 QString
Killbots::Ruleset::filePath() const
78 QString
Killbots::Ruleset::fileName() const
80 return QFileInfo( m_filePath
).fileName();
84 QByteArray
Killbots::Ruleset::scoreGroupKey() const
86 return m_scoreGroupKey
;