2
* Copyright (C) 2012 Canonical, Ltd.
4
* This file is part of dialer-app.
6
* dialer-app is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* dialer-app is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "dialerapplication.h"
24
#include <QStringList>
26
#include <QQmlComponent>
27
#include <QQmlContext>
29
#include <QDBusInterface>
31
#include <QDBusConnectionInterface>
34
#include "dialerappdbus.h"
37
static void printUsage(const QStringList& arguments)
40
<< arguments.at(0).toUtf8().constData()
41
<< "[call://PHONE_NUMBER]"
44
<< "[--test-contacts]"
49
DialerApplication::DialerApplication(int &argc, char **argv)
50
: QGuiApplication(argc, argv), m_view(0), m_applicationIsReady(false)
52
setApplicationName("DialerApp");
53
m_dbus = new DialerAppDBus(this);
56
bool DialerApplication::setup()
58
static QList<QString> validSchemes;
59
bool fullScreen = false;
60
QString contactEngine = "folks";
62
if (validSchemes.isEmpty()) {
63
validSchemes << "call";
64
validSchemes << "voicemail";
68
QStringList arguments = this->arguments();
70
if (arguments.contains("--help")) {
71
printUsage(arguments);
75
if (arguments.contains("--fullscreen")) {
76
arguments.removeAll("--fullscreen");
80
if (arguments.contains("--test-contacts")) {
81
arguments.removeAll("--test-contacts");
82
contactEngine = "memory";
85
// The testability driver is only loaded by QApplication but not by QGuiApplication.
86
// However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
87
if (arguments.contains("-testability")) {
88
arguments.removeAll("-testability");
89
QLibrary testLib(QLatin1String("qttestability"));
91
typedef void (*TasInitialize)(void);
92
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
96
qCritical("Library qttestability resolve failed!");
99
qCritical("Library qttestability load failed!");
103
/* Ubuntu APP Manager gathers info on the list of running applications from the .desktop
104
file specified on the command line with the desktop_file_hint switch, and will also pass a stage hint
105
So app will be launched like this:
107
/usr/bin/dialer-app --desktop_file_hint=/usr/share/applications/dialer-app.desktop
108
--stage_hint=main_stage
110
So remove whatever --arg still there before continue parsing
112
for (int i = arguments.count() - 1; i >=0; --i) {
113
if (arguments[i].startsWith("--")) {
114
arguments.removeAt(i);
118
if (arguments.size() == 2) {
119
QUrl uri(arguments.at(1));
120
if (validSchemes.contains(uri.scheme())) {
121
m_arg = arguments.at(1);
125
// check if the app is already running, if it is, send the message to the running instance
126
QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered("com.canonical.DialerApp");
127
if (reply.isValid() && reply.value()) {
128
QDBusInterface appInterface("com.canonical.DialerApp",
129
"/com/canonical/DialerApp",
130
"com.canonical.DialerApp");
131
appInterface.call("SendAppMessage", m_arg);
135
if (!m_dbus->connectToBus()) {
136
qWarning() << "Failed to expose com.canonical.DialerApp on DBUS.";
139
m_view = new QQuickView();
140
QObject::connect(m_view, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(onViewStatusChanged(QQuickView::Status)));
141
QObject::connect(m_view->engine(), SIGNAL(quit()), SLOT(quit()));
142
m_view->setResizeMode(QQuickView::SizeRootObjectToView);
143
m_view->setTitle("Dialer");
144
m_view->rootContext()->setContextProperty("application", this);
145
m_view->rootContext()->setContextProperty("contactKey", contactKey);
146
m_view->rootContext()->setContextProperty("dbus", m_dbus);
147
m_view->rootContext()->setContextProperty("contactEngine", contactEngine);
148
m_view->engine()->setBaseUrl(QUrl::fromLocalFile(dialerAppDirectory()));
150
QString pluginPath = ubuntuPhonePluginPath();
151
if (!pluginPath.isNull()) {
152
m_view->engine()->addImportPath(pluginPath);
155
m_view->setSource(QUrl::fromLocalFile("dialer-app.qml"));
157
m_view->showFullScreen();
163
SIGNAL(request(QString)),
164
SLOT(onMessageReceived(QString)));
169
DialerApplication::~DialerApplication()
176
void DialerApplication::onViewStatusChanged(QQuickView::Status status)
178
if (status != QQuickView::Ready) {
182
QQuickItem *mainView = m_view->rootObject();
184
QObject::connect(mainView, SIGNAL(applicationReady()), this, SLOT(onApplicationReady()));
188
void DialerApplication::onApplicationReady()
190
QObject::disconnect(QObject::sender(), SIGNAL(applicationReady()), this, SLOT(onApplicationReady()));
191
m_applicationIsReady = true;
192
parseArgument(m_arg);
196
void DialerApplication::parseArgument(const QString &arg)
202
QStringList args = arg.split("://");
203
if (args.size() != 2) {
207
QString scheme = args[0];
208
QString value = args[1];
210
QQuickItem *mainView = m_view->rootObject();
214
const QMetaObject *mo = mainView->metaObject();
217
if (scheme == "call") {
218
int index = mo->indexOfMethod("callNumber(QVariant)");
220
QMetaMethod method = mo->method(index);
221
method.invoke(mainView, Q_ARG(QVariant, QVariant(value)));
223
} else if (scheme == "voicemail") {
224
int index = mo->indexOfMethod("showVoicemail()");
226
QMetaMethod method = mo->method(index);
227
method.invoke(mainView);
232
void DialerApplication::onMessageReceived(const QString &message)
234
if (m_applicationIsReady) {
235
parseArgument(message);
243
void DialerApplication::activateWindow()
247
m_view->requestActivate();