Mercurial > hg > sonic-visualiser
changeset 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 | 0dec5e47dd8f |
children | 32718f05903d |
files | main/MainWindow.cpp main/Surveyer.cpp main/Surveyer.h |
diffstat | 3 files changed, 55 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/main/MainWindow.cpp Mon May 11 17:30:51 2020 +0100 +++ b/main/MainWindow.cpp Tue May 12 17:41:54 2020 +0100 @@ -337,9 +337,24 @@ SVDEBUG << "MainWindow: Starting transform population thread" << endl; TransformFactory::getInstance()->startPopulationThread(); + m_surveyer = nullptr; + +//#define WITH_SURVEY 1 +#ifdef WITH_SURVEY SVDEBUG << "MainWindow: Creating surveyer" << endl; - m_surveyer = new Surveyer - ("sonicvisualiser.org", "survey23-present.txt", "survey23.php"); + Surveyer::Config config; + config.hostname = "sonicvisualiser.org"; + config.testPath = "feedback41-present.txt"; + config.surveyPath = "feedback41.php"; + config.countdownKey = "countdown41"; + config.countdownFrom = 1; + config.title = "Sonic Visualiser - Can you help?"; + config.text = "<h3>Sonic Visualiser: Can you help?</h3><p>Are you using Sonic Visualiser for research or commercial purposes? Or do you intend to do so?</p><p>In the Centre for Digital Music, where Sonic Visualiser is made, we are gathering information about the impact of our work, to guide our future actions.</p><p>Would you be interested in giving us your contact details, and a description of the work you do that is related to Sonic Visualiser?</p><p>Anything you tell us will be used only to guide research and development at Queen Mary University of London.</p>"; + config.acceptLabel = tr("Yes, I'd be happy to"); + config.rejectLabel = tr("No, thank you"); + config.includeSystemInfo = false; + m_surveyer = new Surveyer(config); +#endif SVDEBUG << "MainWindow: Creating version tester" << endl; m_versionTester = new VersionTester
--- a/main/Surveyer.cpp Mon May 11 17:30:51 2020 +0100 +++ b/main/Surveyer.cpp Tue May 12 17:41:54 2020 +0100 @@ -29,22 +29,20 @@ #include "transform/TransformFactory.h" #include "plugin/PluginIdentifier.h" -Surveyer::Surveyer(QString hostname, QString testPath, QString surveyPath) : +Surveyer::Surveyer(Config config) : + m_config(config), m_httpFailed(false), - m_hostname(hostname), - m_testPath(testPath), - m_surveyPath(surveyPath), m_reply(nullptr), m_nm(new QNetworkAccessManager) { QSettings settings; settings.beginGroup("Survey"); - if (!settings.contains("countdown")) { - settings.setValue("countdown", 15); + if (!settings.contains(m_config.countdownKey)) { + settings.setValue(m_config.countdownKey, m_config.countdownFrom); settings.endGroup(); return; } - int countdown = settings.value("countdown").toInt(); + int countdown = settings.value(m_config.countdownKey).toInt(); if (countdown == 0) { // The countdown value will now remain 0 until we have // successfully tested for a survey and offered it to the @@ -54,14 +52,15 @@ // the user the chance to respond to it and (regardless of // whether they want to or not) set the countdown to -1 so // that it is never offered again. - QUrl url(QString("http://%1/%2").arg(m_hostname).arg(m_testPath)); - cerr << "Surveyer: Test URL is " << url << endl; + QUrl url(QString("http://%1/%2") + .arg(m_config.hostname).arg(m_config.testPath)); + SVDEBUG << "Surveyer: Test URL is " << url << endl; m_reply = m_nm->get(QNetworkRequest(url)); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); } else if (countdown > 0) { - settings.setValue("countdown", countdown-1); + settings.setValue(m_config.countdownKey, countdown-1); } settings.endGroup(); } @@ -78,7 +77,7 @@ void Surveyer::error(QNetworkReply::NetworkError) { - cerr << "Surveyer: error: " << m_reply->errorString() << endl; + SVDEBUG << "Surveyer: error: " << m_reply->errorString() << endl; m_httpFailed = true; } @@ -87,21 +86,19 @@ { if (m_httpFailed) return; - QString title = "Sonic Visualiser - User Survey"; - 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>"; + QMessageBox mb(dynamic_cast<QWidget *>(parent())); + mb.setWindowTitle(m_config.title); + mb.setText(m_config.text); - QMessageBox mb(dynamic_cast<QWidget *>(parent())); - mb.setWindowTitle(title); - mb.setText(text); - - QPushButton *yes = mb.addButton(tr("Yes! Take me to the survey"), QMessageBox::ActionRole); - mb.addButton(tr("No, thanks"), QMessageBox::RejectRole); + QPushButton *yes = + mb.addButton(m_config.acceptLabel, QMessageBox::ActionRole); + mb.addButton(m_config.rejectLabel, QMessageBox::RejectRole); mb.exec(); QSettings settings; settings.beginGroup("Survey"); - settings.setValue("countdown", -1); + settings.setValue(m_config.countdownKey, -1); settings.endGroup(); if (mb.clickedButton() == yes) { @@ -136,7 +133,12 @@ plugsarg = plugsarg + *i; } } - 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))); + + if (m_config.includeSystemInfo) { + 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))); + } else { + QDesktopServices::openUrl(QUrl(QString("http://%1/%2?sv=%3").arg(m_config.hostname).arg(m_config.surveyPath).arg(svarg))); + } } }
--- a/main/Surveyer.h Mon May 11 17:30:51 2020 +0100 +++ b/main/Surveyer.h Tue May 12 17:41:54 2020 +0100 @@ -27,7 +27,20 @@ Q_OBJECT public: - Surveyer(QString hostname, QString testPath, QString surveyPath); + struct Config { + QString hostname; + QString testPath; + QString surveyPath; + QString countdownKey; + int countdownFrom; + QString title; + QString text; + QString acceptLabel; + QString rejectLabel; + bool includeSystemInfo; + }; + + Surveyer(Config config); virtual ~Surveyer(); protected slots: @@ -35,10 +48,8 @@ void error(QNetworkReply::NetworkError); private: + Config m_config; bool m_httpFailed; - QString m_hostname; - QString m_testPath; - QString m_surveyPath; QNetworkReply *m_reply; QNetworkAccessManager *m_nm; };