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
=== modified file 'src/Unity/previewstack.cpp'
--- src/Unity/previewstack.cpp 2014-09-11 04:55:52 +0000
+++ src/Unity/previewstack.cpp 2014-10-01 12:59:45 +0000
@@ -77,10 +77,11 @@
77 return false;77 return false;
78}78}
7979
80void PreviewStack::setAssociatedScope(scopes_ng::Scope* scope, QUuid const& session_id)80void PreviewStack::setAssociatedScope(scopes_ng::Scope* scope, QUuid const& session_id, QString const& userAgent)
81{81{
82 m_associatedScope = scope;82 m_associatedScope = scope;
83 m_session_id = session_id;83 m_session_id = session_id;
84 m_userAgent = userAgent;
84}85}
8586
86void PreviewStack::loadForResult(scopes::Result::SPtr const& result)87void PreviewStack::loadForResult(scopes::Result::SPtr const& result)
@@ -124,6 +125,9 @@
124 if (!m_session_id.isNull()) {125 if (!m_session_id.isNull()) {
125 metadata["session-id"] = uuidToString(m_session_id).toStdString();126 metadata["session-id"] = uuidToString(m_session_id).toStdString();
126 }127 }
128 if (!m_userAgent.isEmpty()) {
129 metadata["user-agent"] = m_userAgent.toStdString();
130 }
127131
128 std::shared_ptr<PreviewDataReceiver> listener(new PreviewDataReceiver(m_activePreview));132 std::shared_ptr<PreviewDataReceiver> listener(new PreviewDataReceiver(m_activePreview));
129 std::weak_ptr<ScopeDataReceiverBase> wl(listener);133 std::weak_ptr<ScopeDataReceiverBase> wl(listener);
130134
=== modified file 'src/Unity/previewstack.h'
--- src/Unity/previewstack.h 2014-09-03 09:45:15 +0000
+++ src/Unity/previewstack.h 2014-10-01 12:59:45 +0000
@@ -60,7 +60,7 @@
6060
61 void setWidgetColumnCount(int columnCount) override;61 void setWidgetColumnCount(int columnCount) override;
62 int widgetColumnCount() const override;62 int widgetColumnCount() const override;
63 void setAssociatedScope(scopes_ng::Scope*, QUuid const&);63 void setAssociatedScope(scopes_ng::Scope*, QUuid const&, QString const&);
6464
65private Q_SLOTS:65private Q_SLOTS:
66 void widgetTriggered(QString const&, QString const&, QVariantMap const&);66 void widgetTriggered(QString const&, QString const&, QVariantMap const&);
@@ -81,6 +81,7 @@
8181
82 unity::scopes::Result::SPtr m_previewedResult;82 unity::scopes::Result::SPtr m_previewedResult;
83 QUuid m_session_id;83 QUuid m_session_id;
84 QString m_userAgent;
84};85};
8586
86} // namespace scopes_ng87} // namespace scopes_ng
8788
=== modified file 'src/Unity/scope.cpp'
--- src/Unity/scope.cpp 2014-09-25 05:16:02 +0000
+++ src/Unity/scope.cpp 2014-10-01 12:59:45 +0000
@@ -647,6 +647,11 @@
647647
648 if (m_proxy) {648 if (m_proxy) {
649 scopes::SearchMetadata meta(QLocale::system().name().toStdString(), m_formFactor.toStdString());649 scopes::SearchMetadata meta(QLocale::system().name().toStdString(), m_formFactor.toStdString());
650 auto const userAgent = m_scopesInstance->userAgentString();
651 if (!userAgent.isEmpty()) {
652 meta["user-agent"] = userAgent.toStdString();
653 }
654
650 if (!m_session_id.isNull()) {655 if (!m_session_id.isNull()) {
651 meta["session-id"] = uuidToString(m_session_id).toStdString();656 meta["session-id"] = uuidToString(m_session_id).toStdString();
652 }657 }
@@ -1155,7 +1160,7 @@
1155 }1160 }
11561161
1157 PreviewStack* stack = new PreviewStack(nullptr);1162 PreviewStack* stack = new PreviewStack(nullptr);
1158 stack->setAssociatedScope(this, m_session_id);1163 stack->setAssociatedScope(this, m_session_id, m_scopesInstance->userAgentString());
1159 stack->loadForResult(result);1164 stack->loadForResult(result);
1160 return stack;1165 return stack;
1161}1166}
11621167
=== modified file 'src/Unity/scopes.cpp'
--- src/Unity/scopes.cpp 2014-09-10 11:47:01 +0000
+++ src/Unity/scopes.cpp 2014-10-01 12:59:45 +0000
@@ -29,6 +29,10 @@
29#include <QDebug>29#include <QDebug>
30#include <QTimer>30#include <QTimer>
31#include <QDBusConnection>31#include <QDBusConnection>
32#include <QProcess>
33#include <QFile>
34#include <QUrlQuery>
35#include <QTextStream>
3236
33#include <unity/scopes/Registry.h>37#include <unity/scopes/Registry.h>
34#include <unity/scopes/Scope.h>38#include <unity/scopes/Scope.h>
@@ -106,14 +110,6 @@
106 m_noFavorites = true;110 m_noFavorites = true;
107 }111 }
108112
109 // delaying spawning the worker thread, causes problems with qmlplugindump
110 // without it
111 if (LIST_DELAY < 0) {
112 QByteArray listDelay = qgetenv("UNITY_SCOPES_LIST_DELAY");
113 LIST_DELAY = listDelay.isNull() ? 100 : listDelay.toInt();
114 }
115 QTimer::singleShot(LIST_DELAY, this, SLOT(populateScopes()));
116
117 connect(m_priv.get(), SIGNAL(safeInvalidateScopeResults(const QString&)), this,113 connect(m_priv.get(), SIGNAL(safeInvalidateScopeResults(const QString&)), this,
118 SLOT(invalidateScopeResults(const QString &)), Qt::QueuedConnection);114 SLOT(invalidateScopeResults(const QString &)), Qt::QueuedConnection);
119115
@@ -127,6 +123,8 @@
127123
128 m_overviewScope = new OverviewScope(this);124 m_overviewScope = new OverviewScope(this);
129 m_locationService.reset(new UbuntuLocationService());125 m_locationService.reset(new UbuntuLocationService());
126
127 createUserAgentString();
130}128}
131129
132Scopes::~Scopes()130Scopes::~Scopes()
@@ -137,6 +135,11 @@
137 }135 }
138}136}
139137
138QString Scopes::userAgentString() const
139{
140 return m_userAgent;
141}
142
140int Scopes::rowCount(const QModelIndex& parent) const143int Scopes::rowCount(const QModelIndex& parent) const
141{144{
142 Q_UNUSED(parent)145 Q_UNUSED(parent)
@@ -149,6 +152,89 @@
149 return m_scopes.count();152 return m_scopes.count();
150}153}
151154
155void Scopes::createUserAgentString()
156{
157 QProcess *dpkg = new QProcess(this);
158 connect(dpkg, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(dpkgFinished()));
159 connect(dpkg, SIGNAL(error(QProcess::ProcessError)), this, SLOT(initPopulateScopes()));
160 dpkg->start("dpkg-query -W libunity-scopes3 unity-plugin-scopes unity8", QIODevice::ReadOnly);
161}
162
163void Scopes::dpkgFinished()
164{
165 QProcess *dpkg = qobject_cast<QProcess *>(sender());
166 if (dpkg) {
167 while (dpkg->canReadLine()) {
168 const QString line = dpkg->readLine();
169 const QStringList lineParts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
170 QString key;
171 if (lineParts.size() == 2) {
172 if (lineParts.at(0).startsWith("libunity-scopes")) {
173 key = "scopes-api";
174 }
175 else if (lineParts.at(0).startsWith("unity-plugin-scopes")) {
176 key = "plugin";
177 }
178 else if (lineParts.at(0).startsWith("unity8")) {
179 key = "unity8";
180 }
181 if (!key.isEmpty()) {
182 m_versions.push_back(qMakePair(key, lineParts.at(1)));
183 } else {
184 qWarning() << "Unexpected dpkg-query output:" << line;
185 }
186 }
187 }
188 dpkg->deleteLater();
189
190 QProcess *lsb_release = new QProcess(this);
191 connect(lsb_release, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(lsbReleaseFinished()));
192 connect(lsb_release, SIGNAL(error(QProcess::ProcessError)), this, SLOT(initPopulateScopes()));
193 lsb_release->start("lsb_release -r", QIODevice::ReadOnly);
194 }
195}
196
197void Scopes::lsbReleaseFinished()
198{
199 QProcess *lsb_release = qobject_cast<QProcess *>(sender());
200 if (lsb_release) {
201 const QString out = lsb_release->readAllStandardOutput();
202 const QStringList parts = out.split(QRegExp("\\s+"), QString::SkipEmptyParts);
203 if (parts.size() == 2) {
204 m_versions.push_back(qMakePair(QString("release"), parts.at(1)));
205 }
206 lsb_release->deleteLater();
207
208 QFile buildFile("/etc/ubuntu-build");
209 if (buildFile.open(QIODevice::ReadOnly)) {
210 QTextStream str(&buildFile);
211 QString bld;
212 str >> bld;
213 m_versions.push_back(qMakePair(QString("build"), bld));
214 }
215
216 QUrlQuery q;
217 q.setQueryItems(m_versions);
218 m_versions.clear();
219 m_userAgent = q.toString();
220 }
221
222 qDebug() << "User agent string:" << m_userAgent;
223 initPopulateScopes();
224}
225
226void Scopes::initPopulateScopes()
227{
228 // initiate scopes
229 // delaying spawning the worker thread, causes problems with qmlplugindump
230 // without it
231 if (LIST_DELAY < 0) {
232 QByteArray listDelay = qgetenv("UNITY_SCOPES_LIST_DELAY");
233 LIST_DELAY = listDelay.isNull() ? 100 : listDelay.toInt();
234 }
235 QTimer::singleShot(LIST_DELAY, this, SLOT(populateScopes()));
236}
237
152void Scopes::populateScopes()238void Scopes::populateScopes()
153{239{
154 auto thread = new ScopeListWorker;240 auto thread = new ScopeListWorker;
155241
=== modified file 'src/Unity/scopes.h'
--- src/Unity/scopes.h 2014-09-10 11:47:01 +0000
+++ src/Unity/scopes.h 2014-10-01 12:59:45 +0000
@@ -69,6 +69,7 @@
69 unity::shell::scopes::ScopeInterface* overviewScope() const override;69 unity::shell::scopes::ScopeInterface* overviewScope() const override;
7070
71 LocationService::Ptr locationService() const;71 LocationService::Ptr locationService() const;
72 QString userAgentString() const;
7273
73Q_SIGNALS:74Q_SIGNALS:
74 void metadataRefreshed();75 void metadataRefreshed();
@@ -81,8 +82,13 @@
81 void refreshFinished();82 void refreshFinished();
82 void invalidateScopeResults(QString const&);83 void invalidateScopeResults(QString const&);
8384
85 void initPopulateScopes();
86 void dpkgFinished();
87 void lsbReleaseFinished();
88
84private:89private:
85 void queryScopesOnStartup();90 void queryScopesOnStartup();
91 void createUserAgentString();
8692
87 static int LIST_DELAY;93 static int LIST_DELAY;
88 static const int SCOPE_DELETE_DELAY;94 static const int SCOPE_DELETE_DELAY;
@@ -95,6 +101,8 @@
95 QMap<QString, unity::scopes::ScopeMetadata::SPtr> m_cachedMetadata;101 QMap<QString, unity::scopes::ScopeMetadata::SPtr> m_cachedMetadata;
96 OverviewScope* m_overviewScope;102 OverviewScope* m_overviewScope;
97 QThread* m_listThread;103 QThread* m_listThread;
104 QList<QPair<QString, QString>> m_versions;
105 QString m_userAgent;
98 bool m_loaded;106 bool m_loaded;
99 bool m_queryOnStartup;107 bool m_queryOnStartup;
100108

Subscribers

People subscribed via source and target branches

to all changes: