21 #include <TelepathyQt/Account>
22 #include <TelepathyQt/ChannelRequestHints>
23 #include <TelepathyQt/Contact>
24 #include <TelepathyQt/PendingChannelRequest>
25 #include <TelepathyQt/PendingFailure>
28 #include <KToolInvocation>
30 #include <KLocalizedString>
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")
41 bool delegateToPreferredHandler)
43 if (account.isNull() || contact.isNull()) {
44 kWarning() <<
"Parameters invalid";
47 kDebug() <<
"Requesting text channel for" << contact->id();
49 Tp::ChannelRequestHints hints;
50 if (delegateToPreferredHandler) {
51 hints.setHint(QLatin1String(
"org.freedesktop.Telepathy.ChannelRequest"),
52 QLatin1String(
"DelegateToPreferredHandler"),
56 return account->ensureTextChat(contact,
57 QDateTime::currentDateTime(),
63 const QString &roomName)
65 if (account.isNull() || roomName.isEmpty()) {
66 kWarning() <<
"Parameters invalid";
69 kDebug() <<
"Requesting text chat room " << roomName;
71 Tp::ChannelRequestHints hints;
72 hints.setHint(QLatin1String(
"org.kde.telepathy"), QLatin1String(
"forceRaiseWindow"), QVariant(
true));
74 return account->ensureTextChatroom(roomName,
75 QDateTime::currentDateTime(),
83 if (account.isNull() || contact.isNull()) {
84 kWarning() <<
"Parameters invalid";
87 kDebug() <<
"Requesting audio channel for" << contact->id();
89 return account->ensureAudioCall(contact,
90 QLatin1String(
"audio"),
91 QDateTime::currentDateTime(),
98 if (account.isNull() || contact.isNull()) {
99 kWarning() <<
"Parameters invalid";
102 kDebug() <<
"Requesting audio-video channel for" << contact->id();
104 return account->ensureAudioVideoCall(contact,
105 QLatin1String(
"audio"),
106 QLatin1String(
"video"),
107 QDateTime::currentDateTime(),
114 if (account.isNull() || contact.isNull()) {
115 kWarning() <<
"Parameters invalid";
118 kDebug() <<
"Requesting stream tube for" << contact->id();
120 return account->createStreamTube(contact,
121 QLatin1String(
"rfb"),
122 QDateTime::currentDateTime(),
128 const QString &filePath)
130 if (account.isNull() || contact.isNull()) {
131 kWarning() <<
"Parameters invalid";
134 kDebug() <<
"Requesting file transfer of" << filePath <<
"to" << contact->id();
136 Tp::FileTransferChannelCreationProperties fileTransferProperties(
137 filePath, KMimeType::findByFileContent(filePath)->name());
139 return account->createFileTransfer(contact,
140 fileTransferProperties,
141 QDateTime::currentDateTime(),
149 if (account.isNull() || contact.isNull() || url.isEmpty()) {
150 kWarning() <<
"Parameters invalid";
153 kDebug() <<
"Requesting file transfer of" << url.toLocalFile() <<
"to" << contact->id();
155 Tp::PendingOperation *ret = 0;
156 if (url.isLocalFile()) {
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);
167 if (account.isNull() || contact.isNull()) {
168 kWarning() <<
"Parameters invalid";
171 kDebug() <<
"Opening logviewer for" << contact->id();
173 QStringList arguments;
174 arguments << QLatin1String(
"--") << account->uniqueIdentifier() << contact->id();
177 KToolInvocation::kdeinitExec(QLatin1String(
"ktp-log-viewer"), arguments);