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

Nepomuk-Core

  • KTp
actions.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Dan Vrátil <dvratil@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "actions.h"
20 
21 #include <TelepathyQt/Account>
22 #include <TelepathyQt/ChannelRequestHints>
23 #include <TelepathyQt/Contact>
24 #include <TelepathyQt/PendingChannelRequest>
25 #include <TelepathyQt/PendingFailure>
26 
27 #include <KMimeType>
28 #include <KToolInvocation>
29 #include <KDebug>
30 #include <KLocalizedString>
31 
32 #define PREFERRED_TEXT_CHAT_HANDLER QLatin1String("org.freedesktop.Telepathy.Client.KTp.TextUi")
33 #define PREFERRED_FILE_TRANSFER_HANDLER QLatin1String("org.freedesktop.Telepathy.Client.KTp.FileTransfer")
34 #define PREFERRED_AUDIO_VIDEO_HANDLER QLatin1String("org.freedesktop.Telepathy.Client.KTp.CallUi")
35 #define PREFERRED_RFB_HANDLER QLatin1String("org.freedesktop.Telepathy.Client.krfb_rfb_handler")
36 
37 using namespace KTp;
38 
39 Tp::PendingChannelRequest* Actions::startChat(const Tp::AccountPtr &account,
40  const Tp::ContactPtr &contact,
41  bool delegateToPreferredHandler)
42 {
43  if (account.isNull() || contact.isNull()) {
44  kWarning() << "Parameters invalid";
45  }
46 
47  kDebug() << "Requesting text channel for" << contact->id();
48 
49  Tp::ChannelRequestHints hints;
50  if (delegateToPreferredHandler) {
51  hints.setHint(QLatin1String("org.freedesktop.Telepathy.ChannelRequest"),
52  QLatin1String("DelegateToPreferredHandler"),
53  QVariant(true));
54  }
55 
56  return account->ensureTextChat(contact,
57  QDateTime::currentDateTime(),
58  PREFERRED_TEXT_CHAT_HANDLER,
59  hints);
60 }
61 
62 Tp::PendingChannelRequest* Actions::startGroupChat(const Tp::AccountPtr &account,
63  const QString &roomName)
64 {
65  if (account.isNull() || roomName.isEmpty()) {
66  kWarning() << "Parameters invalid";
67  }
68 
69  kDebug() << "Requesting text chat room " << roomName;
70 
71  Tp::ChannelRequestHints hints;
72  hints.setHint(QLatin1String("org.kde.telepathy"), QLatin1String("forceRaiseWindow"), QVariant(true));
73 
74  return account->ensureTextChatroom(roomName,
75  QDateTime::currentDateTime(),
76  PREFERRED_TEXT_CHAT_HANDLER,
77  hints);
78 }
79 
80 Tp::PendingChannelRequest* Actions::startAudioCall(const Tp::AccountPtr &account,
81  const Tp::ContactPtr &contact)
82 {
83  if (account.isNull() || contact.isNull()) {
84  kWarning() << "Parameters invalid";
85  }
86 
87  kDebug() << "Requesting audio channel for" << contact->id();
88 
89  return account->ensureAudioCall(contact,
90  QLatin1String("audio"),
91  QDateTime::currentDateTime(),
92  PREFERRED_AUDIO_VIDEO_HANDLER);
93 }
94 
95 Tp::PendingChannelRequest* Actions::startAudioVideoCall(const Tp::AccountPtr &account,
96  const Tp::ContactPtr &contact)
97 {
98  if (account.isNull() || contact.isNull()) {
99  kWarning() << "Parameters invalid";
100  }
101 
102  kDebug() << "Requesting audio-video channel for" << contact->id();
103 
104  return account->ensureAudioVideoCall(contact,
105  QLatin1String("audio"),
106  QLatin1String("video"),
107  QDateTime::currentDateTime(),
108  PREFERRED_AUDIO_VIDEO_HANDLER);
109 }
110 
111 Tp::PendingChannelRequest* Actions::startDesktopSharing(const Tp::AccountPtr &account,
112  const Tp::ContactPtr &contact)
113 {
114  if (account.isNull() || contact.isNull()) {
115  kWarning() << "Parameters invalid";
116  }
117 
118  kDebug() << "Requesting stream tube for" << contact->id();
119 
120  return account->createStreamTube(contact,
121  QLatin1String("rfb"),
122  QDateTime::currentDateTime(),
123  PREFERRED_RFB_HANDLER);
124 }
125 
126 Tp::PendingChannelRequest* Actions::startFileTransfer(const Tp::AccountPtr &account,
127  const Tp::ContactPtr &contact,
128  const QString &filePath)
129 {
130  if (account.isNull() || contact.isNull()) {
131  kWarning() << "Parameters invalid";
132  }
133 
134  kDebug() << "Requesting file transfer of" << filePath << "to" << contact->id();
135 
136  Tp::FileTransferChannelCreationProperties fileTransferProperties(
137  filePath, KMimeType::findByFileContent(filePath)->name());
138 
139  return account->createFileTransfer(contact,
140  fileTransferProperties,
141  QDateTime::currentDateTime(),
142  PREFERRED_FILE_TRANSFER_HANDLER);
143 }
144 
145 Tp::PendingOperation* Actions::startFileTransfer(const Tp::AccountPtr &account,
146  const Tp::ContactPtr &contact,
147  const QUrl &url)
148 {
149  if (account.isNull() || contact.isNull() || url.isEmpty()) {
150  kWarning() << "Parameters invalid";
151  }
152 
153  kDebug() << "Requesting file transfer of" << url.toLocalFile() << "to" << contact->id();
154 
155  Tp::PendingOperation *ret = 0;
156  if (url.isLocalFile()) {
157  ret = startFileTransfer(account, contact, url.toLocalFile());
158  } else {
159  ret = new Tp::PendingFailure(QLatin1String("Failed file transfer"), QString(QLatin1String("You are only supposed to send local files, not %1")).arg(url.toString()), account);
160  }
161  return ret;
162 }
163 
164 void Actions::openLogViewer(const Tp::AccountPtr &account,
165  const Tp::ContactPtr &contact)
166 {
167  if (account.isNull() || contact.isNull()) {
168  kWarning() << "Parameters invalid";
169  }
170 
171  kDebug() << "Opening logviewer for" << contact->id();
172 
173  QStringList arguments;
174  arguments << QLatin1String("--") << account->uniqueIdentifier() << contact->id();
175 
176  /* Use "--" so that KCmdLineArgs does not parse UIDs starting with "-" as arguments */
177  KToolInvocation::kdeinitExec(QLatin1String("ktp-log-viewer"), arguments);
178 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
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