diff options
Diffstat (limited to 'src')
25 files changed, 1284 insertions, 668 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h b/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h index 4d86ef0741..fbd3ecdd7a 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h @@ -35,8 +35,6 @@ namespace Constants { const char * const PROJECTCONTEXT = "CMakeProject.ProjectContext"; const char * const CMAKEMIMETYPE = "text/x-cmake"; // TOOD check that this is correct -const char * const CMAKERUNCONFIGURATION = "CMakeProjectManager.CMakeRunConfiguration"; - } // namespace Constants } // namespace CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index b3a83d7d33..6d029aaef6 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp @@ -57,8 +57,8 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString * CMakeSettingsPage *cmp = new CMakeSettingsPage(); addAutoReleasedObject(cmp); addAutoReleasedObject(new CMakeManager(cmp)); - addAutoReleasedObject(new MakeStepFactory()); - addAutoReleasedObject(new CMakeRunConfigurationFactory()); + addAutoReleasedObject(new MakeStepFactory); + addAutoReleasedObject(new CMakeRunConfigurationFactory); return true; } diff --git a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp index b9c317333e..787a0d86a5 100644 --- a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp @@ -46,33 +46,73 @@ using namespace CMakeProjectManager; using namespace CMakeProjectManager::Internal; -CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title) - : ProjectExplorer::LocalApplicationRunConfiguration(pro) - , m_runMode(Gui) - , m_target(target) - , m_workingDirectory(workingDirectory) - , m_title(title) - , m_baseEnvironmentBase(CMakeRunConfiguration::BuildEnvironmentBase) +namespace { +const char * const CMAKE_RC_ID("CMakeProjectManager.CMakeRunConfiguration"); +const char * const CMAKE_RC_PREFIX("CMakeProjectManager.CMakeRunConfiguration."); + +const char * const TARGET_KEY("CMakeProjectManager.CMakeRunConfiguration.Target"); +const char * const WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.WorkingDirectory"); +const char * const USER_WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"); +const char * const USE_TERMINAL_KEY("CMakeProjectManager.CMakeRunConfiguration.UseTerminal"); +const char * const TITLE_KEY("CMakeProjectManager.CMakeRunConfiguation.Title"); +const char * const ARGUMENTS_KEY("CMakeProjectManager.CMakeRunConfiguration.Arguments"); +const char * const USER_ENVIRONMENT_CHANGES_KEY("CMakeProjectManager.CMakeRunConfiguration.UserEnvironmentChanges"); +const char * const BASE_ENVIRONMENT_BASE_KEY("CMakeProjectManager.BaseEnvironmentBase"); + +QString targetFromId(const QString &id) { - setDisplayName(title); + if (!id.startsWith(QLatin1String(CMAKE_RC_PREFIX))) + return QString(); + return id.mid(QString::fromLatin1(CMAKE_RC_PREFIX).length()); +} - connect(pro, SIGNAL(environmentChanged()), - this, SIGNAL(baseEnvironmentChanged())); +QString idFromTarget(const QString &target) +{ + return QString::fromLatin1(CMAKE_RC_PREFIX) + target; } -CMakeRunConfiguration::~CMakeRunConfiguration() +} // namespace + +CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title) : + ProjectExplorer::LocalApplicationRunConfiguration(pro, QString::fromLatin1(CMAKE_RC_PREFIX)), + m_runMode(Gui), + m_target(target), + m_workingDirectory(workingDirectory), + m_title(title), + m_baseEnvironmentBase(CMakeRunConfiguration::BuildEnvironmentBase) { + ctor(); +} +CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, CMakeRunConfiguration *source) : + ProjectExplorer::LocalApplicationRunConfiguration(pro, source), + m_runMode(source->m_runMode), + m_target(source->m_target), + m_workingDirectory(source->m_workingDirectory), + m_userWorkingDirectory(source->m_userWorkingDirectory), + m_title(source->m_title), + m_arguments(source->m_arguments), + m_userEnvironmentChanges(source->m_userEnvironmentChanges), + m_baseEnvironmentBase(source->m_baseEnvironmentBase) +{ + ctor(); } -CMakeProject *CMakeRunConfiguration::cmakeProject() const +CMakeRunConfiguration::~CMakeRunConfiguration() { - return static_cast<CMakeProject *>(project()); } -QString CMakeRunConfiguration::id() const +void CMakeRunConfiguration::ctor() { - return Constants::CMAKERUNCONFIGURATION; + setDisplayName(m_title); + + connect(project(), SIGNAL(environmentChanged()), + this, SIGNAL(baseEnvironmentChanged())); +} + +CMakeProject *CMakeRunConfiguration::cmakeProject() const +{ + return static_cast<CMakeProject *>(project()); } QString CMakeRunConfiguration::executable() const @@ -129,32 +169,34 @@ void CMakeRunConfiguration::setUserWorkingDirectory(const QString &wd) emit workingDirectoryChanged(newWorkingDirectory); } -void CMakeRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writer) const +QVariantMap CMakeRunConfiguration::toMap() const { - ProjectExplorer::LocalApplicationRunConfiguration::save(writer); - writer.saveValue("CMakeRunConfiguration.Target", m_target); - writer.saveValue("CMakeRunConfiguration.WorkingDirectory", m_workingDirectory); - writer.saveValue("CMakeRunConfiguration.UserWorkingDirectory", m_userWorkingDirectory); - writer.saveValue("CMakeRunConfiguration.UseTerminal", m_runMode == Console); - writer.saveValue("CMakeRunConfiguation.Title", m_title); - writer.saveValue("CMakeRunConfiguration.Arguments", m_arguments); - writer.saveValue("CMakeRunConfiguration.UserEnvironmentChanges", ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges)); - writer.saveValue("BaseEnvironmentBase", m_baseEnvironmentBase); + QVariantMap map(ProjectExplorer::LocalApplicationRunConfiguration::toMap()); + + map.insert(QLatin1String(TARGET_KEY), m_target); + map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory); + map.insert(QLatin1String(USER_WORKING_DIRECTORY_KEY), m_userWorkingDirectory); + map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == Console); + map.insert(QLatin1String(TITLE_KEY), m_title); + map.insert(QLatin1String(ARGUMENTS_KEY), m_arguments); + map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges)); + map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase); + return map; } -void CMakeRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader) +bool CMakeRunConfiguration::fromMap(const QVariantMap &map) { - ProjectExplorer::LocalApplicationRunConfiguration::restore(reader); - m_target = reader.restoreValue("CMakeRunConfiguration.Target").toString(); - m_workingDirectory = reader.restoreValue("CMakeRunConfiguration.WorkingDirectory").toString(); - m_userWorkingDirectory = reader.restoreValue("CMakeRunConfiguration.UserWorkingDirectory").toString(); - m_runMode = reader.restoreValue("CMakeRunConfiguration.UseTerminal").toBool() ? Console : Gui; - m_title = reader.restoreValue("CMakeRunConfiguation.Title").toString(); - m_arguments = reader.restoreValue("CMakeRunConfiguration.Arguments").toString(); - m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(reader.restoreValue("CMakeRunConfiguration.UserEnvironmentChanges").toStringList()); - QVariant tmp = reader.restoreValue("BaseEnvironmentBase"); - m_baseEnvironmentBase = tmp.isValid() ? BaseEnvironmentBase(tmp.toInt()) : CMakeRunConfiguration::BuildEnvironmentBase; + m_target = map.value(QLatin1String(TARGET_KEY)).toString(); + m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString(); + m_userWorkingDirectory = map.value(QLatin1String(USER_WORKING_DIRECTORY_KEY)).toString(); + m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY)).toBool() ? Console : Gui; + m_title = map.value(QLatin1String(TITLE_KEY)).toString(); + m_arguments = map.value(QLatin1String(ARGUMENTS_KEY)).toString(); + m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList()); + m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(CMakeRunConfiguration::BuildEnvironmentBase)).toInt()); + + return RunConfiguration::fromMap(map); } QWidget *CMakeRunConfiguration::configurationWidget() @@ -406,61 +448,84 @@ void CMakeRunConfigurationWidget::updateSummary() // Factory -CMakeRunConfigurationFactory::CMakeRunConfigurationFactory() +CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) : + ProjectExplorer::IRunConfigurationFactory(parent) { - } CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory() { - -} - -// used to recreate the runConfigurations when restoring settings -bool CMakeRunConfigurationFactory::canRestore(const QString &id) const -{ - if (id.startsWith(Constants::CMAKERUNCONFIGURATION)) - return true; - return false; } // used to show the list of possible additons to a project, returns a list of ids -QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *project) const +QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *parent) const { - CMakeProject *pro = qobject_cast<CMakeProject *>(project); - if (!pro) + CMakeProject *project(qobject_cast<CMakeProject *>(parent)); + if (!project) return QStringList(); - QStringList allTargets = pro->targets(); - for (int i=0; i<allTargets.size(); ++i) { - allTargets[i] = Constants::CMAKERUNCONFIGURATION + allTargets[i]; - } - return allTargets; + QStringList allIds; + foreach (const QString &target, project->targets()) + allIds << idFromTarget(target); + return allIds; } // used to translate the ids to names to display to the user QString CMakeRunConfigurationFactory::displayNameForId(const QString &id) const { - Q_ASSERT(id.startsWith(Constants::CMAKERUNCONFIGURATION)); + return targetFromId(id); +} - if (id == Constants::CMAKERUNCONFIGURATION) - return "CMake"; // Doesn't happen - else - return id.mid(QString(Constants::CMAKERUNCONFIGURATION).length()); +bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const +{ + CMakeProject *project(qobject_cast<CMakeProject *>(parent)); + if (!project) + return false; + return project->hasTarget(targetFromId(id)); } -ProjectExplorer::RunConfiguration* CMakeRunConfigurationFactory::create(ProjectExplorer::Project *project, const QString &id) +ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id) { - CMakeProject *pro = qobject_cast<CMakeProject *>(project); - Q_ASSERT(pro); - if (id == Constants::CMAKERUNCONFIGURATION) { - // Restoring, filename will be added by restoreSettings - ProjectExplorer::RunConfiguration* rc = new CMakeRunConfiguration(pro, QString::null, QString::null, QString::null); - return rc; - } else { - // Adding new - const QString title = id.mid(QString(Constants::CMAKERUNCONFIGURATION).length()); - const CMakeTarget &ct = pro->targetForTitle(title); - ProjectExplorer::RunConfiguration * rc = new CMakeRunConfiguration(pro, ct.executable, ct.workingDirectory, ct.title); + if (!canCreate(parent, id)) + return 0; + CMakeProject *project(static_cast<CMakeProject *>(parent)); + + const QString title(targetFromId(id)); + const CMakeTarget &ct = project->targetForTitle(title); + return new CMakeRunConfiguration(project, ct.executable, ct.workingDirectory, ct.title); +} + +bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const +{ + if (!qobject_cast<CMakeProject *>(parent)) + return false; + return source->id() == QLatin1String(CMAKE_RC_ID); +} + +ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration * source) +{ + if (!canClone(parent, source)) + return 0; + CMakeProject *project(static_cast<CMakeProject *>(parent)); + CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source)); + return new CMakeRunConfiguration(project, crc); +} + +bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const +{ + if (!qobject_cast<CMakeProject *>(parent)) + return false; + QString id(ProjectExplorer::idFromMap(map)); + return id.startsWith(QLatin1String(CMAKE_RC_ID)); +} + +ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map) +{ + if (!canRestore(parent, map)) + return 0; + CMakeProject *project(static_cast<CMakeProject *>(parent)); + CMakeRunConfiguration *rc(new CMakeRunConfiguration(project, QString(), QString(), QString())); + if (rc->fromMap(map)) return rc; - } + delete rc; + return 0; } diff --git a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.h b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.h index de700e06c4..67130a46ae 100644 --- a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.h +++ b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.h @@ -48,20 +48,23 @@ class CMakeProject; class CMakeRunConfiguration : public ProjectExplorer::LocalApplicationRunConfiguration { - friend class CMakeRunConfigurationWidget; Q_OBJECT + friend class CMakeRunConfigurationWidget; + friend class CMakeRunConfigurationFactory; + public: - CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title); - virtual ~CMakeRunConfiguration(); + CMakeRunConfiguration(CMakeProject *project, const QString &target, + const QString &workingDirectory, const QString &title); + ~CMakeRunConfiguration(); + CMakeProject *cmakeProject() const; - virtual QString id() const; - virtual QString executable() const; - virtual RunMode runMode() const; - virtual QString workingDirectory() const; - virtual QStringList commandLineArguments() const; - virtual ProjectExplorer::Environment environment() const; - virtual QWidget *configurationWidget(); + QString executable() const; + RunMode runMode() const; + QString workingDirectory() const; + QStringList commandLineArguments() const; + ProjectExplorer::Environment environment() const; + QWidget *configurationWidget(); void setExecutable(const QString &executable); void setWorkingDirectory(const QString &workingDirectory); @@ -70,11 +73,11 @@ public: QString title() const; - virtual void save(ProjectExplorer::PersistentSettingsWriter &writer) const; - virtual void restore(const ProjectExplorer::PersistentSettingsReader &reader); - virtual QString dumperLibrary() const; - virtual QStringList dumperLibraryLocations() const; - virtual ProjectExplorer::ToolChain::ToolChainType toolChainType() const; + QString dumperLibrary() const; + QStringList dumperLibraryLocations() const; + ProjectExplorer::ToolChain::ToolChainType toolChainType() const; + + QVariantMap toMap() const; signals: void baseEnvironmentChanged(); @@ -83,7 +86,14 @@ signals: private slots: void setArguments(const QString &newText); + +protected: + CMakeRunConfiguration(CMakeProject *project, CMakeRunConfiguration *source); + virtual bool fromMap(const QVariantMap &map); + private: + void ctor(); + enum BaseEnvironmentBase { CleanEnvironmentBase = 0, SystemEnvironmentBase = 1, BuildEnvironmentBase = 2}; @@ -110,6 +120,7 @@ class CMakeRunConfigurationWidget : public QWidget Q_OBJECT public: CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent = 0); + private slots: void setArguments(const QString &args); void baseEnvironmentChanged(); @@ -117,10 +128,13 @@ private slots: void userChangesChanged(); void setWorkingDirectory(); void resetWorkingDirectory(); + private slots: void baseEnvironmentComboBoxChanged(int index); void workingDirectoryChanged(const QString &workingDirectory); + private: + void ctor(); void updateSummary(); bool m_ignoreChange; CMakeRunConfiguration *m_cmakeRunConfiguration; @@ -133,19 +147,24 @@ private: class CMakeRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory { Q_OBJECT + public: - CMakeRunConfigurationFactory(); - virtual ~CMakeRunConfigurationFactory(); + explicit CMakeRunConfigurationFactory(QObject *parent = 0); + ~CMakeRunConfigurationFactory(); // used to recreate the runConfigurations when restoring settings - virtual bool canRestore(const QString &id) const; + bool canCreate(ProjectExplorer::Project *project, const QString &id) const; + ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id); + bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const; + ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map); + bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *product) const; + ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *product); + // used to show the list of possible additons to a project, returns a list of types - virtual QStringList availableCreationIds(ProjectExplorer::Project *pro) const; + QStringList availableCreationIds(ProjectExplorer::Project *pro) const; // used to translate the types to names to display to the user - virtual QString displayNameForId(const QString &id) const; - virtual ProjectExplorer::RunConfiguration* create(ProjectExplorer::Project *project, const QString &id); + QString displayNameForId(const QString &id) const; }; - } } diff --git a/src/plugins/projectexplorer/applicationrunconfiguration.cpp b/src/plugins/projectexplorer/applicationrunconfiguration.cpp index a134387c58..32cd11e241 100644 --- a/src/plugins/projectexplorer/applicationrunconfiguration.cpp +++ b/src/plugins/projectexplorer/applicationrunconfiguration.cpp @@ -28,7 +28,7 @@ **************************************************************************/ #include "applicationrunconfiguration.h" -#include "persistentsettings.h" + #include "environment.h" #include <projectexplorer/projectexplorerconstants.h> @@ -36,36 +36,24 @@ #include <QtCore/QDir> #include <QtGui/QLabel> -#include <QtGui/QTextDocument> -#include <QDebug> using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; /// LocalApplicationRunConfiguration -LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Project *pro) - : RunConfiguration(pro) -{ -} - -LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration() +LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Project *project, const QString &id) : + RunConfiguration(project, id) { } -QString LocalApplicationRunConfiguration::id() const +LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Project *project, LocalApplicationRunConfiguration *rc) : + RunConfiguration(project, rc) { - return "ProjectExplorer.LocalApplicationRunConfiguration"; } -void LocalApplicationRunConfiguration::save(PersistentSettingsWriter &writer) const -{ - RunConfiguration::save(writer); -} - -void LocalApplicationRunConfiguration::restore(const PersistentSettingsReader &reader) +LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration() { - RunConfiguration::restore(reader); } /// LocalApplicationRunControlFactory diff --git a/src/plugins/projectexplorer/applicationrunconfiguration.h b/src/plugins/projectexplorer/applicationrunconfiguration.h index e59be18b0a..877c80829e 100644 --- a/src/plugins/projectexplorer/applicationrunconfiguration.h +++ b/src/plugins/projectexplorer/applicationrunconfiguration.h @@ -48,9 +48,7 @@ public: Gui }; - LocalApplicationRunConfiguration(Project *pro); virtual ~LocalApplicationRunConfiguration(); - virtual QString id() const; virtual QString executable() const = 0; virtual RunMode runMode() const = 0; virtual QString workingDirectory() const = 0; @@ -60,8 +58,9 @@ public: virtual QStringList dumperLibraryLocations() const = 0; virtual ProjectExplorer::ToolChain::ToolChainType toolChainType() const = 0; - virtual void save(PersistentSettingsWriter &writer) const; - virtual void restore(const PersistentSettingsReader &reader); +protected: + LocalApplicationRunConfiguration(Project *project, const QString &id); + LocalApplicationRunConfiguration(Project *project, LocalApplicationRunConfiguration *rc); }; namespace Internal { diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp index eef1bb28bd..51689dfd57 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp @@ -30,30 +30,42 @@ #include "customexecutablerunconfiguration.h" #include "environment.h" #include "project.h" -#include "persistentsettings.h" -#include "environmenteditmodel.h" #include <coreplugin/icore.h> -#include <projectexplorer/debugginghelper.h> #include <projectexplorer/buildconfiguration.h> +#include <projectexplorer/environmenteditmodel.h> +#include <projectexplorer/debugginghelper.h> #include <utils/detailswidget.h> #include <utils/pathchooser.h> #include <QtGui/QCheckBox> +#include <QtGui/QComboBox> +#include <QtGui/QDialog> +#include <QtGui/QDialogButtonBox> #include <QtGui/QFormLayout> -#include <QtGui/QLineEdit> +#include <QtGui/QHBoxLayout> #include <QtGui/QLabel> +#include <QtGui/QLineEdit> #include <QtGui/QMainWindow> -#include <QtGui/QHBoxLayout> -#include <QtGui/QToolButton> -#include <QtGui/QFileDialog> -#include <QtGui/QGroupBox> -#include <QtGui/QComboBox> -#include <QDialogButtonBox> using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; +namespace { +const char * const CUSTOM_EXECUTABLE_ID("ProjectExplorer.CustomExecutableRunConfiguration"); + +const char * const EXECUTABLE_KEY("ProjectExplorer.CustomExecutableRunConfiguration.Executable"); +const char * const ARGUMENTS_KEY("ProjectExplorer.CustomExecutableRunConfiguration.Arguments"); +const char * const WORKING_DIRECTORY_KEY("ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory"); +const char * const USE_TERMINAL_KEY("ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal"); +const char * const USER_SET_NAME_KEY("ProjectExplorer.CustomExecutableRunConfiguration.UserSetName"); +const char * const USER_NAME_KEY("ProjectExplorer.CustomExecutableRunConfiguration.UserName"); +const char * const USER_ENVIRONMENT_CHANGES_KEY("ProjectExplorer.CustomExecutableRunConfiguration.UserEnvironmentChanges"); +const char * const BASE_ENVIRONMENT_BASE_KEY("ProjectExplorer.CustomExecutableRunConfiguration.BaseEnvironmentBase"); + +const char * const DEFAULT_WORKING_DIR("$BUILDDIR"); +} + class CustomDirectoryPathChooser : public Utils::PathChooser { public: @@ -245,19 +257,16 @@ void CustomExecutableConfigurationWidget::changed() m_userName->setText(m_runConfiguration->userName()); } -CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Project *pro) - : LocalApplicationRunConfiguration(pro), - m_runMode(Gui), - m_userSetName(false), - m_baseEnvironmentBase(CustomExecutableRunConfiguration::BuildEnvironmentBase) +void CustomExecutableRunConfiguration::ctor() { - m_workingDirectory = "$BUILDDIR"; - setDisplayName(tr("Custom Executable")); - - connect(pro, SIGNAL(activeBuildConfigurationChanged()), + if (m_userSetName) + setDisplayName(m_userName); + else + setDisplayName(tr("Custom Executable")); + connect(project(), SIGNAL(activeBuildConfigurationChanged()), this, SLOT(activeBuildConfigurationChanged())); - m_lastActiveBuildConfiguration = pro->activeBuildConfiguration(); + m_lastActiveBuildConfiguration = activeBuildConfiguration(); if (m_lastActiveBuildConfiguration) { connect(m_lastActiveBuildConfiguration, SIGNAL(environmentChanged()), @@ -265,6 +274,30 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Project *pro) } } +CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Project *project) : + LocalApplicationRunConfiguration(project, QLatin1String(CUSTOM_EXECUTABLE_ID)), + m_runMode(Gui), + m_userSetName(false), + m_baseEnvironmentBase(CustomExecutableRunConfiguration::BuildEnvironmentBase) +{ + m_workingDirectory = QLatin1String(DEFAULT_WORKING_DIR); + ctor(); +} + +CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Project *project, CustomExecutableRunConfiguration *source) : + LocalApplicationRunConfiguration(project, source), + m_executable(source->m_executable), + m_workingDirectory(source->m_workingDirectory), + m_cmdArguments(source->m_cmdArguments), + m_runMode(source->m_runMode), + m_userSetName(source->m_userSetName), + m_userName(source->m_userName), + m_userEnvironmentChanges(source->m_userEnvironmentChanges), + m_baseEnvironmentBase(source->m_baseEnvironmentBase) +{ + ctor(); +} + CustomExecutableRunConfiguration::~CustomExecutableRunConfiguration() { } @@ -275,18 +308,13 @@ void CustomExecutableRunConfiguration::activeBuildConfigurationChanged() disconnect(m_lastActiveBuildConfiguration, SIGNAL(environmentChanged()), this, SIGNAL(baseEnvironmentChanged())); } - m_lastActiveBuildConfiguration = project()->activeBuildConfiguration(); + m_lastActiveBuildConfiguration = activeBuildConfiguration(); if (m_lastActiveBuildConfiguration) { connect(m_lastActiveBuildConfiguration, SIGNAL(environmentChanged()), this, SIGNAL(baseEnvironmentChanged())); } } -QString CustomExecutableRunConfiguration::id() const -{ - return "ProjectExplorer.CustomExecutableRunConfiguration"; -} - QString CustomExecutableRunConfiguration::baseExecutable() const { return m_executable; @@ -301,7 +329,7 @@ QString CustomExecutableRunConfiguration::executable() const { QString exec; if (QDir::isRelativePath(m_executable)) { - Environment env = project()->activeBuildConfiguration()->environment(); + Environment env = activeBuildConfiguration()->environment(); exec = env.searchInPath(m_executable); if (exec.isEmpty()) exec = QDir::cleanPath(workingDirectory() + "/" + m_executable); @@ -333,7 +361,7 @@ QString CustomExecutableRunConfiguration::executable() const that->m_workingDirectory = oldWorkingDirectory; that->m_cmdArguments = oldCmdArguments; emit that->changed(); - return QString::null; + return QString(); } } return exec; @@ -352,7 +380,7 @@ QString CustomExecutableRunConfiguration::baseWorkingDirectory() const QString CustomExecutableRunConfiguration::workingDirectory() const { QString wd = m_workingDirectory; - QString bd = project()->activeBuildConfiguration()->buildDirectory(); + QString bd = activeBuildConfiguration()->buildDirectory(); return wd.replace("$BUILDDIR", QDir::cleanPath(bd)); } @@ -381,7 +409,7 @@ ProjectExplorer::Environment CustomExecutableRunConfiguration::baseEnvironment() } else if (m_baseEnvironmentBase == CustomExecutableRunConfiguration::SystemEnvironmentBase) { env = ProjectExplorer::Environment::systemEnvironment(); } else if (m_baseEnvironmentBase == CustomExecutableRunConfiguration::BuildEnvironmentBase) { - env = project()->activeBuildConfiguration()->environment(); + env = activeBuildConfiguration()->environment(); } return env; } @@ -419,31 +447,32 @@ void CustomExecutableRunConfiguration::setUserEnvironmentChanges(const QList<Pro } } -void CustomExecutableRunConfiguration::save(PersistentSettingsWriter &writer) const +QVariantMap CustomExecutableRunConfiguration::toMap() const { - writer.saveValue("Executable", m_executable); - writer.saveValue("Arguments", m_cmdArguments); - writer.saveValue("WorkingDirectory", m_workingDirectory); - writer.saveValue("UseTerminal", m_runMode == Console); - writer.saveValue("UserSetName", m_userSetName); - writer.saveValue("UserName", m_userName); - writer.saveValue("UserEnvironmentChanges", ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges)); - writer.saveValue("BaseEnvironmentBase", m_baseEnvironmentBase); - LocalApplicationRunConfiguration::save(writer); + QVariantMap map(LocalApplicationRunConfiguration::toMap()); + map.insert(QLatin1String(EXECUTABLE_KEY), m_executable); + map.insert(QLatin1String(ARGUMENTS_KEY), m_cmdArguments); + map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory); + map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == Console); + map.insert(QLatin1String(USER_SET_NAME_KEY), m_userSetName); + map.insert(QLatin1String(USER_NAME_KEY), m_userName); + map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges)); + map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(m_baseEnvironmentBase)); + return map; } -void CustomExecutableRunConfiguration::restore(const PersistentSettingsReader &reader) +bool CustomExecutableRunConfiguration::fromMap(const QVariantMap &map) { - m_executable = reader.restoreValue("Executable").toString(); - m_cmdArguments = reader.restoreValue("Arguments").toStringList(); - m_workingDirectory = reader.restoreValue("WorkingDirectory").toString(); - m_runMode = reader.restoreValue("UseTerminal").toBool() ? Console : Gui; - m_userSetName = reader.restoreValue("UserSetName").toBool(); - m_userName = reader.restoreValue("UserName").toString(); - m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(reader.restoreValue("UserEnvironmentChanges").toStringList()); - LocalApplicationRunConfiguration::restore(reader); - QVariant tmp = reader.restoreValue("BaseEnvironmentBase"); - m_baseEnvironmentBase = tmp.isValid() ? BaseEnvironmentBase(tmp.toInt()) : CustomExecutableRunConfiguration::BuildEnvironmentBase; + m_executable = map.value(QLatin1String(EXECUTABLE_KEY)).toString(); + m_cmdArguments = map.value(QLatin1String(ARGUMENTS_KEY)).toStringList(); + m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString(); + m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY)).toBool() ? Console : Gui; + m_userSetName = map.value(QLatin1String(USER_SET_NAME_KEY)).toBool(); + m_userName = map.value(QLatin1String(USER_NAME_KEY)).toString(); + m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList()); + m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(CustomExecutableRunConfiguration::BuildEnvironmentBase)).toInt()); + + return RunConfiguration::fromMap(map); } void CustomExecutableRunConfiguration::setExecutable(const QString &executable) @@ -512,7 +541,8 @@ ProjectExplorer::ToolChain::ToolChainType CustomExecutableRunConfiguration::tool // Factory -CustomExecutableRunConfigurationFactory::CustomExecutableRunConfigurationFactory() +CustomExecutableRunConfigurationFactory::CustomExecutableRunConfigurationFactory(QObject *parent) : + ProjectExplorer::IRunConfigurationFactory(parent) { } @@ -521,33 +551,60 @@ CustomExecutableRunConfigurationFactory::~CustomExecutableRunConfigurationFactor } -// used to recreate the runConfigurations when restoring settings -bool CustomExecutableRunConfigurationFactory::canRestore(const QString &id) const +bool CustomExecutableRunConfigurationFactory::canCreate(Project *project, const QString &id) const +{ + Q_UNUSED(project); + return id == QLatin1String(CUSTOM_EXECUTABLE_ID); +} + +RunConfiguration *CustomExecutableRunConfigurationFactory::create(Project *project, const QString &id) +{ + if (!canCreate(project, id)) + return 0; + + RunConfiguration *rc(new CustomExecutableRunConfiguration(project)); + rc->setDisplayName(tr("Custom Executable")); + return rc; +} + +bool CustomExecutableRunConfigurationFactory::canRestore(Project *project, const QVariantMap &map) const { - return id == "ProjectExplorer.CustomExecutableRunConfiguration"; + QString id(idFromMap(map)); + return canCreate(project, id); } -RunConfiguration* CustomExecutableRunConfigurationFactory::create(Project *project, const QString &id) +RunConfiguration *CustomExecutableRunConfigurationFactory::restore(Project *project, const QVariantMap &map) { - if (id == "ProjectExplorer.CustomExecutableRunConfiguration") { - RunConfiguration* rc = new CustomExecutableRunConfiguration(project); - rc->setDisplayName(tr("Custom Executable")); + if (!canRestore(project, map)) + return 0; + CustomExecutableRunConfiguration *rc(new CustomExecutableRunConfiguration(project)); + if (rc->fromMap(map)) return rc; - } else { + delete rc; + return 0; +} + +bool CustomExecutableRunConfigurationFactory::canClone(Project *parent, RunConfiguration *source) const +{ + return canCreate(parent, source->id()); +} + +RunConfiguration *CustomExecutableRunConfigurationFactory::clone(Project *parent, RunConfiguration *source) +{ + if (!canClone(parent, source)) return 0; - } + return new CustomExecutableRunConfiguration(parent, static_cast<CustomExecutableRunConfiguration*>(source)); } -QStringList CustomExecutableRunConfigurationFactory::availableCreationIds(Project *pro) const +QStringList CustomExecutableRunConfigurationFactory::availableCreationIds(Project *project) const { - Q_UNUSED(pro) - return QStringList()<< "ProjectExplorer.CustomExecutableRunConfiguration"; + Q_UNUSED(project) + return QStringList() << QLatin1String(CUSTOM_EXECUTABLE_ID); } QString CustomExecutableRunConfigurationFactory::displayNameForId(const QString &id) const { - if (id == "ProjectExplorer.CustomExecutableRunConfiguration") + if (id == QLatin1String(CUSTOM_EXECUTABLE_ID)) return tr("Custom Executable"); - else - return QString(); + return QString(); } diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.h b/src/plugins/projectexplorer/customexecutablerunconfiguration.h index 25cf9bbd82..e4b3f58eb8 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.h +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.h @@ -31,6 +31,8 @@ #define CUSTOMEXECUTABLERUNCONFIGURATION_H #include "applicationrunconfiguration.h" + +#include <QtCore/QVariantMap> #include <QtGui/QWidget> QT_BEGIN_NAMESPACE @@ -49,25 +51,27 @@ class PathChooser; namespace ProjectExplorer { class EnvironmentWidget; namespace Internal { - class CustomExecutableConfigurationWidget; +class CustomExecutableConfigurationWidget; } +class CustomExecutableRunConfigurationFactory; + class PROJECTEXPLORER_EXPORT CustomExecutableRunConfiguration : public LocalApplicationRunConfiguration { + Q_OBJECT // the configuration widget needs to setExecutable setWorkingDirectory and setCommandLineArguments friend class Internal::CustomExecutableConfigurationWidget; - Q_OBJECT + friend class CustomExecutableRunConfigurationFactory; public: - CustomExecutableRunConfiguration(Project *pro); + explicit CustomExecutableRunConfiguration(Project *project); ~CustomExecutableRunConfiguration(); - virtual QString id() const; /** * Returns the executable, looks in the environment for it and might even * ask the user if none is specified */ - virtual QString executable() const; + QString executable() const; /** * Returns only what is stored in the internal variable, not what we might @@ -81,20 +85,19 @@ public: */ QString userName() const; - virtual LocalApplicationRunConfiguration::RunMode runMode() const; - virtual QString workingDirectory() const; + LocalApplicationRunConfiguration::RunMode runMode() const; + QString workingDirectory() const; QString baseWorkingDirectory() const; - virtual QStringList commandLineArguments() const; - virtual Environment environment() const; + QStringList commandLineArguments() const; + Environment environment() const; - virtual void save(PersistentSettingsWriter &writer) const; - virtual void restore(const PersistentSettingsReader &reader); + QWidget *configurationWidget(); + QString dumperLibrary() const; + QStringList dumperLibraryLocations() const; - virtual QWidget *configurationWidget(); - virtual QString dumperLibrary() const; - virtual QStringList dumperLibraryLocations() const; + ProjectExplorer::ToolChain::ToolChainType toolChainType() const; - virtual ProjectExplorer::ToolChain::ToolChainType toolChainType() const; + QVariantMap toMap() const; signals: void changed(); @@ -105,7 +108,13 @@ signals: private slots: void activeBuildConfigurationChanged(); +protected: + CustomExecutableRunConfiguration(Project *project, CustomExecutableRunConfiguration *source); + virtual bool fromMap(const QVariantMap &map); + private: + void ctor(); + enum BaseEnvironmentBase { CleanEnvironmentBase = 0, SystemEnvironmentBase = 1, BuildEnvironmentBase = 2}; @@ -137,13 +146,18 @@ class CustomExecutableRunConfigurationFactory : public IRunConfigurationFactory Q_OBJECT public: - CustomExecutableRunConfigurationFactory(); - virtual ~CustomExecutableRunConfigurationFactory(); - // used to recreate the runConfigurations when restoring settings - virtual bool canRestore(const QString &id) const; - virtual RunConfiguration* create(Project *project, const QString &id); - QStringList availableCreationIds(Project *pro) const; + explicit CustomExecutableRunConfigurationFactory(QObject *parent = 0); + ~CustomExecutableRunConfigurationFactory(); + + QStringList availableCreationIds(Project *project) const; QString displayNameForId(const QString &id) const; + + bool canCreate(Project *project, const QString &id) const; + RunConfiguration *create(Project *project, const QString &id); + bool canRestore(Project *project, const QVariantMap &map) const; + RunConfiguration *restore(Project *project, const QVariantMap &map); + bool canClone(Project *parent, RunConfiguration *product) const; + RunConfiguration *clone(Project *parent, RunConfiguration *source); }; namespace Internal { diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 9a46598d26..5608f5ee06 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -168,9 +168,7 @@ void Project::saveSettingsImpl(PersistentSettingsWriter &writer) int i = 0; int activeId = 0; foreach (RunConfiguration* rc, m_runConfigurations) { - writer.setPrefix("RunConfiguration" + QString().setNum(i) + "-"); - writer.saveValue("Id", rc->id()); - rc->save(writer); + writer.saveValue("RunConfiguration" + QString().setNum(i), rc->toMap()); if (rc == m_activeRunConfiguration) activeId = i; ++i; @@ -209,15 +207,14 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader) const QList<IRunConfigurationFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IRunConfigurationFactory>(); forever { - reader.setPrefix("RunConfiguration" + QString().setNum(i) + "-"); - const QVariant &idVariant = reader.restoreValue("Id"); - if (!idVariant.isValid()) + QVariantMap values(reader.restoreValue("RunConfiguration" + QString().setNum(i)).toMap()); + if (values.isEmpty()) break; - const QString &id = idVariant.toString(); foreach (IRunConfigurationFactory *factory, factories) { - if (factory->canRestore(id)) { - RunConfiguration* rc = factory->create(this, id); - rc->restore(reader); + if (factory->canRestore(this, values)) { + RunConfiguration* rc = factory->restore(this, values); + if (!rc) + continue; addRunConfiguration(rc); if (i == activeId) setActiveRunConfiguration(rc); @@ -225,9 +222,7 @@ bool Project::restoreSettingsImpl(PersistentSettingsReader &reader) } ++i; } - reader.setPrefix(QString::null); - - if (!m_activeRunConfiguration && !m_runConfigurations.isEmpty()) + if (!activeRunConfiguration() && !m_runConfigurations.isEmpty()) setActiveRunConfiguration(m_runConfigurations.at(0)); QVariantMap tmp = reader.restoreValue(QLatin1String(EDITOR_SETTINGS_KEY)).toMap(); diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index ca11b487f8..ea9c38d8ce 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -42,18 +42,28 @@ using namespace ProjectExplorer; // RunConfiguration -RunConfiguration::RunConfiguration(Project *project) - : m_project(project) +RunConfiguration::RunConfiguration(Project *project, const QString &id) : + ProjectConfiguration(id), + m_project(project) { + Q_ASSERT(m_project); +} + +RunConfiguration::RunConfiguration(Project *project, RunConfiguration *source) : + ProjectConfiguration(source), + m_project(project) +{ + Q_ASSERT(m_project); } RunConfiguration::~RunConfiguration() { } -Project *RunConfiguration::project() const +bool RunConfiguration::isEnabled(BuildConfiguration *bc) const { - return m_project.data(); + Q_UNUSED(bc); + return true; } bool RunConfiguration::isEnabled() const @@ -66,32 +76,20 @@ bool RunConfiguration::isEnabled() const return isEnabled(m_project->activeBuildConfiguration()); } -QString RunConfiguration::displayName() const -{ - return m_displayName; -} - -void RunConfiguration::setDisplayName(const QString &name) -{ - m_displayName = name; - emit displayNameChanged(); -} - -void RunConfiguration::save(PersistentSettingsWriter &writer) const +BuildConfiguration *RunConfiguration::activeBuildConfiguration() const { - writer.saveValue("RunConfiguration.name", m_displayName); + if (!project()) + return 0; + return project()->activeBuildConfiguration(); } -void RunConfiguration::restore(const PersistentSettingsReader &reader) +Project *RunConfiguration::project() const { - QVariant var = reader.restoreValue("RunConfiguration.name"); - if (var.isValid() && !var.toString().isEmpty()) - m_displayName = var.toString(); + return m_project; } - -IRunConfigurationFactory::IRunConfigurationFactory(QObject *parent) - : QObject(parent) +IRunConfigurationFactory::IRunConfigurationFactory(QObject *parent) : + QObject(parent) { } diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index 3f17b21013..9293b01107 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -30,11 +30,10 @@ #ifndef RUNCONFIGURATION_H #define RUNCONFIGURATION_H +#include "projectconfiguration.h" #include "projectexplorer_export.h" -#include <QtCore/QObject> #include <QtCore/QMetaType> -#include <QtCore/QPointer> #include <QtCore/QWeakPointer> QT_BEGIN_NAMESPACE @@ -45,8 +44,6 @@ QT_END_NAMESPACE namespace ProjectExplorer { class Project; -class PersistentSettingsReader; -class PersistentSettingsWriter; class RunControl; class BuildConfiguration; @@ -62,34 +59,36 @@ class BuildConfiguration; * for a project, but stil be runnable via the output tab. */ -class PROJECTEXPLORER_EXPORT RunConfiguration : public QObject +class PROJECTEXPLORER_EXPORT RunConfiguration : public ProjectConfiguration { Q_OBJECT + public: - explicit RunConfiguration(Project *project); virtual ~RunConfiguration(); - Project *project() const; - // The type of this RunConfiguration, e.g. "ProjectExplorer.LocalApplicationRunConfiguration" - virtual QString id() const = 0; - // Name shown to the user - QString displayName() const; - void setDisplayName(const QString &name); - - virtual bool isEnabled(BuildConfiguration *) const { return true; } + // Used to find out whether a runconfiguration works with the given + // buildconfiguration. + // Note: bc may be 0! + virtual bool isEnabled(BuildConfiguration *bc) const; + // Used to find out whether a runconfiguration works with the active + // buildconfiguration. bool isEnabled() const; // Returns the widget used to configure this run configuration. Ownership is transferred to the caller // rename to createConfigurationWidget virtual QWidget *configurationWidget() = 0; - virtual void save(PersistentSettingsWriter &writer) const; - virtual void restore(const PersistentSettingsReader &reader); -signals: - void displayNameChanged(); + Project *project() const; + +protected: + RunConfiguration(Project *project, const QString &id); + RunConfiguration(Project *project, RunConfiguration *source); + + // convenience method to get current build configuration. + BuildConfiguration *activeBuildConfiguration() const; + private: - QPointer<Project> m_project; - QString m_displayName; + Project *m_project; }; /* The run configuration factory is used for restoring run configurations from @@ -100,20 +99,29 @@ private: * QString displayNameForType(const QString&) are used to generate a list of creatable * RunConfigurations, and create(..) is used to create it. */ -class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : public QObject +class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : + public QObject { Q_OBJECT + public: explicit IRunConfigurationFactory(QObject *parent = 0); virtual ~IRunConfigurationFactory(); - // used to recreate the runConfigurations when restoring settings - virtual bool canRestore(const QString &id) const = 0; + // used to show the list of possible additons to a project, returns a list of types - virtual QStringList availableCreationIds(Project *pro) const = 0; + virtual QStringList availableCreationIds(Project *parent) const = 0; // used to translate the types to names to display to the user virtual QString displayNameForId(const QString &id) const = 0; - // used to create a run configuration from scratch - virtual RunConfiguration* create(Project *project, const QString &id) = 0; + + virtual bool canCreate(Project *parent, const QString &id) const = 0; + virtual RunConfiguration *create(Project *parent, const QString &id) = 0; + virtual bool canRestore(Project *parent, const QVariantMap &map) const = 0; + virtual RunConfiguration *restore(Project *parent, const QVariantMap &map) = 0; + virtual bool canClone(Project *parent, RunConfiguration *product) const = 0; + virtual RunConfiguration *clone(Project *parent, RunConfiguration *product) = 0; + +signals: + void availableCreationIdsChanged(); }; class PROJECTEXPLORER_EXPORT IRunControlFactory : public QObject diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 2a25f9a91b..4e6cfea0ae 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -65,9 +65,17 @@ using namespace QmlProjectManager; using namespace QmlProjectManager::Internal; using namespace ProjectExplorer; -enum { - debug = false -}; +namespace { +const char * const QML_RC_ID("QmlProjectManager.QmlRunConfiguration"); +const char * const QML_RC_DISPLAY_NAME(QT_TRANSLATE_NOOP("QmlProjectManager::Internal::QmlRunConfiguration", "QML Viewer")); + +const char * const QML_VIEWER_KEY("QmlProjectManager.QmlRunConfiguration.QmlViewer"); +const char * const QML_VIEWER_ARGUMENTS_KEY("QmlProjectManager.QmlRunConfiguration.QmlViewerArguments"); +const char * const QML_MAINSCRIPT_KEY("QmlProjectManager.QmlRunConfiguration.MainScript"); +const char * const QML_DEBUG_SERVER_PORT_KEY("QmlProjectManager.QmlRunConfiguration.DebugServerPort"); + +const int DEFAULT_DEBUG_SERVER_PORT(3768); +} // namespace //////////////////////////////////////////////////////////////////////////////////// // QmlProject @@ -343,18 +351,35 @@ void QmlProjectFile::modified(ReloadBehavior *) { } -QmlRunConfiguration::QmlRunConfiguration(QmlProject *pro) - : ProjectExplorer::RunConfiguration(pro), - m_project(pro), - m_debugServerPort(3768) +//////////////////////////////////////////////////////////////////////////////////// +// QmlRunConfiguration +//////////////////////////////////////////////////////////////////////////////////// + +QmlRunConfiguration::QmlRunConfiguration(QmlProject *parent) : + ProjectExplorer::RunConfiguration(parent, QLatin1String(QML_RC_ID)), + m_debugServerPort(DEFAULT_DEBUG_SERVER_PORT) +{ + ctor(); +} + +QmlRunConfiguration::QmlRunConfiguration(QmlProject *parent, QmlRunConfiguration *source) : + ProjectExplorer::RunConfiguration(parent, source), + m_scriptFile(source->m_scriptFile), + m_qmlViewerCustomPath(source->m_qmlViewerCustomPath), + m_qmlViewerArgs(source->m_qmlViewerArgs), + m_debugServerPort(source->m_debugServerPort) { - setDisplayName(tr("QML Viewer")); + ctor(); +} + +void QmlRunConfiguration::ctor() +{ + setDisplayName(tr("QML Viewer", "QMLRunConfiguration display name.")); // prepend creator/bin dir to search path (only useful for special creator-qml package) const QString searchPath = QCoreApplication::applicationDirPath() + Utils::SynchronousProcess::pathSeparator() + QString(qgetenv("PATH")); - m_qmlViewerDefaultPath = Utils::SynchronousProcess::locateBinary(searchPath, QLatin1String("qmlviewer")); } @@ -362,9 +387,9 @@ QmlRunConfiguration::~QmlRunConfiguration() { } -QString QmlRunConfiguration::id() const +QmlProject *QmlRunConfiguration::qmlProject() const { - return QLatin1String(Constants::QMLRUNCONFIGURATION); + return static_cast<QmlProject *>(project()); } QString QmlRunConfiguration::viewerPath() const @@ -389,7 +414,7 @@ QStringList QmlRunConfiguration::viewerArguments() const QString QmlRunConfiguration::workingDirectory() const { - QFileInfo projectFile(m_project->file()->fileName()); + QFileInfo projectFile(qmlProject()->file()->fileName()); return projectFile.absolutePath(); } @@ -405,14 +430,14 @@ QWidget *QmlRunConfiguration::configurationWidget() QComboBox *combo = new QComboBox; - QDir projectDir = m_project->projectDir(); + QDir projectDir = qmlProject()->projectDir(); QStringList files; files.append(tr("<Current File>")); int currentIndex = -1; - foreach (const QString &fn, m_project->files()) { + foreach (const QString &fn, qmlProject()->files()) { QFileInfo fileInfo(fn); if (fileInfo.suffix() != QLatin1String("qml")) continue; @@ -462,7 +487,7 @@ QString QmlRunConfiguration::mainScript() const } } - return m_project->projectDir().absoluteFilePath(m_scriptFile); + return qmlProject()->projectDir().absoluteFilePath(m_scriptFile); } void QmlRunConfiguration::setMainScript(const QString &scriptFile) @@ -490,32 +515,33 @@ void QmlRunConfiguration::onDebugServerPortChanged() } } -void QmlRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writer) const +QVariantMap QmlRunConfiguration::toMap() const { - ProjectExplorer::RunConfiguration::save(writer); + QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); - writer.saveValue(QLatin1String("qmlviewer"), m_qmlViewerCustomPath); - writer.saveValue(QLatin1String("qmlviewerargs"), m_qmlViewerArgs); - writer.saveValue(QLatin1String("mainscript"), m_scriptFile); - writer.saveValue(QLatin1String("debugserverport"), m_debugServerPort); + map.insert(QLatin1String(QML_VIEWER_KEY), m_qmlViewerCustomPath); + map.insert(QLatin1String(QML_VIEWER_ARGUMENTS_KEY), m_qmlViewerArgs); + map.insert(QLatin1String(QML_MAINSCRIPT_KEY), m_scriptFile); + map.insert(QLatin1String(QML_DEBUG_SERVER_PORT_KEY), m_debugServerPort); + return map; } -void QmlRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader) +bool QmlRunConfiguration::fromMap(const QVariantMap &map) { - ProjectExplorer::RunConfiguration::restore(reader); - - m_qmlViewerCustomPath = reader.restoreValue(QLatin1String("qmlviewer")).toString(); - m_qmlViewerArgs = reader.restoreValue(QLatin1String("qmlviewerargs")).toString(); - m_scriptFile = reader.restoreValue(QLatin1String("mainscript")).toString(); - m_debugServerPort = reader.restoreValue(QLatin1String("debugserverport")).toUInt(); + m_qmlViewerCustomPath = map.value(QLatin1String(QML_VIEWER_KEY)).toString(); + m_qmlViewerArgs = map.value(QLatin1String(QML_VIEWER_ARGUMENTS_KEY)).toString(); + m_scriptFile = map.value(QLatin1String(QML_MAINSCRIPT_KEY), tr("<Current File>")).toString(); + m_debugServerPort = map.value(QLatin1String(QML_DEBUG_SERVER_PORT_KEY), DEFAULT_DEBUG_SERVER_PORT).toUInt(); - if (m_scriptFile.isEmpty()) - m_scriptFile = tr("<Current File>"); - if (m_debugServerPort == 0) - m_debugServerPort = 3768; + return RunConfiguration::fromMap(map); } -QmlRunConfigurationFactory::QmlRunConfigurationFactory() +//////////////////////////////////////////////////////////////////////////////////// +// QmlRunConfigurationFactory +//////////////////////////////////////////////////////////////////////////////////// + +QmlRunConfigurationFactory::QmlRunConfigurationFactory(QObject *parent) : + ProjectExplorer::IRunConfigurationFactory(parent) { } @@ -523,31 +549,68 @@ QmlRunConfigurationFactory::~QmlRunConfigurationFactory() { } -bool QmlRunConfigurationFactory::canRestore(const QString &id) const +QStringList QmlRunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *) const { - if (id.startsWith(QLatin1String(Constants::QMLRUNCONFIGURATION))) - return true; + return QStringList() << QLatin1String(QML_RC_ID); +} - return false; +QString QmlRunConfigurationFactory::displayNameForId(const QString &id) const +{ + if (id == QLatin1String(QML_RC_ID)) + return tr("Run QML Script"); + return QString(); } -QStringList QmlRunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *) const +bool QmlRunConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const { - return QStringList(); + if (!qobject_cast<QmlProject *>(parent)) + return false; + return id == QLatin1String(QML_RC_ID); } -QString QmlRunConfigurationFactory::displayNameForId(const QString &id) const +ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id) +{ + if (!canCreate(parent, id)) + return 0; + QmlProject *project(static_cast<QmlProject *>(parent)); + return new QmlRunConfiguration(project); +} + +bool QmlRunConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const +{ + QString id(idFromMap(map)); + return canCreate(parent, id); +} + +ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map) { - return id; + if (!canRestore(parent, map)) + return 0; + QmlProject *project(static_cast<QmlProject *>(parent)); + QmlRunConfiguration *rc(new QmlRunConfiguration(project)); + if (rc->fromMap(map)) + return rc; + delete rc; + return 0; } -ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::create(ProjectExplorer::Project *project, - const QString &) +bool QmlRunConfigurationFactory::canClone(ProjectExplorer::Project *parent, RunConfiguration *source) const { - QmlProject *pro = qobject_cast<QmlProject *>(project); - return new QmlRunConfiguration(pro); + return canCreate(parent, source->id()); } +ProjectExplorer::RunConfiguration *QmlRunConfigurationFactory::clone(ProjectExplorer::Project *parent, RunConfiguration *source) +{ + if (!canClone(parent, source)) + return 0; + QmlProject *project(static_cast<QmlProject *>(parent)); + return new QmlRunConfiguration(project, qobject_cast<QmlRunConfiguration *>(source)); +} + +//////////////////////////////////////////////////////////////////////////////////// +// QmlRunControl +//////////////////////////////////////////////////////////////////////////////////// + QmlRunControl::QmlRunControl(QmlRunConfiguration *runConfiguration, bool debugMode) : RunControl(runConfiguration), m_debugMode(debugMode) { diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 96d836f084..c011dc2484 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -89,20 +89,23 @@ class QmlRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFact Q_OBJECT public: - QmlRunConfigurationFactory(); + explicit QmlRunConfigurationFactory(QObject *parent = 0); virtual ~QmlRunConfigurationFactory(); - // used to recreate the runConfigurations when restoring settings - virtual bool canRestore(const QString &id) const; - // used to show the list of possible additons to a project, returns a list of types virtual QStringList availableCreationIds(ProjectExplorer::Project *pro) const; - // used to translate the types to names to display to the user virtual QString displayNameForId(const QString &id) const; - virtual ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, - const QString &id); + virtual bool canCreate(ProjectExplorer::Project *parent, const QString &id) const; + virtual ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id); + + // used to recreate the runConfigurations when restoring settings + virtual bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const; + virtual ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map); + + virtual bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const; + virtual ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source); }; class QmlRunControl : public ProjectExplorer::RunControl { @@ -217,31 +220,38 @@ private: class QMLPROJECTMANAGER_EXPORT QmlRunConfiguration : public ProjectExplorer::RunConfiguration { Q_OBJECT + friend class Internal::QmlRunConfigurationFactory; + public: - QmlRunConfiguration(QmlProject *pro); + QmlRunConfiguration(QmlProject *parent); virtual ~QmlRunConfiguration(); + QmlProject *qmlProject() const; + QString viewerPath() const; QStringList viewerArguments() const; QString workingDirectory() const; uint debugServerPort() const; // RunConfiguration - virtual QString id() const; virtual QWidget *configurationWidget(); - virtual void save(ProjectExplorer::PersistentSettingsWriter &writer) const; - virtual void restore(const ProjectExplorer::PersistentSettingsReader &reader); + QVariantMap toMap() const; -private Q_SLOTS: +private slots: QString mainScript() const; void setMainScript(const QString &scriptFile); void onQmlViewerChanged(); void onQmlViewerArgsChanged(); void onDebugServerPortChanged(); +protected: + QmlRunConfiguration(QmlProject *parent, QmlRunConfiguration *source); + virtual bool fromMap(const QVariantMap &map); + private: - QmlProject *m_project; + void ctor(); + QString m_scriptFile; QString m_qmlViewerCustomPath; QString m_qmlViewerDefaultPath; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp index b40dd3b909..2745dda31e 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp @@ -50,6 +50,48 @@ #include <QtCore/QDebug> #include <QtCore/QProcess> +namespace { +const char * const MAEMO_RC_ID("Qt4ProjectManager.MaemoRunConfiguration"); +const char * const MAEMO_RC_ID_PREFIX("Qt4ProjectManager.MaemoRunConfiguration."); + +bool hasMaemoRunConfig(ProjectExplorer::Project* project) +{ + Qt4ProjectManager::Qt4Project *qt4Project( + qobject_cast<Qt4ProjectManager::Qt4Project *>(project)); + if (qt4Project) { + QList<ProjectExplorer::RunConfiguration *> list = + qt4Project->runConfigurations(); + foreach (ProjectExplorer::RunConfiguration *rc, list) { + if (qobject_cast<Qt4ProjectManager::Internal::MaemoRunConfiguration *>(rc)) + return true; + } + } + return false; +} + +QString targetFromId(const QString &id) +{ + QString prefix(MAEMO_RC_ID_PREFIX); + if (!id.startsWith(prefix)) + return QString(); + return id.mid(prefix.size()); +} + +QString targetToId(const QString &target) +{ + return QString::fromLatin1(MAEMO_RC_ID_PREFIX) + target; +} + +} // namespace + +static const QLatin1String ArgumentsKey("Arguments"); +static const QLatin1String SimulatorPathKey("Simulator"); +static const QLatin1String DeviceIdKey("DeviceId"); +static const QLatin1String LastDeployedKey("LastDeployed"); +static const QLatin1String DebuggingHelpersLastDeployedKey( + "DebuggingHelpersLastDeployed"); +static const QLatin1String ProFileKey("ProFile"); + namespace Qt4ProjectManager { namespace Internal { @@ -96,22 +138,46 @@ void ErrorDumper::printToStream(QProcess::ProcessError error) // #pragma mark -- MaemoRunConfiguration - -static const QLatin1String ArgumentsKey("Arguments"); -static const QLatin1String SimulatorPathKey("Simulator"); -static const QLatin1String DeviceIdKey("DeviceId"); -static const QLatin1String LastDeployedKey("LastDeployed"); -static const QLatin1String DebuggingHelpersLastDeployedKey( - "DebuggingHelpersLastDeployed"); - -MaemoRunConfiguration::MaemoRunConfiguration(Project *project, +MaemoRunConfiguration::MaemoRunConfiguration(Qt4Project *project, const QString &proFilePath) - : RunConfiguration(project) + : RunConfiguration(project, QLatin1String(MAEMO_RC_ID)) , m_proFilePath(proFilePath) , m_cachedTargetInformationValid(false) , m_cachedSimulatorInformationValid(false) , qemu(0) { + ctor(); +} + +MaemoRunConfiguration::MaemoRunConfiguration(Qt4Project *project, + MaemoRunConfiguration *source) + : RunConfiguration(project, source) + , m_executable(source->m_executable) + , m_proFilePath(source->m_proFilePath) + , m_cachedTargetInformationValid(false) + , m_simulator(source->m_simulator) + , m_simulatorArgs(source->m_simulatorArgs) + , m_simulatorPath(source->m_simulatorPath) + , m_visibleSimulatorParameter(source->m_visibleSimulatorParameter) + , m_cachedSimulatorInformationValid(false) + , m_isUserSetSimulator(source->m_isUserSetSimulator) + , m_userSimulatorPath(source->m_userSimulatorPath) + , m_gdbPath(source->m_gdbPath) + , m_devConfig(source->m_devConfig) + , m_arguments(source->m_arguments) + , m_lastDeployed(source->m_lastDeployed) + , m_debuggingHelpersLastDeployed(source->m_debuggingHelpersLastDeployed) + , qemu(0) +#if USE_SSL_PASSWORD + , m_remoteUserPassword(source->m_remoteUserPassword) + , m_remoteHostRequiresPassword(source->m_remoteHostRequiresPassword) +#endif +{ + ctor(); +} + +void MaemoRunConfiguration::ctor() +{ if (!m_proFilePath.isEmpty()) { setDisplayName(tr("%1 on Maemo device").arg(QFileInfo(m_proFilePath) .completeBaseName())); @@ -122,13 +188,13 @@ MaemoRunConfiguration::MaemoRunConfiguration(Project *project, connect(&MaemoDeviceConfigurations::instance(), SIGNAL(updated()), this, SLOT(updateDeviceConfigurations())); - connect(project, SIGNAL(targetInformationChanged()), + connect(qt4Project(), SIGNAL(targetInformationChanged()), this, SLOT(invalidateCachedTargetInformation())); - connect(project, SIGNAL(targetInformationChanged()), + connect(qt4Project(), SIGNAL(targetInformationChanged()), this, SLOT(enabledStateChanged())); - connect(project, SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), + connect(qt4Project(), SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), this, SLOT(proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode*))); qemu = new QProcess(this); @@ -148,16 +214,9 @@ MaemoRunConfiguration::~MaemoRunConfiguration() qemu = NULL; } -QString MaemoRunConfiguration::id() const -{ - return QLatin1String("Qt4ProjectManager.MaemoRunConfiguration"); -} - -Qt4Project *MaemoRunConfiguration::project() const +Qt4Project *MaemoRunConfiguration::qt4Project() const { - Qt4Project *pro = qobject_cast<Qt4Project *>(RunConfiguration::project()); - Q_ASSERT(pro != 0); - return pro; + return static_cast<Qt4Project *>(project()); } bool MaemoRunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *config) const @@ -179,40 +238,40 @@ void MaemoRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFil invalidateCachedTargetInformation(); } - -void MaemoRunConfiguration::save(PersistentSettingsWriter &writer) const +QVariantMap MaemoRunConfiguration::toMap() const { - writer.saveValue(DeviceIdKey, m_devConfig.internalId); - writer.saveValue(ArgumentsKey, m_arguments); + QVariantMap map(RunConfiguration::toMap()); + map.insert(DeviceIdKey, m_devConfig.internalId); + map.insert(ArgumentsKey, m_arguments); - writer.saveValue(LastDeployedKey, m_lastDeployed); - writer.saveValue(DebuggingHelpersLastDeployedKey, + map.insert(LastDeployedKey, m_lastDeployed); + map.insert(DebuggingHelpersLastDeployedKey, m_debuggingHelpersLastDeployed); - writer.saveValue(SimulatorPathKey, m_simulatorPath); + map.insert(SimulatorPathKey, m_simulatorPath); - const QDir &dir = QFileInfo(project()->file()->fileName()).absoluteDir(); - writer.saveValue("ProFile", dir.relativeFilePath(m_proFilePath)); + const QDir &dir = QFileInfo(qt4Project()->file()->fileName()).absoluteDir(); + map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath)); - RunConfiguration::save(writer); + return map; } -void MaemoRunConfiguration::restore(const PersistentSettingsReader &reader) +bool MaemoRunConfiguration::fromMap(const QVariantMap &map) { - RunConfiguration::restore(reader); - setDeviceConfig(MaemoDeviceConfigurations::instance(). - find(reader.restoreValue(DeviceIdKey).toInt())); - m_arguments = reader.restoreValue(ArgumentsKey).toStringList(); + find(map.value(DeviceIdKey, 0).toInt())); + m_arguments = map.value(ArgumentsKey).toStringList(); - m_lastDeployed = reader.restoreValue(LastDeployedKey).toDateTime(); + m_lastDeployed = map.value(LastDeployedKey).toDateTime(); m_debuggingHelpersLastDeployed = - reader.restoreValue(DebuggingHelpersLastDeployedKey).toDateTime(); + map.value(DebuggingHelpersLastDeployedKey).toDateTime(); + + m_simulatorPath = map.value(SimulatorPathKey).toString(); - m_simulatorPath = reader.restoreValue(SimulatorPathKey).toString(); + const QDir &dir = QFileInfo(qt4Project()->file()->fileName()).absoluteDir(); + m_proFilePath = dir.filePath(map.value(ProFileKey).toString()); - const QDir &dir = QFileInfo(project()->file()->fileName()).absoluteDir(); - m_proFilePath = dir.filePath(reader.restoreValue("ProFile").toString()); + return RunConfiguration::fromMap(map); } bool MaemoRunConfiguration::currentlyNeedsDeployment() const @@ -227,7 +286,7 @@ void MaemoRunConfiguration::wasDeployed() bool MaemoRunConfiguration::hasDebuggingHelpers() const { - Qt4BuildConfiguration *qt4bc = project()->activeQt4BuildConfiguration(); + Qt4BuildConfiguration *qt4bc = qt4Project()->activeQt4BuildConfiguration(); return qt4bc->qtVersion()->hasDebuggingHelper(); } @@ -283,7 +342,7 @@ const QString MaemoRunConfiguration::cmd(const QString &cmdName) const const MaemoToolChain *MaemoRunConfiguration::toolchain() const { Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *> - (project()->activeBuildConfiguration()); + (qt4Project()->activeBuildConfiguration()); QTC_ASSERT(qt4bc, return 0); MaemoToolChain *tc = dynamic_cast<MaemoToolChain *>( qt4bc->toolChain() ); @@ -319,7 +378,7 @@ const QStringList MaemoRunConfiguration::arguments() const const QString MaemoRunConfiguration::dumperLib() const { - Qt4BuildConfiguration *qt4bc = project()->activeQt4BuildConfiguration(); + Qt4BuildConfiguration *qt4bc = qt4Project()->activeQt4BuildConfiguration(); return qt4bc->qtVersion()->debuggingHelperLibrary(); } @@ -415,7 +474,7 @@ void MaemoRunConfiguration::updateTarget() m_executable = QString::null; m_cachedTargetInformationValid = true; - Qt4TargetInformation info = project()->targetInformation(project()->activeQt4BuildConfiguration(), + Qt4TargetInformation info = qt4Project()->targetInformation(qt4Project()->activeQt4BuildConfiguration(), m_proFilePath); if (info.error != Qt4TargetInformation::NoError) { if (info.error == Qt4TargetInformation::ProParserError) { @@ -547,92 +606,116 @@ void MaemoRunConfiguration::updateDeviceConfigurations() // #pragma mark -- MaemoRunConfigurationFactory -MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject* parent) - : IRunConfigurationFactory(parent) +MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject *parent) : + IRunConfigurationFactory(parent) { + ProjectExplorerPlugin *explorer = ProjectExplorerPlugin::instance(); + connect(explorer->session(), SIGNAL(projectAdded(ProjectExplorer::Project*)), + this, SLOT(projectAdded(ProjectExplorer::Project*))); + connect(explorer->session(), SIGNAL(projectRemoved(ProjectExplorer::Project*)), + this, SLOT(projectRemoved(ProjectExplorer::Project*))); + connect(explorer, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), + this, SLOT(currentProjectChanged(ProjectExplorer::Project*))); } MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory() { } -bool MaemoRunConfigurationFactory::canRestore(const QString &id) const +bool MaemoRunConfigurationFactory::canCreate(Project *parent, + const QString &id) const { - return id == "Qt4ProjectManager.MaemoRunConfiguration"; + if (!qobject_cast<Qt4Project *>(parent)) + return false; + return id.startsWith(QLatin1String(MAEMO_RC_ID)); } -QStringList MaemoRunConfigurationFactory::availableCreationIds( - Project *pro) const +bool MaemoRunConfigurationFactory::canRestore(Project *parent, + const QVariantMap &map) const { - Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro); - if (qt4project) { - QStringList applicationProFiles; - QList<Qt4ProFileNode *> list = qt4project->applicationProFiles(); - foreach (Qt4ProFileNode * node, list) { - applicationProFiles.append("MaemoRunConfiguration." + node->path()); - } - return applicationProFiles; - } - return QStringList(); + QString id(ProjectExplorer::idFromMap(map)); + return canCreate(parent, id); +} + +bool MaemoRunConfigurationFactory::canClone(Project *parent, + RunConfiguration *source) const +{ + QString id(source->id()); + return canCreate(parent, id); +} + +QStringList MaemoRunConfigurationFactory::availableCreationIds(Project *pro) const +{ + Qt4Project *qt4Project(qobject_cast<Qt4Project *>(pro)); + if (!qt4Project) + return QStringList(); + + return qt4Project->applicationProFilePathes(QLatin1String(MAEMO_RC_ID_PREFIX)); } QString MaemoRunConfigurationFactory::displayNameForId(const QString &id) const { - const int size = QString::fromLocal8Bit("MaemoRunConfiguration.").size(); - return tr("%1 on Maemo Device").arg(QFileInfo(id.mid(size)) - .completeBaseName()); + QString target(targetFromId(id)); + if (target.isEmpty()) + return QString(); + return tr("%1 on Maemo Device").arg(QFileInfo(target).completeBaseName()); } -RunConfiguration *MaemoRunConfigurationFactory::create(Project *project, - const QString &id) +RunConfiguration *MaemoRunConfigurationFactory::create(Project *parent, + const QString &id) { - Qt4Project *qt4project = qobject_cast<Qt4Project *>(project); - Q_ASSERT(qt4project); + if (!canCreate(parent, id)) + return 0; + Qt4Project *pqt4parent(static_cast<Qt4Project *>(parent)); + MaemoRunConfiguration *rc(new MaemoRunConfiguration(pqt4parent, targetFromId(id))); + setupRunConfiguration(rc); + return rc; - connect(project, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration *)), - this, SLOT(addedRunConfiguration(ProjectExplorer::RunConfiguration *))); - connect(project, SIGNAL(removedRunConfiguration(RunConfiguration *)), - this, SLOT(removedRunConfiguration(ProjectExplorer::RunConfiguration *))); +} - RunConfiguration *rc = 0; - const QLatin1String prefix("MaemoRunConfiguration."); - if (id.startsWith(prefix)) { - rc = new MaemoRunConfiguration(qt4project, id.mid(QString(prefix).size())); - } else { - Q_ASSERT(id == "Qt4ProjectManager.MaemoRunConfiguration"); - rc = new MaemoRunConfiguration(qt4project, QString::null); - } +RunConfiguration *MaemoRunConfigurationFactory::restore(Project *parent, + const QVariantMap &map) +{ + if (!canRestore(parent, map)) + return 0; + Qt4Project *qt4Project(qobject_cast<Qt4Project *>(parent)); + Q_ASSERT(qt4Project); - if (rc) { - connect(project, SIGNAL(runConfigurationsEnabledStateChanged()), - rc, SLOT(enabledStateChanged())); - connect(MaemoManager::instance(), SIGNAL(startStopQemu()), rc, - SLOT(startStopQemu())); - connect(rc, SIGNAL(qemuProcessStatus(bool)), - MaemoManager::instance(), SLOT(updateQemuSimulatorStarter(bool))); + MaemoRunConfiguration *rc(new MaemoRunConfiguration(qt4Project, QString())); + if (!rc->fromMap(map)) { + delete rc; + return 0; } - ProjectExplorerPlugin *explorer = ProjectExplorerPlugin::instance(); - connect(explorer->session(), SIGNAL(projectAdded(ProjectExplorer::Project*)), - this, SLOT(projectAdded(ProjectExplorer::Project*))); - connect(explorer->session(), SIGNAL(projectRemoved(ProjectExplorer::Project*)), - this, SLOT(projectRemoved(ProjectExplorer::Project*))); - connect(explorer, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), - this, SLOT(currentProjectChanged(ProjectExplorer::Project*))); + setupRunConfiguration(rc); + return rc; +} + +RunConfiguration *MaemoRunConfigurationFactory::clone(Project *parent, + RunConfiguration *source) +{ + if (!canClone(parent, source)) + return 0; + Qt4Project *qt4Project(static_cast<Qt4Project *>(parent)); + MaemoRunConfiguration *old(static_cast<MaemoRunConfiguration *>(source)); + MaemoRunConfiguration *rc(new MaemoRunConfiguration(qt4Project, old)); + + setupRunConfiguration(rc); return rc; } -bool hasMaemoRunConfig(ProjectExplorer::Project* project) +void MaemoRunConfigurationFactory::setupRunConfiguration(MaemoRunConfiguration *rc) { - if (Qt4Project *qt4Project = qobject_cast<Qt4Project *>(project)) { - QList<RunConfiguration *> list = qt4Project->runConfigurations(); - foreach (RunConfiguration *rc, list) { - if (qobject_cast<MaemoRunConfiguration *>(rc)) - return true; - } - } - return false; + if (!rc) + return; + + connect(rc->project(), SIGNAL(runConfigurationsEnabledStateChanged()), + rc, SLOT(enabledStateChanged())); + connect(MaemoManager::instance(), SIGNAL(startStopQemu()), + rc, SLOT(startStopQemu())); + connect(rc, SIGNAL(qemuProcessStatus(bool)), + MaemoManager::instance(), SLOT(updateQemuSimulatorStarter(bool))); } void MaemoRunConfigurationFactory::addedRunConfiguration(ProjectExplorer::RunConfiguration *rc) @@ -650,6 +733,13 @@ void MaemoRunConfigurationFactory::removedRunConfiguration(ProjectExplorer::RunC void MaemoRunConfigurationFactory::projectAdded( ProjectExplorer::Project *project) { + connect(project, SIGNAL(addedRunConfiguration(ProjectExplorer::Project*, + QString)), + this, SLOT(addedRunConfiguration(ProjectExplorer::Project*))); + connect(project, SIGNAL(removedRunConfiguration(ProjectExplorer::Project*, + QString)), + this, SLOT(removedRunConfiguration(ProjectExplorer::Project*))); + if (hasMaemoRunConfig(project)) MaemoManager::instance()->addQemuSimulatorStarter(project); } @@ -657,6 +747,13 @@ void MaemoRunConfigurationFactory::projectAdded( void MaemoRunConfigurationFactory::projectRemoved( ProjectExplorer::Project *project) { + disconnect(project, SIGNAL(addedRunConfiguration(ProjectExplorer::Project*, + QString)), + this, SLOT(addedRunConfiguration(ProjectExplorer::Project*))); + disconnect(project, SIGNAL(removedRunConfiguration(ProjectExplorer::Project*, + QString)), + this, SLOT(removedRunConfiguration(ProjectExplorer::Project*))); + if (hasMaemoRunConfig(project)) MaemoManager::instance()->removeQemuSimulatorStarter(project); } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h index c12f2671ff..1da3fb24d4 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h @@ -61,23 +61,22 @@ public slots: void printToStream(QProcess::ProcessError error); }; +class MaemoRunConfigurationFactory; class MaemoRunConfiguration : public ProjectExplorer::RunConfiguration { Q_OBJECT + friend class MaemoRunConfigurationFactory; + public: - MaemoRunConfiguration(ProjectExplorer::Project *project, + MaemoRunConfiguration(Qt4Project *project, const QString &proFilePath); - ~MaemoRunConfiguration(); + virtual ~MaemoRunConfiguration(); - QString id() const; bool isEnabled(ProjectExplorer::BuildConfiguration *config) const; using RunConfiguration::isEnabled; QWidget *configurationWidget(); - Qt4Project *project() const; - - void save(ProjectExplorer::PersistentSettingsWriter &writer) const; - void restore(const ProjectExplorer::PersistentSettingsReader &reader); + Qt4Project *qt4Project() const; bool currentlyNeedsDeployment() const; void wasDeployed(); @@ -115,12 +114,19 @@ public: bool remoteHostRequiresPassword() const { return m_remoteHostRequiresPassword; } #endif + virtual QVariantMap toMap() const; + signals: void deviceConfigurationsUpdated(); void targetInformationChanged(); void cachedSimulatorInformationChanged(); void qemuProcessStatus(bool running); +protected: + MaemoRunConfiguration(Qt4Project *project, + MaemoRunConfiguration *source); + virtual bool fromMap(const QVariantMap &map); + private slots: void proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro); void updateDeviceConfigurations(); @@ -136,13 +142,13 @@ private slots: void enabledStateChanged(); private: + void ctor(); void updateTarget(); void updateSimulatorInformation(); const QString cmd(const QString &cmdName) const; const MaemoToolChain *toolchain() const; bool fileNeedsDeployment(const QString &path, const QDateTime &lastDeployed) const; -private: QString m_executable; QString m_proFilePath; bool m_cachedTargetInformationValid; @@ -176,13 +182,19 @@ private: class MaemoRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory { Q_OBJECT + public: - MaemoRunConfigurationFactory(QObject *parent); + explicit MaemoRunConfigurationFactory(QObject *parent = 0); ~MaemoRunConfigurationFactory(); - bool canRestore(const QString &id) const; QStringList availableCreationIds(ProjectExplorer::Project *project) const; QString displayNameForId(const QString &id) const; + + bool canRestore(ProjectExplorer::Project *project, const QVariantMap &map) const; + bool canClone(ProjectExplorer::Project *project, ProjectExplorer::RunConfiguration *source) const; + bool canCreate(ProjectExplorer::Project *project, const QString &id) const; + ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Project *project, const QVariantMap &map); + ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Project *project, ProjectExplorer::RunConfiguration *source); ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id); private slots: @@ -192,6 +204,9 @@ private slots: void projectAdded(ProjectExplorer::Project *project); void projectRemoved(ProjectExplorer::Project *project); void currentProjectChanged(ProjectExplorer::Project *project); + +private: + void setupRunConfiguration(MaemoRunConfiguration *rc); }; diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp index 233269e43c..803800b8be 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp @@ -58,17 +58,31 @@ using namespace ProjectExplorer; using namespace Qt4ProjectManager; using namespace Qt4ProjectManager::Internal; -enum { debug = 0 }; - -static const int PROGRESS_PACKAGECREATED = 100; -static const int PROGRESS_PACKAGESIGNED = 200; -static const int PROGRESS_DEPLOYBASE = 200; -static const int PROGRESS_PACKAGEDEPLOYED = 300; -static const int PROGRESS_PACKAGEINSTALLED = 400; -static const int PROGRESS_MAX = 400; +namespace { +const char * const S60_DEVICE_RC_ID("Qt4ProjectManager.S60DeviceRunConfiguration"); +const char * const S60_DEVICE_RC_PREFIX("Qt4ProjectManager.S60DeviceRunConfiguration."); + +const char * const PRO_FILE_KEY("Qt4ProjectManager.S60DeviceRunConfiguration.ProFile"); +const char * const SIGNING_MODE_KEY("Qt4ProjectManager.S60DeviceRunConfiguration.SigningMode"); +const char * const CUSTOM_SIGNATURE_PATH_KEY("Qt4ProjectManager.S60DeviceRunConfiguration.CustomSignaturePath"); +const char * const CUSTOM_KEY_PATH_KEY("Qt4ProjectManager.S60DeviceRunConfiguration.CustomKeyPath"); +const char * const SERIAL_PORT_NAME_KEY("Qt4ProjectManager.S60DeviceRunConfiguration.SerialPortName"); +const char * const COMMUNICATION_TYPE_KEY("Qt4ProjectManager.S60DeviceRunConfiguration.CommunicationType"); +const char * const COMMAND_LINE_ARGUMENTS_KEY("Qt4ProjectManager.S60DeviceRunConfiguration.CommandLineArguments"); + +const int PROGRESS_PACKAGECREATED = 100; +const int PROGRESS_PACKAGESIGNED = 200; +const int PROGRESS_DEPLOYBASE = 200; +const int PROGRESS_PACKAGEDEPLOYED = 300; +const int PROGRESS_PACKAGEINSTALLED = 400; +const int PROGRESS_MAX = 400; + +enum { + debug = false +}; // Format information about a file -static QString lsFile(const QString &f) +QString lsFile(const QString &f) { QString rc; const QFileInfo fi(f); @@ -77,9 +91,25 @@ static QString lsFile(const QString &f) return rc; } + +QString pathFromId(const QString &id) +{ + if (!id.startsWith(QLatin1String(S60_DEVICE_RC_PREFIX))) + return QString(); + return id.mid(QString::fromLatin1(S60_DEVICE_RC_PREFIX).size()); +} + +QString pathToId(const QString &path) +{ + return QString::fromLatin1(S60_DEVICE_RC_PREFIX) + path; +} + +} + // ======== S60DeviceRunConfiguration -S60DeviceRunConfiguration::S60DeviceRunConfiguration(Project *project, const QString &proFilePath) - : RunConfiguration(project), + +S60DeviceRunConfiguration::S60DeviceRunConfiguration(Project *project, const QString &proFilePath) : + RunConfiguration(project, pathToId(proFilePath)), m_proFilePath(proFilePath), m_cachedTargetInformationValid(false), #ifdef Q_OS_WIN @@ -91,24 +121,42 @@ S60DeviceRunConfiguration::S60DeviceRunConfiguration(Project *project, const QSt #endif m_signingMode(SignSelf) { + ctor(); +} + +S60DeviceRunConfiguration::S60DeviceRunConfiguration(Project *project, S60DeviceRunConfiguration *source) : + RunConfiguration(project, source), + m_proFilePath(source->m_proFilePath), + m_cachedTargetInformationValid(false), + m_serialPortName(source->m_serialPortName), + m_communicationType(source->m_communicationType), + m_signingMode(source->m_signingMode), + m_customSignaturePath(source->m_customSignaturePath), + m_customKeyPath(source->m_customKeyPath) +{ + ctor(); +} + +void S60DeviceRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro) +{ + if (m_proFilePath == pro->path()) + invalidateCachedTargetInformation(); +} + +void S60DeviceRunConfiguration::ctor() +{ if (!m_proFilePath.isEmpty()) setDisplayName(tr("%1 on Symbian Device").arg(QFileInfo(m_proFilePath).completeBaseName())); else setDisplayName(tr("QtS60DeviceRunConfiguration")); - connect(project, SIGNAL(targetInformationChanged()), + connect(qt4Project(), SIGNAL(targetInformationChanged()), this, SLOT(invalidateCachedTargetInformation())); - connect(project, SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), + connect(qt4Project(), SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), this, SLOT(proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode*))); } -void S60DeviceRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro) -{ - if (m_proFilePath == pro->path()) - invalidateCachedTargetInformation(); -} - S60DeviceRunConfiguration::~S60DeviceRunConfiguration() { @@ -119,11 +167,6 @@ Qt4Project *S60DeviceRunConfiguration::qt4Project() const return static_cast<Qt4Project *>(project()); } -QString S60DeviceRunConfiguration::id() const -{ - return QLatin1String("Qt4ProjectManager.DeviceRunConfiguration"); -} - ProjectExplorer::ToolChain::ToolChainType S60DeviceRunConfiguration::toolChainType( ProjectExplorer::BuildConfiguration *configuration) const { @@ -151,30 +194,35 @@ QWidget *S60DeviceRunConfiguration::configurationWidget() return new S60DeviceRunConfigurationWidget(this); } -void S60DeviceRunConfiguration::save(PersistentSettingsWriter &writer) const +QVariantMap S60DeviceRunConfiguration::toMap() const { + QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir(); - writer.saveValue("ProFile", projectDir.relativeFilePath(m_proFilePath)); - writer.saveValue("SigningMode", (int)m_signingMode); - writer.saveValue("CustomSignaturePath", m_customSignaturePath); - writer.saveValue("CustomKeyPath", m_customKeyPath); - writer.saveValue("SerialPortName", m_serialPortName); - writer.saveValue("CommunicationType", m_communicationType); - writer.saveValue("CommandLineArguments", m_commandLineArguments); - RunConfiguration::save(writer); + + map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath)); + map.insert(QLatin1String(SIGNING_MODE_KEY), (int)m_signingMode); + map.insert(QLatin1String(CUSTOM_SIGNATURE_PATH_KEY), m_customSignaturePath); + map.insert(QLatin1String(CUSTOM_KEY_PATH_KEY), m_customKeyPath); + map.insert(QLatin1String(SERIAL_PORT_NAME_KEY), m_serialPortName); + map.insert(QLatin1String(COMMUNICATION_TYPE_KEY), m_communicationType); + map.insert(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY), m_commandLineArguments); + + return map; } -void S60DeviceRunConfiguration::restore(const PersistentSettingsReader &reader) +bool S60DeviceRunConfiguration::fromMap(const QVariantMap &map) { - RunConfiguration::restore(reader); - const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir(); - m_proFilePath = projectDir.filePath(reader.restoreValue("ProFile").toString()); - m_signingMode = (SigningMode)reader.restoreValue("SigningMode").toInt(); - m_customSignaturePath = reader.restoreValue("CustomSignaturePath").toString(); - m_customKeyPath = reader.restoreValue("CustomKeyPath").toString(); - m_serialPortName = reader.restoreValue("SerialPortName").toString().trimmed(); - m_communicationType = reader.restoreValue("CommunicationType").toInt(); - m_commandLineArguments = reader.restoreValue("CommandLineArguments").toStringList(); + const QDir projectDir = QFileInfo(qt4Project()->file()->fileName()).absoluteDir(); + + m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString()); + m_signingMode = static_cast<SigningMode>(map.value(QLatin1String(SIGNING_MODE_KEY)).toInt()); + m_customSignaturePath = map.value(QLatin1String(CUSTOM_SIGNATURE_PATH_KEY)).toString(); + m_customKeyPath = map.value(QLatin1String(CUSTOM_KEY_PATH_KEY)).toString(); + m_serialPortName = map.value(QLatin1String(SERIAL_PORT_NAME_KEY)).toString().trimmed(); + m_communicationType = map.value(QLatin1String(COMMUNICATION_TYPE_KEY)).toInt(); + m_commandLineArguments = map.value(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY)).toStringList(); + + return RunConfiguration::fromMap(map); } QString S60DeviceRunConfiguration::serialPortName() const @@ -345,8 +393,8 @@ void S60DeviceRunConfiguration::invalidateCachedTargetInformation() // ======== S60DeviceRunConfigurationFactory -S60DeviceRunConfigurationFactory::S60DeviceRunConfigurationFactory(QObject *parent) - : IRunConfigurationFactory(parent) +S60DeviceRunConfigurationFactory::S60DeviceRunConfigurationFactory(QObject *parent) : + IRunConfigurationFactory(parent) { } @@ -354,44 +402,74 @@ S60DeviceRunConfigurationFactory::~S60DeviceRunConfigurationFactory() { } -bool S60DeviceRunConfigurationFactory::canRestore(const QString &id) const +QStringList S60DeviceRunConfigurationFactory::availableCreationIds(Project *parent) const { - return id == "Qt4ProjectManager.DeviceRunConfiguration"; + Qt4Project *qt4project = qobject_cast<Qt4Project *>(parent); + if (!qt4project) + return QStringList(); + + return qt4project->applicationProFilePathes(QLatin1String(S60_DEVICE_RC_PREFIX)); } -QStringList S60DeviceRunConfigurationFactory::availableCreationIds(Project *pro) const +QString S60DeviceRunConfigurationFactory::displayNameForId(const QString &id) const { - Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro); - if (qt4project) { - QStringList applicationProFiles; - QList<Qt4ProFileNode *> list = qt4project->applicationProFiles(); - foreach (Qt4ProFileNode * node, list) { - applicationProFiles.append("QtSymbianDeviceRunConfiguration." + node->path()); - } - return applicationProFiles; - } else { - return QStringList(); - } + if (!pathFromId(id).isEmpty()) + return tr("%1 on Symbian Device").arg(QFileInfo(pathFromId(id)).completeBaseName()); + return QString(); } -QString S60DeviceRunConfigurationFactory::displayNameForId(const QString &id) const +bool S60DeviceRunConfigurationFactory::canCreate(Project *parent, const QString &id) const { - QString fileName = id.mid(QString("QtSymbianDeviceRunConfiguration.").size()); - return tr("%1 on Symbian Device").arg(QFileInfo(fileName).completeBaseName()); + Qt4Project * project(qobject_cast<Qt4Project *>(parent)); + if (!project) + return false; + return project->hasApplicationProFile(pathFromId(id)); } -RunConfiguration *S60DeviceRunConfigurationFactory::create(Project *project, const QString &id) +RunConfiguration *S60DeviceRunConfigurationFactory::create(Project *parent, const QString &id) { - Qt4Project *p = qobject_cast<Qt4Project *>(project); - Q_ASSERT(p); - if (id.startsWith("QtSymbianDeviceRunConfiguration.")) { - QString fileName = id.mid(QString("QtSymbianDeviceRunConfiguration.").size()); - return new S60DeviceRunConfiguration(p, fileName); - } - Q_ASSERT(id == "Qt4ProjectManager.DeviceRunConfiguration"); - // The right path is set in restoreSettings - RunConfiguration *rc = new S60DeviceRunConfiguration(p, QString::null); - return rc; + if (!canCreate(parent, id)) + return 0; + + Qt4Project *project(static_cast<Qt4Project *>(parent)); + return new S60DeviceRunConfiguration(project, pathFromId(id)); +} + +bool S60DeviceRunConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const +{ + if (!qobject_cast<Qt4Project *>(parent)) + return false; + QString id(ProjectExplorer::idFromMap(map)); + return id == QLatin1String(S60_DEVICE_RC_ID); +} + +RunConfiguration *S60DeviceRunConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map) +{ + if (!canRestore(parent, map)) + return 0; + Qt4Project *project(static_cast<Qt4Project *>(parent)); + S60DeviceRunConfiguration *rc(new S60DeviceRunConfiguration(project, QString())); + if (rc->fromMap(map)) + return rc; + + delete rc; + return 0; +} + +bool S60DeviceRunConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const +{ + if (!qobject_cast<Qt4Project *>(parent)) + return false; + return source->id() == QLatin1String(S60_DEVICE_RC_ID); +} + +RunConfiguration *S60DeviceRunConfigurationFactory::clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) +{ + if (!canClone(parent, source)) + return 0; + Qt4Project *project = static_cast<Qt4Project *>(parent); + S60DeviceRunConfiguration * old(static_cast<S60DeviceRunConfiguration *>(source)); + return new S60DeviceRunConfiguration(project, old); } // ======== S60DeviceRunControlBase @@ -845,6 +923,7 @@ bool S60DeviceRunControlBase::checkConfiguration(QString * /* errorMessage */, } // =============== S60DeviceRunControl + S60DeviceRunControl::S60DeviceRunControl(ProjectExplorer::RunConfiguration *runConfiguration) : S60DeviceRunControlBase(runConfiguration) { diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h index 0247672e4c..ed6b52aed6 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h +++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h @@ -44,7 +44,7 @@ class QWidget; QT_END_NAMESPACE namespace Debugger { - class DebuggerStartParameters; +class DebuggerStartParameters; } namespace Qt4ProjectManager { @@ -52,26 +52,26 @@ class Qt4Project; namespace Internal { class Qt4ProFileNode; +class S60DeviceRunConfigurationFactory; class S60DeviceRunConfiguration : public ProjectExplorer::RunConfiguration { Q_OBJECT + friend class S60DeviceRunConfigurationFactory; + public: enum SigningMode { SignSelf, SignCustom }; - explicit S60DeviceRunConfiguration(ProjectExplorer::Project *project, const QString &proFilePath); - ~S60DeviceRunConfiguration(); + S60DeviceRunConfiguration(ProjectExplorer::Project *project, const QString &proFilePath); + virtual ~S60DeviceRunConfiguration(); Qt4Project *qt4Project() const; - QString id() const; bool isEnabled(ProjectExplorer::BuildConfiguration *configuration) const; QWidget *configurationWidget(); - void save(ProjectExplorer::PersistentSettingsWriter &writer) const; - void restore(const ProjectExplorer::PersistentSettingsReader &reader); QString serialPortName() const; void setSerialPortName(const QString &name); @@ -99,6 +99,8 @@ public: ProjectExplorer::ToolChain::ToolChainType toolChainType() const; + QVariantMap toMap() const; + signals: void targetInformationChanged(); @@ -106,9 +108,14 @@ private slots: void invalidateCachedTargetInformation(); void proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro); +protected: + S60DeviceRunConfiguration(ProjectExplorer::Project *project, S60DeviceRunConfiguration *source); + virtual bool fromMap(const QVariantMap &map); + private: ProjectExplorer::ToolChain::ToolChainType toolChainType(ProjectExplorer::BuildConfiguration *configuration) const; void updateTarget(); + void ctor(); QString m_proFilePath; QString m_targetName; @@ -128,14 +135,21 @@ private: class S60DeviceRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory { Q_OBJECT + public: - explicit S60DeviceRunConfigurationFactory(QObject *parent); + explicit S60DeviceRunConfigurationFactory(QObject *parent = 0); ~S60DeviceRunConfigurationFactory(); - bool canRestore(const QString &id) const; - QStringList availableCreationIds(ProjectExplorer::Project *pro) const; + + bool canCreate(ProjectExplorer::Project *parent, const QString &id) const; + ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *parent, const QString &id); + bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const; + ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map); + bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const; + ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source); + + QStringList availableCreationIds(ProjectExplorer::Project *parent) const; // used to translate the ids to names to display to the user QString displayNameForId(const QString &id) const; - ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id); }; /* S60DeviceRunControlBase: Builds the package and starts launcher diff --git a/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp index 6e39e1f98f..74cc7a4bb3 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp @@ -51,24 +51,59 @@ using namespace ProjectExplorer; using namespace Qt4ProjectManager; using namespace Qt4ProjectManager::Internal; +namespace { +const char * const S60_EMULATOR_RC_ID("Qt4ProjectManager.S60EmulatorRunConfiguration"); +const char * const S60_EMULATOR_RC_PREFIX("Qt4ProjectManager.S60EmulatorRunConfiguration."); + +const char * const PRO_FILE_KEY("Qt4ProjectManager.S60EmulatorRunConfiguration.ProFile"); + +QString pathFromId(const QString &id) +{ + if (!id.startsWith(QLatin1String(S60_EMULATOR_RC_PREFIX))) + return QString(); + return id.mid(QString::fromLatin1(S60_EMULATOR_RC_PREFIX).size()); +} + +QString pathToId(const QString &path) +{ + return QString::fromLatin1(S60_EMULATOR_RC_PREFIX) + path; +} + +} + // ======== S60EmulatorRunConfiguration -S60EmulatorRunConfiguration::S60EmulatorRunConfiguration(Project *project, const QString &proFilePath) - : RunConfiguration(project), + +S60EmulatorRunConfiguration::S60EmulatorRunConfiguration(Project *project, const QString &proFilePath) : + RunConfiguration(project, QLatin1String(S60_EMULATOR_RC_ID)), m_proFilePath(proFilePath), m_cachedTargetInformationValid(false) { + ctor(); +} + +S60EmulatorRunConfiguration::S60EmulatorRunConfiguration(Project *project, S60EmulatorRunConfiguration *source) : + RunConfiguration(project, source), + m_proFilePath(source->m_proFilePath), + m_cachedTargetInformationValid(false) +{ + ctor(); +} + +void S60EmulatorRunConfiguration::ctor() +{ if (!m_proFilePath.isEmpty()) setDisplayName(tr("%1 in Symbian Emulator").arg(QFileInfo(m_proFilePath).completeBaseName())); else - setDisplayName(tr("QtSymbianEmulatorRunConfiguration")); + setDisplayName(tr("Qt Symbian Emulator RunConfiguration")); - connect(project, SIGNAL(targetInformationChanged()), + connect(qt4Project(), SIGNAL(targetInformationChanged()), this, SLOT(invalidateCachedTargetInformation())); - connect(project, SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), + connect(qt4Project(), SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), this, SLOT(proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode*))); } + S60EmulatorRunConfiguration::~S60EmulatorRunConfiguration() { } @@ -85,11 +120,6 @@ Qt4Project *S60EmulatorRunConfiguration::qt4Project() const return static_cast<Qt4Project *>(project()); } -QString S60EmulatorRunConfiguration::id() const -{ - return "Qt4ProjectManager.EmulatorRunConfiguration"; -} - bool S60EmulatorRunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *configuration) const { Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(configuration); @@ -103,18 +133,20 @@ QWidget *S60EmulatorRunConfiguration::configurationWidget() return new S60EmulatorRunConfigurationWidget(this); } -void S60EmulatorRunConfiguration::save(PersistentSettingsWriter &writer) const +QVariantMap S60EmulatorRunConfiguration::toMap() const { + QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir(); - writer.saveValue("ProFile", projectDir.relativeFilePath(m_proFilePath)); - RunConfiguration::save(writer); + map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath)); + return map; } -void S60EmulatorRunConfiguration::restore(const PersistentSettingsReader &reader) +bool S60EmulatorRunConfiguration::fromMap(const QVariantMap &map) { - RunConfiguration::restore(reader); - const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir(); - m_proFilePath = projectDir.filePath(reader.restoreValue("ProFile").toString()); + const QDir projectDir = QFileInfo(qt4Project()->file()->fileName()).absoluteDir(); + m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString()); + + return RunConfiguration::fromMap(map); } QString S60EmulatorRunConfiguration::executable() const @@ -224,44 +256,71 @@ S60EmulatorRunConfigurationFactory::~S60EmulatorRunConfigurationFactory() { } -bool S60EmulatorRunConfigurationFactory::canRestore(const QString &id) const +bool S60EmulatorRunConfigurationFactory::canCreate(Project *parent, const QString &id) const { - return id == "Qt4ProjectManager.EmulatorRunConfiguration"; + Qt4Project *project(qobject_cast<Qt4Project *>(parent)); + if (!project) + return false; + return project->hasApplicationProFile(pathFromId(id)); } -QStringList S60EmulatorRunConfigurationFactory::availableCreationIds(Project *pro) const +RunConfiguration *S60EmulatorRunConfigurationFactory::create(Project *parent, const QString &id) { - Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro); - if (qt4project) { - QStringList applicationProFiles; - QList<Qt4ProFileNode *> list = qt4project->applicationProFiles(); - foreach (Qt4ProFileNode * node, list) { - applicationProFiles.append("QtSymbianEmulatorRunConfiguration." + node->path()); - } - return applicationProFiles; - } else { - return QStringList(); - } + if (!canCreate(parent, id)) + return 0; + Qt4Project *project(static_cast<Qt4Project *>(parent)); + return new S60EmulatorRunConfiguration(project, pathFromId(id)); } -QString S60EmulatorRunConfigurationFactory::displayNameForId(const QString &id) const +bool S60EmulatorRunConfigurationFactory::canRestore(Project *parent, const QVariantMap &map) const { - QString fileName = id.mid(QString("QtSymbianEmulatorRunConfiguration.").size()); - return tr("%1 in Symbian Emulator").arg(QFileInfo(fileName).completeBaseName()); + if (!qobject_cast<Qt4Project *>(parent)) + return false; + QString id(ProjectExplorer::idFromMap(map)); + return id.startsWith(QLatin1String(S60_EMULATOR_RC_ID)); } -RunConfiguration *S60EmulatorRunConfigurationFactory::create(Project *project, const QString &id) +RunConfiguration *S60EmulatorRunConfigurationFactory::restore(Project *parent, const QVariantMap &map) { - Qt4Project *p = qobject_cast<Qt4Project *>(project); - Q_ASSERT(p); - if (id.startsWith("QtSymbianEmulatorRunConfiguration.")) { - QString fileName = id.mid(QString("QtSymbianEmulatorRunConfiguration.").size()); - return new S60EmulatorRunConfiguration(p, fileName); - } - Q_ASSERT(id == "Qt4ProjectManager.EmulatorRunConfiguration"); - // The right path is set in restoreSettings - RunConfiguration *rc = new S60EmulatorRunConfiguration(p, QString::null); - return rc; + if (!canRestore(parent, map)) + return 0; + Qt4Project *project(static_cast<Qt4Project *>(parent)); + S60EmulatorRunConfiguration *rc(new S60EmulatorRunConfiguration(project, QString())); + if (rc->fromMap(map)) + return rc; + delete rc; + return 0; +} + +bool S60EmulatorRunConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const +{ + if (!qobject_cast<Qt4Project *>(parent)) + return false; + return source->id() == QLatin1String(S60_EMULATOR_RC_ID); +} + +RunConfiguration *S60EmulatorRunConfigurationFactory::clone(Project *parent, RunConfiguration *source) +{ + if (!canClone(parent, source)) + return 0; + Qt4Project *project(static_cast<Qt4Project *>(parent)); + return new S60EmulatorRunConfiguration(project, QString()); +} + +QStringList S60EmulatorRunConfigurationFactory::availableCreationIds(Project *pro) const +{ + Qt4Project *qt4project(qobject_cast<Qt4Project *>(pro)); + if (!qt4project) + return QStringList(); + + return qt4project->applicationProFilePathes(QLatin1String(S60_EMULATOR_RC_PREFIX)); +} + +QString S60EmulatorRunConfigurationFactory::displayNameForId(const QString &id) const +{ + if (!pathFromId(id).isEmpty()) + return tr("%1 in Symbian Emulator").arg(QFileInfo(pathFromId(id)).completeBaseName()); + return QString(); } // ======== S60EmulatorRunControl diff --git a/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.h b/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.h index c4aa2103bf..86c4b0eaec 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.h +++ b/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.h @@ -33,6 +33,7 @@ #include <projectexplorer/runconfiguration.h> #include <projectexplorer/applicationlauncher.h> +#include <QtCore/QVariantMap> #include <QtGui/QWidget> QT_BEGIN_NAMESPACE @@ -41,7 +42,7 @@ class QLineEdit; QT_END_NAMESPACE namespace Utils { - class DetailsWidget; +class DetailsWidget; } namespace Qt4ProjectManager { @@ -49,24 +50,26 @@ class Qt4Project; namespace Internal { class Qt4ProFileNode; +class S60EmulatorRunConfigurationFactory; class S60EmulatorRunConfiguration : public ProjectExplorer::RunConfiguration { Q_OBJECT + friend class S60EmulatorRunConfigurationFactory; + public: - S60EmulatorRunConfiguration(ProjectExplorer::Project *project, const QString &proFilePath); - ~S60EmulatorRunConfiguration(); + S60EmulatorRunConfiguration(ProjectExplorer::Project *parent, const QString &proFilePath); + virtual ~S60EmulatorRunConfiguration(); Qt4Project *qt4Project() const; - QString id() const; bool isEnabled(ProjectExplorer::BuildConfiguration *configuration) const; QWidget *configurationWidget(); - void save(ProjectExplorer::PersistentSettingsWriter &writer) const; - void restore(const ProjectExplorer::PersistentSettingsReader &reader); QString executable() const; + QVariantMap toMap() const; + signals: void targetInformationChanged(); @@ -74,7 +77,12 @@ private slots: void invalidateCachedTargetInformation(); void proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro); +protected: + S60EmulatorRunConfiguration(ProjectExplorer::Project *parent, S60EmulatorRunConfiguration *source); + virtual bool fromMap(const QVariantMap &map); + private: + void ctor(); void updateTarget(); QString m_proFilePath; @@ -105,13 +113,19 @@ class S60EmulatorRunConfigurationFactory : public ProjectExplorer::IRunConfigura { Q_OBJECT public: - explicit S60EmulatorRunConfigurationFactory(QObject *parent); + explicit S60EmulatorRunConfigurationFactory(QObject *parent = 0); ~S60EmulatorRunConfigurationFactory(); - bool canRestore(const QString &id) const; + + bool canCreate(ProjectExplorer::Project *project, const QString &id) const; + ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id); + bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const; + ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map); + bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const; + ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source); + QStringList availableCreationIds(ProjectExplorer::Project *pro) const; // used to translate the ids to names to display to the user QString displayNameForId(const QString &id) const; - ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id); }; class S60EmulatorRunControl : public ProjectExplorer::RunControl diff --git a/src/plugins/qt4projectmanager/qt-s60/s60manager.cpp b/src/plugins/qt4projectmanager/qt-s60/s60manager.cpp index e8853ff768..e4bc1eed2a 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60manager.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60manager.cpp @@ -107,12 +107,12 @@ S60Manager::S60Manager(QObject *parent) #endif m_devices->detectQtForDevices(); // Order! - addAutoReleasedObject(new S60EmulatorRunConfigurationFactory(this)); + addAutoReleasedObject(new S60EmulatorRunConfigurationFactory); addAutoReleasedObject(new RunControlFactory<S60EmulatorRunControl, S60EmulatorRunConfiguration> (QLatin1String(ProjectExplorer::Constants::RUNMODE), tr("Run in Emulator"), parent)); - addAutoReleasedObject(new S60DeviceRunConfigurationFactory(this)); + addAutoReleasedObject(new S60DeviceRunConfigurationFactory); addAutoReleasedObject(new RunControlFactory<S60DeviceRunControl, S60DeviceRunConfiguration> (QLatin1String(ProjectExplorer::Constants::RUNMODE), diff --git a/src/plugins/qt4projectmanager/qt4buildconfiguration.cpp b/src/plugins/qt4projectmanager/qt4buildconfiguration.cpp index f9987e1f78..fc150595e8 100644 --- a/src/plugins/qt4projectmanager/qt4buildconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt4buildconfiguration.cpp @@ -50,6 +50,11 @@ const char * const BUILD_DIRECTORY_KEY("Qt4ProjectManager.Qt4BuildConfiguration. const char * const TOOLCHAIN_KEY("Qt4ProjectManager.Qt4BuildConfiguration.ToolChain"); const char * const BUILD_CONFIGURATION_KEY("Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration"); const char * const QT_VERSION_ID_KEY("Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId"); + +enum { + debug = false +}; + } Qt4BuildConfiguration::Qt4BuildConfiguration(Qt4Project *pro) : diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp index f22d63e676..3741edfe59 100644 --- a/src/plugins/qt4projectmanager/qt4project.cpp +++ b/src/plugins/qt4projectmanager/qt4project.cpp @@ -1023,6 +1023,26 @@ QList<Qt4ProFileNode *> Qt4Project::applicationProFiles() const return list; } +bool Qt4Project::hasApplicationProFile(const QString &path) const +{ + if (path.isEmpty()) + return false; + + QList<Qt4ProFileNode *> list = applicationProFiles(); + foreach (Qt4ProFileNode * node, list) + if (node->path() == path) + return true; + return false; +} + +QStringList Qt4Project::applicationProFilePathes(const QString &prepend) const +{ + QStringList proFiles; + foreach (Qt4ProFileNode *node, applicationProFiles()) + proFiles.append(prepend + node->path()); + return proFiles; +} + void Qt4Project::projectTypeChanged(Qt4ProFileNode *node, const Qt4ProjectType oldType, const Qt4ProjectType newType) { if (oldType == Internal::ApplicationTemplate diff --git a/src/plugins/qt4projectmanager/qt4project.h b/src/plugins/qt4projectmanager/qt4project.h index 9be7d5dd29..cf32219405 100644 --- a/src/plugins/qt4projectmanager/qt4project.h +++ b/src/plugins/qt4projectmanager/qt4project.h @@ -171,6 +171,8 @@ public: QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets(); QList<Internal::Qt4ProFileNode *> applicationProFiles() const; + bool hasApplicationProFile(const QString &path) const; + QStringList applicationProFilePathes(const QString &prepend = QString()) const; void notifyChanged(const QString &name); diff --git a/src/plugins/qt4projectmanager/qt4runconfiguration.cpp b/src/plugins/qt4projectmanager/qt4runconfiguration.cpp index cc2086389d..b340ac1552 100644 --- a/src/plugins/qt4projectmanager/qt4runconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt4runconfiguration.cpp @@ -57,43 +57,74 @@ using ProjectExplorer::LocalApplicationRunConfiguration; using ProjectExplorer::PersistentSettingsReader; using ProjectExplorer::PersistentSettingsWriter; -Qt4RunConfiguration::Qt4RunConfiguration(Qt4Project *pro, const QString &proFilePath) - : LocalApplicationRunConfiguration(pro), - m_proFilePath(proFilePath), - m_runMode(Gui), - m_userSetName(false), - m_cachedTargetInformationValid(false), - m_isUsingDyldImageSuffix(false), - m_userSetWokingDirectory(false), - m_baseEnvironmentBase(Qt4RunConfiguration::BuildEnvironmentBase) +namespace { +const char * const QT4_RC_ID("Qt4ProjectManager.Qt4RunConfiguration"); +const char * const QT4_RC_PREFIX("Qt4ProjectManager.Qt4RunConfiguration."); + +const char * const COMMAND_LINE_ARGUMENTS_KEY("Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"); +const char * const PRO_FILE_KEY("Qt4ProjectManager.Qt4RunConfiguration.ProFile"); +const char * const USER_SET_NAME_KEY("Qt4ProjectManager.Qt4RunConfiguration.UserSetName"); +const char * const USE_TERMINAL_KEY("Qt4ProjectManager.Qt4RunConfiguration.UseTerminal"); +const char * const USE_DYLD_IMAGE_SUFFIX_KEY("Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix"); +const char * const USER_ENVIRONMENT_CHANGES_KEY("Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges"); +const char * const BASE_ENVIRONMENT_BASE_KEY("Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase"); +const char * const USER_SET_WORKING_DIRECTORY_KEY("Qt4ProjectManager.Qt4RunConfiguration.UserSetWorkingDirectory"); +const char * const USER_WORKING_DIRECTORY_KEY("Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"); + +QString pathFromId(const QString &id) { - if (!m_proFilePath.isEmpty()) - setDisplayName(QFileInfo(m_proFilePath).completeBaseName()); - else - setDisplayName(tr("Qt4RunConfiguration")); + if (!id.startsWith(QLatin1String(QT4_RC_PREFIX))) + return QString(); + return id.mid(QString::fromLatin1(QT4_RC_PREFIX).size()); +} - connect(pro, SIGNAL(targetInformationChanged()), - this, SLOT(invalidateCachedTargetInformation())); +QString pathToId(const QString &path) +{ + return QString::fromLatin1(QT4_RC_PREFIX) + path; +} - connect(pro, SIGNAL(environmentChanged()), - this, SIGNAL(baseEnvironmentChanged())); +} // namespace - connect(pro, SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), - this, SLOT(proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode*))); +// +// Qt4RunConfiguration +// + +Qt4RunConfiguration::Qt4RunConfiguration(Qt4Project *parent, const QString &proFilePath) : + LocalApplicationRunConfiguration(parent, QLatin1String(QT4_RC_ID)), + m_proFilePath(proFilePath), + m_runMode(Gui), + m_userSetName(false), + m_cachedTargetInformationValid(false), + m_isUsingDyldImageSuffix(false), + m_userSetWokingDirectory(false), + m_baseEnvironmentBase(Qt4RunConfiguration::BuildEnvironmentBase) +{ + ctor(); } -Qt4RunConfiguration::~Qt4RunConfiguration() +Qt4RunConfiguration::Qt4RunConfiguration(Qt4Project *parent, Qt4RunConfiguration *source) : + LocalApplicationRunConfiguration(parent, source), + m_commandLineArguments(source->m_commandLineArguments), + m_proFilePath(source->m_proFilePath), + m_runMode(source->m_runMode), + m_userSetName(source->m_userSetName), + m_cachedTargetInformationValid(false), + m_isUsingDyldImageSuffix(source->m_isUsingDyldImageSuffix), + m_userSetWokingDirectory(source->m_userSetWokingDirectory), + m_userWorkingDirectory(source->m_userWorkingDirectory), + m_userEnvironmentChanges(source->m_userEnvironmentChanges), + m_baseEnvironmentBase(source->m_baseEnvironmentBase) { + ctor(); } -Qt4Project *Qt4RunConfiguration::qt4Project() const +Qt4RunConfiguration::~Qt4RunConfiguration() { - return static_cast<Qt4Project *>(project()); } -QString Qt4RunConfiguration::id() const +Qt4Project *Qt4RunConfiguration::qt4Project() const { - return "Qt4ProjectManager.Qt4RunConfiguration"; + return static_cast<Qt4Project *>(project()); } bool Qt4RunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *configuration) const @@ -119,6 +150,19 @@ void Qt4RunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileN invalidateCachedTargetInformation(); } +void Qt4RunConfiguration::ctor() +{ + setDefaultDisplayName(); + connect(qt4Project(), SIGNAL(targetInformationChanged()), + this, SLOT(invalidateCachedTargetInformation())); + + connect(qt4Project(), SIGNAL(environmentChanged()), + this, SIGNAL(baseEnvironmentChanged())); + + connect(qt4Project(), SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)), + this, SLOT(proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode*))); +} + ////// /// Qt4RunConfigurationWidget ///// @@ -402,41 +446,43 @@ QWidget *Qt4RunConfiguration::configurationWidget() return new Qt4RunConfigurationWidget(this, 0); } -void Qt4RunConfiguration::save(PersistentSettingsWriter &writer) const +QVariantMap Qt4RunConfiguration::toMap() const { const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir(); - writer.saveValue("CommandLineArguments", m_commandLineArguments); - writer.saveValue("ProFile", projectDir.relativeFilePath(m_proFilePath)); - writer.saveValue("UserSetName", m_userSetName); - writer.saveValue("UseTerminal", m_runMode == Console); - writer.saveValue("UseDyldImageSuffix", m_isUsingDyldImageSuffix); - writer.saveValue("UserEnvironmentChanges", ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges)); - writer.saveValue("BaseEnvironmentBase", m_baseEnvironmentBase); - writer.saveValue("UserSetWorkingDirectory", m_userSetWokingDirectory); - writer.saveValue("UserWorkingDirectory", m_userWorkingDirectory); - LocalApplicationRunConfiguration::save(writer); + QVariantMap map(LocalApplicationRunConfiguration::toMap()); + map.insert(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY), m_commandLineArguments); + map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath)); + map.insert(QLatin1String(USER_SET_NAME_KEY), m_userSetName); + map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == Console); + map.insert(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), m_isUsingDyldImageSuffix); + map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges)); + map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase); + map.insert(QLatin1String(USER_SET_WORKING_DIRECTORY_KEY), m_userSetWokingDirectory); + map.insert(QLatin1String(USER_WORKING_DIRECTORY_KEY), m_userWorkingDirectory); + return map; } -void Qt4RunConfiguration::restore(const PersistentSettingsReader &reader) +bool Qt4RunConfiguration::fromMap(const QVariantMap &map) { - LocalApplicationRunConfiguration::restore(reader); const QDir projectDir = QFileInfo(project()->file()->fileName()).absoluteDir(); - m_commandLineArguments = reader.restoreValue("CommandLineArguments").toStringList(); - m_proFilePath = projectDir.filePath(reader.restoreValue("ProFile").toString()); - m_userSetName = reader.restoreValue("UserSetName").toBool(); - m_runMode = reader.restoreValue("UseTerminal").toBool() ? Console : Gui; - m_isUsingDyldImageSuffix = reader.restoreValue("UseDyldImageSuffix").toBool(); - QVariant v = reader.restoreValue("UserSetWorkingDirectory"); - m_userSetWokingDirectory = v.isValid() ? v.toBool() : false; - m_userWorkingDirectory = reader.restoreValue("UserWorkingDirectory").toString(); + m_commandLineArguments = map.value(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY)).toStringList(); + m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString()); + m_userSetName = map.value(QLatin1String(USER_SET_NAME_KEY), false).toBool(); + m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY), false).toBool() ? Console : Gui; + m_isUsingDyldImageSuffix = map.value(QLatin1String(USE_DYLD_IMAGE_SUFFIX_KEY), false).toBool(); + + m_userSetWokingDirectory = map.value(QLatin1String(USER_SET_WORKING_DIRECTORY_KEY), false).toBool(); + m_userWorkingDirectory = map.value(QLatin1String(USER_WORKING_DIRECTORY_KEY)).toString(); + if (!m_proFilePath.isEmpty()) { m_cachedTargetInformationValid = false; if (!m_userSetName) - setDisplayName(QFileInfo(m_proFilePath).completeBaseName()); + setDefaultDisplayName(); } - m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(reader.restoreValue("UserEnvironmentChanges").toStringList()); - QVariant tmp = reader.restoreValue("BaseEnvironmentBase"); - m_baseEnvironmentBase = tmp.isValid() ? BaseEnvironmentBase(tmp.toInt()) : Qt4RunConfiguration::BuildEnvironmentBase; + m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList()); + m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(Qt4RunConfiguration::BuildEnvironmentBase)).toInt()); + + return RunConfiguration::fromMap(map); } QString Qt4RunConfiguration::executable() const @@ -526,7 +572,7 @@ void Qt4RunConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer: void Qt4RunConfiguration::setWorkingDirectory(const QString &wd) { - if (wd== "") { + if (wd.isEmpty()) { m_userSetWokingDirectory = false; m_userWorkingDirectory = QString::null; emit workingDirectoryChanged(workingDirectory()); @@ -553,12 +599,11 @@ void Qt4RunConfiguration::setUserName(const QString &name) { if (name.isEmpty()) { m_userSetName = false; - setDisplayName(tr("Qt4RunConfiguration")); + setDefaultDisplayName(); } else { m_userSetName = true; setDisplayName(name); } - emit displayNameChanged(name); } QString Qt4RunConfiguration::proFilePath() const @@ -616,6 +661,16 @@ QStringList Qt4RunConfiguration::dumperLibraryLocations() const return QStringList(); } +void Qt4RunConfiguration::setDefaultDisplayName() +{ + if (m_userSetName) + return; + if (!m_proFilePath.isEmpty()) + setDisplayName(QFileInfo(m_proFilePath).completeBaseName()); + else + setDisplayName(tr("Qt4 RunConfiguration")); +} + void Qt4RunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env) { if (m_baseEnvironmentBase == env) @@ -639,7 +694,8 @@ ProjectExplorer::ToolChain::ToolChainType Qt4RunConfiguration::toolChainType() c /// This class is used to restore run settings (saved in .user files) /// -Qt4RunConfigurationFactory::Qt4RunConfigurationFactory() +Qt4RunConfigurationFactory::Qt4RunConfigurationFactory(QObject *parent) : + ProjectExplorer::IRunConfigurationFactory(parent) { } @@ -647,42 +703,68 @@ Qt4RunConfigurationFactory::~Qt4RunConfigurationFactory() { } -// used to recreate the runConfigurations when restoring settings -bool Qt4RunConfigurationFactory::canRestore(const QString &id) const +bool Qt4RunConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const { - return id == "Qt4ProjectManager.Qt4RunConfiguration"; + Qt4Project *qt4project = qobject_cast<Qt4Project *>(parent); + if (!qt4project) + return false; + return qt4project->hasApplicationProFile(pathFromId(id)); } -ProjectExplorer::RunConfiguration *Qt4RunConfigurationFactory::create(ProjectExplorer::Project *project, const QString &id) +ProjectExplorer::RunConfiguration *Qt4RunConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id) { - Qt4Project *p = qobject_cast<Qt4Project *>(project); - Q_ASSERT(p); - if (id.startsWith("Qt4RunConfiguration.")) { - QString fileName = id.mid(QString("Qt4RunConfiguration.").size()); - return new Qt4RunConfiguration(p, fileName); - } - Q_ASSERT(id == "Qt4ProjectManager.Qt4RunConfiguration"); - // The right path is set in restoreSettings - return new Qt4RunConfiguration(p, QString::null); + if (!canCreate(parent, id)) + return 0; + Qt4Project *project(static_cast<Qt4Project *>(parent)); + return new Qt4RunConfiguration(project, pathFromId(id)); +} + +bool Qt4RunConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const +{ + if (!qobject_cast<Qt4Project *>(parent)) + return false; + QString id(ProjectExplorer::idFromMap(map)); + return id.startsWith(QLatin1String(QT4_RC_ID)); +} + +ProjectExplorer::RunConfiguration *Qt4RunConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map) +{ + if (!canRestore(parent, map)) + return 0; + Qt4Project *project(static_cast<Qt4Project *>(parent)); + Qt4RunConfiguration *rc(new Qt4RunConfiguration(project, QString())); + if (rc->fromMap(map)) + return rc; + + delete rc; + return 0; +} + +bool Qt4RunConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const +{ + if (!qobject_cast<Qt4Project *>(parent)) + return false; + return source->id().startsWith(QLatin1String(QT4_RC_ID)); +} + +ProjectExplorer::RunConfiguration *Qt4RunConfigurationFactory::clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) +{ + if (!canClone(parent, source)) + return 0; + Qt4Project *project(static_cast<Qt4Project *>(parent)); + Qt4RunConfiguration *old(static_cast<Qt4RunConfiguration *>(source)); + return new Qt4RunConfiguration(project, old); } QStringList Qt4RunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *pro) const { Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro); - if (qt4project) { - QStringList applicationProFiles; - QList<Qt4ProFileNode *> list = qt4project->applicationProFiles(); - foreach (Qt4ProFileNode * node, list) { - applicationProFiles.append("Qt4RunConfiguration." + node->path()); - } - return applicationProFiles; - } else { + if (!qt4project) return QStringList(); - } + return qt4project->applicationProFilePathes(QLatin1String(QT4_RC_PREFIX)); } QString Qt4RunConfigurationFactory::displayNameForId(const QString &id) const { - QString fileName = id.mid(QString("Qt4RunConfiguration.").size()); - return QFileInfo(fileName).completeBaseName(); + return QFileInfo(pathFromId(id)).completeBaseName(); } diff --git a/src/plugins/qt4projectmanager/qt4runconfiguration.h b/src/plugins/qt4projectmanager/qt4runconfiguration.h index 55b57daa8f..afc2b787e9 100644 --- a/src/plugins/qt4projectmanager/qt4runconfiguration.h +++ b/src/plugins/qt4projectmanager/qt4runconfiguration.h @@ -55,23 +55,23 @@ class Qt4Project; namespace Internal { class Qt4PriFileNode; class Qt4ProFileNode; +class Qt4RunConfigurationFactory; class Qt4RunConfiguration : public ProjectExplorer::LocalApplicationRunConfiguration { Q_OBJECT // to change the display name and arguments and set the userenvironmentchanges friend class Qt4RunConfigurationWidget; + friend class Qt4RunConfigurationFactory; + public: - Qt4RunConfiguration(Qt4Project *pro, const QString &proFilePath); + Qt4RunConfiguration(Qt4Project *parent, const QString &proFilePath); virtual ~Qt4RunConfiguration(); Qt4Project *qt4Project() const; - virtual QString id() const; virtual bool isEnabled(ProjectExplorer::BuildConfiguration *configuration) const; virtual QWidget *configurationWidget(); - virtual void save(ProjectExplorer::PersistentSettingsWriter &writer) const; - virtual void restore(const ProjectExplorer::PersistentSettingsReader &reader); virtual QString executable() const; virtual RunMode runMode() const; @@ -87,6 +87,7 @@ public: QString proFilePath() const; // TODO detectQtShadowBuild() ? how did this work ? + QVariantMap toMap() const; public slots: // This function is called if: @@ -115,13 +116,20 @@ private slots: void setUserName(const QString&); void setRunMode(RunMode runMode); +protected: + Qt4RunConfiguration(Qt4Project *parent, Qt4RunConfiguration *source); + virtual bool fromMap(const QVariantMap &map); + private: enum BaseEnvironmentBase { CleanEnvironmentBase = 0, SystemEnvironmentBase = 1, BuildEnvironmentBase = 2 }; + void setDefaultDisplayName(); void setBaseEnvironmentBase(BaseEnvironmentBase env); BaseEnvironmentBase baseEnvironmentBase() const; + void ctor(); + ProjectExplorer::Environment baseEnvironment() const; QString baseEnvironmentText() const; void setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff); @@ -132,7 +140,6 @@ private: QString m_proFilePath; // Full path to the Application Pro File // Cached startup sub project information - QStringList m_targets; QString m_executable; QString m_workingDir; ProjectExplorer::LocalApplicationRunConfiguration::RunMode m_runMode; @@ -148,6 +155,7 @@ private: class Qt4RunConfigurationWidget : public QWidget { Q_OBJECT + public: Qt4RunConfigurationWidget(Qt4RunConfiguration *qt4runconfigration, QWidget *parent); protected: @@ -194,12 +202,19 @@ private: class Qt4RunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory { Q_OBJECT + public: - Qt4RunConfigurationFactory(); + explicit Qt4RunConfigurationFactory(QObject *parent = 0); virtual ~Qt4RunConfigurationFactory(); - virtual bool canRestore(const QString &id) const; + + virtual bool canCreate(ProjectExplorer::Project *project, const QString &id) const; virtual ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id); - QStringList availableCreationIds(ProjectExplorer::Project *pro) const; + virtual bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const; + virtual ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map); + virtual bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const; + virtual ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source); + + QStringList availableCreationIds(ProjectExplorer::Project *parent) const; QString displayNameForId(const QString &id) const; }; |