-rw-r--r-- | core/launcher/runningappbar.cpp | 125 | ||||
-rw-r--r-- | core/launcher/runningappbar.h | 8 |
2 files changed, 82 insertions, 51 deletions
diff --git a/core/launcher/runningappbar.cpp b/core/launcher/runningappbar.cpp index c8f45d5..3ac66f2 100644 --- a/core/launcher/runningappbar.cpp +++ b/core/launcher/runningappbar.cpp @@ -26,3 +26,6 @@ #include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <qdir.h> #include <qtimer.h> @@ -31,3 +34,3 @@ #include <qpainter.h> -#include "qprocess.h" +#include <opie/oprocess.h> #include <qpe/qpeapplication.h> @@ -47,2 +50,3 @@ RunningAppBar::RunningAppBar(QWidget* parent) #ifdef QWS + connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); @@ -50,2 +54,3 @@ RunningAppBar::RunningAppBar(QWidget* parent) #endif + QCopChannel* channel = new QCopChannel( "QPE/System", this ); @@ -57,6 +62,7 @@ RunningAppBar::RunningAppBar(QWidget* parent) -RunningAppBar::~RunningAppBar() { -} +RunningAppBar::~RunningAppBar() +{} -void RunningAppBar::newQcopChannel(const QString& channelName) { +void RunningAppBar::newQcopChannel(const QString& channelName) +{ QString prefix("QPE/Application/"); @@ -72,3 +78,4 @@ void RunningAppBar::newQcopChannel(const QString& channelName) { -void RunningAppBar::removedQcopChannel(const QString& channelName) { +void RunningAppBar::removedQcopChannel(const QString& channelName) +{ QString prefix("QPE/Application/"); @@ -84,3 +91,4 @@ void RunningAppBar::removedQcopChannel(const QString& channelName) { -void RunningAppBar::received(const QCString& msg, const QByteArray& data) { +void RunningAppBar::received(const QCString& msg, const QByteArray& data) +{ // Since fast apps appear and disappear without disconnecting from their @@ -92,3 +100,4 @@ void RunningAppBar::received(const QCString& msg, const QByteArray& data) { addTask(*m_AppLnkSet->findExec(appName)); - } else if ( msg == "fastAppHiding(QString)") { + } + else if ( msg == "fastAppHiding(QString)") { QString appName; @@ -99,3 +108,4 @@ void RunningAppBar::received(const QCString& msg, const QByteArray& data) { -void RunningAppBar::addTask(const AppLnk& appLnk) { +void RunningAppBar::addTask(const AppLnk& appLnk) +{ // qDebug("Added %s to app list.", appLnk.name().latin1()); @@ -107,3 +117,4 @@ void RunningAppBar::addTask(const AppLnk& appLnk) { -void RunningAppBar::removeTask(const AppLnk& appLnk) { +void RunningAppBar::removeTask(const AppLnk& appLnk) +{ unsigned int i = 0; @@ -114,2 +125,12 @@ void RunningAppBar::removeTask(const AppLnk& appLnk) { m_AppList.remove(); + + // grab the keyboard back, in case the app crashed/forgot + + QPEApplication *qpeapp = (QPEApplication *) qApp; + + if ( appLnk.exec() == qpeapp-> keyboardGrabbedBy ( )) { + qDebug ( "grabbing keyboard back from %s", appLnk.name().latin1()); + qpeapp-> grabKeyboard ( ); + } + delete target; @@ -136,3 +157,4 @@ void RunningAppBar::mousePressEvent(QMouseEvent *e) } - } else { + } + else { break; @@ -199,3 +221,4 @@ const int AppMonitor::RAISE_TIMEOUT_MS = 500; AppMonitor::AppMonitor(const AppLnk& app, RunningAppBar& owner) - : QObject(0L), m_Owner(owner), m_App(app), m_PsProc(0L), m_AppKillerBox(0L) { + : QObject(0L), m_Owner(owner), m_App(app), m_AppKillerBox(0L) +{ QCopChannel* channel = new QCopChannel( "QPE/System", this ); @@ -207,3 +230,4 @@ AppMonitor::AppMonitor(const AppLnk& app, RunningAppBar& owner) -AppMonitor::~AppMonitor() { +AppMonitor::~AppMonitor() +{ if (m_AppKillerBox) { @@ -214,3 +238,4 @@ AppMonitor::~AppMonitor() { -void AppMonitor::received(const QCString& msg, const QByteArray& data) { +void AppMonitor::received(const QCString& msg, const QByteArray& data) +{ QDataStream stream( data, IO_ReadOnly ); @@ -239,4 +264,4 @@ void AppMonitor::received(const QCString& msg, const QByteArray& data) { -void AppMonitor::timerExpired() { - // qDebug("Checking in on %s", m_App.name().latin1()); +void AppMonitor::timerExpired() +{ // We store this incase the application responds while we're @@ -251,41 +276,47 @@ void AppMonitor::timerExpired() { if (m_AppKillerBox->exec() == QMessageBox::Yes) { - // qDebug("Killing the app!!! Bwuhahahaha!"); - m_PsProc = new QProcess(QString("ps")); - m_PsProc->addArgument("h"); - m_PsProc->addArgument("-C"); - m_PsProc->addArgument(m_App.exec()); - m_PsProc->addArgument("-o"); - m_PsProc->addArgument("pid"); - connect(m_PsProc, SIGNAL(processExited()), this, SLOT(psProcFinished())); - m_PsProc->start(); - } - else { - // qDebug("Wuss.."); - // WE DELETE OURSELVES HERE! Don't do anything else!! - delete this; - } -} + QDir proc ( "/proc/", "[0-9]*", QDir::Name | QDir::Reversed, QDir::Dirs ); + QStringList allprocs = proc. entryList ( ); -void AppMonitor::psProcFinished() { - QString pid = m_PsProc->readLineStdout(); - delete m_PsProc; - m_PsProc = 0L; + pid_t mypid = ::getpid ( ); - // qDebug("Killing app %s", pid.latin1()); - if (pid.isEmpty()) { - // Hmm.. did the application bail before we got there? - qDebug("AppMonitor: Tried to kill application %s but ps couldn't find it.", m_App.exec().latin1()); - } - else { - int success = kill(pid.toUInt(), SIGKILL); - if (success == 0) { + for ( QStringList::Iterator it = allprocs. begin ( ); it != allprocs. end ( ); ++it ) { + if (( *it ). toInt ( ) <= mypid ) // only interested in children + continue; + + QCString s = QString ( "/proc/" + *it + "/stat" ). local8Bit ( ); + + FILE *fp = ::fopen ( s. data ( ), "r" ); + if ( fp ) { + pid_t pid, ppid; + char *execptr, *exec = 0; + + if ( ::fscanf ( fp, "%d %as %*c %d ", &pid, &execptr, &ppid ) == 3 ) { + exec = execptr [0] ? execptr + 1 : execptr; + if ( exec [0] ) + exec [::strlen ( exec ) - 1] = 0; + + if (( ppid == ::getpid ( )) && ( m_App. exec ( ). local8Bit ( ) == exec )) { + bool success = false; + + qDebug ( "trying to kill pid=%d, exec=%s, ppid=%d", pid, exec, ppid ); + + + success |= ( ::kill ( pid, SIGTERM ) == 0 ); + ::usleep ( 1000 * 500 ); + success |= ( ::kill ( pid, SIGKILL ) == 0 ); + + if ( success ) m_Owner.removeTask(m_App); + + ::free ( execptr ); + break; + } + ::free ( execptr ); + } + ::fclose ( fp ); } - else { - qWarning("Could not kill task %s", m_App.exec().latin1()); } } - - // WE DELETE OURSELVES HERE! Don't do anything else!! delete this; } + diff --git a/core/launcher/runningappbar.h b/core/launcher/runningappbar.h index 880bb69..eb5880e 100644 --- a/core/launcher/runningappbar.h +++ b/core/launcher/runningappbar.h @@ -33,3 +33,4 @@ class QMessageBox; -class RunningAppBar : public QFrame { +class RunningAppBar : public QFrame +{ Q_OBJECT @@ -64,3 +65,4 @@ class RunningAppBar : public QFrame { */ -class AppMonitor : public QObject { +class AppMonitor : public QObject +{ Q_OBJECT @@ -76,3 +78,2 @@ class AppMonitor : public QObject { void received(const QCString& msg, const QByteArray& data); - void psProcFinished(); @@ -82,3 +83,2 @@ class AppMonitor : public QObject { QTimer m_Timer; - QProcess* m_PsProc; QMessageBox* m_AppKillerBox; |