2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-06-13 17:56:46 +00:00
|
|
|
#include <QShortcut>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
|
|
|
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/usersurvey.h"
|
2014-06-13 17:56:46 +00:00
|
|
|
#include "ui_usersurvey.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/version.h"
|
|
|
|
#include "desktop-widgets/subsurfacewebservices.h"
|
|
|
|
#include "desktop-widgets/updatemanager.h"
|
2014-06-13 17:56:46 +00:00
|
|
|
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/helpers.h"
|
|
|
|
#include "core/subsurfacesysinfo.h"
|
2014-06-30 14:19:22 +00:00
|
|
|
|
2014-06-13 17:56:46 +00:00
|
|
|
UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent),
|
|
|
|
ui(new Ui::UserSurvey)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-08-16 03:41:41 +00:00
|
|
|
ui->buttonBox->buttons().first()->setText(tr("Send"));
|
2014-07-16 07:58:01 +00:00
|
|
|
this->adjustSize();
|
2014-06-14 21:20:14 +00: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 15:59:50 +00:00
|
|
|
os = QString("ssrfVers=%1").arg(subsurface_canonical_version());
|
2014-06-30 14:19:22 +00:00
|
|
|
os.append(QString("&prettyOsName=%1").arg(SubsurfaceSysInfo::prettyOsName()));
|
2015-02-14 07:49:58 +00:00
|
|
|
QString arch = SubsurfaceSysInfo::buildCpuArchitecture();
|
2014-06-30 22:40:08 +00:00
|
|
|
os.append(QString("&appCpuArch=%1").arg(arch));
|
|
|
|
if (arch == "i386") {
|
2015-02-14 07:49:58 +00:00
|
|
|
QString osArch = SubsurfaceSysInfo::currentCpuArchitecture();
|
2014-07-31 18:20:11 +00:00
|
|
|
os.append(QString("&osCpuArch=%1").arg(osArch));
|
2014-06-30 22:40:08 +00:00
|
|
|
}
|
2014-06-30 14:19:22 +00:00
|
|
|
os.append(QString("&uiLang=%1").arg(uiLanguage(NULL)));
|
2015-11-19 01:57:13 +00:00
|
|
|
os.append(QString("&uuid=%1").arg(getUUID()));
|
2014-07-31 18:20:11 +00:00
|
|
|
ui->system->setPlainText(getVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UserSurvey::getVersion()
|
|
|
|
{
|
|
|
|
QString arch;
|
|
|
|
// fill in the system data
|
2015-12-20 15:59:50 +00:00
|
|
|
QString sysInfo = QString("Subsurface %1").arg(subsurface_canonical_version());
|
2015-01-25 15:03:21 +00:00
|
|
|
sysInfo.append(tr("\nOperating system: %1").arg(SubsurfaceSysInfo::prettyOsName()));
|
2015-02-14 07:49:58 +00:00
|
|
|
arch = SubsurfaceSysInfo::buildCpuArchitecture();
|
2015-01-25 15:03:21 +00:00
|
|
|
sysInfo.append(tr("\nCPU architecture: %1").arg(arch));
|
2014-07-31 18:20:11 +00:00
|
|
|
if (arch == "i386")
|
2015-02-14 07:49:58 +00:00
|
|
|
sysInfo.append(tr("\nOS CPU architecture: %1").arg(SubsurfaceSysInfo::currentCpuArchitecture()));
|
2014-08-08 17:42:39 +00:00
|
|
|
sysInfo.append(tr("\nLanguage: %1").arg(uiLanguage(NULL)));
|
2014-07-31 18:20:11 +00:00
|
|
|
return sysInfo;
|
2014-06-13 17:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UserSurvey::~UserSurvey()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-06-30 14:19:22 +00:00
|
|
|
#define ADD_OPTION(_name) values.append(ui->_name->isChecked() ? "&" #_name "=1" : "&" #_name "=0")
|
|
|
|
|
2014-06-13 17:56:46 +00:00
|
|
|
void UserSurvey::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
// now we need to collect the data and submit it
|
2014-06-30 14:19:22 +00: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 20:20:21 +00:00
|
|
|
connect(uss.sendSurvey(values), SIGNAL(finished()), SLOT(requestReceived()));
|
2014-06-13 17:56:46 +00: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-10 23:06:38 +00:00
|
|
|
response.addButton(tr("Ask later"), QMessageBox::AcceptRole);
|
2014-06-13 17:56:46 +00: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:
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("UserSurvey");
|
|
|
|
s.setValue("SurveyDone", "declined");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hide();
|
|
|
|
}
|
2014-06-30 14:19:22 +00:00
|
|
|
|
2014-07-16 20:20:21 +00:00
|
|
|
void UserSurvey::requestReceived()
|
2014-06-30 14:19:22 +00:00
|
|
|
{
|
|
|
|
QMessageBox msgbox;
|
2014-07-10 23:06:38 +00:00
|
|
|
QString msgTitle = tr("Submit user survey.");
|
2014-07-09 17:26:43 +00:00
|
|
|
QString msgText = "<h3>" + tr("Subsurface was unable to submit the user survey.") + "</h3>";
|
2014-06-30 14:19:22 +00:00
|
|
|
|
2014-07-16 20:20:21 +00:00
|
|
|
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
2014-06-30 14:19:22 +00:00
|
|
|
if (reply->error() != QNetworkReply::NoError) {
|
|
|
|
//Network Error
|
2014-07-09 17:26:43 +00: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 14:19:22 +00: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.");
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("UserSurvey");
|
|
|
|
s.setValue("SurveyDone", "submitted");
|
|
|
|
} 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-29 22:04:52 +00:00
|
|
|
msgbox.setWindowIcon(QIcon(":/subsurface-icon"));
|
2014-06-30 14:19:22 +00:00
|
|
|
msgbox.setText(msgText);
|
|
|
|
msgbox.setTextFormat(Qt::RichText);
|
|
|
|
msgbox.exec();
|
|
|
|
reply->deleteLater();
|
|
|
|
}
|