Merge lp:~rmescandon/telegram-app/reconnect-on-demand into lp:~libqtelegram-team/telegram-app/qml-plugin

Proposed by Roberto Mier Escandon
Status: Merged
Merged at revision: 194
Proposed branch: lp:~rmescandon/telegram-app/reconnect-on-demand
Merge into: lp:~libqtelegram-team/telegram-app/qml-plugin
Diff against target: 148 lines (+49/-10)
6 files modified
qmlplugin/dbmanager.cpp (+14/-4)
qmlplugin/dbmanager.h (+1/-0)
qmlplugin/telegramclient.cpp (+10/-1)
qmlplugin/telegramclient.h (+2/-3)
uitest/ui/DialogsPage.qml (+21/-1)
uitest/ui/SignInPage.qml (+1/-1)
To merge this branch: bzr merge lp:~rmescandon/telegram-app/reconnect-on-demand
Reviewer Review Type Date Requested Status
Michał Karnicki (community) Approve
Review via email: mp+231414@code.launchpad.net

Description of the change

Created two new methods for telegramClient object, to be used from qml:

telegramClient.sleep()
telegramClient.wake()

that can be used when application goes to background and comes back to foreground. Sleep invalidates library (closing network connections) instance and closes database connection. Wake method restarts library.

To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) wrote :

in-line comments. +1, but feel free to grab me for comments after fix.

review: Approve
195. By Roberto Mier Escandon

CHANGED wake and sleep method names by init and shutdown

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qmlplugin/dbmanager.cpp'
2--- qmlplugin/dbmanager.cpp 2014-08-18 18:49:11 +0000
3+++ qmlplugin/dbmanager.cpp 2014-08-20 08:22:47 +0000
4@@ -28,9 +28,7 @@
5 }
6
7 DbManager::~DbManager() {
8- if (m_database.isOpen()) {
9- m_database.close();
10- }
11+ closeDatabase();
12 }
13
14 DbManager *DbManager::instance() {
15@@ -38,6 +36,12 @@
16 return self;
17 }
18
19+void DbManager::closeDatabase() {
20+ if (m_database.isOpen()) {
21+ m_database.close();
22+ }
23+}
24+
25 bool DbManager::initializeDatabase() {
26
27 QDir dir(Config::instance()->databasePath());
28@@ -47,7 +51,13 @@
29 }
30
31 m_databasePath = dir.absoluteFilePath(DATABASE_NAME);
32- m_database = QSqlDatabase::addDatabase("QSQLITE");
33+
34+ // if database doesn't contain a default connection, add it.
35+ // This should avoid destroying and creating again the default connection
36+ // if existing yet.
37+ if (!m_database.contains()) {
38+ m_database = QSqlDatabase::addDatabase("QSQLITE");
39+ }
40 m_database.setDatabaseName(m_databasePath);
41
42 if (!createOrUpdateDatabase()) {
43
44=== modified file 'qmlplugin/dbmanager.h'
45--- qmlplugin/dbmanager.h 2014-08-18 18:49:11 +0000
46+++ qmlplugin/dbmanager.h 2014-08-20 08:22:47 +0000
47@@ -30,6 +30,7 @@
48 static DbManager *instance();
49
50 bool initializeDatabase();
51+ void closeDatabase();
52 QSqlDatabase database() const;
53
54 bool beginTransaction();
55
56=== modified file 'qmlplugin/telegramclient.cpp'
57--- qmlplugin/telegramclient.cpp 2014-08-19 10:07:39 +0000
58+++ qmlplugin/telegramclient.cpp 2014-08-20 08:22:47 +0000
59@@ -32,7 +32,7 @@
60 TelegramClient::~TelegramClient() {
61 }
62
63-void TelegramClient::initTelegramLibrary() {
64+void TelegramClient::init() {
65
66 bool createLib = !m_telegram;
67
68@@ -49,6 +49,15 @@
69 }
70 }
71
72+void TelegramClient::shutdown() {
73+
74+ m_telegram->deleteLater();
75+ m_telegram = 0;
76+
77+ DbManager::instance()->closeDatabase();
78+}
79+
80+
81 void TelegramClient::onAuthLoggedIn() {
82
83 DbManager::instance()->initializeDatabase();
84
85=== modified file 'qmlplugin/telegramclient.h'
86--- qmlplugin/telegramclient.h 2014-08-19 10:07:39 +0000
87+++ qmlplugin/telegramclient.h 2014-08-20 08:22:47 +0000
88@@ -42,11 +42,10 @@
89 void setDatabasePath(const QString &path) { Config::instance()->setDatabasePath(path); }
90
91
92- Q_INVOKABLE void initTelegramLibrary();
93+ Q_INVOKABLE void init();
94+ Q_INVOKABLE void shutdown();
95
96 Q_INVOKABLE qint64 messagesSendMessage(TLInputPeer *peer, const QString &message);
97- Q_INVOKABLE void setContactsFilterTerm(QString term);
98- Q_INVOKABLE void setDialogsFilterTerm(QString term);
99
100 Q_SIGNALS:
101 void databasePathChanged(QString);
102
103=== modified file 'uitest/ui/DialogsPage.qml'
104--- uitest/ui/DialogsPage.qml 2014-08-18 21:18:34 +0000
105+++ uitest/ui/DialogsPage.qml 2014-08-20 08:22:47 +0000
106@@ -38,9 +38,29 @@
107 }
108
109
110+ Button {
111+ id: sleepButton
112+ text: "Sleep"
113+
114+ onClicked: {
115+ if (text === "Sleep") {
116+ text = "Wake";
117+ telegramClient.shutdown();
118+ } else {
119+ text = "Sleep";
120+ telegramClient.init();
121+ }
122+ }
123+ }
124+
125 ListView {
126 id: dialogsListView
127- anchors.fill: parent
128+ anchors {
129+ left: parent.left
130+ right: parent.right
131+ bottom: parent.bottom
132+ top: sleepButton.bottom
133+ }
134
135 model: dialogsProxy
136
137
138=== modified file 'uitest/ui/SignInPage.qml'
139--- uitest/ui/SignInPage.qml 2014-08-18 21:18:34 +0000
140+++ uitest/ui/SignInPage.qml 2014-08-20 08:22:47 +0000
141@@ -23,7 +23,7 @@
142 userTextField.enabled = false;
143 signInButton.enabled = false;
144 telegramClient.phoneNumber = userTextField.text;
145- telegramClient.initTelegramLibrary();
146+ telegramClient.init();
147 }
148 }
149

Subscribers

People subscribed via source and target branches