Index: src/mainwindow.cpp
===================================================================
--- src/mainwindow.cpp	(revision 5587b87fac8fd2762db0159e7b97beeb76bf5b9c)
+++ src/mainwindow.cpp	(revision 899d1b8e15f517c4ab2c4edbff5fa53650a2e936)
@@ -31,15 +31,25 @@
 	: QMainWindow(parent)
 {
+	settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
+	loadLanguage();
 	setupUi(this);
-	settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
+#ifndef Q_OS_WINCE
+	printer = new QPrinter();
+#endif // Q_OS_WINCE
+	groupSettingsLanguageList = new QActionGroup(this);
+	loadLangList();
 	spinCities->setValue(settings->value("NumCities",5).toInt());
-	connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
-	connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
-#ifndef Q_OS_WINCE
-	connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(PrintSetup()));
-#endif // Q_OS_WINCE
-	connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve()));
-	connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random()));
-	connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int)));
+	actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
+	connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
+	connect(actionSettingsPreferences,SIGNAL(triggered()),this,SLOT(actionSettingsPreferencesTriggered()));
+	connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
+	connect(groupSettingsLanguageList,SIGNAL(triggered(QAction *)),this,SLOT(groupSettingsLanguageListTriggered(QAction *)));
+	connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(actionHelpAboutTriggered()));
+#ifndef Q_OS_WINCE
+	connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(actionFilePrintSetupTriggered()));
+#endif // Q_OS_WINCE
+	connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
+	connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked()));
+	connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
 QRect rect = geometry();
 #ifdef Q_OS_WINCE
@@ -73,5 +83,51 @@
 }
 
-void MainWindow::CitiesNumberChanged(int n)
+bool MainWindow::loadLanguage()
+{
+// i18n
+bool ad = settings->value("Language","").toString().isEmpty();
+QString lang = settings->value("Language",QLocale::system().name()).toString();
+static QTranslator *qtTranslator;
+	if (qtTranslator) {
+		qApp->removeTranslator(qtTranslator);
+		delete qtTranslator;
+		qtTranslator = NULL;
+	}
+	qtTranslator = new QTranslator();
+	if (lang.compare("en") && !lang.startsWith("en_")) {
+		// Trying to load system Qt library translation...
+		if (qtTranslator->load("qt_" + lang,QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+			qApp->installTranslator(qtTranslator);
+		else
+			// No luck. Let's try to load bundled one.
+			if (qtTranslator->load("qt_" + lang,"i18n"))
+				qApp->installTranslator(qtTranslator);
+			else {
+				delete qtTranslator;
+				qtTranslator = NULL;
+			}
+	}
+	// Now let's load application translation.
+static QTranslator *translator;
+	if (translator) {
+		qApp->removeTranslator(translator);
+		delete translator;
+	}
+	translator = new QTranslator();
+	if (lang.compare("en") && !lang.startsWith("en_")) {
+		if (translator->load(lang,"i18n"))
+			qApp->installTranslator(translator);
+		else {
+			if (!ad)
+				QMessageBox(QMessageBox::Warning,trUtf8("Language change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec();
+			delete translator;
+			translator = NULL;
+			return false;
+		}
+	}
+	return true;
+}
+
+void MainWindow::spinCitiesValueChanged(int n)
 {
 #ifdef Q_OS_WINCE
@@ -88,5 +144,11 @@
 }
 
-void MainWindow::ChangeSettings()
+
+void MainWindow::actionFileNewTriggered()
+{
+	tspmodel->clear();
+}
+
+void MainWindow::actionSettingsPreferencesTriggered()
 {
 SettingsDialog sd(this);
@@ -95,12 +157,14 @@
 
 #ifndef Q_OS_WINCE
-void MainWindow::PrintSetup()
-{
-QPrintDialog pd;
+void MainWindow::actionFilePrintSetupTriggered()
+{
+QPrintDialog pd(printer,this);
+	pd.setOption(QAbstractPrintDialog::PrintSelection,false);
+	pd.setOption(QAbstractPrintDialog::PrintPageRange,false);
 	pd.exec();
 }
 #endif // Q_OS_WINCE
 
-void MainWindow::Random()
+void MainWindow::buttonRandomClicked()
 {
 	tspmodel->randomize();
@@ -111,5 +175,5 @@
 }
 
-void MainWindow::Solve()
+void MainWindow::buttonSolveClicked()
 {
 	// TODO: Task solving goes here :-)
@@ -136,5 +200,5 @@
 }
 
-void MainWindow::showAbout()
+void MainWindow::actionHelpAboutTriggered()
 {
 	// TODO: Normal about window :-)
@@ -149,4 +213,54 @@
 }
 
+void MainWindow::loadLangList()
+{
+QSettings langinfo("i18n/languages.ini",QSettings::IniFormat);
+	langinfo.setIniCodec("UTF-8");
+QDir dir("i18n","*.qm",QDir::Name | QDir::IgnoreCase,QDir::Files);
+	if (!dir.exists())
+		return;
+QFileInfoList langs = dir.entryInfoList();
+	if (langs.size() <= 0)
+		return;
+	menuSettingsLanguage->addSeparator();
+QAction *a;
+	for (int k = 0; k < langs.size(); k++) {
+		QFileInfo lang = langs.at(k);
+		if (!lang.completeBaseName().startsWith("qt_")) {
+			a = menuSettingsLanguage->addAction(langinfo.value(lang.completeBaseName() + "/NativeName",lang.completeBaseName()).toString());
+			a->setData(lang.completeBaseName());
+			a->setCheckable(true);
+			a->setActionGroup(groupSettingsLanguageList);
+			if (settings->value("Language",QLocale::system().name()).toString().startsWith(lang.completeBaseName()))
+				a->setChecked(true);
+		}
+	}
+}
+
+void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked)
+{
+	if (checked) {
+		settings->remove("Language");
+		QMessageBox(QMessageBox::Information,trUtf8("Language change"),trUtf8("Language will be autodetected on next application start."),QMessageBox::Ok,this).exec();
+	} else
+		settings->setValue("Language",groupSettingsLanguageList->checkedAction()->data().toString());
+}
+
+void MainWindow::groupSettingsLanguageListTriggered(QAction *action)
+{
+	if (actionSettingsLanguageAutodetect->isChecked()) {
+		// We have language autodetection. It needs to be disabled to change language.
+		if (QMessageBox(QMessageBox::Question,trUtf8("Language change"),trUtf8("You have language autodetection turned on.\nIt needs to be off.\nDo you wish to turn it off?"),QMessageBox::Yes | QMessageBox::No,this).exec() == QMessageBox::Yes) {
+			actionSettingsLanguageAutodetect->trigger();
+		} else
+			return;
+	}
+	if (loadLanguage()) {
+		settings->setValue("Language",action->data().toString());
+		retranslateUi(this);
+	} else {
+	}
+}
+
 void MainWindow::closeEvent(QCloseEvent *event)
 {
