Frontend:
authorsmxx
Mon, 01 Mar 2010 12:55:54 +0000
changeset 2898 c53636f556f8
parent 2897 5eda7b3cc24f
child 2899 2608f6919da2
Frontend: * Added language selection to options menu to allow using other languages than the one detected by Qt
QTfrontend/gameuiconfig.cpp
QTfrontend/gameuiconfig.h
QTfrontend/main.cpp
QTfrontend/pages.cpp
QTfrontend/pages.h
--- a/QTfrontend/gameuiconfig.cpp	Mon Mar 01 12:20:38 2010 +0000
+++ b/QTfrontend/gameuiconfig.cpp	Mon Mar 01 12:55:54 2010 +0000
@@ -39,7 +39,7 @@
 	//Form->resize(value("window/width", 640).toUInt(), value("window/height", 450).toUInt());
 	resizeToConfigValues();
 
-	Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/WeaponTooltip", true).toBool());
+	Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltip", true).toBool());
 
 	int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString());
 	Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t);
@@ -85,6 +85,8 @@
         Form->ui.pageOptions->CBAutoUpdate->setChecked(value("misc/autoUpdate", true).toBool());
 #endif
 
+	Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", QLocale::system().name())));
+
 	depth = QApplication::desktop()->depth();
 	if (depth < 16) depth = 16;
 	else if (depth > 16) depth = 32;
@@ -115,7 +117,7 @@
 
 	setValue("video/frontendeffects", isFrontendEffects());
 
-	setValue("misc/WeaponTooltip", isWeaponTooltip());
+	setValue("misc/weaponTooltip", isWeaponTooltip());
 
 	bool ffscr = isFrontendFullscreen();
 	setValue("video/frontendfullscreen", ffscr);
@@ -147,6 +149,7 @@
 
 	setValue("misc/altdamage", isAltDamageEnabled());
 	setValue("misc/appendTimeToRecords", appendDateTimeToRecordName());
+	setValue("misc/locale", language());
 
 #ifdef SPARKLE_ENABLED
         setValue("misc/autoUpdate", isAutoUpdateEnabled());
@@ -154,6 +157,11 @@
     Form->gameSettings->sync();
 }
 
+QString GameUIConfig::language()
+{
+	return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString();
+}
+
 QRect GameUIConfig::vid_Resolution()
 {
 	QRect result(0, 0, 640, 480);
--- a/QTfrontend/gameuiconfig.h	Mon Mar 01 12:20:38 2010 +0000
+++ b/QTfrontend/gameuiconfig.h	Mon Mar 01 12:55:54 2010 +0000
@@ -37,6 +37,7 @@
 	bool vid_Fullscreen();
 	bool isSoundEnabled();
 	bool isFrontendSoundEnabled();
+	QString language();
 #ifdef _WIN32
 	bool isSoundHardware();
 #endif
--- a/QTfrontend/main.cpp	Mon Mar 01 12:20:38 2010 +0000
+++ b/QTfrontend/main.cpp	Mon Mar 01 12:55:54 2010 +0000
@@ -23,6 +23,7 @@
 #include <QPlastiqueStyle>
 #include <QRegExp>
 #include <QMap>
+#include <QSettings>
 
 #include "hwform.h"
 #include "hwconsts.h"
@@ -321,6 +322,7 @@
 		}
 	}
 
+
 	datadir->cd(bindir->absolutePath());
 	datadir->cd(*cDataDir);
 	if(!datadir->cd("hedgewars/Data")) {
@@ -331,11 +333,7 @@
 		return 1;
 	}
 
-	QTranslator Translator;
-	Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
-	app.installTranslator(&Translator);
-
-	Themes = new QStringList();
+	/*Themes = new QStringList();
 	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
 	if (themesfile.open(QIODevice::ReadOnly)) {
 		QTextStream stream(&themesfile);
@@ -347,14 +345,29 @@
 		themesfile.close();
 	} else {
 		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
-	}
+	}*/
 
 	QDir tmpdir;
 	tmpdir.cd(datadir->absolutePath());
+	tmpdir.cd("Themes");
+	tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
+	Themes = new QStringList(tmpdir.entryList(QStringList("*")));
+
+	tmpdir.cd(datadir->absolutePath());
 	tmpdir.cd("Maps");
 	tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
 	mapList = new QStringList(tmpdir.entryList(QStringList("*")));
 
+
+	QTranslator Translator;
+	{
+		QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
+		
+		Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + settings.value("misc/locale", QLocale::system().name()).toString());
+		app.installTranslator(&Translator);
+	}
+
+
 	HWForm *Form = new HWForm();
 
 
--- a/QTfrontend/pages.cpp	Mon Mar 01 12:20:38 2010 +0000
+++ b/QTfrontend/pages.cpp	Mon Mar 01 12:55:54 2010 +0000
@@ -435,18 +435,36 @@
             editNetNick->setText(QLineEdit::tr("unnamed"));
             MiscLayout->addWidget(editNetNick, 0, 1);
 
+            QLabel *labelLanguage = new QLabel(groupMisc);
+            labelLanguage->setText(QLabel::tr("Locale") + " *");
+            MiscLayout->addWidget(labelLanguage, 1, 0);
+
+            CBLanguage = new QComboBox(groupMisc);
+            QDir tmpdir;
+            tmpdir.cd(datadir->absolutePath());
+            tmpdir.cd("Locale");
+            tmpdir.setFilter(QDir::Files);
+            QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm"));
+            for(int i = 0; i < locs.count(); i++)
+            {
+                QLocale loc(locs[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1"));
+                CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
+            }
+
+            MiscLayout->addWidget(CBLanguage, 1, 1);
+
             CBAltDamage = new QCheckBox(groupMisc);
             CBAltDamage->setText(QCheckBox::tr("Alternative damage show"));
-            MiscLayout->addWidget(CBAltDamage, 1, 0, 1, 2);
+            MiscLayout->addWidget(CBAltDamage, 2, 0, 1, 2);
 
             CBNameWithDate = new QCheckBox(groupMisc);
             CBNameWithDate->setText(QCheckBox::tr("Append date and time to record file name"));
-            MiscLayout->addWidget(CBNameWithDate, 2, 0, 1, 2);
+            MiscLayout->addWidget(CBNameWithDate, 3, 0, 1, 2);
 
 #ifdef SPARKLE_ENABLED
             CBAutoUpdate = new QCheckBox(groupMisc);
             CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup"));
-            MiscLayout->addWidget(CBAutoUpdate, 3, 0, 1, 2);
+            MiscLayout->addWidget(CBAutoUpdate, 4, 0, 1, 2);
 #endif
 
             gbTBLayout->addWidget(groupMisc, 2, 0);
@@ -467,7 +485,7 @@
             GBAlayout->addWidget(CBFrontendFullscreen);
 
             CBFrontendEffects = new QCheckBox(AGGroupBox);
-            CBFrontendEffects->setText(QCheckBox::tr("Frontend effects (requires restart)"));
+            CBFrontendEffects->setText(QCheckBox::tr("Frontend effects") + " *");
             GBAlayout->addWidget(CBFrontendEffects);
 
             CBEnableFrontendSound = new QCheckBox(AGGroupBox);
@@ -542,6 +560,16 @@
             CBShowFPS->setText(QCheckBox::tr("Show FPS"));
             GBAlayout->addWidget(CBShowFPS);
 
+            hr = new QFrame(AGGroupBox);
+            hr->setFrameStyle(QFrame::HLine);
+            hr->setLineWidth(3);
+            hr->setFixedHeight(12);
+            GBAlayout->addWidget(hr);
+
+	            QLabel *restartNote = new QLabel(this);
+            restartNote->setText(QString("* ") + QLabel::tr("Restart game to apply"));
+            GBAlayout->addWidget(restartNote);
+
             gbTBLayout->addWidget(AGGroupBox, 0, 1, 3, 1);
         }
 
--- a/QTfrontend/pages.h	Mon Mar 01 12:20:38 2010 +0000
+++ b/QTfrontend/pages.h	Mon Mar 01 12:55:54 2010 +0000
@@ -206,6 +206,7 @@
 	QPushButton *WeaponEdit;
 	QComboBox *WeaponsName;
 	QCheckBox *WeaponTooltip;
+	QComboBox *CBLanguage;
 
 	QPushButton *BtnBack;
 	IconedGroupBox *teamsBox;