Index: src/mainwindow.cpp
===================================================================
--- src/mainwindow.cpp	(revision 9aa0e521edb1f928199e8ff7f59aa45fa1df27e4)
+++ src/mainwindow.cpp	(revision 6b3d3c1bbb46290b77de51eb3bcb573be840c56a)
@@ -87,8 +87,9 @@
 	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
+		setFileName();
 #ifdef Q_OS_WINCE
 	taskView->resizeColumnsToContents();
@@ -164,4 +165,10 @@
 }
 
+void MainWindow::setFileName(QString fileName)
+{
+	this->fileName = fileName;
+	setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(trUtf8("Travelling Salesman Problem")));
+}
+
 void MainWindow::spinCitiesValueChanged(int n)
 {
@@ -179,13 +186,27 @@
 }
 
+bool MainWindow::maybeSave()
+{
+	if (!isWindowModified())
+		return true;
+int res = QMessageBox(QMessageBox::Warning,trUtf8("Unsaved Changes"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,this).exec();
+	if (res == QMessageBox::Save)
+		return saveTask();
+	else if (res == QMessageBox::Cancel)
+		return false;
+	else
+		return true;
+}
 
 void MainWindow::actionFileNewTriggered()
 {
-	if (isWindowModified()) {
-int res = QMessageBox(QMessageBox::Warning,trUtf8("New Task"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,this).exec();
-		if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask()))
-			return;
-	}
+	if (!maybeSave())
+		return;
 	tspmodel->clear();
+#ifdef Q_OS_WINCE
+	taskView->resizeColumnsToContents();
+	taskView->resizeRowsToContents();
+#endif
+	setFileName();
 	setWindowModified(false);
 	tabWidget->setCurrentIndex(0);
@@ -196,15 +217,12 @@
 void MainWindow::actionFileOpenTriggered()
 {
-	if (isWindowModified()) {
-int res = QMessageBox(QMessageBox::Warning,trUtf8("Task Open"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,this).exec();
-		if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask()))
-			return;
-	}
+	if (!maybeSave())
+		return;
 QFileDialog od(this);
 	od.setAcceptMode(QFileDialog::AcceptOpen);
 	od.setFileMode(QFileDialog::ExistingFile);
 QStringList filters(trUtf8("All Supported Formats") + " (*.tspt *.zkt)");
-	filters.append(QString(trUtf8("%1 Task Files")).arg("TSPSG") + " (*.tspt)");
-	filters.append(QString(trUtf8("%1 Task Files")).arg("ZKomModRd") + " (*.zkt)");
+	filters.append(trUtf8("%1 Task Files").arg("TSPSG") + " (*.tspt)");
+	filters.append(trUtf8("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");
 	filters.append(trUtf8("All Files") + " (*)");
 	od.setNameFilters(filters);
@@ -212,10 +230,21 @@
 		return;
 QStringList files = od.selectedFiles();
-	if (files.size() < 1)
-		return;
-	tspmodel->loadTask(files.first());
+	if (files.empty())
+		return;
+	QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+	if (!tspmodel->loadTask(files.first())) {
+		QApplication::restoreOverrideCursor();
+		return;
+	}
+	setFileName(files.first());
+#ifdef Q_OS_WINCE
+	taskView->resizeColumnsToContents();
+	taskView->resizeRowsToContents();
+#endif
+	tabWidget->setCurrentIndex(0);
 	setWindowModified(false);
 	solutionText->clear();
 	enableSolutionActions(false);
+	QApplication::restoreOverrideCursor();
 }
 
@@ -264,18 +293,26 @@
 QFileDialog sd(this);
 	sd.setAcceptMode(QFileDialog::AcceptSave);
-QStringList filters(QString(trUtf8("%1 Task File")).arg("TSPSG") + " (*.tspt)");
+QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)");
 	filters.append(trUtf8("All Files") + " (*)");
 	sd.setNameFilters(filters);
 	sd.setDefaultSuffix("tspt");
+	if (fileName.endsWith(".tspt",Qt::CaseInsensitive))
+		sd.selectFile(fileName);
+	else
+		sd.selectFile(QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt");
 	if (sd.exec() != QDialog::Accepted)
 		return false;
 QStringList files = sd.selectedFiles();
-	if (files.size() < 1)
+	if (files.empty())
 		return false;
+	QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
 	if (tspmodel->saveTask(files.first())) {
+		setFileName(files.first());
 		setWindowModified(false);
+		QApplication::restoreOverrideCursor();
 		return true;
-	} else
-		return false;
+	}
+	QApplication::restoreOverrideCursor();
+	return false;
 }
 
@@ -351,5 +388,5 @@
 			row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok));
 			if (!ok) {
-				QMessageBox(QMessageBox::Critical,trUtf8("Data error"),QString(trUtf8("Error in cell [Row %1; Column %2]: Invalid data format.")).arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();
+				QMessageBox(QMessageBox::Critical,trUtf8("Data error"),trUtf8("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();
 				return;
 			}
@@ -467,7 +504,10 @@
 			return;
 	}
+bool untitled = (fileName == trUtf8("Untitled") + ".tspt");
 	if (loadLanguage(action->data().toString())) {
 		settings->setValue("Language",action->data().toString());
 		retranslateUi(this);
+		if (untitled)
+			setFileName();
 	}
 }
@@ -475,10 +515,7 @@
 void MainWindow::closeEvent(QCloseEvent *event)
 {
-	if (isWindowModified()) {
-int res = QMessageBox(QMessageBox::Warning,trUtf8("Application Close"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,this).exec();
-		if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask())) {
-			event->ignore();
-			return;
-		}
+	if (!maybeSave()) {
+		event->ignore();
+		return;
 	}
 	settings->setValue("NumCities",spinCities->value());
Index: src/mainwindow.h
===================================================================
--- src/mainwindow.h	(revision 9aa0e521edb1f928199e8ff7f59aa45fa1df27e4)
+++ src/mainwindow.h	(revision 6b3d3c1bbb46290b77de51eb3bcb573be840c56a)
@@ -38,7 +38,9 @@
 {
 	Q_OBJECT
+
 public:
 	MainWindow(QWidget *parent = 0);
 	void closeEvent(QCloseEvent *);
+
 private slots:
 	void actionFileNewTriggered();
@@ -58,16 +60,20 @@
 	void spinCitiesValueChanged(int);
 	void numCitiesChanged(int);
+
 private:
 	QSettings *settings;
 	QPrinter *printer;
 	CTSPModel *tspmodel;
+	QString fileName;
 	QActionGroup *groupSettingsLanguageList;
 	QStringList output;
+	void enableSolutionActions(bool enable = true);
+	void initDocStyleSheet();
 	bool loadLanguage(QString lang = "");
 	void loadLangList();
-	void initDocStyleSheet();
+	bool maybeSave();
+	void outputMatrix(tMatrix, QStringList &, int nRow = -1, int nCol = -1);
+	void setFileName(QString fileName = trUtf8("Untitled") + ".tspt");
 	bool saveTask();
-	void outputMatrix(tMatrix, QStringList &, int nRow = -1, int nCol = -1);
-	void enableSolutionActions(bool enable = true);
 };
 
Index: src/tspmodel.cpp
===================================================================
--- src/tspmodel.cpp	(revision 9aa0e521edb1f928199e8ff7f59aa45fa1df27e4)
+++ src/tspmodel.cpp	(revision 6b3d3c1bbb46290b77de51eb3bcb573be840c56a)
@@ -154,10 +154,10 @@
 }
 
-void CTSPModel::loadTask(QString fname)
+bool CTSPModel::loadTask(QString fname)
 {
 QFile f(fname);
 	if (!f.open(QIODevice::ReadOnly)) {
 		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),QString(trUtf8("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec();
-		return;
+		return false;
 	}
 QDataStream ds(&f);
@@ -166,42 +166,52 @@
 	ds >> sig;
 	if (loadError(ds.status()))
-		return;
+		return false;
 	ds.device()->reset();
 	if (sig == TSPT)
-		loadTSPT(&ds);
+		if (!loadTSPT(&ds)) {
+			f.close();
+			return false;
+		}
 	else if ((sig >> 16) == ZKT)
-		loadZKT(&ds);
-	else
+		if (!loadZKT(&ds)) {
+			f.close();
+			return false;
+		}
+	else {
 		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unknown file format or file is corrupted."),QMessageBox::Ok).exec();
+		f.close();
+		return false;
+	}
 	f.close();
-}
-
-void CTSPModel::loadTSPT(QDataStream *ds)
+	return true;
+}
+
+bool CTSPModel::loadTSPT(QDataStream *ds)
 {
 	// Skipping signature
 	ds->skipRawData(sizeof(TSPT));
 	if (loadError(ds->status()))
-		return;
+		return false;
 	// File version
 quint8 version;
 	*ds >> version;
 	if (loadError(ds->status()))
-		return;
+		return false;
 	if (version > TSPT_VERSION) {
 		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();
-		return;
+		return false;
 	}
 	// Skipping metadata
 	ds->skipRawData(TSPT_META_SIZE);
 	if (loadError(ds->status()))
-		return;
+		return false;
 	// Cities number
 quint16 size;
 	*ds >> size;
 	if (loadError(ds->status()))
-		return;
+		return false;
 	if (size < 3) {
 		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
-		return;
+		return false;
 	}
 	if (nCities != size)
@@ -214,24 +224,25 @@
 				if (loadError(ds->status())) {
 					clear();
-					return;
+					return false;
 				}
 			}
 	emit dataChanged(index(0,0),index(nCities - 1,nCities - 1));
-}
-
-void CTSPModel::loadZKT(QDataStream *ds)
+	return true;
+}
+
+bool CTSPModel::loadZKT(QDataStream *ds)
 {
 	// Skipping signature
 	ds->skipRawData(sizeof(ZKT));
 	if (loadError(ds->status()))
-		return;
+		return false;
 	// File version
 quint16 version;
 	ds->readRawData(reinterpret_cast<char *>(&version),2);
 	if (loadError(ds->status()))
-		return;
+		return false;
 	if (version > ZKT_VERSION) {
 		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();
-		return;
+		return false;
 	}
 	// Cities number
@@ -239,8 +250,8 @@
 	ds->readRawData(reinterpret_cast<char *>(&size),1);
 	if (loadError(ds->status()))
-		return;
+		return false;
 	if ((size < 3) || (size > 5)) {
 		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
-		return;
+		return false;
 	}
 	if (nCities != size)
@@ -254,5 +265,5 @@
 				if (loadError(ds->status())) {
 					clear();
-					return;
+					return false;
 				}
 				table[r][c] = val;
@@ -261,8 +272,9 @@
 				if (loadError(ds->status())) {
 					clear();
-					return;
+					return false;
 				}
 			}
 	emit dataChanged(index(0,0),index(nCities - 1,nCities - 1));
+	return true;
 }
 
Index: src/tspmodel.h
===================================================================
--- src/tspmodel.h	(revision 9aa0e521edb1f928199e8ff7f59aa45fa1df27e4)
+++ src/tspmodel.h	(revision 6b3d3c1bbb46290b77de51eb3bcb573be840c56a)
@@ -30,28 +30,31 @@
 {
 	Q_OBJECT
+
 public:
 	CTSPModel(QObject *parent = 0);
+	void clear();
+	int columnCount(const QModelIndex &) const;
+	QVariant data(const QModelIndex &, int) const;
+	Qt::ItemFlags flags(const QModelIndex &) const;
+	QVariant headerData(int, Qt::Orientation, int) const;
+	bool loadTask(QString);
+	quint16 numCities() const;
+	void randomize();
 	int rowCount(const QModelIndex &) const;
-	int columnCount(const QModelIndex &) const;
-	QVariant headerData(int, Qt::Orientation, int) const;
-	QVariant data(const QModelIndex &, int) const;
+	bool saveTask(QString);
 	bool setData(const QModelIndex &, const QVariant &, int);
-	Qt::ItemFlags flags(const QModelIndex &) const;
-	quint16 numCities() const;
 	void setNumCities(int);
-	void clear();
-	void loadTask(QString);
-	bool saveTask(QString);
-	void randomize();
+
 signals:
 	void numCitiesChanged(int);
+
 private:
 	QSettings *settings;
 	QVector<QVector<double> > table;
 	quint16 nCities;
+	bool loadError(QDataStream::Status);
+	bool loadZKT(QDataStream *);
+	bool loadTSPT(QDataStream *);
 	int rand(int, int) const;
-	bool loadError(QDataStream::Status);
-	void loadZKT(QDataStream *);
-	void loadTSPT(QDataStream *);
 };
 
