# HG changeset patch # User Chris Cannam # Date 1589301714 -3600 # Node ID 62b1a3a242ee3c88395178d388aaf29833739a69 # Parent 0dec5e47dd8f5197eb96ce9273ed4dcda1bb6c8a Towards reusing the survey logic for a request for info & guidance diff -r 0dec5e47dd8f -r 62b1a3a242ee main/MainWindow.cpp --- 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 = "

Sonic Visualiser: Can you help?

Are you using Sonic Visualiser for research or commercial purposes? Or do you intend to do so?

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.

Would you be interested in giving us your contact details, and a description of the work you do that is related to Sonic Visualiser?

Anything you tell us will be used only to guide research and development at Queen Mary University of London.

"; + 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 diff -r 0dec5e47dd8f -r 62b1a3a242ee main/Surveyer.cpp --- 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 = "

Sonic Visualiser: Take part in our survey!

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.

We do not ask for any personal information, and it should only take five minutes.

Would you like to take part?

"; + QMessageBox mb(dynamic_cast(parent())); + mb.setWindowTitle(m_config.title); + mb.setText(m_config.text); - QMessageBox mb(dynamic_cast(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))); + } } } diff -r 0dec5e47dd8f -r 62b1a3a242ee main/Surveyer.h --- 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; };