config_two.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE games lskat program
00003    Copyright (c) 2006 Martin Heni <kde@heni-online.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 // Qt includes
00022 
00023 // KDE includes
00024 #include <kdebug.h>
00025 #include <klocale.h>
00026 
00027 // Local includes
00028 #include "config_two.h"
00029 
00030 
00031 // Constructor for the configuration
00032 ConfigTwo::ConfigTwo(QObject* parent)
00033          : QObject(parent)
00034 {
00035   // Create Players
00036   mPlayers.clear();
00037   mPlayers[0] = new Player(0, this);
00038   mPlayers[1] = new Player(1, this);
00039 }
00040 
00041 
00042 // Resets the data
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   // Default input types (must be after GUI and players)
00049   setInputType(0, TypeMouseInput);
00050   setInputType(1, TypeAiInput);
00051 }
00052 
00053 
00054 // Destructor
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 // Save properties
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   // Save player
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 // Load properties
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   // Load player
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 // Retrieve a player.
00113 Player* ConfigTwo::player(int no)
00114 {
00115   if (!mPlayers.contains(no)) return 0;
00116   return mPlayers[no];
00117 }
00118 
00119 
00120 // Retrieve player as iterator
00121 QHashIterator<int,Player*> ConfigTwo::playerIterator()
00122 {
00123   QHashIterator<int,Player*> it(mPlayers);
00124   return it;
00125 }
00126 
00127 
00128 // Retrieve input type of given player
00129 InputDeviceType ConfigTwo::inputType(int no)
00130 {
00131   return mInputTypes[no];
00132 }
00133 
00134 
00135 // Set the input type for a given players
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"

Generated on Tue May 1 09:34:40 2007 for LSkat by  doxygen 1.4.6