Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit e4cbf225 authored by David Edmundson's avatar David Edmundson

Telepathy integration

This sends recieved text messages to any Telepathy client and allows the
user to respond from there.
This should work with both our clients and Empathy.

An account on telepathy is created on activation.

As Telepathy clients expect backends to be always running, this is
started by the daemon to
suppress client errors. The plugin system then talks to the same CM via
use of a singleton accessor.

Based on work by Alexandr Akulich then tidied up and rebased.
parent 501e5431
......@@ -13,6 +13,11 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DI
find_package(Qt5 5.2 REQUIRED COMPONENTS Quick)
find_package(KF5 REQUIRED COMPONENTS I18n ConfigWidgets DBusAddons IconThemes)
find_package(Qca-qt5 2.1.0 REQUIRED)
find_package(TelepathyQt5 0.9.5)
find_package(TelepathyQt5Service 0.9.5)
if (TelepathyQt5_FOUND)
add_definitions(-DHAVE_TELEPATHY)
endif()
include_directories(${CMAKE_SOURCE_DIR})
......@@ -49,6 +54,11 @@ add_subdirectory(plugins)
add_subdirectory(plasmoid)
add_subdirectory(cli)
add_subdirectory(fileitemactionplugin)
if (TelepathyQt5_FOUND)
add_subdirectory(telepathy-cm)
endif()
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
......
......@@ -8,6 +8,9 @@ add_executable(kdeconnectd kdeconnectd.cpp)
target_link_libraries(kdeconnectd kdeconnectcore KF5::KIOWidgets KF5::DBusAddons KF5::Notifications KF5::I18n Qt5::Widgets)
ecm_mark_nongui_executable(kdeconnectd)
if(TelepathyQt5_FOUND)
target_link_libraries(kdeconnectd connectcm)
endif()
configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop)
configure_file(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)
......@@ -15,3 +18,4 @@ configure_file(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop DESTINATION ${AUTOSTART_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
install(TARGETS kdeconnectd DESTINATION ${LIBEXEC_INSTALL_DIR})
......@@ -34,6 +34,10 @@
#include "core/device.h"
#include "kdeconnect-version.h"
#ifdef HAVE_TELEPATHY
#include "kdeconnecttelepathyprotocolfactory.h"
#endif
#ifndef Q_OS_WIN
#include <sys/socket.h>
......@@ -127,6 +131,11 @@ int main(int argc, char* argv[])
Daemon* daemon = new DesktopDaemon;
QObject::connect(daemon, SIGNAL(destroyed(QObject*)), &app, SLOT(quit()));
initializeTermHandlers(&app, daemon);
#ifdef HAVE_TELEPATHY
//keep a reference to the KTP CM so that we can register on DBus
auto telepathyPlugin = KDEConnectTelepathyProtocolFactory::interface();
#endif
return app.exec();
}
......
......@@ -12,3 +12,9 @@ target_link_libraries(kdeconnect_telephony
KF5::I18n
KF5::Notifications
)
if (TelepathyQt5_FOUND)
target_link_libraries(kdeconnect_telephony
connectcm
)
endif()
\ No newline at end of file
......@@ -35,7 +35,11 @@ Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony")
TelephonyPlugin::TelephonyPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
{
#ifdef HAVE_TELEPATHY
//keep a reference to the KTP CM so that we can register on DBus
m_telepathyInterface = KDEConnectTelepathyProtocolFactory::interface();
connect(m_telepathyInterface.constData(), SIGNAL(messageReceived(QString,QString)), SLOT(sendSms(QString,QString)));
#endif
}
KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np)
......@@ -88,10 +92,11 @@ KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np)
notification->setActions( QStringList(i18n("Mute Call")) );
connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::sendMutePackage);
} else if (event == QLatin1String("sms")) {
const QString messageBody = np.get<QString>("messageBody","");
notification->setActions( QStringList(i18n("Reply")) );
notification->setProperty("phoneNumber", phoneNumber);
notification->setProperty("contactName", contactName);
notification->setProperty("originalMessage", np.get<QString>("messageBody",""));
notification->setProperty("originalMessage", messageBody);
connect(notification, &KNotification::action1Activated, this, &TelephonyPlugin::showSendSmsDialog);
}
......@@ -104,15 +109,23 @@ bool TelephonyPlugin::receivePackage(const NetworkPackage& np)
if (np.get<bool>("isCancel")) {
//TODO: Clear the old notification
} else {
KNotification* n = createNotification(np);
if (n != nullptr) n->sendEvent();
return true;
}
#ifdef HAVE_TELEPATHY
if (np.get<QString>("event") == QLatin1String("sms")) {
const QString messageBody = np.get<QString>("messageBody","");
const QString phoneNumber = np.get<QString>("phoneNumber", i18n("unknown number"));
const QString contactName = np.get<QString>("contactName", phoneNumber);
if (m_telepathyInterface->sendMessage(contactName, messageBody)) {
return true;
}
}
#endif
KNotification* n = createNotification(np);
if (n != nullptr) n->sendEvent();
return true;
}
void TelephonyPlugin::sendMutePackage()
......
......@@ -27,6 +27,10 @@
#include <core/kdeconnectplugin.h>
#ifdef HAVE_TELEPATHY
#include "kdeconnecttelepathyprotocolfactory.h"
#endif
#define PACKAGE_TYPE_TELEPHONY QLatin1String("kdeconnect.telephony")
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY)
......@@ -50,6 +54,11 @@ private Q_SLOTS:
private:
KNotification* createNotification(const NetworkPackage& np);
#ifdef HAVE_TELEPATHY
ConnectProtocolPtr m_telepathyInterface;
#endif
};
......
project(connectcm)
add_definitions(-DCONNECTCM_LIBRARY)
set(connectcm_SOURCES
connection.cpp
protocol.cpp
textchannel.cpp
kdeconnecttelepathyprotocolfactory.cpp
)
add_library(connectcm SHARED ${connectcm_SOURCES})
target_link_libraries(connectcm
PUBLIC
Qt5::Core
${TELEPATHY_QT5_LIBRARIES}
${TELEPATHY_QT5_SERVICE_LIBRARIES}
)
install (TARGETS connectcm
${INSTALL_TARGETS_DEFAULT_ARGS}
)
Connect TelepathyQt-based Connection Manager.
#ifndef CONNECTCM_EXPORT_H
#define CONNECTCM_EXPORT_H
#include <QtCore/QtGlobal>
#if defined(CONNECTCM_LIBRARY)
#define CONNECTCM_EXPORT Q_DECL_EXPORT
#else
#define CONNECTCM_EXPORT Q_DECL_IMPORT
#endif
#endif
This diff is collapsed.
/*
Copyright (C) 2014 Alexandr Akulich <akulichalexander@gmail.com>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef CONNECTCM_CONNECTION_H
#define CONNECTCM_CONNECTION_H
#include "connectcm_export.h"
#include <TelepathyQt/BaseConnection>
#include <TelepathyQt/BaseChannel>
class CONNECTCM_EXPORT ConnectConnection : public Tp::BaseConnection
{
Q_OBJECT
public:
ConnectConnection(const QDBusConnection &dbusConnection,
const QString &cmName, const QString &protocolName,
const QVariantMap &parameters);
~ConnectConnection();
static Tp::SimpleStatusSpecMap getSimpleStatusSpecMap();
void connect(Tp::DBusError *error);
QStringList inspectHandles(uint handleType, const Tp::UIntList &handles, Tp::DBusError *error);
Tp::BaseChannelPtr createChannelCB(const QVariantMap &request, Tp::DBusError *error);
Tp::UIntList requestHandles(uint handleType, const QStringList &identifiers, Tp::DBusError *error);
Tp::ContactAttributesMap getContactListAttributes(const QStringList &interfaces, bool hold, Tp::DBusError *error);
Tp::ContactAttributesMap getContactAttributes(const Tp::UIntList &handles, const QStringList &interfaces, Tp::DBusError *error);
Tp::SimplePresence getPresence(uint handle);
uint setPresence(const QString &status, const QString &message, Tp::DBusError *error);
uint ensureContact(const QString &identifier);
public slots:
bool receiveMessage(const QString &sender, const QString &message);
void setContactList(const QStringList &identifiers);
signals:
void messageReceived(const QString &sender, const QString &message);
private:
uint getHandle(const QString &identifier) const;
uint addContact(const QString &identifier);
uint addContacts(const QStringList &identifiers);
Tp::BaseConnectionContactsInterfacePtr contactsIface;
Tp::BaseConnectionSimplePresenceInterfacePtr simplePresenceIface;
Tp::BaseConnectionContactListInterfacePtr contactListIface;
Tp::BaseConnectionAddressingInterfacePtr addressingIface;
Tp::BaseConnectionRequestsInterfacePtr requestsIface;
QMap<uint, QString> m_handles;
/* Maps a contact handle to its subscription state */
QString m_deviceId;
};
#endif // CONNECTCM_CONNECTION_H
[ConnectionManager]
BusName=org.freedesktop.Telepathy.ConnectionManager.kdeconnect
ObjectPath=/org/freedesktop/Telepathy/ConnectionManager/kdeconnect
Interfaces=
[Protocol kdeconnect]
\ No newline at end of file
#include <TelepathyQt/Types>
#include <TelepathyQt/BaseConnectionManager>
#include <TelepathyQt/Constants>
#include <TelepathyQt/Debug>
#include <TelepathyQt/Types>
#include <TelepathyQt/ConnectionManager>
#include <TelepathyQt/AccountManager>
#include <TelepathyQt/Account>
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/PendingAccount>
#include <TelepathyQt/AccountSet>
#include <QtDBus/QDBusConnection>
#include "protocol.h"
#include "kdeconnecttelepathyprotocolfactory.h"
Tp::WeakPtr<KDEConnectTelepathyProtocol> KDEConnectTelepathyProtocolFactory::s_interface;
ConnectProtocolPtr KDEConnectTelepathyProtocolFactory::interface() {
if (s_interface.isNull()) {
Tp::registerTypes();
Tp::enableDebug(true);
Tp::enableWarnings(true);
ConnectProtocolPtr protocol = Tp::BaseProtocol::create<KDEConnectTelepathyProtocol>(
QDBusConnection::sessionBus(),
QLatin1String("kdeconnect"));
s_interface = protocol;
static Tp::BaseConnectionManagerPtr cm = Tp::BaseConnectionManager::create(
QDBusConnection::sessionBus(), QLatin1String("kdeconnect"));
protocol->setConnectionManagerName(cm->name());
protocol->setEnglishName(QLatin1String("KDE Connect"));
protocol->setIconName(QLatin1String("kdeconnect"));
protocol->setVCardField(QLatin1String("phone_number"));
cm->addProtocol(protocol);
cm->registerObject();
//fake being a client and create an account to use this connection
//maybe this should be per device.. with a device ID as a parameter, but lets keep it connect for now
Tp::AccountManagerPtr am = Tp::AccountManager::create(QDBusConnection::sessionBus());
QObject::connect(am->becomeReady(), &Tp::PendingOperation::finished, [am]() {
Tp::AccountSetPtr accounts = am->accountsByProtocol("kdeconnect");
if (!accounts) {
return;
}
if (accounts->accounts().isEmpty()) {
Tp::PendingAccount* pa = am->createAccount("kdeconnect", "kdeconnect", "kdeconnect", QVariantMap(), QVariantMap());
QObject::connect(pa, &Tp::PendingOperation::finished, pa, [pa](){
if (!pa->account()) {
return;
}
pa->account()->setEnabled(true);
pa->account()->setRequestedPresence(Tp::Presence::available());
});
} else {
Tp::AccountPtr account = accounts->accounts().first();
account->setRequestedPresence(Tp::Presence::available());
}
});
}
return s_interface.toStrongRef();
}
#include "protocol.h"
#include "connectcm_export.h"
typedef Tp::SharedPtr<KDEConnectTelepathyProtocol> ConnectProtocolPtr;
/*
* SingletonFactory for plugins to get access to the Telepathy connection manager
* Whilst the main process also holds a reference.
*
*/
class CONNECTCM_EXPORT KDEConnectTelepathyProtocolFactory
{
public:
static ConnectProtocolPtr interface();
private:
static Tp::WeakPtr<KDEConnectTelepathyProtocol> s_interface;
};
/*
Copyright (C) 2014 Alexandr Akulich <akulichalexander@gmail.com>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "protocol.h"
#include "connection.h"
#include <TelepathyQt/BaseConnection>
#include <TelepathyQt/Constants>
#include <TelepathyQt/RequestableChannelClassSpec>
#include <TelepathyQt/RequestableChannelClassSpecList>
#include <TelepathyQt/Types>
#include <QLatin1String>
#include <QVariantMap>
KDEConnectTelepathyProtocol::KDEConnectTelepathyProtocol(const QDBusConnection &dbusConnection, const QString &name)
: BaseProtocol(dbusConnection, name)
{
// setParameters(Tp::ProtocolParameterList()
// << Tp::ProtocolParameter(QLatin1String("device_id"), QLatin1String("s"), Tp::ConnMgrParamFlagRequired)
// << Tp::ProtocolParameter(QLatin1String("self_name"), QLatin1String("s"), 0));
setRequestableChannelClasses(Tp::RequestableChannelClassSpecList() << Tp::RequestableChannelClassSpec::textChat());
// callbacks
setCreateConnectionCallback(memFun(this, &KDEConnectTelepathyProtocol::createConnection));
setIdentifyAccountCallback(memFun(this, &KDEConnectTelepathyProtocol::identifyAccount));
setNormalizeContactCallback(memFun(this, &KDEConnectTelepathyProtocol::normalizeContact));
addrIface = Tp::BaseProtocolAddressingInterface::create();
addrIface->setAddressableVCardFields(QStringList() << QLatin1String("x-example-vcard-field"));
addrIface->setAddressableUriSchemes(QStringList() << QLatin1String("example-uri-scheme"));
addrIface->setNormalizeVCardAddressCallback(memFun(this, &KDEConnectTelepathyProtocol::normalizeVCardAddress));
addrIface->setNormalizeContactUriCallback(memFun(this, &KDEConnectTelepathyProtocol::normalizeContactUri));
plugInterface(Tp::AbstractProtocolInterfacePtr::dynamicCast(addrIface));
/*
presenceIface = Tp::BaseProtocolPresenceInterface::create();
presenceIface->setStatuses(Tp::PresenceSpecList(ConnectConnection::getConnectStatusSpecMap()));
plugInterface(Tp::AbstractProtocolInterfacePtr::dynamicCast(presenceIface));*/
Tp::DBusError err;
}
KDEConnectTelepathyProtocol::~KDEConnectTelepathyProtocol()
{
}
void KDEConnectTelepathyProtocol::setConnectionManagerName(const QString &newName)
{
m_connectionManagerName = newName;
}
bool KDEConnectTelepathyProtocol::sendMessage(QString sender, QString message)
{
if (m_connection) {
return m_connection->receiveMessage(sender, message);
}
return false;
}
void KDEConnectTelepathyProtocol::setContactList(QStringList list)
{
if (m_connection) {
m_connection->setContactList(list);
}
}
Tp::BaseConnectionPtr KDEConnectTelepathyProtocol::createConnection(const QVariantMap &parameters, Tp::DBusError *error)
{
Q_UNUSED(error)
auto newConnection = Tp::BaseConnection::create<ConnectConnection>(m_connectionManagerName, this->name(), parameters);
connect(newConnection.constData(), SIGNAL(messageReceived(QString,QString)), SIGNAL(messageReceived(QString,QString)));
m_connection = newConnection;
return newConnection;
}
QString KDEConnectTelepathyProtocol::identifyAccount(const QVariantMap &parameters, Tp::DBusError *error)
{
qDebug() << Q_FUNC_INFO << parameters;
error->set(QLatin1String("IdentifyAccount.Error.NotImplemented"), QLatin1String(""));
return QString();
}
QString KDEConnectTelepathyProtocol::normalizeContact(const QString &contactId, Tp::DBusError *error)
{
qDebug() << Q_FUNC_INFO << contactId;
error->set(QLatin1String("NormalizeContact.Error.NotImplemented"), QLatin1String(""));
return QString();
}
QString KDEConnectTelepathyProtocol::normalizeVCardAddress(const QString &vcardField, const QString vcardAddress,
Tp::DBusError *error)
{
qDebug() << Q_FUNC_INFO << vcardField << vcardAddress;
error->set(QLatin1String("NormalizeVCardAddress.Error.NotImplemented"), QLatin1String(""));
return QString();
}
QString KDEConnectTelepathyProtocol::normalizeContactUri(const QString &uri, Tp::DBusError *error)
{
qDebug() << Q_FUNC_INFO << uri;
error->set(QLatin1String("NormalizeContactUri.Error.NotImplemented"), QLatin1String(""));
return QString();
}
/*
Copyright (C) 2014 Alexandr Akulich <akulichalexander@gmail.com>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef CONNECTCM_PROTOCOL_H
#define CONNECTCM_PROTOCOL_H
#include "connectcm_export.h"
#include <TelepathyQt/BaseProtocol>
class ConnectConnection;
class CONNECTCM_EXPORT KDEConnectTelepathyProtocol : public Tp::BaseProtocol
{
Q_OBJECT
Q_DISABLE_COPY(KDEConnectTelepathyProtocol)
public:
KDEConnectTelepathyProtocol(const QDBusConnection &dbusConnection, const QString &name);
virtual ~KDEConnectTelepathyProtocol();
QString connectionManagerName() const;
void setConnectionManagerName(const QString &newName);
public slots:
bool sendMessage(QString sender, QString message);
void setContactList(QStringList list);
signals:
void contactsListChanged(QStringList);
void messageReceived(QString sender, QString message);
private:
Tp::BaseConnectionPtr createConnection(const QVariantMap &parameters, Tp::DBusError *error);
QString identifyAccount(const QVariantMap &parameters, Tp::DBusError *error);
QString normalizeContact(const QString &contactId, Tp::DBusError *error);
// Proto.I.Addressing
QString normalizeVCardAddress(const QString &vCardField, const QString vCardAddress,
Tp::DBusError *error);
QString normalizeContactUri(const QString &uri, Tp::DBusError *error);
Tp::BaseProtocolAddressingInterfacePtr addrIface;
Tp::BaseProtocolAvatarsInterfacePtr avatarsIface;
QString m_connectionManagerName;
//normally keeping the connection in the protocol would be really weird
//however we want to proxy the messages to the active connection and want a single entry point
Tp::SharedPtr<ConnectConnection> m_connection;
};
inline QString KDEConnectTelepathyProtocol::connectionManagerName() const
{
return m_connectionManagerName;
}
#endif // CONNECTCM_PROTOCOL_H
/*
Copyright (C) 2014 Alexandr Akulich <akulichalexander@gmail.com>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "textchannel.h"
#include <TelepathyQt/Constants>
#include <TelepathyQt/RequestableChannelClassSpec>
#include <TelepathyQt/RequestableChannelClassSpecList>
#include <TelepathyQt/Types>
#include <QLatin1String>
#include <QVariantMap>
#include <QDebug>
ConnectTextChannel::ConnectTextChannel(QObject *connection, Tp::BaseChannel *baseChannel, uint targetHandle, const QString &identifier)
: Tp::BaseChannelTextType(baseChannel),
m_connection(connection),
m_identifier(identifier)
{
QStringList supportedContentTypes = QStringList() << "text/plain";
Tp::UIntList messageTypes = Tp::UIntList() << Tp::ChannelTextMessageTypeNormal;
uint messagePartSupportFlags = 0;
uint deliveryReportingSupport = 0;
m_messagesIface = Tp::BaseChannelMessagesInterface::create(this,
supportedContentTypes,
messageTypes,
messagePartSupportFlags,
deliveryReportingSupport);
baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(m_messagesIface));
m_messagesIface->setSendMessageCallback(Tp::memFun(this, &ConnectTextChannel::sendMessageCallback));
}
ConnectTextChannelPtr ConnectTextChannel::create(QObject *connection, Tp::BaseChannel *baseChannel, uint targetHandle, const QString &identifier)
{
return ConnectTextChannelPtr(new ConnectTextChannel(connection, baseChannel, targetHandle, identifier));
}
ConnectTextChannel::~ConnectTextChannel()
{
}
QString ConnectTextChannel::sendMessageCallback(const Tp::MessagePartList &messageParts, uint flags, Tp::DBusError *error)
{
QString content;
for (Tp::MessagePartList::const_iterator i = messageParts.begin()+1; i != messageParts.end(); ++i) {
if(i->count(QLatin1String("content-type"))
&& i->value(QLatin1String("content-type")).variant().toString() == QLatin1String("text/plain")
&& i->count(QLatin1String("content")))
{
content = i->value(QLatin1String("content")).variant().toString();
break;
}
}
QMetaObject::invokeMethod(m_connection, "messageReceived", Q_ARG(QString, m_identifier), Q_ARG(QString, content));
return QString();
}
/*
Copyright (C) 2014 Alexandr Akulich <akulichalexander@gmail.com>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef CONNECTCM_TEXTCHANNEL_H
#define CONNECTCM_TEXTCHANNEL_H
#include "connectcm_export.h"
#include <TelepathyQt/BaseChannel>
class ConnectTextChannel;
typedef Tp::SharedPtr<ConnectTextChannel> ConnectTextChannelPtr;
class CONNECTCM_EXPORT ConnectTextChannel : public Tp::BaseChannelTextType
{
Q_OBJECT
public:
static ConnectTextChannelPtr create(QObject *connection, Tp::BaseChannel *baseChannel, uint targetHandle, const QString &identifier);
virtual ~ConnectTextChannel();
QString sendMessageCallback(const Tp::MessagePartList &messageParts, uint flags, Tp::DBusError *error);
private:
ConnectTextChannel(QObject *connection, Tp::BaseChannel *baseChannel, uint targetHandle, const QString &identifier);
QObject *m_connection;
QString m_identifier;
Tp::BaseChannelTextTypePtr m_channelTextType;
Tp::BaseChannelMessagesInterfacePtr m_messagesIface;
};
#endif // CONNECTCM_TEXTCHANNEL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment