Merge lp:~stolowski/unity-scopes-shell/send-user-agent into lp:unity-scopes-shell

Proposed by Paweł Stołowski
Status: Merged
Approved by: Pete Woods
Approved revision: 150
Merged at revision: 154
Proposed branch: lp:~stolowski/unity-scopes-shell/send-user-agent
Merge into: lp:unity-scopes-shell
Diff against target: 247 lines (+115/-11)
5 files modified
src/Unity/previewstack.cpp (+5/-1)
src/Unity/previewstack.h (+2/-1)
src/Unity/scope.cpp (+6/-1)
src/Unity/scopes.cpp (+94/-8)
src/Unity/scopes.h (+8/-0)
To merge this branch: bzr merge lp:~stolowski/unity-scopes-shell/send-user-agent
Reviewer Review Type Date Requested Status
Pete Woods (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+235766@code.launchpad.net

Commit message

Send build number, release name and package versions of unity8, shell plugin and scopes api with user-agent hint in SearchMetadata and PreviewMetadata.

Description of the change

Send build number, release name and package versions of unity8, shell plugin and scopes api with user-agent hint in SearchMetadata and PreviewMetadata.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) wrote :

Should we not use libdpkg-dev rather than parsing command line output?

Revision history for this message
Pete Woods (pete-woods) wrote :

Okay, fair enough there's a bunch of other stuff we need to find out.

150. By Paweł Stołowski

Make sure scopes are populated also if dpkg or lsb_release cannot be executed.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) :
review: Approve
151. By Paweł Stołowski

Merged trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Unity/previewstack.cpp'
2--- src/Unity/previewstack.cpp 2014-09-11 04:55:52 +0000
3+++ src/Unity/previewstack.cpp 2014-10-01 12:59:45 +0000
4@@ -77,10 +77,11 @@
5 return false;
6 }
7
8-void PreviewStack::setAssociatedScope(scopes_ng::Scope* scope, QUuid const& session_id)
9+void PreviewStack::setAssociatedScope(scopes_ng::Scope* scope, QUuid const& session_id, QString const& userAgent)
10 {
11 m_associatedScope = scope;
12 m_session_id = session_id;
13+ m_userAgent = userAgent;
14 }
15
16 void PreviewStack::loadForResult(scopes::Result::SPtr const& result)
17@@ -124,6 +125,9 @@
18 if (!m_session_id.isNull()) {
19 metadata["session-id"] = uuidToString(m_session_id).toStdString();
20 }
21+ if (!m_userAgent.isEmpty()) {
22+ metadata["user-agent"] = m_userAgent.toStdString();
23+ }
24
25 std::shared_ptr<PreviewDataReceiver> listener(new PreviewDataReceiver(m_activePreview));
26 std::weak_ptr<ScopeDataReceiverBase> wl(listener);
27
28=== modified file 'src/Unity/previewstack.h'
29--- src/Unity/previewstack.h 2014-09-03 09:45:15 +0000
30+++ src/Unity/previewstack.h 2014-10-01 12:59:45 +0000
31@@ -60,7 +60,7 @@
32
33 void setWidgetColumnCount(int columnCount) override;
34 int widgetColumnCount() const override;
35- void setAssociatedScope(scopes_ng::Scope*, QUuid const&);
36+ void setAssociatedScope(scopes_ng::Scope*, QUuid const&, QString const&);
37
38 private Q_SLOTS:
39 void widgetTriggered(QString const&, QString const&, QVariantMap const&);
40@@ -81,6 +81,7 @@
41
42 unity::scopes::Result::SPtr m_previewedResult;
43 QUuid m_session_id;
44+ QString m_userAgent;
45 };
46
47 } // namespace scopes_ng
48
49=== modified file 'src/Unity/scope.cpp'
50--- src/Unity/scope.cpp 2014-09-25 05:16:02 +0000
51+++ src/Unity/scope.cpp 2014-10-01 12:59:45 +0000
52@@ -647,6 +647,11 @@
53
54 if (m_proxy) {
55 scopes::SearchMetadata meta(QLocale::system().name().toStdString(), m_formFactor.toStdString());
56+ auto const userAgent = m_scopesInstance->userAgentString();
57+ if (!userAgent.isEmpty()) {
58+ meta["user-agent"] = userAgent.toStdString();
59+ }
60+
61 if (!m_session_id.isNull()) {
62 meta["session-id"] = uuidToString(m_session_id).toStdString();
63 }
64@@ -1155,7 +1160,7 @@
65 }
66
67 PreviewStack* stack = new PreviewStack(nullptr);
68- stack->setAssociatedScope(this, m_session_id);
69+ stack->setAssociatedScope(this, m_session_id, m_scopesInstance->userAgentString());
70 stack->loadForResult(result);
71 return stack;
72 }
73
74=== modified file 'src/Unity/scopes.cpp'
75--- src/Unity/scopes.cpp 2014-09-10 11:47:01 +0000
76+++ src/Unity/scopes.cpp 2014-10-01 12:59:45 +0000
77@@ -29,6 +29,10 @@
78 #include <QDebug>
79 #include <QTimer>
80 #include <QDBusConnection>
81+#include <QProcess>
82+#include <QFile>
83+#include <QUrlQuery>
84+#include <QTextStream>
85
86 #include <unity/scopes/Registry.h>
87 #include <unity/scopes/Scope.h>
88@@ -106,14 +110,6 @@
89 m_noFavorites = true;
90 }
91
92- // delaying spawning the worker thread, causes problems with qmlplugindump
93- // without it
94- if (LIST_DELAY < 0) {
95- QByteArray listDelay = qgetenv("UNITY_SCOPES_LIST_DELAY");
96- LIST_DELAY = listDelay.isNull() ? 100 : listDelay.toInt();
97- }
98- QTimer::singleShot(LIST_DELAY, this, SLOT(populateScopes()));
99-
100 connect(m_priv.get(), SIGNAL(safeInvalidateScopeResults(const QString&)), this,
101 SLOT(invalidateScopeResults(const QString &)), Qt::QueuedConnection);
102
103@@ -127,6 +123,8 @@
104
105 m_overviewScope = new OverviewScope(this);
106 m_locationService.reset(new UbuntuLocationService());
107+
108+ createUserAgentString();
109 }
110
111 Scopes::~Scopes()
112@@ -137,6 +135,11 @@
113 }
114 }
115
116+QString Scopes::userAgentString() const
117+{
118+ return m_userAgent;
119+}
120+
121 int Scopes::rowCount(const QModelIndex& parent) const
122 {
123 Q_UNUSED(parent)
124@@ -149,6 +152,89 @@
125 return m_scopes.count();
126 }
127
128+void Scopes::createUserAgentString()
129+{
130+ QProcess *dpkg = new QProcess(this);
131+ connect(dpkg, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(dpkgFinished()));
132+ connect(dpkg, SIGNAL(error(QProcess::ProcessError)), this, SLOT(initPopulateScopes()));
133+ dpkg->start("dpkg-query -W libunity-scopes3 unity-plugin-scopes unity8", QIODevice::ReadOnly);
134+}
135+
136+void Scopes::dpkgFinished()
137+{
138+ QProcess *dpkg = qobject_cast<QProcess *>(sender());
139+ if (dpkg) {
140+ while (dpkg->canReadLine()) {
141+ const QString line = dpkg->readLine();
142+ const QStringList lineParts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
143+ QString key;
144+ if (lineParts.size() == 2) {
145+ if (lineParts.at(0).startsWith("libunity-scopes")) {
146+ key = "scopes-api";
147+ }
148+ else if (lineParts.at(0).startsWith("unity-plugin-scopes")) {
149+ key = "plugin";
150+ }
151+ else if (lineParts.at(0).startsWith("unity8")) {
152+ key = "unity8";
153+ }
154+ if (!key.isEmpty()) {
155+ m_versions.push_back(qMakePair(key, lineParts.at(1)));
156+ } else {
157+ qWarning() << "Unexpected dpkg-query output:" << line;
158+ }
159+ }
160+ }
161+ dpkg->deleteLater();
162+
163+ QProcess *lsb_release = new QProcess(this);
164+ connect(lsb_release, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(lsbReleaseFinished()));
165+ connect(lsb_release, SIGNAL(error(QProcess::ProcessError)), this, SLOT(initPopulateScopes()));
166+ lsb_release->start("lsb_release -r", QIODevice::ReadOnly);
167+ }
168+}
169+
170+void Scopes::lsbReleaseFinished()
171+{
172+ QProcess *lsb_release = qobject_cast<QProcess *>(sender());
173+ if (lsb_release) {
174+ const QString out = lsb_release->readAllStandardOutput();
175+ const QStringList parts = out.split(QRegExp("\\s+"), QString::SkipEmptyParts);
176+ if (parts.size() == 2) {
177+ m_versions.push_back(qMakePair(QString("release"), parts.at(1)));
178+ }
179+ lsb_release->deleteLater();
180+
181+ QFile buildFile("/etc/ubuntu-build");
182+ if (buildFile.open(QIODevice::ReadOnly)) {
183+ QTextStream str(&buildFile);
184+ QString bld;
185+ str >> bld;
186+ m_versions.push_back(qMakePair(QString("build"), bld));
187+ }
188+
189+ QUrlQuery q;
190+ q.setQueryItems(m_versions);
191+ m_versions.clear();
192+ m_userAgent = q.toString();
193+ }
194+
195+ qDebug() << "User agent string:" << m_userAgent;
196+ initPopulateScopes();
197+}
198+
199+void Scopes::initPopulateScopes()
200+{
201+ // initiate scopes
202+ // delaying spawning the worker thread, causes problems with qmlplugindump
203+ // without it
204+ if (LIST_DELAY < 0) {
205+ QByteArray listDelay = qgetenv("UNITY_SCOPES_LIST_DELAY");
206+ LIST_DELAY = listDelay.isNull() ? 100 : listDelay.toInt();
207+ }
208+ QTimer::singleShot(LIST_DELAY, this, SLOT(populateScopes()));
209+}
210+
211 void Scopes::populateScopes()
212 {
213 auto thread = new ScopeListWorker;
214
215=== modified file 'src/Unity/scopes.h'
216--- src/Unity/scopes.h 2014-09-10 11:47:01 +0000
217+++ src/Unity/scopes.h 2014-10-01 12:59:45 +0000
218@@ -69,6 +69,7 @@
219 unity::shell::scopes::ScopeInterface* overviewScope() const override;
220
221 LocationService::Ptr locationService() const;
222+ QString userAgentString() const;
223
224 Q_SIGNALS:
225 void metadataRefreshed();
226@@ -81,8 +82,13 @@
227 void refreshFinished();
228 void invalidateScopeResults(QString const&);
229
230+ void initPopulateScopes();
231+ void dpkgFinished();
232+ void lsbReleaseFinished();
233+
234 private:
235 void queryScopesOnStartup();
236+ void createUserAgentString();
237
238 static int LIST_DELAY;
239 static const int SCOPE_DELETE_DELAY;
240@@ -95,6 +101,8 @@
241 QMap<QString, unity::scopes::ScopeMetadata::SPtr> m_cachedMetadata;
242 OverviewScope* m_overviewScope;
243 QThread* m_listThread;
244+ QList<QPair<QString, QString>> m_versions;
245+ QString m_userAgent;
246 bool m_loaded;
247 bool m_queryOnStartup;
248

Subscribers

People subscribed via source and target branches

to all changes: