Merge lp:~phablet-team/telephony-service/connect-disconnect-accounts into lp:telephony-service/staging

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 1247
Merged at revision: 1251
Proposed branch: lp:~phablet-team/telephony-service/connect-disconnect-accounts
Merge into: lp:telephony-service/staging
Prerequisite: lp:~phablet-team/telephony-service/online-account-match
Diff against target: 183 lines (+71/-4)
6 files modified
TODO (+3/-0)
accounts/irc/data/telephony-irc-im.service (+2/-2)
handler/texthandler.cpp (+22/-0)
handler/texthandler.h (+4/-0)
libtelephonyservice/accountentry.cpp (+27/-2)
libtelephonyservice/accountentry.h (+13/-0)
To merge this branch: bzr merge lp:~phablet-team/telephony-service/connect-disconnect-accounts
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
Review via email: mp+318944@code.launchpad.net

Commit message

Monitor app and disconnect/connect accounts when appropriate.

Description of the change

Monitor app and disconnect/connect accounts when appropriate.

To post a comment you must log in.
1240. By Tiago Salem Herrmann

merge parent branch

1241. By Tiago Salem Herrmann

merge parent branch

1242. By Tiago Salem Herrmann

temporary fix for online detection

1243. By Tiago Salem Herrmann

Disable auto-connect on irc protocols

1244. By Tiago Salem Herrmann

check if there is a connection before disconnecting

1245. By Tiago Salem Herrmann

add connection status property

1246. By Tiago Salem Herrmann

Use connectionStatus() instead of connection()->status()

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Just one request, looks good otherwise.

review: Needs Fixing
1247. By Tiago Salem Herrmann

add entry to TODO list

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good now,thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'TODO'
2--- TODO 2012-11-27 12:21:47 +0000
3+++ TODO 2017-03-22 16:56:09 +0000
4@@ -16,3 +16,6 @@
5 places
6 - Change the ChannelObserver and the ChannelApprover code to allow using from
7 both places.
8+
9+Handler
10+- Move app monitoring to from TextHandler to ApplicationUtils
11
12=== modified file 'accounts/irc/data/telephony-irc-im.service'
13--- accounts/irc/data/telephony-irc-im.service 2017-03-22 16:56:08 +0000
14+++ accounts/irc/data/telephony-irc-im.service 2017-03-22 16:56:09 +0000
15@@ -10,8 +10,8 @@
16 <group name="telepathy">
17 <setting name="manager">irc</setting>
18 <setting name="protocol">irc</setting>
19- <setting name="ConnectAutomatically">true</setting>
20- <setting type="s" name="AutomaticPresence">2;available;;</setting>
21+ <setting name="ConnectAutomatically">false</setting>
22+ <setting type="s" name="AutomaticPresence">1;offline;;</setting>
23 </group>
24 <group name="auth">
25 <setting name="method">password</setting>
26
27=== modified file 'handler/texthandler.cpp'
28--- handler/texthandler.cpp 2017-03-22 16:56:08 +0000
29+++ handler/texthandler.cpp 2017-03-22 16:56:09 +0000
30@@ -35,10 +35,32 @@
31
32 TextHandler::TextHandler(QObject *parent)
33 : QObject(parent)
34+ , mMessagingAppMonitor("com.canonical.MessagingApp", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration|QDBusServiceWatcher::WatchForUnregistration)
35 {
36 qDBusRegisterMetaType<AttachmentStruct>();
37 qDBusRegisterMetaType<AttachmentList>();
38 qRegisterMetaType<PendingMessage>();
39+ connect(&mMessagingAppMonitor, SIGNAL(serviceRegistered(const QString&)), SLOT(onMessagingAppOpen()));
40+ connect(&mMessagingAppMonitor, SIGNAL(serviceUnregistered(const QString&)), SLOT(onMessagingAppClosed()));
41+}
42+
43+void TextHandler::onMessagingAppOpen()
44+{
45+ Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) {
46+ if (!account->active() && account->protocolInfo()->leaveRoomsOnClose()) {
47+ account->reconnect();
48+ }
49+ }
50+}
51+
52+void TextHandler::onMessagingAppClosed()
53+{
54+ Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) {
55+ if (account->protocolInfo()->leaveRoomsOnClose()) {
56+ account->requestDisconnect();
57+ }
58+ }
59+
60 }
61
62 TextHandler *TextHandler::instance()
63
64=== modified file 'handler/texthandler.h'
65--- handler/texthandler.h 2017-03-22 16:56:08 +0000
66+++ handler/texthandler.h 2017-03-22 16:56:09 +0000
67@@ -54,6 +54,9 @@
68 void onTextChannelAvailable(Tp::TextChannelPtr channel);
69 void onTextChannelInvalidated();
70
71+ void onMessagingAppOpen();
72+ void onMessagingAppClosed();
73+
74 protected:
75 QList<Tp::TextChannelPtr> existingChannels(const QString &accountId, const QVariantMap &properties);
76 Tp::TextChannelPtr existingChannelFromObjectPath(const QString &objectPath);
77@@ -61,6 +64,7 @@
78 private:
79 explicit TextHandler(QObject *parent = 0);
80 QList<Tp::TextChannelPtr> mChannels;
81+ QDBusServiceWatcher mMessagingAppMonitor;
82 };
83
84 #endif // TEXTHANDLER_H
85
86=== modified file 'libtelephonyservice/accountentry.cpp'
87--- libtelephonyservice/accountentry.cpp 2017-03-22 16:56:08 +0000
88+++ libtelephonyservice/accountentry.cpp 2017-03-22 16:56:09 +0000
89@@ -55,7 +55,7 @@
90
91 bool AccountEntry::active() const
92 {
93- if (mAccount.isNull() || mAccount->connection().isNull() || mAccount->connection()->status() != Tp::ConnectionStatusConnected) {
94+ if (mAccount.isNull() || mAccount->connection().isNull() || mAccount->connectionStatus() != Tp::ConnectionStatusConnected) {
95 return false;
96 }
97
98@@ -117,7 +117,7 @@
99 bool AccountEntry::connected() const
100 {
101 return !mAccount.isNull() && !mAccount->connection().isNull() &&
102- mAccount->connection()->status() == Tp::ConnectionStatusConnected;
103+ mAccount->connectionStatus() == Tp::ConnectionStatusConnected;
104 }
105
106 AccountEntry::Capabilities AccountEntry::capabilities() const
107@@ -319,6 +319,14 @@
108 Q_EMIT capabilitiesChanged();
109 }
110
111+AccountEntry::ConnectionStatus AccountEntry::connectionStatus() const
112+{
113+ if (mAccount && mAccount->connection()) {
114+ return (ConnectionStatus)mAccount->connectionStatus();
115+ }
116+ return ConnectionStatusDisconnected;
117+}
118+
119 void AccountEntry::addAccountLabel(const QString &accountId, QString &text)
120 {
121 AccountEntry *account = TelepathyHelper::instance()->accountForId(accountId);
122@@ -327,3 +335,20 @@
123 text += QString(" - [%1]").arg(account->displayName());
124 }
125 }
126+
127+void AccountEntry::reconnect()
128+{
129+ if (mAccount.isNull() || (mAccount->connection() && mAccount->connectionStatus() != Tp::ConnectionStatusDisconnected)) {
130+ return;
131+ }
132+ mAccount->reconnect();
133+ mAccount->setRequestedPresence(Tp::Presence::available());
134+}
135+
136+void AccountEntry::requestDisconnect()
137+{
138+ if (mAccount.isNull() || !mAccount->connection() || mAccount->connectionStatus() == Tp::ConnectionStatusDisconnected) {
139+ return;
140+ }
141+ mAccount->setRequestedPresence(Tp::Presence::offline());
142+}
143
144=== modified file 'libtelephonyservice/accountentry.h'
145--- libtelephonyservice/accountentry.h 2017-03-22 16:56:08 +0000
146+++ libtelephonyservice/accountentry.h 2017-03-22 16:56:09 +0000
147@@ -49,7 +49,9 @@
148 Q_PROPERTY(Capabilities capabilities READ capabilities NOTIFY capabilitiesChanged)
149 Q_PROPERTY(QVariantMap accountProperties READ accountProperties WRITE setAccountProperties NOTIFY accountPropertiesChanged)
150 Q_PROPERTY(QVariantMap parameters READ parameters NOTIFY parametersChanged)
151+ Q_PROPERTY(ConnectionStatus connectionStatus READ connectionStatus NOTIFY connectionStatusChanged)
152 Q_ENUMS(AccountType)
153+ Q_ENUMS(ConnectionStatus)
154 friend class AccountEntryFactory;
155
156 public:
157@@ -69,6 +71,12 @@
158 };
159 Q_DECLARE_FLAGS(Capabilities, Capability);
160
161+ enum ConnectionStatus {
162+ ConnectionStatusConnected = Tp::ConnectionStatusConnected,
163+ ConnectionStatusConnecting = Tp::ConnectionStatusConnecting,
164+ ConnectionStatusDisconnected = Tp::ConnectionStatusDisconnected
165+ };
166+
167 bool ready() const;
168 QString accountId() const;
169 QString displayName() const;
170@@ -92,8 +100,13 @@
171
172 Protocol *protocolInfo() const;
173
174+ ConnectionStatus connectionStatus() const;
175+
176 static void addAccountLabel(const QString &accountId, QString &text);
177
178+ void reconnect();
179+ void requestDisconnect();
180+
181 Q_SIGNALS:
182 void accountReady();
183 void accountIdChanged();

Subscribers

People subscribed via source and target branches

to all changes: