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