[PATCH 2/2] Divelogs.de: change the 'Apply' button to 'Done' for upload

Lubomir I. Ivanov neolit123 at gmail.com
Mon Dec 9 09:23:32 UTC 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

Post downloading we have an 'Apply' button that can be clicked
to apply/merge the downloaded dives. When uploading we
rename the button to 'Done' and enable the button if the
upload was successful. The 'Cancel' button on the other hand
becomes disabled.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 qt-ui/subsurfacewebservices.cpp | 19 +++++++++++++++++++
 qt-ui/subsurfacewebservices.h   |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index abd5f6f..d4a1428 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -200,6 +200,7 @@ WebServices::WebServices(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
 	connect(&timeout, SIGNAL(timeout()), this, SLOT(downloadTimedOut()));
 	ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
 	timeout.setSingleShot(true);
+	defaultApplyText = ui.buttonBox->button(QDialogButtonBox::Apply)->text();
 }
 
 void WebServices::hidePassword()
@@ -281,6 +282,7 @@ void WebServices::resetState()
 	ui.progressBar->reset();
 	ui.progressBar->setRange(0,1);
 	ui.status->setText(QString());
+	ui.buttonBox->button(QDialogButtonBox::Apply)->setText(defaultApplyText);
 }
 
 // #
@@ -536,6 +538,8 @@ DivelogsDeWebServices* DivelogsDeWebServices::instance()
 
 void DivelogsDeWebServices::downloadDives()
 {
+	uploadMode = false;
+	resetState();
 	hideUpload();
 	exec();
 }
@@ -573,6 +577,10 @@ void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
 	multipart = ∓
 	hideDownload();
 	resetState();
+	uploadMode = true;
+	ui.buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(true);
+	ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
+	ui.buttonBox->button(QDialogButtonBox::Apply)->setText(tr("Done"));
 	exec();
 
 	multipart = NULL;
@@ -585,6 +593,7 @@ void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
 
 DivelogsDeWebServices::DivelogsDeWebServices(QWidget* parent, Qt::WindowFlags f): WebServices(parent, f)
 {
+	uploadMode = false;
 	QSettings s;
 	ui.userID->setText(s.value("divelogde_user").toString());
 	ui.password->setText(s.value("divelogde_pass").toString());
@@ -758,6 +767,9 @@ void DivelogsDeWebServices::uploadFinished()
 
 	ui.progressBar->setRange(0,1);
 	ui.upload->setEnabled(true);
+	ui.buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
+	ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
+	ui.buttonBox->button(QDialogButtonBox::Apply)->setText(tr("Done"));
 	ui.status->setText(tr("Upload finished"));
 
 	// check what the server sent us: it might contain
@@ -807,6 +819,13 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton* button)
 	ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
 	switch(ui.buttonBox->buttonRole(button)){
 	case QDialogButtonBox::ApplyRole:{
+		/* in 'uploadMode' button is called 'Done' and closes the dialog */
+		if (uploadMode) {
+			hide();
+			close();
+			resetState();
+			break;
+		}
 		/* parse file and import dives */
 		char *error = NULL;
 		parse_file(zipFile.fileName().toLocal8Bit().data(), &error);
diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h
index 07f902b..f6b3ee2 100644
--- a/qt-ui/subsurfacewebservices.h
+++ b/qt-ui/subsurfacewebservices.h
@@ -41,6 +41,7 @@ protected:
 	QNetworkReply *reply;
 	QTimer timeout;
 	QByteArray downloadedData;
+	QString defaultApplyText;
 };
 
 class SubsurfaceWebServices : public WebServices {
@@ -87,6 +88,7 @@ private:
 
 	QHttpMultiPart *multipart;
 	QTemporaryFile zipFile;
+	bool uploadMode;
 };
 
 #endif
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list