Mercurial > hg > sonic-visualiser
comparison main/Surveyer.cpp @ 2535:62b1a3a242ee
Towards reusing the survey logic for a request for info & guidance
author | Chris Cannam |
---|---|
date | Tue, 12 May 2020 17:41:54 +0100 |
parents | 0b15f3b16776 |
children |
comparison
equal
deleted
inserted
replaced
2534:0dec5e47dd8f | 2535:62b1a3a242ee |
---|---|
27 #include "../version.h" | 27 #include "../version.h" |
28 | 28 |
29 #include "transform/TransformFactory.h" | 29 #include "transform/TransformFactory.h" |
30 #include "plugin/PluginIdentifier.h" | 30 #include "plugin/PluginIdentifier.h" |
31 | 31 |
32 Surveyer::Surveyer(QString hostname, QString testPath, QString surveyPath) : | 32 Surveyer::Surveyer(Config config) : |
33 m_config(config), | |
33 m_httpFailed(false), | 34 m_httpFailed(false), |
34 m_hostname(hostname), | |
35 m_testPath(testPath), | |
36 m_surveyPath(surveyPath), | |
37 m_reply(nullptr), | 35 m_reply(nullptr), |
38 m_nm(new QNetworkAccessManager) | 36 m_nm(new QNetworkAccessManager) |
39 { | 37 { |
40 QSettings settings; | 38 QSettings settings; |
41 settings.beginGroup("Survey"); | 39 settings.beginGroup("Survey"); |
42 if (!settings.contains("countdown")) { | 40 if (!settings.contains(m_config.countdownKey)) { |
43 settings.setValue("countdown", 15); | 41 settings.setValue(m_config.countdownKey, m_config.countdownFrom); |
44 settings.endGroup(); | 42 settings.endGroup(); |
45 return; | 43 return; |
46 } | 44 } |
47 int countdown = settings.value("countdown").toInt(); | 45 int countdown = settings.value(m_config.countdownKey).toInt(); |
48 if (countdown == 0) { | 46 if (countdown == 0) { |
49 // The countdown value will now remain 0 until we have | 47 // The countdown value will now remain 0 until we have |
50 // successfully tested for a survey and offered it to the | 48 // successfully tested for a survey and offered it to the |
51 // user. If the survey doesn't exist any more, then we'll | 49 // user. If the survey doesn't exist any more, then we'll |
52 // simply never present it to the user and the countdown will | 50 // simply never present it to the user and the countdown will |
53 // remain 0 forever. If the survey does exist, then we offer | 51 // remain 0 forever. If the survey does exist, then we offer |
54 // the user the chance to respond to it and (regardless of | 52 // the user the chance to respond to it and (regardless of |
55 // whether they want to or not) set the countdown to -1 so | 53 // whether they want to or not) set the countdown to -1 so |
56 // that it is never offered again. | 54 // that it is never offered again. |
57 QUrl url(QString("http://%1/%2").arg(m_hostname).arg(m_testPath)); | 55 QUrl url(QString("http://%1/%2") |
58 cerr << "Surveyer: Test URL is " << url << endl; | 56 .arg(m_config.hostname).arg(m_config.testPath)); |
57 SVDEBUG << "Surveyer: Test URL is " << url << endl; | |
59 m_reply = m_nm->get(QNetworkRequest(url)); | 58 m_reply = m_nm->get(QNetworkRequest(url)); |
60 connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), | 59 connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), |
61 this, SLOT(error(QNetworkReply::NetworkError))); | 60 this, SLOT(error(QNetworkReply::NetworkError))); |
62 connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); | 61 connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); |
63 } else if (countdown > 0) { | 62 } else if (countdown > 0) { |
64 settings.setValue("countdown", countdown-1); | 63 settings.setValue(m_config.countdownKey, countdown-1); |
65 } | 64 } |
66 settings.endGroup(); | 65 settings.endGroup(); |
67 } | 66 } |
68 | 67 |
69 Surveyer::~Surveyer() | 68 Surveyer::~Surveyer() |
76 } | 75 } |
77 | 76 |
78 void | 77 void |
79 Surveyer::error(QNetworkReply::NetworkError) | 78 Surveyer::error(QNetworkReply::NetworkError) |
80 { | 79 { |
81 cerr << "Surveyer: error: " << m_reply->errorString() << endl; | 80 SVDEBUG << "Surveyer: error: " << m_reply->errorString() << endl; |
82 m_httpFailed = true; | 81 m_httpFailed = true; |
83 } | 82 } |
84 | 83 |
85 void | 84 void |
86 Surveyer::finished() | 85 Surveyer::finished() |
87 { | 86 { |
88 if (m_httpFailed) return; | 87 if (m_httpFailed) return; |
89 | 88 |
90 QString title = "Sonic Visualiser - User Survey"; | 89 QMessageBox mb(dynamic_cast<QWidget *>(parent())); |
91 QString text = "<h3>Sonic Visualiser: Take part in our survey!</h3><p>We at Queen Mary, University of London are running a short survey for users of Sonic Visualiser. We are trying to find out how useful Sonic Visualiser is to people, and what we can do to improve it.</p><p>We do not ask for any personal information, and it should only take five minutes.</p><p>Would you like to take part?</p>"; | 90 mb.setWindowTitle(m_config.title); |
91 mb.setText(m_config.text); | |
92 | 92 |
93 QMessageBox mb(dynamic_cast<QWidget *>(parent())); | 93 QPushButton *yes = |
94 mb.setWindowTitle(title); | 94 mb.addButton(m_config.acceptLabel, QMessageBox::ActionRole); |
95 mb.setText(text); | 95 mb.addButton(m_config.rejectLabel, QMessageBox::RejectRole); |
96 | |
97 QPushButton *yes = mb.addButton(tr("Yes! Take me to the survey"), QMessageBox::ActionRole); | |
98 mb.addButton(tr("No, thanks"), QMessageBox::RejectRole); | |
99 | 96 |
100 mb.exec(); | 97 mb.exec(); |
101 | 98 |
102 QSettings settings; | 99 QSettings settings; |
103 settings.beginGroup("Survey"); | 100 settings.beginGroup("Survey"); |
104 settings.setValue("countdown", -1); | 101 settings.setValue(m_config.countdownKey, -1); |
105 settings.endGroup(); | 102 settings.endGroup(); |
106 | 103 |
107 if (mb.clickedButton() == yes) { | 104 if (mb.clickedButton() == yes) { |
108 QString svarg = SV_VERSION; | 105 QString svarg = SV_VERSION; |
109 QString platformarg = "unknown"; | 106 QString platformarg = "unknown"; |
134 i != packages.end(); ++i) { | 131 i != packages.end(); ++i) { |
135 if (plugsarg != "") plugsarg = plugsarg + ","; | 132 if (plugsarg != "") plugsarg = plugsarg + ","; |
136 plugsarg = plugsarg + *i; | 133 plugsarg = plugsarg + *i; |
137 } | 134 } |
138 } | 135 } |
139 QDesktopServices::openUrl(QUrl(QString("http://%1/%2?sv=%3&plugs=%4&platform=%5").arg(m_hostname).arg(m_surveyPath).arg(svarg).arg(plugsarg).arg(platformarg))); | 136 |
137 if (m_config.includeSystemInfo) { | |
138 QDesktopServices::openUrl(QUrl(QString("http://%1/%2?sv=%3&plugs=%4&platform=%5").arg(m_config.hostname).arg(m_config.surveyPath).arg(svarg).arg(plugsarg).arg(platformarg))); | |
139 } else { | |
140 QDesktopServices::openUrl(QUrl(QString("http://%1/%2?sv=%3").arg(m_config.hostname).arg(m_config.surveyPath).arg(svarg))); | |
141 } | |
140 } | 142 } |
141 } | 143 } |
142 | 144 |
143 | 145 |