summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLasse Holmstedt <lasse.holmstedt@nokia.com>2012-03-02 09:57:20 +0100
committerMatthias Ettrich <matthias.ettrich@nokia.com>2012-03-02 13:59:49 +0100
commitc9252b54b67b622095976398a24237da36553c37 (patch)
tree87561ed4a2eb01f99886617d611eff33a59531e6 /src
parentc1592fc209da887217ade663f9b3e5ff59aba346 (diff)
Change the PrelaunchProcessBackendFactory constructor to default
Otherwise you must subclass it in order to create it in QML. Change-Id: Idbf78477518f366def7d3aadd56ef14734059db2 Reviewed-by: Matthias Ettrich <matthias.ettrich@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/prelaunchprocessbackendfactory.cpp57
-rw-r--r--src/core/prelaunchprocessbackendfactory.h13
2 files changed, 55 insertions, 15 deletions
diff --git a/src/core/prelaunchprocessbackendfactory.cpp b/src/core/prelaunchprocessbackendfactory.cpp
index a1b435a..7f47863 100644
--- a/src/core/prelaunchprocessbackendfactory.cpp
+++ b/src/core/prelaunchprocessbackendfactory.cpp
@@ -41,6 +41,7 @@
#include "prelaunchprocessbackendfactory.h"
#include "prelaunchprocessbackend.h"
+#include "processinfo.h"
QT_BEGIN_NAMESPACE_PROCESSMANAGER
@@ -61,20 +62,17 @@ const int kPrelaunchTimerInterval = 1000;
/*!
Construct a PrelaunchProcessBackendFactory with optional \a parent.
- The \a info ProcessInfo is used to start the prelaunched process. This is
- different from the final ProcessInfo which will be passed to the prelaunched
- process as a QBinaryJson document.
+ To be able to use the PrelaunchProcessBackendFactory, you also need to set
+ a ProcessInfo object to it that specifies which process is prelaunched.
*/
-
-PrelaunchProcessBackendFactory::PrelaunchProcessBackendFactory(const ProcessInfo& info, QObject *parent)
+PrelaunchProcessBackendFactory::PrelaunchProcessBackendFactory(QObject *parent)
: ProcessBackendFactory(parent)
, m_prelaunch(NULL)
- , m_info(info)
+ , m_info(0)
{
connect(&m_timer, SIGNAL(timeout()), SLOT(timeout()));
m_timer.setSingleShot(true);
m_timer.setInterval(kPrelaunchTimerInterval);
- m_timer.start();
}
/*!
@@ -85,12 +83,22 @@ PrelaunchProcessBackendFactory::~PrelaunchProcessBackendFactory()
{
}
+bool PrelaunchProcessBackendFactory::canCreate(const ProcessInfo &info) const
+{
+ if (!m_info)
+ return false;
+
+ return ProcessBackendFactory::canCreate(info);
+}
+
/*!
Construct a PrelaunchProcessBackend from a ProcessInfo \a info record with \a parent.
*/
-ProcessBackend * PrelaunchProcessBackendFactory::create(const ProcessInfo& info, QObject *parent)
+ProcessBackend * PrelaunchProcessBackendFactory::create(const ProcessInfo &info, QObject *parent)
{
+ Q_ASSERT(m_info);
+
PrelaunchProcessBackend *prelaunch = m_prelaunch;
if ( prelaunch && prelaunch->isReady() ) {
@@ -100,10 +108,9 @@ ProcessBackend * PrelaunchProcessBackendFactory::create(const ProcessInfo& info,
prelaunch->setInfo(info);
prelaunch->setParent(parent);
prelaunch->disconnect(this);
- }
- else {
+ } else {
// qDebug() << "Creating prelaunch from scratch";
- prelaunch = new PrelaunchProcessBackend(m_info, parent);
+ prelaunch = new PrelaunchProcessBackend(*m_info, parent);
prelaunch->prestart();
prelaunch->setInfo(info);
}
@@ -122,6 +129,11 @@ QList<Q_PID> PrelaunchProcessBackendFactory::internalProcesses()
return list;
}
+ProcessInfo *PrelaunchProcessBackendFactory::processInfo() const
+{
+ return m_info;
+}
+
/*!
Return the current launch interval in milliseconds
*/
@@ -174,8 +186,9 @@ void PrelaunchProcessBackendFactory::timeout()
{
Q_ASSERT(m_prelaunch == NULL);
Q_ASSERT(!m_memoryRestricted);
+ Q_ASSERT(m_info);
- m_prelaunch = new PrelaunchProcessBackend(m_info, this);
+ m_prelaunch = new PrelaunchProcessBackend(*m_info, this);
connect(m_prelaunch, SIGNAL(finished(int,QProcess::ExitStatus)),
SLOT(prelaunchFinished(int,QProcess::ExitStatus)));
m_prelaunch->prestart();
@@ -197,6 +210,26 @@ void PrelaunchProcessBackendFactory::prelaunchFinished(int exitCode, QProcess::E
}
/*!
+ Sets the ProcessInfo that is used to determine the prelaunched runtime to \a processInfo.
+ Takes ownership of the object. If the ProcessInfo object is changed, the old object is deleted.
+ */
+void PrelaunchProcessBackendFactory::setProcessInfo(ProcessInfo *processInfo)
+{
+ if (m_info != processInfo) {
+ delete m_info;
+ m_info = processInfo;
+
+ if (m_info) {
+ m_info->setParent(this);
+ m_timer.start();
+ } else {
+ m_timer.stop();
+ }
+ emit processInfoChanged();
+ }
+}
+
+/*!
\fn void PrelaunchProcessBackendFactory::launchIntervalChanged()
This signal is emitted when the launchInterval is changed.
*/
diff --git a/src/core/prelaunchprocessbackendfactory.h b/src/core/prelaunchprocessbackendfactory.h
index 0274cb6..4bda904 100644
--- a/src/core/prelaunchprocessbackendfactory.h
+++ b/src/core/prelaunchprocessbackendfactory.h
@@ -41,31 +41,38 @@
#define PRELAUNCH_PROCESS_BACKEND_FACTORY_H
#include "processbackendfactory.h"
-#include "processinfo.h"
#include "processmanager-global.h"
#include <QTimer>
QT_BEGIN_NAMESPACE_PROCESSMANAGER
+class ProcessInfo;
class PrelaunchProcessBackend;
class Q_ADDON_PROCESSMANAGER_EXPORT PrelaunchProcessBackendFactory : public ProcessBackendFactory
{
Q_OBJECT
Q_PROPERTY(int launchInterval READ launchInterval WRITE setLaunchInterval NOTIFY launchIntervalChanged)
+ Q_PROPERTY(ProcessInfo* processInfo READ processInfo WRITE setProcessInfo NOTIFY processInfoChanged)
public:
- PrelaunchProcessBackendFactory(const ProcessInfo& info, QObject *parent = 0);
+ PrelaunchProcessBackendFactory(QObject *parent = 0);
virtual ~PrelaunchProcessBackendFactory();
+
+ virtual bool canCreate(const ProcessInfo &info) const;
virtual ProcessBackend *create(const ProcessInfo& info, QObject *parent);
virtual QList<Q_PID> internalProcesses();
+ ProcessInfo *processInfo() const;
+ void setProcessInfo(ProcessInfo *processInfo);
+
int launchInterval() const;
void setLaunchInterval(int interval);
signals:
void launchIntervalChanged();
+ void processInfoChanged();
protected:
virtual void handleMemoryRestrictionChange();
@@ -76,7 +83,7 @@ private slots:
private:
PrelaunchProcessBackend *m_prelaunch;
- ProcessInfo m_info;
+ ProcessInfo *m_info;
QTimer m_timer;
};