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