3 #include <TelepathyQt4/Account>
4 #include <TelepathyQt4/AccountInterface>
5 #include <TelepathyQt4/PendingOperation>
6 #include <TelepathyQt4/PendingVoid>
7 #include <TelepathyQt4/PendingReady>
8 #include <QtDBus/QDBusPendingCallWatcher>
9 #include <QtDBus/QDBusPendingReply>
11 tpSession::tpSession()
13 QDBusConnection bus = QDBusConnection::sessionBus();
14 mAM = AccountManager::create(bus,
15 AccountFactory::create(bus, Account::FeatureCore),
16 ConnectionFactory::create(bus, Connection::FeatureCore),
17 ChannelFactory::create(bus));
19 connect(mAM->becomeReady(),
20 SIGNAL(finished(Tp::PendingOperation *)),
21 SLOT(onAMReady(Tp::PendingOperation *)));
24 void tpSession::onAMReady(Tp::PendingOperation *op)
27 qWarning() << "error making AM ready";
31 mAccount = mAM->accountForPath("/org/freedesktop/Telepathy/Account/ring/tel/ring");
33 qWarning() << "no account for ring found";
37 //connect(mAccount->baseInterface(), SIGNAL(AccountPropertyChanged(const QVariantMap&)), this, SLOT(onPrivacyChanged(const QVariantMap&)));
38 if (!mAccount->haveConnection()) {
39 connect(mAccount.data(),
40 SIGNAL(haveConnectionChanged(bool)),
41 SLOT(onAccountHaveConnectionChanged(bool)));
43 mConnection = mAccount->connection();
48 void tpSession::onPropertyChanged(const QVariantMap& properties)
50 qDebug() << "TODO: change state when Privacy has been updated by someone else" << properties;
53 void tpSession::onAccountHaveConnectionChanged(bool haveConnection)
56 mConnection = mAccount->connection();
61 void tpSession::onSetPrivacyFinished(Tp::PendingOperation *op)
64 qWarning() << "unable to set com.nokia.Telepathy.Connection.Interface.GSM.Privacy";
68 qDebug() << "com.nokia.Telepathy.Connection.Interface.GSM.Privacy property set";
69 emit privacyUpdated(showId);
72 void tpSession::onGotPrivacy(QDBusPendingCallWatcher *watcher)
74 QDBusPendingReply<QVariant> reply = *watcher;
76 if (reply.isError()) {
77 qWarning() << "unable to get com.nokia.Telepathy.Connection.Interface.GSM.Privacy";
81 // Don't ask me why, but no-id == showId and id == hide it.
82 if(qdbus_cast<QStringList>(reply.value()) == QVariant("no-id"))
86 emit privacyUpdated(showId);
88 qDebug() << "com.nokia.Telepathy.Connection.Interface.GSM.Privacy property set";
91 void tpSession::retrievePrivacy()
94 qWarning() << "Account Manager connection unavailable";
98 if (!mConnection->hasInterface("com.nokia.Telepathy.Connection.Interface.GSM")) {
99 qWarning() << "connection does not have interface GSM";
103 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
104 mConnection->propertiesInterface()->Get(
105 QLatin1String("com.nokia.Telepathy.Connection.Interface.GSM"),
106 QLatin1String("Privacy")), this);
109 SIGNAL(finished(QDBusPendingCallWatcher *)),
110 SLOT(onGotPrivacy(QDBusPendingCallWatcher *)));
112 qDebug() << "com.nokia.Telepathy.Connection.Interface.GSM.Privacy retrieved";
115 void tpSession::setPrivacy(bool value)
120 qWarning() << "Account Manager connection unavailable";
124 if (!mConnection->hasInterface("com.nokia.Telepathy.Connection.Interface.GSM")) {
125 qWarning() << "connection does not have interface GSM";
130 // Don't ask me why, but no-id == showId and id == hide it.
132 call = new PendingVoid(
133 mConnection->propertiesInterface()->Set(
134 QLatin1String("com.nokia.Telepathy.Connection.Interface.GSM"),
135 QLatin1String("Privacy"), QDBusVariant("no-id")),
138 call = new PendingVoid(
139 mConnection->propertiesInterface()->Set(
140 QLatin1String("com.nokia.Telepathy.Connection.Interface.GSM"),
141 QLatin1String("Privacy"), QDBusVariant("id")),
145 SIGNAL(finished(Tp::PendingOperation*)),
146 SLOT(onSetPrivacyFinished(Tp::PendingOperation*)));