00001
00002
00003
00004 #include "settings.h"
00005
00006 #include <kglobal.h>
00007 #include <QtCore/QFile>
00008
00009 class SettingsHelper
00010 {
00011 public:
00012 SettingsHelper() : q(0) {}
00013 ~SettingsHelper() { delete q; }
00014 Settings *q;
00015 };
00016 K_GLOBAL_STATIC(SettingsHelper, s_globalSettings)
00017 Settings *Settings::self()
00018 {
00019 if (!s_globalSettings->q) {
00020 new Settings;
00021 s_globalSettings->q->readConfig();
00022 }
00023
00024 return s_globalSettings->q;
00025 }
00026
00027 Settings::Settings( )
00028 : KConfigSkeleton( QLatin1String( "ksquaresrc" ) )
00029 {
00030 Q_ASSERT(!s_globalSettings->q);
00031 s_globalSettings->q = this;
00032 setCurrentGroup( QLatin1String( "Game Settings" ) );
00033
00034 KConfigSkeleton::ItemInt *itemNumOfPlayers;
00035 itemNumOfPlayers = new KConfigSkeleton::ItemInt( currentGroup(), QLatin1String( "NumOfPlayers" ), mNumOfPlayers, 2 );
00036 addItem( itemNumOfPlayers, QLatin1String( "NumOfPlayers" ) );
00037 KConfigSkeleton::ItemStringList *itemPlayerNames;
00038 itemPlayerNames = new KConfigSkeleton::ItemStringList( currentGroup(), QLatin1String( "PlayerNames" ), mPlayerNames );
00039 addItem( itemPlayerNames, QLatin1String( "PlayerNames" ) );
00040 QList<int> defaultHumanList;
00041 defaultHumanList.append( 2 );
00042 defaultHumanList.append( 2 );
00043 defaultHumanList.append( 2 );
00044 defaultHumanList.append( 2 );
00045
00046 KConfigSkeleton::ItemIntList *itemHumanList;
00047 itemHumanList = new KConfigSkeleton::ItemIntList( currentGroup(), QLatin1String( "HumanList" ), mHumanList, defaultHumanList );
00048 addItem( itemHumanList, QLatin1String( "HumanList" ) );
00049 KConfigSkeleton::ItemInt *itemBoardWidth;
00050 itemBoardWidth = new KConfigSkeleton::ItemInt( currentGroup(), QLatin1String( "BoardWidth" ), mBoardWidth, 10 );
00051 addItem( itemBoardWidth, QLatin1String( "BoardWidth" ) );
00052 KConfigSkeleton::ItemInt *itemBoardHeight;
00053 itemBoardHeight = new KConfigSkeleton::ItemInt( currentGroup(), QLatin1String( "BoardHeight" ), mBoardHeight, 7 );
00054 addItem( itemBoardHeight, QLatin1String( "BoardHeight" ) );
00055 KConfigSkeleton::ItemInt *itemQuickStart;
00056 itemQuickStart = new KConfigSkeleton::ItemInt( currentGroup(), QLatin1String( "QuickStart" ), mQuickStart, 0 );
00057 addItem( itemQuickStart, QLatin1String( "QuickStart" ) );
00058
00059 setCurrentGroup( QLatin1String( "AI" ) );
00060
00061 KConfigSkeleton::ItemInt *itemDifficulty;
00062 itemDifficulty = new KConfigSkeleton::ItemInt( currentGroup(), QLatin1String( "Difficulty" ), mDifficulty, 0 );
00063 addItem( itemDifficulty, QLatin1String( "Difficulty" ) );
00064
00065 setCurrentGroup( QLatin1String( "Display" ) );
00066
00067 KConfigSkeleton::ItemColor *itemLineColor;
00068 itemLineColor = new KConfigSkeleton::ItemColor( currentGroup(), QLatin1String( "LineColor" ), mLineColor, QColor( 0,0,0 ) );
00069 addItem( itemLineColor, QLatin1String( "LineColor" ) );
00070 KConfigSkeleton::ItemColor *itemIndicatorLineColor;
00071 itemIndicatorLineColor = new KConfigSkeleton::ItemColor( currentGroup(), QLatin1String( "IndicatorLineColor" ), mIndicatorLineColor, QColor( 255,255,0 ) );
00072 addItem( itemIndicatorLineColor, QLatin1String( "IndicatorLineColor" ) );
00073 KConfigSkeleton::ItemColor *itemHighlightColor;
00074 itemHighlightColor = new KConfigSkeleton::ItemColor( currentGroup(), QLatin1String( "HighlightColor" ), mHighlightColor, QColor( 220,100,100 ) );
00075 addItem( itemHighlightColor, QLatin1String( "HighlightColor" ) );
00076 }
00077
00078 Settings::~Settings()
00079 {
00080 }
00081