00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <kdebug.h>
00025 #include <klocale.h>
00026
00027
00028 #include "config_two.h"
00029
00030
00031
00032 ConfigTwo::ConfigTwo(QObject* parent)
00033 : QObject(parent)
00034 {
00035
00036 mPlayers.clear();
00037 mPlayers[0] = new Player(0, this);
00038 mPlayers[1] = new Player(1, this);
00039 }
00040
00041
00042
00043 void ConfigTwo::reset()
00044 {
00045 mPlayers[0]->setName(i18nc("Default player name", "Alice"));
00046 mPlayers[1]->setName(i18nc("Default player name","Bob"));
00047
00048
00049 setInputType(0, TypeMouseInput);
00050 setInputType(1, TypeAiInput);
00051 }
00052
00053
00054
00055 ConfigTwo::~ConfigTwo()
00056 {
00057 QHashIterator<int,Player*> it(mPlayers);
00058 while(it.hasNext())
00059 {
00060 it.next();
00061 Player* player = it.value();
00062 delete player;
00063 }
00064 mPlayers.clear();
00065 }
00066
00067
00068
00069 void ConfigTwo::save(KConfig *cfg)
00070 {
00071 KConfigGroup group = cfg->group("LSkatData");
00072 group.writeEntry("input0", (int)mInputTypes[0]);
00073 group.writeEntry("input1", (int)mInputTypes[1]);
00074
00075
00076 QHashIterator<int,Player*> it = playerIterator();
00077 while(it.hasNext())
00078 {
00079 it.next();
00080 Player* player = it.value();
00081 int no = it.key();
00082 KConfigGroup playercfg = cfg->group(QString("LSkat_Player%1").arg(no));
00083 player->save(playercfg);
00084 }
00085 }
00086
00087
00088
00089 void ConfigTwo::load(KConfig* cfg)
00090 {
00091 reset();
00092 KConfigGroup group = cfg->group("LSkatData");
00093 int num;
00094 num = group.readEntry("input0", (int)mInputTypes[0]);
00095 setInputType(0, (InputDeviceType)num);
00096 num = group.readEntry("input1", (int)mInputTypes[1]);
00097 setInputType(1, (InputDeviceType)num);
00098
00099
00100 QHashIterator<int,Player*> it = playerIterator();
00101 while(it.hasNext())
00102 {
00103 it.next();
00104 Player* player = it.value();
00105 int no = it.key();
00106 KConfigGroup playercfg = cfg->group(QString("LSkat_Player%1").arg(no));
00107 player->load(playercfg);
00108 }
00109 }
00110
00111
00112
00113 Player* ConfigTwo::player(int no)
00114 {
00115 if (!mPlayers.contains(no)) return 0;
00116 return mPlayers[no];
00117 }
00118
00119
00120
00121 QHashIterator<int,Player*> ConfigTwo::playerIterator()
00122 {
00123 QHashIterator<int,Player*> it(mPlayers);
00124 return it;
00125 }
00126
00127
00128
00129 InputDeviceType ConfigTwo::inputType(int no)
00130 {
00131 return mInputTypes[no];
00132 }
00133
00134
00135
00136 void ConfigTwo::setInputType(int no, InputDeviceType type)
00137 {
00138 mInputTypes[no] = type;
00139 emit signalInputType(no, type);
00140 }
00141
00142
00143 #include "config_two.moc"