2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2012-09-18 15:58:07 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2012-09-18 15:58:07 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
#include "rmqtoperation.h"
|
|
|
|
|
|
|
|
|
|
#include "addkeysoperation.h"
|
|
|
|
|
#include "addqtoperation.h"
|
|
|
|
|
#include "findkeyoperation.h"
|
|
|
|
|
#include "findvalueoperation.h"
|
|
|
|
|
#include "getoperation.h"
|
|
|
|
|
#include "rmkeysoperation.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
// ToolChain file stuff:
|
2013-10-29 16:44:24 +01:00
|
|
|
const char PREFIX[] = "QtVersion.";
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
// ToolChain:
|
2013-10-29 16:44:24 +01:00
|
|
|
const char AUTODETECTION_SOURCE[] = "autodetectionSource";
|
2012-09-18 15:58:07 +02:00
|
|
|
|
|
|
|
|
QString RmQtOperation::name() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("rmQt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString RmQtOperation::helpText() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("remove a Qt version from Qt Creator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString RmQtOperation::argumentsHelpText() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(" --id <ID> The id of the qt version to remove.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RmQtOperation::setArguments(const QStringList &args)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < args.count(); ++i) {
|
|
|
|
|
const QString current = args.at(i);
|
|
|
|
|
const QString next = ((i + 1) < args.count()) ? args.at(i + 1) : QString();
|
|
|
|
|
|
|
|
|
|
if (current == QLatin1String("--id")) {
|
2013-02-07 10:42:24 +01:00
|
|
|
if (next.isNull()) {
|
|
|
|
|
std::cerr << "No parameter for --id given." << std::endl << std::endl;
|
2012-09-18 15:58:07 +02:00
|
|
|
return false;
|
2013-02-07 10:42:24 +01:00
|
|
|
}
|
2012-09-18 15:58:07 +02:00
|
|
|
++i; // skip next;
|
|
|
|
|
m_id = next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 10:42:24 +01:00
|
|
|
if (m_id.isEmpty())
|
|
|
|
|
std::cerr << "No id given." << std::endl << std::endl;
|
|
|
|
|
|
2012-09-18 15:58:07 +02:00
|
|
|
return !m_id.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RmQtOperation::execute() const
|
|
|
|
|
{
|
2014-07-02 10:12:38 +03:00
|
|
|
QVariantMap map = load(QLatin1String("QtVersions"));
|
2012-09-18 15:58:07 +02:00
|
|
|
if (map.isEmpty())
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
QVariantMap result = rmQt(map, m_id);
|
|
|
|
|
if (result == map)
|
2013-07-08 08:35:18 +02:00
|
|
|
return 2;
|
2012-09-18 15:58:07 +02:00
|
|
|
|
2014-07-02 10:12:38 +03:00
|
|
|
return save(result, QLatin1String("QtVersions")) ? 0 : 3;
|
2012-09-18 15:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
bool RmQtOperation::test() const
|
|
|
|
|
{
|
|
|
|
|
// Add toolchain:
|
|
|
|
|
QVariantMap map = AddQtOperation::initializeQtVersions();
|
|
|
|
|
|
|
|
|
|
QVariantMap result = rmQt(QVariantMap(), QLatin1String("nonexistant"));
|
|
|
|
|
if (result != map)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
map = AddQtOperation::addQt(map, QLatin1String("testId"), QLatin1String("name"), QLatin1String("type"),
|
|
|
|
|
QLatin1String("/tmp/test"),
|
|
|
|
|
KeyValuePairList() << KeyValuePair(QLatin1String("ExtraKey"), QVariant(QLatin1String("ExtraValue"))));
|
|
|
|
|
map = AddQtOperation::addQt(map, QLatin1String("testId2"), QLatin1String("other name"), QLatin1String("type"),
|
|
|
|
|
QLatin1String("/tmp/test2"),
|
|
|
|
|
KeyValuePairList());
|
|
|
|
|
|
|
|
|
|
result = rmQt(map, QLatin1String("nonexistant"));
|
|
|
|
|
if (result != map)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
result = rmQt(map, QLatin1String("testId2"));
|
|
|
|
|
if (result == map
|
|
|
|
|
|| !result.contains(QLatin1String("QtVersion.0"))
|
|
|
|
|
|| result.value(QLatin1String("QtVersion.0")) != map.value(QLatin1String("QtVersion.0")))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
result = rmQt(map, QLatin1String("testId"));
|
|
|
|
|
if (result == map
|
|
|
|
|
|| !result.contains(QLatin1String("QtVersion.0"))
|
|
|
|
|
|| result.value(QLatin1String("QtVersion.0")) != map.value(QLatin1String("QtVersion.1")))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
result = rmQt(result, QLatin1String("testId2"));
|
|
|
|
|
if (result == map)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
QVariantMap RmQtOperation::rmQt(const QVariantMap &map, const QString &id)
|
|
|
|
|
{
|
2012-11-20 16:28:53 +01:00
|
|
|
QString sdkId = id;
|
|
|
|
|
if (!id.startsWith(QLatin1String("SDK.")))
|
|
|
|
|
sdkId = QString::fromLatin1("SDK.") + id;
|
|
|
|
|
|
2012-09-18 15:58:07 +02:00
|
|
|
QVariantList qtList;
|
|
|
|
|
for (QVariantMap::const_iterator i = map.begin(); i != map.end(); ++i) {
|
|
|
|
|
if (!i.key().startsWith(QLatin1String(PREFIX)))
|
|
|
|
|
continue;
|
|
|
|
|
QVariantMap qtData = i.value().toMap();
|
2012-11-20 16:28:53 +01:00
|
|
|
const QString dataId = qtData.value(QLatin1String(AUTODETECTION_SOURCE)).toString();
|
|
|
|
|
if ((dataId != id) && (dataId != sdkId))
|
2012-09-18 15:58:07 +02:00
|
|
|
qtList.append(qtData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap newMap = AddQtOperation::initializeQtVersions();
|
|
|
|
|
for (int i = 0; i < qtList.count(); ++i)
|
|
|
|
|
newMap.insert(QString::fromLatin1(PREFIX) + QString::number(i), qtList.at(i));
|
|
|
|
|
|
|
|
|
|
return newMap;
|
|
|
|
|
}
|
|
|
|
|
|