summaryrefslogtreecommitdiffstats
path: root/kreversi/highscores.cpp
blob: fae86a40f07f8a87f19415b3011aca4f8692ddde (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (c) 2004 Nicolas HADACEK ([email protected])
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */


#include "highscores.h"

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


namespace KExtHighscore
{

const ExtManager::Data ExtManager::DATA[SuperEngine::NbStrengths] = {
  { I18N_NOOP("1 (Beginner)"), "beginner" },
  { I18N_NOOP("2"), 0 },
  { I18N_NOOP("3"), 0 },
  { I18N_NOOP("4 (Average)"), "average" },
  { I18N_NOOP("5"), 0 },
  { I18N_NOOP("6"), 0 },
  { I18N_NOOP("7 (Expert)"), "expert" }
};


ExtManager::ExtManager()
    : Manager(SuperEngine::NbStrengths)
{
  setShowStatistics(true);
  setShowDrawGamesStatistic(true);

  const uint       RANGE[6] = { 0, 32, 40, 48, 56, 64 };
  TQMemArray<uint>  s;
  s.duplicate(RANGE, 6);
  setScoreHistogram(s, ScoreBound);
}


TQString ExtManager::gameTypeLabel(uint gameType, LabelType type) const
{
  const Data &data = DATA[gameType];
  switch (type) {
  case Icon:     return data.icon;
  case Standard: return TQString::number(gameType);
  case I18N:     return i18n(data.label);
  case WW:       break;
  }

  return TQString();
}


void ExtManager::convertLegacy(uint gameType)
{
  // Since there is no information about the skill level
  // in the legacy highscore list, consider they are
  // for beginner skill ...
  tqDebug("convert legacy %i", gameType);

  if ( gameType!=0 )
    return;

  KConfigGroupSaver  cg(kapp->config(), "High Score");

  for (uint i = 1; i <= 10; i++) {
    TQString  key = "Pos" + TQString::number(i);
    TQString  name = cg.config()->readEntry(key + "Name", TQString());

    if ( name.isEmpty() )
      name = i18n("anonymous");

    uint  score = cg.config()->readUnsignedNumEntry(key + "NumChips", 0);
    if ( score==0 )
      continue;

    TQString    sdate = cg.config()->readEntry(key + "Date", TQString());
    TQDateTime  date  = TQDateTime::fromString(sdate);
    Score      s(Won);

    s.setScore(score);
    s.setData("name", name);
    if ( date.isValid() )
      s.setData("date", date);
    submitLegacyScore(s);
  }
}


} // Namespace