Merge branch 'survey'

This commit is contained in:
Dirk Hohndel 2014-06-30 14:06:03 -07:00
commit 8315f44d2c
5 changed files with 129 additions and 28 deletions

View file

@ -911,3 +911,16 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
break; 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);
}

View file

@ -97,6 +97,20 @@ private:
bool uploadMode; 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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View file

@ -6,9 +6,11 @@
#include "usersurvey.h" #include "usersurvey.h"
#include "ui_usersurvey.h" #include "ui_usersurvey.h"
#include "ssrf-version.h" #include "ssrf-version.h"
#include "subsurfacewebservices.h"
#include "helpers.h" #include "helpers.h"
#include "subsurfacesysinfo.h" #include "subsurfacesysinfo.h"
UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent), UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent),
ui(new Ui::UserSurvey) ui(new Ui::UserSurvey)
{ {
@ -19,10 +21,17 @@ UserSurvey::UserSurvey(QWidget *parent) : QDialog(parent),
connect(quitKey, SIGNAL(activated()), parent, SLOT(close())); connect(quitKey, SIGNAL(activated()), parent, SLOT(close()));
// fill in the system data // fill in the system data
ui->system->append(tr("Subsurface %1").arg(VERSION_STRING)); QString sysInfo = QString("Subsurface %1").arg(VERSION_STRING);
ui->system->append(tr("Operating System: %1").arg(SubsurfaceSysInfo::prettyOsName())); os = QString("ssrfVers=%1").arg(VERSION_STRING);
ui->system->append(tr("CPU Architecture: %1").arg(SubsurfaceSysInfo::cpuArchitecture())); sysInfo.append(tr("\nOperating System: %1").arg(SubsurfaceSysInfo::prettyOsName()));
ui->system->append(tr("Language: %1").arg(uiLanguage(NULL))); 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() UserSurvey::~UserSurvey()
@ -30,12 +39,22 @@ UserSurvey::~UserSurvey()
delete ui; delete ui;
} }
#define ADD_OPTION(_name) values.append(ui->_name->isChecked() ? "&" #_name "=1" : "&" #_name "=0")
void UserSurvey::on_buttonBox_accepted() void UserSurvey::on_buttonBox_accepted()
{ {
// now we need to collect the data and submit it // now we need to collect the data and submit it
QSettings s; QString values = os;
s.beginGroup("UserSurvey"); ADD_OPTION(recreational);
s.setValue("SurveyDone", "submitted"); 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(); hide();
} }
@ -60,3 +79,39 @@ void UserSurvey::on_buttonBox_rejected()
} }
hide(); hide();
} }
void UserSurvey::requestReceived(QNetworkReply *reply)
{
QMessageBox msgbox;
QString msgTitle = tr("Submit User Survey.");
QString msgText = tr("<h3>Subsurface was unable to submit the user survey.</h3>");
if (reply->error() != QNetworkReply::NoError) {
//Network Error
msgText = msgText + tr("<br/><b>The following error occurred:</b><br/>") + reply->errorString()
+ tr("<br/><br/><b>Please check your internet connection.</b>");
} 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);
msgbox.setText(msgText);
msgbox.setTextFormat(Qt::RichText);
msgbox.exec();
reply->deleteLater();
}

View file

@ -2,6 +2,8 @@
#define USERSURVEY_H #define USERSURVEY_H
#include <QDialog> #include <QDialog>
class QNetworkAccessManager;
class QNetworkReply;
namespace Ui { namespace Ui {
class UserSurvey; class UserSurvey;
@ -18,8 +20,13 @@ private
slots: slots:
void on_buttonBox_accepted(); void on_buttonBox_accepted();
void on_buttonBox_rejected(); void on_buttonBox_rejected();
void requestReceived(QNetworkReply *reply);
private: private:
Ui::UserSurvey *ui; Ui::UserSurvey *ui;
QString os;
QString checkboxes;
QString suggestions;
QNetworkAccessManager *manager;
}; };
#endif // USERSURVEY_H #endif // USERSURVEY_H

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>500</width> <width>500</width>
<height>524</height> <height>600</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -17,7 +17,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>40</x> <x>40</x>
<y>490</y> <y>560</y>
<width>451</width> <width>451</width>
<height>32</height> <height>32</height>
</rect> </rect>
@ -118,7 +118,7 @@
<string>I am downloading dives from supported dive computer</string> <string>I am downloading dives from supported dive computer</string>
</property> </property>
</widget> </widget>
<widget class="QCheckBox" name="import_2"> <widget class="QCheckBox" name="divecomputer">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
@ -144,22 +144,15 @@
<string>I am manually entering dives</string> <string>I am manually entering dives</string>
</property> </property>
</widget> </widget>
<widget class="QTextEdit" name="suggestions"> <widget class="QPlainTextEdit" name="suggestions">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>270</y> <y>300</y>
<width>481</width> <width>481</width>
<height>101</height> <height>101</height>
</rect> </rect>
</property> </property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Suggestions and missing features&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget> </widget>
<widget class="QCheckBox" name="companion"> <widget class="QCheckBox" name="companion">
<property name="geometry"> <property name="geometry">
@ -174,21 +167,40 @@ p, li { white-space: pre-wrap; }
<string>I use the Android companion app to track dive locations</string> <string>I use the Android companion app to track dive locations</string>
</property> </property>
</widget> </widget>
<widget class="QTextEdit" name="system"> <widget class="QPlainTextEdit" name="system">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>380</y> <y>450</y>
<width>481</width> <width>481</width>
<height>101</height> <height>101</height>
</rect> </rect>
</property> </property>
<property name="html"> </widget>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <widget class="QLabel" name="label_3">
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; <property name="geometry">
p, li { white-space: pre-wrap; } <rect>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; <x>10</x>
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <y>270</y>
<width>471</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Please type suggestions (in English) in the following box</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>10</x>
<y>420</y>
<width>471</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>The following information about your system will also be submitted</string>
</property> </property>
</widget> </widget>
</widget> </widget>
@ -197,7 +209,7 @@ p, li { white-space: pre-wrap; }
<tabstop>tech</tabstop> <tabstop>tech</tabstop>
<tabstop>planning</tabstop> <tabstop>planning</tabstop>
<tabstop>download</tabstop> <tabstop>download</tabstop>
<tabstop>import_2</tabstop> <tabstop>divecomputer</tabstop>
<tabstop>manual</tabstop> <tabstop>manual</tabstop>
<tabstop>companion</tabstop> <tabstop>companion</tabstop>
<tabstop>suggestions</tabstop> <tabstop>suggestions</tabstop>