Commit 3d9e43b1 authored by Nicolas Fella's avatar Nicolas Fella Committed by Marco Martin

Refactor dialer code

parent 73af5c54
......@@ -3,9 +3,9 @@ set(plasmaphonedialer_SRCS
dialerutils.cpp
call-handler.cpp
call-manager.cpp
resources.qrc
)
qt5_add_resources(RESOURCES resources.qrc)
add_executable(plasmaphonedialer ${plasmaphonedialer_SRCS} ${RESOURCES})
add_executable(plasmaphonedialer ${plasmaphonedialer_SRCS})
target_compile_definitions(plasmaphonedialer PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
find_package(PhoneNumber COMPONENTS PhoneNumber REQUIRED)
......
......@@ -34,6 +34,7 @@
#include <TelepathyQt/PendingReady>
#include <KLocalizedString>
#include <KLocalizedContext>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QtQml>
......@@ -162,19 +163,15 @@ int main(int argc, char **argv)
qCritical() << "Unable to get SIM account";
return -1;
}
const QString packagePath("org.kde.phone.dialer");
//usually we have an ApplicationWindow here, so we do not need to create a window by ourselves
auto *obj = new KDeclarative::QmlObject();
obj->setTranslationDomain(packagePath);
obj->setInitializationDelayed(true);
obj->setSource(QUrl("qrc:///main.qml"));
obj->engine()->rootContext()->setContextProperty("commandlineArguments", parser.positionalArguments());
QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
auto *dialerUtils = new DialerUtils(simAccount);
obj->engine()->rootContext()->setContextProperty("dialerUtils", QVariant::fromValue(dialerUtils));
engine.rootContext()->setContextProperty("dialerUtils", QVariant::fromValue(dialerUtils));
engine.rootContext()->setContextProperty("commandlineArguments", parser.positionalArguments());
obj->completeInitialization();
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
Tp::SharedPtr<CallHandler> callHandler(new CallHandler(dialerUtils));
registrar->registerClient(Tp::AbstractClientPtr::dynamicCast(callHandler), "Plasma.Dialer");
......@@ -184,39 +181,33 @@ int main(int argc, char **argv)
KAboutData::setApplicationData(aboutData);
//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();
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));
}
});
if (!parser.isSet(daemonOption)) {
window->show();
window->requestActivate();
}
window->setTitle(obj->package().metadata().name());
window->setIcon(QIcon::fromTheme(obj->package().metadata().iconName()));
QWindow *window = qobject_cast<QWindow *>(engine.rootObjects()[0]);
Q_ASSERT(window);
if (!parser.positionalArguments().isEmpty()) {
QString numberArg = parser.positionalArguments().first();
QObject::connect(&service, &KDBusService::activateRequested, [=](const QStringList &arguments, const QString &workingDirectory) {
Q_UNUSED(workingDirectory);
window->show();
window->requestActivate();
if (arguments.length() > 0) {
QString numberArg = arguments[1];
if (numberArg.startsWith("call://")) {
numberArg = numberArg.mid(7);
}
qWarning() << "Calling" << numberArg;
obj->rootObject()->metaObject()->invokeMethod(obj->rootObject(), "call", Q_ARG(QVariant, numberArg));
dialerUtils->dial(numberArg);
}
});
if (!parser.isSet(daemonOption)) {
window->show();
window->requestActivate();
}
if (!parser.positionalArguments().isEmpty()) {
QString numberArg = parser.positionalArguments().first();
if (numberArg.startsWith("call://")) {
numberArg = numberArg.mid(7);
}
} else {
qWarning() << "Error loading the ApplicationWindow";
qWarning() << "Calling" << numberArg;
dialerUtils->dial(numberArg);
}
return app.exec();
......
......@@ -33,6 +33,8 @@ ApplicationWindow {
width: 1080
height: 800
visible: false
//keep track if we were visible when ringing
property bool wasVisible
//was the last call an incoming one?
......
<RCC>
<qresource prefix="/">
<file alias="main.qml">contents/ui/main.qml</file>
<file alias="Call/AnswerSwipe.qml">contents/ui/Call/AnswerSwipe.qml</file>
<file alias="Call/CallPage.qml">contents/ui/Call/CallPage.qml</file>
<file alias="Call/Avatar.qml">contents/ui/Call/Avatar.qml</file>
<file alias="Dialer/Dialer.qml">contents/ui/Dialer/Dialer.qml</file>
<file alias="Dialer/ContactsList.qml">contents/ui/Dialer/ContactsList.qml</file>
<file alias="Dialer/DialPage.qml">contents/ui/Dialer/DialPage.qml</file>
<file alias="Dialer/private/SectionScroller.js">contents/ui/Dialer/private/SectionScroller.js</file>
<file alias="Dialer/RoundImage.qml">contents/ui/Dialer/RoundImage.qml</file>
<file alias="Dialer/History.qml">contents/ui/Dialer/History.qml</file>
<file alias="Dialer/CustomSectionScroller.qml">contents/ui/Dialer/CustomSectionScroller.qml</file>
<file alias="Dialer/HistoryDelegate.qml">contents/ui/Dialer/HistoryDelegate.qml</file>
<file alias="Dialpad/Dialpad.qml">contents/ui/Dialpad/Dialpad.qml</file>
<file alias="Dialpad/PhoneNumberInput.qml">contents/ui/Dialpad/PhoneNumberInput.qml</file>
<file alias="Dialpad/DialerButton.qml">contents/ui/Dialpad/DialerButton.qml</file>
<file alias="Dialpad/DialerIconButton.qml">contents/ui/Dialpad/DialerIconButton.qml</file>
<file alias="main.qml">qml/main.qml</file>
<file alias="Call/AnswerSwipe.qml">qml/Call/AnswerSwipe.qml</file>
<file alias="Call/CallPage.qml">qml/Call/CallPage.qml</file>
<file alias="Call/Avatar.qml">qml/Call/Avatar.qml</file>
<file alias="Dialer/Dialer.qml">qml/Dialer/Dialer.qml</file>
<file alias="Dialer/ContactsList.qml">qml/Dialer/ContactsList.qml</file>
<file alias="Dialer/DialPage.qml">qml/Dialer/DialPage.qml</file>
<file alias="Dialer/private/SectionScroller.js">qml/Dialer/private/SectionScroller.js</file>
<file alias="Dialer/RoundImage.qml">qml/Dialer/RoundImage.qml</file>
<file alias="Dialer/History.qml">qml/Dialer/History.qml</file>
<file alias="Dialer/CustomSectionScroller.qml">qml/Dialer/CustomSectionScroller.qml</file>
<file alias="Dialer/HistoryDelegate.qml">qml/Dialer/HistoryDelegate.qml</file>
<file alias="Dialpad/Dialpad.qml">qml/Dialpad/Dialpad.qml</file>
<file alias="Dialpad/PhoneNumberInput.qml">qml/Dialpad/PhoneNumberInput.qml</file>
<file alias="Dialpad/DialerButton.qml">qml/Dialpad/DialerButton.qml</file>
<file alias="Dialpad/DialerIconButton.qml">qml/Dialpad/DialerIconButton.qml</file>
</qresource>
</RCC>
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