mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Improve on error reporting in the ConfigureDiveComputer class
This patch improves on the error reporting for the dive computer configuration dialog to use config->lastError. The previous code was using a different argument in each function, which lacked uniformity. Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com> Signed-off-by: Thiago Macieira <thiago@macieira.org>
This commit is contained in:
		
							parent
							
								
									24cb0b0496
								
							
						
					
					
						commit
						4e99382c96
					
				
					 3 changed files with 13 additions and 16 deletions
				
			
		|  | @ -50,7 +50,7 @@ void ConfigureDiveComputer::saveDeviceDetails(DeviceDetails *details, device_dat | ||||||
| 	writeThread->start(); | 	writeThread->start(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText) | bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data) | ||||||
| { | { | ||||||
| 	QString xml = ""; | 	QString xml = ""; | ||||||
| 	QString vendor = data->vendor; | 	QString vendor = data->vendor; | ||||||
|  | @ -187,7 +187,7 @@ bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *detai | ||||||
| 	writer.writeEndDocument(); | 	writer.writeEndDocument(); | ||||||
| 	QFile file(fileName); | 	QFile file(fileName); | ||||||
| 	if (!file.open(QIODevice::WriteOnly)) { | 	if (!file.open(QIODevice::WriteOnly)) { | ||||||
| 		errorText = tr("Could not save the backup file %1. Error Message: %2") | 		lastError = tr("Could not save the backup file %1. Error Message: %2") | ||||||
| 				.arg(fileName, file.errorString()); | 				.arg(fileName, file.errorString()); | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
|  | @ -199,11 +199,11 @@ bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *detai | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText) | bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *details) | ||||||
| { | { | ||||||
| 	QFile file(fileName); | 	QFile file(fileName); | ||||||
| 	if (!file.open(QIODevice::ReadOnly)) { | 	if (!file.open(QIODevice::ReadOnly)) { | ||||||
| 		errorText = tr("Could not open backup file: %1").arg(file.errorString()); | 		lastError = tr("Could not open backup file: %1").arg(file.errorString()); | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -401,7 +401,7 @@ bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *de | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ConfigureDiveComputer::startFirmwareUpdate(QString fileName, device_data_t *data, QString errorText) | void ConfigureDiveComputer::startFirmwareUpdate(QString fileName, device_data_t *data) | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -32,9 +32,9 @@ public: | ||||||
| 	device_data_t *m_data; | 	device_data_t *m_data; | ||||||
| 	void saveDeviceDetails(DeviceDetails *details, device_data_t *data); | 	void saveDeviceDetails(DeviceDetails *details, device_data_t *data); | ||||||
| 	void fetchDeviceDetails(); | 	void fetchDeviceDetails(); | ||||||
| 	bool saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText); | 	bool saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data); | ||||||
| 	bool restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText); | 	bool restoreXMLBackup(QString fileName, DeviceDetails *details); | ||||||
| 	void startFirmwareUpdate(QString fileName, device_data_t *data, QString errorText); | 	void startFirmwareUpdate(QString fileName, device_data_t *data); | ||||||
| signals: | signals: | ||||||
| 	void message(QString msg); | 	void message(QString msg); | ||||||
| 	void error(QString err); | 	void error(QString err); | ||||||
|  |  | ||||||
|  | @ -396,11 +396,10 @@ void ConfigureDiveComputerDialog::on_backupButton_clicked() | ||||||
| 	if (!backupPath.isEmpty()) { | 	if (!backupPath.isEmpty()) { | ||||||
| 		populateDeviceDetails(); | 		populateDeviceDetails(); | ||||||
| 		getDeviceData(); | 		getDeviceData(); | ||||||
| 		QString errorText = ""; | 		if (!config->saveXMLBackup(backupPath, deviceDetails, &device_data)) { | ||||||
| 		if (!config->saveXMLBackup(backupPath, deviceDetails, &device_data, errorText)) { |  | ||||||
| 			QMessageBox::critical(this, tr("XML Backup Error"), | 			QMessageBox::critical(this, tr("XML Backup Error"), | ||||||
| 					      tr("An error occurred while saving the backup file.\n%1") | 					      tr("An error occurred while saving the backup file.\n%1") | ||||||
| 					      .arg(errorText) | 					      .arg(config->lastError) | ||||||
| 					      ); | 					      ); | ||||||
| 		} else { | 		} else { | ||||||
| 			QMessageBox::information(this, tr("Backup succeeded"), | 			QMessageBox::information(this, tr("Backup succeeded"), | ||||||
|  | @ -420,11 +419,10 @@ void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked() | ||||||
| 							   filename, tr("Backup files (*.xml)") | 							   filename, tr("Backup files (*.xml)") | ||||||
| 							   ); | 							   ); | ||||||
| 	if (!restorePath.isEmpty()) { | 	if (!restorePath.isEmpty()) { | ||||||
| 		QString errorText = ""; | 		if (!config->restoreXMLBackup(restorePath, deviceDetails)) { | ||||||
| 		if (!config->restoreXMLBackup(restorePath, deviceDetails, errorText)) { |  | ||||||
| 			QMessageBox::critical(this, tr("XML Restore Error"), | 			QMessageBox::critical(this, tr("XML Restore Error"), | ||||||
| 					      tr("An error occurred while restoring the backup file.\n%1") | 					      tr("An error occurred while restoring the backup file.\n%1") | ||||||
| 					      .arg(errorText) | 					      .arg(config->lastError) | ||||||
| 					      ); | 					      ); | ||||||
| 		} else { | 		} else { | ||||||
| 			reloadValues(); | 			reloadValues(); | ||||||
|  | @ -447,8 +445,7 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked() | ||||||
| 							  ); | 							  ); | ||||||
| 	if (!firmwarePath.isEmpty()) { | 	if (!firmwarePath.isEmpty()) { | ||||||
| 		getDeviceData(); | 		getDeviceData(); | ||||||
| 		QString errText; | 		config->startFirmwareUpdate(firmwarePath, &device_data); | ||||||
| 		config->startFirmwareUpdate(firmwarePath, &device_data, errText); |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue