changeset 662:6f06094daba0

Restore and update old Surveyer class (survey itself is not there yet)
author Chris Cannam
date Tue, 26 Nov 2013 11:41:12 +0000
parents 9d6eadfd390e
children 55efa5a18814
files main/MainWindow.cpp main/MainWindow.h main/Surveyer.cpp main/Surveyer.h sv.pro
diffstat 5 files changed, 211 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Tue Nov 26 11:16:58 2013 +0000
+++ b/main/MainWindow.cpp	Tue Nov 26 11:41:12 2013 +0000
@@ -82,6 +82,7 @@
 #include "rdf/PluginRDFIndexer.h"
 #include "rdf/RDFExporter.h"
 
+#include "Surveyer.h"
 #include "framework/VersionTester.h"
 
 // For version information
@@ -306,8 +307,11 @@
     
     TransformFactory::getInstance()->startPopulationThread();
 
+    m_surveyer = new Surveyer
+        ("sonicvisualiser.org", "survey23-present.txt", "survey23.php");
+
     m_versionTester = new VersionTester
-        ("sonicvisualiser.org", "/latest-version.txt", SV_VERSION);
+        ("sonicvisualiser.org", "latest-version.txt", SV_VERSION);
     connect(m_versionTester, SIGNAL(newerVersionAvailable(QString)),
             this, SLOT(newerVersionAvailable(QString)));
 }
@@ -320,6 +324,7 @@
     delete m_preferencesDialog;
     delete m_layerTreeDialog;
     delete m_versionTester;
+    delete m_surveyer;
     Profiles::getInstance()->dump();
 //    SVDEBUG << "MainWindow::~MainWindow finishing" << endl;
 }
--- a/main/MainWindow.h	Tue Nov 26 11:16:58 2013 +0000
+++ b/main/MainWindow.h	Tue Nov 26 11:41:12 2013 +0000
@@ -61,6 +61,7 @@
 class QFileSystemWatcher;
 class QScrollArea;
 class VersionTester;
+class Surveyer;
 
 class MainWindow : public MainWindowBase
 {
@@ -248,6 +249,7 @@
 
     QFileSystemWatcher      *m_templateWatcher;
 
+    Surveyer                *m_surveyer;
     VersionTester           *m_versionTester;
 
     struct LayerConfiguration {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/Surveyer.cpp	Tue Nov 26 11:41:12 2013 +0000
@@ -0,0 +1,148 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+/*
+   This is a modified version of a source file from the 
+   Rosegarden MIDI and audio sequencer and notation editor.
+   This file copyright 2000-2009 Chris Cannam.
+*/
+
+#include "Surveyer.h"
+
+#include <iostream>
+
+#include <QNetworkAccessManager>
+
+#include <QSettings>
+#include <QMessageBox>
+#include <QDesktopServices>
+#include <QPushButton>
+#include <QUrl>
+
+#include "version.h"
+
+#include "transform/TransformFactory.h"
+#include "plugin/PluginIdentifier.h"
+
+Surveyer::Surveyer(QString hostname, QString testPath, QString surveyPath) :
+    m_httpFailed(false),
+    m_hostname(hostname),
+    m_testPath(testPath),
+    m_surveyPath(surveyPath),
+    m_nm(new QNetworkAccessManager)
+{
+    QSettings settings;
+    settings.beginGroup("Survey");
+    if (!settings.contains("countdown")) {
+        settings.setValue("countdown", 15);
+        settings.endGroup();
+        return;
+    }
+    int countdown = settings.value("countdown").toInt();
+    if (countdown == 0) {
+        // The countdown value will now remain 0 until we have
+        // successfully tested for a survey and offered it to the
+        // user.  If the survey doesn't exist any more, then we'll
+        // simply never present it to the user and the countdown will
+        // remain 0 forever.  If the survey does exist, then we offer
+        // 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));
+        std::cerr << "Surveyer: Test URL is " << url << std::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.endGroup();
+}
+
+Surveyer::~Surveyer()
+{
+    if (m_reply) {
+        m_reply->abort();
+        m_reply->deleteLater();
+    }
+    delete m_nm;
+}
+
+void
+Surveyer::error(QNetworkReply::NetworkError)
+{
+    std::cerr << "Surveyer: error: " << m_reply->errorString() << std::endl;
+    m_httpFailed = true;
+}
+
+void
+Surveyer::finished()
+{
+    if (m_httpFailed) return;
+
+    QString title = "Sonic Visualiser - User Survey";
+    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>";
+
+    QMessageBox mb(dynamic_cast<QWidget *>(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);
+
+    mb.exec();
+
+    QSettings settings;
+    settings.beginGroup("Survey");
+    settings.setValue("countdown", -1);
+    settings.endGroup();
+
+    if (mb.clickedButton() == yes) {
+        QString svarg = SV_VERSION;
+        QString platformarg = "unknown";
+#ifdef Q_OS_WIN32
+        platformarg = "win32";
+#else
+#ifdef Q_OS_MAC
+        platformarg = "osx";
+#else
+        platformarg = "posix";
+#endif
+#endif
+        QString plugsarg;
+        TransformFactory *tf = TransformFactory::getInstance();
+        if (tf) {
+            TransformList tl = tf->getAllTransformDescriptions();
+            std::set<QString> packages;
+            for (size_t i = 0; i < tl.size(); ++i) {
+                TransformId id = tl[i].identifier;
+                Transform t;
+                t.setIdentifier(id);
+                QString plugid = t.getPluginIdentifier();
+                QString type, soname, label;
+                PluginIdentifier::parseIdentifier(plugid, type, soname, label);
+                if (type == "vamp") packages.insert(soname);
+            }
+            for (std::set<QString>::const_iterator i = packages.begin();
+                 i != packages.end(); ++i) {
+                if (plugsarg != "") plugsarg = plugsarg + ",";
+                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)));
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/Surveyer.h	Tue Nov 26 11:41:12 2013 +0000
@@ -0,0 +1,53 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+/*
+   This is a modified version of a source file from the 
+   Rosegarden MIDI and audio sequencer and notation editor.
+   This file copyright 2000-2009 Chris Cannam.
+*/
+
+#ifndef _SURVEYER_H_
+#define _SURVEYER_H_
+
+#include <QStringList>
+#include <QString>
+#include <QObject>
+#include <QNetworkReply>
+
+class QNetworkAccessManager;
+
+class Surveyer : public QObject
+{
+    Q_OBJECT
+
+public:
+    Surveyer(QString hostname, QString testPath, QString surveyPath);
+    virtual ~Surveyer();
+
+protected slots:
+    void finished();
+    void error(QNetworkReply::NetworkError);
+
+private:
+    bool m_httpFailed;
+    QString m_hostname;
+    QString m_testPath;
+    QString m_surveyPath;
+    QNetworkReply *m_reply;
+    QNetworkAccessManager *m_nm;
+};
+
+#endif
+
--- a/sv.pro	Tue Nov 26 11:16:58 2013 +0000
+++ b/sv.pro	Tue Nov 26 11:41:12 2013 +0000
@@ -69,10 +69,12 @@
 RESOURCES += sonic-visualiser.qrc
 
 HEADERS += main/MainWindow.h \
+           main/Surveyer.h \
            main/PreferencesDialog.h
 SOURCES += main/main.cpp \
            main/OSCHandler.cpp \
            main/MainWindow.cpp \
+           main/Surveyer.cpp \
            main/PreferencesDialog.cpp 
 
 # for mac integration