27 #include <KNotification>
28 #include <KLocalizedString>
30 #include <TelepathyQt/Contact>
31 #include <TelepathyQt/Connection>
32 #include <TelepathyQt/ReferencedHandles>
33 #include <TelepathyQt/PendingReady>
34 #include <TelepathyQt/ChannelDispatchOperation>
36 Approver::Approver(
const Tp::MethodInvocationContextPtr<> &context,
37 const QList<Tp::ChannelPtr> &channels,
38 const Tp::ChannelDispatchOperationPtr &dispatchOperation,
43 m_dispatchOp(dispatchOperation),
46 kDebug() <<
"Initializing approver";
48 connect(m_dispatchOp->becomeReady(),
49 SIGNAL(finished(Tp::PendingOperation*)),
50 SLOT(onDispatchOperationReady(Tp::PendingOperation*)));
53 void Approver::onDispatchOperationReady(Tp::PendingOperation *op)
56 kError() <<
"Dispatch operation failed to become ready"
57 << op->errorName() << op->errorMessage();
58 m_context->setFinishedWithError(op->errorName(), op->errorMessage());
63 kDebug() <<
"DispatchOp ready!";
65 Tp::ChannelPtr channel = m_dispatchOp->channels()[0];
66 connect(channel->becomeReady(),
67 SIGNAL(
finished(Tp::PendingOperation*)),
68 SLOT(onChannelReady(Tp::PendingOperation*)));
71 void Approver::onChannelReady(Tp::PendingOperation *op)
74 kError() <<
"Channel failed to become ready"
75 << op->errorName() << op->errorMessage();
76 m_context->setFinishedWithError(op->errorName(), op->errorMessage());
81 kDebug() <<
"Channel ready!";
83 Tp::ContactPtr contact = m_dispatchOp->channels()[0]->initiatorContact();
85 KNotification *notification =
new KNotification(
"newrfb", NULL, KNotification::Persistent);
86 notification->setTitle(i18n(
"Invitation to view remote desktop"));
87 notification->setText(i18n(
"%1 wants to share his/her desktop with you", contact->alias()));
88 notification->setActions(QStringList() << i18n(
"Accept") << i18n(
"Reject"));
90 Tp::Client::ConnectionInterfaceAvatarsInterface *avatarIface =
91 m_dispatchOp->channels()[0]->connection()->optionalInterface<Tp::Client::ConnectionInterfaceAvatarsInterface>();
94 QDBusPendingReply<QByteArray, QString> reply = avatarIface->RequestAvatar(
95 contact->handle().takeFirst());
97 reply.waitForFinished();
99 if (!reply.isError()) {
101 avatar.loadFromData(reply.value());
102 notification->setPixmap(avatar);
106 connect(notification, SIGNAL(action1Activated()), SLOT(onAccepted()));
107 connect(notification, SIGNAL(action2Activated()), SLOT(onRejected()));
108 connect(notification, SIGNAL(ignored()), SLOT(onRejected()));
110 notification->sendEvent();
112 m_notification = notification;
114 m_context->setFinished();
119 kDebug() <<
"Destroying approver";
122 void Approver::onAccepted()
124 kDebug() <<
"Channel approved";
125 m_dispatchOp->handleWith(TP_QT_IFACE_CLIENT +
".krdc_rfb_handler");
130 void Approver::onRejected()
132 kDebug() <<
"Channel rejected";
133 connect(m_dispatchOp->claim(), SIGNAL(
finished(Tp::PendingOperation*)),
134 SLOT(onClaimFinished(Tp::PendingOperation*)));
137 void Approver::onClaimFinished(Tp::PendingOperation *op)
140 kError() <<
"Claim operation failed"
141 << op->errorName() << op->errorMessage();
142 m_context->setFinishedWithError(op->errorName(), op->errorMessage());
145 foreach(
const Tp::ChannelPtr &channel, m_channels)
146 channel->requestClose();