~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qtsupport/qmlobservertool.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-12-02 09:16:15 UTC
  • mfrom: (1.1.29)
  • Revision ID: timo.jyrinki@canonical.com-20131202091615-xbj1os1f604ber1m
New upstream release candidate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
 
** Contact: http://www.qt-project.org/legal
5
 
**
6
 
** This file is part of Qt Creator.
7
 
**
8
 
** Commercial License Usage
9
 
** Licensees holding valid commercial Qt licenses may use this file in
10
 
** accordance with the commercial license agreement provided with the
11
 
** Software or, alternatively, in accordance with the terms contained in
12
 
** a written agreement between you and Digia.  For licensing terms and
13
 
** conditions see http://qt.digia.com/licensing.  For further information
14
 
** use the contact form at http://qt.digia.com/contact-us.
15
 
**
16
 
** GNU Lesser General Public License Usage
17
 
** Alternatively, this file may be used under the terms of the GNU Lesser
18
 
** General Public License version 2.1 as published by the Free Software
19
 
** Foundation and appearing in the file LICENSE.LGPL included in the
20
 
** packaging of this file.  Please review the following information to
21
 
** ensure the GNU Lesser General Public License version 2.1 requirements
22
 
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
 
**
24
 
** In addition, as a special exception, Digia gives you certain additional
25
 
** rights.  These rights are described in the Digia Qt LGPL Exception
26
 
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
 
**
28
 
****************************************************************************/
29
 
 
30
 
#include "qmlobservertool.h"
31
 
 
32
 
#include "qtsupportconstants.h"
33
 
#include "baseqtversion.h"
34
 
#include <coreplugin/icore.h>
35
 
 
36
 
#include <QDesktopServices>
37
 
#include <QCoreApplication>
38
 
#include <QDir>
39
 
#include <QDebug>
40
 
 
41
 
namespace QtSupport {
42
 
 
43
 
static QStringList recursiveFileList(const QDir &dir, const QString &prefix)
44
 
{
45
 
    QStringList files;
46
 
 
47
 
    QString _prefix = prefix;
48
 
    if (!_prefix.isEmpty() && !_prefix.endsWith(QLatin1Char('/')))
49
 
        _prefix.append(QLatin1Char('/'));
50
 
 
51
 
    foreach (const QString &fileName, dir.entryList(QDir::Files))
52
 
        files << _prefix + fileName;
53
 
 
54
 
    foreach (const QString &subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
55
 
        files += recursiveFileList(QDir(dir.absoluteFilePath(subDir)), _prefix + subDir);
56
 
 
57
 
    return files;
58
 
}
59
 
 
60
 
static QStringList installDirectories(const QString &qtInstallData)
61
 
{
62
 
    const QChar slash = QLatin1Char('/');
63
 
    const uint hash = qHash(qtInstallData);
64
 
    QStringList directories;
65
 
    directories
66
 
            << (qtInstallData + QLatin1String("/qtc-qmlobserver/"))
67
 
            << QDir::cleanPath((QCoreApplication::applicationDirPath() + QLatin1String("/../qtc-qmlobserver/") + QString::number(hash))) + slash
68
 
            << (QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/qtc-qmlobserver/") + QString::number(hash)) + slash;
69
 
    return directories;
70
 
}
71
 
 
72
 
static QString sourcePath()
73
 
{
74
 
    return Core::ICore::resourcePath() + QLatin1String("/qml/qmlobserver/");
75
 
}
76
 
 
77
 
static QStringList sourceFileNames()
78
 
{
79
 
    return recursiveFileList(QDir(sourcePath()), QString());
80
 
}
81
 
 
82
 
static QStringList validBinaryFilenames()
83
 
{
84
 
    return QStringList()
85
 
            << QLatin1String("debug/qmlobserver.exe")
86
 
            << QLatin1String("qmlobserver.exe")
87
 
            << QLatin1String("qmlobserver")
88
 
            << QLatin1String("QMLObserver.app/Contents/MacOS/QMLObserver");
89
 
}
90
 
 
91
 
bool QmlObserverTool::canBuild(const BaseQtVersion *qtVersion, QString *reason)
92
 
{
93
 
    if (qtVersion->type() != QLatin1String(Constants::DESKTOPQT)
94
 
            && qtVersion->type() != QLatin1String(Constants::SIMULATORQT)) {
95
 
        if (reason)
96
 
            *reason = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "Only available for Qt for Desktop or Qt for Qt Simulator.");
97
 
        return false;
98
 
    }
99
 
 
100
 
    if (qtVersion->qtVersion() < QtVersionNumber(4, 7, 1)) {
101
 
        if (reason)
102
 
            *reason = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "Only available for Qt 4.7.1 or newer.");
103
 
        return false;
104
 
    }
105
 
    if (qtVersion->qtVersion() >= QtVersionNumber(4, 8, 0)) {
106
 
        if (reason)
107
 
            *reason = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "Not needed.");
108
 
        return false;
109
 
    }
110
 
    return true;
111
 
}
112
 
 
113
 
QString QmlObserverTool::toolByInstallData(const QString &qtInstallData)
114
 
{
115
 
    if (!Core::ICore::instance())
116
 
        return QString();
117
 
 
118
 
    const QStringList directories = installDirectories(qtInstallData);
119
 
    const QStringList binFilenames = validBinaryFilenames();
120
 
 
121
 
    return byInstallDataHelper(sourcePath(), sourceFileNames(), directories, binFilenames, false);
122
 
}
123
 
 
124
 
QStringList QmlObserverTool::locationsByInstallData(const QString &qtInstallData)
125
 
{
126
 
    QStringList result;
127
 
    QFileInfo fileInfo;
128
 
    const QStringList binFilenames = validBinaryFilenames();
129
 
    foreach (const QString &directory, installDirectories(qtInstallData)) {
130
 
        if (getHelperFileInfoFor(binFilenames, directory, &fileInfo))
131
 
            result << fileInfo.filePath();
132
 
    }
133
 
    return result;
134
 
}
135
 
 
136
 
bool  QmlObserverTool::build(BuildHelperArguments arguments, QString *log, QString *errorMessage)
137
 
{
138
 
    arguments.helperName = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "QMLObserver");
139
 
    arguments.proFilename = QLatin1String("qmlobserver.pro");
140
 
 
141
 
    return buildHelper(arguments, log, errorMessage);
142
 
}
143
 
 
144
 
static inline bool mkpath(const QString &targetDirectory, QString *errorMessage)
145
 
{
146
 
    if (!QDir().mkpath(targetDirectory)) {
147
 
        *errorMessage = QCoreApplication::translate("ProjectExplorer::QmlObserverTool", "The target directory %1 could not be created.").arg(targetDirectory);
148
 
        return false;
149
 
    }
150
 
    return true;
151
 
}
152
 
 
153
 
QString QmlObserverTool::copy(const QString &qtInstallData, QString *errorMessage)
154
 
{
155
 
    const QStringList directories = installDirectories(qtInstallData);
156
 
 
157
 
    // Try to find a writable directory.
158
 
    foreach (const QString &directory, directories) {
159
 
        if (!mkpath(directory, errorMessage))
160
 
            continue;
161
 
 
162
 
        errorMessage->clear();
163
 
 
164
 
        if (copyFiles(sourcePath(), sourceFileNames(), directory, errorMessage)) {
165
 
            errorMessage->clear();
166
 
            return directory;
167
 
        }
168
 
    }
169
 
    *errorMessage = QCoreApplication::translate("ProjectExplorer::QmlObserverTool",
170
 
                                                "QMLObserver could not be built in any of the directories:\n- %1\n\nReason: %2")
171
 
                    .arg(directories.join(QLatin1String("\n- ")), *errorMessage);
172
 
    return QString();
173
 
}
174
 
 
175
 
} // namespace