Commit e4dca97f authored by hjk's avatar hjk

ProjectExplorer: Pimpl RunControl

It is a fairly central exported class, no need to expose storage
details to user code.

Change-Id: Ibe199969450bc30b46ab7500e04a22300c492f2c
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 51661d4d
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include <QTimer> #include <QTimer>
#include <QPushButton> #include <QPushButton>
#ifdef Q_OS_MAC #ifdef Q_OS_OSX
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#endif #endif
...@@ -531,93 +531,139 @@ IRunConfigurationAspect *IRunControlFactory::createRunConfigurationAspect(RunCon ...@@ -531,93 +531,139 @@ IRunConfigurationAspect *IRunControlFactory::createRunConfigurationAspect(RunCon
than it needs to be. than it needs to be.
*/ */
RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode) namespace Internal {
: m_runMode(mode), m_runConfiguration(runConfiguration), m_outputFormatter(0)
class RunControlPrivate
{ {
if (runConfiguration) { public:
m_displayName = runConfiguration->displayName(); RunControlPrivate(RunConfiguration *runConfiguration, Core::Id mode)
m_outputFormatter = runConfiguration->createOutputFormatter(); : runMode(mode), runConfiguration(runConfiguration)
{
if (runConfiguration) {
displayName = runConfiguration->displayName();
outputFormatter = runConfiguration->createOutputFormatter();
if (runConfiguration->target())
project = runConfiguration->target()->project();
}
// We need to ensure that there's always a OutputFormatter
if (!outputFormatter)
outputFormatter = new Utils::OutputFormatter();
}
if (runConfiguration->target()) ~RunControlPrivate()
m_project = m_runConfiguration->target()->project(); {
delete outputFormatter;
} }
// We need to ensure that there's always a OutputFormatter QString displayName;
if (!m_outputFormatter) Runnable runnable;
m_outputFormatter = new Utils::OutputFormatter(); Connection connection;
Core::Id runMode;
Utils::Icon icon;
const QPointer<RunConfiguration> runConfiguration;
QPointer<Project> project;
Utils::OutputFormatter *outputFormatter = 0;
// A handle to the actual application process.
ProcessHandle applicationProcessHandle;
#ifdef Q_OS_OSX
//these two are used to bring apps in the foreground on Mac
qint64 internalPid;
int foregroundCount;
#endif
};
} // Internal
RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode)
: d(new Internal::RunControlPrivate(runConfiguration, mode))
{
} }
RunControl::~RunControl() RunControl::~RunControl()
{ {
delete m_outputFormatter; delete d;
} }
Utils::OutputFormatter *RunControl::outputFormatter() Utils::OutputFormatter *RunControl::outputFormatter()
{ {
return m_outputFormatter; return d->outputFormatter;
} }
Core::Id RunControl::runMode() const Core::Id RunControl::runMode() const
{ {
return m_runMode; return d->runMode;
}
const Runnable &RunControl::runnable() const
{
return d->runnable;
} }
void RunControl::setRunnable(const Runnable &runnable) void RunControl::setRunnable(const Runnable &runnable)
{ {
m_runnable = runnable; d->runnable = runnable;
}
const Connection &RunControl::connection() const
{
return d->connection;
} }
void RunControl::setConnection(const Connection &connection) void RunControl::setConnection(const Connection &connection)
{ {
m_connection = connection; d->connection = connection;
} }
QString RunControl::displayName() const QString RunControl::displayName() const
{ {
return m_displayName; return d->displayName;
} }
void RunControl::setDisplayName(const QString &displayName) void RunControl::setDisplayName(const QString &displayName)
{ {
m_displayName = displayName; d->displayName = displayName;
} }
void RunControl::setIcon(const Utils::Icon &icon) void RunControl::setIcon(const Utils::Icon &icon)
{ {
m_icon = icon; d->icon = icon;
} }
Utils::Icon RunControl::icon() const Utils::Icon RunControl::icon() const
{ {
return m_icon; return d->icon;
} }
Abi RunControl::abi() const Abi RunControl::abi() const
{ {
if (const RunConfiguration *rc = m_runConfiguration.data()) if (const RunConfiguration *rc = d->runConfiguration.data())
return rc->abi(); return rc->abi();
return Abi(); return Abi();
} }
RunConfiguration *RunControl::runConfiguration() const RunConfiguration *RunControl::runConfiguration() const
{ {
return m_runConfiguration.data(); return d->runConfiguration.data();
} }
Project *RunControl::project() const Project *RunControl::project() const
{ {
return m_project.data(); return d->project.data();
} }
ProcessHandle RunControl::applicationProcessHandle() const ProcessHandle RunControl::applicationProcessHandle() const
{ {
return m_applicationProcessHandle; return d->applicationProcessHandle;
} }
void RunControl::setApplicationProcessHandle(const ProcessHandle &handle) void RunControl::setApplicationProcessHandle(const ProcessHandle &handle)
{ {
if (m_applicationProcessHandle != handle) { if (d->applicationProcessHandle != handle) {
m_applicationProcessHandle = handle; d->applicationProcessHandle = handle;
emit applicationProcessHandleChanged(); emit applicationProcessHandleChanged();
} }
} }
...@@ -679,14 +725,14 @@ bool RunControl::showPromptToStopDialog(const QString &title, ...@@ -679,14 +725,14 @@ bool RunControl::showPromptToStopDialog(const QString &title,
bool RunControl::sameRunConfiguration(const RunControl *other) const bool RunControl::sameRunConfiguration(const RunControl *other) const
{ {
return other->m_runConfiguration.data() == m_runConfiguration.data(); return other->d->runConfiguration.data() == d->runConfiguration.data();
} }
void RunControl::bringApplicationToForeground(qint64 pid) void RunControl::bringApplicationToForeground(qint64 pid)
{ {
#ifdef Q_OS_MAC #ifdef Q_OS_OSX
m_internalPid = pid; d->internalPid = pid;
m_foregroundCount = 0; d->foregroundCount = 0;
bringApplicationToForegroundInternal(); bringApplicationToForegroundInternal();
#else #else
Q_UNUSED(pid) Q_UNUSED(pid)
...@@ -695,14 +741,14 @@ void RunControl::bringApplicationToForeground(qint64 pid) ...@@ -695,14 +741,14 @@ void RunControl::bringApplicationToForeground(qint64 pid)
void RunControl::bringApplicationToForegroundInternal() void RunControl::bringApplicationToForegroundInternal()
{ {
#ifdef Q_OS_MAC #ifdef Q_OS_OSX
ProcessSerialNumber psn; ProcessSerialNumber psn;
GetProcessForPID(m_internalPid, &psn); GetProcessForPID(d->internalPid, &psn);
if (SetFrontProcess(&psn) == procNotFound && m_foregroundCount < 15) { if (SetFrontProcess(&psn) == procNotFound && d->foregroundCount < 15) {
// somehow the mac/carbon api says // somehow the mac/carbon api says
// "-600 no eligible process with specified process id" // "-600 no eligible process with specified process id"
// if we call SetFrontProcess too early // if we call SetFrontProcess too early
++m_foregroundCount; ++d->foregroundCount;
QTimer::singleShot(200, this, &RunControl::bringApplicationToForegroundInternal); QTimer::singleShot(200, this, &RunControl::bringApplicationToForegroundInternal);
return; return;
} }
......
...@@ -27,11 +27,9 @@ ...@@ -27,11 +27,9 @@
#define RUNCONFIGURATION_H #define RUNCONFIGURATION_H
#include "projectconfiguration.h" #include "projectconfiguration.h"
#include "projectexplorer_export.h"
#include "projectexplorerconstants.h" #include "projectexplorerconstants.h"
#include "applicationlauncher.h" #include "applicationlauncher.h"
#include <utils/outputformat.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/icon.h> #include <utils/icon.h>
...@@ -55,6 +53,8 @@ class RunConfigWidget; ...@@ -55,6 +53,8 @@ class RunConfigWidget;
class RunControl; class RunControl;
class Target; class Target;
namespace Internal { class RunControlPrivate; }
// FIXME: This should also contain a handle to an remote device if used. // FIXME: This should also contain a handle to an remote device if used.
class PROJECTEXPLORER_EXPORT ProcessHandle class PROJECTEXPLORER_EXPORT ProcessHandle
{ {
...@@ -368,10 +368,10 @@ public: ...@@ -368,10 +368,10 @@ public:
Utils::OutputFormatter *outputFormatter(); Utils::OutputFormatter *outputFormatter();
Core::Id runMode() const; Core::Id runMode() const;
const Runnable &runnable() const { return m_runnable; } const Runnable &runnable() const;
void setRunnable(const Runnable &runnable); void setRunnable(const Runnable &runnable);
const Connection &connection() const { return m_connection; } const Connection &connection() const;
void setConnection(const Connection &connection); void setConnection(const Connection &connection);
public slots: public slots:
...@@ -393,24 +393,7 @@ protected: ...@@ -393,24 +393,7 @@ protected:
private: private:
void bringApplicationToForegroundInternal(); void bringApplicationToForegroundInternal();
Internal::RunControlPrivate *d;
QString m_displayName;
Runnable m_runnable;
Connection m_connection;
Core::Id m_runMode;
Utils::Icon m_icon;
const QPointer<RunConfiguration> m_runConfiguration;
QPointer<Project> m_project;
Utils::OutputFormatter *m_outputFormatter;
// A handle to the actual application process.
ProcessHandle m_applicationProcessHandle;
#ifdef Q_OS_MAC
//these two are used to bring apps in the foreground on Mac
qint64 m_internalPid;
int m_foregroundCount;
#endif
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment