annotate main/Surveyer.cpp @ 1371:b75831cdf795 mp3-gapless

Stop reporting sync errors only when we really are at eof, i.e. after the input callback has been called again (previously we just tested whether we'd buffered up all the input, which of course we do in one go at the start)
author Chris Cannam
date Tue, 29 Nov 2016 16:45:29 +0000
parents 7707d9175d55
children 06f061c54b66
rev   line source
Chris@662 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@662 2
Chris@662 3 /*
Chris@662 4 Sonic Visualiser
Chris@662 5 An audio file viewer and annotation editor.
Chris@662 6 Centre for Digital Music, Queen Mary, University of London.
Chris@662 7
Chris@662 8 This program is free software; you can redistribute it and/or
Chris@662 9 modify it under the terms of the GNU General Public License as
Chris@662 10 published by the Free Software Foundation; either version 2 of the
Chris@662 11 License, or (at your option) any later version. See the file
Chris@662 12 COPYING included with this distribution for more information.
Chris@662 13 */
Chris@662 14
Chris@662 15 #include "Surveyer.h"
Chris@662 16
Chris@662 17 #include <iostream>
Chris@662 18
Chris@662 19 #include <QNetworkAccessManager>
Chris@662 20
Chris@662 21 #include <QSettings>
Chris@662 22 #include <QMessageBox>
Chris@662 23 #include <QDesktopServices>
Chris@662 24 #include <QPushButton>
Chris@662 25 #include <QUrl>
Chris@662 26
Chris@662 27 #include "version.h"
Chris@662 28
Chris@662 29 #include "transform/TransformFactory.h"
Chris@662 30 #include "plugin/PluginIdentifier.h"
Chris@662 31
Chris@662 32 Surveyer::Surveyer(QString hostname, QString testPath, QString surveyPath) :
Chris@662 33 m_httpFailed(false),
Chris@662 34 m_hostname(hostname),
Chris@662 35 m_testPath(testPath),
Chris@662 36 m_surveyPath(surveyPath),
Chris@666 37 m_reply(0),
Chris@662 38 m_nm(new QNetworkAccessManager)
Chris@662 39 {
Chris@662 40 QSettings settings;
Chris@662 41 settings.beginGroup("Survey");
Chris@662 42 if (!settings.contains("countdown")) {
Chris@662 43 settings.setValue("countdown", 15);
Chris@662 44 settings.endGroup();
Chris@662 45 return;
Chris@662 46 }
Chris@662 47 int countdown = settings.value("countdown").toInt();
Chris@662 48 if (countdown == 0) {
Chris@662 49 // The countdown value will now remain 0 until we have
Chris@662 50 // successfully tested for a survey and offered it to the
Chris@662 51 // user. If the survey doesn't exist any more, then we'll
Chris@662 52 // simply never present it to the user and the countdown will
Chris@662 53 // remain 0 forever. If the survey does exist, then we offer
Chris@662 54 // the user the chance to respond to it and (regardless of
Chris@662 55 // whether they want to or not) set the countdown to -1 so
Chris@662 56 // that it is never offered again.
Chris@662 57 QUrl url(QString("http://%1/%2").arg(m_hostname).arg(m_testPath));
Chris@665 58 cerr << "Surveyer: Test URL is " << url << endl;
Chris@662 59 m_reply = m_nm->get(QNetworkRequest(url));
Chris@662 60 connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)),
Chris@662 61 this, SLOT(error(QNetworkReply::NetworkError)));
Chris@662 62 connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
Chris@662 63 } else if (countdown > 0) {
Chris@662 64 settings.setValue("countdown", countdown-1);
Chris@662 65 }
Chris@662 66 settings.endGroup();
Chris@662 67 }
Chris@662 68
Chris@662 69 Surveyer::~Surveyer()
Chris@662 70 {
Chris@662 71 if (m_reply) {
Chris@662 72 m_reply->abort();
Chris@662 73 m_reply->deleteLater();
Chris@662 74 }
Chris@662 75 delete m_nm;
Chris@662 76 }
Chris@662 77
Chris@662 78 void
Chris@662 79 Surveyer::error(QNetworkReply::NetworkError)
Chris@662 80 {
Chris@665 81 cerr << "Surveyer: error: " << m_reply->errorString() << endl;
Chris@662 82 m_httpFailed = true;
Chris@662 83 }
Chris@662 84
Chris@662 85 void
Chris@662 86 Surveyer::finished()
Chris@662 87 {
Chris@662 88 if (m_httpFailed) return;
Chris@662 89
Chris@662 90 QString title = "Sonic Visualiser - User Survey";
Chris@662 91 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>";
Chris@662 92
Chris@662 93 QMessageBox mb(dynamic_cast<QWidget *>(parent()));
Chris@662 94 mb.setWindowTitle(title);
Chris@662 95 mb.setText(text);
Chris@662 96
Chris@662 97 QPushButton *yes = mb.addButton(tr("Yes! Take me to the survey"), QMessageBox::ActionRole);
Chris@662 98 mb.addButton(tr("No, thanks"), QMessageBox::RejectRole);
Chris@662 99
Chris@662 100 mb.exec();
Chris@662 101
Chris@662 102 QSettings settings;
Chris@662 103 settings.beginGroup("Survey");
Chris@662 104 settings.setValue("countdown", -1);
Chris@662 105 settings.endGroup();
Chris@662 106
Chris@662 107 if (mb.clickedButton() == yes) {
Chris@662 108 QString svarg = SV_VERSION;
Chris@662 109 QString platformarg = "unknown";
Chris@662 110 #ifdef Q_OS_WIN32
Chris@662 111 platformarg = "win32";
Chris@662 112 #else
Chris@662 113 #ifdef Q_OS_MAC
Chris@662 114 platformarg = "osx";
Chris@662 115 #else
Chris@662 116 platformarg = "posix";
Chris@662 117 #endif
Chris@662 118 #endif
Chris@662 119 QString plugsarg;
Chris@662 120 TransformFactory *tf = TransformFactory::getInstance();
Chris@662 121 if (tf) {
Chris@662 122 TransformList tl = tf->getAllTransformDescriptions();
Chris@662 123 std::set<QString> packages;
Chris@662 124 for (size_t i = 0; i < tl.size(); ++i) {
Chris@662 125 TransformId id = tl[i].identifier;
Chris@662 126 Transform t;
Chris@662 127 t.setIdentifier(id);
Chris@662 128 QString plugid = t.getPluginIdentifier();
Chris@662 129 QString type, soname, label;
Chris@662 130 PluginIdentifier::parseIdentifier(plugid, type, soname, label);
Chris@662 131 if (type == "vamp") packages.insert(soname);
Chris@662 132 }
Chris@662 133 for (std::set<QString>::const_iterator i = packages.begin();
Chris@662 134 i != packages.end(); ++i) {
Chris@662 135 if (plugsarg != "") plugsarg = plugsarg + ",";
Chris@662 136 plugsarg = plugsarg + *i;
Chris@662 137 }
Chris@662 138 }
Chris@662 139 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 140 }
Chris@662 141 }
Chris@662 142
Chris@662 143