1
/****************************************************************************
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of Qt Creator.
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.
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.
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.
28
****************************************************************************/
30
#include "qmlobservertool.h"
32
#include "qtsupportconstants.h"
33
#include "baseqtversion.h"
34
#include <coreplugin/icore.h>
36
#include <QDesktopServices>
37
#include <QCoreApplication>
43
static QStringList recursiveFileList(const QDir &dir, const QString &prefix)
47
QString _prefix = prefix;
48
if (!_prefix.isEmpty() && !_prefix.endsWith(QLatin1Char('/')))
49
_prefix.append(QLatin1Char('/'));
51
foreach (const QString &fileName, dir.entryList(QDir::Files))
52
files << _prefix + fileName;
54
foreach (const QString &subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
55
files += recursiveFileList(QDir(dir.absoluteFilePath(subDir)), _prefix + subDir);
60
static QStringList installDirectories(const QString &qtInstallData)
62
const QChar slash = QLatin1Char('/');
63
const uint hash = qHash(qtInstallData);
64
QStringList 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;
72
static QString sourcePath()
74
return Core::ICore::resourcePath() + QLatin1String("/qml/qmlobserver/");
77
static QStringList sourceFileNames()
79
return recursiveFileList(QDir(sourcePath()), QString());
82
static QStringList validBinaryFilenames()
85
<< QLatin1String("debug/qmlobserver.exe")
86
<< QLatin1String("qmlobserver.exe")
87
<< QLatin1String("qmlobserver")
88
<< QLatin1String("QMLObserver.app/Contents/MacOS/QMLObserver");
91
bool QmlObserverTool::canBuild(const BaseQtVersion *qtVersion, QString *reason)
93
if (qtVersion->type() != QLatin1String(Constants::DESKTOPQT)
94
&& qtVersion->type() != QLatin1String(Constants::SIMULATORQT)) {
96
*reason = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "Only available for Qt for Desktop or Qt for Qt Simulator.");
100
if (qtVersion->qtVersion() < QtVersionNumber(4, 7, 1)) {
102
*reason = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "Only available for Qt 4.7.1 or newer.");
105
if (qtVersion->qtVersion() >= QtVersionNumber(4, 8, 0)) {
107
*reason = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "Not needed.");
113
QString QmlObserverTool::toolByInstallData(const QString &qtInstallData)
115
if (!Core::ICore::instance())
118
const QStringList directories = installDirectories(qtInstallData);
119
const QStringList binFilenames = validBinaryFilenames();
121
return byInstallDataHelper(sourcePath(), sourceFileNames(), directories, binFilenames, false);
124
QStringList QmlObserverTool::locationsByInstallData(const QString &qtInstallData)
128
const QStringList binFilenames = validBinaryFilenames();
129
foreach (const QString &directory, installDirectories(qtInstallData)) {
130
if (getHelperFileInfoFor(binFilenames, directory, &fileInfo))
131
result << fileInfo.filePath();
136
bool QmlObserverTool::build(BuildHelperArguments arguments, QString *log, QString *errorMessage)
138
arguments.helperName = QCoreApplication::translate("QmakeProjectManager::QmlObserverTool", "QMLObserver");
139
arguments.proFilename = QLatin1String("qmlobserver.pro");
141
return buildHelper(arguments, log, errorMessage);
144
static inline bool mkpath(const QString &targetDirectory, QString *errorMessage)
146
if (!QDir().mkpath(targetDirectory)) {
147
*errorMessage = QCoreApplication::translate("ProjectExplorer::QmlObserverTool", "The target directory %1 could not be created.").arg(targetDirectory);
153
QString QmlObserverTool::copy(const QString &qtInstallData, QString *errorMessage)
155
const QStringList directories = installDirectories(qtInstallData);
157
// Try to find a writable directory.
158
foreach (const QString &directory, directories) {
159
if (!mkpath(directory, errorMessage))
162
errorMessage->clear();
164
if (copyFiles(sourcePath(), sourceFileNames(), directory, errorMessage)) {
165
errorMessage->clear();
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);