mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
Add basic Telepathy call handling
This commit is contained in:
parent
75664c118a
commit
cd453ba653
10 changed files with 246 additions and 8 deletions
|
|
@ -27,6 +27,7 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Gui Widgets Qml Quick Te
|
|||
|
||||
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Plasma Service Declarative I18n)
|
||||
find_package(KF5 REQUIRED COMPONENTS PlasmaQuick DBusAddons Notifications)
|
||||
find_package(TelepathyQt5 REQUIRED)
|
||||
find_package(KF5Wayland CONFIG)
|
||||
set_package_properties(KF5Wayland PROPERTIES
|
||||
TYPE REQUIRED
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ kpackage_install_package(package org.kde.phone.dialer genericqml)
|
|||
install(FILES package/metadata.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} RENAME org.kde.phone.dialer.desktop)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(plugin)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ Item {
|
|||
Layout.fillWidth: true
|
||||
text: i18n("End Call")
|
||||
onClicked: {
|
||||
ofonoWrapper.hangup();
|
||||
tpCaller.hangUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import QtQuick.Layouts 1.1
|
|||
import QtQuick.LocalStorage 2.0
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.extras 2.0 as PlasmaExtras
|
||||
import org.kde.plasma.private.tpcaller 1.0
|
||||
|
||||
ApplicationWindow {
|
||||
id: root
|
||||
|
|
@ -58,7 +59,8 @@ ApplicationWindow {
|
|||
|
||||
//BEGIN FUNCTIONS
|
||||
function call(number) {
|
||||
ofonoWrapper.call(number);
|
||||
tpCaller.dial(number);
|
||||
//ofonoWrapper.call(number);
|
||||
}
|
||||
|
||||
function insertCallInHistory(number, duration, callType) {
|
||||
|
|
@ -147,15 +149,19 @@ ApplicationWindow {
|
|||
id: ofonoWrapper
|
||||
}
|
||||
|
||||
TpCaller {
|
||||
id: tpCaller
|
||||
}
|
||||
|
||||
//END MODELS
|
||||
|
||||
//BEGIN UI
|
||||
PlasmaExtras.ConditionalLoader {
|
||||
anchors.fill: parent
|
||||
when: root.visible && ofonoWrapper.status == "idle"
|
||||
when: root.visible && !tpCaller.callInProgress
|
||||
source: Qt.resolvedUrl("Dialer/DialPage.qml")
|
||||
z: ofonoWrapper.status == "idle" ? 2 : 0
|
||||
opacity: ofonoWrapper.status == "idle" ? 1 : 0
|
||||
z: !tpCaller.callInProgress ? 2 : 0
|
||||
opacity: !tpCaller.callInProgress ? 1 : 0
|
||||
Behavior on opacity {
|
||||
OpacityAnimator {
|
||||
duration: units.shortDuration
|
||||
|
|
@ -166,10 +172,10 @@ ApplicationWindow {
|
|||
|
||||
PlasmaExtras.ConditionalLoader {
|
||||
anchors.fill: parent
|
||||
when: ofonoWrapper.status != "idle"
|
||||
when: tpCaller.callInProgress
|
||||
source: Qt.resolvedUrl("Call/CallPage.qml")
|
||||
opacity: ofonoWrapper.status != "idle" ? 1 : 0
|
||||
z: ofonoWrapper.status != "idle" ? 2 : 0
|
||||
opacity: tpCaller.callInProgress ? 1 : 0
|
||||
z: tpCaller.callInProgress ? 2 : 0
|
||||
Behavior on opacity {
|
||||
OpacityAnimator {
|
||||
duration: units.shortDuration
|
||||
|
|
|
|||
15
dialer/plugin/CMakeLists.txt
Normal file
15
dialer/plugin/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
include_directories(${TELEPATHY_QT5_INCLUDE_DIR})
|
||||
|
||||
set(tpcallerplugin_SRCS
|
||||
tp-call-plugin.cpp
|
||||
tp-caller.cpp
|
||||
)
|
||||
|
||||
add_library(tpcallerplugin SHARED ${tpcallerplugin_SRCS})
|
||||
target_link_libraries(tpcallerplugin Qt5::Core
|
||||
Qt5::Qml
|
||||
${TELEPATHY_QT5_LIBRARIES})
|
||||
|
||||
install(TARGETS tpcallerplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/tpcaller)
|
||||
|
||||
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/tpcaller)
|
||||
3
dialer/plugin/qmldir
Normal file
3
dialer/plugin/qmldir
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module org.kde.plasma.private.tpcaller
|
||||
|
||||
plugin tpcallerplugin
|
||||
30
dialer/plugin/tp-call-plugin.cpp
Normal file
30
dialer/plugin/tp-call-plugin.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "tp-call-plugin.h"
|
||||
#include "tp-caller.h"
|
||||
|
||||
#include <QtQml>
|
||||
|
||||
void TpCallPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.tpcaller"));
|
||||
|
||||
qmlRegisterType<TpCaller>(uri, 1, 0, "TpCaller");
|
||||
}
|
||||
|
||||
35
dialer/plugin/tp-call-plugin.h
Normal file
35
dialer/plugin/tp-call-plugin.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TPCALLPLUGIN_H
|
||||
#define TPCALLPLUGIN_H
|
||||
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class QQmlEngine;
|
||||
class TpCallPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri);
|
||||
};
|
||||
|
||||
#endif // TPCALLPLUGIN_H
|
||||
100
dialer/plugin/tp-caller.cpp
Normal file
100
dialer/plugin/tp-caller.cpp
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "tp-caller.h"
|
||||
|
||||
#include <TelepathyQt/Debug>
|
||||
#include <TelepathyQt/Constants>
|
||||
#include <TelepathyQt/ContactMessenger>
|
||||
#include <TelepathyQt/PendingChannel>
|
||||
#include <TelepathyQt/PendingReady>
|
||||
#include <TelepathyQt/PendingContacts>
|
||||
#include <TelepathyQt/TextChannel>
|
||||
#include <TelepathyQt/Types>
|
||||
#include <TelepathyQt/ContactManager>
|
||||
|
||||
TpCaller::TpCaller(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
Tp::registerTypes();
|
||||
Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), Tp::Features() << Tp::Connection::FeatureConnected);
|
||||
|
||||
Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
|
||||
Tp::Features textFeatures = Tp::Features() << Tp::TextChannel::FeatureMessageQueue
|
||||
<< Tp::TextChannel::FeatureMessageSentSignal
|
||||
<< Tp::TextChannel::FeatureChatState
|
||||
<< Tp::TextChannel::FeatureMessageCapabilities;
|
||||
|
||||
channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
|
||||
channelFactory->addFeaturesForTextChats(textFeatures);
|
||||
|
||||
m_simAccount = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME, QStringLiteral("/org/freedesktop/Telepathy/Account/ofono/ofono/account0"), connectionFactory, channelFactory);
|
||||
Tp::PendingReady *op = m_simAccount->becomeReady(Tp::Features() << Tp::Account::FeatureCore);
|
||||
|
||||
qDebug() << "Calling becomeReady on account" << m_simAccount->isValid();
|
||||
|
||||
connect(op, &Tp::PendingOperation::finished, [=](){
|
||||
qDebug() << "account ready";
|
||||
qDebug() << "is error" << op->isError();
|
||||
});
|
||||
}
|
||||
|
||||
void TpCaller::dial(const QString &number)
|
||||
{
|
||||
auto pendingContact = m_simAccount->connection()->contactManager()->contactsForIdentifiers(QStringList() << number);
|
||||
|
||||
connect(pendingContact, &Tp::PendingOperation::finished, [=](){
|
||||
if (pendingContact->contacts().size() < 1) {
|
||||
qWarning() << " no contacts";
|
||||
return;
|
||||
}
|
||||
qDebug() << "Starting call...";
|
||||
Tp::PendingChannel *pendingChannel = m_simAccount->ensureAndHandleAudioCall(pendingContact->contacts().first());
|
||||
connect(pendingChannel, &Tp::PendingChannel::finished, [=](){
|
||||
if (pendingChannel->isError()) {
|
||||
qWarning() << "Error when requesting channel" << pendingChannel->errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
m_callChannel = pendingChannel->channel();
|
||||
Q_EMIT callInProgressChanged();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
bool TpCaller::callInProgress()
|
||||
{
|
||||
return m_callChannel && m_callChannel->isValid() && m_callChannel->connection();
|
||||
}
|
||||
|
||||
|
||||
void TpCaller::hangUp()
|
||||
{
|
||||
qDebug() << "About to hangup" << m_callChannel << m_callChannel->isValid() << m_callChannel->connection();
|
||||
if (m_callChannel && m_callChannel->isValid() && m_callChannel->connection()) {
|
||||
qDebug() << "Hanging up";
|
||||
Tp::PendingOperation *op = m_callChannel->requestClose();
|
||||
connect(op, &Tp::PendingOperation::finished, [=]() {
|
||||
if (op->isError()) {
|
||||
qWarning() << "Unable to hang up:" << op->errorMessage();
|
||||
}
|
||||
qDebug() << "Channel close request complete";
|
||||
Q_EMIT callInProgressChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
47
dialer/plugin/tp-caller.h
Normal file
47
dialer/plugin/tp-caller.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef TPCALLER_H
|
||||
#define TPCALLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <TelepathyQt/Account>
|
||||
#include <TelepathyQt/Channel>
|
||||
|
||||
class TpCaller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool callInProgress READ callInProgress NOTIFY callInProgressChanged);
|
||||
|
||||
public:
|
||||
TpCaller(QObject *parent = 0);
|
||||
Q_INVOKABLE void dial(const QString &number);
|
||||
Q_INVOKABLE void hangUp();
|
||||
|
||||
bool callInProgress();
|
||||
|
||||
Q_SIGNALS:
|
||||
void callInProgressChanged();
|
||||
|
||||
private:
|
||||
Tp::AccountPtr m_simAccount;
|
||||
Tp::ChannelPtr m_callChannel;
|
||||
};
|
||||
|
||||
#endif // TPCALLER_H
|
||||
|
||||
Loading…
Reference in a new issue