Chris@662: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@662: Chris@662: /* Chris@662: Sonic Visualiser Chris@662: An audio file viewer and annotation editor. Chris@662: Centre for Digital Music, Queen Mary, University of London. Chris@662: Chris@662: This program is free software; you can redistribute it and/or Chris@662: modify it under the terms of the GNU General Public License as Chris@662: published by the Free Software Foundation; either version 2 of the Chris@662: License, or (at your option) any later version. See the file Chris@662: COPYING included with this distribution for more information. Chris@662: */ Chris@662: Chris@662: #include "Surveyer.h" Chris@662: Chris@662: #include Chris@662: Chris@662: #include Chris@662: Chris@662: #include Chris@662: #include Chris@662: #include Chris@662: #include Chris@662: #include Chris@662: Chris@1538: #include "../version.h" Chris@662: Chris@662: #include "transform/TransformFactory.h" Chris@662: #include "plugin/PluginIdentifier.h" Chris@662: Chris@662: Surveyer::Surveyer(QString hostname, QString testPath, QString surveyPath) : Chris@662: m_httpFailed(false), Chris@662: m_hostname(hostname), Chris@662: m_testPath(testPath), Chris@662: m_surveyPath(surveyPath), Chris@666: m_reply(0), Chris@662: m_nm(new QNetworkAccessManager) Chris@662: { Chris@662: QSettings settings; Chris@662: settings.beginGroup("Survey"); Chris@662: if (!settings.contains("countdown")) { Chris@662: settings.setValue("countdown", 15); Chris@662: settings.endGroup(); Chris@662: return; Chris@662: } Chris@662: int countdown = settings.value("countdown").toInt(); Chris@662: if (countdown == 0) { Chris@662: // The countdown value will now remain 0 until we have Chris@662: // successfully tested for a survey and offered it to the Chris@662: // user. If the survey doesn't exist any more, then we'll Chris@662: // simply never present it to the user and the countdown will Chris@662: // remain 0 forever. If the survey does exist, then we offer Chris@662: // the user the chance to respond to it and (regardless of Chris@662: // whether they want to or not) set the countdown to -1 so Chris@662: // that it is never offered again. Chris@662: QUrl url(QString("http://%1/%2").arg(m_hostname).arg(m_testPath)); Chris@665: cerr << "Surveyer: Test URL is " << url << endl; Chris@662: m_reply = m_nm->get(QNetworkRequest(url)); Chris@662: connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), Chris@662: this, SLOT(error(QNetworkReply::NetworkError))); Chris@662: connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); Chris@662: } else if (countdown > 0) { Chris@662: settings.setValue("countdown", countdown-1); Chris@662: } Chris@662: settings.endGroup(); Chris@662: } Chris@662: Chris@662: Surveyer::~Surveyer() Chris@662: { Chris@662: if (m_reply) { Chris@662: m_reply->abort(); Chris@662: m_reply->deleteLater(); Chris@662: } Chris@662: delete m_nm; Chris@662: } Chris@662: Chris@662: void Chris@662: Surveyer::error(QNetworkReply::NetworkError) Chris@662: { Chris@665: cerr << "Surveyer: error: " << m_reply->errorString() << endl; Chris@662: m_httpFailed = true; Chris@662: } Chris@662: Chris@662: void Chris@662: Surveyer::finished() Chris@662: { Chris@662: if (m_httpFailed) return; Chris@662: Chris@662: QString title = "Sonic Visualiser - User Survey"; Chris@662: 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?

"; Chris@662: Chris@662: QMessageBox mb(dynamic_cast(parent())); Chris@662: mb.setWindowTitle(title); Chris@662: mb.setText(text); Chris@662: Chris@662: QPushButton *yes = mb.addButton(tr("Yes! Take me to the survey"), QMessageBox::ActionRole); Chris@662: mb.addButton(tr("No, thanks"), QMessageBox::RejectRole); Chris@662: Chris@662: mb.exec(); Chris@662: Chris@662: QSettings settings; Chris@662: settings.beginGroup("Survey"); Chris@662: settings.setValue("countdown", -1); Chris@662: settings.endGroup(); Chris@662: Chris@662: if (mb.clickedButton() == yes) { Chris@662: QString svarg = SV_VERSION; Chris@662: QString platformarg = "unknown"; Chris@662: #ifdef Q_OS_WIN32 Chris@662: platformarg = "win32"; Chris@662: #else Chris@662: #ifdef Q_OS_MAC Chris@662: platformarg = "osx"; Chris@662: #else Chris@662: platformarg = "posix"; Chris@662: #endif Chris@662: #endif Chris@662: QString plugsarg; Chris@662: TransformFactory *tf = TransformFactory::getInstance(); Chris@662: if (tf) { Chris@662: TransformList tl = tf->getAllTransformDescriptions(); Chris@662: std::set packages; Chris@662: for (size_t i = 0; i < tl.size(); ++i) { Chris@662: TransformId id = tl[i].identifier; Chris@662: Transform t; Chris@662: t.setIdentifier(id); Chris@662: QString plugid = t.getPluginIdentifier(); Chris@662: QString type, soname, label; Chris@662: PluginIdentifier::parseIdentifier(plugid, type, soname, label); Chris@662: if (type == "vamp") packages.insert(soname); Chris@662: } Chris@662: for (std::set::const_iterator i = packages.begin(); Chris@662: i != packages.end(); ++i) { Chris@662: if (plugsarg != "") plugsarg = plugsarg + ","; Chris@662: plugsarg = plugsarg + *i; Chris@662: } Chris@662: } Chris@662: 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))); Chris@662: } Chris@662: } Chris@662: Chris@662: