summaryrefslogtreecommitdiffstats
path: root/kpat/gamestatsimpl.cpp
blob: 59e37b790583811ebac02d1669cf4a0625c44b31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "gamestatsimpl.h"
#include "dealer.h"
#include "version.h"

#include <tqcombobox.h>
#include <tqlabel.h>

#include <kapplication.h>
#include <kconfig.h>
#include <klocale.h>

GameStatsImpl::GameStatsImpl(TQWidget* aParent, const char* aname)
	: GameStats(aParent, aname)
{
	TQStringList list;
	TQValueList<DealerInfo*>::ConstIterator it;
	for (it = DealerInfoList::self()->games().begin();
			it != DealerInfoList::self()->games().end(); ++it)
	{
		// while we develop, it may happen that some lower
		// indices do not exist
		uint index = (*it)->gameindex;
		for (uint i = 0; i <= index; i++)
			if (list.count() <= i)
				list.append("unknown");
		list[index] = i18n((*it)->name);
		list[index].tqreplace('&',"");
	}
	GameType->insertStringList(list);
	showGameType(0);
}

void GameStatsImpl::showGameType(int id)
{
	GameType->setCurrentItem(id);
	setGameType(id);
}

void GameStatsImpl::setGameType(int id)
{
	// Trick to reset string to original value
	languageChange();
	KConfig *config = kapp->config();
	KConfigGroupSaver kcs(config, scores_group);
	unsigned int t = config->readUnsignedNumEntry(TQString("total%1").tqarg(id),0);
	Played->setText(Played->text().tqarg(t));
	unsigned int w = config->readUnsignedNumEntry(TQString("won%1").tqarg(id),0);
	Won->setText(Won->text().tqarg(w));
	if (t)
		WonPerc->setText(WonPerc->text().tqarg(w*100/t));
	else
		WonPerc->setText(WonPerc->text().tqarg(0));
	WinStreak->setText(
		WinStreak->text().tqarg(config->readUnsignedNumEntry(TQString("maxwinstreak%1").tqarg(id),0)));
	LooseStreak->setText(
		LooseStreak->text().tqarg(config->readUnsignedNumEntry(TQString("maxloosestreak%1").tqarg(id),0)));
}