author | zecke <zecke> | 2003-08-28 14:40:33 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-28 14:40:33 (UTC) |
commit | fcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d (patch) (side-by-side diff) | |
tree | 3a304196f52e12761cab01420a189be4369a9522 | |
parent | 8aff9d2f2d079e4500b6bbbd9f410c16cee3f6a1 (diff) | |
download | opie-fcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d.zip opie-fcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d.tar.gz opie-fcc9c16cbd679ebc459ff0ec6228bbdedbfdfe1d.tar.bz2 |
Compile fixes
-rw-r--r-- | core/launcher/qcopbridge.cpp | 222 | ||||
-rw-r--r-- | core/launcher/qcopbridge.h | 25 | ||||
-rw-r--r-- | core/launcher/runningappbar.cpp | 356 |
3 files changed, 228 insertions, 375 deletions
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp index 6177a7c..f780235 100644 --- a/core/launcher/qcopbridge.cpp +++ b/core/launcher/qcopbridge.cpp @@ -23,5 +23,8 @@ -#include <qpe/qcopenvelope_qws.h> -#include <qpe/qpeapplication.h> -#include <qpe/version.h> +#ifdef Q_WS_QWS +#include <qtopia/qcopenvelope_qws.h> +#endif +#include <qtopia/qpeapplication.h> +#include <qtopia/global.h> +#include <qtopia/version.h> @@ -31,2 +34,3 @@ #include <qdatastream.h> +#include <qcstring.h> #include <qstringlist.h> @@ -34,3 +38,4 @@ #include <qregexp.h> -#ifdef QWS +#include <qtimer.h> +#ifdef Q_WS_QWS #include <qcopchannel_qws.h> @@ -38,6 +43,10 @@ +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE +#endif +#ifndef Q_OS_WIN32 #include <pwd.h> -#include <sys/types.h> #include <unistd.h> +#include <sys/types.h> +#endif @@ -47,2 +56,4 @@ +#include "launcherglobal.h" + //#define INSECURE @@ -51,3 +62,3 @@ const int block_size = 51200; -QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , +QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, const char* name ) @@ -70,2 +81,3 @@ QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent , sendSync = FALSE; + openConnections.setAutoDelete( TRUE ); } @@ -79,2 +91,14 @@ QCopBridge::~QCopBridge() +void QCopBridge::authorizeConnections() +{ + QListIterator<QCopBridgePI> it(openConnections); + while ( it.current() ) { + if ( !it.current()->verifyAuthorised() ) { + disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); + openConnections.removeRef( it.current() ); + } else + ++it; + } +} + void QCopBridge::newConnection( int socket ) @@ -83,3 +107,8 @@ void QCopBridge::newConnection( int socket ) openConnections.append( pi ); - connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( connectionClosed( QCopBridgePI *) ) ); + connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); + + /* ### libqtopia merge FIXME */ +#if 0 + QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); +#endif #ifndef QT_NO_COP @@ -94,8 +123,13 @@ void QCopBridge::newConnection( int socket ) -void QCopBridge::connectionClosed( QCopBridgePI *pi ) +void QCopBridge::closed( QCopBridgePI *pi ) { - openConnections.remove( pi ); + emit connectionClosed( pi->peerAddress() ); + openConnections.removeRef( pi ); if ( openConnections.count() == 0 ) { + /* ### FIXME libqtopia merge */ +#if 0 + QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); +#endif #ifndef QT_NO_COP - QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; + QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; #endif @@ -112,71 +146,4 @@ void QCopBridge::closeOpenConnections() -void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args ) +void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) { - command.stripWhiteSpace(); - - int paren = command.find( "(" ); - if ( paren <= 0 ) { - qDebug("DesktopMessage: bad qcop syntax"); - return; - } - - QString params = command.mid( paren + 1 ); - if ( params[params.length()-1] != ')' ) { - qDebug("DesktopMessage: bad qcop syntax"); - return; - } - - params.truncate( params.length()-1 ); - - QStringList paramList = QStringList::split( ",", params ); - QString data; - if ( paramList.count() ) { - QDataStream stream( args, IO_ReadOnly ); - for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { - QString str; - if ( *it == "QString" ) { - stream >> str; - } else if ( *it == "QCString" ) { - QCString cstr; - stream >> cstr; - str = QString::fromLocal8Bit( cstr ); - } else if ( *it == "int" ) { - int i; - stream >> i; - str = QString::number( i ); - } else if ( *it == "bool" ) { - int i; - stream >> i; - str = QString::number( i ); - } else { - qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); - return; - } - QString estr; - for (int i=0; i<(int)str.length(); i++) { - QChar ch = str[i]; - if ( ch.row() ) - goto quick; - switch (ch.cell()) { - case '&': - estr.append( "&" ); - break; - case ' ': - estr.append( "&0x20;" ); - break; - case '\n': - estr.append( "&0x0d;" ); - break; - case '\r': - estr.append( "&0x0a;" ); - break; - default: quick: - estr.append(ch); - } - } - data += " " + estr; - } - } - QString sendCommand = QString(command.data()) + data; - // send the command to all open connections if ( command == "startSync()" ) { @@ -187,5 +154,6 @@ void QCopBridge::desktopMessage( const QCString &command, const QByteArray &args + // send the command to all open connections QCopBridgePI *pi; for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { - pi->sendDesktopMessage( sendCommand ); + pi->sendDesktopMessage( command, data ); } @@ -200,3 +168,3 @@ void QCopBridge::timerEvent( QTimerEvent * ) -QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) +QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) : QSocket( parent, name ) @@ -211,14 +179,11 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) state = Forbidden; - startTimer( 0 ); + close(); } else -#endif +#endif { state = Connected; - sendSync = FALSE; connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); - connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); - QString intro="220 Qtopia "; intro += QPE_VERSION; intro += ";"; - intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; + intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; @@ -227,7 +192,10 @@ QCopBridgePI::QCopBridgePI( int socket, QObject *parent , const char* name ) state = Wait_USER; - - // idle timer to close connections when not used anymore - startTimer( 60000 ); - connected = TRUE; } + sendSync = FALSE; + connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); + + // idle timer to close connections when not used anymore + timer = new QTimer(this); + connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); + timer->start( 300000, TRUE ); } @@ -237,10 +205,16 @@ QCopBridgePI::~QCopBridgePI() { +} +bool QCopBridgePI::verifyAuthorised() +{ + if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { + state = Forbidden; + return FALSE; + } + return TRUE; } -void QCopBridgePI::connectionClosed() +void QCopBridgePI::myConnectionClosed() { emit connectionClosed( this ); - // qDebug( "Debug: Connection closed" ); - delete this; } @@ -249,3 +223,3 @@ void QCopBridgePI::sendDesktopMessage( const QString &msg ) { - QString str = "CALL QPE/Desktop " + msg; + QString str = "CALL QPE/Desktop " + msg; // No tr send ( str ); @@ -253,2 +227,15 @@ void QCopBridgePI::sendDesktopMessage( const QString &msg ) +void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) +{ + if ( !isOpen() ) // eg. Forbidden + return; + const char hdr[]="CALLB QPE/Desktop "; + writeBlock(hdr,sizeof(hdr)-1); + writeBlock(msg,msg.length()); + writeBlock(" ",1); + QByteArray b64 = Opie::Global::encodeBase64(data); + writeBlock(b64.data(),b64.size()); + writeBlock("\r\n",2); +} + @@ -256,2 +243,4 @@ void QCopBridgePI::send( const QString& msg ) { + if ( !isOpen() ) // eg. Forbidden + return; QTextStream os( this ); @@ -263,4 +252,6 @@ void QCopBridgePI::read() { - while ( canReadLine() ) + while ( canReadLine() ) { + timer->start( 300000, TRUE ); process( readLine().stripWhiteSpace() ); + } } @@ -285,4 +276,4 @@ void QCopBridgePI::process( const QString& message ) if ( cmd == "QUIT" ) { - send( "211 Have a nice day!" ); - delete this; + send( "211 Have a nice day!" ); // No tr + close(); return; @@ -298,6 +289,6 @@ void QCopBridgePI::process( const QString& message ) if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { - send( "530 Please login with USER and PASS" ); + send( "530 Please login with USER and PASS" ); // No tr return; } - send( "331 User name ok, need password" ); + send( "331 User name ok, need password" ); // No tr state = Wait_PASS; @@ -310,6 +301,6 @@ void QCopBridgePI::process( const QString& message ) if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { - send( "530 Please login with USER and PASS" ); + send( "530 Please login with USER and PASS" ); // No tr return; } - send( "230 User logged in, proceed" ); + send( "230 User logged in, proceed" ); // No tr state = Ready; @@ -324,4 +315,3 @@ void QCopBridgePI::process( const QString& message ) else if ( cmd == "NOOP" ) { - connected = TRUE; - send( "200 Command okay" ); + send( "200 Command okay" ); // No tr } @@ -334,3 +324,3 @@ void QCopBridgePI::process( const QString& message ) if ( msg.count() < 3 ) { - send( "500 Syntax error, command unrecognized" ); + send( "500 Syntax error, command unrecognized" ); // No tr } @@ -345,3 +335,3 @@ void QCopBridgePI::process( const QString& message ) if ( paren <= 0 ) { - send( "500 Syntax error, command unrecognized" ); + send( "500 Syntax error, command unrecognized" ); // No tr return; @@ -350,4 +340,4 @@ void QCopBridgePI::process( const QString& message ) QString params = command.mid( paren + 1 ); - if ( params[params.length()-1] != ')' ) { - send( "500 Syntax error, command unrecognized" ); + if ( params[(int)params.length()-1] != ')' ) { + send( "500 Syntax error, command unrecognized" ); // No tr return; @@ -363,3 +353,3 @@ void QCopBridgePI::process( const QString& message ) if ( paramList.count() > msg.count() - 3 ) { - send( "500 Syntax error, command unrecognized" ); + send( "500 Syntax error, command unrecognized" ); // No tr return; @@ -383,3 +373,3 @@ void QCopBridgePI::process( const QString& message ) else { - send( "500 Syntax error, command unrecognized" ); + send( "500 Syntax error, command unrecognized" ); // No tr return; @@ -397,3 +387,3 @@ void QCopBridgePI::process( const QString& message ) #endif - + #ifndef QT_NO_COP @@ -404,3 +394,3 @@ void QCopBridgePI::process( const QString& message ) - send( "200 Command okay" ); + send( "200 Command okay" ); // No tr #endif @@ -410,3 +400,3 @@ void QCopBridgePI::process( const QString& message ) else - send( "502 Command not implemented" ); + send( "502 Command not implemented" ); // No tr } @@ -414,9 +404 @@ void QCopBridgePI::process( const QString& message ) - -void QCopBridgePI::timerEvent( QTimerEvent * ) -{ - if ( connected ) - connected = FALSE; - else - connectionClosed(); -} diff --git a/core/launcher/qcopbridge.h b/core/launcher/qcopbridge.h index 408d10d..bae3f88 100644 --- a/core/launcher/qcopbridge.h +++ b/core/launcher/qcopbridge.h @@ -22,2 +22,3 @@ +#include <qtopia/global.h> #include <qserversocket.h> @@ -31,2 +32,3 @@ class QCopBridgePI; class QCopChannel; +class QTimer; @@ -42,10 +44,14 @@ public: void closeOpenConnections(); + void authorizeConnections(); public slots: - void connectionClosed( QCopBridgePI *pi ); + void closed( QCopBridgePI *pi ); void desktopMessage( const QCString &call, const QByteArray & ); - + +signals: + void connectionClosed( const QHostAddress & ); + protected: void timerEvent( QTimerEvent * ); - + private: @@ -69,7 +75,9 @@ public: void sendDesktopMessage( const QString &msg ); + void sendDesktopMessage( const QCString &msg, const QByteArray& ); void startSync() { sendSync = TRUE; } - + bool verifyAuthorised(); + signals: void connectionClosed( QCopBridgePI *); - + protected slots: @@ -78,6 +86,3 @@ protected slots: void process( const QString& command ); - void connectionClosed(); - -protected: - void timerEvent( QTimerEvent *e ); + void myConnectionClosed(); @@ -87,4 +92,4 @@ private: QHostAddress peeraddress; - bool connected; bool sendSync; + QTimer *timer; }; diff --git a/core/launcher/runningappbar.cpp b/core/launcher/runningappbar.cpp index 356200b..1fda5a4 100644 --- a/core/launcher/runningappbar.cpp +++ b/core/launcher/runningappbar.cpp @@ -18,4 +18,3 @@ ** -********************************************************************** -*/ +***********************************************************************/ @@ -23,39 +22,27 @@ -// For "kill" -#include <sys/types.h> -#include <signal.h> -#include <stdio.h> +#include <qtopia/global.h> + #include <stdlib.h> -#include <qdir.h> #include <qtimer.h> #include <qpopupmenu.h> -#include <qmessagebox.h> #include <qpainter.h> -#include <opie/oprocess.h> -#include <qpe/qpeapplication.h> -#include <qpe/applnk.h> -#include <qpe/qcopenvelope_qws.h> -#include <qpe/global.h> -#include <qwindowsystem_qws.h> +#include <qmessagebox.h> + +#include <qtopia/qpeapplication.h> +#include <qtopia/applnk.h> +#include <qtopia/qcopenvelope_qws.h> +#include <qtopia/mimetype.h> + #include "runningappbar.h" +#include "serverinterface.h" RunningAppBar::RunningAppBar(QWidget* parent) - : QFrame(parent), m_AppLnkSet(0L), m_SelectedAppIndex( -1) + : QFrame(parent), selectedAppIndex(-1) { - setBackgroundMode( PaletteBackground ); - - m_AppLnkSet = new AppLnkSet( QPEApplication::qpeDir() + "apps" ); - -#ifdef QWS + QCopChannel* channel = new QCopChannel( "QPE/System", this ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), + this, SLOT(received(const QCString&, const QByteArray&)) ); - connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); - connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); -#endif - - QCopChannel* channel = new QCopChannel( "QPE/System", this ); - connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), - this, SLOT(received(const QCString&, const QByteArray&)) ); - - spacing = AppLnk::smallIconSize() + 3; + spacing = AppLnk::smallIconSize()+3; } @@ -63,69 +50,42 @@ RunningAppBar::RunningAppBar(QWidget* parent) RunningAppBar::~RunningAppBar() -{} - -void RunningAppBar::newQcopChannel(const QString& channelName) -{ - QString prefix("QPE/Application/"); - if (channelName.startsWith(prefix)) { - QString appName = channelName.mid(prefix.length()); - // qDebug("App %s just connected!", appName.latin1()); - const AppLnk* newGuy = m_AppLnkSet->findExec(appName); - if (newGuy && !newGuy->isPreloaded()) { - addTask(*newGuy); - } - } -} - -void RunningAppBar::removedQcopChannel(const QString& channelName) { - QString prefix("QPE/Application/"); - if (channelName.startsWith(prefix)) { - QString appName = channelName.mid(prefix.length()); - qDebug("App %s just disconnected!", appName.latin1()); - const AppLnk* newGuy = m_AppLnkSet->findExec(appName); - if (newGuy) { - removeTask(*newGuy); - } - } } -void RunningAppBar::received(const QCString& msg, const QByteArray& data) -{ - // Since fast apps appear and disappear without disconnecting from their - // channel we need to watch for the showing/hiding events and update according. - QDataStream stream( data, IO_ReadOnly ); - if ( msg == "fastAppShowing(QString)") { - QString appName; - stream >> appName; - addTask(*m_AppLnkSet->findExec(appName)); - } - else if ( msg == "fastAppHiding(QString)") { - QString appName; - stream >> appName; - removeTask(*m_AppLnkSet->findExec(appName)); - } +void RunningAppBar::received(const QCString& msg, const QByteArray& data) { + // Since fast apps appear and disappear without disconnecting from their + // channel we need to watch for the showing/hiding events and update according. + QDataStream stream( data, IO_ReadOnly ); + if ( msg == "fastAppShowing(QString)") { + QString appName; + stream >> appName; + // qDebug("fastAppShowing %s", appName.data() ); + const AppLnk* f = ServerInterface::appLnks().findExec(appName); + if ( f ) addTask(*f); + } else if ( msg == "fastAppHiding(QString)") { + QString appName; + stream >> appName; + const AppLnk* f = ServerInterface::appLnks().findExec(appName); + if ( f ) removeTask(*f); + } } -void RunningAppBar::addTask(const AppLnk& appLnk) -{ - // qDebug("Added %s to app list.", appLnk.name().latin1()); - AppLnk* newApp = new AppLnk(appLnk); - newApp->setExec(appLnk.exec()); - m_AppList.prepend(newApp); - update(); +void RunningAppBar::addTask(const AppLnk& appLnk) { + qDebug("Added %s to app list.", appLnk.name().latin1()); + AppLnk* newApp = new AppLnk(appLnk); + newApp->setExec(appLnk.exec()); + appList.prepend(newApp); + update(); } -void RunningAppBar::removeTask(const AppLnk& appLnk) -{ - unsigned int i = 0; - for (; i < m_AppList.count() ; i++) { - AppLnk* target = m_AppList.at(i); - if (target->exec() == appLnk.exec()) { - qDebug("Removing %s from app list.", appLnk.name().latin1()); - m_AppList.remove(); - - delete target; - } - } - update(); +void RunningAppBar::removeTask(const AppLnk& appLnk) { + unsigned int i = 0; + for (; i < appList.count() ; i++) { + AppLnk* target = appList.at(i); + if (target->exec() == appLnk.exec()) { + qDebug("Removing %s from app list.", appLnk.name().latin1()); + appList.remove(); + delete target; + } + } + update(); } @@ -134,23 +94,22 @@ void RunningAppBar::mousePressEvent(QMouseEvent *e) { - // Find out if the user is clicking on an app icon... - // If so, snag the index so when we repaint we show it - // as highlighed. - m_SelectedAppIndex = 0; - int x = 0; - QListIterator<AppLnk> it( m_AppList ); - for ( ; it.current(); ++it, ++m_SelectedAppIndex, x += spacing ) { - if ( x + spacing <= width() ) { - if ( e->x() >= x && e->x() < x + spacing ) { - if ( m_SelectedAppIndex < (int)m_AppList.count() ) { - repaint(FALSE); - return ; - } - } - } - else { - break; - } + // Find out if the user is clicking on an app icon... + // If so, snag the index so when we repaint we show it + // as highlighed. + selectedAppIndex = 0; + int x=0; + QListIterator<AppLnk> it( appList ); + for ( ; it.current(); ++it,++selectedAppIndex,x+=spacing ) { + if ( x + spacing <= width() ) { + if ( e->x() >= x && e->x() < x+spacing ) { + if ( selectedAppIndex < (int)appList.count() ) { + repaint(FALSE); + return; } - m_SelectedAppIndex = -1; - repaint( FALSE ); + } + } else { + break; + } + } + selectedAppIndex = -1; + repaint( FALSE ); } @@ -159,20 +118,11 @@ void RunningAppBar::mouseReleaseEvent(QMouseEvent *e) { - if (e->button() == QMouseEvent::RightButton) { - return ; - } - if ( m_SelectedAppIndex >= 0 ) { - QString channel = QString("QPE/Application/") + m_AppList.at(m_SelectedAppIndex)->exec(); - if (QCopChannel::isRegistered(channel.latin1())) { - // qDebug("%s is running!", m_AppList.at(m_SelectedAppIndex)->exec().latin1()); - QCopEnvelope e(channel.latin1(), "raise()"); - // This class will delete itself after hearing from the app or the timer expiring - (void)new AppMonitor(*m_AppList.at(m_SelectedAppIndex), *this); - } - else { - removeTask(*m_AppList.at(m_SelectedAppIndex)); - } - - m_SelectedAppIndex = -1; - update(); - } + if (e->button() == QMouseEvent::RightButton) + return; + if ( selectedAppIndex >= 0 ) { + QString app = appList.at(selectedAppIndex)->exec(); + QCopEnvelope e("QPE/System", "raise(QString)"); + e << app; + selectedAppIndex = -1; + update(); + } } @@ -181,23 +131,24 @@ void RunningAppBar::paintEvent( QPaintEvent * ) { - QPainter p( this ); - AppLnk *curApp; - int x = 0; - int y = (height() - AppLnk::smallIconSize()) / 2; - int i = 0; - - //p.fillRect( 0, 0, width(), height(), colorGroup().background() ); - - QListIterator<AppLnk> it(m_AppList); - - for (; it.current(); i++, ++it ) { - if ( x + spacing <= width() ) { - curApp = it.current(); - if ( (int)i == m_SelectedAppIndex ) - p.fillRect( x, y, spacing, curApp->pixmap().height() + 1, colorGroup().highlight() ); - else - // p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 ); - p.drawPixmap( x, y, curApp->pixmap() ); - x += spacing; - } - } + QPainter p( this ); + AppLnk *curApp; + int x = 0; + int y = (height() - AppLnk::smallIconSize()) / 2; + int i = 0; + + p.fillRect( 0, 0, width(), height(), colorGroup().background() ); + + QListIterator<AppLnk> it(appList); + + for (; it.current(); i++, ++it ) { + if ( x + spacing <= width() ) { + curApp = it.current(); + qWarning("Drawing %s", curApp->name().latin1() ); + if ( (int)i == selectedAppIndex ) + p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() ); + else + p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 ); + p.drawPixmap( x, y, curApp->pixmap() ); + x += spacing; + } + } } @@ -206,108 +157,23 @@ QSize RunningAppBar::sizeHint() const { - return QSize( frameWidth(), AppLnk::smallIconSize() + frameWidth()*2 + 3 ); + return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 ); } -const int AppMonitor::RAISE_TIMEOUT_MS = 500; - -AppMonitor::AppMonitor(const AppLnk& app, RunningAppBar& owner) - : QObject(0L), m_Owner(owner), m_App(app), m_AppKillerBox(0L) +void RunningAppBar::applicationLaunched(const QString &appName) { - QCopChannel* channel = new QCopChannel( "QPE/System", this ); - connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), - this, SLOT(received(const QCString&, const QByteArray&)) ); - connect(&m_Timer, SIGNAL(timeout()), this, SLOT(timerExpired())); - m_Timer.start(RAISE_TIMEOUT_MS, TRUE); + qDebug("desktop:: app: %s launched with pid ", appName.data() ); + const AppLnk* newGuy = ServerInterface::appLnks().findExec(appName); + if ( newGuy && !newGuy->isPreloaded() ) { + addTask( *newGuy ); + } } -AppMonitor::~AppMonitor() +void RunningAppBar::applicationTerminated(const QString &app) { - if (m_AppKillerBox) { - delete m_AppKillerBox; - m_AppKillerBox = 0L; - } -} - -void AppMonitor::received(const QCString& msg, const QByteArray& data) -{ - QDataStream stream( data, IO_ReadOnly ); - - if (msg == "appRaised(QString)") { - QString appName; - stream >> appName; - if (appName == m_App.exec()) { - // qDebug("Got a heartbeat from %s", appName.latin1()); - m_Timer.stop(); - // Check to make sure we're not waiting on user input... - if (m_AppKillerBox) { - // If we are, we kill the dialog box, and the code waiting on the result - // will clean us up (basically the user said "no"). - delete m_AppKillerBox; - m_AppKillerBox = 0L; - } - else { - // Ok, we're not waiting on user input, so clean us up now. - // WE DELETE OURSELVES HERE! Don't do anything else!! - delete this; - } - } - } + const AppLnk* gone = ServerInterface::appLnks().findExec(app); + if ( gone ) { + removeTask(*gone); + } } -void AppMonitor::timerExpired() -{ - // We store this incase the application responds while we're - // waiting for user input so we know not to delete ourselves. This - // will be cleaned up in the destructor. - m_AppKillerBox = new QMessageBox(tr("Application Problem"), - tr("<p>%1 is not responding.</p>").arg(m_App.name()) + - tr("<p>Would you like to force the application to exit?</p>"), - QMessageBox::Warning, QMessageBox::Yes, - QMessageBox::No | QMessageBox::Default, - QMessageBox::NoButton); - if ( m_AppKillerBox-> exec ( ) == QMessageBox::Yes ) { - QDir proc ( "/proc/", "[0-9]*", QDir::Name | QDir::Reversed, QDir::Dirs ); - QStringList allprocs = proc. entryList ( ); - - pid_t mypid = ::getpid ( ); - - 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 ); - } - } - } - delete this; -} |