3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
7 #include "telepathyutility.h"
8 #include "accountmanagerproxy.h"
9 #include "accountproxy.h"
10 #include "accountcompatproxy.h"
11 #include "connifacereqproxy.h"
12 #include <QDBusInterface>
13 #include <QDBusConnection>
14 #include <QStringList>
15 #include <QDBusPendingReply>
16 #include <QDBusObjectPath>
19 using namespace org::freedesktop::Telepathy;
21 TelepathyUtility::TelepathyUtility(QObject *parent) :
26 TelepathyUtility::~TelepathyUtility(){
30 //Get a list of all Telepathy accounts
31 QList<QDBusObjectPath> TelepathyUtility::getAllAccounts(){
33 QList<QDBusObjectPath> objPathList;
35 QDBusInterface *iface = new QDBusInterface(AM_SERVICE,AM_OBJ_PATH,DBUS_PROPS_IFACE,QDBusConnection::sessionBus(),this);
36 if (iface->isValid()){
37 QDBusReply<QDBusVariant> reply = iface->call(QDBus::AutoDetect,"Get",AM_INTERFACE,"ValidAccounts");
39 if (reply.isValid()){;
40 QDBusVariant validAccounts = reply.value();
41 const QVariant var = validAccounts.variant();
42 const QDBusArgument arg = var.value<QDBusArgument>();
46 QDBusObjectPath opath;
48 if (opath.path().contains("tel")){
49 qDebug() << opath.path();
51 objPathList.append(opath);
56 qDebug() << "Error occurred while fetching accounts list "<<reply.error();
60 qDebug() << "Error occurred while connecting to DBus interface";
67 //Check if Vicar telepathy account exists
68 bool TelepathyUtility::accountExists(){
69 bool vicarAccountExists = false;
70 QList<QDBusObjectPath> accountsList = this->getAllAccounts();
71 QDBusObjectPath account;
72 foreach (account,accountsList){
73 if (account.path().contains("vicar/tel/vicar")){
74 vicarAccountExists = true;
79 return vicarAccountExists;
82 //Get telepathy account status
83 QString TelepathyUtility::getAccountStatus(){
85 QString status = "Not Available";
87 QList<QDBusObjectPath> accountsList = this->getAllAccounts();
88 QDBusObjectPath account;
89 foreach (account,accountsList){
90 if (account.path().contains("vicar/tel/vicar")){
91 AccountProxy *accountProxy = new AccountProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this);
92 if (accountProxy->isValid()){
93 uint intStatus = accountProxy->property("ConnectionStatus").toUInt();
94 //Based on http://telepathy.freedesktop.org/spec/Connection.html#Connection_Status
100 status = "Connecting";
103 status = "Disconnected";
113 //Create Vicar telepathy account (used during installation)
114 bool TelepathyUtility::createAccount(){
116 AccountManagerProxy *amProxy = new AccountManagerProxy(AM_SERVICE,AM_OBJ_PATH,QDBusConnection::sessionBus(),this);
118 QMap<QString,QVariant> connectionParametersMap;
119 connectionParametersMap.insert("account","vicar");
121 QList<QVariant> presenceDetails;
122 uint presenceType(2); //Available = 2
123 presenceDetails << presenceType;
124 presenceDetails << "online";
125 presenceDetails << "Available";
127 SimplePresence presence;
128 presence.type = presenceType;
129 presence.status = "online";
130 presence.statusMessage = "Available";
132 QMap<QString,QVariant> accountPropertiesMap;
133 accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.AutomaticPresence",QVariant::fromValue(presence));
134 accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.Enabled",true);
135 accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.ConnectAutomatically",true);
136 accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.RequestedPresence",QVariant::fromValue(presence));
137 accountPropertiesMap.insert("com.nokia.Account.Interface.Compat.Profile","vicar");
139 QStringList valuesList;
140 valuesList.append("TEL");
141 accountPropertiesMap.insert("com.nokia.Account.Interface.Compat.SecondaryVCardFields",valuesList);
143 QDBusPendingReply<QDBusObjectPath> reply = amProxy->CreateAccount("vicar","tel","Vicar",connectionParametersMap,accountPropertiesMap);
144 reply.waitForFinished();
146 if (reply.isValid()){
147 QDBusObjectPath account = reply.value();
148 qDebug() << account.path() <<" created successfully.";
150 AccountCompatProxy *accountCompatProxy = new AccountCompatProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this);
151 if (accountCompatProxy->isValid()){
152 QDBusPendingReply<> dbusReply = accountCompatProxy->SetHasBeenOnline();
153 dbusReply.waitForFinished();
154 if (dbusReply.isError()){
155 qDebug() << "Error occurred while setting HasBeenOnline property "<<dbusReply.error();
161 qDebug() << "Error creating VICaR telepathy account "<<reply.error();
168 //Delete Vicar telepathy account (used during uninstallation)
169 bool TelepathyUtility::deleteAccount(){
171 QList<QDBusObjectPath> accountsList = this->getAllAccounts();
172 QDBusObjectPath account;
173 foreach (account,accountsList){
174 if (account.path().contains("vicar/tel/vicar")){
175 AccountProxy *accountProxy = new AccountProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this);
176 if (accountProxy->isValid()){
177 QDBusPendingReply<> dbusReply = accountProxy->Remove();
178 dbusReply.waitForFinished();
179 if (dbusReply.isError()){
180 qDebug() << "Error occurred while removing VICaR account "<<dbusReply.error();
184 qDebug() <<"VICaR account deleted";
193 bool TelepathyUtility::callNumberWithRing(QString number){
197 ConnectionInterfaceRequestsProxy *requestsProxy = new ConnectionInterfaceRequestsProxy(RING_CONN_SERVICE,RING_CONN_PATH,QDBusConnection::sessionBus(),this);
198 if (requestsProxy->isValid()){
199 QVariantMap channelRequestDetails;
200 uint targetHandleType(1);
201 channelRequestDetails.insert("org.freedesktop.Telepathy.Channel.TargetHandleType",targetHandleType);
202 channelRequestDetails.insert("org.freedesktop.Telepathy.Channel.TargetID",number);
203 channelRequestDetails.insert("org.freedesktop.Telepathy.Channel.ChannelType","org.freedesktop.Telepathy.Channel.Type.StreamedMedia");
204 QDBusPendingReply<QDBusObjectPath,QVariantMap> dbusReply = requestsProxy->CreateChannel(channelRequestDetails);
205 dbusReply.waitForFinished();
206 if (!dbusReply.isError()){
207 QDBusObjectPath objPath = dbusReply.argumentAt<0>();
208 QVariantMap channelProperties = dbusReply.argumentAt<1>();
212 qDebug() << "Error occurred calling "<<number<< ". Error is "<< dbusReply.error();
220 bool TelepathyUtility::sendDTMFTone(QString tone){
226 // Marshall the Presence data into a D-Bus argument
227 QDBusArgument &operator<<(QDBusArgument &argument, const SimplePresence &simplePresence)
229 argument.beginStructure();
230 argument << simplePresence.type << simplePresence.status << simplePresence.statusMessage;
231 argument.endStructure();
235 // Retrieve the Presence data from the D-Bus argument
236 const QDBusArgument &operator>>(const QDBusArgument &argument, SimplePresence &simplePresence)
238 argument.beginStructure();
239 argument >> simplePresence.type >> simplePresence.status >> simplePresence.statusMessage;
240 argument.endStructure();