maemoglobal.h 7.18 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
30
31
32
33
34
35
**
**************************************************************************/

#ifndef MAEMOGLOBAL_H
#define MAEMOGLOBAL_H

36
#include "linuxdeviceconfiguration.h"
37

38
#include <coreplugin/ifile.h>
39
40
#include <utils/environment.h>

41
#include <projectexplorer/buildstep.h>
Tobias Hunger's avatar
Tobias Hunger committed
42
#include <projectexplorer/buildsteplist.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
43
#include <projectexplorer/deployconfiguration.h>
44

ck's avatar
ck committed
45
#include <QtCore/QList>
46
#include <QtCore/QSharedPointer>
Friedemann Kleint's avatar
Friedemann Kleint committed
47
#include <QtCore/QCoreApplication>
ck's avatar
ck committed
48

49
50
51
#define ASSERT_STATE_GENERIC(State, expected, actual)                         \
    MaemoGlobal::assertState<State>(expected, actual, Q_FUNC_INFO)

52
QT_BEGIN_NAMESPACE
53
class QDateTime;
54
class QProcess;
55
56
57
class QString;
QT_END_NAMESPACE

58
namespace QtSupport { class BaseQtVersion; }
59
namespace Utils { class SshConnection; }
60
61

namespace RemoteLinux {
62
63
namespace Internal {

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class WatchableFile : public Core::IFile
{
    Q_OBJECT
public:
    WatchableFile(const QString &fileName, QObject *parent = 0)
        : Core::IFile(parent), m_fileName(fileName) {}

    bool save(QString *, const QString &, bool) { return false; }
    QString fileName() const { return m_fileName; }
    QString defaultPath() const { return QString(); }
    QString suggestedFileName() const { return QString(); }
    QString mimeType() const { return QLatin1String("text/plain"); }
    bool isModified() const { return false; }
    bool isReadOnly() const { return false; }
    bool isSaveAsAllowed() const { return false; }
    ReloadBehavior reloadBehavior(ChangeTrigger, ChangeType) const { return BehaviorSilent; }
    bool reload(QString *, ReloadFlag, ChangeType) { emit modified(); return true; }
    void rename(const QString &) {}

signals:
    void modified();

private:
    QString m_fileName;
};

90
91
class MaemoGlobal
{
92
    Q_DECLARE_TR_FUNCTIONS(RemoteLinux::Internal::MaemoGlobal)
93
public:
94
    enum PackagingSystem { Dpkg, Rpm, Tar };
95

96
    static bool isMaemoTargetId(const QString &id);
97
98
99
    static bool isFremantleTargetId(const QString &id);
    static bool isHarmattanTargetId(const QString &id);
    static bool isMeegoTargetId(const QString &id);
dt's avatar
dt committed
100
101
102
    static bool isValidMaemo5QtVersion(const QString &qmakePath);
    static bool isValidHarmattanQtVersion(const QString &qmakePath);
    static bool isValidMeegoQtVersion(const QString &qmakePath);
103

104
    static bool isLinuxQt(const QtSupport::BaseQtVersion *qtVersion);
Christian Kandeler's avatar
Christian Kandeler committed
105
106
    static bool hasLinuxQt(const ProjectExplorer::Target *target);

107
    static QString homeDirOnDevice(const QString &uname);
108
    static QString devrootshPath();
109
110
    static int applicationIconSize(const QString &osType);
    static QString remoteSudo(const QString &osType, const QString &uname);
111
    static QString remoteCommandPrefix(const QString &osType);
112
    static QString remoteEnvironment(const QList<Utils::EnvironmentItem> &list);
113
    static QString remoteSourceProfilesCommand();
114
    static QString failedToConnectToServerMessage(const QSharedPointer<Utils::SshConnection> &connection,
115
116
117
        const QSharedPointer<const LinuxDeviceConfiguration> &deviceConfig);
    static QString deviceConfigurationName(const QSharedPointer<const LinuxDeviceConfiguration> &devConf);
    static PortList freePorts(const QSharedPointer<const LinuxDeviceConfiguration> &devConf,
118
        const QtSupport::BaseQtVersion *qtVersion);
119

120
121
    static void addMaddeEnvironment(Utils::Environment &env, const QString &qmakePath);
    static void transformMaddeCall(QString &command, QStringList &args, const QString &qmakePath);
dt's avatar
dt committed
122
123
124
125
    static QString maddeRoot(const QString &qmakePath);
    static QString targetRoot(const QString &qmakePath);
    static QString targetName(const QString &qmakePath);
    static QString madCommand(const QString &qmakePath);
126
127
    static QString madDeveloperUiName(const QString &osType);
    static QString osType(const QString &qmakePath);
128

129
    // TODO: IS this still needed with Qt Version having an Abi?
dt's avatar
dt committed
130
    static QString architecture(const QString &qmakePath);
131
132

    static bool callMad(QProcess &proc, const QStringList &args,
dt's avatar
dt committed
133
        const QString &qmakePath, bool useTarget);
134
    static bool callMadAdmin(QProcess &proc, const QStringList &args,
dt's avatar
dt committed
135
        const QString &qmakePath, bool useTarget);
ck's avatar
ck committed
136

137
    static QString osTypeToString(const QString &osType);
138

139
    static PackagingSystem packagingSystem(const QString &osType);
140

141
    static bool removeRecursively(const QString &filePath, QString &error);
142
143
    static bool copyRecursively(const QString &srcFilePath,
        const QString &tgtFilePath, QString *error = 0);
144

145
146
147
148
149
    static bool isFileNewerThan(const QString &filePath,
        const QDateTime &timeStamp);

    template<class T> static T *earlierBuildStep(const ProjectExplorer::DeployConfiguration *dc,
        const ProjectExplorer::BuildStep *laterBuildStep)
ck's avatar
ck committed
150
    {
151
152
        if (!dc)
            return 0;
153
        const ProjectExplorer::BuildStepList * const bsl = dc->stepList();
Tobias Hunger's avatar
Tobias Hunger committed
154
        const QList<ProjectExplorer::BuildStep *> &buildSteps = bsl->steps();
155
156
157
        for (int i = 0; i < buildSteps.count(); ++i) {
            if (buildSteps.at(i) == laterBuildStep)
                return 0;
158
            if (T * const step = dynamic_cast<T *>(buildSteps.at(i)))
ck's avatar
ck committed
159
160
161
162
                return step;
        }
        return 0;
    }
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

    template<typename State> static void assertState(State expected,
        State actual, const char *func)
    {
        assertState(QList<State>() << expected, actual, func);
    }

    template<typename State> static void assertState(const QList<State> &expected,
        State actual, const char *func)
    {
        if (!expected.contains(actual)) {
            qWarning("Warning: Unexpected state %d in function %s.",
                actual, func);
        }
    }
178

179
    static bool isValidMaemoQtVersion(const QString &qmakePath, const QString &osType);
dt's avatar
dt committed
180
private:
dt's avatar
dt committed
181
182
    static QString madAdminCommand(const QString &qmakePath);
    static bool callMaddeShellScript(QProcess &proc, const QString &qmakePath,
183
        const QString &command, const QStringList &args, bool useTarget);
dt's avatar
dt committed
184
    static QStringList targetArgs(const QString &qmakePath, bool useTarget);
185
186
187
};

} // namespace Internal
188
} // namespace RemoteLinux
189
190

#endif // MAEMOGLOBAL_H