Chris@333
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@333
|
2
|
Chris@333
|
3 /*
|
Chris@333
|
4 Sonic Visualiser
|
Chris@333
|
5 An audio file viewer and annotation editor.
|
Chris@333
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@333
|
7
|
Chris@333
|
8 This program is free software; you can redistribute it and/or
|
Chris@333
|
9 modify it under the terms of the GNU General Public License as
|
Chris@333
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@333
|
11 License, or (at your option) any later version. See the file
|
Chris@333
|
12 COPYING included with this distribution for more information.
|
Chris@333
|
13 */
|
Chris@333
|
14
|
Chris@333
|
15 /*
|
Chris@333
|
16 This is a modified version of a source file from the
|
Chris@333
|
17 Rosegarden MIDI and audio sequencer and notation editor.
|
Chris@333
|
18 This file copyright 2000-2009 Chris Cannam.
|
Chris@333
|
19 */
|
Chris@333
|
20
|
Chris@333
|
21 #include "Surveyer.h"
|
Chris@333
|
22
|
Chris@333
|
23 #include <iostream>
|
Chris@333
|
24
|
Chris@333
|
25 #include <QHttp>
|
Chris@333
|
26
|
Chris@333
|
27 #include <QSettings>
|
Chris@333
|
28 #include <QMessageBox>
|
Chris@333
|
29 #include <QDesktopServices>
|
Chris@333
|
30 #include <QPushButton>
|
Chris@333
|
31 #include <QUrl>
|
Chris@333
|
32
|
Chris@333
|
33 #include "version.h"
|
Chris@333
|
34
|
Chris@333
|
35 #include "transform/TransformFactory.h"
|
Chris@333
|
36 #include "plugin/PluginIdentifier.h"
|
Chris@333
|
37
|
Chris@333
|
38 Surveyer::Surveyer(QObject *parent) :
|
Chris@333
|
39 QObject(parent),
|
Chris@333
|
40 m_httpFailed(false)
|
Chris@333
|
41 {
|
Chris@333
|
42 QSettings settings;
|
Chris@333
|
43 settings.beginGroup("Survey");
|
Chris@333
|
44 if (!settings.contains("countdown")) {
|
Chris@343
|
45 settings.setValue("countdown", 15);
|
Chris@333
|
46 settings.endGroup();
|
Chris@333
|
47 return;
|
Chris@333
|
48 }
|
Chris@333
|
49 int countdown = settings.value("countdown").toInt();
|
Chris@333
|
50 if (countdown == 0) {
|
Chris@333
|
51 // The countdown value will now remain 0 until we have
|
Chris@333
|
52 // successfully tested for a survey and offered it to the
|
Chris@333
|
53 // user. If the survey doesn't exist any more, then we'll
|
Chris@333
|
54 // simply never present it to the user and the countdown will
|
Chris@333
|
55 // remain 0 forever. If the survey does exist, then we offer
|
Chris@333
|
56 // the user the chance to respond to it and (regardless of
|
Chris@333
|
57 // whether they want to or not) set the countdown to -1 so
|
Chris@333
|
58 // that it is never offered again.
|
Chris@333
|
59 QHttp *http = new QHttp();
|
Chris@333
|
60 connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
|
Chris@333
|
61 this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &)));
|
Chris@333
|
62 connect(http, SIGNAL(done(bool)),
|
Chris@333
|
63 this, SLOT(httpDone(bool)));
|
Chris@333
|
64 http->setHost("sonicvisualiser.org");
|
Chris@333
|
65 http->get("/survey16-present.txt");
|
Chris@333
|
66 } else if (countdown > 0) {
|
Chris@333
|
67 settings.setValue("countdown", countdown-1);
|
Chris@333
|
68 }
|
Chris@333
|
69 settings.endGroup();
|
Chris@333
|
70 }
|
Chris@333
|
71
|
Chris@333
|
72 Surveyer::~Surveyer()
|
Chris@333
|
73 {
|
Chris@333
|
74 }
|
Chris@333
|
75
|
Chris@333
|
76 void
|
Chris@333
|
77 Surveyer::httpResponseHeaderReceived(const QHttpResponseHeader &h)
|
Chris@333
|
78 {
|
Chris@333
|
79 if (h.statusCode() / 100 != 2) m_httpFailed = true;
|
Chris@333
|
80 }
|
Chris@333
|
81
|
Chris@333
|
82 void
|
Chris@333
|
83 Surveyer::httpDone(bool error)
|
Chris@333
|
84 {
|
Chris@333
|
85 QHttp *http = const_cast<QHttp *>(dynamic_cast<const QHttp *>(sender()));
|
Chris@333
|
86 if (!http) return;
|
Chris@333
|
87 http->deleteLater();
|
Chris@333
|
88 // if (error || m_httpFailed) return;
|
Chris@333
|
89
|
Chris@333
|
90 QByteArray responseData = http->readAll();
|
Chris@333
|
91 QString str = QString::fromUtf8(responseData.data());
|
Chris@333
|
92 QStringList lines = str.split('\n', QString::SkipEmptyParts);
|
Chris@333
|
93 if (lines.empty()) return;
|
Chris@333
|
94
|
Chris@333
|
95 QString response = lines[0];
|
Chris@333
|
96 // if (response != "yes") return;
|
Chris@333
|
97
|
Chris@333
|
98 QString title = "Sonic Visualiser - User Survey";
|
Chris@334
|
99 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@333
|
100
|
Chris@333
|
101 QMessageBox mb(dynamic_cast<QWidget *>(parent()));
|
Chris@333
|
102 mb.setWindowTitle(title);
|
Chris@333
|
103 mb.setText(text);
|
Chris@333
|
104
|
Chris@333
|
105 QPushButton *yes = mb.addButton(tr("Yes! Take me to the survey"), QMessageBox::ActionRole);
|
Chris@334
|
106 mb.addButton(tr("No, thanks"), QMessageBox::RejectRole);
|
Chris@333
|
107
|
Chris@333
|
108 mb.exec();
|
Chris@333
|
109
|
Chris@334
|
110 QSettings settings;
|
Chris@334
|
111 settings.beginGroup("Survey");
|
Chris@334
|
112 settings.setValue("countdown", -1);
|
Chris@334
|
113 settings.endGroup();
|
Chris@334
|
114
|
Chris@333
|
115 if (mb.clickedButton() == yes) {
|
Chris@333
|
116 QString svarg = SV_VERSION;
|
Chris@333
|
117 QString platformarg = "unknown";
|
Chris@333
|
118 #ifdef _WIN32
|
Chris@333
|
119 platformarg = "win32";
|
Chris@333
|
120 #else
|
Chris@333
|
121 #ifdef __APPLE__
|
Chris@333
|
122 platformarg = "osx";
|
Chris@333
|
123 #else
|
Chris@333
|
124 platformarg = "posix";
|
Chris@333
|
125 #endif
|
Chris@333
|
126 #endif
|
Chris@333
|
127 QString plugsarg;
|
Chris@333
|
128 TransformFactory *tf = TransformFactory::getInstance();
|
Chris@333
|
129 if (tf) {
|
Chris@333
|
130 TransformList tl = tf->getAllTransformDescriptions();
|
Chris@333
|
131 std::set<QString> packages;
|
Chris@333
|
132 for (size_t i = 0; i < tl.size(); ++i) {
|
Chris@333
|
133 TransformId id = tl[i].identifier;
|
Chris@333
|
134 Transform t;
|
Chris@333
|
135 t.setIdentifier(id);
|
Chris@333
|
136 QString plugid = t.getPluginIdentifier();
|
Chris@333
|
137 QString type, soname, label;
|
Chris@333
|
138 PluginIdentifier::parseIdentifier(plugid, type, soname, label);
|
Chris@334
|
139 if (type == "vamp") packages.insert(soname);
|
Chris@333
|
140 }
|
Chris@333
|
141 for (std::set<QString>::const_iterator i = packages.begin();
|
Chris@333
|
142 i != packages.end(); ++i) {
|
Chris@333
|
143 if (plugsarg != "") plugsarg = plugsarg + ",";
|
Chris@333
|
144 plugsarg = plugsarg + *i;
|
Chris@333
|
145 }
|
Chris@333
|
146 }
|
Chris@333
|
147 QDesktopServices::openUrl(QUrl(QString("http://sonicvisualiser.org/survey16.php?sv=%1&plugs=%2&platform=%3").arg(svarg).arg(plugsarg).arg(platformarg)));
|
Chris@333
|
148 }
|
Chris@333
|
149 }
|
Chris@333
|
150
|
Chris@333
|
151
|