X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fvicar-lib%2Fsrc%2Ftelepathyutility.cpp;fp=src%2Fvicar-lib%2Fsrc%2Ftelepathyutility.cpp;h=259ad0cd916e16366c69707d3a4f5dc96c724a4a;hb=11d5c26f3a622a0fc32f9cb89e1658846201af4d;hp=0000000000000000000000000000000000000000;hpb=40b1207a3eb33b54e8ac780cabd4a68f7931f248;p=vicar diff --git a/src/vicar-lib/src/telepathyutility.cpp b/src/vicar-lib/src/telepathyutility.cpp new file mode 100644 index 0000000..259ad0c --- /dev/null +++ b/src/vicar-lib/src/telepathyutility.cpp @@ -0,0 +1,208 @@ +/* +@version: 0.5 +@author: Sudheer K. +@license: GNU General Public License +*/ + +#include "telepathyutility.h" +#include "accountmanagerproxy.h" +#include "accountproxy.h" +#include "accountcompatproxy.h" +#include +#include +#include +#include +#include +#include + +using namespace org::freedesktop::Telepathy; + +TelepathyUtility::TelepathyUtility(QObject *parent) : + QObject(parent) +{ +} + +TelepathyUtility::~TelepathyUtility(){ + +} + +//Get a list of all Telepathy accounts +QList TelepathyUtility::getAllAccounts(){ + + QList objPathList; + + QDBusInterface *iface = new QDBusInterface(AM_SERVICE,AM_OBJ_PATH,DBUS_PROPS_IFACE,QDBusConnection::sessionBus(),this); + if (iface->isValid()){ + QDBusReply reply = iface->call(QDBus::AutoDetect,"Get",AM_INTERFACE,"ValidAccounts"); + + if (reply.isValid()){; + QDBusVariant validAccounts = reply.value(); + const QVariant var = validAccounts.variant(); + const QDBusArgument arg = var.value(); + + arg.beginArray(); + while (!arg.atEnd()){ + QDBusObjectPath opath; + arg >> opath; + if (opath.path().contains("tel")){ + qDebug() << opath.path(); + } + objPathList.append(opath); + } + arg.endArray(); + } + else{ + qDebug() << "Error occurred while fetching accounts list "< accountsList = this->getAllAccounts(); + QDBusObjectPath account; + foreach (account,accountsList){ + if (account.path().contains("vicar/tel/vicar")){ + vicarAccountExists = true; + break; + } + } + + return vicarAccountExists; +} + +//Get telepathy account status +QString TelepathyUtility::getAccountStatus(){ + + QString status = "Not Available"; + + QList accountsList = this->getAllAccounts(); + QDBusObjectPath account; + foreach (account,accountsList){ + if (account.path().contains("vicar/tel/vicar")){ + AccountProxy *accountProxy = new AccountProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this); + if (accountProxy->isValid()){ + uint intStatus = accountProxy->property("ConnectionStatus").toUInt(); + //Based on http://telepathy.freedesktop.org/spec/Connection.html#Connection_Status + switch(intStatus){ + case 0: + status = "Connected"; + break; + case 1: + status = "Connecting"; + break; + case 2: + status = "Disconnected"; + break; + } + } + } + } + + return status; +} + +//Create Vicar telepathy account (used installation) +bool TelepathyUtility::createAccount(){ + + AccountManagerProxy *amProxy = new AccountManagerProxy(AM_SERVICE,AM_OBJ_PATH,QDBusConnection::sessionBus(),this); + + QMap connectionParametersMap; + connectionParametersMap.insert("account","vicar"); + + QList presenceDetails; + uint presenceType(2); //Available = 2 + presenceDetails << presenceType; + presenceDetails << "online"; + presenceDetails << "Available"; + + SimplePresence presence; + presence.type = presenceType; + presence.status = "online"; + presence.statusMessage = "Available"; + + QMap accountPropertiesMap; + accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.AutomaticPresence",QVariant::fromValue(presence)); + accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.Enabled",true); + accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.ConnectAutomatically",true); + accountPropertiesMap.insert("org.freedesktop.Telepathy.Account.RequestedPresence",QVariant::fromValue(presence)); + accountPropertiesMap.insert("com.nokia.Account.Interface.Compat.Profile","vicar"); + + QStringList valuesList; + valuesList.append("TEL"); + accountPropertiesMap.insert("com.nokia.Account.Interface.Compat.SecondaryVCardFields",valuesList); + + QDBusPendingReply reply = amProxy->CreateAccount("vicar","tel","Vicar",connectionParametersMap,accountPropertiesMap); + reply.waitForFinished(); + + if (reply.isValid()){ + QDBusObjectPath account = reply.value(); + qDebug() << account.path() <<" created successfully."; + + AccountCompatProxy *accountCompatProxy = new AccountCompatProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this); + if (accountCompatProxy->isValid()){ + QDBusPendingReply<> dbusReply = accountCompatProxy->SetHasBeenOnline(); + dbusReply.waitForFinished(); + if (dbusReply.isError()){ + qDebug() << "Error occurred while setting HasBeenOnline property "< accountsList = this->getAllAccounts(); + QDBusObjectPath account; + foreach (account,accountsList){ + if (account.path().contains("vicar/tel/vicar")){ + AccountProxy *accountProxy = new AccountProxy(AM_SERVICE,account.path(),QDBusConnection::sessionBus(),this); + if (accountProxy->isValid()){ + QDBusPendingReply<> dbusReply = accountProxy->Remove(); + dbusReply.waitForFinished(); + if (dbusReply.isError()){ + qDebug() << "Error occurred while removing VICaR account "<>(const QDBusArgument &argument, SimplePresence &simplePresence) + { + argument.beginStructure(); + argument >> simplePresence.type >> simplePresence.status >> simplePresence.statusMessage; + argument.endStructure(); + return argument; + }