diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 1babdaa8e..f545345d5 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -911,3 +911,16 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) break; } } + +UserSurveyServices::UserSurveyServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f) +{ + +} + +void UserSurveyServices::sendSurvey(QString values) +{ + QNetworkRequest request; + request.setUrl(QString("http://subsurface.hohndel.org/survey?%1").arg(values)); + request.setRawHeader("Accept", "text/xml"); + reply = manager()->get(request); +} diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h index b54da67c7..f2138ac6f 100644 --- a/qt-ui/subsurfacewebservices.h +++ b/qt-ui/subsurfacewebservices.h @@ -97,6 +97,20 @@ private: bool uploadMode; }; +class UserSurveyServices : public WebServices { + Q_OBJECT +public: + void sendSurvey(QString values); + explicit UserSurveyServices(QWidget *parent = 0, Qt::WindowFlags f = 0); +private +slots: + // need to declare them as no ops or Qt4 is unhappy + virtual void startDownload() { } + virtual void startUpload() { } + virtual void buttonClicked(QAbstractButton *button) { } + +}; + #ifdef __cplusplus extern "C" { #endif diff --git a/qt-ui/usersurvey.cpp b/qt-ui/usersurvey.cpp index 10beb94ee..f08168ed3 100644 --- a/qt-ui/usersurvey.cpp +++ b/qt-ui/usersurvey.cpp @@ -6,9 +6,11 @@ #include "usersurvey.h" #include "ui_usersurvey.h" #include "ssrf-version.h" +#include "subsurfacewebservices.h" #include "helpers.h" #include "subsurfacesysinfo.h" + UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent), ui(new Ui::UserSurvey) { @@ -19,10 +21,17 @@ UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent), connect(quitKey, SIGNAL(activated()), parent, SLOT(close())); // fill in the system data - ui->system->append(tr("Subsurface %1").arg(VERSION_STRING)); - ui->system->append(tr("Operating System: %1").arg(SubsurfaceSysInfo::prettyOsName())); - ui->system->append(tr("CPU Architecture: %1").arg(SubsurfaceSysInfo::cpuArchitecture())); - ui->system->append(tr("Language: %1").arg(uiLanguage(NULL))); + QString sysInfo = QString("Subsurface %1").arg(VERSION_STRING); + os = QString("ssrfVers=%1").arg(VERSION_STRING); + sysInfo.append(tr("\nOperating System: %1").arg(SubsurfaceSysInfo::prettyOsName())); + os.append(QString("&prettyOsName=%1").arg(SubsurfaceSysInfo::prettyOsName())); + sysInfo.append(tr("\nCPU Architecture: %1").arg(SubsurfaceSysInfo::cpuArchitecture())); + os.append(QString("&cpuArch=%1").arg(SubsurfaceSysInfo::cpuArchitecture())); + sysInfo.append(tr("\nLanguage: %1").arg(uiLanguage(NULL))); + os.append(QString("&uiLang=%1").arg(uiLanguage(NULL))); + ui->system->setPlainText(sysInfo); + manager = SubsurfaceWebServices::manager(); + connect(manager, SIGNAL(finished(QNetworkReply *)), SLOT(requestReceived(QNetworkReply *))); } UserSurvey::~UserSurvey() @@ -30,12 +39,22 @@ UserSurvey::~UserSurvey() delete ui; } +#define ADD_OPTION(_name) values.append(ui->_name->isChecked() ? "&" #_name "=1" : "&" #_name "=0") + void UserSurvey::on_buttonBox_accepted() { // now we need to collect the data and submit it - QSettings s; - s.beginGroup("UserSurvey"); - s.setValue("SurveyDone", "submitted"); + 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); + uss.sendSurvey(values); hide(); } @@ -60,3 +79,39 @@ void UserSurvey::on_buttonBox_rejected() } hide(); } + +void UserSurvey::requestReceived(QNetworkReply *reply) +{ + QMessageBox msgbox; + QString msgTitle = tr("Submit User Survey."); + QString msgText = tr("

Subsurface was unable to submit the user survey.

"); + + + if (reply->error() != QNetworkReply::NoError) { + //Network Error + msgText = msgText + tr("
The following error occurred:
") + reply->errorString() + + tr("

Please check your internet connection."); + } 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.

%1").arg(responseBody); + msgbox.setIcon(QMessageBox::Warning); + } + } + + msgbox.setWindowTitle(msgTitle); + msgbox.setText(msgText); + msgbox.setTextFormat(Qt::RichText); + msgbox.exec(); + reply->deleteLater(); +} diff --git a/qt-ui/usersurvey.h b/qt-ui/usersurvey.h index e1663c7e0..b9221852b 100644 --- a/qt-ui/usersurvey.h +++ b/qt-ui/usersurvey.h @@ -2,6 +2,8 @@ #define USERSURVEY_H #include +class QNetworkAccessManager; +class QNetworkReply; namespace Ui { class UserSurvey; @@ -18,8 +20,13 @@ private slots: void on_buttonBox_accepted(); void on_buttonBox_rejected(); + void requestReceived(QNetworkReply *reply); private: Ui::UserSurvey *ui; + QString os; + QString checkboxes; + QString suggestions; + QNetworkAccessManager *manager; }; #endif // USERSURVEY_H diff --git a/qt-ui/usersurvey.ui b/qt-ui/usersurvey.ui index 67d8d9870..386dee504 100644 --- a/qt-ui/usersurvey.ui +++ b/qt-ui/usersurvey.ui @@ -7,7 +7,7 @@ 0 0 500 - 524 + 600 @@ -17,7 +17,7 @@ 40 - 490 + 560 451 32 @@ -118,7 +118,7 @@ I am downloading dives from supported dive computer - + 10 @@ -144,22 +144,15 @@ I am manually entering dives - + 10 - 270 + 300 481 101 - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Suggestions and missing features</p></body></html> - @@ -174,21 +167,40 @@ p, li { white-space: pre-wrap; } I use the Android companion app to track dive locations - + 10 - 380 + 450 481 101 - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + 10 + 270 + 471 + 20 + + + + Please type suggestions (in English) in the following box + + + + + + 10 + 420 + 471 + 20 + + + + The following information about your system will also be submitted @@ -197,7 +209,7 @@ p, li { white-space: pre-wrap; } tech planning download - import_2 + divecomputer manual companion suggestions