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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-08-07 11:50:58 +0000
+++ CMakeLists.txt 2015-03-11 16:52:16 +0000
@@ -34,6 +34,9 @@
34find_package(Qt5Widgets REQUIRED)34find_package(Qt5Widgets REQUIRED)
35find_package(Qt5Quick REQUIRED)35find_package(Qt5Quick REQUIRED)
3636
37find_package (PkgConfig)
38pkg_check_modules (CONNECTIVITY REQUIRED connectivity-qt1)
39
37set(CMAKE_INCLUDE_CURRENT_DIR ON)40set(CMAKE_INCLUDE_CURRENT_DIR ON)
38set(CMAKE_AUTOMOC ON)41set(CMAKE_AUTOMOC ON)
3942
4043
=== modified file 'debian/control'
--- debian/control 2014-08-14 09:59:55 +0000
+++ debian/control 2015-03-11 16:52:16 +0000
@@ -6,6 +6,8 @@
6 dbus-test-runner,6 dbus-test-runner,
7 debhelper (>= 9),7 debhelper (>= 9),
8 hardening-wrapper,8 hardening-wrapper,
9 libconnectivity-qt1-dev,
10 pkg-config,
9 python,11 python,
10 qt5-default,12 qt5-default,
11 qt5-qmake,13 qt5-qmake,
1214
=== modified file 'src/Ubuntu/PushNotifications/CMakeLists.txt'
--- src/Ubuntu/PushNotifications/CMakeLists.txt 2014-10-23 19:15:41 +0000
+++ src/Ubuntu/PushNotifications/CMakeLists.txt 2015-03-11 16:52:16 +0000
@@ -15,6 +15,9 @@
1515
16qt5_use_modules(${PLUGIN} Core Gui Qml DBus)16qt5_use_modules(${PLUGIN} Core Gui Qml DBus)
1717
18include_directories(${CONNECTIVITY_INCLUDE_DIRS})
19target_link_libraries(${PLUGIN} ${CONNECTIVITY_LDFLAGS})
20
18file(GLOB QML_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.qml qmldir *.js)21file(GLOB QML_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.qml qmldir *.js)
19install(TARGETS ${PLUGIN} DESTINATION ${IMPORTS_DIR})22install(TARGETS ${PLUGIN} DESTINATION ${IMPORTS_DIR})
20install(FILES ${QML_FILES} DESTINATION ${IMPORTS_DIR})23install(FILES ${QML_FILES} DESTINATION ${IMPORTS_DIR})
2124
=== modified file 'src/Ubuntu/PushNotifications/pushclient.cpp'
--- src/Ubuntu/PushNotifications/pushclient.cpp 2015-01-19 18:42:19 +0000
+++ src/Ubuntu/PushNotifications/pushclient.cpp 2015-03-11 16:52:16 +0000
@@ -29,20 +29,46 @@
29#define PUSH_IFACE "com.ubuntu.PushNotifications"29#define PUSH_IFACE "com.ubuntu.PushNotifications"
30#define POSTAL_IFACE "com.ubuntu.Postal"30#define POSTAL_IFACE "com.ubuntu.Postal"
3131
32using ubuntu::connectivity::NetworkingStatus;
33
32PushClient::PushClient(QObject *parent) :34PushClient::PushClient(QObject *parent) :
33 QObject(parent)35 QObject(parent),
36 ns(new NetworkingStatus())
34{37{
35}38}
3639
37void PushClient::registerApp(const QString &appId) {40void PushClient::setAppId(const QString &appId) {
38 if (appId == this->appId || appId == "")41 if (appId == this->appId || appId.isEmpty())
39 return;42 return;
4043
41 this->appId = appId;44 this->appId = appId;
45 emit appIdChanged(appId);
46
47 if (ns->status() == NetworkingStatus::Online) {
48 registerApp();
49 }
50 else {
51 QObject::disconnect(ns.data());
52 QObject::connect(ns.data(), SIGNAL(statusChanged(NetworkingStatus::Status)),
53 this, SLOT(connectionStatusChanged(NetworkingStatus::Status)));
54 }
55}
56
57void PushClient::connectionStatusChanged(NetworkingStatus::Status status)
58{
59 if (status == NetworkingStatus::Online) {
60 QObject::disconnect(ns.data());
61 registerApp();
62 }
63}
64
65void PushClient::registerApp()
66{
67 if (appId.isEmpty())
68 return;
4269
43 pkgname = appId.split("_").at(0);70 pkgname = appId.split("_").at(0);
44 pkgname = pkgname.replace(".","_2e").replace("-","_2d");71 pkgname = pkgname.replace(".","_2e").replace("-","_2d");
45 emit appIdChanged(appId);
4672
47 QString register_path(PUSH_PATH);73 QString register_path(PUSH_PATH);
48 register_path += "/" + pkgname;74 register_path += "/" + pkgname;
4975
=== modified file 'src/Ubuntu/PushNotifications/pushclient.h'
--- src/Ubuntu/PushNotifications/pushclient.h 2014-11-21 16:34:36 +0000
+++ src/Ubuntu/PushNotifications/pushclient.h 2015-03-11 16:52:16 +0000
@@ -21,6 +21,7 @@
21#include <QObject>21#include <QObject>
22#include <QString>22#include <QString>
23#include <QStringList>23#include <QStringList>
24#include <ubuntu/connectivity/networking-status.h>
2425
25class QDBusPendingCallWatcher;26class QDBusPendingCallWatcher;
2627
@@ -29,7 +30,7 @@
29 Q_OBJECT30 Q_OBJECT
30public:31public:
31 explicit PushClient(QObject *parent = 0);32 explicit PushClient(QObject *parent = 0);
32 void registerApp(const QString &appid);33 void setAppId(const QString &appid);
33 QString getStatus() {return this->status;};34 QString getStatus() {return this->status;};
34 QString getAppId();35 QString getAppId();
35 QString getToken();36 QString getToken();
@@ -37,7 +38,7 @@
37 void setCount(int count);38 void setCount(int count);
38 int getCount();39 int getCount();
3940
40 Q_PROPERTY(QString appId WRITE registerApp READ getAppId NOTIFY appIdChanged);41 Q_PROPERTY(QString appId WRITE setAppId READ getAppId NOTIFY appIdChanged);
41 Q_PROPERTY(QString token READ getToken NOTIFY tokenChanged);42 Q_PROPERTY(QString token READ getToken NOTIFY tokenChanged);
42 Q_PROPERTY(QStringList notifications NOTIFY notificationsChanged);43 Q_PROPERTY(QStringList notifications NOTIFY notificationsChanged);
43 Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged);44 Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged);
@@ -64,8 +65,12 @@
64 void popAllFinished(QDBusPendingCallWatcher *watcher);65 void popAllFinished(QDBusPendingCallWatcher *watcher);
65 void setCounterFinished(QDBusPendingCallWatcher *watcher);66 void setCounterFinished(QDBusPendingCallWatcher *watcher);
66 void clearPersistentFinished(QDBusPendingCallWatcher *watcher);67 void clearPersistentFinished(QDBusPendingCallWatcher *watcher);
68 void connectionStatusChanged(ubuntu::connectivity::NetworkingStatus::Status);
6769
68private:70private:
71 void registerApp();
72
73 QScopedPointer<ubuntu::connectivity::NetworkingStatus> ns;
69 QString appId;74 QString appId;
70 QString pkgname;75 QString pkgname;
71 QString token;76 QString token;

Subscribers

People subscribed via source and target branches