Commit c998e969 authored by Camilo higuita's avatar Camilo higuita

add dialer backend for testing on plasmo

parent 4d3ee728
......@@ -56,7 +56,7 @@ set(union_ASSETS
assets/union_assets.qrc
)
add_executable(union
add_executable(${PROJECT_NAME}
${union_SRCS}
${union_HDRS}
${union_ASSETS}
......@@ -65,22 +65,24 @@ add_executable(union
if (ANDROID)
find_package(Qt5 REQUIRED COMPONENTS AndroidExtras)
target_link_libraries(vvave Qt5::AndroidExtras)
target_link_libraries(${PROJECT_NAME} Qt5::AndroidExtras)
# kde_source_files_enable_exceptions(union src/pix.cpp)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
add_subdirectory(src/dialer/linux)
else()
find_package(KF5 ${KF5_VERSION} REQUIRED COMPONENTS I18n Notifications Config KIO Attica Contacts People )
find_package(Qt5 REQUIRED COMPONENTS WebEngine)
target_link_libraries(union KF5::ConfigCore KF5::Notifications KF5::KIOCore KF5::I18n KF5::Attica KF5::Contacts KF5::People )
target_link_libraries(${PROJECT_NAME} KF5::ConfigCore KF5::Notifications KF5::KIOCore KF5::I18n KF5::Attica KF5::Contacts KF5::People )
endif()
if (TARGET create-apk-union)
set_target_properties(create-apk-union PROPERTIES ANDROID_APK_DIR "${MAUIKIT_ANDROID_DIR}")
endif()
target_link_libraries(union MauiKit Qt5::Sql Qt5::Qml Qt5::Widgets Qt5::Svg Qt5::Concurrent)
target_link_libraries(${PROJECT_NAME} MauiKit Qt5::Sql Qt5::Qml Qt5::Widgets Qt5::Svg Qt5::Concurrent)
install(TARGETS union ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES org.kde.communicator.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
#TODO: port to ecm_install_icons()
......
set(dialer_SRCS
main.cpp
dialerutils.cpp
call-handler.cpp
call-manager.cpp
)
add_executable(${PROJECT_NAME} ${dialer_SRCS})
target_compile_definitions(${PROJECT_NAME} PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
#find_package(ActiveApp REQUIRED)
find_package(PhoneNumber COMPONENTS PhoneNumber REQUIRED)
target_link_libraries(${PROJECT_NAME}
PhoneNumber::PhoneNumber
Qt5::Gui
Qt5::Quick
Qt5::Widgets
KF5::Declarative
KF5::I18n
KF5::Package
KF5::QuickAddons
KF5::DBusAddons
KF5::Notifications
${TELEPATHY_QT5_LIBRARIES}
)
install(TARGETS ${PROJECT_NAME} ${INSTALL_TARGETS_DEFAULT_ARGS})
#install(FILES plasma_dialer.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR})
#configure_file(org.freedesktop.Telepathy.Client.Plasma.Dialer.service.in
# org.freedesktop.Telepathy.Client.Plasma.Dialer.service)
#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.Plasma.Dialer.service
# DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
#install(FILES Plasma.Dialer.client DESTINATION ${SHARE_INSTALL_PREFIX}/telepathy/clients/)
#elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
# add_subdirectory(src/dialer/linux)
# target_link_libraries(${PROJECT_NAME}
# PhoneNumber::PhoneNumber
# Qt5::Gui
# Qt5::Quick
# ${TELEPATHY_QT5_LIBRARIES}
# KF5::Declarative
# KF5::Package
# KF5::QuickAddons
# KF5::DBusAddons)
[org.freedesktop.Telepathy.Client]
Interfaces=org.freedesktop.Telepathy.Client.Handler
[org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 0]
org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Call1
org.freedesktop.Telepathy.Channel.TargetHandleType u=1
[org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 1]
org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Call1
org.freedesktop.Telepathy.Channel.TargetHandleType u=1
org.freedesktop.Telepathy.Channel.Type.Call1.InitialAudio b=true
[org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 2]
org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Call1
org.freedesktop.Telepathy.Channel.TargetHandleType u=1
org.freedesktop.Telepathy.Channel.Type.Call1.InitialVideo b=true
[org.freedesktop.Telepathy.Client.Handler]
BypassApproval=true
[org.freedesktop.Telepathy.Client.Handler.Capabilities]
org.freedesktop.Telepathy.Channel.Type.Call1/audio=true
org.freedesktop.Telepathy.Channel.Type.Call1/video=false
org.freedesktop.Telepathy.Channel.Type.Call1/ice=true
org.freedesktop.Telepathy.Channel.Type.Call1/gtalk-p2p=false
org.freedesktop.Telepathy.Channel.Type.Call1/shm=true
org.freedesktop.Telepathy.Channel.Type.Call1/video/h264=false
/*
Copyright (C) 2009-2012 George Kiagiadakis <kiagiadakis.george@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "call-handler.h"
#include "call-manager.h"
#include "dialerutils.h"
#include <TelepathyQt/CallChannel>
#include <TelepathyQt/ChannelClassSpec>
static inline Tp::ChannelClassSpecList channelClassSpecList()
{
return Tp::ChannelClassSpecList() << Tp::ChannelClassSpec::audioCall();
}
static inline Tp::AbstractClientHandler::Capabilities capabilities()
{
Tp::AbstractClientHandler::Capabilities caps;
//we support both audio and video in calls
caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/audio"));
// caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/video"));
//transport methods - farstream supports them all
caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/ice"));
caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/gtalk-p2p"));
caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/shm"));
//significant codecs
caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/video/h264"));
return caps;
}
CallHandler::CallHandler(DialerUtils *utils)
: Tp::AbstractClientHandler(channelClassSpecList(), capabilities())
{
m_dialerUtils = utils;
m_dialerUtils->setCallState("idle");
qDebug() << "Call handler ready";
}
CallHandler::~CallHandler()
= default;
bool CallHandler::bypassApproval() const
{
return true;
}
void CallHandler::handleChannels(const Tp::MethodInvocationContextPtr<> & context,
const Tp::AccountPtr & account,
const Tp::ConnectionPtr & connection,
const QList<Tp::ChannelPtr> & channels,
const QList<Tp::ChannelRequestPtr> & requestsSatisfied,
const QDateTime & userActionTime,
const Tp::AbstractClientHandler::HandlerInfo & handlerInfo)
{
Q_UNUSED(account);
Q_UNUSED(connection);
Q_UNUSED(requestsSatisfied);
Q_UNUSED(userActionTime);
Q_UNUSED(handlerInfo);
Q_FOREACH(const Tp::ChannelPtr & channel, channels) {
Tp::CallChannelPtr callChannel = Tp::CallChannelPtr::qObjectCast(channel);
if (!callChannel) {
qDebug() << "Channel is not a Call channel. Ignoring";
continue;
}
//check if any call manager is already handling this channel
if (!handledCallChannels.contains(callChannel)) {
handledCallChannels.append(callChannel);
new CallManager(callChannel, m_dialerUtils, this);
}
}
context->setFinished();
}
/*
Copyright (C) 2009 George Kiagiadakis <kiagiadakis.george@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CALL_HANDLER_H
#define CALL_HANDLER_H
#include <TelepathyQt/AbstractClientHandler>
class DialerUtils;
class CallHandler : public QObject, public Tp::AbstractClientHandler
{
Q_OBJECT
public:
CallHandler(DialerUtils *utils);
~CallHandler() override;
bool bypassApproval() const override;
void handleChannels(const Tp::MethodInvocationContextPtr<> & context,
const Tp::AccountPtr & account,
const Tp::ConnectionPtr & connection,
const QList<Tp::ChannelPtr> & channels,
const QList<Tp::ChannelRequestPtr> & requestsSatisfied,
const QDateTime & userActionTime,
const Tp::AbstractClientHandler::HandlerInfo & handlerInfo) override;
private:
QList<Tp::CallChannelPtr> handledCallChannels;
DialerUtils *m_dialerUtils;
};
#endif
This diff is collapsed.
/*
Copyright (C) 2012 George Kiagiadakis <kiagiadakis.george@gmail.com>
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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CALL_MANAGER_H
#define CALL_MANAGER_H
#include <QObject>
#include <TelepathyQt/CallChannel>
class DialerUtils;
class CallManager : public QObject
{
Q_OBJECT
public:
explicit CallManager(const Tp::CallChannelPtr &callChannel, DialerUtils *dialerUtils, QObject *parent = nullptr);
~CallManager() override;
private Q_SLOTS:
void onCallStateChanged(Tp::CallState state);
void onCallAccepted();
void onCallRejected();
void onHangUpRequested();
private:
void ensureCallWindow();
private:
struct Private;
Private *const d;
};
#endif // CALL_MANAGER_H
/*
* Copyright 2015 Marco Martin <mart@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 "dialerutils.h"
#include <QDebug>
#include <TelepathyQt/PendingOperation>
#include <TelepathyQt/PendingChannelRequest>
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/Constants>
#include <TelepathyQt/PendingContacts>
#include <TelepathyQt/Types>
#include <TelepathyQt/ContactManager>
#include "phonenumbers/phonenumberutil.h"
#include "phonenumbers/asyoutypeformatter.h"
DialerUtils::DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent)
: QObject(parent),
m_missedCalls(0),
m_simAccount(simAccount),
m_callDuration(0),
m_callContactAlias(QString())
{
Tp::PendingReady *op = m_simAccount->becomeReady(Tp::Features() << Tp::Account::FeatureCore);
connect(op, &Tp::PendingOperation::finished, [=](){
if (op->isError()) {
qWarning() << "SIM card account failed to get ready:" << op->errorMessage();
} else {
qDebug() << "SIM Account ready to use";
}
});
}
DialerUtils::~DialerUtils()
= default;
void DialerUtils::dial(const QString &number)
{
// FIXME: this should be replaced by kpeople thing
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::PendingChannelRequest *pendingChannel = m_simAccount->ensureAudioCall(pendingContact->contacts().first());
connect(pendingChannel, &Tp::PendingChannelRequest::finished, [=](){
if (pendingChannel->isError()) {
qWarning() << "Error when requesting channel" << pendingChannel->errorMessage();
setCallState("failed");
}
});
});
}
QString DialerUtils::callState() const
{
return m_callState;
}
const QString DialerUtils::formatNumber(const QString& number)
{
using namespace ::i18n::phonenumbers;
// Get formatter instance
QLocale locale;
QStringList qcountry = locale.name().split('_');
QString countrycode(qcountry.constLast());
const char* country = countrycode.toUtf8().constData();
PhoneNumberUtil* util = PhoneNumberUtil::GetInstance();
AsYouTypeFormatter* formatter = util->PhoneNumberUtil::GetAsYouTypeFormatter(country);
// Normalize input
string stdnumber = number.toUtf8().constData();
util->NormalizeDiallableCharsOnly(&stdnumber);
// Format
string formatted;
formatter->Clear();
for (char& c : stdnumber) {
formatter->InputDigit(c, &formatted);
}
delete formatter;
return QString::fromStdString(formatted);
}
void DialerUtils::setCallState(const QString &state)
{
if (m_callState != state) {
m_callState = state;
Q_EMIT callStateChanged();
}
}
uint DialerUtils::callDuration() const
{
return m_callDuration;
}
void DialerUtils::setCallDuration(uint duration)
{
m_callDuration = duration;
Q_EMIT callDurationChanged();
}
QString DialerUtils::callContactAlias() const
{
return m_callContactAlias;
}
void DialerUtils::setCallContactAlias(const QString &contactAlias)
{
if (m_callContactAlias != contactAlias) {
m_callContactAlias = contactAlias;
Q_EMIT callContactAliasChanged();
}
}
QString DialerUtils::callContactNumber() const
{
return m_callContactNumber;
}
void DialerUtils::setCallContactNumber(const QString &contactNumber)
{
if (m_callContactNumber != contactNumber) {
m_callContactNumber = contactNumber;
Q_EMIT callContactNumberChanged();
}
}
bool DialerUtils::isIncomingCall() const
{
return m_isIncomingCall;
}
void DialerUtils::setIsIncomingCall(bool isIncomingCall)
{
if (m_isIncomingCall != isIncomingCall) {
m_isIncomingCall = isIncomingCall;
Q_EMIT isIncomingCallChanged();
}
}
void DialerUtils::emitCallEnded()
{
qDebug() << "Call ended:" << m_callContactNumber << m_callDuration;
Q_EMIT callEnded(m_callContactNumber, m_callDuration, m_isIncomingCall);
m_callDuration = 0;
m_callContactNumber = QString();
m_callContactAlias = QString();
}
void DialerUtils::resetMissedCalls()
{
m_missedCalls = 0;
if (m_callsNotification) {
m_callsNotification->close();
}
m_callsNotification.clear();
}
#include "moc_dialerutils.cpp"
/*
* Copyright 2015 Marco Martin <mart@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 DIALERUTILS_H
#define DIALERUTILS_H
#include <QObject>
#include <QPointer>
#include <KNotification>
#include <TelepathyQt/Account>
class DialerUtils : public QObject
{
Q_OBJECT
Q_PROPERTY(QString callState READ callState NOTIFY callStateChanged);
Q_PROPERTY(uint callDuration READ callDuration NOTIFY callDurationChanged);
Q_PROPERTY(QString callContactAlias READ callContactAlias NOTIFY callContactAliasChanged);
Q_PROPERTY(QString callContactNumber READ callContactNumber NOTIFY callContactNumberChanged);
Q_PROPERTY(bool isIncomingCall READ isIncomingCall NOTIFY isIncomingCallChanged);
public:
DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent = nullptr);
~DialerUtils() override;
QString callState() const;
void setCallState(const QString &state);
uint callDuration() const;
void setCallDuration(uint duration);
QString callContactAlias() const;
void setCallContactAlias(const QString &contactAlias);
QString callContactNumber() const;
void setCallContactNumber(const QString &contactNumber);
bool isIncomingCall() const;
void setIsIncomingCall(bool isIncomingCall);
void emitCallEnded();
Q_INVOKABLE void resetMissedCalls();
Q_INVOKABLE void dial(const QString &number);
Q_INVOKABLE const QString formatNumber(const QString& number);
Q_SIGNALS:
void missedCallsActionTriggered();
void callStateChanged();
void callDurationChanged();
void callContactAliasChanged();
void callContactNumberChanged();
void isIncomingCallChanged();
void acceptCall();
void rejectCall();
void hangUp();
void callEnded(const QString &callContactNumber, uint callDuration, bool isIncomingCall);
private:
QPointer <KNotification> m_callsNotification;
QPointer <KNotification> m_ringingNotification;
int m_missedCalls;
QString m_callState;
Tp::AccountPtr m_simAccount;
QString m_callContactNumber;
uint m_callDuration;
QString m_callContactAlias;
bool m_isIncomingCall;
};
#endif
/*
* Copyright 2015 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program 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 General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QApplication>
#include "dialerutils.h"
#include "call-handler.h"
#include <TelepathyQt/Types>
#include <TelepathyQt/Debug>
#include <TelepathyQt/ClientRegistrar>
#include <TelepathyQt/CallChannel>
#include <TelepathyQt/ChannelClassSpec>
#include <TelepathyQt/ChannelFactory>
#include <TelepathyQt/Account>
#include <klocalizedstring.h>
#include <qcommandlineparser.h>
#include <qcommandlineoption.h>
#include <QQuickItem>
#include <QtQml>
#include <kpackage/package.h>
#include <kpackage/packageloader.h>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlExpression>
#include <QQmlProperty>
#include <QQuickWindow>
#include <kdeclarative/qmlobject.h>
#include <KAboutData>
#include <KDBusService>
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QFile file(QDir::homePath() + "/dialer.log");
bool opened = file.open(QIODevice::WriteOnly | QIODevice::Append);
Q_ASSERT(opened);
QString strout;
QTextStream out(&strout);
out << QTime::currentTime().toString("hh:mm:ss.zzz ");
out << context.function << ":" << context.line << " ";
switch (type) {
case QtDebugMsg: out << "DBG"; break;
case QtInfoMsg: out << "NFO"; break;
case QtWarningMsg: out << "WRN"; break;
case QtCriticalMsg: out << "CRT"; break;
case QtFatalMsg: out << "FTL"; break;
}
out << " " << msg << '\n';
// Write to log file
QTextStream fileout(&file);
fileout << strout;
out.flush();
// Write to stdout
QTextStream console(stdout);
console << strout;
console.flush();
}
int main(int argc, char **argv)
{
qInstallMessageHandler(myMessageOutput);
QCommandLineParser parser;
QApplication app(argc, argv);
const QString description = i18n("Plasma Phone Dialer");
const char version[] = PROJECT_VERSION;
// app.setQuitOnLastWindowClosed(false);
app.setApplicationVersion(version);
app.setOrganizationDomain("kde.org");
KDBusService service(KDBusService::Unique);
parser.addVersionOption();
parser.addHelpOption();
parser.setApplicationDescription(description);
QCommandLineOption daemonOption(QStringList() << QStringLiteral("d") <<
QStringLiteral("daemon"),
i18n("Daemon mode. run without displaying anything."));
parser.addPositionalArgument("number", i18n("Call the given number"));
parser.addOption(daemonOption);
parser.process(app);