Commit 15636c27 authored by Anupam Basak's avatar Anupam Basak

Formatted with clang-format

parent 178dd6b9
......@@ -30,16 +30,16 @@ static inline Tp::AbstractClientHandler::Capabilities capabilities()
{
Tp::AbstractClientHandler::Capabilities caps;
//we support both audio and video in calls
// 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"));
// caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/video"));
//transport methods - farstream supports them all
// 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
// significant codecs
caps.setToken(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String("/video/h264"));
return caps;
......@@ -53,21 +53,20 @@ CallHandler::CallHandler(DialerUtils *utils)
qDebug() << "Call handler ready";
}
CallHandler::~CallHandler()
= default;
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)
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);
......@@ -75,13 +74,13 @@ void CallHandler::handleChannels(const Tp::MethodInvocationContextPtr<> & contex
Q_UNUSED(userActionTime);
Q_UNUSED(handlerInfo);
Q_FOREACH(const Tp::ChannelPtr & channel, channels) {
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
// check if any call manager is already handling this channel
if (!handledCallChannels.contains(callChannel)) {
handledCallChannels.append(callChannel);
new CallManager(callChannel, m_dialerUtils, this);
......
......@@ -29,13 +29,14 @@ public:
~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;
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;
......
......@@ -18,8 +18,8 @@
#include "dialerutils.h"
#include <QTimer>
#include <KNotification>
#include <KLocalizedString>
#include <KNotification>
// #include "call-window.h"
// #include "approver.h"
// #include "../libktpcall/call-channel-handler.h"
......@@ -27,12 +27,11 @@
// #include <KTp/telepathy-handler-application.h>
struct CallManager::Private
{
struct CallManager::Private {
Tp::CallChannelPtr callChannel;
// CallChannelHandler *channelHandler;
// QPointer<CallWindow> callWindow;
// QPointer<Approver> approver;
// CallChannelHandler *channelHandler;
// QPointer<CallWindow> callWindow;
// QPointer<Approver> approver;
DialerUtils *dialerUtils;
KNotification *ringingNotification;
KNotification *callsNotification;
......@@ -41,14 +40,14 @@ struct CallManager::Private
};
CallManager::CallManager(const Tp::CallChannelPtr &callChannel, DialerUtils *dialerUtils, QObject *parent)
: QObject(parent), d(new Private)
: QObject(parent)
, d(new Private)
{
// KTp::TelepathyHandlerApplication::newJob();
// KTp::TelepathyHandlerApplication::newJob();
d->dialerUtils = dialerUtils;
d->callChannel = callChannel;
connect(callChannel.data(), SIGNAL(callStateChanged(Tp::CallState)),
SLOT(onCallStateChanged(Tp::CallState)));
connect(callChannel.data(), SIGNAL(callStateChanged(Tp::CallState)), SLOT(onCallStateChanged(Tp::CallState)));
connect(d->dialerUtils, &DialerUtils::acceptCall, this, &CallManager::onCallAccepted);
connect(d->dialerUtils, &DialerUtils::rejectCall, this, &CallManager::onCallRejected);
......@@ -64,17 +63,17 @@ CallManager::CallManager(const Tp::CallChannelPtr &callChannel, DialerUtils *dia
d->callsNotification = nullptr;
d->callTimer = nullptr;
//create the channel handler
// d->channelHandler = new CallChannelHandler(callChannel, this);
// create the channel handler
// d->channelHandler = new CallChannelHandler(callChannel, this);
//delete the CallManager when the channel has closed
//and the farstream side has safely shut down.
//NOTE this MUST be used with Qt::QueuedConnection because of
// delete the CallManager when the channel has closed
// and the farstream side has safely shut down.
// NOTE this MUST be used with Qt::QueuedConnection because of
// https://bugreports.qt-project.org/browse/QTBUG-24571
// connect(d->channelHandler, SIGNAL(channelClosed()),
// this, SLOT(deleteLater()), Qt::QueuedConnection);
// connect(d->channelHandler, SIGNAL(channelClosed()),
// this, SLOT(deleteLater()), Qt::QueuedConnection);
//bring us up-to-date with the current call state
// bring us up-to-date with the current call state
onCallStateChanged(d->callChannel->callState());
}
......@@ -82,12 +81,12 @@ CallManager::~CallManager()
{
qDebug() << "Deleting CallManager";
//delete the window just in case CallManager was deleted
//before the channel entered CallStateEnded
// delete d->callWindow.data();
// delete d;
// delete the window just in case CallManager was deleted
// before the channel entered CallStateEnded
// delete d->callWindow.data();
// delete d;
// KTp::TelepathyHandlerApplication::jobFinished();
// KTp::TelepathyHandlerApplication::jobFinished();
}
void CallManager::onCallStateChanged(Tp::CallState state)
......@@ -106,15 +105,15 @@ void CallManager::onCallStateChanged(Tp::CallState state)
switch (state) {
case Tp::CallStatePendingInitiator:
Q_ASSERT(d->callChannel->isRequested());
(void) d->callChannel->accept();
(void)d->callChannel->accept();
break;
case Tp::CallStateInitialising:
if (d->callChannel->isRequested()) {
d->dialerUtils->setCallState("dialing");
//show status that the call is conneting
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusConnecting);
// show status that the call is conneting
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusConnecting);
} else {
qDebug() << "Call is initialising";
}
......@@ -122,14 +121,14 @@ void CallManager::onCallStateChanged(Tp::CallState state)
case Tp::CallStateInitialised:
if (d->callChannel->isRequested()) {
d->dialerUtils->setCallState("dialing");
//show status that the remote end is ringing
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusRemoteRinging);
// show status that the remote end is ringing
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusRemoteRinging);
} else {
d->dialerUtils->setCallState("incoming");
//show approver;
(void) d->callChannel->setRinging();
// show approver;
(void)d->callChannel->setRinging();
if (!d->ringingNotification) {
d->ringingNotification = new KNotification("ringing", KNotification::Persistent | KNotification::LoopSound, nullptr);
d->ringingNotification->setComponentName("plasma_dialer");
......@@ -140,25 +139,25 @@ void CallManager::onCallStateChanged(Tp::CallState state)
case Tp::CallStateAccepted:
if (d->callChannel->isRequested()) {
d->dialerUtils->setCallState("answered");
//show status that the remote end accepted the call
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusRemoteAccepted);
// show status that the remote end accepted the call
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusRemoteAccepted);
} else {
//hide approver & show call window
// hide approver & show call window
if (d->ringingNotification) {
d->ringingNotification->close();
}
// delete d->approver.data();
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusConnecting);
// delete d->approver.data();
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusConnecting);
}
break;
case Tp::CallStateActive:
//normally the approver is already deleted and the call window
//already exists at this point, but we just want to be safe
//in case the CM decides to do a weird state jump
// normally the approver is already deleted and the call window
// already exists at this point, but we just want to be safe
// in case the CM decides to do a weird state jump
if (!d->callChannel->isRequested()) {
// delete d->approver.data();
// delete d->approver.data();
}
d->dialerUtils->setCallState("active");
d->callTimer = new QTimer(this);
......@@ -167,15 +166,15 @@ void CallManager::onCallStateChanged(Tp::CallState state)
});
d->callTimer->start(1000);
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusActive);
// ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusActive);
break;
case Tp::CallStateEnded:
d->dialerUtils->setCallState("ended");
if (d->ringingNotification) {
d->ringingNotification->close();
}
//FIXME this is defined in the spec, but try to find a proper enum value for it
// FIXME this is defined in the spec, but try to find a proper enum value for it
if (d->callChannel->callStateReason().reason == 5) {
qDebug() << "Adding notification";
d->missedCalls++;
......@@ -204,24 +203,24 @@ void CallManager::onCallStateChanged(Tp::CallState state)
d->callTimer->deleteLater();
d->callTimer = nullptr;
}
//if we requested the call, make sure we have a window to show the error (if any)
// if (d->callChannel->isRequested()) {
// ensureCallWindow();
// }
// if we requested the call, make sure we have a window to show the error (if any)
// if (d->callChannel->isRequested()) {
// ensureCallWindow();
// }
// if (d->callWindow) {
// Tp::CallStateReason reason = d->callChannel->callStateReason();
// d->callWindow.data()->setStatus(CallWindow::StatusDisconnected, reason);
//
// //kill the call manager when the call window is closed,
// //after shutting down the channelHandler
// connect(d->callWindow.data(), SIGNAL(destroyed()), d->channelHandler, SLOT(shutdown()));
// } else {
// //missed the call
// qCDebug(KTP_CALL_UI) << "missed call";
// delete d->approver.data();
// d->channelHandler->shutdown();
// }
// if (d->callWindow) {
// Tp::CallStateReason reason = d->callChannel->callStateReason();
// d->callWindow.data()->setStatus(CallWindow::StatusDisconnected, reason);
//
// //kill the call manager when the call window is closed,
// //after shutting down the channelHandler
// connect(d->callWindow.data(), SIGNAL(destroyed()), d->channelHandler, SLOT(shutdown()));
// } else {
// //missed the call
// qCDebug(KTP_CALL_UI) << "missed call";
// delete d->approver.data();
// d->channelHandler->shutdown();
// }
break;
default:
Q_ASSERT(false);
......@@ -230,12 +229,12 @@ void CallManager::onCallStateChanged(Tp::CallState state)
void CallManager::onCallAccepted()
{
(void) d->callChannel->accept();
(void)d->callChannel->accept();
}
void CallManager::onCallRejected()
{
(void) d->callChannel->hangup(Tp::CallStateChangeReasonRejected, TP_QT_ERROR_REJECTED);
(void)d->callChannel->hangup(Tp::CallStateChangeReasonRejected, TP_QT_ERROR_REJECTED);
}
void CallManager::onHangUpRequested()
......@@ -247,26 +246,26 @@ void CallManager::onHangUpRequested()
if (op->isError()) {
qWarning() << "Unable to hang up:" << op->errorMessage();
}
// d->callChannel->requestClose();
// d->callChannel->requestClose();
});
}
}
void CallManager::ensureCallWindow()
{
// if (!d->callWindow) {
// d->callWindow = new CallWindow(d->callChannel);
// d->callWindow.data()->show();
// d->callWindow.data()->setAttribute(Qt::WA_DeleteOnClose);
//
// connect(d->channelHandler, SIGNAL(contentAdded(CallContentHandler*)),
// d->callWindow.data(), SLOT(onContentAdded(CallContentHandler*)));
// connect(d->channelHandler, SIGNAL(contentRemoved(CallContentHandler*)),
// d->callWindow.data(), SLOT(onContentRemoved(CallContentHandler*)));
//
// //inform the ui about already existing contents
// Q_FOREACH(CallContentHandler *content, d->channelHandler->contents()) {
// d->callWindow.data()->onContentAdded(content);
// }
// }
// if (!d->callWindow) {
// d->callWindow = new CallWindow(d->callChannel);
// d->callWindow.data()->show();
// d->callWindow.data()->setAttribute(Qt::WA_DeleteOnClose);
//
// connect(d->channelHandler, SIGNAL(contentAdded(CallContentHandler*)),
// d->callWindow.data(), SLOT(onContentAdded(CallContentHandler*)));
// connect(d->channelHandler, SIGNAL(contentRemoved(CallContentHandler*)),
// d->callWindow.data(), SLOT(onContentRemoved(CallContentHandler*)));
//
// //inform the ui about already existing contents
// Q_FOREACH(CallContentHandler *content, d->channelHandler->contents()) {
// d->callWindow.data()->onContentAdded(content);
// }
// }
}
......@@ -20,27 +20,27 @@
#include <QDebug>
#include <TelepathyQt/PendingOperation>
#include <TelepathyQt/PendingChannelRequest>
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/Constants>
#include <TelepathyQt/ContactManager>
#include <TelepathyQt/PendingChannelRequest>
#include <TelepathyQt/PendingContacts>
#include <TelepathyQt/PendingOperation>
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/Types>
#include <TelepathyQt/ContactManager>
#include "phonenumbers/phonenumberutil.h"
#include "phonenumbers/asyoutypeformatter.h"
#include "phonenumbers/phonenumberutil.h"
DialerUtils::DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent)
: QObject(parent),
m_missedCalls(0),
m_simAccount(simAccount),
m_callDuration(0),
m_callContactAlias(QString())
: 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, [=](){
connect(op, &Tp::PendingOperation::finished, [=]() {
if (op->isError()) {
qWarning() << "SIM card account failed to get ready:" << op->errorMessage();
} else {
......@@ -49,22 +49,21 @@ DialerUtils::DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent)
});
}
DialerUtils::~DialerUtils()
= default;
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, [=](){
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, [=](){
connect(pendingChannel, &Tp::PendingChannelRequest::finished, [=]() {
if (pendingChannel->isError()) {
qWarning() << "Error when requesting channel" << pendingChannel->errorMessage();
setCallState("failed");
......@@ -78,7 +77,7 @@ QString DialerUtils::callState() const
return m_callState;
}
const QString DialerUtils::formatNumber(const QString& number)
const QString DialerUtils::formatNumber(const QString &number)
{
using namespace ::i18n::phonenumbers;
......@@ -86,9 +85,9 @@ const QString DialerUtils::formatNumber(const QString& number)
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);
const char *country = countrycode.toUtf8().constData();
PhoneNumberUtil *util = PhoneNumberUtil::GetInstance();
AsYouTypeFormatter *formatter = util->PhoneNumberUtil::GetAsYouTypeFormatter(country);
// Normalize input
string stdnumber = number.toUtf8().constData();
......@@ -97,7 +96,7 @@ const QString DialerUtils::formatNumber(const QString& number)
// Format
string formatted;
formatter->Clear();
for (char& c : stdnumber) {
for (char &c : stdnumber) {
formatter->InputDigit(c, &formatted);
}
delete formatter;
......
......@@ -19,9 +19,9 @@
#ifndef DIALERUTILS_H
#define DIALERUTILS_H
#include <KNotification>
#include <QObject>
#include <QPointer>
#include <KNotification>
#include <TelepathyQt/Account>
......@@ -35,7 +35,6 @@ class DialerUtils : public QObject
Q_PROPERTY(bool isIncomingCall READ isIncomingCall NOTIFY isIncomingCallChanged);
public:
DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent = nullptr);
~DialerUtils() override;
......@@ -58,7 +57,7 @@ public:
Q_INVOKABLE void resetMissedCalls();
Q_INVOKABLE void dial(const QString &number);
Q_INVOKABLE const QString formatNumber(const QString& number);
Q_INVOKABLE const QString formatNumber(const QString &number);
Q_SIGNALS:
void missedCallsActionTriggered();
......@@ -73,8 +72,8 @@ Q_SIGNALS:
void callEnded(const QString &callContactNumber, uint callDuration, bool isIncomingCall);
private:
QPointer <KNotification> m_callsNotification;
QPointer <KNotification> m_ringingNotification;
QPointer<KNotification> m_callsNotification;
QPointer<KNotification> m_ringingNotification;
int m_missedCalls;
QString m_callState;
Tp::AccountPtr m_simAccount;
......@@ -84,5 +83,4 @@ private:
bool m_isIncomingCall;
};
#endif
......@@ -19,34 +19,33 @@
#include <QApplication>
#include "dialerutils.h"
#include "call-handler.h"
#include "dialerutils.h"
#include <TelepathyQt/Types>
#include <TelepathyQt/Debug>
#include <TelepathyQt/ClientRegistrar>
#include <TelepathyQt/Account>
#include <TelepathyQt/CallChannel>
#include <TelepathyQt/ChannelClassSpec>
#include <TelepathyQt/ChannelFactory>
#include <TelepathyQt/Account>
#include <TelepathyQt/ClientRegistrar>
#include <TelepathyQt/Debug>
#include <TelepathyQt/Types>
#include <klocalizedstring.h>
#include <qcommandlineparser.h>
#include <qcommandlineoption.h>
#include <QQuickItem>
#include <QtQml>
#include <klocalizedstring.h>
#include <qcommandlineoption.h>
#include <qcommandlineparser.h>
#include <kpackage/package.h>
#include <kpackage/packageloader.h>
#include <KAboutData>
#include <KDBusService>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlExpression>
#include <QQmlProperty>
#include <QQuickWindow>
#include <kdeclarative/qmlobject.h>
#include <KAboutData>
#include <KDBusService>
#include <kpackage/package.h>
#include <kpackage/packageloader.h>
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
......@@ -61,11 +60,21 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
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;
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';
......@@ -90,7 +99,7 @@ int main(int argc, char **argv)
const QString description = i18n("Plasma Phone Dialer");
const char version[] = PROJECT_VERSION;
// app.setQuitOnLastWindowClosed(false);
// app.setQuitOnLastWindowClosed(false);
app.setApplicationVersion(version);
app.setOrganizationDomain("kde.org");
......@@ -100,9 +109,7 @@ int main(int argc, char **argv)
parser.addHelpOption();
parser.setApplicationDescription(description);
QCommandLineOption daemonOption(QStringList() << QStringLiteral("d") <<
QStringLiteral("daemon"),
i18n("Daemon mode. run without displaying anything."));
QCommandLineOption daemonOption(QStringList() << QStringLiteral("d") << QStringLiteral("daemon"), i18n("Daemon mode. run without displaying anything."));
parser.addPositionalArgument("number", i18n("Call the given number"));
......@@ -112,43 +119,28 @@ int main(int argc, char **argv)
Tp::registerTypes();
Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
Tp::Features() << Tp::Account::FeatureCore
);
Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(), Tp::Features() << Tp::Account::FeatureCore);
Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
Tp::Features() << Tp::Connection::FeatureCore
<< Tp::Connection::FeatureSelfContact
<< Tp::Connection::FeatureConnected
);
Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), Tp::Features() << Tp::Connection::FeatureCore << Tp::Connection::FeatureSelfContact << Tp::Connection::FeatureConnected);
Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());