2008-01-25 19:42:59 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Eliot
|
2009-01-24 18:44:56 +01:00
|
|
|
* Copyright (C) 2008-2009 Olivier Teulière
|
2008-01-25 19:42:59 +01:00
|
|
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
|
|
|
*
|
|
|
|
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-01-27 00:03:32 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-25 19:42:59 +01:00
|
|
|
#include <QtCore/QSettings>
|
2008-01-26 17:58:46 +01:00
|
|
|
#include <QtGui/QFileDialog>
|
2008-09-05 23:31:30 +02:00
|
|
|
#include <QtGui/QMessageBox>
|
2011-07-28 22:55:48 +02:00
|
|
|
#include <QtCore/QStringList>
|
2008-01-25 19:42:59 +01:00
|
|
|
|
|
|
|
#include "prefs_dialog.h"
|
2008-09-05 23:31:30 +02:00
|
|
|
#include "game_exception.h"
|
2008-01-25 19:42:59 +01:00
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
2008-01-26 17:58:46 +01:00
|
|
|
const QString PrefsDialog::kINTF_ALIGN_HISTORY = "Interface/AlignHistory";
|
|
|
|
const QString PrefsDialog::kINTF_DIC_PATH = "Interface/DicPath";
|
2011-07-28 22:55:48 +02:00
|
|
|
const QString PrefsDialog::kINTF_DEFINITIONS_SITE_URL = "Interface/DefinitionsSiteUrl";
|
2009-01-04 18:39:27 +01:00
|
|
|
const QString PrefsDialog::kINTF_SHOW_TILES_POINTS = "Interface/ShowTilesPoints";
|
2008-12-08 22:37:02 +01:00
|
|
|
const QString PrefsDialog::kINTF_WARN_REPLAY_TURN = "Interface/WarnReplayTurn";
|
2008-12-08 22:38:12 +01:00
|
|
|
const QString PrefsDialog::kINTF_SHOW_TOOLBAR = "Interface/ShowToolBar";
|
2008-12-14 14:20:38 +01:00
|
|
|
const QString PrefsDialog::kINTF_LINK_TRAINING_7P1 = "Interface/LinkTrainingRackWith7P1";
|
2011-12-30 19:33:48 +01:00
|
|
|
const QString PrefsDialog::kINTF_DEFAULT_AI_LEVEL = "Interface/DefaultAiLevel";
|
2012-01-26 20:57:43 +01:00
|
|
|
const QString PrefsDialog::kINTF_TIMER_TOTAL_DURATION = "Interface/TimerTotalDuration";
|
|
|
|
const QString PrefsDialog::kINTF_TIMER_ALERT_DURATION = "Interface/TimerAlertDuration";
|
2011-07-28 22:55:48 +02:00
|
|
|
const QString PrefsDialog::kDEFAULT_DEF_SITE = "http://fr.wiktionary.org/wiki/%w";
|
2008-01-25 19:42:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
PrefsDialog::PrefsDialog(QWidget *iParent)
|
|
|
|
: QDialog(iParent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2012-01-26 20:57:43 +01:00
|
|
|
lineEditDefSite->setToolTip(_q("URL of the site used to display word definitions.\n"
|
|
|
|
"In the URL, %w will be replaced with the word in lower case. Examples:\n"
|
|
|
|
"\thttp://fr.wiktionary.org/wiki/%w\n"
|
|
|
|
"\thttp://en.wiktionary.org/wiki/%w\n"
|
|
|
|
"\thttp://images.google.com/images?q=%w"));
|
|
|
|
spinBoxDefaultLevel->setToolTip(_q("Default level for Eliot, "
|
|
|
|
"used when creating a new game.\n"
|
|
|
|
"Accepted range: [0-100]"));
|
|
|
|
spinBoxTimerTotal->setToolTip(_q("Total duration of the timer, in seconds.\n"
|
|
|
|
"Changing this value will reset the timer."));
|
|
|
|
spinBoxTimerAlert->setToolTip(_q("Number of remaining seconds when an alert is triggered.\n"
|
|
|
|
"Use a value of -1 to disable the alert.\n"
|
|
|
|
"Changing this value will reset the timer."));
|
2008-01-25 19:42:59 +01:00
|
|
|
|
2008-09-05 23:31:30 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Interface settings
|
|
|
|
QSettings qs(ORGANIZATION, PACKAGE_NAME);
|
|
|
|
lineEditIntfDicPath->setText(qs.value(kINTF_DIC_PATH, "").toString());
|
2011-07-28 22:55:48 +02:00
|
|
|
lineEditDefSite->setText(qs.value(kINTF_DEFINITIONS_SITE_URL,
|
|
|
|
kDEFAULT_DEF_SITE).toString());
|
2008-12-08 22:37:02 +01:00
|
|
|
checkBoxIntfAlignHistory->setChecked(qs.value(kINTF_ALIGN_HISTORY).toBool());
|
2009-01-04 18:39:27 +01:00
|
|
|
bool showPoints = qs.value(kINTF_SHOW_TILES_POINTS, true).toBool();
|
|
|
|
checkBoxIntfShowPoints->setChecked(showPoints);
|
2008-12-08 22:38:12 +01:00
|
|
|
bool warnReplayTurn = qs.value(kINTF_WARN_REPLAY_TURN, true).toBool();
|
|
|
|
checkBoxIntfWarnReplayTurn->setChecked(warnReplayTurn);
|
2008-12-14 14:20:38 +01:00
|
|
|
bool linkTraining7P1 = qs.value(kINTF_LINK_TRAINING_7P1, false).toBool();
|
|
|
|
checkBoxIntfLinkTraining7P1->setChecked(linkTraining7P1);
|
2011-12-30 19:33:48 +01:00
|
|
|
int defaultAiLevel = qs.value(kINTF_DEFAULT_AI_LEVEL, 100).toInt();
|
|
|
|
spinBoxDefaultLevel->setValue(defaultAiLevel);
|
2012-01-26 20:57:43 +01:00
|
|
|
int timerTotal = qs.value(kINTF_TIMER_TOTAL_DURATION, 180).toInt();
|
|
|
|
spinBoxTimerTotal->setValue(timerTotal);
|
|
|
|
int timerAlert = qs.value(kINTF_TIMER_ALERT_DURATION, 30).toInt();
|
|
|
|
spinBoxTimerAlert->setValue(timerAlert);
|
2008-09-05 23:31:30 +02:00
|
|
|
|
|
|
|
// Duplicate settings
|
2008-09-22 23:21:38 +02:00
|
|
|
checkBoxDuplRefuseInvalid->setChecked(Settings::Instance().getBool("duplicate.reject-invalid"));
|
|
|
|
spinBoxDuplSoloPlayers->setValue(Settings::Instance().getInt("duplicate.solo-players"));
|
|
|
|
spinBoxDuplSoloValue->setValue(Settings::Instance().getInt("duplicate.solo-value"));
|
2008-12-14 14:20:38 +01:00
|
|
|
|
|
|
|
// Freegame settings
|
|
|
|
checkBoxFreeRefuseInvalid->setChecked(Settings::Instance().getBool("freegame.reject-invalid"));
|
|
|
|
|
|
|
|
// Training settings
|
2009-01-22 19:30:22 +01:00
|
|
|
spinBoxTrainSearchLimit->setValue(Settings::Instance().getInt("training.search-limit"));
|
2008-09-05 23:31:30 +02:00
|
|
|
}
|
|
|
|
catch (GameException &e)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, _q("%1 error").arg(PACKAGE_NAME),
|
|
|
|
_q("Cannot load preferences: %1").arg(e.what()));
|
|
|
|
}
|
2008-01-25 19:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrefsDialog::accept()
|
|
|
|
{
|
|
|
|
updateSettings();
|
2008-09-22 23:21:38 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Settings::Instance().save();
|
|
|
|
}
|
|
|
|
catch (GameException &e)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, _q("%1 error").arg(PACKAGE_NAME),
|
2009-02-19 22:56:41 +01:00
|
|
|
_q("Cannot save preferences: %1").arg(e.what()));
|
2008-09-22 23:21:38 +02:00
|
|
|
}
|
2008-01-25 19:42:59 +01:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrefsDialog::updateSettings()
|
|
|
|
{
|
2008-01-26 17:58:46 +01:00
|
|
|
bool shouldEmitUpdate = false;
|
|
|
|
|
2008-09-05 23:31:30 +02:00
|
|
|
try
|
2008-01-26 17:58:46 +01:00
|
|
|
{
|
2008-09-05 23:31:30 +02:00
|
|
|
// Interface settings
|
|
|
|
QSettings qs(ORGANIZATION, PACKAGE_NAME);
|
2008-12-08 22:37:02 +01:00
|
|
|
qs.setValue(kINTF_DIC_PATH, lineEditIntfDicPath->text());
|
2011-07-28 22:55:48 +02:00
|
|
|
qs.setValue(kINTF_DEFINITIONS_SITE_URL, lineEditDefSite->text());
|
2009-01-04 18:39:27 +01:00
|
|
|
if (qs.value(kINTF_ALIGN_HISTORY, true).toBool() != checkBoxIntfAlignHistory->isChecked())
|
2008-09-05 23:31:30 +02:00
|
|
|
{
|
|
|
|
// We need to redraw the history widget
|
|
|
|
shouldEmitUpdate = true;
|
|
|
|
qs.setValue(kINTF_ALIGN_HISTORY, checkBoxIntfAlignHistory->isChecked());
|
|
|
|
}
|
2009-01-04 18:39:27 +01:00
|
|
|
if (qs.value(kINTF_SHOW_TILES_POINTS, true).toBool() != checkBoxIntfShowPoints->isChecked())
|
|
|
|
{
|
|
|
|
// We need to redraw the board
|
|
|
|
shouldEmitUpdate = true;
|
|
|
|
qs.setValue(kINTF_SHOW_TILES_POINTS, checkBoxIntfShowPoints->isChecked());
|
|
|
|
}
|
2008-12-08 22:37:02 +01:00
|
|
|
qs.setValue(kINTF_WARN_REPLAY_TURN, checkBoxIntfWarnReplayTurn->isChecked());
|
2009-01-04 18:39:27 +01:00
|
|
|
if (qs.value(kINTF_LINK_TRAINING_7P1, false).toBool() != checkBoxIntfLinkTraining7P1->isChecked())
|
2008-12-14 14:20:38 +01:00
|
|
|
{
|
|
|
|
// We need to (dis)connect the training widget with the dictionary
|
|
|
|
// tools window
|
|
|
|
shouldEmitUpdate = true;
|
|
|
|
qs.setValue(kINTF_LINK_TRAINING_7P1, checkBoxIntfLinkTraining7P1->isChecked());
|
|
|
|
}
|
2011-12-30 19:33:48 +01:00
|
|
|
if (qs.value(kINTF_DEFAULT_AI_LEVEL, 100).toInt() != spinBoxDefaultLevel->value())
|
|
|
|
{
|
|
|
|
// We need to change the default AI level
|
|
|
|
shouldEmitUpdate = true;
|
|
|
|
qs.setValue(kINTF_DEFAULT_AI_LEVEL, spinBoxDefaultLevel->value());
|
|
|
|
}
|
2012-01-26 20:57:43 +01:00
|
|
|
if (qs.value(kINTF_TIMER_TOTAL_DURATION, 180).toInt() != spinBoxTimerTotal->value())
|
|
|
|
{
|
|
|
|
// We need to change the default AI level
|
|
|
|
shouldEmitUpdate = true;
|
|
|
|
qs.setValue(kINTF_TIMER_TOTAL_DURATION, spinBoxTimerTotal->value());
|
|
|
|
}
|
|
|
|
if (qs.value(kINTF_TIMER_ALERT_DURATION, 30).toInt() != spinBoxTimerAlert->value())
|
|
|
|
{
|
|
|
|
// We need to change the default AI level
|
|
|
|
shouldEmitUpdate = true;
|
|
|
|
qs.setValue(kINTF_TIMER_ALERT_DURATION, spinBoxTimerAlert->value());
|
|
|
|
}
|
2008-09-05 23:31:30 +02:00
|
|
|
|
|
|
|
// Duplicate settings
|
2008-09-22 23:21:38 +02:00
|
|
|
Settings::Instance().setBool("duplicate.reject-invalid",
|
2008-09-05 23:31:30 +02:00
|
|
|
checkBoxDuplRefuseInvalid->isChecked());
|
2008-09-22 23:21:38 +02:00
|
|
|
Settings::Instance().setInt("duplicate.solo-players",
|
2008-09-05 23:31:30 +02:00
|
|
|
spinBoxDuplSoloPlayers->value());
|
2008-09-22 23:21:38 +02:00
|
|
|
Settings::Instance().setInt("duplicate.solo-value",
|
2008-09-05 23:31:30 +02:00
|
|
|
spinBoxDuplSoloValue->value());
|
|
|
|
|
|
|
|
// Freegame settings
|
2008-09-22 23:21:38 +02:00
|
|
|
Settings::Instance().setBool("freegame.reject-invalid",
|
2008-09-05 23:31:30 +02:00
|
|
|
checkBoxFreeRefuseInvalid->isChecked());
|
|
|
|
|
|
|
|
// Training settings
|
2009-01-22 19:30:22 +01:00
|
|
|
Settings::Instance().setInt("training.search-limit",
|
|
|
|
spinBoxTrainSearchLimit->value());
|
2008-09-05 23:31:30 +02:00
|
|
|
}
|
|
|
|
catch (GameException &e)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, _q("%1 error").arg(PACKAGE_NAME),
|
|
|
|
_q("Cannot save preferences: %1").arg(e.what()));
|
|
|
|
}
|
2008-01-26 17:58:46 +01:00
|
|
|
|
|
|
|
if (shouldEmitUpdate)
|
2008-12-14 14:20:38 +01:00
|
|
|
emit prefsUpdated();
|
2008-01-25 19:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-26 17:58:46 +01:00
|
|
|
void PrefsDialog::on_pushButtonIntfDicBrowse_clicked()
|
|
|
|
{
|
|
|
|
QString fileName =
|
|
|
|
QFileDialog::getOpenFileName(this, _q("Choose a dictionary"), "", "*.dawg");
|
|
|
|
if (fileName != "")
|
|
|
|
lineEditIntfDicPath->setText(fileName);
|
|
|
|
}
|
|
|
|
|