Skip to content

Commit

Permalink
- Added ProcessManager from the old QTablet code base.
Browse files Browse the repository at this point in the history
- Now it's possible to start applications from the QLauncher
- QLauncher will be hidden when the application is started.
  • Loading branch information
zchydem committed Jan 7, 2009
1 parent 6b664f0 commit d496e86
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 6 deletions.
8 changes: 6 additions & 2 deletions core/core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ DESTDIR = $$BUILDDIR/core/lib

# Input
HEADERS += comchannel.hh \
settings.hh
settings.hh \
processmanager.hh

SOURCES += comchannel.cc \
settings.cc
settings.cc \
processmanager.cc

target.path = $$INSTALLDIR/lib
headers.files = $$HEADERS
headers.path = $$INSTALLDIR/include
Expand Down
95 changes: 95 additions & 0 deletions core/processmanager.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <processmanager.hh>
#include <QProcess>
#include <QDebug>

namespace qtablet
{
ProcessManager * ProcessManager::instance()
{
static ProcessManager instance;
return &instance;
}


void ProcessManager::exec( QString const & program )
{
if ( program.isEmpty() )
{
return;
}

QProcess *proc = new QProcess( this);


connect( proc, SIGNAL( finished(int, QProcess::ExitStatus ) ),
this, SLOT ( finished(int, QProcess::ExitStatus ) ) );
connect( proc, SIGNAL( error( QProcess::ProcessError ) ),
this, SLOT ( error( QProcess::ProcessError ) ) );
connect( proc, SIGNAL( started() ),
this, SLOT ( started() ) );

qDebug() << "ProcessManager:exec: " << program;
proc->start( program );
m_processMap.insert( proc, ProcessData(0, program) );
}


ProcessManager::ProcessManager()
{

}

ProcessManager::~ProcessManager()
{

}

void ProcessManager::finished( int exitCode, QProcess::ExitStatus exitStatus )
{
Q_UNUSED( exitCode );

// Remove the finished process from the map
QProcess* proc = qobject_cast<QProcess*>( sender() );
ProcessData data = m_processMap.take( proc );

if ( QProcess::CrashExit == exitStatus )
{
// Notify the framework about the crashed process
emit processCrashed( data.getPid(), data.getName() );
}

qDebug() << "ProcessManager: process " << data.getName() << " with pid: " << data.getPid() << "finished.";

// Let Qt handle process deletion
proc->deleteLater();

// Let the world know what this process has finished
emit processFinished( data );
}


void ProcessManager::error( QProcess::ProcessError error )
{
// just forward the error. finished should handle process removal.
emit processError( error );
}

void ProcessManager::started()
{
QProcess* proc = qobject_cast<QProcess*>( sender() );

// Get the ProcessData object from the map and set it's pid
QMap<QProcess*, ProcessData>::iterator it = m_processMap.find( proc );

if ( it == m_processMap.end() ){
qCritical() << "ProcessManager: could not find the process from the processMap";
return;
}

// Now that we are sure that process is ok, let's store its pid
it->setPid( proc->pid() );

// let the interested parties to know that some process has started
emit processStarted( *it );
}
}
146 changes: 146 additions & 0 deletions core/processmanager.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#ifndef PROCESS_MANAGER_HH
#define PROCESS_MANAGER_HH

#include <QObject>
#include <QMap>
#include <QProcess>




namespace qtablet
{
//! ProcessData stores is a class for additional data about the process.
//!
//! Class Process stores process' name or path and the pid.
//! This data will be used e.g. on crash situations for informing the user
//! about the application crash.
//!
class ProcessData
{
public:

//! Default CTor.
ProcessData():
m_name(),
m_pid()
{
}

//! Ctor.
//! \param pid process id
//! \name process name or path
ProcessData( Q_PID const & pid, QString const & name ):
m_name( name ),
m_pid ( pid )
{
}

//! Dtor. Does nothing.
virtual ~ProcessData()
{
}

//! \return name of the process.
QString const getName() const
{
return m_name;
}

//! Set pid.
//! \param pid process id.
void setPid( Q_PID const & pid )
{
m_pid = pid;
}
//! \return the pid of the process.
Q_PID getPid() const
{
return m_pid;
}

//! Assign operator.
//! \param other object to be assigned to this.
ProcessData &operator=(ProcessData const & other)
{
if ( this == &other ){
return *this;
}
m_name = other.m_name;
m_pid = other.m_pid;
return *this;
}

private:
//! Process name
QString m_name;

//! Process id
Q_PID m_pid;
};


//! ProcessManager is a sigleton class for process management in theQTablet framework.

//!
//!
//! $Author: zchydem $
//! $Date: 2008-04-13 23:34:11 +0300 (Sun, 13 Apr 2008) $
//! $Revision: 84 $
class ProcessManager: public QObject
{
Q_OBJECT
public:
//! Get the singleton instance of ProcessManager.
//! \return instance of ProcessManager
static ProcessManager * instance();

//! Execute program \p program and the arguments can be given in the same string
//! \param program e.g. "/usb/bin/ls -la "
void exec( QString const & program );


protected:
//! CTor. Used internally
ProcessManager();

//! Dtor. Does nothing.
virtual ~ProcessManager();

protected slots:
//! Callback which is called when one of the previously started processes finish.
//! \param exitCode see Qt Documentation
//! \param exitStatus see Qt Documentation
void finished( int exitCode, QProcess::ExitStatus exitStatus );

//! Callback which is called on error.
//! \param error see Qt Documentation
void error( QProcess::ProcessError error );

//! Callback which is called when a process has started. After this slot
//! is being called, the process is added to the process map.
void started();

signals:
//! Signal for indicating process crash.
//! \param pid process id
//! \param name process name
void processCrashed( qint64 pid, QString const name );

//! Signal for indicating process error.
//! \param error process error code.
void processError( QProcess::ProcessError error );

//! Signal for indicating that a process has been started
//! \param processData information about the process (pid, name)
void processStarted( ProcessData const processData );

void processFinished( ProcessData const processData );

private:

//! QMap for processes and their names
QMap <QProcess*, ProcessData> m_processMap;
};
}
#endif
7 changes: 5 additions & 2 deletions wall/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ int main( int argc, char *argv[] ){
qtablet::QLauncher * launcher = new qtablet::QLauncher;
scene.addItem( launcher );


qtablet::PannableView * wall = new qtablet::PannableView( Qt::Vertical, 800, 480 );
wall->setLayout( createWall() );
scene.addItem( wall );
Expand All @@ -94,6 +95,8 @@ int main( int argc, char *argv[] ){
group.addState(state1);
group.addState(state2);

QObject::connect( launcher, SIGNAL(hideQLauncher()), state1, SLOT(activate()) );

state1->setConnectionState(button1, SIGNAL(clicked()), state2, SLOT(activate()));
state1->setGeometry( wall, QRectF(0,0,800,480) );
state1->setGeometry( button, QRectF(720,0, 80, 480 ) );
Expand Down Expand Up @@ -122,9 +125,9 @@ int main( int argc, char *argv[] ){
QtAnimation * anim4 = new QtAnimation(launcher, "geometry");

//anim3->setEasingCurve( QtEasingCurve::OutBounce );
anim3->setDuration( 1000 );
//anim3->setDuration( 1000 );
//anim4->setEasingCurve( QtEasingCurve::OutBounce );
anim4->setDuration( 1000 );
//anim4->setDuration( 1000 );

transition2.add(anim3);
transition2.add(new QtAnimation(button, "geometry"));
Expand Down
11 changes: 9 additions & 2 deletions wall/qlauncher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "settings.hh"
#include "labelitem.hh"
#include "desktopfileparser.hh"
#include "processmanager.hh"

#include <QtDebug>
#include <QGraphicsGridLayout>
Expand Down Expand Up @@ -132,9 +133,15 @@ void QLauncher::execApplication(){
qCritical() << "Failed to get signal emitter item";
return;
}
ProcessManager * procMgr = ProcessManager::instance();
if ( procMgr == 0 ){
qCritical() << "QLauncher: Null process manager. Can't execute application";
return;
}

qDebug() << "TODO: execApplication not implemented yet."
<< "exec: " << item->itemAttribute( DesktopFileParser::Exec ).toString();
// TODO: Handle all the signals that ProcessManager emits.
procMgr->exec( item->itemAttribute( DesktopFileParser::Exec ).toString() );
emit hideQLauncher();
}

void QLauncher::showApplicationInfo(){
Expand Down
3 changes: 3 additions & 0 deletions wall/qlauncher.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ protected slots:
void execApplication();
void showApplicationInfo();

signals:
void hideQLauncher();

private:
QLauncherPrivate * d_ptr;
};
Expand Down

0 comments on commit d496e86

Please sign in to comment.