1 | /* |
2 | * Copyright 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 "rulesetdetailsdialog.h" |
21 | |
22 | #include "ruleset.h" |
23 | |
24 | #include <KDE/KLocale> |
25 | |
26 | #include <QtGui/QFormLayout> |
27 | #include <QtGui/QLabel> |
28 | #include <QtGui/QScrollArea> |
29 | |
30 | Killbots::RulesetDetailsDialog::RulesetDetailsDialog( QWidget * parent ) |
31 | : KDialog( parent ) |
32 | { |
33 | setButtons( KDialog::Close ); |
34 | } |
35 | |
36 | |
37 | void Killbots::RulesetDetailsDialog::loadRuleset( const Ruleset * ruleset ) |
38 | { |
39 | static QStringList maskedItems = QStringList() << "Name" << "Author" << "AuthorContact" << "Description" ; |
40 | static QStringList junkheapEnumText = QStringList() |
41 | << i18nc("Quantity of junkheaps that can be pushed" , "None" ) |
42 | << i18nc("Quantity of junkheaps that can be pushed" , "One" ) |
43 | << i18nc("Quantity of junkheaps that can be pushed" , "Many" ); |
44 | |
45 | |
46 | // If the dialog hasn't been setup already, do so. |
47 | if ( m_labels.size() == 0 ) |
48 | { |
49 | QWidget * widget = new QWidget(); |
50 | QFormLayout * layout = new QFormLayout( widget ); |
51 | |
52 | foreach ( const KConfigSkeletonItem * item, ruleset->items() ) |
53 | { |
54 | if ( !maskedItems.contains( item->name() ) ) |
55 | { |
56 | QString labelText = item->label().isEmpty() ? item->name() : item->label(); |
57 | labelText = i18nc( "%1 is a pretranslated string that we're turning into a label" , "%1:" , labelText ); |
58 | |
59 | QLabel * valueLabel = new QLabel(); |
60 | m_labels[ item->name() ] = valueLabel; |
61 | layout->addRow( new QLabel( labelText ), valueLabel ); |
62 | } |
63 | } |
64 | |
65 | setMainWidget( widget ); |
66 | } |
67 | |
68 | QMap<QString,QLabel*>::const_iterator it = m_labels.constBegin(); |
69 | QMap<QString,QLabel*>::const_iterator end = m_labels.constEnd(); |
70 | for ( ; it != end; it++ ) |
71 | { |
72 | const KConfigSkeletonItem * item = ruleset->findItem( it.key() ); |
73 | |
74 | QString valueText; |
75 | if ( dynamic_cast<const KCoreConfigSkeleton::ItemBool *>( item ) ) |
76 | valueText = item->property().toBool() ? i18n("Yes" ) : i18n("No" ); |
77 | else if ( it.key() == "PushableJunkheaps" ) |
78 | valueText = junkheapEnumText.at( item->property().toInt() ); |
79 | else |
80 | valueText = item->property().toString(); |
81 | |
82 | it.value()->setText( valueText ); |
83 | } |
84 | |
85 | setCaption( i18n("Details of %1 Game Type" , ruleset->name() ) ); |
86 | } |
87 | |
88 | |
89 | |
90 | |