• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krdc

  • sources
  • kde-4.12
  • kdenetwork
  • krdc
  • krdc_approver
approver.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Collabora Ltd <info@collabora.co.uk>
4 ** Copyright (C) 2009 Abner Silva <abner.silva@kdemail.net>
5 **
6 ** This file is part of KDE.
7 **
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
21 **
22 ****************************************************************************/
23 
24 #include "approver.h"
25 
26 #include <KDebug>
27 #include <KNotification>
28 #include <KLocalizedString>
29 
30 #include <TelepathyQt/Contact>
31 #include <TelepathyQt/Connection>
32 #include <TelepathyQt/ReferencedHandles>
33 #include <TelepathyQt/PendingReady>
34 #include <TelepathyQt/ChannelDispatchOperation>
35 
36 Approver::Approver(const Tp::MethodInvocationContextPtr<> &context,
37  const QList<Tp::ChannelPtr> &channels,
38  const Tp::ChannelDispatchOperationPtr &dispatchOperation,
39  QObject *parent)
40  : QObject(parent),
41  m_context(context),
42  m_channels(channels),
43  m_dispatchOp(dispatchOperation),
44  m_notification(0)
45 {
46  kDebug() << "Initializing approver";
47 
48  connect(m_dispatchOp->becomeReady(),
49  SIGNAL(finished(Tp::PendingOperation*)),
50  SLOT(onDispatchOperationReady(Tp::PendingOperation*)));
51 }
52 
53 void Approver::onDispatchOperationReady(Tp::PendingOperation *op)
54 {
55  if (op->isError()) {
56  kError() << "Dispatch operation failed to become ready"
57  << op->errorName() << op->errorMessage();
58  m_context->setFinishedWithError(op->errorName(), op->errorMessage());
59  emit finished();
60  return;
61  }
62 
63  kDebug() << "DispatchOp ready!";
64 
65  Tp::ChannelPtr channel = m_dispatchOp->channels()[0];
66  connect(channel->becomeReady(),
67  SIGNAL(finished(Tp::PendingOperation*)),
68  SLOT(onChannelReady(Tp::PendingOperation*)));
69 }
70 
71 void Approver::onChannelReady(Tp::PendingOperation *op)
72 {
73  if (op->isError()) {
74  kError() << "Channel failed to become ready"
75  << op->errorName() << op->errorMessage();
76  m_context->setFinishedWithError(op->errorName(), op->errorMessage());
77  emit finished();
78  return;
79  }
80 
81  kDebug() << "Channel ready!";
82 
83  Tp::ContactPtr contact = m_dispatchOp->channels()[0]->initiatorContact();
84 
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"));
89 
90  Tp::Client::ConnectionInterfaceAvatarsInterface *avatarIface =
91  m_dispatchOp->channels()[0]->connection()->optionalInterface<Tp::Client::ConnectionInterfaceAvatarsInterface>();
92 
93  if (avatarIface) {
94  QDBusPendingReply<QByteArray, QString> reply = avatarIface->RequestAvatar(
95  contact->handle().takeFirst());
96 
97  reply.waitForFinished();
98 
99  if (!reply.isError()) {
100  QPixmap avatar;
101  avatar.loadFromData(reply.value());
102  notification->setPixmap(avatar);
103  }
104  }
105 
106  connect(notification, SIGNAL(action1Activated()), SLOT(onAccepted()));
107  connect(notification, SIGNAL(action2Activated()), SLOT(onRejected()));
108  connect(notification, SIGNAL(ignored()), SLOT(onRejected()));
109 
110  notification->sendEvent();
111 
112  m_notification = notification;
113 
114  m_context->setFinished();
115 }
116 
117 Approver::~Approver()
118 {
119  kDebug() << "Destroying approver";
120 }
121 
122 void Approver::onAccepted()
123 {
124  kDebug() << "Channel approved";
125  m_dispatchOp->handleWith(TP_QT_IFACE_CLIENT + ".krdc_rfb_handler");
126 
127  emit finished();
128 }
129 
130 void Approver::onRejected()
131 {
132  kDebug() << "Channel rejected";
133  connect(m_dispatchOp->claim(), SIGNAL(finished(Tp::PendingOperation*)),
134  SLOT(onClaimFinished(Tp::PendingOperation*)));
135 }
136 
137 void Approver::onClaimFinished(Tp::PendingOperation *op)
138 {
139  if (op->isError()) {
140  kError() << "Claim operation failed"
141  << op->errorName() << op->errorMessage();
142  m_context->setFinishedWithError(op->errorName(), op->errorMessage());
143  }
144  else {
145  foreach(const Tp::ChannelPtr &channel, m_channels)
146  channel->requestClose();
147  }
148 
149  emit finished();
150 }
Approver::finished
void finished()
QObject
approver.h
Approver::~Approver
~Approver()
Definition: approver.cpp:117
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krdc

Skip menu "krdc"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal