changeset 333:faff9cd8f663

* Offer the user a chance to answer our survey (only once, and only after several runs of the program, and only if the survey is known to be live on the website)
author Chris Cannam
date Thu, 27 Aug 2009 16:31:45 +0000
parents b168df820681
children f50fa43143ae
files main/MainWindow.cpp main/MainWindow.h main/Surveyer.cpp main/Surveyer.h sv.pro
diffstat 5 files changed, 211 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Fri Aug 14 14:01:09 2009 +0000
+++ b/main/MainWindow.cpp	Thu Aug 27 16:31:45 2009 +0000
@@ -78,6 +78,8 @@
 #include "rdf/PluginRDFIndexer.h"
 #include "rdf/RDFExporter.h"
 
+#include "Surveyer.h"
+
 // For version information
 #include <vamp/vamp.h>
 #include <vamp-hostsdk/PluginBase.h>
@@ -347,6 +349,8 @@
     setupTransformsMenu();
 
     m_mainMenusCreated = true;
+
+    Surveyer *surveyer = new Surveyer(this);
 }
 
 void
@@ -4000,4 +4004,12 @@
     m_keyReference->show();
 }
 
-
+void
+MainWindow::newerVersionAvailable(QString version)
+{
+    QString title(tr("Newer version available"));
+    QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of Sonic Visualiser.  Version %3 is now available.</p><p>Please consult the <a href=\"http://sonicvisualiser.org/\">Sonic Visualiser website</a> for more information.</p>").arg(SV_VERSION).arg(version));
+    QMessageBox::information(this, title, text);
+}
+
+
--- a/main/MainWindow.h	Fri Aug 14 14:01:09 2009 +0000
+++ b/main/MainWindow.h	Thu Aug 27 16:31:45 2009 +0000
@@ -173,6 +173,7 @@
     virtual void help();
     virtual void about();
     virtual void keyReference();
+    virtual void newerVersionAvailable(QString);
 
 protected:
     Overview                *m_overview;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/Surveyer.cpp	Thu Aug 27 16:31:45 2009 +0000
@@ -0,0 +1,146 @@
+/* -*- 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 <QHttp>
+
+#include <QSettings>
+#include <QMessageBox>
+#include <QDesktopServices>
+#include <QPushButton>
+#include <QUrl>
+
+#include "version.h"
+
+#include "transform/TransformFactory.h"
+#include "plugin/PluginIdentifier.h"
+
+Surveyer::Surveyer(QObject *parent) :
+    QObject(parent),
+    m_httpFailed(false)
+{
+    QSettings settings;
+    settings.beginGroup("Survey");
+    if (!settings.contains("countdown")) {
+        settings.setValue("countdown", 5);
+        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.
+        QHttp *http = new QHttp();
+        connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
+                this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &)));
+        connect(http, SIGNAL(done(bool)),
+                this, SLOT(httpDone(bool)));
+        http->setHost("sonicvisualiser.org");
+        http->get("/survey16-present.txt");
+    } else if (countdown > 0) {
+        settings.setValue("countdown", countdown-1);
+    }
+    settings.endGroup();
+}
+
+Surveyer::~Surveyer()
+{
+}
+
+void
+Surveyer::httpResponseHeaderReceived(const QHttpResponseHeader &h)
+{
+    if (h.statusCode() / 100 != 2) m_httpFailed = true;
+}
+
+void
+Surveyer::httpDone(bool error)
+{
+    QHttp *http = const_cast<QHttp *>(dynamic_cast<const QHttp *>(sender()));
+    if (!http) return;
+    http->deleteLater();
+//    if (error || m_httpFailed) return;
+
+    QByteArray responseData = http->readAll();
+    QString str = QString::fromUtf8(responseData.data());
+    QStringList lines = str.split('\n', QString::SkipEmptyParts);
+    if (lines.empty()) return;
+
+    QString response = lines[0];
+//    if (response != "yes") 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 there's absolutely nothing commercial about it, 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();
+
+    if (mb.clickedButton() == yes) {
+        QString svarg = SV_VERSION;
+        QString platformarg = "unknown";
+#ifdef _WIN32
+        platformarg = "win32";
+#else
+#ifdef __APPLE__
+        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);
+                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://sonicvisualiser.org/survey16.php?sv=%1&plugs=%2&platform=%3").arg(svarg).arg(plugsarg).arg(platformarg)));
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/Surveyer.h	Thu Aug 27 16:31:45 2009 +0000
@@ -0,0 +1,47 @@
+/* -*- 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>
+
+class QHttpResponseHeader;
+
+class Surveyer : public QObject
+{
+    Q_OBJECT
+
+public:
+    Surveyer(QObject *parent = 0);
+    virtual ~Surveyer();
+
+protected slots:
+    void httpResponseHeaderReceived(const QHttpResponseHeader &);
+    void httpDone(bool);
+
+private:
+    bool m_httpFailed;
+};
+
+#endif
+
--- a/sv.pro	Fri Aug 14 14:01:09 2009 +0000
+++ b/sv.pro	Thu Aug 27 16:31:45 2009 +0000
@@ -39,11 +39,13 @@
 
 # Input
 HEADERS += main/MainWindow.h \
-           main/PreferencesDialog.h
+           main/PreferencesDialog.h \
+           main/Surveyer.h
 SOURCES += main/main.cpp \
            main/OSCHandler.cpp \
            main/MainWindow.cpp \
-           main/PreferencesDialog.cpp
+           main/PreferencesDialog.cpp \
+           main/Surveyer.cpp
 RESOURCES += sonic-visualiser.qrc