An error occurred while loading the file. Please try again.
-
Ghislain MARY authoredb485789d
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef UTILS_H
#define UTILS_H
#include <QStringList>
#include <QMap>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <QtCore/QDateTime>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonDocument>
#include <iostream>
QT_BEGIN_NAMESPACE
enum PlatformFlag {
WindowsBased = 0x1000,
UnixBased = 0x2000,
IntelBased = 0x4000,
ArmBased = 0x8000,
MinGW = 0x10000
};
enum Platform {
Windows = WindowsBased + IntelBased,
WindowsMinGW = WindowsBased + IntelBased + MinGW,
WinRtIntel = WindowsBased + IntelBased + 1,
WinRtArm = WindowsBased + ArmBased + 2,
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
WinPhoneIntel = WindowsBased + IntelBased + 3,
WinPhoneArm = WindowsBased + ArmBased + 4,
Unix = UnixBased,
UnknownPlatform
};
enum ListOption {
ListNone = 0,
ListSource,
ListTarget,
ListRelative,
ListMapping
};
inline std::wostream &operator<<(std::wostream &str, const QString &s)
{
#ifdef Q_OS_WIN
str << reinterpret_cast<const wchar_t *>(s.utf16());
#else
str << s.toStdWString();
#endif
return str;
}
// Container class for JSON output
class JsonOutput
{
typedef QPair<QString, QString> SourceTargetMapping;
typedef QList<SourceTargetMapping> SourceTargetMappings;
public:
void addFile(const QString &source, const QString &target)
{
m_files.append(SourceTargetMapping(source, target));
}
void removeTargetDirectory(const QString &targetDirectory)
{
for (int i = m_files.size() - 1; i >= 0; --i) {
if (m_files.at(i).second == targetDirectory)
m_files.removeAt(i);
}
}
QByteArray toJson() const
{
QJsonObject document;
QJsonArray files;
foreach (const SourceTargetMapping &mapping, m_files) {
QJsonObject object;
object.insert(QStringLiteral("source"), QDir::toNativeSeparators(mapping.first));
object.insert(QStringLiteral("target"), QDir::toNativeSeparators(mapping.second));
files.append(object);
}
document.insert(QStringLiteral("files"), files);
return QJsonDocument(document).toJson();
}
QByteArray toList(ListOption option, const QDir &base) const
{
QByteArray list;
foreach (const SourceTargetMapping &mapping, m_files) {
const QString source = QDir::toNativeSeparators(mapping.first);
const QString fileName = QFileInfo(mapping.first).fileName();
const QString target = QDir::toNativeSeparators(mapping.second) + QDir::separator() + fileName;
switch (option) {
case ListNone:
break;
case ListSource:
list += source.toUtf8() + '\n';
break;