comparison main/Surveyer.cpp @ 677:bfd68cc71a25 imaf_enc

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