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 << "available";
125 presenceDetails << "Available";
127 SimplePresence presence;
128 presence.type = presenceType;
129 presence.status = "available";
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("org.freedesktop.Telepathy.Account.Service","vicar"); //Required when service can't be determined by the protocol name
138 accountPropertiesMap.insert("com.nokia.Account.Interface.Compat.Profile","vicar");
140 QStringList valuesList;
141 valuesList.append("TEL");
142 accountPropertiesMap.insert("com.nokia.Account.Interface.Compat.SecondaryVCardFields",valuesList);
144 //QStringList uriSchemeList;
145 //uriSchemeList.append("tel");
146 //accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.Interface.Addressing.DRAFT.URISchemes",uriSchemeList);
148 QDBusPendingReply<QDBusObjectPath> reply = amProxy->CreateAccount("vicar","tel","Vicar",connectionParametersMap,accountPropertiesMap);
149 reply.waitForFinished();
151 if (reply.isValid()){
152 QDBusObjectPath account = reply.value();
153 qDebug() << account.path() <<" created successfully.";
155 AccountCompatProxy *accountCompatProxy = new AccountCompatProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this);
156 if (accountCompatProxy->isValid()){
157 QDBusPendingReply<> dbusReply = accountCompatProxy->SetHasBeenOnline();
158 dbusReply.waitForFinished();
159 if (dbusReply.isError()){
160 qDebug() << "Error occurred while setting HasBeenOnline property "<<dbusReply.error();
166 qDebug() << "Error creating VICaR telepathy account "<<reply.error();
173 //Delete Vicar telepathy account (used during uninstallation)
174 bool TelepathyUtility::deleteAccount(){
176 QList<QDBusObjectPath> accountsList = this->getAllAccounts();
177 QDBusObjectPath account;
178 foreach (account,accountsList){
179 if (account.path().contains("vicar/tel/vicar")){
180 AccountProxy *accountProxy = new AccountProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this);
181 if (accountProxy->isValid()){
182 QDBusPendingReply<> dbusReply = accountProxy->Remove();
183 dbusReply.waitForFinished();
184 if (dbusReply.isError()){
185 qDebug() << "Error occurred while removing VICaR account "<<dbusReply.error();
189 qDebug() <<"VICaR account deleted";
198 bool TelepathyUtility::callNumberWithRing(QString number){
202 ConnectionInterfaceRequestsProxy *requestsProxy = new ConnectionInterfaceRequestsProxy(RING_CONN_SERVICE,RING_CONN_PATH,QDBusConnection::sessionBus(),this);
203 if (requestsProxy->isValid()){
204 QVariantMap channelRequestDetails;
205 uint targetHandleType(1);
206 channelRequestDetails.insert("org.freedesktop.Telepathy.Channel.TargetHandleType",targetHandleType);
207 channelRequestDetails.insert("org.freedesktop.Telepathy.Channel.TargetID",number);
208 channelRequestDetails.insert("org.freedesktop.Telepathy.Channel.ChannelType","org.freedesktop.Telepathy.Channel.Type.StreamedMedia");
209 QDBusPendingReply<QDBusObjectPath,QVariantMap> dbusReply = requestsProxy->CreateChannel(channelRequestDetails);
210 dbusReply.waitForFinished();
211 if (!dbusReply.isError()){
212 QDBusObjectPath objPath = dbusReply.argumentAt<0>();
213 QVariantMap channelProperties = dbusReply.argumentAt<1>();
217 qDebug() << "Error occurred calling "<<number<< ". Error is "<< dbusReply.error();
225 bool TelepathyUtility::sendDTMFTone(QString tone){
231 // Marshall the Presence data into a D-Bus argument
232 QDBusArgument &operator<<(QDBusArgument &argument, const SimplePresence &simplePresence)
234 argument.beginStructure();
235 argument << simplePresence.type << simplePresence.status << simplePresence.statusMessage;
236 argument.endStructure();
240 // Retrieve the Presence data from the D-Bus argument
241 const QDBusArgument &operator>>(const QDBusArgument &argument, SimplePresence &simplePresence)
243 argument.beginStructure();
244 argument >> simplePresence.type >> simplePresence.status >> simplePresence.statusMessage;
245 argument.endStructure();