Index: resources/tspsg.qrc
===================================================================
--- resources/tspsg.qrc	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ resources/tspsg.qrc	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -3,4 +3,5 @@
         <file>about.bmp</file>
         <file>icon.png</file>
+        <file>icons/back.png</file>
         <file>icons/button_cancel.png</file>
         <file>icons/button_ok.png</file>
Index: src/globals.h
===================================================================
--- src/globals.h	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/globals.h	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -38,4 +38,5 @@
 #define DEF_RAND_MIN 1
 #define DEF_RAND_MAX 10
+#define DEF_NUM_CITIES 5
 #define DEF_OFFSET 100
 #define DEF_FONT_FAMILY "Courier New"
@@ -56,4 +57,6 @@
 #define ZKT_VERSION quint8(1)
 
+// Maximum available number of cities
+#define MAX_NUM_CITIES 20
 // This value means infinity :-)
 #ifndef INFINITY
@@ -63,3 +66,9 @@
 #define INFSTR "---"
 
+// Let's check that default number of cities is sane (<= MAX_NUM_CITIES)
+#if DEF_NUM_CITIES > MAX_NUM_CITIES
+	#undef DEF_NUM_CITIES
+	#define DEF_NUM_CITIES MAX_NUM_CITIES
+#endif
+
 #endif // GLOBALS_H
Index: src/mainwindow.cpp
===================================================================
--- src/mainwindow.cpp	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/mainwindow.cpp	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -46,8 +46,9 @@
 	actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
 	loadLangList();
-	spinCities->setValue(settings->value("NumCities",5).toInt());
+	spinCities->setMaximum(MAX_NUM_CITIES);
 	actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
 	connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
 	connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered()));
+	connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered()));
 	connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered()));
 	connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered()));
@@ -62,7 +63,8 @@
 	connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
 	connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked()));
+	connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked()));
 	connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
+	setCentralWidget(tabWidget);
 QRect rect = geometry();
-	setCentralWidget(tabWidget);
 #ifndef Q_OS_WINCE
 	if (settings->value("SavePos",false).toBool()) {
@@ -82,22 +84,22 @@
 	qsrand(QDateTime().currentDateTime().toTime_t());
 	tspmodel = new CTSPModel();
-	tspmodel->setNumCities(spinCities->value());
-	taskView->setModel(tspmodel);
 	connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
 	connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged()));
 	connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged()));
-	if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) {
+	if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1))))
 		setFileName(QCoreApplication::arguments().at(1));
-		setWindowModified(false);
-	} else
+	else {
 		setFileName();
-#ifdef Q_OS_WINCE
+		spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
+	}
+	taskView->setModel(tspmodel);
+	setWindowModified(false);
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif // Q_OS_WINCE
 }
 
 void MainWindow::enableSolutionActions(bool enable)
 {
+	buttonSaveSolution->setEnabled(enable);
 	actionFileSaveAsSolution->setEnabled(enable);
 	solutionText->setEnabled(enable);
@@ -173,9 +175,6 @@
 void MainWindow::spinCitiesValueChanged(int n)
 {
-#ifdef Q_OS_WINCE
 int count = tspmodel->numCities();
-#endif // Q_OS_WINCE
 	tspmodel->setNumCities(n);
-#ifdef Q_OS_WINCE
 	if (n > count)
 		for (int k = count; k < n; k++) {
@@ -183,5 +182,4 @@
 			taskView->resizeRowToContents(k);
 		}
-#endif // Q_OS_WINCE
 }
 
@@ -204,8 +202,6 @@
 		return;
 	tspmodel->clear();
-#ifdef Q_OS_WINCE
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif
 	setFileName();
 	setWindowModified(false);
@@ -238,8 +234,6 @@
 	}
 	setFileName(files.first());
-#ifdef Q_OS_WINCE
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif
 	tabWidget->setCurrentIndex(0);
 	setWindowModified(false);
@@ -247,4 +241,16 @@
 	enableSolutionActions(false);
 	QApplication::restoreOverrideCursor();
+}
+
+void MainWindow::actionFileSaveTriggered()
+{
+	if ((fileName == trUtf8("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive)))
+		saveTask();
+	else {
+		QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+		if (tspmodel->saveTask(fileName))
+			setWindowModified(false);
+		QApplication::restoreOverrideCursor();
+	}
 }
 
@@ -350,8 +356,11 @@
 	tspmodel->randomize();
 	setWindowModified(true);
-#ifdef Q_OS_WINCE
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif // Q_OS_WINCE
+}
+
+void MainWindow::buttonBackToTaskClicked()
+{
+	tabWidget->setCurrentIndex(0);
 }
 
@@ -395,5 +404,5 @@
 	}
 CTSPSolver solver;
-sStep *root = solver.solve(spinCities->value(),matrix);
+sStep *root = solver.solve(n,matrix,this);
 	if (!root)
 		return;
@@ -542,4 +551,6 @@
 void MainWindow::numCitiesChanged(int nCities)
 {
+	blockSignals(true);
 	spinCities->setValue(nCities);
-}
+	blockSignals(false);
+}
Index: src/mainwindow.h
===================================================================
--- src/mainwindow.h	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/mainwindow.h	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -46,4 +46,5 @@
 	void actionFileNewTriggered();
 	void actionFileOpenTriggered();
+	void actionFileSaveTriggered();
 	void actionFileSaveAsTaskTriggered();
 	void actionFileSaveAsSolutionTriggered();
@@ -58,4 +59,5 @@
 	void buttonSolveClicked();
 	void buttonRandomClicked();
+	void buttonBackToTaskClicked();
 	void spinCitiesValueChanged(int);
 	void numCitiesChanged(int);
@@ -63,5 +65,7 @@
 private:
 	QSettings *settings;
+#ifndef Q_OS_WINCE
 	QPrinter *printer;
+#endif // Q_OS_WINCE
 	CTSPModel *tspmodel;
 	QString fileName;
Index: src/tspmodel.cpp
===================================================================
--- src/tspmodel.cpp	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/tspmodel.cpp	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -206,16 +206,18 @@
 	if (loadError(ds->status()))
 		return false;
-	// Cities number
+	// Number of cities
 quint16 size;
 	*ds >> size;
 	if (loadError(ds->status()))
 		return false;
-	if (size < 3) {
+	if ((size < 3) || (size > MAX_NUM_CITIES)) {
 		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
 		return false;
 	}
-	if (nCities != size)
+	if (nCities != size) {
+		setNumCities(size);
 		emit numCitiesChanged(size);
-	// Costs
+	}
+	// Travel costs
 	for (int r = 0; r < size; r++)
 		for (int c = 0; c < size; c++)
@@ -246,5 +248,5 @@
 		return false;
 	}
-	// Cities number
+	// Number of cities
 quint8 size;
 	ds->readRawData(reinterpret_cast<char *>(&size),1);
@@ -255,7 +257,9 @@
 		return false;
 	}
-	if (nCities != size)
+	if (nCities != size) {
+		setNumCities(size);
 		emit numCitiesChanged(size);
-	// Costs
+	}
+	// Travel costs
 double val;
 	for (int r = 0; r < 5; r++)
Index: src/tspmodel.h
===================================================================
--- src/tspmodel.h	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/tspmodel.h	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -54,6 +54,6 @@
 	quint16 nCities;
 	bool loadError(QDataStream::Status);
+	bool loadTSPT(QDataStream *);
 	bool loadZKT(QDataStream *);
-	bool loadTSPT(QDataStream *);
 	int rand(int, int) const;
 };
Index: src/tspsolver.cpp
===================================================================
--- src/tspsolver.cpp	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/tspsolver.cpp	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -97,5 +97,6 @@
 	for (int r = 0; r < nCities; r++)
 		for (int c = 0; c < nCities; c++)
-			if ((matrix[r][c] == 0) && !forbidden.values(r).contains(c)) {
+//			if ((matrix[r][c] == 0) && !forbidden.values(r).contains(c)) {
+			if (matrix[r][c] == 0) {
 				sum = findMinInRow(r,matrix,c) + findMinInCol(c,matrix,r);
 				if (sum > h) {
@@ -154,8 +155,8 @@
 int nRow, nCol;
 	while (route.size() < nCities) {
-		forbidden.clear();
+//		forbidden.clear();
 		step->alts = findCandidate(step->matrix,nRow,nCol,s);
 		while (hasSubCycles(nRow,nCol)) {
-			forbidden[nRow] = nCol;
+//			forbidden[nRow] = nCol;
 			step->matrix[nRow][nCol] = INFINITY;
 			step->price += align(step->matrix);
@@ -204,11 +205,11 @@
 	}
 
-	pd.reset();
+	if (!root && !pd.wasCanceled()) {
+		pd.reset();
+		QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("Unable to find solution.\nMaybe, this task has no solutions."),QMessageBox::Ok,parent).exec();
+	}
+
 	qApp->processEvents();
 
-	if (!root && !pd.wasCanceled()) {
-		QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("This task has no solution."),QMessageBox::Ok,parent).exec();
-	}
-
 	return root;
 }
Index: src/tspsolver.h
===================================================================
--- src/tspsolver.h	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/tspsolver.h	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -53,5 +53,5 @@
 	sStep *root;
 	QHash<int,int> route;
-	QHash<int,int> forbidden;
+//	QHash<int,int> forbidden;
 	double align(tMatrix &);
 	void cleanup();
Index: src/version.h
===================================================================
--- src/version.h	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ src/version.h	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -45,5 +45,5 @@
 #endif // BUILD_NUMBER == 65535
 
-// "Converting" number to string
+// "Converting" x to quoted string
 #define QUOTE_X(x) #x
 #define QUOTE(x) QUOTE_X(x)
Index: ui/mainwindow.ce.ui
===================================================================
--- ui/mainwindow.ce.ui	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ ui/mainwindow.ce.ui	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -10,10 +10,10 @@
     <x>0</x>
     <y>0</y>
-    <width>225</width>
-    <height>322</height>
+    <width>247</width>
+    <height>339</height>
    </rect>
   </property>
   <property name="windowTitle">
-   <string>Travelling Salesman Problem[*]</string>
+   <string>Travelling Salesman Problem</string>
   </property>
   <property name="windowIcon">
@@ -30,6 +30,6 @@
       <x>9</x>
       <y>9</y>
-      <width>207</width>
-      <height>248</height>
+      <width>221</width>
+      <height>261</height>
      </rect>
     </property>
@@ -112,7 +112,4 @@
           <property name="minimum">
            <number>3</number>
-          </property>
-          <property name="maximum">
-           <number>5</number>
           </property>
           <property name="value">
@@ -220,4 +217,58 @@
        </widget>
       </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QPushButton" name="buttonSaveSolution">
+          <property name="enabled">
+           <bool>false</bool>
+          </property>
+          <property name="cursor">
+           <cursorShape>PointingHandCursor</cursorShape>
+          </property>
+          <property name="statusTip">
+           <string>Save solution to a file</string>
+          </property>
+          <property name="text">
+           <string>Save Solution</string>
+          </property>
+          <property name="icon">
+           <iconset resource="../resources/tspsg.qrc">
+            <normaloff>:/images/icons/filesaveas.png</normaloff>:/images/icons/filesaveas.png</iconset>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="QPushButton" name="buttonBackToTask">
+          <property name="cursor">
+           <cursorShape>PointingHandCursor</cursorShape>
+          </property>
+          <property name="statusTip">
+           <string>Go back to Task tab</string>
+          </property>
+          <property name="text">
+           <string>Back to Task</string>
+          </property>
+          <property name="icon">
+           <iconset resource="../resources/tspsg.qrc">
+            <normaloff>:/images/icons/back.png</normaloff>:/images/icons/back.png</iconset>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
@@ -229,5 +280,5 @@
      <x>0</x>
      <y>0</y>
-     <width>225</width>
+     <width>247</width>
      <height>22</height>
     </rect>
@@ -247,5 +298,5 @@
      </property>
      <property name="title">
-      <string>Save &amp;As...</string>
+      <string>Save &amp;As</string>
      </property>
      <property name="icon">
@@ -363,5 +414,5 @@
    </property>
    <property name="statusTip">
-    <string>Save solution steps and graph</string>
+    <string>Save solution to a file</string>
    </property>
   </action>
@@ -437,4 +488,7 @@
     <string>Open help contents</string>
    </property>
+   <property name="shortcut">
+    <string>Ctrl+F1</string>
+   </property>
   </action>
   <action name="actionHelpContextual">
@@ -452,4 +506,7 @@
     <string>Open context help</string>
    </property>
+   <property name="shortcut">
+    <string>F1</string>
+   </property>
   </action>
   <action name="actionHelpAbout">
@@ -496,7 +553,4 @@
    <property name="statusTip">
     <string>Save task to file</string>
-   </property>
-   <property name="shortcut">
-    <string>Ctrl+S</string>
    </property>
   </action>
@@ -526,14 +580,11 @@
    </property>
    <property name="text">
+    <string notr="true">&amp;English</string>
+   </property>
+   <property name="iconText">
     <string notr="true">English</string>
    </property>
-   <property name="iconText">
-    <string notr="true">English</string>
-   </property>
   </action>
   <action name="actionFileSave">
-   <property name="enabled">
-    <bool>false</bool>
-   </property>
    <property name="icon">
     <iconset resource="../resources/tspsg.qrc">
@@ -548,4 +599,7 @@
    <property name="statusTip">
     <string>Save current task</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+S</string>
    </property>
   </action>
@@ -589,4 +643,20 @@
    </hints>
   </connection>
+  <connection>
+   <sender>buttonBackToTask</sender>
+   <signal>clicked()</signal>
+   <receiver>actionFileSaveAsSolution</receiver>
+   <slot>trigger()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>172</x>
+     <y>299</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>-1</x>
+     <y>-1</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
 </ui>
Index: ui/mainwindow.ui
===================================================================
--- ui/mainwindow.ui	(revision e96fad30799e6030d28398123e313210f9a443b0)
+++ ui/mainwindow.ui	(revision aaf2113307a1f7e0af077955ae20083a3d6c9128)
@@ -7,6 +7,6 @@
     <x>0</x>
     <y>0</y>
-    <width>491</width>
-    <height>400</height>
+    <width>502</width>
+    <height>407</height>
    </rect>
   </property>
@@ -24,6 +24,6 @@
       <x>0</x>
       <y>0</y>
-      <width>481</width>
-      <height>311</height>
+      <width>287</width>
+      <height>298</height>
      </rect>
     </property>
@@ -100,7 +100,4 @@
           <property name="minimum">
            <number>3</number>
-          </property>
-          <property name="maximum">
-           <number>5</number>
           </property>
           <property name="value">
@@ -208,4 +205,58 @@
        </widget>
       </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QPushButton" name="buttonSaveSolution">
+          <property name="enabled">
+           <bool>false</bool>
+          </property>
+          <property name="cursor">
+           <cursorShape>PointingHandCursor</cursorShape>
+          </property>
+          <property name="statusTip">
+           <string>Save solution to a file</string>
+          </property>
+          <property name="text">
+           <string>Save Solution</string>
+          </property>
+          <property name="icon">
+           <iconset resource="../resources/tspsg.qrc">
+            <normaloff>:/images/icons/filesaveas.png</normaloff>:/images/icons/filesaveas.png</iconset>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="QPushButton" name="buttonBackToTask">
+          <property name="cursor">
+           <cursorShape>PointingHandCursor</cursorShape>
+          </property>
+          <property name="statusTip">
+           <string>Go back to Task tab</string>
+          </property>
+          <property name="text">
+           <string>Back to Task</string>
+          </property>
+          <property name="icon">
+           <iconset resource="../resources/tspsg.qrc">
+            <normaloff>:/images/icons/back.png</normaloff>:/images/icons/back.png</iconset>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
@@ -217,5 +268,5 @@
      <x>0</x>
      <y>0</y>
-     <width>491</width>
+     <width>502</width>
      <height>22</height>
     </rect>
@@ -232,5 +283,5 @@
     <widget class="QMenu" name="menuFileSaveAs">
      <property name="title">
-      <string>Save &amp;As...</string>
+      <string>Save &amp;As</string>
      </property>
      <property name="icon">
@@ -379,9 +430,12 @@
     <string>&amp;Solution...</string>
    </property>
+   <property name="iconText">
+    <string>Solution...</string>
+   </property>
    <property name="toolTip">
     <string>Save solution</string>
    </property>
    <property name="statusTip">
-    <string>Save solution steps and graph</string>
+    <string>Save solution to a file</string>
    </property>
   </action>
@@ -457,4 +511,7 @@
     <string>Open help contents</string>
    </property>
+   <property name="shortcut">
+    <string>Ctrl+F1</string>
+   </property>
   </action>
   <action name="actionHelpContextual">
@@ -472,4 +529,7 @@
     <string>Open context help</string>
    </property>
+   <property name="shortcut">
+    <string>F1</string>
+   </property>
   </action>
   <action name="actionHelpAbout">
@@ -512,7 +572,4 @@
    <property name="statusTip">
     <string>Save task to file</string>
-   </property>
-   <property name="shortcut">
-    <string>Ctrl+S</string>
    </property>
   </action>
@@ -542,14 +599,11 @@
    </property>
    <property name="text">
+    <string notr="true">&amp;English</string>
+   </property>
+   <property name="iconText">
     <string notr="true">English</string>
    </property>
-   <property name="iconText">
-    <string notr="true">English</string>
-   </property>
   </action>
   <action name="actionFileSave">
-   <property name="enabled">
-    <bool>false</bool>
-   </property>
    <property name="icon">
     <iconset resource="../resources/tspsg.qrc">
@@ -567,4 +621,7 @@
    <property name="statusTip">
     <string>Save current task</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+S</string>
    </property>
   </action>
@@ -605,4 +662,20 @@
    </hints>
   </connection>
+  <connection>
+   <sender>buttonSaveSolution</sender>
+   <signal>clicked()</signal>
+   <receiver>actionFileSaveAsSolution</receiver>
+   <slot>trigger()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>58</x>
+     <y>327</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>-1</x>
+     <y>-1</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
 </ui>
