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@2535: Surveyer::Surveyer(Config config) : Chris@2535: m_config(config), Chris@662: m_httpFailed(false), Chris@2126: m_reply(nullptr), Chris@662: m_nm(new QNetworkAccessManager) Chris@662: { Chris@662: QSettings settings; Chris@662: settings.beginGroup("Survey"); Chris@2535: if (!settings.contains(m_config.countdownKey)) { Chris@2535: settings.setValue(m_config.countdownKey, m_config.countdownFrom); Chris@662: settings.endGroup(); Chris@662: return; Chris@662: } Chris@2535: int countdown = settings.value(m_config.countdownKey).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@2535: QUrl url(QString("http://%1/%2") Chris@2535: .arg(m_config.hostname).arg(m_config.testPath)); Chris@2535: SVDEBUG << "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@2535: settings.setValue(m_config.countdownKey, 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@2535: SVDEBUG << "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@2535: QMessageBox mb(dynamic_cast(parent())); Chris@2535: mb.setWindowTitle(m_config.title); Chris@2535: mb.setText(m_config.text); Chris@662: Chris@2535: QPushButton *yes = Chris@2535: mb.addButton(m_config.acceptLabel, QMessageBox::ActionRole); Chris@2535: mb.addButton(m_config.rejectLabel, QMessageBox::RejectRole); Chris@662: Chris@662: mb.exec(); Chris@662: Chris@662: QSettings settings; Chris@662: settings.beginGroup("Survey"); Chris@2535: settings.setValue(m_config.countdownKey, -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@2535: Chris@2535: if (m_config.includeSystemInfo) { Chris@2535: 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))); Chris@2535: } else { Chris@2535: QDesktopServices::openUrl(QUrl(QString("http://%1/%2?sv=%3").arg(m_config.hostname).arg(m_config.surveyPath).arg(svarg))); Chris@2535: } Chris@662: } Chris@662: } Chris@662: Chris@662: