1 | /* |
2 | * Copyright 2007-2009 Parker Coates <coates@kde.org> |
3 | * |
4 | * This file is part of Killbots. |
5 | * |
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. |
10 | * |
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. |
15 | * |
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/>. |
18 | */ |
19 | |
20 | #include "ruleset.h" |
21 | |
22 | #include <KDE/KConfigGroup> |
23 | #include <KDE/KDebug> |
24 | #include <KDE/KStandardDirs> |
25 | |
26 | #include <QtCore/QFileInfo> |
27 | |
28 | const Killbots::Ruleset * Killbots::Ruleset::load( const QString & fileName ) |
29 | { |
30 | const Ruleset * result = 0; |
31 | |
32 | if ( !fileName.isEmpty() ) |
33 | { |
34 | QString filePath = KStandardDirs::locate( "ruleset" , fileName ); |
35 | if ( !filePath.isEmpty() ) |
36 | { |
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 ); |
42 | } |
43 | } |
44 | |
45 | kDebug( !result ) << "Failed to load " << fileName; |
46 | |
47 | return result; |
48 | } |
49 | |
50 | |
51 | Killbots::Ruleset::Ruleset( const QString & filePath ) |
52 | : RulesetBase( filePath ) |
53 | { |
54 | m_filePath = filePath; |
55 | QString untranslatedName = KConfigGroup( config(), "KillbotsRuleset" ).readEntryUntranslated("Name" ); |
56 | m_scoreGroupKey = untranslatedName.simplified().remove(' ').toLatin1(); |
57 | } |
58 | |
59 | |
60 | Killbots::Ruleset::~Ruleset() |
61 | { |
62 | } |
63 | |
64 | |
65 | QString Killbots::Ruleset::filePath() const |
66 | { |
67 | return m_filePath; |
68 | } |
69 | |
70 | |
71 | QString Killbots::Ruleset::fileName() const |
72 | { |
73 | return QFileInfo( m_filePath ).fileName(); |
74 | } |
75 | |
76 | |
77 | QByteArray Killbots::Ruleset::scoreGroupKey() const |
78 | { |
79 | return m_scoreGroupKey; |
80 | } |
81 | |