| 
									
										
										
										
											2017-04-27 20:26:05 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | #include <QShortcut>
 | 
					
						
							|  |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2018-08-29 03:08:47 -07:00
										 |  |  | #include <QSettings>
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "desktop-widgets/usersurvey.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | #include "ui_usersurvey.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "core/version.h"
 | 
					
						
							|  |  |  | #include "desktop-widgets/subsurfacewebservices.h"
 | 
					
						
							|  |  |  | #include "desktop-widgets/updatemanager.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-03 22:15:19 +02:00
										 |  |  | #include "core/qthelper.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-04 22:02:03 -07:00
										 |  |  | #include "core/subsurfacesysinfo.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent), | 
					
						
							|  |  |  | 	ui(new Ui::UserSurvey) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-08-15 21:41:41 -06:00
										 |  |  | 	ui->buttonBox->buttons().first()->setText(tr("Send")); | 
					
						
							| 
									
										
										
										
											2014-07-16 11:58:01 +04:00
										 |  |  | 	this->adjustSize(); | 
					
						
							| 
									
										
										
										
											2014-06-14 14:20:14 -07:00
										 |  |  | 	QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | 
					
						
							|  |  |  | 	connect(closeKey, SIGNAL(activated()), this, SLOT(close())); | 
					
						
							|  |  |  | 	QShortcut *quitKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | 
					
						
							|  |  |  | 	connect(quitKey, SIGNAL(activated()), parent, SLOT(close())); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-20 07:59:50 -08:00
										 |  |  | 	os = QString("ssrfVers=%1").arg(subsurface_canonical_version()); | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 	os.append(QString("&prettyOsName=%1").arg(SubsurfaceSysInfo::prettyOsName())); | 
					
						
							| 
									
										
										
										
											2015-02-13 23:49:58 -08:00
										 |  |  | 	QString arch = SubsurfaceSysInfo::buildCpuArchitecture(); | 
					
						
							| 
									
										
										
										
											2014-06-30 15:40:08 -07:00
										 |  |  | 	os.append(QString("&appCpuArch=%1").arg(arch)); | 
					
						
							|  |  |  | 	if (arch == "i386") { | 
					
						
							| 
									
										
										
										
											2015-02-13 23:49:58 -08:00
										 |  |  | 		QString osArch = SubsurfaceSysInfo::currentCpuArchitecture(); | 
					
						
							| 
									
										
										
										
											2014-07-31 11:20:11 -07:00
										 |  |  | 		os.append(QString("&osCpuArch=%1").arg(osArch)); | 
					
						
							| 
									
										
										
										
											2014-06-30 15:40:08 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 	os.append(QString("&uiLang=%1").arg(uiLanguage(NULL))); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:57:13 -08:00
										 |  |  | 	os.append(QString("&uuid=%1").arg(getUUID())); | 
					
						
							| 
									
										
										
										
											2014-07-31 11:20:11 -07:00
										 |  |  | 	ui->system->setPlainText(getVersion()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString UserSurvey::getVersion() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QString arch; | 
					
						
							|  |  |  | 	// fill in the system data
 | 
					
						
							| 
									
										
										
										
											2015-12-20 07:59:50 -08:00
										 |  |  | 	QString sysInfo = QString("Subsurface %1").arg(subsurface_canonical_version()); | 
					
						
							| 
									
										
										
										
											2015-01-25 17:03:21 +02:00
										 |  |  | 	sysInfo.append(tr("\nOperating system: %1").arg(SubsurfaceSysInfo::prettyOsName())); | 
					
						
							| 
									
										
										
										
											2015-02-13 23:49:58 -08:00
										 |  |  | 	arch = SubsurfaceSysInfo::buildCpuArchitecture(); | 
					
						
							| 
									
										
										
										
											2015-01-25 17:03:21 +02:00
										 |  |  | 	sysInfo.append(tr("\nCPU architecture: %1").arg(arch)); | 
					
						
							| 
									
										
										
										
											2014-07-31 11:20:11 -07:00
										 |  |  | 	if (arch == "i386") | 
					
						
							| 
									
										
										
										
											2015-02-13 23:49:58 -08:00
										 |  |  | 		sysInfo.append(tr("\nOS CPU architecture: %1").arg(SubsurfaceSysInfo::currentCpuArchitecture())); | 
					
						
							| 
									
										
										
										
											2014-08-08 10:42:39 -07:00
										 |  |  | 	sysInfo.append(tr("\nLanguage: %1").arg(uiLanguage(NULL))); | 
					
						
							| 
									
										
										
										
											2014-07-31 11:20:11 -07:00
										 |  |  | 	return sysInfo; | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | UserSurvey::~UserSurvey() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete ui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | #define ADD_OPTION(_name) values.append(ui->_name->isChecked() ? "&" #_name "=1" : "&" #_name "=0")
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | void UserSurvey::on_buttonBox_accepted() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// now we need to collect the data and submit it
 | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 	QString values = os; | 
					
						
							|  |  |  | 	ADD_OPTION(recreational); | 
					
						
							|  |  |  | 	ADD_OPTION(tech); | 
					
						
							|  |  |  | 	ADD_OPTION(planning); | 
					
						
							|  |  |  | 	ADD_OPTION(download); | 
					
						
							|  |  |  | 	ADD_OPTION(divecomputer); | 
					
						
							|  |  |  | 	ADD_OPTION(manual); | 
					
						
							|  |  |  | 	ADD_OPTION(companion); | 
					
						
							|  |  |  | 	values.append(QString("&suggestion=%1").arg(ui->suggestions->toPlainText())); | 
					
						
							|  |  |  | 	UserSurveyServices uss(this); | 
					
						
							| 
									
										
										
										
											2014-07-16 17:20:21 -03:00
										 |  |  | 	connect(uss.sendSurvey(values), SIGNAL(finished()), SLOT(requestReceived())); | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | 	hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UserSurvey::on_buttonBox_rejected() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QMessageBox response(this); | 
					
						
							|  |  |  | 	response.setText(tr("Should we ask you later?")); | 
					
						
							|  |  |  | 	response.addButton(tr("Don't ask me again"), QMessageBox::RejectRole); | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:38 +01:00
										 |  |  | 	response.addButton(tr("Ask later"), QMessageBox::AcceptRole); | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | 	response.setWindowTitle(tr("Ask again?")); // Not displayed on MacOSX as described in Qt API
 | 
					
						
							|  |  |  | 	response.setIcon(QMessageBox::Question); | 
					
						
							|  |  |  | 	response.setWindowModality(Qt::WindowModal); | 
					
						
							|  |  |  | 	switch (response.exec()) { | 
					
						
							|  |  |  | 	case QDialog::Accepted: | 
					
						
							|  |  |  | 		// nothing to do here, we'll just ask again the next time they start
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case QDialog::Rejected: | 
					
						
							| 
									
										
										
										
											2018-08-29 03:08:47 -07:00
										 |  |  | 		QSettings s; | 
					
						
							|  |  |  | 		s.beginGroup("UserSurvey"); | 
					
						
							|  |  |  | 		s.setValue("SurveyDone", "declined"); | 
					
						
							| 
									
										
										
										
											2014-06-13 10:56:46 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	hide(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-16 17:20:21 -03:00
										 |  |  | void UserSurvey::requestReceived() | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMessageBox msgbox; | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:38 +01:00
										 |  |  | 	QString msgTitle = tr("Submit user survey."); | 
					
						
							| 
									
										
										
										
											2014-07-09 10:26:43 -07:00
										 |  |  | 	QString msgText = "<h3>" + tr("Subsurface was unable to submit the user survey.") + "</h3>"; | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-16 17:20:21 -03:00
										 |  |  | 	QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 	if (reply->error() != QNetworkReply::NoError) { | 
					
						
							|  |  |  | 		//Network Error
 | 
					
						
							| 
									
										
										
										
											2014-07-09 10:26:43 -07:00
										 |  |  | 		msgText = msgText + "<br/><b>" + tr("The following error occurred:") + "</b><br/>" + reply->errorString() | 
					
						
							|  |  |  | 				+ "<br/><br/><b>" + tr("Please check your internet connection.") + "</b>"; | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		//No network error
 | 
					
						
							|  |  |  | 		QString response(reply->readAll()); | 
					
						
							|  |  |  | 		QString responseBody = response.split("\"").at(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		msgbox.setIcon(QMessageBox::Information); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (responseBody == "OK") { | 
					
						
							|  |  |  | 			msgText = tr("Survey successfully submitted."); | 
					
						
							| 
									
										
										
										
											2018-08-29 03:08:47 -07:00
										 |  |  | 			QSettings s; | 
					
						
							|  |  |  | 			s.beginGroup("UserSurvey"); | 
					
						
							|  |  |  | 			s.setValue("SurveyDone", "submitted"); | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			msgText = tr("There was an error while trying to check for updates.<br/><br/>%1").arg(responseBody); | 
					
						
							|  |  |  | 			msgbox.setIcon(QMessageBox::Warning); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msgbox.setWindowTitle(msgTitle); | 
					
						
							| 
									
										
										
										
											2017-11-28 08:37:01 +01:00
										 |  |  | 	msgbox.setWindowIcon(QIcon(":subsurface-icon")); | 
					
						
							| 
									
										
										
										
											2014-06-30 07:19:22 -07:00
										 |  |  | 	msgbox.setText(msgText); | 
					
						
							|  |  |  | 	msgbox.setTextFormat(Qt::RichText); | 
					
						
							|  |  |  | 	msgbox.exec(); | 
					
						
							|  |  |  | 	reply->deleteLater(); | 
					
						
							|  |  |  | } |