forked from qt-creator/qt-creator
Android: Make runconfiguration use aspects
Change-Id: I6d89de901e64b2f29d62073e458eb6cd86c44acd Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -24,10 +24,12 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "androidrunconfiguration.h"
|
||||
|
||||
#include "androidconstants.h"
|
||||
#include "androidglobal.h"
|
||||
#include "androidtoolchain.h"
|
||||
#include "androidmanager.h"
|
||||
#include "androidrunconfigurationwidget.h"
|
||||
#include "adbcommandswidget.h"
|
||||
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/project.h>
|
||||
@@ -36,88 +38,125 @@
|
||||
#include <qtsupport/qtoutputformatter.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/detailswidget.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QSpacerItem>
|
||||
#include <QWidget>
|
||||
|
||||
using namespace Android::Internal;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Android {
|
||||
using namespace Internal;
|
||||
|
||||
const char amStartArgsKey[] = "Android.AmStartArgsKey";
|
||||
const char preStartShellCmdsKey[] = "Android.PreStartShellCmdListKey";
|
||||
const char postFinishShellCmdsKey[] = "Android.PostFinishShellCmdListKey";
|
||||
BaseStringListAspect::BaseStringListAspect(RunConfiguration *runConfig,
|
||||
const QString &settingsKey,
|
||||
Core::Id id)
|
||||
: IRunConfigurationAspect(runConfig)
|
||||
{
|
||||
setSettingsKey(settingsKey);
|
||||
setId(id);
|
||||
}
|
||||
|
||||
BaseStringListAspect::~BaseStringListAspect() = default;
|
||||
|
||||
void BaseStringListAspect::addToConfigurationLayout(QFormLayout *layout)
|
||||
{
|
||||
QTC_CHECK(!m_widget);
|
||||
m_widget = new AdbCommandsWidget(layout->parentWidget());
|
||||
m_widget->setCommandList(m_value);
|
||||
m_widget->setTitleText(m_label);
|
||||
layout->addRow(m_widget);
|
||||
connect(m_widget.data(), &AdbCommandsWidget::commandsChanged, this, [this] {
|
||||
m_value = m_widget->commandsList();
|
||||
emit changed();
|
||||
});
|
||||
}
|
||||
|
||||
void BaseStringListAspect::fromMap(const QVariantMap &map)
|
||||
{
|
||||
m_value = map.value(settingsKey()).toStringList();
|
||||
}
|
||||
|
||||
void BaseStringListAspect::toMap(QVariantMap &data) const
|
||||
{
|
||||
data.insert(settingsKey(), m_value);
|
||||
}
|
||||
|
||||
QStringList BaseStringListAspect::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void BaseStringListAspect::setValue(const QStringList &value)
|
||||
{
|
||||
m_value = value;
|
||||
if (m_widget)
|
||||
m_widget->setCommandList(m_value);
|
||||
}
|
||||
|
||||
void BaseStringListAspect::setLabel(const QString &label)
|
||||
{
|
||||
m_label = label;
|
||||
}
|
||||
|
||||
|
||||
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
auto amStartArgsAspect = new BaseStringAspect(this);
|
||||
amStartArgsAspect->setId(Constants::ANDROID_AMSTARTARGS_ASPECT);
|
||||
amStartArgsAspect->setSettingsKey("Android.AmStartArgsKey");
|
||||
amStartArgsAspect->setLabelText(tr("Activity manager start options:"));
|
||||
amStartArgsAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
|
||||
addExtraAspect(amStartArgsAspect);
|
||||
|
||||
auto preStartShellCmdAspect = new BaseStringListAspect(this);
|
||||
preStartShellCmdAspect->setId(Constants::ANDROID_PRESTARTSHELLCMDLIST_ASPECT);
|
||||
preStartShellCmdAspect->setSettingsKey("Android.PreStartShellCmdListKey");
|
||||
preStartShellCmdAspect->setLabel(tr("Shell commands to run on Android device before application launch."));
|
||||
addExtraAspect(preStartShellCmdAspect);
|
||||
|
||||
auto postStartShellCmdAspect = new BaseStringListAspect(this);
|
||||
postStartShellCmdAspect->setId(Constants::ANDROID_POSTSTARTSHELLCMDLIST_ASPECT);
|
||||
postStartShellCmdAspect->setSettingsKey("Android.PostStartShellCmdListKey");
|
||||
postStartShellCmdAspect->setLabel(tr("Shell commands to run on Android device after application quits."));
|
||||
addExtraAspect(postStartShellCmdAspect);
|
||||
|
||||
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
||||
connect(target->project(), &Project::parsingFinished, this, [this] {
|
||||
updateTargetInformation();
|
||||
});
|
||||
}
|
||||
|
||||
void AndroidRunConfiguration::setPreStartShellCommands(const QStringList &cmdList)
|
||||
{
|
||||
m_preStartShellCommands = cmdList;
|
||||
}
|
||||
|
||||
void AndroidRunConfiguration::setPostFinishShellCommands(const QStringList &cmdList)
|
||||
{
|
||||
m_postFinishShellCommands = cmdList;
|
||||
}
|
||||
|
||||
void AndroidRunConfiguration::setAmStartExtraArgs(const QStringList &args)
|
||||
{
|
||||
m_amStartExtraArgs = args;
|
||||
}
|
||||
|
||||
QWidget *AndroidRunConfiguration::createConfigurationWidget()
|
||||
{
|
||||
auto configWidget = new AndroidRunConfigurationWidget();
|
||||
configWidget->setAmStartArgs(m_amStartExtraArgs);
|
||||
configWidget->setPreStartShellCommands(m_preStartShellCommands);
|
||||
configWidget->setPostFinishShellCommands(m_postFinishShellCommands);
|
||||
connect(configWidget, &AndroidRunConfigurationWidget::amStartArgsChanged,
|
||||
this, &AndroidRunConfiguration::setAmStartExtraArgs);
|
||||
connect(configWidget, &AndroidRunConfigurationWidget::preStartCmdsChanged,
|
||||
this, &AndroidRunConfiguration::setPreStartShellCommands);
|
||||
connect(configWidget, &AndroidRunConfigurationWidget::postFinishCmdsChanged,
|
||||
this, &AndroidRunConfiguration::setPostFinishShellCommands);
|
||||
return configWidget;
|
||||
}
|
||||
auto widget = new QWidget;
|
||||
auto layout = new QFormLayout(widget);
|
||||
|
||||
bool AndroidRunConfiguration::fromMap(const QVariantMap &map)
|
||||
{
|
||||
if (!RunConfiguration::fromMap(map))
|
||||
return false;
|
||||
m_preStartShellCommands = map.value(preStartShellCmdsKey).toStringList();
|
||||
m_postFinishShellCommands = map.value(postFinishShellCmdsKey).toStringList();
|
||||
m_amStartExtraArgs = map.value(amStartArgsKey).toStringList();
|
||||
return true;
|
||||
}
|
||||
extraAspect(Constants::ANDROID_AMSTARTARGS_ASPECT)->addToConfigurationLayout(layout);
|
||||
|
||||
QVariantMap AndroidRunConfiguration::toMap() const
|
||||
{
|
||||
QVariantMap res = RunConfiguration::toMap();
|
||||
res[preStartShellCmdsKey] = m_preStartShellCommands;
|
||||
res[postFinishShellCmdsKey] = m_postFinishShellCommands;
|
||||
res[amStartArgsKey] = m_amStartExtraArgs;
|
||||
return res;
|
||||
}
|
||||
auto warningIconLabel = new QLabel;
|
||||
warningIconLabel->setPixmap(Utils::Icons::WARNING.pixmap());
|
||||
|
||||
const QStringList &AndroidRunConfiguration::amStartExtraArgs() const
|
||||
{
|
||||
return m_amStartExtraArgs;
|
||||
}
|
||||
auto warningLabel = new QLabel(tr("If the \"am start\" options conflict, the application might not start."));
|
||||
layout->addRow(warningIconLabel, warningLabel);
|
||||
|
||||
const QStringList &AndroidRunConfiguration::preStartShellCommands() const
|
||||
{
|
||||
return m_preStartShellCommands;
|
||||
}
|
||||
extraAspect(Constants::ANDROID_PRESTARTSHELLCMDLIST_ASPECT)->addToConfigurationLayout(layout);
|
||||
extraAspect(Constants::ANDROID_POSTSTARTSHELLCMDLIST_ASPECT)->addToConfigurationLayout(layout);
|
||||
|
||||
const QStringList &AndroidRunConfiguration::postFinishShellCommands() const
|
||||
{
|
||||
return m_postFinishShellCommands;
|
||||
auto wrapped = wrapWidget(widget);
|
||||
auto detailsWidget = qobject_cast<DetailsWidget *>(wrapped);
|
||||
QTC_ASSERT(detailsWidget, return wrapped);
|
||||
detailsWidget->setState(DetailsWidget::Expanded);
|
||||
detailsWidget->setSummaryText(tr("Android run settings"));
|
||||
return detailsWidget;
|
||||
}
|
||||
|
||||
void AndroidRunConfiguration::updateTargetInformation()
|
||||
|
||||
Reference in New Issue
Block a user