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 /*
|
Chris@662
|
16 This is a modified version of a source file from the
|
Chris@662
|
17 Rosegarden MIDI and audio sequencer and notation editor.
|
Chris@662
|
18 This file copyright 2000-2009 Chris Cannam.
|
Chris@662
|
19 */
|
Chris@662
|
20
|
Chris@662
|
21 #include "Surveyer.h"
|
Chris@662
|
22
|
Chris@662
|
23 #include <iostream>
|
Chris@662
|
24
|
Chris@662
|
25 #include <QNetworkAccessManager>
|
Chris@662
|
26
|
Chris@662
|
27 #include <QSettings>
|
Chris@662
|
28 #include <QMessageBox>
|
Chris@662
|
29 #include <QDesktopServices>
|
Chris@662
|
30 #include <QPushButton>
|
Chris@662
|
31 #include <QUrl>
|
Chris@662
|
32
|
Chris@662
|
33 #include "version.h"
|
Chris@662
|
34
|
Chris@662
|
35 #include "transform/TransformFactory.h"
|
Chris@662
|
36 #include "plugin/PluginIdentifier.h"
|
Chris@662
|
37
|
Chris@662
|
38 Surveyer::Surveyer(QString hostname, QString testPath, QString surveyPath) :
|
Chris@662
|
39 m_httpFailed(false),
|
Chris@662
|
40 m_hostname(hostname),
|
Chris@662
|
41 m_testPath(testPath),
|
Chris@662
|
42 m_surveyPath(surveyPath),
|
Chris@662
|
43 m_nm(new QNetworkAccessManager)
|
Chris@662
|
44 {
|
Chris@662
|
45 QSettings settings;
|
Chris@662
|
46 settings.beginGroup("Survey");
|
Chris@662
|
47 if (!settings.contains("countdown")) {
|
Chris@662
|
48 settings.setValue("countdown", 15);
|
Chris@662
|
49 settings.endGroup();
|
Chris@662
|
50 return;
|
Chris@662
|
51 }
|
Chris@662
|
52 int countdown = settings.value("countdown").toInt();
|
Chris@662
|
53 if (countdown == 0) {
|
Chris@662
|
54 // The countdown value will now remain 0 until we have
|
Chris@662
|
55 // successfully tested for a survey and offered it to the
|
Chris@662
|
56 // user. If the survey doesn't exist any more, then we'll
|
Chris@662
|
57 // simply never present it to the user and the countdown will
|
Chris@662
|
58 // remain 0 forever. If the survey does exist, then we offer
|
Chris@662
|
59 // the user the chance to respond to it and (regardless of
|
Chris@662
|
60 // whether they want to or not) set the countdown to -1 so
|
Chris@662
|
61 // that it is never offered again.
|
Chris@662
|
62 QUrl url(QString("http://%1/%2").arg(m_hostname).arg(m_testPath));
|
Chris@662
|
63 std::cerr << "Surveyer: Test URL is " << url << std::endl;
|
Chris@662
|
64 m_reply = m_nm->get(QNetworkRequest(url));
|
Chris@662
|
65 connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)),
|
Chris@662
|
66 this, SLOT(error(QNetworkReply::NetworkError)));
|
Chris@662
|
67 connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
|
Chris@662
|
68 } else if (countdown > 0) {
|
Chris@662
|
69 settings.setValue("countdown", countdown-1);
|
Chris@662
|
70 }
|
Chris@662
|
71 settings.endGroup();
|
Chris@662
|
72 }
|
Chris@662
|
73
|
Chris@662
|
74 Surveyer::~Surveyer()
|
Chris@662
|
75 {
|
Chris@662
|
76 if (m_reply) {
|
Chris@662
|
77 m_reply->abort();
|
Chris@662
|
78 m_reply->deleteLater();
|
Chris@662
|
79 }
|
Chris@662
|
80 delete m_nm;
|
Chris@662
|
81 }
|
Chris@662
|
82
|
Chris@662
|
83 void
|
Chris@662
|
84 Surveyer::error(QNetworkReply::NetworkError)
|
Chris@662
|
85 {
|
Chris@662
|
86 std::cerr << "Surveyer: error: " << m_reply->errorString() << std::endl;
|
Chris@662
|
87 m_httpFailed = true;
|
Chris@662
|
88 }
|
Chris@662
|
89
|
Chris@662
|
90 void
|
Chris@662
|
91 Surveyer::finished()
|
Chris@662
|
92 {
|
Chris@662
|
93 if (m_httpFailed) return;
|
Chris@662
|
94
|
Chris@662
|
95 QString title = "Sonic Visualiser - User Survey";
|
Chris@662
|
96 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
|
97
|
Chris@662
|
98 QMessageBox mb(dynamic_cast<QWidget *>(parent()));
|
Chris@662
|
99 mb.setWindowTitle(title);
|
Chris@662
|
100 mb.setText(text);
|
Chris@662
|
101
|
Chris@662
|
102 QPushButton *yes = mb.addButton(tr("Yes! Take me to the survey"), QMessageBox::ActionRole);
|
Chris@662
|
103 mb.addButton(tr("No, thanks"), QMessageBox::RejectRole);
|
Chris@662
|
104
|
Chris@662
|
105 mb.exec();
|
Chris@662
|
106
|
Chris@662
|
107 QSettings settings;
|
Chris@662
|
108 settings.beginGroup("Survey");
|
Chris@662
|
109 settings.setValue("countdown", -1);
|
Chris@662
|
110 settings.endGroup();
|
Chris@662
|
111
|
Chris@662
|
112 if (mb.clickedButton() == yes) {
|
Chris@662
|
113 QString svarg = SV_VERSION;
|
Chris@662
|
114 QString platformarg = "unknown";
|
Chris@662
|
115 #ifdef Q_OS_WIN32
|
Chris@662
|
116 platformarg = "win32";
|
Chris@662
|
117 #else
|
Chris@662
|
118 #ifdef Q_OS_MAC
|
Chris@662
|
119 platformarg = "osx";
|
Chris@662
|
120 #else
|
Chris@662
|
121 platformarg = "posix";
|
Chris@662
|
122 #endif
|
Chris@662
|
123 #endif
|
Chris@662
|
124 QString plugsarg;
|
Chris@662
|
125 TransformFactory *tf = TransformFactory::getInstance();
|
Chris@662
|
126 if (tf) {
|
Chris@662
|
127 TransformList tl = tf->getAllTransformDescriptions();
|
Chris@662
|
128 std::set<QString> packages;
|
Chris@662
|
129 for (size_t i = 0; i < tl.size(); ++i) {
|
Chris@662
|
130 TransformId id = tl[i].identifier;
|
Chris@662
|
131 Transform t;
|
Chris@662
|
132 t.setIdentifier(id);
|
Chris@662
|
133 QString plugid = t.getPluginIdentifier();
|
Chris@662
|
134 QString type, soname, label;
|
Chris@662
|
135 PluginIdentifier::parseIdentifier(plugid, type, soname, label);
|
Chris@662
|
136 if (type == "vamp") packages.insert(soname);
|
Chris@662
|
137 }
|
Chris@662
|
138 for (std::set<QString>::const_iterator i = packages.begin();
|
Chris@662
|
139 i != packages.end(); ++i) {
|
Chris@662
|
140 if (plugsarg != "") plugsarg = plugsarg + ",";
|
Chris@662
|
141 plugsarg = plugsarg + *i;
|
Chris@662
|
142 }
|
Chris@662
|
143 }
|
Chris@662
|
144 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
|
145 }
|
Chris@662
|
146 }
|
Chris@662
|
147
|
Chris@662
|
148
|