Merge lp:~3v1n0/ubuntu-push-qml/register-wait-for-network into lp:ubuntu-push-qml

Proposed by Marco Trevisan (Treviño) on 2015-03-11
Status: Merged
Approved by: Roberto Alsina on 2015-06-17
Approved revision: 19
Merged at revision: 21
Proposed branch: lp:~3v1n0/ubuntu-push-qml/register-wait-for-network
Merge into: lp:ubuntu-push-qml
Diff against target: 138 lines (+45/-6)
5 files modified
CMakeLists.txt (+3/-0)
debian/control (+2/-0)
src/Ubuntu/PushNotifications/CMakeLists.txt (+3/-0)
src/Ubuntu/PushNotifications/pushclient.cpp (+30/-4)
src/Ubuntu/PushNotifications/pushclient.h (+7/-2)
To merge this branch: bzr merge lp:~3v1n0/ubuntu-push-qml/register-wait-for-network
Reviewer Review Type Date Requested Status
Roberto Alsina (community) 2015-03-11 Approve on 2015-06-17
PS Jenkins bot continuous-integration Approve on 2015-03-11
Review via email: mp+252603@code.launchpad.net

Commit message

PushClient: only try to register if we're currently connected, or wait for connection

Description of the change

Without this, just including a push client inside an app fails all the times, and it's not easily possible to get a token as soon as we get online. See attached bug for more info and qml possible solutions.

To post a comment you must log in.
18. By Marco Trevisan (Treviño) on 2015-03-11

PushClient: only try to register if we're currently connected, or wait for connection

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
19. By Marco Trevisan (Treviño) on 2015-03-11

debian/control: add pkg-config as build-debpend

PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-08-07 11:50:58 +0000
3+++ CMakeLists.txt 2015-03-11 16:52:16 +0000
4@@ -34,6 +34,9 @@
5 find_package(Qt5Widgets REQUIRED)
6 find_package(Qt5Quick REQUIRED)
7
8+find_package (PkgConfig)
9+pkg_check_modules (CONNECTIVITY REQUIRED connectivity-qt1)
10+
11 set(CMAKE_INCLUDE_CURRENT_DIR ON)
12 set(CMAKE_AUTOMOC ON)
13
14
15=== modified file 'debian/control'
16--- debian/control 2014-08-14 09:59:55 +0000
17+++ debian/control 2015-03-11 16:52:16 +0000
18@@ -6,6 +6,8 @@
19 dbus-test-runner,
20 debhelper (>= 9),
21 hardening-wrapper,
22+ libconnectivity-qt1-dev,
23+ pkg-config,
24 python,
25 qt5-default,
26 qt5-qmake,
27
28=== modified file 'src/Ubuntu/PushNotifications/CMakeLists.txt'
29--- src/Ubuntu/PushNotifications/CMakeLists.txt 2014-10-23 19:15:41 +0000
30+++ src/Ubuntu/PushNotifications/CMakeLists.txt 2015-03-11 16:52:16 +0000
31@@ -15,6 +15,9 @@
32
33 qt5_use_modules(${PLUGIN} Core Gui Qml DBus)
34
35+include_directories(${CONNECTIVITY_INCLUDE_DIRS})
36+target_link_libraries(${PLUGIN} ${CONNECTIVITY_LDFLAGS})
37+
38 file(GLOB QML_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.qml qmldir *.js)
39 install(TARGETS ${PLUGIN} DESTINATION ${IMPORTS_DIR})
40 install(FILES ${QML_FILES} DESTINATION ${IMPORTS_DIR})
41
42=== modified file 'src/Ubuntu/PushNotifications/pushclient.cpp'
43--- src/Ubuntu/PushNotifications/pushclient.cpp 2015-01-19 18:42:19 +0000
44+++ src/Ubuntu/PushNotifications/pushclient.cpp 2015-03-11 16:52:16 +0000
45@@ -29,20 +29,46 @@
46 #define PUSH_IFACE "com.ubuntu.PushNotifications"
47 #define POSTAL_IFACE "com.ubuntu.Postal"
48
49+using ubuntu::connectivity::NetworkingStatus;
50+
51 PushClient::PushClient(QObject *parent) :
52- QObject(parent)
53+ QObject(parent),
54+ ns(new NetworkingStatus())
55 {
56 }
57
58-void PushClient::registerApp(const QString &appId) {
59- if (appId == this->appId || appId == "")
60+void PushClient::setAppId(const QString &appId) {
61+ if (appId == this->appId || appId.isEmpty())
62 return;
63
64 this->appId = appId;
65+ emit appIdChanged(appId);
66+
67+ if (ns->status() == NetworkingStatus::Online) {
68+ registerApp();
69+ }
70+ else {
71+ QObject::disconnect(ns.data());
72+ QObject::connect(ns.data(), SIGNAL(statusChanged(NetworkingStatus::Status)),
73+ this, SLOT(connectionStatusChanged(NetworkingStatus::Status)));
74+ }
75+}
76+
77+void PushClient::connectionStatusChanged(NetworkingStatus::Status status)
78+{
79+ if (status == NetworkingStatus::Online) {
80+ QObject::disconnect(ns.data());
81+ registerApp();
82+ }
83+}
84+
85+void PushClient::registerApp()
86+{
87+ if (appId.isEmpty())
88+ return;
89
90 pkgname = appId.split("_").at(0);
91 pkgname = pkgname.replace(".","_2e").replace("-","_2d");
92- emit appIdChanged(appId);
93
94 QString register_path(PUSH_PATH);
95 register_path += "/" + pkgname;
96
97=== modified file 'src/Ubuntu/PushNotifications/pushclient.h'
98--- src/Ubuntu/PushNotifications/pushclient.h 2014-11-21 16:34:36 +0000
99+++ src/Ubuntu/PushNotifications/pushclient.h 2015-03-11 16:52:16 +0000
100@@ -21,6 +21,7 @@
101 #include <QObject>
102 #include <QString>
103 #include <QStringList>
104+#include <ubuntu/connectivity/networking-status.h>
105
106 class QDBusPendingCallWatcher;
107
108@@ -29,7 +30,7 @@
109 Q_OBJECT
110 public:
111 explicit PushClient(QObject *parent = 0);
112- void registerApp(const QString &appid);
113+ void setAppId(const QString &appid);
114 QString getStatus() {return this->status;};
115 QString getAppId();
116 QString getToken();
117@@ -37,7 +38,7 @@
118 void setCount(int count);
119 int getCount();
120
121- Q_PROPERTY(QString appId WRITE registerApp READ getAppId NOTIFY appIdChanged);
122+ Q_PROPERTY(QString appId WRITE setAppId READ getAppId NOTIFY appIdChanged);
123 Q_PROPERTY(QString token READ getToken NOTIFY tokenChanged);
124 Q_PROPERTY(QStringList notifications NOTIFY notificationsChanged);
125 Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged);
126@@ -64,8 +65,12 @@
127 void popAllFinished(QDBusPendingCallWatcher *watcher);
128 void setCounterFinished(QDBusPendingCallWatcher *watcher);
129 void clearPersistentFinished(QDBusPendingCallWatcher *watcher);
130+ void connectionStatusChanged(ubuntu::connectivity::NetworkingStatus::Status);
131
132 private:
133+ void registerApp();
134+
135+ QScopedPointer<ubuntu::connectivity::NetworkingStatus> ns;
136 QString appId;
137 QString pkgname;
138 QString token;

Subscribers

People subscribed via source and target branches