Chris@333: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@333: Chris@333: /* Chris@333: Sonic Visualiser Chris@333: An audio file viewer and annotation editor. Chris@333: Centre for Digital Music, Queen Mary, University of London. Chris@333: Chris@333: This program is free software; you can redistribute it and/or Chris@333: modify it under the terms of the GNU General Public License as Chris@333: published by the Free Software Foundation; either version 2 of the Chris@333: License, or (at your option) any later version. See the file Chris@333: COPYING included with this distribution for more information. Chris@333: */ Chris@333: Chris@333: /* Chris@333: This is a modified version of a source file from the Chris@333: Rosegarden MIDI and audio sequencer and notation editor. Chris@333: This file copyright 2000-2009 Chris Cannam. Chris@333: */ Chris@333: Chris@333: #include "Surveyer.h" Chris@333: Chris@333: #include Chris@333: Chris@333: #include Chris@333: Chris@333: #include Chris@333: #include Chris@333: #include Chris@333: #include Chris@333: #include Chris@333: Chris@333: #include "version.h" Chris@333: Chris@333: #include "transform/TransformFactory.h" Chris@333: #include "plugin/PluginIdentifier.h" Chris@333: Chris@333: Surveyer::Surveyer(QObject *parent) : Chris@333: QObject(parent), Chris@333: m_httpFailed(false) Chris@333: { Chris@333: QSettings settings; Chris@333: settings.beginGroup("Survey"); Chris@333: if (!settings.contains("countdown")) { Chris@333: settings.setValue("countdown", 5); Chris@333: settings.endGroup(); Chris@333: return; Chris@333: } Chris@333: int countdown = settings.value("countdown").toInt(); Chris@333: if (countdown == 0) { Chris@333: // The countdown value will now remain 0 until we have Chris@333: // successfully tested for a survey and offered it to the Chris@333: // user. If the survey doesn't exist any more, then we'll Chris@333: // simply never present it to the user and the countdown will Chris@333: // remain 0 forever. If the survey does exist, then we offer Chris@333: // the user the chance to respond to it and (regardless of Chris@333: // whether they want to or not) set the countdown to -1 so Chris@333: // that it is never offered again. Chris@333: QHttp *http = new QHttp(); Chris@333: connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), Chris@333: this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &))); Chris@333: connect(http, SIGNAL(done(bool)), Chris@333: this, SLOT(httpDone(bool))); Chris@333: http->setHost("sonicvisualiser.org"); Chris@333: http->get("/survey16-present.txt"); Chris@333: } else if (countdown > 0) { Chris@333: settings.setValue("countdown", countdown-1); Chris@333: } Chris@333: settings.endGroup(); Chris@333: } Chris@333: Chris@333: Surveyer::~Surveyer() Chris@333: { Chris@333: } Chris@333: Chris@333: void Chris@333: Surveyer::httpResponseHeaderReceived(const QHttpResponseHeader &h) Chris@333: { Chris@333: if (h.statusCode() / 100 != 2) m_httpFailed = true; Chris@333: } Chris@333: Chris@333: void Chris@333: Surveyer::httpDone(bool error) Chris@333: { Chris@333: QHttp *http = const_cast(dynamic_cast(sender())); Chris@333: if (!http) return; Chris@333: http->deleteLater(); Chris@333: // if (error || m_httpFailed) return; Chris@333: Chris@333: QByteArray responseData = http->readAll(); Chris@333: QString str = QString::fromUtf8(responseData.data()); Chris@333: QStringList lines = str.split('\n', QString::SkipEmptyParts); Chris@333: if (lines.empty()) return; Chris@333: Chris@333: QString response = lines[0]; Chris@333: // if (response != "yes") return; Chris@333: Chris@333: QString title = "Sonic Visualiser - User Survey"; Chris@334: 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@333: Chris@333: QMessageBox mb(dynamic_cast(parent())); Chris@333: mb.setWindowTitle(title); Chris@333: mb.setText(text); Chris@333: Chris@333: QPushButton *yes = mb.addButton(tr("Yes! Take me to the survey"), QMessageBox::ActionRole); Chris@334: mb.addButton(tr("No, thanks"), QMessageBox::RejectRole); Chris@333: Chris@333: mb.exec(); Chris@333: Chris@334: QSettings settings; Chris@334: settings.beginGroup("Survey"); Chris@334: settings.setValue("countdown", -1); Chris@334: settings.endGroup(); Chris@334: Chris@333: if (mb.clickedButton() == yes) { Chris@333: QString svarg = SV_VERSION; Chris@333: QString platformarg = "unknown"; Chris@333: #ifdef _WIN32 Chris@333: platformarg = "win32"; Chris@333: #else Chris@333: #ifdef __APPLE__ Chris@333: platformarg = "osx"; Chris@333: #else Chris@333: platformarg = "posix"; Chris@333: #endif Chris@333: #endif Chris@333: QString plugsarg; Chris@333: TransformFactory *tf = TransformFactory::getInstance(); Chris@333: if (tf) { Chris@333: TransformList tl = tf->getAllTransformDescriptions(); Chris@333: std::set packages; Chris@333: for (size_t i = 0; i < tl.size(); ++i) { Chris@333: TransformId id = tl[i].identifier; Chris@333: Transform t; Chris@333: t.setIdentifier(id); Chris@333: QString plugid = t.getPluginIdentifier(); Chris@333: QString type, soname, label; Chris@333: PluginIdentifier::parseIdentifier(plugid, type, soname, label); Chris@334: if (type == "vamp") packages.insert(soname); Chris@333: } Chris@333: for (std::set::const_iterator i = packages.begin(); Chris@333: i != packages.end(); ++i) { Chris@333: if (plugsarg != "") plugsarg = plugsarg + ","; Chris@333: plugsarg = plugsarg + *i; Chris@333: } Chris@333: } Chris@333: QDesktopServices::openUrl(QUrl(QString("http://sonicvisualiser.org/survey16.php?sv=%1&plugs=%2&platform=%3").arg(svarg).arg(plugsarg).arg(platformarg))); Chris@333: } Chris@333: } Chris@333: Chris@333: