2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-09-30 15:32:06 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "androidextralibrarylistmodel.h"
|
2015-02-18 16:01:58 +01:00
|
|
|
|
2018-05-04 11:13:43 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2015-02-18 16:01:58 +01:00
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
2013-10-29 16:19:24 +01:00
|
|
|
#include <qmakeprojectmanager/qmakeproject.h>
|
|
|
|
|
#include <qmakeprojectmanager/qmakenodes.h>
|
2018-05-04 11:13:43 +02:00
|
|
|
|
2014-03-07 12:56:59 +01:00
|
|
|
#include <proparser/prowriter.h>
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2015-02-18 16:01:58 +01:00
|
|
|
|
2014-07-23 12:47:51 +02:00
|
|
|
using namespace QmakeAndroidSupport;
|
2013-09-30 15:32:06 +02:00
|
|
|
using namespace Internal;
|
2015-02-18 16:01:58 +01:00
|
|
|
using QmakeProjectManager::QmakeProject;
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2015-02-18 16:01:58 +01:00
|
|
|
AndroidExtraLibraryListModel::AndroidExtraLibraryListModel(ProjectExplorer::Target *target,
|
2013-09-30 15:32:06 +02:00
|
|
|
QObject *parent)
|
2015-02-18 16:01:58 +01:00
|
|
|
: QAbstractItemModel(parent),
|
|
|
|
|
m_target(target)
|
2013-09-30 15:32:06 +02:00
|
|
|
{
|
|
|
|
|
|
2015-02-18 16:01:58 +01:00
|
|
|
activeRunConfigurationChanged();
|
|
|
|
|
|
|
|
|
|
auto project = static_cast<QmakeProject *>(target->project());
|
|
|
|
|
connect(project, &QmakeProject::proFileUpdated,
|
|
|
|
|
this, &AndroidExtraLibraryListModel::proFileUpdated);
|
|
|
|
|
|
|
|
|
|
connect(target, &ProjectExplorer::Target::activeRunConfigurationChanged,
|
|
|
|
|
this, &AndroidExtraLibraryListModel::activeRunConfigurationChanged);
|
2013-09-30 15:32:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex AndroidExtraLibraryListModel::index(int row, int column, const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return createIndex(row, column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex AndroidExtraLibraryListModel::parent(const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AndroidExtraLibraryListModel::rowCount(const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return m_entries.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AndroidExtraLibraryListModel::columnCount(const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant AndroidExtraLibraryListModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(index.row() >= 0 && index.row() < m_entries.size());
|
2014-03-27 11:42:20 +01:00
|
|
|
const QString &entry = QDir::cleanPath(m_entries.at(index.row()));
|
2013-09-30 15:32:06 +02:00
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole: return entry;
|
|
|
|
|
default: return QVariant();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 16:01:58 +01:00
|
|
|
void AndroidExtraLibraryListModel::activeRunConfigurationChanged()
|
2013-09-30 15:32:06 +02:00
|
|
|
{
|
2017-02-10 11:16:18 +01:00
|
|
|
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
|
|
|
|
if (!pro || pro->parseInProgress()) {
|
2015-02-18 16:01:58 +01:00
|
|
|
emit enabledChanged(false);
|
2013-09-30 15:32:06 +02:00
|
|
|
return;
|
2015-02-18 16:01:58 +01:00
|
|
|
}
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2014-03-07 12:56:59 +01:00
|
|
|
m_scope = QLatin1String("contains(ANDROID_TARGET_ARCH,")
|
2017-02-10 11:16:18 +01:00
|
|
|
+ pro->singleVariableValue(QmakeProjectManager::Variable::AndroidArch)
|
2014-03-07 12:56:59 +01:00
|
|
|
+ QLatin1Char(')');
|
|
|
|
|
|
2014-03-11 18:05:17 +01:00
|
|
|
bool enabled;
|
2013-09-30 15:32:06 +02:00
|
|
|
beginResetModel();
|
2017-02-10 11:16:18 +01:00
|
|
|
if (pro->validParse() && pro->projectType() == QmakeProjectManager::ProjectType::ApplicationTemplate) {
|
|
|
|
|
m_entries = pro->variableValue(QmakeProjectManager::Variable::AndroidExtraLibs);
|
2014-03-11 18:05:17 +01:00
|
|
|
enabled = true;
|
|
|
|
|
} else {
|
|
|
|
|
// parsing error or not a application template
|
|
|
|
|
m_entries.clear();
|
|
|
|
|
enabled = false;
|
|
|
|
|
}
|
2013-09-30 15:32:06 +02:00
|
|
|
endResetModel();
|
2014-03-11 18:05:17 +01:00
|
|
|
|
|
|
|
|
emit enabledChanged(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 11:16:18 +01:00
|
|
|
QmakeProjectManager::QmakeProFile *AndroidExtraLibraryListModel::activeProFile() const
|
2015-02-18 16:01:58 +01:00
|
|
|
{
|
|
|
|
|
ProjectExplorer::RunConfiguration *rc = m_target->activeRunConfiguration();
|
2018-05-04 11:13:43 +02:00
|
|
|
if (!rc)
|
|
|
|
|
return nullptr;
|
2015-02-18 16:01:58 +01:00
|
|
|
auto project = static_cast<QmakeProject *>(m_target->project());
|
2018-05-04 11:13:43 +02:00
|
|
|
return project->rootProFile()->findProFile(Utils::FileName::fromString(rc->buildKey()));
|
2015-02-18 16:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-10 11:16:18 +01:00
|
|
|
void AndroidExtraLibraryListModel::proFileUpdated(QmakeProjectManager::QmakeProFile *pro)
|
2015-02-18 16:01:58 +01:00
|
|
|
{
|
2017-02-10 11:16:18 +01:00
|
|
|
if (activeProFile() != pro)
|
2015-02-18 16:01:58 +01:00
|
|
|
return;
|
|
|
|
|
activeRunConfigurationChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-11 18:05:17 +01:00
|
|
|
bool AndroidExtraLibraryListModel::isEnabled() const
|
|
|
|
|
{
|
2017-02-10 11:16:18 +01:00
|
|
|
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
|
|
|
|
return pro && !pro->parseInProgress() && pro->projectType() == QmakeProjectManager::ProjectType::ApplicationTemplate;
|
2013-09-30 15:32:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidExtraLibraryListModel::addEntries(const QStringList &list)
|
|
|
|
|
{
|
2017-02-10 11:16:18 +01:00
|
|
|
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
|
|
|
|
if (!pro || pro->projectType() != QmakeProjectManager::ProjectType::ApplicationTemplate)
|
2013-09-30 15:32:06 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size() + list.size());
|
|
|
|
|
|
2014-03-27 11:39:24 +01:00
|
|
|
foreach (const QString &path, list)
|
2015-02-18 16:01:58 +01:00
|
|
|
m_entries += QLatin1String("$$PWD/")
|
2017-02-10 11:16:18 +01:00
|
|
|
+ pro->filePath().toFileInfo().absoluteDir().relativeFilePath(path);
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2017-02-10 11:16:18 +01:00
|
|
|
pro->setProVariable("ANDROID_EXTRA_LIBS", m_entries, m_scope,
|
|
|
|
|
QmakeProjectManager::Internal::ProWriter::ReplaceValues
|
|
|
|
|
| QmakeProjectManager::Internal::ProWriter::MultiLine);
|
2013-09-30 15:32:06 +02:00
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-02 16:17:25 +02:00
|
|
|
bool greaterModelIndexByRow(const QModelIndex &a, const QModelIndex &b)
|
|
|
|
|
{
|
|
|
|
|
return a.row() > b.row();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidExtraLibraryListModel::removeEntries(QModelIndexList list)
|
2013-09-30 15:32:06 +02:00
|
|
|
{
|
2017-02-10 11:16:18 +01:00
|
|
|
QmakeProjectManager::QmakeProFile *pro = activeProFile();
|
|
|
|
|
if (!pro)
|
|
|
|
|
return;
|
|
|
|
|
if (list.isEmpty() || !pro || pro->projectType() != QmakeProjectManager::ProjectType::ApplicationTemplate)
|
2013-09-30 15:32:06 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-10-02 16:17:25 +02:00
|
|
|
std::sort(list.begin(), list.end(), greaterModelIndexByRow);
|
|
|
|
|
|
2013-09-30 15:32:06 +02:00
|
|
|
int i = 0;
|
|
|
|
|
while (i < list.size()) {
|
2013-10-02 16:17:25 +02:00
|
|
|
int lastRow = list.at(i++).row();
|
|
|
|
|
int firstRow = lastRow;
|
|
|
|
|
while (i < list.size() && firstRow - list.at(i).row() <= 1)
|
|
|
|
|
firstRow = list.at(i++).row();
|
2013-09-30 15:32:06 +02:00
|
|
|
|
2013-10-02 16:17:25 +02:00
|
|
|
beginRemoveRows(QModelIndex(), firstRow, lastRow);
|
2013-09-30 15:32:06 +02:00
|
|
|
int count = lastRow - firstRow + 1;
|
|
|
|
|
while (count-- > 0)
|
2013-10-02 16:17:25 +02:00
|
|
|
m_entries.removeAt(firstRow);
|
2013-09-30 15:32:06 +02:00
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 11:16:18 +01:00
|
|
|
pro->setProVariable(QLatin1String("ANDROID_EXTRA_LIBS"), m_entries, m_scope);
|
2013-09-30 15:32:06 +02:00
|
|
|
}
|