diff options
author | hjk <hjk121@nokiamail.com> | 2013-08-02 11:41:02 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2013-08-05 09:50:28 +0200 |
commit | 1ec636cbd642e1cb43b2273068000232a8839fe6 (patch) | |
tree | 90d8ab0f6b38f7b28131ab5283f13440eefc04d5 /src/plugins/analyzerbase/ianalyzertool.cpp | |
parent | 92e8f8e59bd312a9da8252bc0eb95ab7d44b45ef (diff) | |
download | qt-creator-1ec636cbd642e1cb43b2273068000232a8839fe6.tar.gz |
Analyzer: Move common startTool implementations to IAnalyzerTool base
Change-Id: I963cb2d025a10cee75b9a9648531c4daeb1b70aa
Reviewed-by: Aurindam Jana <aurindam.jana@digia.com>
Diffstat (limited to 'src/plugins/analyzerbase/ianalyzertool.cpp')
-rw-r--r-- | src/plugins/analyzerbase/ianalyzertool.cpp | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/plugins/analyzerbase/ianalyzertool.cpp b/src/plugins/analyzerbase/ianalyzertool.cpp index f1355824d6..25394f0b56 100644 --- a/src/plugins/analyzerbase/ianalyzertool.cpp +++ b/src/plugins/analyzerbase/ianalyzertool.cpp @@ -30,7 +30,29 @@ #include "ianalyzertool.h" +#include "analyzermanager.h" +#include "analyzerruncontrol.h" +#include "startremotedialog.h" + +#include <coreplugin/icore.h> +#include <coreplugin/imode.h> +#include <coreplugin/modemanager.h> + +#include <projectexplorer/projectexplorer.h> +#include <projectexplorer/project.h> +#include <projectexplorer/buildconfiguration.h> +#include <projectexplorer/target.h> + +#include <utils/qtcassert.h> +#include <utils/checkablemessagebox.h> + +#include <QAction> +#include <QDialog> +#include <QDialogButtonBox> +#include <QSettings> + using namespace Core; +using namespace ProjectExplorer; namespace Analyzer { @@ -78,4 +100,119 @@ AbstractAnalyzerSubConfig *IAnalyzerTool::createProjectSettings() return 0; } +static bool buildTypeAccepted(IAnalyzerTool::ToolMode toolMode, + BuildConfiguration::BuildType buildType) +{ + if (toolMode == IAnalyzerTool::AnyMode) + return true; + if (buildType == BuildConfiguration::Unknown) + return true; + if (buildType == BuildConfiguration::Debug + && toolMode == IAnalyzerTool::DebugMode) + return true; + if (buildType == BuildConfiguration::Release + && toolMode == IAnalyzerTool::ReleaseMode) + return true; + return false; +} + +static void startLocalTool(IAnalyzerTool *tool) +{ + // Make sure mode is shown. + AnalyzerManager::showMode(); + + ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance(); + + // ### not sure if we're supposed to check if the RunConFiguration isEnabled + Project *pro = pe->startupProject(); + BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown; + if (pro) { + if (const Target *target = pro->activeTarget()) { + // Build configuration is 0 for QML projects. + if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration()) + buildType = buildConfig->buildType(); + } + } + + // Check the project for whether the build config is in the correct mode + // if not, notify the user and urge him to use the correct mode. + if (!buildTypeAccepted(tool->toolMode(), buildType)) { + const QString currentMode = buildType == BuildConfiguration::Debug + ? AnalyzerManager::tr("Debug") + : AnalyzerManager::tr("Release"); + + QSettings *settings = ICore::settings(); + const QString configKey = QLatin1String("Analyzer.AnalyzeCorrectMode"); + int ret; + if (settings->contains(configKey)) { + ret = settings->value(configKey, QDialog::Accepted).toInt(); + } else { + QString toolModeString; + switch (tool->toolMode()) { + case IAnalyzerTool::DebugMode: + toolModeString = AnalyzerManager::tr("Debug"); + break; + case IAnalyzerTool::ReleaseMode: + toolModeString = AnalyzerManager::tr("Release"); + break; + default: + QTC_CHECK(false); + } + const QString toolName = tool->displayName(); + const QString title = AnalyzerManager::tr("Run %1 in %2 Mode?").arg(toolName).arg(currentMode); + const QString message = AnalyzerManager::tr("<html><head/><body><p>You are trying " + "to run the tool \"%1\" on an application in %2 mode. " + "The tool is designed to be used in %3 mode.</p><p>" + "Debug and Release mode run-time characteristics differ " + "significantly, analytical findings for one mode may or " + "may not be relevant for the other.</p><p>" + "Do you want to continue and run the tool in %2 mode?</p></body></html>") + .arg(toolName).arg(currentMode).arg(toolModeString); + const QString checkBoxText = AnalyzerManager::tr("&Do not ask again"); + bool checkBoxSetting = false; + const QDialogButtonBox::StandardButton button = + Utils::CheckableMessageBox::question(ICore::mainWindow(), + title, message, checkBoxText, + &checkBoxSetting, QDialogButtonBox::Yes|QDialogButtonBox::Cancel, + QDialogButtonBox::Cancel); + ret = button == QDialogButtonBox::Yes ? QDialog::Accepted : QDialog::Rejected; + + if (checkBoxSetting && ret == QDialog::Accepted) + settings->setValue(configKey, ret); + } + if (ret == QDialog::Rejected) + return; + } + + pe->runProject(pro, tool->runMode()); +} + +static void startRemoteTool(IAnalyzerTool *tool) +{ + StartRemoteDialog dlg; + if (dlg.exec() != QDialog::Accepted) + return; + + AnalyzerStartParameters sp; + sp.startMode = StartRemote; + sp.connParams = dlg.sshParams(); + sp.debuggee = dlg.executable(); + sp.debuggeeArgs = dlg.arguments(); + sp.displayName = dlg.executable(); + sp.workingDirectory = dlg.workingDirectory(); + + AnalyzerRunControl *rc = tool->createRunControl(sp, 0); + QObject::connect(AnalyzerManager::stopAction(), SIGNAL(triggered()), rc, SLOT(stopIt())); + + ProjectExplorerPlugin::instance()->startRunControl(rc, tool->runMode()); +} + +void IAnalyzerTool::startTool(StartMode mode) +{ + if (mode == StartLocal) + startLocalTool(this); + if (mode == StartRemote) + startRemoteTool(this); +} + } // namespace Analyzer |