~renatofilho/messaging-app/fix-1417341-rtm

1 by Tiago Salem Herrmann
initial commit
1
/*
2
 * Copyright (C) 2012-2013 Canonical, Ltd.
3
 *
4
 * Authors:
5
 *  Olivier Tilloy <olivier.tilloy@canonical.com>
6
 *
7
 * This file is part of messaging-app.
8
 *
9
 * messaging-app is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; version 3.
12
 *
13
 * messaging-app is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
// Qt
23
#include <QtCore/QCoreApplication>
24
#include <QtCore/QDir>
25
#include <QtDBus/QDBusConnection>
26
#include <QtDBus/QDBusConnectionInterface>
27
#include <QtDBus/QDBusReply>
28
104.1.2 by Gustavo Pichorim Boiko
Move the path definition to the config file.
29
#define I18N_DIRECTORY "@CMAKE_INSTALL_PREFIX@/share/locale"
30
1 by Tiago Salem Herrmann
initial commit
31
inline bool isRunningInstalled() {
32
    static bool installed = (QCoreApplication::applicationDirPath() ==
33
                             QDir(("@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@")).canonicalPath());
34
    return installed;
35
}
36
37
inline QString messagingAppDirectory() {
38
    if (isRunningInstalled()) {
39
        return QString("@CMAKE_INSTALL_PREFIX@/@MESSAGING_APP_DIR@/");
40
    } else {
41
        return QString("@CMAKE_SOURCE_DIR@/src/qml/");
42
    }
43
}
44
45
inline QString ubuntuPhonePluginPath() {
46
    if (isRunningInstalled()) {
47
        return QString::null;
48
    } else {
49
        return QString("@CMAKE_SOURCE_DIR@/");
50
    }
51
}
52
53
inline bool isMessagingApplicationInstance() {
54
    return QCoreApplication::applicationName() == "MessagingApp";
55
}
56
57
inline bool isMessagingApplicationRunning() {
58
    QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered("com.canonical.MessagingApp");
59
    if (reply.isValid()) {
60
        return reply.value();
61
    }
62
    return false;
63
}