kolf.cpp 27.1 KB
Newer Older
1
2
/*
    Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu>
3
    Copyright 2010 Stefan Majewsky <majewsky@gmx.net>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

    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
*/

20
#include "kolf.h"
21
#include "editor.h"
22
#include "landscape.h"
23
#include "newgame.h"
24
#include "objects.h"
25
#include "obstacles.h"
26
#include "scoreboard.h"
27

28
#include <KActionCollection>
29
30
31
#include <KIO/CopyJob>
#include <KIO/Job>
#include <KJobWidgets>
32
#include <KLocalizedString>
33
34
35
#include <KMessageBox>
#include <KScoreDialog>
#include <KSelectAction>
36
#include <KSharedConfig>
37
38
#include <KStandardAction>
#include <KStandardGameAction>
André Wöbbeking's avatar
André Wöbbeking committed
39
#include <KStandardGuiItem>
40
#include <KToggleAction>
41
#include <QFileDialog>
Laurent Montel's avatar
Laurent Montel committed
42
#include <QGridLayout>
43
#include <QMimeDatabase>
44
#include <QStandardPaths>
45
#include <QStatusBar>
46
#include <QTemporaryFile>
47
#include <QTimer>
Jason Katz-Brown's avatar
Jason Katz-Brown committed
48

49
KolfWindow::KolfWindow()
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
50
    : KXmlGuiWindow(nullptr)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
51
{
Laurent Montel's avatar
Laurent Montel committed
52
	setObjectName( QStringLiteral("Kolf" ));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
53
	competition = false;
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
54
55
56
57
	game = nullptr;
	editor = nullptr;
	spacer = nullptr;
	scoreboard = nullptr;
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
58
	isTutorial = false;
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
59

60
	setupActions();
61

Laurent Montel's avatar
Laurent Montel committed
62
63
64
65
66
67
68
69
70
71
72
	m_itemFactory.registerType<Kolf::Slope>(QStringLiteral("slope"), i18n("Slope"));
	m_itemFactory.registerType<Kolf::Puddle>(QStringLiteral("puddle"), i18n("Puddle"));
	m_itemFactory.registerType<Kolf::Wall>(QStringLiteral("wall"), i18n("Wall"));
	m_itemFactory.registerType<Kolf::Cup>(QStringLiteral("cup"), i18n("Cup"), true); //true == addOnNewHole
	m_itemFactory.registerType<Kolf::Sand>(QStringLiteral("sand"), i18n("Sand"));
	m_itemFactory.registerType<Kolf::Windmill>(QStringLiteral("windmill"), i18n("Windmill"));
	m_itemFactory.registerType<Kolf::BlackHole>(QStringLiteral("blackhole"), i18n("Black Hole"));
	m_itemFactory.registerType<Kolf::Floater>(QStringLiteral("floater"), i18n("Floater"));
	m_itemFactory.registerType<Kolf::Bridge>(QStringLiteral("bridge"), i18n("Bridge"));
	m_itemFactory.registerType<Kolf::Sign>(QStringLiteral("sign"), i18n("Sign"));
	m_itemFactory.registerType<Kolf::Bumper>(QStringLiteral("bumper"), i18n("Bumper"));
73
	//NOTE: The plugin mechanism has been removed because it is not used anyway.
Jason Katz-Brown's avatar
Jason Katz-Brown committed
74

75
	filename = QString();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
76
77
	dummy = new QWidget(this);
	setCentralWidget(dummy);
Stephan Kulow's avatar
Stephan Kulow committed
78
	layout = new QGridLayout(dummy);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
79
80
81
82

	resize(420, 480);
}

83
KolfWindow::~KolfWindow()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
84
85
86
{
}

87
void KolfWindow::setupActions()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
88
{
89
90
91
92
	// Game
	newAction = KStandardGameAction::gameNew(this, SLOT(newGame()), actionCollection());
	endAction = KStandardGameAction::end(this, SLOT(closeGame()), actionCollection());
	KStandardGameAction::quit(this, SLOT(close()), actionCollection());
Jason Katz-Brown's avatar
Jason Katz-Brown committed
93

Laurent Montel's avatar
Laurent Montel committed
94
	saveAction = actionCollection()->addAction(KStandardAction::Save, QStringLiteral("game_save"), this, SLOT(save()));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
95
	saveAction->setText(i18n("Save &Course"));
Laurent Montel's avatar
Laurent Montel committed
96
	saveAsAction = actionCollection()->addAction(KStandardAction::SaveAs, QStringLiteral("game_save_as"), this, SLOT(saveAs()));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
97
	saveAsAction->setText(i18n("Save &Course As..."));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
98

Laurent Montel's avatar
Laurent Montel committed
99
	saveGameAction = actionCollection()->addAction(QStringLiteral("savegame"));
100
	saveGameAction->setText(i18n("&Save Game"));
101
	connect(saveGameAction, &QAction::triggered, this, &KolfWindow::saveGame);
Laurent Montel's avatar
Laurent Montel committed
102
	saveGameAsAction = actionCollection()->addAction(QStringLiteral("savegameas"));
103
	saveGameAsAction->setText(i18n("&Save Game As..."));
104
	connect(saveGameAsAction, &QAction::triggered, this, &KolfWindow::saveGameAs);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
105

106
	loadGameAction = KStandardGameAction::load(this, SLOT(loadGame()), actionCollection());
107
	highScoreAction = KStandardGameAction::highscores(this, SLOT(showHighScores()), actionCollection());
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
108

109
	// Hole
Laurent Montel's avatar
Laurent Montel committed
110
111
	editingAction = new KToggleAction(QIcon::fromTheme( QStringLiteral( "document-properties") ), i18n("&Edit"), this);
	actionCollection()->addAction(QStringLiteral("editing"), editingAction);
112
	connect(editingAction, &QAction::triggered, this, &KolfWindow::emptySlot);
113
	actionCollection()->setDefaultShortcut(editingAction, Qt::CTRL+Qt::Key_E);
Laurent Montel's avatar
Laurent Montel committed
114
115
	newHoleAction = actionCollection()->addAction(QStringLiteral("newhole"));
	newHoleAction->setIcon(QIcon::fromTheme( QStringLiteral( "document-new" )));
116
	newHoleAction->setText(i18n("&New"));
117
	connect(newHoleAction, &QAction::triggered, this, &KolfWindow::emptySlot);
118
	actionCollection()->setDefaultShortcut(newHoleAction, Qt::CTRL+Qt::SHIFT+Qt::Key_N);
Laurent Montel's avatar
Laurent Montel committed
119
120
	clearHoleAction = actionCollection()->addAction(QStringLiteral("clearhole"));
	clearHoleAction->setIcon(QIcon::fromTheme( QStringLiteral( "edit-clear-locationbar-ltr" )));
121
	clearHoleAction->setText(KStandardGuiItem::clear().text());
122
	connect(clearHoleAction, &QAction::triggered, this, &KolfWindow::emptySlot);
123
	actionCollection()->setDefaultShortcut(clearHoleAction, Qt::CTRL+Qt::Key_Delete);
Laurent Montel's avatar
Laurent Montel committed
124
	resetHoleAction = actionCollection()->addAction(QStringLiteral("resethole"));
125
	resetHoleAction->setText(i18n("&Reset"));
126
	connect(resetHoleAction, &QAction::triggered, this, &KolfWindow::emptySlot);
127
	actionCollection()->setDefaultShortcut(resetHoleAction, Qt::CTRL+Qt::Key_R);
128
	undoShotAction = KStandardAction::undo(this, &KolfWindow::emptySlot, this);
Laurent Montel's avatar
Laurent Montel committed
129
	actionCollection()->addAction(QStringLiteral("undoshot"), undoShotAction);
130
	undoShotAction->setText(i18n("&Undo Shot"));
Laurent Montel's avatar
Port++    
Laurent Montel committed
131
	//replayShotAction = new QAction(i18n("&Replay Shot"), 0, this, SLOT(emptySlot()), actionCollection(), "replay");
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
132

133
	// Go
134
	holeAction = new KSelectAction(i18n("Switch to Hole"), this);
Laurent Montel's avatar
Laurent Montel committed
135
	actionCollection()->addAction(QStringLiteral("switchhole"), holeAction);
136
	connect(holeAction, &QAction::triggered, this, &KolfWindow::emptySlot);
Laurent Montel's avatar
Laurent Montel committed
137
138
	nextAction = actionCollection()->addAction(QStringLiteral("nexthole"));
	nextAction->setIcon(QIcon::fromTheme( QStringLiteral( "go-next" )));
139
	nextAction->setText(i18n("&Next Hole"));
140
	connect(nextAction, &QAction::triggered, this, &KolfWindow::emptySlot);
141
	actionCollection()->setDefaultShortcuts(nextAction, KStandardShortcut::forward());
Laurent Montel's avatar
Laurent Montel committed
142
143
	prevAction = actionCollection()->addAction(QStringLiteral("prevhole"));
	prevAction->setIcon(QIcon::fromTheme( QStringLiteral( "go-previous" )));
144
	prevAction->setText(i18n("&Previous Hole"));
145
	connect(prevAction, &QAction::triggered, this, &KolfWindow::emptySlot);
146
	actionCollection()->setDefaultShortcuts(prevAction, KStandardShortcut::back());
Laurent Montel's avatar
Laurent Montel committed
147
148
	firstAction = actionCollection()->addAction(QStringLiteral("firsthole"));
	firstAction->setIcon(QIcon::fromTheme( QStringLiteral( "go-home" )));
149
	firstAction->setText(i18n("&First Hole"));
150
	connect(firstAction, &QAction::triggered, this, &KolfWindow::emptySlot);
151
	actionCollection()->setDefaultShortcuts(firstAction, KStandardShortcut::begin());
Laurent Montel's avatar
Laurent Montel committed
152
	lastAction = actionCollection()->addAction(QStringLiteral("lasthole"));
153
	lastAction->setText(i18n("&Last Hole"));
154
	connect(lastAction, &QAction::triggered, this, &KolfWindow::emptySlot);
155
	actionCollection()->setDefaultShortcut(lastAction, Qt::CTRL+Qt::SHIFT+Qt::Key_End); // why not KStandardShortcut::End (Ctrl+End)?
Laurent Montel's avatar
Laurent Montel committed
156
157
	randAction = actionCollection()->addAction(QStringLiteral("randhole"));
	randAction->setIcon(QIcon::fromTheme( QStringLiteral( "go-jump" )));
158
	randAction->setText(i18n("&Random Hole"));
159
	connect(randAction, &QAction::triggered, this, &KolfWindow::emptySlot);
160

161
	// Settings
162
	useMouseAction = new KToggleAction(i18n("Enable &Mouse for Moving Putter"), this);
Laurent Montel's avatar
Laurent Montel committed
163
	actionCollection()->addAction(QStringLiteral("usemouse"), useMouseAction);
164
165
	connect(useMouseAction, &QAction::triggered, this, &KolfWindow::emptySlot);
	connect(useMouseAction, &QAction::toggled, this, &KolfWindow::useMouseChanged);
Laurent Montel's avatar
Laurent Montel committed
166
	KConfigGroup configGroup(KSharedConfig::openConfig(), "Settings");
Paul Broadbent's avatar
Paul Broadbent committed
167
	useMouseAction->setChecked(configGroup.readEntry("useMouse", true));
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
168

169
	useAdvancedPuttingAction = new KToggleAction(i18n("Enable &Advanced Putting"), this);
Laurent Montel's avatar
Laurent Montel committed
170
	actionCollection()->addAction(QStringLiteral("useadvancedputting"), useAdvancedPuttingAction);
171
172
	connect(useAdvancedPuttingAction, &QAction::triggered, this, &KolfWindow::emptySlot);
	connect(useAdvancedPuttingAction, &QAction::toggled, this, &KolfWindow::useAdvancedPuttingChanged);
Paul Broadbent's avatar
Paul Broadbent committed
173
	useAdvancedPuttingAction->setChecked(configGroup.readEntry("useAdvancedPutting", false));
174

Laurent Montel's avatar
Laurent Montel committed
175
176
	showInfoAction = new KToggleAction(QIcon::fromTheme( QStringLiteral( "help-about")), i18n("Show &Info"), this);
	actionCollection()->addAction(QStringLiteral("showinfo"), showInfoAction);
177
	connect(showInfoAction, &QAction::triggered, this, &KolfWindow::emptySlot);
178
	actionCollection()->setDefaultShortcut(showInfoAction, Qt::CTRL+Qt::Key_I);
179
	connect(showInfoAction, &QAction::toggled, this, &KolfWindow::showInfoChanged);
180
	showInfoAction->setChecked(configGroup.readEntry("showInfo", true));
181

182
	showGuideLineAction = new KToggleAction(i18n("Show Putter &Guideline"), this);
Laurent Montel's avatar
Laurent Montel committed
183
	actionCollection()->addAction(QStringLiteral("showguideline"), showGuideLineAction);
184
185
	connect(showGuideLineAction, &QAction::triggered, this, &KolfWindow::emptySlot);
	connect(showGuideLineAction, &QAction::toggled, this, &KolfWindow::showGuideLineChanged);
Paul Broadbent's avatar
Paul Broadbent committed
186
	showGuideLineAction->setChecked(configGroup.readEntry("showGuideLine", true));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
187

188
	KToggleAction *act = new KToggleAction(i18n("Enable All Dialog Boxes"), this);
Laurent Montel's avatar
Laurent Montel committed
189
	actionCollection()->addAction(QStringLiteral("enableAll"), act);
190
	connect(act, &QAction::triggered, this, &KolfWindow::enableAllMessages);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
191

192
	soundAction = new KToggleAction(i18n("Play &Sounds"), this);
Laurent Montel's avatar
Laurent Montel committed
193
	actionCollection()->addAction(QStringLiteral("sound"), soundAction);
194
195
	connect(soundAction, &QAction::triggered, this, &KolfWindow::emptySlot);
	connect(soundAction, &QAction::toggled, this, &KolfWindow::soundChanged);
Paul Broadbent's avatar
Paul Broadbent committed
196
	soundAction->setChecked(configGroup.readEntry("sound", true));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
197

Laurent Montel's avatar
Laurent Montel committed
198
	aboutAction = actionCollection()->addAction(QStringLiteral("aboutcourse"));
199
	aboutAction->setText(i18n("&About Course"));
200
	connect(aboutAction, &QAction::triggered, this, &KolfWindow::emptySlot);
Laurent Montel's avatar
Laurent Montel committed
201
	tutorialAction = actionCollection()->addAction(QStringLiteral("tutorial"));
202
	tutorialAction->setText(i18n("&Tutorial"));
203
	connect(tutorialAction, &QAction::triggered, this, &KolfWindow::tutorial);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
204

Benjamin Meyer's avatar
Benjamin Meyer committed
205
	setupGUI();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
206
207
}

208
bool KolfWindow::queryClose()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
209
{
210
211
	if (game)
		if (game->askSave(true))
212
213
			return false;
	return true;
Jason Katz-Brown's avatar
Jason Katz-Brown committed
214
215
}

216
void KolfWindow::startNewGame()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
217
{
Laurent Montel's avatar
Laurent Montel committed
218
        NewGameDialog *dialog = nullptr;
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
219
	int firstHole = 1;
Jason Katz-Brown's avatar
Jason Katz-Brown committed
220

Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
221
222
	if (loadedGame.isNull())
	{
223
		dialog = new NewGameDialog(filename.isNull());
Laurent Montel's avatar
Laurent Montel committed
224
225
226
227
                if (dialog->exec() != QDialog::Accepted) {
                    delete dialog;
                    return;
               }
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
228
229
230
231
	}

	players.clear();
	delete scoreboard;
232
	scoreboard = new ScoreBoard(dummy);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
233
234
235
236
	layout->addWidget(scoreboard, 1, 0);
	scoreboard->show();

	if (loadedGame.isNull())
Jason Katz-Brown's avatar
Jason Katz-Brown committed
237
	{
238
		for (int newId = 1; newId <= dialog->players()->count(); ++newId)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
239
240
		{
			players.append(Player());
241
			players.last().ball()->setColor(dialog->players()->at(newId-1)->color());
242
			players.last().setName(dialog->players()->at(newId-1)->name());
Jason Katz-Brown's avatar
Jason Katz-Brown committed
243
244
			players.last().setId(newId);
		}
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
245

Jason Katz-Brown's avatar
Jason Katz-Brown committed
246
		competition = dialog->competition();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
247
		filename = filename.isNull()? dialog->course() : filename;
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
248
249
250
	}
	else
	{
251
		KConfig config(loadedGame);
Paul Broadbent's avatar
Paul Broadbent committed
252
		KConfigGroup configGroup(config.group("0 Saved Game"));
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
253

Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
254
		if (isTutorial)
Laurent Montel's avatar
Laurent Montel committed
255
			filename = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("tutorial.kolf"));
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
256
		else
Paul Broadbent's avatar
Paul Broadbent committed
257
			filename = configGroup.readEntry("Course", QString());
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
258

Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
259
260
		if (filename.isNull())
			return;
Jason Katz-Brown's avatar
Jason Katz-Brown committed
261

Paul Broadbent's avatar
Paul Broadbent committed
262
263
		competition = configGroup.readEntry("Competition", false);
		firstHole = configGroup.readEntry("Current Hole", 1);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
264
265
266

		players.clear();
		KolfGame::scoresFromSaved(&config, players);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
267
268
	}

Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
269
270
271
	for (PlayerList::Iterator it = players.begin(); it != players.end(); ++it)
		scoreboard->newPlayer((*it).name());

Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
272
	delete spacer;
Laurent Montel's avatar
Laurent Montel committed
273
        spacer = nullptr;
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
274
	delete game;
Laurent Montel's avatar
Laurent Montel committed
275
        game = new KolfGame(m_itemFactory, &players, filename, dummy);
276
	game->setStrict(competition);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
	connect(game, &KolfGame::newHole, scoreboard, &ScoreBoard::newHole);
	connect(game, &KolfGame::scoreChanged, scoreboard, &ScoreBoard::setScore);
	connect(game, &KolfGame::parChanged, scoreboard, &ScoreBoard::parChanged);
	connect(game, &KolfGame::modifiedChanged, this, &KolfWindow::updateModified);
	connect(game, &KolfGame::newPlayersTurn, this, &KolfWindow::newPlayersTurn);
	connect(game, &KolfGame::holesDone, this, &KolfWindow::gameOver);
	connect(game, &KolfGame::checkEditing, this, &KolfWindow::checkEditing);
	connect(game, &KolfGame::editingStarted, this, &KolfWindow::editingStarted);
	connect(game, &KolfGame::editingEnded, this, &KolfWindow::editingEnded);
	connect(game, &KolfGame::inPlayStart, this, &KolfWindow::inPlayStart);
	connect(game, &KolfGame::inPlayEnd, this, &KolfWindow::inPlayEnd);
	connect(game, &KolfGame::maxStrokesReached, this, &KolfWindow::maxStrokesReached);
	connect(game, &KolfGame::largestHole, this, &KolfWindow::updateHoleMenu);
	connect(game, &KolfGame::titleChanged, this, &KolfWindow::titleChanged);
	connect(game, &KolfGame::newStatusText, this, &KolfWindow::newStatusText);
	connect(game, QOverload<int>::of(&KolfGame::currentHole), this, &KolfWindow::setCurrentHole);
	connect(holeAction, &QAction::triggered, game, QOverload<int>::of(&KolfGame::switchHole));
	connect(nextAction, &QAction::triggered, game, &KolfGame::nextHole);
	connect(prevAction, &QAction::triggered, game, &KolfGame::prevHole);
	connect(firstAction, &QAction::triggered, game, &KolfGame::firstHole);
	connect(lastAction, &QAction::triggered, game, &KolfGame::lastHole);
	connect(randAction, &QAction::triggered, game, &KolfGame::randHole);
	connect(editingAction, &QAction::triggered, game, &KolfGame::toggleEditMode);
	connect(newHoleAction, &QAction::triggered, game, &KolfGame::addNewHole);
	connect(clearHoleAction, &QAction::triggered, game, &KolfGame::clearHole);
	connect(resetHoleAction, &QAction::triggered, game, &KolfGame::resetHole);
	connect(undoShotAction, &QAction::triggered, game, &KolfGame::undoShot);
	//connect(replayShotAction, &QAction::triggered, game, &KolfGame::replay);
	connect(aboutAction, &QAction::triggered, game, &KolfGame::showInfoDlg);
	connect(useMouseAction, &QAction::toggled, game, &KolfGame::setUseMouse);
	connect(useAdvancedPuttingAction, &QAction::toggled, game, &KolfGame::setUseAdvancedPutting);
	connect(soundAction, &QAction::toggled, game, &KolfGame::setSound);
	connect(showGuideLineAction, &QAction::toggled, game, &KolfGame::setShowGuideLine);
	connect(showInfoAction, &QAction::toggled, game, &KolfGame::setShowInfo);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
312
313

	game->setUseMouse(useMouseAction->isChecked());
314
	game->setUseAdvancedPutting(useAdvancedPuttingAction->isChecked());
315
	game->setShowInfo(showInfoAction->isChecked());
316
317
	game->setShowGuideLine(showGuideLineAction->isChecked());
	game->setSound(soundAction->isChecked());
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
318

319
	layout->addWidget(game, 0, 0);//, Qt::AlignCenter);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342

	game->show();
	game->setFocus();

	setEditingEnabled(true);
	endAction->setEnabled(true);
	setHoleMovementEnabled(true);
	setHoleOtherEnabled(true);
	aboutAction->setEnabled(true);
	highScoreAction->setEnabled(true);
	saveAction->setEnabled(true);
	saveAsAction->setEnabled(true);
	saveGameAction->setEnabled(true);
	saveGameAsAction->setEnabled(true);

	clearHoleAction->setEnabled(false);
	newHoleAction->setEnabled(false);
	newAction->setEnabled(false);
	loadGameAction->setEnabled(false);
	tutorialAction->setEnabled(false);

	// so game can do stuff that needs to be done
	// after things above are connected
343
	game->startFirstHole(firstHole);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
344
345
346
	delete dialog;
}

347
void KolfWindow::newGame()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
348
{
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
349
	isTutorial = false;
350
	filename = QString();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
351
352
353
	startNewGame();
}

354
void KolfWindow::tutorial()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
355
{
356
	QString newfilename = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("tutorial.kolfgame"));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
357
	if (newfilename.isNull())
358
	        return;
359

360
	filename = QString();
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
361
362
363
	loadedGame = newfilename;
	isTutorial = true;

Jason Katz-Brown's avatar
Jason Katz-Brown committed
364
	startNewGame();
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
365

366
	loadedGame = QString();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
367
368
}

369
void KolfWindow::closeGame()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
370
371
{
	if (game)
372
373
374
	{
		if (game->askSave(true))
			return;
Jason Katz-Brown's avatar
Jason Katz-Brown committed
375
		game->pause();
376
	}
377

378
	filename = QString();
379

Jason Katz-Brown's avatar
Jason Katz-Brown committed
380
381
	editingEnded();
	delete game;
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
382
	game = nullptr;
383
	loadedGame = QString();
384

Jason Katz-Brown's avatar
Jason Katz-Brown committed
385
386
387
388
	editingAction->setChecked(false);
	setEditingEnabled(false);
	endAction->setEnabled(false);
	aboutAction->setEnabled(false);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
389
	highScoreAction->setEnabled(false);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
390
391
	saveAction->setEnabled(false);
	saveAsAction->setEnabled(false);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
392
393
	saveGameAction->setEnabled(false);
	saveGameAsAction->setEnabled(false);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
394
	setHoleMovementEnabled(false);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
395
	setHoleOtherEnabled(false);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
396
397
398
399

	clearHoleAction->setEnabled(false);
	newHoleAction->setEnabled(false);
	newAction->setEnabled(true);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
400
	loadGameAction->setEnabled(true);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
401
	tutorialAction->setEnabled(true);
402

403
	titleChanged(QString());
404
	updateModified(false);
405

406
	QTimer::singleShot(100, this, &KolfWindow::createSpacer);
407
408
}

409
void KolfWindow::createSpacer()
410
411
412
413
{
	// make a player to play the spacer hole
	spacerPlayers.clear();
	spacerPlayers.append(Player());
Laurent Montel's avatar
Laurent Montel committed
414
	spacerPlayers.last().ball()->setColor(Qt::yellow);
Laurent Montel's avatar
Laurent Montel committed
415
	spacerPlayers.last().setName(QStringLiteral("player"));
416
417
418
	spacerPlayers.last().setId(1);

	delete spacer;
Laurent Montel's avatar
Laurent Montel committed
419
	spacer = new KolfGame(m_itemFactory, &spacerPlayers, QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("intro")), dummy);
420
	spacer->setSound(false);
421
	layout->addWidget(spacer, 0, 0);//, Qt::AlignCenter);
422
423
424
	spacer->ignoreEvents(true);

	spacer->show();
425
426
	spacer->startFirstHole(1);
	spacer->hidePutter();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
427
428
}

429
void KolfWindow::gameOver()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
430
{
431
432
433
	int curPar = 0;
	int lowScore = INT_MAX; // let's hope it doesn't stay this way!
	int curScore = 1;
434
435

	// names of people who had the lowest score
436
	QStringList names;
437

438
	HighScoreList highScores;
439
	int scoreBoardIndex = 1;
440
441

	while (curScore != 0)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
442
	{
443
444
445
		QString curName;

		// name taken as a reference and filled out
446
		curScore = scoreboard->total(scoreBoardIndex, curName);
447

448
		scoreBoardIndex++;
449
450

		if (curName == i18n("Par"))
451
		{
452
			curPar = curScore;
453
			curScore = 0;
454
			continue;
455
		}
Jason Katz-Brown's avatar
Jason Katz-Brown committed
456

457
458
459
460
461
462
463
464
		if (curScore == 0)
			continue;

		// attempt to add everybody to the highscore list
		// (ignored if we aren't competing down below)
		highScores.append(HighScore(curName, curScore));

		if (curScore < lowScore)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
465
		{
466
467
468
			names.clear();
			lowScore = curScore;
			names.append(curName);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
469
		}
470
471
472
		else if (curScore == lowScore)
			names.append(curName);
	}
Jason Katz-Brown's avatar
Jason Katz-Brown committed
473

474
475
476
477
	// only announce a winner if more than two entries
	// (player and par) are on the scoreboard + one to go past end
	// + 1 for koodoo
	if (scoreBoardIndex > 4)
478
	{
479
480
		if (names.count() > 1)
		{
481
			QString winners = names.join( i18n(" and " ));
482
			KMessageBox::information(this, i18n("%1 tied", winners));
483
484
		}
		else
485
			KMessageBox::information(this, i18n("%1 won!", names.first()));
486
487
488
489
	}

	if (competition)
	{
490
491
		// deal with highscores
		// KScoreDialog makes it very easy :-))
Jason Katz-Brown's avatar
Jason Katz-Brown committed
492

Jason Katz-Brown's avatar
Jason Katz-Brown committed
493
		KScoreDialog *scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Custom1 | KScoreDialog::Score, this);
Laurent Montel's avatar
Laurent Montel committed
494
		scoreDialog->addField(KScoreDialog::Custom1, i18n("Par"), QStringLiteral("Par"));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
495
496
497
498

		CourseInfo courseInfo;
		game->courseInfo(courseInfo, game->curFilename());

499
		scoreDialog->setConfigGroup(qMakePair(QByteArray(courseInfo.untranslatedName.toUtf8() + " Highscores"), i18n("High Scores for %1", courseInfo.name)));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
500

501
502
503
		for (HighScoreList::Iterator it = highScores.begin(); it != highScores.end(); ++it)
		{
			KScoreDialog::FieldInfo info;
504
                        info[KScoreDialog::Name] = (*it).name;
505
                        info[KScoreDialog::Score].setNum((*it).score);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
506
			info[KScoreDialog::Custom1] = QString::number(curPar);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
507

508
                        scoreDialog->addScore(info, KScoreDialog::LessIsMore);
509
		}
Jason Katz-Brown's avatar
Jason Katz-Brown committed
510

511
		scoreDialog->setComment(i18n("High Scores for %1", courseInfo.name));
512
		scoreDialog->show();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
513
514
	}

515
	QTimer::singleShot(700, this, &KolfWindow::closeGame);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
516
517
}

518
void KolfWindow::showHighScores()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
519
{
Jason Katz-Brown's avatar
Jason Katz-Brown committed
520
	KScoreDialog *scoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Custom1 | KScoreDialog::Score, this);
Laurent Montel's avatar
Laurent Montel committed
521
	scoreDialog->addField(KScoreDialog::Custom1, i18n("Par"), QStringLiteral("Par"));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
522
523
524
525

	CourseInfo courseInfo;
	game->courseInfo(courseInfo, game->curFilename());

526
	scoreDialog->setConfigGroup(qMakePair(QByteArray(courseInfo.untranslatedName.toUtf8() + " Highscores"), i18n("High Scores for %1", courseInfo.name)));
527
	scoreDialog->setComment(i18n("High Scores for %1", courseInfo.name));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
528
529
530
	scoreDialog->show();
}

531
void KolfWindow::save()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
532
533
534
535
536
537
{
	if (filename.isNull())
	{
		saveAs();
		return;
	}
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
538

539
	if (game) {
Jason Katz-Brown's avatar
Jason Katz-Brown committed
540
		game->save();
541
542
		game->setFocus();
	}
Jason Katz-Brown's avatar
Jason Katz-Brown committed
543
544
}

545
void KolfWindow::saveAs()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
546
{
547
548
549
550
551
552
553
	QPointer<QFileDialog> fileSaveDialog = new QFileDialog(this);
	fileSaveDialog->setWindowTitle(i18nc("@title:window", "Pick Kolf Course to Save To"));
	fileSaveDialog->setMimeTypeFilters(QStringList(QStringLiteral("application/x-kourse")));
	fileSaveDialog->setAcceptMode(QFileDialog::AcceptSave);
	if (fileSaveDialog->exec() == QDialog::Accepted) {
		QUrl newfile = fileSaveDialog->selectedUrls().first();
		if (!newfile.isEmpty()) {
554
			filename = newfile.toLocalFile();
555
556
557
558
			game->setFilename(filename);
			game->save();
			game->setFocus();
		}
Jason Katz-Brown's avatar
Jason Katz-Brown committed
559
	}
560
	delete fileSaveDialog;
Jason Katz-Brown's avatar
Jason Katz-Brown committed
561
562
}

563
void KolfWindow::saveGameAs()
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
564
{
565
566
567
568
569
570
571
572
573
574
		QPointer<QFileDialog> fileSaveDialog = new QFileDialog(this);
		fileSaveDialog->setWindowTitle(i18nc("@title:window", "Pick Saved Game to Save To"));
		fileSaveDialog->setMimeTypeFilters(QStringList(QStringLiteral("application/x-kolf")));
		fileSaveDialog->setAcceptMode(QFileDialog::AcceptSave);
		if (fileSaveDialog->exec() == QDialog::Accepted) {
			QUrl newfile = fileSaveDialog->selectedUrls().first();
			if (newfile.isEmpty()) {
				return;
			}
			else {
575
				loadedGame = newfile.toLocalFile();
576
577
578
579
				saveGame();
			}
		}
		delete fileSaveDialog;
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
580
581
}

582
void KolfWindow::saveGame()
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
583
584
585
586
587
588
{
	if (loadedGame.isNull())
	{
		saveGameAs();
		return;
	}
589

590
	KConfig config(loadedGame);
Paul Broadbent's avatar
Paul Broadbent committed
591
	KConfigGroup configGroup(config.group("0 Saved Game"));
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
592

Paul Broadbent's avatar
Paul Broadbent committed
593
594
	configGroup.writeEntry("Competition", competition);
	configGroup.writeEntry("Course", filename);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
595
596
597

	game->saveScores(&config);

Paul Broadbent's avatar
Paul Broadbent committed
598
	configGroup.sync();
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
599
600
}

601
void KolfWindow::loadGame()
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
602
{
603
604
605
606
607
608
	QPointer<QFileDialog> fileLoadDialog = new QFileDialog(this);
	fileLoadDialog->setWindowTitle(i18nc("@title:window", "Pick Kolf Saved Game"));
	fileLoadDialog->setMimeTypeFilters(QStringList(QStringLiteral("application/x-kolf")));
	fileLoadDialog->setAcceptMode(QFileDialog::AcceptOpen);
	fileLoadDialog->setFileMode(QFileDialog::ExistingFile);
	if (fileLoadDialog->exec() == QDialog::Accepted) {
609
		loadedGame = fileLoadDialog->selectedUrls().first().toLocalFile();
610
611
612
613
614
615
616
617
618
		if (loadedGame.isEmpty()) {
			return;
		}
		else {
			isTutorial = false;
			startNewGame();
		}
	}
	delete fileLoadDialog;
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
619
620
}

Jaison Lee's avatar
Jaison Lee committed
621
// called by main for command line files
Laurent Montel's avatar
Laurent Montel committed
622
void KolfWindow::openUrl(const QUrl &url)
623
{
624
625
626
627
628
629
	QTemporaryFile tempFile;
	tempFile.open();
	KIO::FileCopyJob *job = KIO::file_copy(url, QUrl::fromLocalFile(tempFile.fileName()), -1, KIO::Overwrite);
	KJobWidgets::setWindow(job, this);
	job->exec();
	if (!job->error())
630
631
	{
		isTutorial = false;
632
633
		QMimeDatabase db;
		QString mimeType = db.mimeTypeForFile(tempFile).name();
Laurent Montel's avatar
Laurent Montel committed
634
		if (mimeType == QLatin1String("application/x-kourse"))
635
			filename = tempFile.fileName();
Laurent Montel's avatar
Laurent Montel committed
636
		else if (mimeType == QLatin1String("application/x-kolf"))
637
			loadedGame = tempFile.fileName();
638
639
640
641
642
643
		else
		{
			closeGame();
			return;
		}

644
		QTimer::singleShot(10, this, &KolfWindow::startNewGame);
645
646
647
648
649
	}
	else
		closeGame();
}

650
void KolfWindow::newPlayersTurn(Player *player)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
651
{
652
	tempStatusBarText = i18n("%1's turn", player->name());
Jason Katz-Brown's avatar
Jason Katz-Brown committed
653
654

	if (showInfoAction->isChecked())
Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
655
		statusBar()->showMessage(tempStatusBarText, 5 * 1000);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
656
	else
Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
657
		statusBar()->showMessage(tempStatusBarText);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
658

659
	scoreboard->setCurrentCell(player->id() - 1, game->currentHole() - 1);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
660
661
}

662
void KolfWindow::newStatusText(const QString &text)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
663
664
{
	if (text.isEmpty())
Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
665
		statusBar()->showMessage(tempStatusBarText);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
666
	else
Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
667
		statusBar()->showMessage(text);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
668
669
}

670
void KolfWindow::editingStarted()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
671
672
{
	delete editor;
673
	editor = new Editor(m_itemFactory, dummy);
Laurent Montel's avatar
Laurent Montel committed
674
	editor->setObjectName( QStringLiteral( "Editor" ) );
675
676
677
678
	connect(editor, &Editor::addNewItem, game, &KolfGame::addNewObject);
	connect(editor, &Editor::changed, game, &KolfGame::setModified);
	connect(editor, &Editor::addNewItem, this, &KolfWindow::setHoleFocus);
	connect(game, &KolfGame::newSelectedItem, editor, &Editor::setItem);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
679
680
681
682
683
684
685
686

	scoreboard->hide();

	layout->addWidget(editor, 1, 0);
	editor->show();

	clearHoleAction->setEnabled(true);
	newHoleAction->setEnabled(true);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
687
	setHoleOtherEnabled(false);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
688
689
690
691

	game->setFocus();
}

692
void KolfWindow::editingEnded()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
693
694
{
	delete editor;
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
695
	editor = nullptr;
Jason Katz-Brown's avatar
Jason Katz-Brown committed
696
697
698
699
700
701

	if (scoreboard)
		scoreboard->show();

	clearHoleAction->setEnabled(false);
	newHoleAction->setEnabled(false);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
702
	setHoleOtherEnabled(true);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
703
704
705
706
707

	if (game)
		game->setFocus();
}

708
void KolfWindow::inPlayStart()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
709
710
{
	setEditingEnabled(false);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
711
	setHoleOtherEnabled(false);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
712
713
714
	setHoleMovementEnabled(false);
}

715
void KolfWindow::inPlayEnd()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
716
717
{
	setEditingEnabled(true);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
718
	setHoleOtherEnabled(true);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
719
720
721
	setHoleMovementEnabled(true);
}

722
void KolfWindow::maxStrokesReached(const QString &name)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
723
{
724
	KMessageBox::sorry(this, i18n("%1's score has reached the maximum for this hole.", name));
Jason Katz-Brown's avatar
Jason Katz-Brown committed
725
726
}

727
void KolfWindow::updateHoleMenu(int largest)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
728
729
730
731
732
733
734
735
736
737
738
{
	QStringList items;
	for (int i = 1; i <= largest; ++i)
		items.append(QString::number(i));

	// setItems for some reason enables the action
	bool shouldbe = holeAction->isEnabled();
	holeAction->setItems(items);
	holeAction->setEnabled(shouldbe);
}

739
void KolfWindow::setHoleMovementEnabled(bool yes)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
740
741
742
743
744
745
746
747
748
749
{
	if (competition)
		yes = false;

	holeAction->setEnabled(yes);

	nextAction->setEnabled(yes);
	prevAction->setEnabled(yes);
	firstAction->setEnabled(yes);
	lastAction->setEnabled(yes);
750
	randAction->setEnabled(yes);
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
751
752
}

753
void KolfWindow::setHoleOtherEnabled(bool yes)
Jason Katz-Brown's avatar
   
Jason Katz-Brown committed
754
755
756
{
	if (competition)
		yes = false;
Jason Katz-Brown's avatar
Jason Katz-Brown committed
757
758

	resetHoleAction->setEnabled(yes);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
759
	undoShotAction->setEnabled(yes);
760
	//replayShotAction->setEnabled(yes);
Jason Katz-Brown's avatar
Jason Katz-Brown committed
761
762
}

763
void KolfWindow::setEditingEnabled(bool yes)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
764
765
766
767
{
	editingAction->setEnabled(competition? false : yes);
}

768
void KolfWindow::checkEditing()
769
770
771
772
{
	editingAction->setChecked(true);
}

773
void KolfWindow::updateModified(bool mod)
774
775
776
777
778
{
	courseModified = mod;
	titleChanged(title);
}

779
void KolfWindow::titleChanged(const QString &newTitle)
780
{
781
782
	title = newTitle;
	setCaption(title, courseModified);
783
784
}

785
void KolfWindow::useMouseChanged(bool yes)
786
{
Laurent Montel's avatar
Laurent Montel committed
787
	KConfigGroup configGroup(KSharedConfig::openConfig(), "Settings"); configGroup.writeEntry("useMouse", yes); configGroup.sync();
788
789
}

790
void KolfWindow::useAdvancedPuttingChanged(bool yes)
791
{
Laurent Montel's avatar
Laurent Montel committed
792
	KConfigGroup configGroup(KSharedConfig::openConfig(), "Settings"); configGroup.writeEntry("useAdvancedPutting", yes); configGroup.sync();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
793
794
}

795
void KolfWindow::showInfoChanged(bool yes)
796
{
Laurent Montel's avatar
Laurent Montel committed
797
	KConfigGroup configGroup(KSharedConfig::openConfig(), "Settings"); configGroup.writeEntry("showInfo", yes); configGroup.sync();
798
799
}

800
void KolfWindow::showGuideLineChanged(bool yes)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
801
{
Laurent Montel's avatar
Laurent Montel committed
802
	KConfigGroup configGroup(KSharedConfig::openConfig(), "Settings"); configGroup.writeEntry("showGuideLine", yes); configGroup.sync();
803
804
}

805
void KolfWindow::soundChanged(bool yes)
Jason Katz-Brown's avatar
Jason Katz-Brown committed
806
{
Laurent Montel's avatar
Laurent Montel committed
807
	KConfigGroup configGroup(KSharedConfig::openConfig(), "Settings"); configGroup.writeEntry("sound", yes); configGroup.sync();
Jason Katz-Brown's avatar
Jason Katz-Brown committed
808
809
}

810
void KolfWindow::enableAllMessages()
Jason Katz-Brown's avatar
Jason Katz-Brown committed
811
812
813
814
{
	KMessageBox::enableAllMessages();
}

815
void KolfWindow::setCurrentHole(int hole)
816
{
817
	if (!holeAction || holeAction->items().count() < hole)
818
		return;
819
820
821
822
	// Golf is 1-based, KListAction is 0-based
	holeAction->setCurrentItem(hole - 1);
}

Laurent Montel's avatar
Laurent Montel committed
823