2015-04-21 10:12:10 +00:00
|
|
|
/*
|
|
|
|
|
* 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>
|
|
|
|
|
|
2015-04-26 13:50:59 +00:00
|
|
|
#include "dialerutils.h"
|
2015-06-18 21:25:59 +00:00
|
|
|
#include "call-handler.h"
|
|
|
|
|
|
|
|
|
|
#include <TelepathyQt/Types>
|
|
|
|
|
#include <TelepathyQt/Debug>
|
|
|
|
|
#include <TelepathyQt/ClientRegistrar>
|
|
|
|
|
#include <TelepathyQt/CallChannel>
|
|
|
|
|
#include <TelepathyQt/ChannelClassSpec>
|
|
|
|
|
#include <TelepathyQt/ChannelFactory>
|
2015-06-18 23:27:20 +00:00
|
|
|
#include <TelepathyQt/Account>
|
2015-04-26 13:50:59 +00:00
|
|
|
|
2015-04-21 10:12:10 +00:00
|
|
|
#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>
|
|
|
|
|
|
2015-06-19 15:55:21 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
// TODO: print it on stdout too?
|
|
|
|
|
QFile file("/home/phablet/dialer.log");
|
|
|
|
|
|
|
|
|
|
bool opened = file.open(QIODevice::WriteOnly | QIODevice::Append);
|
|
|
|
|
Q_ASSERT(opened);
|
|
|
|
|
|
|
|
|
|
QTextStream out(&file);
|
|
|
|
|
out << QTime::currentTime().toString("hh:mm:ss.zzz ");
|
|
|
|
|
out << context.function << ":" << context.line << " ";
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case QtDebugMsg: out << "DBG"; break;
|
|
|
|
|
case QtWarningMsg: out << "WRN"; break;
|
|
|
|
|
case QtCriticalMsg: out << "CRT"; break;
|
|
|
|
|
case QtFatalMsg: out << "FTL"; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out << " " << msg << '\n';
|
|
|
|
|
out.flush();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 10:12:10 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2015-06-19 15:55:21 +00:00
|
|
|
qInstallMessageHandler(myMessageOutput);
|
2015-04-21 10:12:10 +00:00
|
|
|
QCommandLineParser parser;
|
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
|
|
app.setQuitOnLastWindowClosed(false);
|
|
|
|
|
KDBusService service(KDBusService::Unique);
|
|
|
|
|
|
|
|
|
|
const QString description = i18n("Plasma Phone Dialer");
|
|
|
|
|
const char version[] = PROJECT_VERSION;
|
|
|
|
|
|
|
|
|
|
app.setApplicationVersion(version);
|
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
|
parser.setApplicationDescription(description);
|
|
|
|
|
|
2015-04-29 08:39:40 +00:00
|
|
|
QCommandLineOption daemonOption(QStringList() << QStringLiteral("d") <<
|
|
|
|
|
QStringLiteral("daemon"),
|
|
|
|
|
i18n("Daemon mode. run without displaying anything."));
|
|
|
|
|
|
2015-05-05 17:29:48 +00:00
|
|
|
parser.addPositionalArgument("number", i18n("Call the given number"));
|
|
|
|
|
|
2015-04-21 10:12:10 +00:00
|
|
|
parser.addOption(daemonOption);
|
|
|
|
|
|
|
|
|
|
parser.process(app);
|
|
|
|
|
|
2015-06-18 23:24:46 +00:00
|
|
|
Tp::registerTypes();
|
|
|
|
|
|
|
|
|
|
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::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
|
|
|
|
|
channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
|
|
|
|
|
channelFactory->addFeaturesForCalls(Tp::Features() << Tp::CallChannel::FeatureContents
|
|
|
|
|
<< Tp::CallChannel::FeatureCallState
|
|
|
|
|
<< Tp::CallChannel::FeatureCallMembers
|
|
|
|
|
<< Tp::CallChannel::FeatureLocalHoldState
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// channelFactory->addFeaturesForTextChats(Tp::Features() << Tp::TextChannel::FeatureMessageQueue
|
|
|
|
|
// << Tp::TextChannel::FeatureMessageSentSignal
|
|
|
|
|
// << Tp::TextChannel::FeatureChatState
|
|
|
|
|
// << Tp::TextChannel::FeatureMessageCapabilities);
|
|
|
|
|
|
|
|
|
|
Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias
|
|
|
|
|
<< Tp::Contact::FeatureAvatarData
|
|
|
|
|
);
|
|
|
|
|
|
2015-06-19 15:55:47 +00:00
|
|
|
Tp::ClientRegistrarPtr registrar = Tp::ClientRegistrar::create(accountFactory, connectionFactory,
|
|
|
|
|
channelFactory, contactFactory);
|
2015-06-18 23:24:46 +00:00
|
|
|
|
|
|
|
|
Tp::AccountPtr simAccount = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME, QStringLiteral("/org/freedesktop/Telepathy/Account/ofono/ofono/account0"),
|
|
|
|
|
connectionFactory, channelFactory);
|
|
|
|
|
|
|
|
|
|
|
2015-04-21 10:12:10 +00:00
|
|
|
const QString packagePath("org.kde.phone.dialer");
|
|
|
|
|
|
|
|
|
|
//usually we have an ApplicationWindow here, so we do not need to create a window by ourselves
|
|
|
|
|
KDeclarative::QmlObject *obj = new KDeclarative::QmlObject();
|
|
|
|
|
obj->setTranslationDomain(packagePath);
|
|
|
|
|
obj->setInitializationDelayed(true);
|
|
|
|
|
obj->loadPackage(packagePath);
|
|
|
|
|
obj->engine()->rootContext()->setContextProperty("commandlineArguments", parser.positionalArguments());
|
|
|
|
|
|
2015-06-18 23:24:46 +00:00
|
|
|
DialerUtils *dialerUtils = new DialerUtils(simAccount);
|
2015-04-26 13:50:59 +00:00
|
|
|
obj->engine()->rootContext()->setContextProperty("dialerUtils", QVariant::fromValue(dialerUtils));
|
|
|
|
|
|
2015-04-21 10:12:10 +00:00
|
|
|
obj->completeInitialization();
|
|
|
|
|
|
|
|
|
|
if (!obj->package().metadata().isValid()) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 23:24:46 +00:00
|
|
|
Tp::SharedPtr<CallHandler> callHandler(new CallHandler(dialerUtils));
|
|
|
|
|
registrar->registerClient(Tp::AbstractClientPtr::dynamicCast(callHandler), "Phone.Dialer");
|
|
|
|
|
|
2015-04-21 10:12:10 +00:00
|
|
|
KPluginMetaData data = obj->package().metadata();
|
|
|
|
|
// About data
|
|
|
|
|
KAboutData aboutData(data.pluginId(), data.name(), data.version(), data.description(), KAboutLicense::byKeyword(data.license()).key());
|
|
|
|
|
|
|
|
|
|
for (auto author : data.authors()) {
|
|
|
|
|
aboutData.addAuthor(author.name(), author.task(), author.emailAddress(), author.webAddress(), author.ocsUsername());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//The root is not a window?
|
|
|
|
|
//have to use a normal QQuickWindow since the root item is already created
|
|
|
|
|
QWindow *window = qobject_cast<QWindow *>(obj->rootObject());
|
|
|
|
|
if (window) {
|
|
|
|
|
QObject::connect(&service, &KDBusService::activateRequested, [=](const QStringList &arguments, const QString &workingDirectory) {
|
|
|
|
|
Q_UNUSED(workingDirectory);
|
|
|
|
|
window->show();
|
|
|
|
|
window->requestActivate();
|
2015-05-05 17:38:31 +00:00
|
|
|
if (arguments.length() > 0) {
|
|
|
|
|
QString numberArg = arguments[1];
|
|
|
|
|
if (numberArg.startsWith("call://")) {
|
|
|
|
|
numberArg = numberArg.mid(7);
|
|
|
|
|
}
|
|
|
|
|
obj->rootObject()->metaObject()->invokeMethod(obj->rootObject(), "call", Q_ARG(QVariant, numberArg));
|
|
|
|
|
}
|
2015-04-21 10:12:10 +00:00
|
|
|
});
|
|
|
|
|
if (!parser.isSet(daemonOption)) {
|
|
|
|
|
window->show();
|
|
|
|
|
window->requestActivate();
|
|
|
|
|
}
|
|
|
|
|
window->setTitle(obj->package().metadata().name());
|
|
|
|
|
window->setIcon(QIcon::fromTheme(obj->package().metadata().iconName()));
|
2015-04-29 08:39:40 +00:00
|
|
|
|
2015-05-05 17:29:48 +00:00
|
|
|
if (!parser.positionalArguments().isEmpty()) {
|
|
|
|
|
QString numberArg = parser.positionalArguments().first();
|
|
|
|
|
if (numberArg.startsWith("call://")) {
|
|
|
|
|
numberArg = numberArg.mid(7);
|
|
|
|
|
}
|
|
|
|
|
qWarning() << "Calling" << numberArg;
|
|
|
|
|
obj->rootObject()->metaObject()->invokeMethod(obj->rootObject(), "call", Q_ARG(QVariant, numberArg));
|
2015-04-29 08:39:40 +00:00
|
|
|
}
|
2015-04-21 10:12:10 +00:00
|
|
|
} else {
|
|
|
|
|
qWarning() << "Error loading the ApplicationWindow";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|