27 #include <TelepathyQt/AccountManager>
28 #include <TelepathyQt/SimpleCallObserver>
29 #include <TelepathyQt/PendingOperation>
30 #include <TelepathyQt/PendingReady>
31 #include <TelepathyQt/PendingAccount>
35 using namespace media::telephony;
38 namespace MediaHubService {
46 mCallObserver(Tp::SimpleCallObserver::create(mAccount)) {
47 connect(mCallObserver.data(), SIGNAL(callStarted(Tp::CallChannelPtr)), SIGNAL(offHook()));
48 connect(mCallObserver.data(), SIGNAL(callEnded(Tp::CallChannelPtr,QString,QString)), SIGNAL(onHook()));
49 connect(mCallObserver.data(), SIGNAL(streamedMediaCallStarted(Tp::StreamedMediaChannelPtr)), SIGNAL(offHook()));
50 connect(mCallObserver.data(), SIGNAL(streamedMediaCallEnded(Tp::StreamedMediaChannelPtr,QString,QString)), SIGNAL(onHook()));
58 Tp::AccountPtr mAccount;
59 Tp::SimpleCallObserverPtr mCallObserver;
77 QTimer::singleShot(0,
this, SLOT(accountManagerSetup()));
81 for (std::list<TelepathyCallMonitor*>::iterator it = mCallMonitors.begin();
82 it != mCallMonitors.end();
89 void accountManagerSetup() {
90 mAccountManager = Tp::AccountManager::create(Tp::AccountFactory::create(QDBusConnection::sessionBus(),
91 Tp::Account::FeatureCore),
92 Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
93 Tp::Connection::FeatureCore));
94 connect(mAccountManager->becomeReady(),
95 SIGNAL(finished(Tp::PendingOperation*)),
96 SLOT(accountManagerReady(Tp::PendingOperation*)));
99 void accountManagerReady(Tp::PendingOperation* operation) {
100 static uint8_t retries = 0;
101 if (operation->isError()) {
102 MH_ERROR(
"TelepathyBridge: Operation failed (accountManagerReady)");
104 QTimer::singleShot(1000,
this, SLOT(accountManagerSetup()));
110 Q_FOREACH(
const Tp::AccountPtr& account, mAccountManager->allAccounts()) {
111 connect(account->becomeReady(Tp::Account::FeatureCapabilities),
112 SIGNAL(finished(Tp::PendingOperation*)),
113 SLOT(accountReady(Tp::PendingOperation*)));
116 connect(mAccountManager.data(), SIGNAL(newAccount(Tp::AccountPtr)), SLOT(newAccount(Tp::AccountPtr)));
119 void newAccount(
const Tp::AccountPtr& account)
121 connect(account->becomeReady(Tp::Account::FeatureCapabilities),
122 SIGNAL(finished(Tp::PendingOperation*)),
123 SLOT(accountReady(Tp::PendingOperation*)));
126 void accountReady(Tp::PendingOperation* operation) {
127 if (operation->isError()) {
128 MH_ERROR(
"TelepathyAccount: Operation failed (accountReady)");
132 Tp::PendingReady* pendingReady = qobject_cast<Tp::PendingReady*>(operation);
133 if (pendingReady == 0) {
134 MH_ERROR(
"Rejecting account because could not understand ready status");
138 checkAndAddAccount(Tp::AccountPtr::qObjectCast(pendingReady->proxy()));
144 m_callState = media::telephony::CallMonitor::State::OffHook;
145 Q_EMIT q->callStateChanged();
151 m_callState = media::telephony::CallMonitor::State::OnHook;
152 Q_EMIT q->callStateChanged();
156 Tp::AccountManagerPtr mAccountManager;
157 std::list<TelepathyCallMonitor*> mCallMonitors;
158 media::telephony::CallMonitor::State m_callState;
161 void checkAndAddAccount(
const Tp::AccountPtr& account)
163 Tp::ConnectionCapabilities caps = account->capabilities();
167 auto tcm =
new TelepathyCallMonitor(account);
168 connect(tcm, SIGNAL(offHook()), SLOT(offHook()));
169 connect(tcm, SIGNAL(onHook()), SLOT(onHook()));
170 mCallMonitors.push_back(tcm);
188 return d->m_callState;
191 #include "call_monitor.moc"