-rw-r--r-- | core/launcher/desktop.cpp | 6 | ||||
-rw-r--r-- | core/launcher/launcher.cpp | 6 | ||||
-rw-r--r-- | core/launcher/launcher.pro | 2 | ||||
-rw-r--r-- | core/launcher/runningappbar.cpp | 287 | ||||
-rw-r--r-- | core/launcher/runningappbar.h | 88 | ||||
-rw-r--r-- | core/launcher/startmenu.cpp | 4 | ||||
-rw-r--r-- | core/launcher/taskbar.cpp | 21 | ||||
-rw-r--r-- | core/launcher/taskbar.h | 10 |
8 files changed, 405 insertions, 19 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index a19e4c6..bca95b2 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp @@ -1,1034 +1,1034 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "desktop.h" #include "info.h" #include "launcher.h" -#include "mrulist.h" +//#include "mrulist.h" #include "qcopbridge.h" #include "shutdownimpl.h" #include "startmenu.h" #include "taskbar.h" #include "transferserver.h" #include "irserver.h" #include "packageslave.h" #include <qpe/applnk.h> #include <qpe/mimetype.h> #include <qpe/password.h> #include <qpe/config.h> #include <qpe/power.h> #include <qpe/timeconversion.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/network.h> #include <qpe/global.h> #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) #include <qpe/custom.h> #endif #include <opie/odevice.h> #include <qgfx_qws.h> #include <qmainwindow.h> #include <qmessagebox.h> #include <qtimer.h> #include <qwindowsystem_qws.h> #include <qvaluelist.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> class QCopKeyRegister { public: QCopKeyRegister() : keyCode( 0 ) { } QCopKeyRegister( int k, const QString &c, const QString &m ) : keyCode( k ), channel( c ), message( m ) { } int getKeyCode() const { return keyCode; } QString getChannel() const { return channel; } QString getMessage() const { return message; } private: int keyCode; QString channel, message; }; typedef QValueList<QCopKeyRegister> KeyRegisterList; KeyRegisterList keyRegisterList; static Desktop* qpedesktop = 0; static int loggedin = 0; static void login( bool at_poweron ) { if ( !loggedin ) { Global::terminateBuiltin( "calibrate" ); Password::authenticate( at_poweron ); loggedin = 1; QCopEnvelope e( "QPE/Desktop", "unlocked()" ); } } bool Desktop::screenLocked() { return loggedin == 0; } /* Priority is number of alerts that are needed to pop up alert. */ class DesktopPowerAlerter : public QMessageBox { public: DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) : QMessageBox( tr( "Battery Status" ), "Low Battery", QMessageBox::Critical, QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton, QMessageBox::NoButton, parent, name, FALSE ) { currentPriority = INT_MAX; alertCount = 0; } void alert( const QString &text, int priority ); void hideEvent( QHideEvent * ); private: int currentPriority; int alertCount; }; void DesktopPowerAlerter::alert( const QString &text, int priority ) { alertCount++; if ( alertCount < priority ) return ; if ( priority > currentPriority ) return ; currentPriority = priority; setText( text ); show(); } void DesktopPowerAlerter::hideEvent( QHideEvent *e ) { QMessageBox::hideEvent( e ); alertCount = 0; currentPriority = INT_MAX; } class QPEScreenSaver : public QWSScreenSaver { private: int LcdOn; public: QPEScreenSaver() { m_disable_suspend = 100; m_enable_dim = false; m_enable_lightoff = false; m_enable_onlylcdoff = false; m_lcd_status = true; m_backlight_bright = -1; m_backlight_forcedoff = false; // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) ODevice::inst ( ) -> setDisplayStatus ( true ); } void restore() { if ( !m_lcd_status ) // We must have turned it off ODevice::inst ( ) -> setDisplayStatus ( true ); setBacklight ( -1 ); } bool save( int level ) { switch ( level ) { case 0: if ( m_disable_suspend > 0 && m_enable_dim ) { if ( backlight() > 1 ) setBacklight( 1 ); // lowest non-off } return true; break; case 1: if ( m_disable_suspend > 1 && m_enable_lightoff ) { setBacklight( 0 ); // off } return true; break; case 2: if ( m_enable_onlylcdoff ) { ODevice::inst ( ) -> setDisplayStatus ( false ); m_lcd_status = false; return true; } else // We're going to suspend the whole machine { if ( ( m_disable_suspend > 2 ) && ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && ( !Network::networkOnline ( ) ) ) { QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); return true; } } break; } return false; } private: static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) { if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) return 0; if ( interval < 0 ) { // Restore screen blanking and power saving state interval = config.readNumEntry( value, def ); } return interval; } public: void setIntervals( int i1, int i2, int i3 ) { Config config( "qpe" ); config.setGroup( "Screensaver" ); int v[ 4 ]; i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); i3 = ssi( i3, config, "", "Interval", 60 ); //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); v [ 0 ] = QMAX( 1000 * i1, 100 ); v [ 1 ] = QMAX( 1000 * i2, 100 ); v [ 2 ] = QMAX( 1000 * i3, 100 ); v [ 3 ] = 0; m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); if ( !i1 && !i2 && !i3 ) QWSServer::setScreenSaverInterval( 0 ); else QWSServer::setScreenSaverIntervals( v ); } void setInterval ( int interval ) { setIntervals ( -1, -1, interval ); } void setMode ( int mode ) { if ( mode > m_disable_suspend ) setInterval( -1 ); m_disable_suspend = mode; } int backlight ( ) { if ( m_backlight_bright == -1 ) { // Read from config Config config ( "qpe" ); config. setGroup ( "Screensaver" ); m_backlight_bright = config. readNumEntry ( "Brightness", 255 ); } return m_backlight_bright; } void setBacklight ( int bright ) { if ( bright == -3 ) { // Forced on m_backlight_forcedoff = false; bright = -1; } if ( m_backlight_forcedoff && bright != -2 ) return ; if ( bright == -2 ) { // Toggle between off and on bright = m_backlight_bright ? 0 : -1; m_backlight_forcedoff = !bright; } m_backlight_bright = bright; bright = backlight ( ); ODevice::inst ( ) -> setDisplayBrightness ( bright ); m_backlight_bright = bright; } private: int m_disable_suspend; bool m_enable_dim; bool m_enable_lightoff; bool m_enable_onlylcdoff; bool m_lcd_status; int m_backlight_bright; bool m_backlight_forcedoff; }; void DesktopApplication::switchLCD ( bool on ) { if ( qApp ) { DesktopApplication *dapp = (DesktopApplication *) qApp; - + if ( dapp-> m_screensaver ) dapp-> m_screensaver-> setBacklight ( on ? -3 : -1 ); } } DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) : QPEApplication( argc, argv, appType ) { QTimer * t = new QTimer( this ); connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); t->start( 10000 ); ps = new PowerStatus; pa = new DesktopPowerAlerter( 0 ); channel = new QCopChannel( "QPE/Desktop", this ); connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); channel = new QCopChannel( "QPE/System", this ); connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); m_screensaver = new QPEScreenSaver; m_screensaver-> setInterval ( -1 ); QWSServer::setScreenSaver( m_screensaver ); } DesktopApplication::~DesktopApplication() { delete ps; delete pa; } void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) { #ifdef Q_WS_QWS QDataStream stream( data, IO_ReadOnly ); if ( msg == "keyRegister(int key, QString channel, QString message)" ) { int k; QString c, m; stream >> k; stream >> c; stream >> m; qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); keyRegisterList.append( QCopKeyRegister( k, c, m ) ); } else if ( msg == "suspend()" ) { emit power(); } #endif } void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) { #ifdef Q_WS_QWS QDataStream stream ( data, IO_ReadOnly ); if ( msg == "setScreenSaverInterval(int)" ) { int time; stream >> time; m_screensaver-> setInterval( time ); } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { int t1, t2, t3; stream >> t1 >> t2 >> t3; m_screensaver-> setIntervals( t1, t2, t3 ); } else if ( msg == "setBacklight(int)" ) { int bright; stream >> bright; m_screensaver-> setBacklight( bright ); } else if ( msg == "setScreenSaverMode(int)" ) { int mode; stream >> mode; m_screensaver-> setMode ( mode ); } #endif } enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; #ifdef Q_WS_QWS bool DesktopApplication::qwsEventFilter( QWSEvent *e ) { qpedesktop->checkMemory(); if ( e->type == QWSEvent::Key ) { QWSKeyEvent * ke = ( QWSKeyEvent * ) e; if ( !loggedin && ke->simpleData.keycode != Key_F34 ) return TRUE; bool press = ke->simpleData.is_press; bool autoRepeat = ke->simpleData.is_auto_repeat; /* app that registers key/message to be sent back to the app, when it doesn't have focus, when user presses key, unless keyboard has been requested from app. will not send multiple repeats if user holds key i.e. one shot */ if ( !keyRegisterList.isEmpty() ) { KeyRegisterList::Iterator it; for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() && press ) { if ( press ) qDebug( "press" ); else qDebug( "release" ); QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); } } } if ( !keyboardGrabbed() ) { if ( ke->simpleData.keycode == Key_F9 ) { if ( press ) emit datebook(); return TRUE; } if ( ke->simpleData.keycode == Key_F10 ) { if ( !press && cardSendTimer ) { emit contacts(); delete cardSendTimer; } else if ( press ) { cardSendTimer = new QTimer(); cardSendTimer->start( 2000, TRUE ); connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); } return TRUE; } /* menu key now opens application menu/toolbar if ( ke->simpleData.keycode == Key_F11 ) { if ( press ) emit menu(); return TRUE; } */ if ( ke->simpleData.keycode == Key_F12 ) { while ( activePopupWidget() ) activePopupWidget() ->close(); if ( press ) emit launch(); return TRUE; } if ( ke->simpleData.keycode == Key_F13 ) { if ( press ) emit email(); return TRUE; } } if ( ke->simpleData.keycode == Key_F34 ) { if ( press ) emit power(); return TRUE; } // This was used for the iPAQ PowerButton // See main.cpp for new KeyboardFilter // // if ( ke->simpleData.keycode == Key_SysReq ) { // if ( press ) emit power(); // return TRUE; // } if ( ke->simpleData.keycode == Key_F35 ) { if ( press ) emit backlight(); return TRUE; } if ( ke->simpleData.keycode == Key_F32 ) { if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); return TRUE; } if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { if ( press ) emit symbol(); return TRUE; } if ( ke->simpleData.keycode == Key_NumLock ) { if ( press ) emit numLockStateToggle(); } if ( ke->simpleData.keycode == Key_CapsLock ) { if ( press ) emit capsLockStateToggle(); } if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) qpedesktop->keyClick(); } else { if ( e->type == QWSEvent::Mouse ) { QWSMouseEvent * me = ( QWSMouseEvent * ) e; static bool up = TRUE; if ( me->simpleData.state & LeftButton ) { if ( up ) { up = FALSE; qpedesktop->screenClick(); } } else { up = TRUE; } } } return QPEApplication::qwsEventFilter( e ); } #endif void DesktopApplication::psTimeout() { qpedesktop->checkMemory(); // in case no events are being generated *ps = PowerStatusManager::readStatus(); if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { pa->alert( tr( "Battery is running very low." ), 6 ); } if ( ps->batteryStatus() == PowerStatus::Critical ) { pa->alert( tr( "Battery level is critical!\n" "Keep power off until power restored!" ), 1 ); } if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 3 ); } } void DesktopApplication::sendCard() { delete cardSendTimer; cardSendTimer = 0; QString card = getenv( "HOME" ); card += "/Applications/addressbook/businesscard.vcf"; if ( QFile::exists( card ) ) { QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); QString mimetype = "text/x-vCard"; e << tr( "business card" ) << card << mimetype; } } #if defined(QPE_HAVE_MEMALERTER) QPE_MEMALERTER_IMPL #endif //=========================================================================== Desktop::Desktop() : QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), qcopBridge( 0 ), transferServer( 0 ), packageSlave( 0 ) { qpedesktop = this; // bg = new Info( this ); tb = new TaskBar; launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); int displayw = qApp->desktop() ->width(); int displayh = qApp->desktop() ->height(); QSize sz = tb->sizeHint(); setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); tb->show(); launcher->showMaximized(); launcher->show(); launcher->raise(); #if defined(QPE_HAVE_MEMALERTER) initMemalerter(); #endif // start services startTransferServer(); ( void ) new IrServer( this ); rereadVolumes(); packageSlave = new PackageSlave( this ); connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); qApp->installEventFilter( this ); } void Desktop::show() { login( TRUE ); QWidget::show(); } Desktop::~Desktop() { delete launcher; delete tb; delete qcopBridge; delete transferServer; } bool Desktop::recoverMemory() { return tb->recoverMemory(); } void Desktop::checkMemory() { #if defined(QPE_HAVE_MEMALERTER) static bool ignoreNormal = FALSE; static bool existingMessage = FALSE; if ( existingMessage ) return ; // don't show a second message while still on first existingMessage = TRUE; switch ( memstate ) { case Unknown: break; case Low: memstate = Unknown; if ( recoverMemory() ) ignoreNormal = TRUE; else QMessageBox::warning( 0 , "Memory Status", "The memory smacks of shortage. \n" "Please save data. " ); break; case Normal: memstate = Unknown; if ( ignoreNormal ) ignoreNormal = FALSE; else QMessageBox::information ( 0 , "Memory Status", "There is enough memory again." ); break; case VeryLow: memstate = Unknown; QMessageBox::critical( 0 , "Memory Status", "The memory is very low. \n" "Please end this application \n" "immediately." ); recoverMemory(); } existingMessage = FALSE; #endif } static bool isVisibleWindow( int wid ) { const QList<QWSWindow> &list = qwsServer->clientWindows(); QWSWindow* w; for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { if ( w->winId() == wid ) return !w->isFullyObscured(); } return FALSE; } static bool hasVisibleWindow( const QString& clientname ) { const QList<QWSWindow> &list = qwsServer->clientWindows(); QWSWindow* w; for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) return TRUE; } return FALSE; } void Desktop::raiseLauncher() { Config cfg( "qpe" ); //F12 'Home' cfg.setGroup( "AppsKey" ); QString tempItem; tempItem = cfg.readEntry( "Middle", "Home" ); if ( tempItem == "Home" || tempItem.isEmpty() ) { if ( isVisibleWindow( launcher->winId() ) ) launcher->nextView(); else launcher->raise(); } else { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << tempItem; } } void Desktop::executeOrModify( const QString& appLnkFile ) { AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); if ( lnk.isValid() ) { QCString app = lnk.exec().utf8(); Global::terminateBuiltin( "calibrate" ); if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { - MRUList::addTask( &lnk ); + // MRUList::addTask( &lnk ); if ( hasVisibleWindow( app ) ) QCopChannel::send( "QPE/Application/" + app, "nextView()" ); else QCopChannel::send( "QPE/Application/" + app, "raise()" ); } else { lnk.execute(); } } } void Desktop::raiseDatebook() { Config cfg( "qpe" ); //F9 'Activity' cfg.setGroup( "AppsKey" ); QString tempItem; tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); if ( tempItem == "Calendar" || tempItem.isEmpty() ) { tempItem = "datebook"; } QCopEnvelope e( "QPE/System", "execute(QString)" ); e << tempItem; } void Desktop::raiseContacts() { Config cfg( "qpe" ); //F10, 'Contacts' cfg.setGroup( "AppsKey" ); QString tempItem; tempItem = cfg.readEntry( "Left2nd", "Address Book" ); if ( tempItem == "Address Book" || tempItem.isEmpty() ) { tempItem = "addressbook"; } QCopEnvelope e( "QPE/System", "execute(QString)" ); e << tempItem; } void Desktop::raiseMenu() { Config cfg( "qpe" ); //F11, 'Menu cfg.setGroup( "AppsKey" ); QString tempItem; tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { Global::terminateBuiltin( "calibrate" ); tb->startMenu() ->launch(); } else { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << tempItem; } } void Desktop::raiseEmail() { Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 cfg.setGroup( "AppsKey" ); QString tempItem; tempItem = cfg.readEntry( "RightEnd", "Mail" ); if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { tempItem = "mail"; } QCopEnvelope e( "QPE/System", "execute(QString)" ); e << tempItem; } // autoStarts apps on resume and start void Desktop::execAutoStart() { QString appName; int delay; QDateTime now = QDateTime::currentDateTime(); Config cfg( "autostart" ); cfg.setGroup( "AutoStart" ); appName = cfg.readEntry( "Apps", "" ); delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); // If the time between suspend and resume was longer then the // value saved as delay, start the app if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << QString( appName ); } } #if defined(QPE_HAVE_TOGGLELIGHT) #include <qpe/config.h> #include <sys/ioctl.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include <linux/ioctl.h> #include <time.h> #endif void Desktop::togglePower() { static bool excllock = false; if ( excllock ) return ; excllock = true; bool wasloggedin = loggedin; loggedin = 0; suspendTime = QDateTime::currentDateTime(); ODevice::inst ( ) -> suspend ( ); QWSServer::screenSaverActivate ( false ); DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call { QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep } if ( wasloggedin ) login( TRUE ); execAutoStart(); //qcopBridge->closeOpenConnections(); excllock = false; } void Desktop::toggleLight() { QCopEnvelope e( "QPE/System", "setBacklight(int)" ); e << -2; // toggle } void Desktop::toggleSymbolInput() { tb->toggleSymbolInput(); } void Desktop::toggleNumLockState() { tb->toggleNumLockState(); } void Desktop::toggleCapsLockState() { tb->toggleCapsLockState(); } void Desktop::styleChange( QStyle &s ) { QWidget::styleChange( s ); int displayw = qApp->desktop() ->width(); int displayh = qApp->desktop() ->height(); QSize sz = tb->sizeHint(); tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); } void DesktopApplication::shutdown() { if ( type() != GuiServer ) return ; ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), this, SLOT( shutdown( ShutdownImpl::Type ) ) ); sd->showMaximized(); } void DesktopApplication::shutdown( ShutdownImpl::Type t ) { switch ( t ) { case ShutdownImpl::ShutdownSystem: execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 ); break; case ShutdownImpl::RebootSystem: execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 ); break; case ShutdownImpl::RestartDesktop: restart(); break; case ShutdownImpl::TerminateDesktop: prepareForTermination( FALSE ); // This is a workaround for a Qt bug // clipboard applet has to stop its poll timer, or Qt/E // will hang on quit() right before it emits aboutToQuit() emit aboutToQuit ( ); quit(); break; } } void DesktopApplication::restart() { prepareForTermination( TRUE ); #ifdef Q_WS_QWS for ( int fd = 3; fd < 100; fd++ ) close( fd ); #if defined(QT_DEMO_SINGLE_FLOPPY) execl( "/sbin/init", "qpe", 0 ); #elif defined(QT_QWS_CASSIOPEIA) execl( "/bin/sh", "sh", 0 ); #else execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); #endif exit( 1 ); #endif } void Desktop::startTransferServer() { // start qcop bridge server qcopBridge = new QCopBridge( 4243 ); if ( !qcopBridge->ok() ) { delete qcopBridge; qcopBridge = 0; } // start transfer server transferServer = new TransferServer( 4242 ); if ( !transferServer->ok() ) { delete transferServer; transferServer = 0; } if ( !transferServer || !qcopBridge ) startTimer( 2000 ); } void Desktop::timerEvent( QTimerEvent *e ) { killTimer( e->timerId() ); startTransferServer(); } void Desktop::terminateServers() { delete transferServer; delete qcopBridge; transferServer = 0; qcopBridge = 0; } void Desktop::rereadVolumes() { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); touchclick = cfg.readBoolEntry( "TouchSound" ); keyclick = cfg.readBoolEntry( "KeySound" ); alarmsound = cfg.readBoolEntry( "AlarmSound" ); } void Desktop::keyClick() { if ( keyclick ) ODevice::inst ( ) -> keySound ( ); } void Desktop::screenClick() { if ( touchclick ) ODevice::inst ( ) -> touchSound ( ); } void Desktop::soundAlarm() { if ( qpedesktop-> alarmsound ) ODevice::inst ( ) -> alarmSound ( ); } bool Desktop::eventFilter( QObject *, QEvent *ev ) { if ( ev-> type ( ) == QEvent::KeyPress ) { QKeyEvent * ke = ( QKeyEvent * ) ev; if ( ke-> key ( ) == Qt::Key_F11 ) { // menu key QWidget * active = qApp-> activeWindow ( ); if ( active && active-> isPopup ( ) ) active->close(); /* * On iPAQ 38xx that key is not the "menu key" but the mail key * To not confuse the users, make it launch the mail app on 38xx */ if ( ODevice::inst() ->model() == OMODEL_iPAQ_H38xx ) { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << QString( "mail" ); return true; } else { raiseMenu ( ); return true; } } } return false; } diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp index effcd24..fd89410 100644 --- a/core/launcher/launcher.cpp +++ b/core/launcher/launcher.cpp @@ -1,1003 +1,1003 @@ /********************************************************************** ** Copyright (c) 2002 Holger zecke Freyther ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT // have this class. #define QTOPIA_INTERNAL_FSLP #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/resource.h> #include <qpe/applnk.h> #include <qpe/config.h> #include <qpe/global.h> #include <qpe/qpeapplication.h> #include <qpe/mimetype.h> #include <qpe/storage.h> #include <qpe/palmtoprecord.h> #include <qdatetime.h> #include <qdir.h> #include <qwindowsystem_qws.h> #include <qtimer.h> #include <qcombobox.h> #include <qvbox.h> #include <qlayout.h> #include <qstyle.h> #include <qpushbutton.h> #include <qtabbar.h> #include <qwidgetstack.h> #include <qlayout.h> #include <qregexp.h> #include <qmessagebox.h> #include <qframe.h> #include <qpainter.h> #include <qlabel.h> #include <qtextstream.h> #include "launcherview.h" #include "launcher.h" #include "syncdialog.h" #include "desktop.h" #include <qpe/lnkproperties.h> -#include "mrulist.h" +//#include "mrulist.h" #include "qrsync.h" #include <stdlib.h> #include <unistd.h> #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <stdio.h> #include <sys/vfs.h> #include <mntent.h> #endif #include <qpe/storage.h> #include "mediummountgui.h" //#define SHOW_ALL // uidGen // uidGen namespace { QStringList configToMime( Config *cfg ){ QStringList mimes; bool tmpMime = true; cfg->setGroup("mimetypes" ); tmpMime = cfg->readBoolEntry("all" ,true); if( tmpMime ){ mimes << QString::null; return mimes; }else{ tmpMime = cfg->readBoolEntry("audio", true ); if(tmpMime ) mimes.append("audio/*" ); tmpMime = cfg->readBoolEntry("image", true ); if(tmpMime ) mimes.append("image/*" ); tmpMime = cfg->readBoolEntry("text", true ); if(tmpMime ) mimes.append("text/*"); tmpMime = cfg->readBoolEntry("video", true ); if(tmpMime ) mimes.append("video/*" ); } return mimes; } } CategoryTabWidget::CategoryTabWidget( QWidget* parent ) : QVBox( parent ) { categoryBar = 0; stack = 0; } void CategoryTabWidget::prevTab() { if ( categoryBar ) { int n = categoryBar->count(); int tab = categoryBar->currentTab(); if ( tab >= 0 ) categoryBar->setCurrentTab( (tab - 1 + n)%n ); } } void CategoryTabWidget::nextTab() { if ( categoryBar ) { int n = categoryBar->count(); int tab = categoryBar->currentTab(); categoryBar->setCurrentTab( (tab + 1)%n ); } } void CategoryTabWidget::addItem( const QString& linkfile ) { int i=0; AppLnk *app = new AppLnk(linkfile); if ( !app->isValid() ) { delete app; return; } if ( !app->file().isEmpty() ) { // A document delete app; app = new DocLnk(linkfile); ((LauncherView*)(stack->widget(ids.count()-1)))->addItem(app); return; } for ( QStringList::Iterator it=ids.begin(); it!=ids.end(); ++it) { if ( !(*it).isEmpty() ) { QRegExp tf(*it,FALSE,TRUE); if ( tf.match(app->type()) >= 0 ) { ((LauncherView*)stack->widget(i))->addItem(app); return; } i++; } } } void CategoryTabWidget::initializeCategories(AppLnkSet* rootFolder, AppLnkSet* docFolder, const QList<FileSystem> &fs) { delete categoryBar; categoryBar = new CategoryTabBar( this ); QPalette pal = categoryBar->palette(); pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); categoryBar->setPalette( pal ); delete stack; stack = new QWidgetStack(this); tabs=0; ids.clear(); QStringList types = rootFolder->types(); for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) { if ( !(*it).isEmpty() ) { newView(*it,rootFolder->typePixmap(*it),rootFolder->typeName(*it)); } } QListIterator<AppLnk> it( rootFolder->children() ); AppLnk* l; while ( (l=it.current()) ) { if ( l->type() == "Separator" ) { rootFolder->remove(l); delete l; } else { int i=0; for ( QStringList::Iterator it=types.begin(); it!=types.end(); ++it) { if ( *it == l->type() ) ((LauncherView*)stack->widget(i))->addItem(l,FALSE); i++; } } ++it; } rootFolder->detachChildren(); for (int i=0; i<tabs; i++) ((LauncherView*)stack->widget(i))->sort(); // all documents docview = newView( QString::null, Resource::loadPixmap("DocsIcon"), tr("Documents")); docview->populate( docFolder, QString::null ); docFolder->detachChildren(); docview->setFileSystems(fs); docview->setToolsEnabled(TRUE); connect( categoryBar, SIGNAL(selected(int)), stack, SLOT(raiseWidget(int)) ); ((LauncherView*)stack->widget(0))->setFocus(); categoryBar->show(); stack->show(); } void CategoryTabWidget::updateDocs(AppLnkSet* docFolder, const QList<FileSystem> &fs) { docview->populate( docFolder, QString::null ); docFolder->detachChildren(); docview->setFileSystems(fs); docview->updateTools(); } LauncherView* CategoryTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label ) { LauncherView* view = new LauncherView( stack ); connect( view, SIGNAL(clicked(const AppLnk*)), this, SIGNAL(clicked(const AppLnk*))); connect( view, SIGNAL(rightPressed(AppLnk*)), this, SIGNAL(rightPressed(AppLnk*))); ids.append(id); categoryBar->addTab( new QTab( pm, label ) ); stack->addWidget( view, tabs++ ); return view; } void CategoryTabWidget::updateLink(const QString& linkfile) { int i=0; LauncherView* view; while ((view = (LauncherView*)stack->widget(i++))) { if ( view->removeLink(linkfile) ) break; } addItem(linkfile); docview->updateTools(); } void CategoryTabWidget::paletteChange( const QPalette &p ) { QVBox::paletteChange( p ); QPalette pal = palette(); pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); categoryBar->setPalette( pal ); categoryBar->update(); } void CategoryTabWidget::setBusy(bool on) { if ( on ) ((LauncherView*)stack->visibleWidget())->setBusy(TRUE); else for (int i=0; i<tabs; i++) ((LauncherView*)stack->widget(i))->setBusy(FALSE); } CategoryTabBar::CategoryTabBar( QWidget *parent, const char *name ) : QTabBar( parent, name ) { setFocusPolicy( NoFocus ); connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) ); } CategoryTabBar::~CategoryTabBar() { } void CategoryTabBar::layoutTabs() { if ( !count() ) return; // int percentFalloffTable[] = { 100, 70, 40, 12, 6, 3, 1, 0 }; int hiddenTabWidth = -7; int middleTab = currentTab(); int hframe, vframe, overlap; style().tabbarMetrics( this, hframe, vframe, overlap ); QFontMetrics fm = fontMetrics(); int x = 0; QRect r; QTab *t; int available = width()-1; int required = 0; for ( int i = 0; i < count(); i++ ) { t = tab(i); // if (( i < (middleTab - 1) ) || ( i > (middleTab + 1) )) { if ( i != middleTab ) { // required += hiddenTabWidth + hframe - overlap; available -= hiddenTabWidth + hframe - overlap; if ( t->iconSet() != 0 ) available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); } else { required += fm.width( t->text() ) + hframe - overlap; if ( t->iconSet() != 0 ) required += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); } } for ( int i = 0; i < count(); i++ ) { t = tab(i); // if (( i < (middleTab - 1) ) || ( i > (middleTab + 1) )) { if ( i != middleTab ) { int w = hiddenTabWidth; int ih = 0; if ( t->iconSet() != 0 ) { w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); } int h = QMAX( fm.height(), ih ); h = QMAX( h, QApplication::globalStrut().height() ); h += vframe; w += hframe; t->setRect( QRect(x, 0, w, h) ); x += t->rect().width() - overlap; r = r.unite( t->rect() ); } else { int w = fm.width( t->text() ); int ih = 0; if ( t->iconSet() != 0 ) { w += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); } int h = QMAX( fm.height(), ih ); h = QMAX( h, QApplication::globalStrut().height() ); h += vframe; w += hframe; // t->setRect( QRect(x, 0, w * available/required, h) ); t->setRect( QRect(x, 0, available, h) ); x += t->rect().width() - overlap; r = r.unite( t->rect() ); } } QRect rr = tab(count()-1)->rect(); rr.setRight(width()-1); tab(count()-1)->setRect( rr ); for ( t = tabList()->first(); t; t = tabList()->next() ) { QRect tr = t->rect(); tr.setHeight( r.height() ); t->setRect( tr ); } update(); } void CategoryTabBar::paint( QPainter * p, QTab * t, bool selected ) const { #if QT_VERSION >= 300 QStyle::SFlags flags = QStyle::Style_Default; if ( selected ) flags |= QStyle::Style_Selected; style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(), colorGroup(), flags, QStyleOption(t) ); #else style().drawTab( p, this, t, selected ); #endif QRect r( t->rect() ); QFont f( font() ); if ( selected ) f.setBold( TRUE ); p->setFont( f ); int iw = 0; int ih = 0; if ( t->iconSet() != 0 ) { iw = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 2; ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); } int w = iw + p->fontMetrics().width( t->text() ) + 4; int h = QMAX(p->fontMetrics().height() + 4, ih ); paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3, r.top() + (r.height()-h)/2, w, h ), t, #if QT_VERSION >= 300 t->identifier() == keyboardFocusTab() #else t->identitifer() == keyboardFocusTab() #endif ); } void CategoryTabBar::paintLabel( QPainter* p, const QRect&, QTab* t, bool has_focus ) const { QRect r = t->rect(); // if ( t->id != currentTab() ) //r.moveBy( 1, 1 ); // if ( t->iconSet() ) { // the tab has an iconset, draw it in the right mode QIconSet::Mode mode = (t->isEnabled() && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled; if ( mode == QIconSet::Normal && has_focus ) mode = QIconSet::Active; QPixmap pixmap = t->iconSet()->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); int pixh = pixmap.height(); p->drawPixmap( r.left() + 6, r.center().y() - pixh / 2 + 1, pixmap ); r.setLeft( r.left() + pixw + 5 ); } QRect tr = r; if ( r.width() < 20 ) return; if ( t->isEnabled() && isEnabled() ) { #if defined(_WS_WIN32_) if ( colorGroup().brush( QColorGroup::Button ) == colorGroup().brush( QColorGroup::Background ) ) p->setPen( colorGroup().buttonText() ); else p->setPen( colorGroup().foreground() ); #else p->setPen( colorGroup().foreground() ); #endif p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() ); } else { p->setPen( palette().disabled().foreground() ); p->drawText( tr, AlignCenter | AlignVCenter | ShowPrefix, t->text() ); } } //--------------------------------------------------------------------------- Launcher::Launcher( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) { setCaption( tr("Launcher") ); syncDialog = 0; // we have a pretty good idea how big we'll be setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() ); tabs = 0; rootFolder = 0; docsFolder = 0; int stamp = uidgen.generate(); // this is our timestamp to see which devices we know //uidgen.store( stamp ); m_timeStamp = QString::number( stamp ); tabs = new CategoryTabWidget( this ); tabs->setMaximumWidth( qApp->desktop()->width() ); setCentralWidget( tabs ); connect( tabs, SIGNAL(selected(const QString&)), this, SLOT(viewSelected(const QString&)) ); connect( tabs, SIGNAL(clicked(const AppLnk*)), this, SLOT(select(const AppLnk*))); connect( tabs, SIGNAL(rightPressed(AppLnk*)), this, SLOT(properties(AppLnk*))); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); #endif storage = new StorageInfo( this ); connect( storage, SIGNAL( disksChanged() ), SLOT( storageChanged() ) ); updateTabs(); preloadApps(); in_lnk_props = FALSE; got_lnk_change = FALSE; } Launcher::~Launcher() { } static bool isVisibleWindow(int wid) { const QList<QWSWindow> &list = qwsServer->clientWindows(); QWSWindow* w; for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { if ( w->winId() == wid ) return !w->isFullyObscured(); } return FALSE; } void Launcher::showMaximized() { if ( isVisibleWindow( winId() ) ) doMaximize(); else QTimer::singleShot( 20, this, SLOT(doMaximize()) ); } void Launcher::doMaximize() { QMainWindow::showMaximized(); } void Launcher::updateMimeTypes() { MimeType::clear(); updateMimeTypes(rootFolder); } void Launcher::updateMimeTypes(AppLnkSet* folder) { for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { AppLnk *app = it.current(); if ( app->type() == "Folder" ) updateMimeTypes((AppLnkSet *)app); else { MimeType::registerApp(*app); } } } /** This is a HACK.... * Reason: scanning huge mediums, microdirvers for examples * consomes time. To avoid that we invented the MediumMountCheck * * a) the user globally disabled medium checking. We can ignore * all removable medium * b) the user enabled medium checking globally and we need to use this mimefilter * c) the user enabled medium checking on a per medium bases * c1) we already checked and its not ask again turns * c2) we need to ask and then apply the mimefilter */ void Launcher::loadDocs() // ok here comes a hack belonging to Global:: { delete docsFolder; docsFolder = new DocLnkSet; DocLnkSet *tmp = 0; QString home = QString(getenv("HOME")) + "/Documents"; tmp = new DocLnkSet( home , QString::null); docsFolder->appendFrom( *tmp ); delete tmp; // RAM documents StorageInfo storage; const QList<FileSystem> &fileSystems = storage.fileSystems(); QListIterator<FileSystem> it ( fileSystems ); for ( ; it.current(); ++it ) { if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { tmp = new DocLnkSet( (*it)->path(), QString::null ); docsFolder->appendFrom( *tmp ); delete tmp; } } Config mediumCfg( "medium"); mediumCfg.setGroup("main"); // a) -zecke we don't want to check if(!mediumCfg.readBoolEntry("use", true ) ) return; // find out wich filesystems are new in this round // We will do this by having a timestamp inside each mountpoint // if the current timestamp doesn't match this is a new file system and // come up with our MediumMountGui :) let the hacking begin int stamp = uidgen.generate(); QString newStamp = QString::number( stamp ); // generates newtime Stamp // b) if( mediumCfg.readBoolEntry("global", true ) ){ QString mime = configToMime(&mediumCfg).join(";"); for( it.toFirst(); it.current(); ++it ){ if( (*it)->isRemovable() ){ tmp = new DocLnkSet( (*it)->path(), mime ); docsFolder->appendFrom( *tmp ); delete tmp; } } // done return; // save the else } // c) zecke for ( it.toFirst(); it.current(); ++it ) { if ( (*it)->isRemovable() ) { // let's find out if we should search on it Config cfg( (*it)->path() + "/.opiestorage.cf", Config::File); cfg.setGroup("main"); QString stamp = cfg.readEntry("timestamp", QDateTime::currentDateTime().toString() ); /** This medium is uptodate */ if( stamp == m_timeStamp ){ // ok we know this card cfg.writeEntry("timestamp", newStamp ); //just write a new timestamp // we need to scan the list now. Hopefully the cache will be there // read the mimetypes from the config and search for documents QStringList mimetypes = configToMime( &cfg); tmp = new DocLnkSet( (*it)->path(), mimetypes.join(";") ); docsFolder->appendFrom( *tmp ); delete tmp; }else{ // come up with the gui cause this a new card MediumMountGui medium(&cfg, (*it)->path() ); if( medium.check() ){ // we did not ask before or ask again is off /** c2) */ if( medium.exec() ){ // he clicked yes so search it // speicher //cfg.read(); // cause of a race we need to reread - fixed cfg.setGroup("main"); cfg.writeEntry("timestamp", newStamp ); cfg.write(); tmp = new DocLnkSet( (*it)->path(), medium.mimeTypes().join(";" ) ); docsFolder->appendFrom( *tmp ); delete tmp; }// no else /** c1) */ }else{ // we checked // do something different see what we need to do // let's see if we should check the device cfg.setGroup("main" ); bool check = cfg.readBoolEntry("autocheck", true ); if( check ){ // find the documents tmp = new DocLnkSet( (*it)->path(), configToMime(&cfg ).join(";") ); docsFolder->appendFrom( *tmp ); delete tmp; } } } } } m_timeStamp = newStamp; } void Launcher::updateTabs() { MimeType::updateApplications(); // ### reads all applnks twice delete rootFolder; rootFolder = new AppLnkSet( MimeType::appsFolderName() ); loadDocs(); tabs->initializeCategories(rootFolder, docsFolder, storage->fileSystems()); } void Launcher::updateDocs() { loadDocs(); tabs->updateDocs(docsFolder,storage->fileSystems()); } void Launcher::viewSelected(const QString& s) { setCaption( s + tr(" - Launcher") ); } void Launcher::nextView() { tabs->nextTab(); } void Launcher::select( const AppLnk *appLnk ) { if ( appLnk->type() == "Folder" ) { // Not supported: flat is simpler for the user } else { if ( appLnk->exec().isNull() ) { QMessageBox::information(this,tr("No application"), tr("<p>No application is defined for this document." "<p>Type is %1.").arg(appLnk->type())); return; } tabs->setBusy(TRUE); emit executing( appLnk ); appLnk->execute(); } } void Launcher::externalSelected(const AppLnk *appLnk) { tabs->setBusy(TRUE); emit executing( appLnk ); } void Launcher::properties( AppLnk *appLnk ) { if ( appLnk->type() == "Folder" ) { // Not supported: flat is simpler for the user } else { in_lnk_props = TRUE; got_lnk_change = FALSE; LnkProperties prop(appLnk); connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); prop.showMaximized(); prop.exec(); in_lnk_props = FALSE; if ( got_lnk_change ) { updateLink(lnk_change); } } } void Launcher::updateLink(const QString& link) { if (link.isNull()) updateTabs(); else if (link.isEmpty()) updateDocs(); else tabs->updateLink(link); } void Launcher::systemMessage( const QCString &msg, const QByteArray &data) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "closing(QString)" ){ QString app; stream >> app; - qWarning("app closed %s", app.latin1() ); - MRUList::removeTask( app ); + //qWarning("app closed %s", app.latin1() ); + // MRUList::removeTask( app ); }else if ( msg == "linkChanged(QString)" ) { QString link; stream >> link; if ( in_lnk_props ) { got_lnk_change = TRUE; lnk_change = link; } else { updateLink(link); } } else if ( msg == "busy()" ) { emit busy(); } else if ( msg == "notBusy(QString)" ) { QString app; stream >> app; tabs->setBusy(FALSE); emit notBusy(app); } else if ( msg == "mkdir(QString)" ) { QString dir; stream >> dir; if ( !dir.isEmpty() ) mkdir( dir ); } else if ( msg == "rdiffGenSig(QString,QString)" ) { QString baseFile, sigFile; stream >> baseFile >> sigFile; QRsync::generateSignature( baseFile, sigFile ); } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { QString baseFile, sigFile, deltaFile; stream >> baseFile >> sigFile >> deltaFile; QRsync::generateDiff( baseFile, sigFile, deltaFile ); } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { QString baseFile, deltaFile; stream >> baseFile >> deltaFile; if ( !QFile::exists( baseFile ) ) { QFile f( baseFile ); f.open( IO_WriteOnly ); f.close(); } QRsync::applyDiff( baseFile, deltaFile ); QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); e << baseFile; } else if ( msg == "rdiffCleanup()" ) { mkdir( "/tmp/rdiff" ); QDir dir; dir.setPath( "/tmp/rdiff" ); QStringList entries = dir.entryList(); for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) dir.remove( *it ); } else if ( msg == "sendHandshakeInfo()" ) { QString home = getenv( "HOME" ); QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); e << home; int locked = (int) Desktop::screenLocked(); e << locked; // register an app for autostart // if clear is send the list is cleared. } else if ( msg == "autoStart(QString)" ) { QString appName; stream >> appName; Config cfg( "autostart" ); cfg.setGroup( "AutoStart" ); if ( appName.compare("clear") == 0){ cfg.writeEntry("Apps", ""); } } else if ( msg == "autoStart(QString,QString)" ) { QString modifier, appName; stream >> modifier >> appName; Config cfg( "autostart" ); cfg.setGroup( "AutoStart" ); if ( modifier.compare("add") == 0 ){ // only add if appname is entered if (!appName.isEmpty()) { cfg.writeEntry("Apps", appName); } } else if (modifier.compare("remove") == 0 ) { // need to change for multiple entries // actually remove is right now simular to clear, but in future there // should be multiple apps in autostart possible. QString checkName; checkName = cfg.readEntry("Apps", ""); if (checkName == appName) { cfg.writeEntry("Apps", ""); } } // case the autostart feature should be delayed } else if ( msg == "autoStart(QString,QString,QString)") { QString modifier, appName, delay; stream >> modifier >> appName >> delay; Config cfg( "autostart" ); cfg.setGroup( "AutoStart" ); if ( modifier.compare("add") == 0 ){ // only add it appname is entered if (!appName.isEmpty()) { cfg.writeEntry("Apps", appName); cfg.writeEntry("Delay", delay); } } else { } } else if ( msg == "sendCardInfo()" ) { QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); const QList<FileSystem> &fs = storage->fileSystems(); QListIterator<FileSystem> it ( fs ); QString s; QString homeDir = getenv("HOME"); QString hardDiskHome; for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() || (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) s += (*it)->name() + "=" + (*it)->path() + "/Documents " + QString::number( (*it)->availBlocks() * (*it)->blockSize() ) + " " + (*it)->options() + ";"; else if ( (*it)->disk() == "/dev/mtdblock1" || (*it)->disk() == "/dev/mtdblock/1" ) s += (*it)->name() + "=" + homeDir + "/Documents " + QString::number( (*it)->availBlocks() * (*it)->blockSize() ) + " " + (*it)->options() + ";"; else if ( (*it)->name().contains( tr("Hard Disk") ) && homeDir.contains( (*it)->path() ) && (*it)->path().length() > hardDiskHome.length() ) hardDiskHome = (*it)->name() + "=" + homeDir + "/Documents " + QString::number( (*it)->availBlocks() * (*it)->blockSize() ) + " " + (*it)->options() + ";"; } if ( !hardDiskHome.isEmpty() ) s += hardDiskHome; e << s; } else if ( msg == "sendSyncDate(QString)" ) { QString app; stream >> app; Config cfg( "qpe" ); cfg.setGroup("SyncDate"); QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); e << app << cfg.readEntry( app ); //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(), //cfg.readEntry( app ).latin1() ); } else if ( msg == "setSyncDate(QString,QString)" ) { QString app, date; stream >> app >> date; Config cfg( "qpe" ); cfg.setGroup("SyncDate"); cfg.writeEntry( app, date ); //qDebug("setSyncDate(QString,QString) %s %s", app.latin1(), date.latin1()); } else if ( msg == "startSync(QString)" ) { QString what; stream >> what; delete syncDialog; syncDialog = 0; syncDialog = new SyncDialog( this, "syncProgress", FALSE, WStyle_Tool | WStyle_Customize | Qt::WStyle_StaysOnTop ); syncDialog->showMaximized(); syncDialog->whatLabel->setText( "<b>" + what + "</b>" ); connect( syncDialog->buttonCancel, SIGNAL( clicked() ), SLOT( cancelSync() ) ); } else if ( msg == "stopSync()") { delete syncDialog; syncDialog = 0; } else if ( msg == "getAllDocLinks()" ) { loadDocs(); QString contents; for ( QListIterator<DocLnk> it( docsFolder->children() ); it.current(); ++it ) { DocLnk *doc = it.current(); QFileInfo fi( doc->file() ); if ( !fi.exists() ) continue; bool fake = !doc->linkFileKnown(); if ( !fake ) { QFile f( doc->linkFile() ); if ( f.open( IO_ReadOnly ) ) { QTextStream ts( &f ); ts.setEncoding( QTextStream::UnicodeUTF8 ); contents += ts.read(); f.close(); } else fake = TRUE; } if (fake) { contents += "[Desktop Entry]\n"; contents += "Categories = " + Qtopia::Record::idsToString( doc->categories() ) + "\n"; contents += "File = "+doc->file()+"\n"; contents += "Name = "+doc->name()+"\n"; contents += "Type = "+doc->type()+"\n"; } contents += QString("Size = %1\n").arg( fi.size() ); } //qDebug( "sending length %d", contents.length() ); QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); e << contents; qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); delete docsFolder; docsFolder = 0; } } void Launcher::cancelSync() { QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); } void Launcher::storageChanged() { if ( in_lnk_props ) { got_lnk_change = TRUE; lnk_change = ""; } else { updateDocs(); } } bool Launcher::mkdir(const QString &localPath) { QDir fullDir(localPath); if (fullDir.exists()) return true; // at this point the directory doesn't exist // go through the directory tree and start creating the direcotories // that don't exist; if we can't create the directories, return false QString dirSeps = "/"; int dirIndex = localPath.find(dirSeps); QString checkedPath; // didn't find any seps; weird, use the cur dir instead if (dirIndex == -1) { //qDebug("No seperators found in path %s", localPath.latin1()); checkedPath = QDir::currentDirPath(); } while (checkedPath != localPath) { // no more seperators found, use the local path if (dirIndex == -1) checkedPath = localPath; else { // the next directory to check checkedPath = localPath.left(dirIndex) + "/"; // advance the iterator; the next dir seperator dirIndex = localPath.find(dirSeps, dirIndex+1); } QDir checkDir(checkedPath); if (!checkDir.exists()) { //qDebug("mkdir making dir %s", checkedPath.latin1()); if (!checkDir.mkdir(checkedPath)) { qDebug("Unable to make directory %s", checkedPath.latin1()); return FALSE; } } } return TRUE; } void Launcher::preloadApps() { Config cfg("Launcher"); cfg.setGroup("Preload"); QStringList apps = cfg.readListEntry("Apps",','); for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); } } diff --git a/core/launcher/launcher.pro b/core/launcher/launcher.pro index 5b32bc3..0e557aa 100644 --- a/core/launcher/launcher.pro +++ b/core/launcher/launcher.pro @@ -1,118 +1,120 @@ TEMPLATE = app CONFIG = qt warn_on release DESTDIR = ../../bin HEADERS = background.h \ desktop.h \ qprocess.h \ mediummountgui.h \ info.h \ appicons.h \ taskbar.h \ sidething.h \ mrulist.h \ + runningappbar.h \ stabmon.h \ inputmethods.h \ systray.h \ wait.h \ shutdownimpl.h \ launcher.h \ launcherview.h \ ../../core/apps/calibrate/calibrate.h \ startmenu.h \ transferserver.h \ qcopbridge.h \ packageslave.h \ irserver.h \ ../../rsync/buf.h \ ../../rsync/checksum.h \ ../../rsync/command.h \ ../../rsync/emit.h \ ../../rsync/job.h \ ../../rsync/netint.h \ ../../rsync/protocol.h \ ../../rsync/prototab.h \ ../../rsync/rsync.h \ ../../rsync/search.h \ ../../rsync/stream.h \ ../../rsync/sumset.h \ ../../rsync/trace.h \ ../../rsync/types.h \ ../../rsync/util.h \ ../../rsync/whole.h \ ../../rsync/config_rsync.h \ ../../rsync/qrsync.h # quicklauncher.h \ SOURCES = background.cpp \ desktop.cpp \ mediummountgui.cpp \ qprocess.cpp qprocess_unix.cpp \ info.cpp \ appicons.cpp \ taskbar.cpp \ sidething.cpp \ mrulist.cpp \ + runningappbar.cpp \ stabmon.cpp \ inputmethods.cpp \ systray.cpp \ wait.cpp \ shutdownimpl.cpp \ launcher.cpp \ launcherview.cpp \ ../../core/apps/calibrate/calibrate.cpp \ transferserver.cpp \ packageslave.cpp \ irserver.cpp \ qcopbridge.cpp \ startmenu.cpp \ main.cpp \ ../../rsync/base64.c \ ../../rsync/buf.c \ ../../rsync/checksum.c \ ../../rsync/command.c \ ../../rsync/delta.c \ ../../rsync/emit.c \ ../../rsync/hex.c \ ../../rsync/job.c \ ../../rsync/mdfour.c \ ../../rsync/mksum.c \ ../../rsync/msg.c \ ../../rsync/netint.c \ ../../rsync/patch.c \ ../../rsync/prototab.c \ ../../rsync/readsums.c \ ../../rsync/scoop.c \ ../../rsync/search.c \ ../../rsync/stats.c \ ../../rsync/stream.c \ ../../rsync/sumset.c \ ../../rsync/trace.c \ ../../rsync/tube.c \ ../../rsync/util.c \ ../../rsync/version.c \ ../../rsync/whole.c \ ../../rsync/qrsync.cpp INTERFACES = syncdialog.ui INCLUDEPATH += ../../include DEPENDPATH += ../../include . INCLUDEPATH += ../../core/apps/calibrate DEPENDPATH += ../../core/apps/calibrate INCLUDEPATH += ../../rsync DEPENDPATH += ../../rsync TARGET = qpe LIBS += -lqpe -lcrypt -lopie TRANSLATIONS = ../../i18n/de/qpe.ts \ ../../i18n/en/qpe.ts \ ../../i18n/es/qpe.ts \ ../../i18n/fr/qpe.ts \ ../../i18n/hu/qpe.ts \ ../../i18n/ja/qpe.ts \ ../../i18n/ko/qpe.ts \ ../../i18n/no/qpe.ts \ ../../i18n/pl/qpe.ts \ ../../i18n/pt/qpe.ts \ ../../i18n/pt_BR/qpe.ts \ ../../i18n/sl/qpe.ts \ ../../i18n/zh_CN/qpe.ts \ ../../i18n/it/qpe.ts \ ../../i18n/zh_TW/qpe.ts diff --git a/core/launcher/runningappbar.cpp b/core/launcher/runningappbar.cpp new file mode 100644 index 0000000..298f671 --- a/dev/null +++ b/core/launcher/runningappbar.cpp @@ -0,0 +1,287 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of the Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +********************************************************************** +*/ + +#define QTOPIA_INTERNAL_PRELOADACCESS + +// For "kill" +#include <sys/types.h> +#include <signal.h> + +#include <qtimer.h> +#include <qpopupmenu.h> +#include <qmessagebox.h> +#include <qpainter.h> +#include "qprocess.h" +#include <qpe/qpeapplication.h> +#include <qpe/applnk.h> +#include <qpe/qcopenvelope_qws.h> +#include <qpe/global.h> +#include <qwindowsystem_qws.h> +#include "runningappbar.h" + +RunningAppBar::RunningAppBar(QWidget* parent) + : QFrame(parent), m_AppLnkSet(0L), m_SelectedAppIndex(-1) +{ + m_AppLnkSet = new AppLnkSet( QPEApplication::qpeDir() + "apps" ); + + connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); + connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); + 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; +} + +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::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::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::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; + } + } + m_SelectedAppIndex = -1; + repaint( FALSE ); +} + +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(); + } +} + +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; + } + } +} + +QSize RunningAppBar::sizeHint() const +{ + 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_PsProc(0L), m_AppKillerBox(0L) { + 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); +} + +AppMonitor::~AppMonitor() { + 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; + } + } + } +} + +void AppMonitor::timerExpired() { + // qDebug("Checking in on %s", m_App.name().latin1()); + // 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) { + // 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; + } +} + +void AppMonitor::psProcFinished() { + QString pid = m_PsProc->readLineStdout(); + delete m_PsProc; + m_PsProc = 0L; + + // 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) { + m_Owner.removeTask(m_App); + } + 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 new file mode 100644 index 0000000..880bb69 --- a/dev/null +++ b/core/launcher/runningappbar.h @@ -0,0 +1,88 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of the Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef RUNNING_APP_BAR_H +#define RUNNING_APP_BAR_H + +#include <qframe.h> +#include <qlist.h> +#include <qtimer.h> + +class AppLnk; +class AppLnkSet; +class QCString; +class QProcess; +class QMessageBox; + +class RunningAppBar : public QFrame { + Q_OBJECT + + public: + RunningAppBar(QWidget* parent); + ~RunningAppBar(); + + void addTask(const AppLnk& appLnk); + void removeTask(const AppLnk& appLnk); + void paintEvent(QPaintEvent* event); + void mousePressEvent(QMouseEvent*); + void mouseReleaseEvent(QMouseEvent*); + QSize sizeHint() const; + + private slots: + void newQcopChannel(const QString& channel); + void removedQcopChannel(const QString& channel); + void received(const QCString& msg, const QByteArray& data); + + private: + AppLnkSet* m_AppLnkSet; + QList<AppLnk> m_AppList; + int m_SelectedAppIndex; + int spacing; +}; + +/** + * Internal class that checks back in on the process when timerExpired is called + * to make sure the process is on top. If it's not it displays a dialog + * box asking permission to kill it. + */ +class AppMonitor : public QObject { + Q_OBJECT + + public: + static const int RAISE_TIMEOUT_MS; + + AppMonitor(const AppLnk& app, RunningAppBar& owner); + ~AppMonitor(); + + private slots: + void timerExpired(); + void received(const QCString& msg, const QByteArray& data); + void psProcFinished(); + + private: + RunningAppBar& m_Owner; + const AppLnk& m_App; + QTimer m_Timer; + QProcess* m_PsProc; + QMessageBox* m_AppKillerBox; +}; + +#endif + diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp index 5bac874..5506c55 100644 --- a/core/launcher/startmenu.cpp +++ b/core/launcher/startmenu.cpp @@ -1,171 +1,171 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "startmenu.h" #include "sidething.h" -#include "mrulist.h" +//#include "mrulist.h" #include "info.h" #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/resource.h> #include <qdict.h> #include <stdlib.h> // #define USE_CONFIG_FILE StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) { loadOptions(); setPixmap( Resource::loadPixmap( startButtonPixmap ) ); setFocusPolicy( NoFocus ); //setFlat( startButtonIsFlat ); apps = new AppLnkSet( QPEApplication::qpeDir() + "apps" ); createMenu(); } void StartMenu::mousePressEvent( QMouseEvent * ) { launch(); if (desktopInfo) desktopInfo->menuClicked(); } StartMenu::~StartMenu() { delete apps; } void StartMenu::loadOptions() { #ifdef USE_CONFIG_FILE // Read configuration file Config config("StartMenu"); config.setGroup( "StartMenu" ); QString tmpBoolString1 = config.readEntry( "UseWidePopupMenu", "FALSE" ); useWidePopupMenu = ( tmpBoolString1 == "TRUE" ) ? TRUE : FALSE; QString tmpBoolString2 = config.readEntry( "StartButtonIsFlat", "TRUE" ); startButtonIsFlat = ( tmpBoolString2 == "TRUE" ) ? TRUE : FALSE; - QString tmpBoolString3 = config.readEntry( "UseMRUList", "TRUE" ); +// QString tmpBoolString3 = config.readEntry( "UseMRUList", "TRUE" ); popupMenuSidePixmap = config.readEntry( "PopupMenuSidePixmap", "launcher/sidebar" ); startButtonPixmap = config.readEntry( "StartButtonPixmap", "go" ); #else // Basically just #include the .qpe_menu.conf file settings useWidePopupMenu = FALSE; popupMenuSidePixmap = "lauchner/sidebar"; startButtonIsFlat = TRUE; startButtonPixmap = "launcher/start_button"; #endif } void StartMenu::createMenu() { if ( useWidePopupMenu ) launchMenu = new PopupWithLaunchSideThing( this, &popupMenuSidePixmap ); else launchMenu = new StartPopupMenu( this ); loadMenu( apps, launchMenu ); } void StartMenu::itemSelected( int id ) { const AppLnk *app = apps->find( id ); if ( app ) app->execute(); } bool StartMenu::loadMenu( AppLnkSet *folder, QPopupMenu *menu ) { bool result = FALSE; QStringList typs = folder->types(); QDict<QPopupMenu> typpop; for (QStringList::Iterator tit=typs.begin(); tit!=typs.end(); ++tit) { if ( !(*tit).isEmpty() ) { QPopupMenu *new_menu = new StartPopupMenu( menu ); typpop.insert(*tit, new_menu); connect( new_menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); menu->insertItem( folder->typePixmap(*tit), folder->typeName(*tit), new_menu ); } } QListIterator<AppLnk> it( folder->children() ); for ( ; it.current(); ++it ) { AppLnk *app = it.current(); if ( app->type() == "Separator" ) { menu->insertSeparator(); } else { QString t = app->type(); QPopupMenu* pmenu = typpop.find(t); if ( !pmenu ) pmenu = menu; pmenu->insertItem( app->pixmap(), app->name(), app->id() ); result=TRUE; } } if ( result ) connect( menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); return result; } void StartMenu::launch() { int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height(); if ( launchMenu->isVisible() ) launchMenu->hide(); else launchMenu->popup( QPoint( 1, y ) ); } const AppLnk* StartMenu::execToLink(const QString& appname) { const AppLnk* a = apps->findExec( appname ); return a; } void StartPopupMenu::keyPressEvent( QKeyEvent *e ) { if ( e->key() == Key_F33 || e->key() == Key_Space ) { // "OK" button, little hacky QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0); QPopupMenu::keyPressEvent( &ke ); } else { QPopupMenu::keyPressEvent( e ); } } diff --git a/core/launcher/taskbar.cpp b/core/launcher/taskbar.cpp index e38b9fe..9f397eb 100644 --- a/core/launcher/taskbar.cpp +++ b/core/launcher/taskbar.cpp @@ -1,316 +1,323 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** *********************************************************************/ #include "startmenu.h" #include "inputmethods.h" #include "mrulist.h" +#include "runningappbar.h" #include "systray.h" #include "calibrate.h" #include "wait.h" #include "appicons.h" #include "taskbar.h" #include "desktop.h" #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/global.h> #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) #include <qpe/custom.h> #endif #include <opie/odevice.h> #include <qlabel.h> #include <qlayout.h> #include <qtimer.h> #include <qwindowsystem_qws.h> #include <qwidgetstack.h> #if defined( Q_WS_QWS ) #include <qwsdisplay_qws.h> #include <qgfx_qws.h> #endif #define FACTORY(T) \ static QWidget *new##T( bool maximized ) { \ QWidget *w = new T( 0, "test", QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ if ( maximized ) { \ if ( qApp->desktop()->width() <= 350 ) { \ w->showMaximized(); \ } else { \ w->resize( QSize( 300, 300 ) ); \ } \ } \ w->show(); \ return w; \ } #ifdef SINGLE_APP #define APP(a,b,c,d) FACTORY(b) #include "../launcher/apps.h" #undef APP #endif // SINGLE_APP static Global::Command builtins[] = { #ifdef SINGLE_APP #define APP(a,b,c,d) { a, new##b, c }, #include "../launcher/apps.h" #undef APP #endif #if defined(QT_QWS_IPAQ) || defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_EBX) { "calibrate", TaskBar::calibrate, 1, 0 }, #endif #if !defined(QT_QWS_CASSIOPEIA) { "shutdown", Global::shutdown, 1, 0 }, // { "run", run, 1, 0 }, #endif { 0, TaskBar::calibrate, 0, 0 }, }; static bool initNumLock() { #ifdef QPE_INITIAL_NUMLOCK_STATE QPE_INITIAL_NUMLOCK_STATE #endif return FALSE; } class LockKeyState : public QWidget { public: LockKeyState( QWidget *parent ) : QWidget(parent), nl(initNumLock()), cl(FALSE) { nl_pm = Resource::loadPixmap("numlock"); cl_pm = Resource::loadPixmap("capslock"); } QSize sizeHint() const { return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1); } void toggleNumLockState() { nl = !nl; repaint(); } void toggleCapsLockState() { cl = !cl; repaint(); } void paintEvent( QPaintEvent * ) { int y = (height()-sizeHint().height())/2; QPainter p(this); if ( nl ) p.drawPixmap(1,y,nl_pm); if ( cl ) p.drawPixmap(1,y+nl_pm.height()+1,cl_pm); } private: QPixmap nl_pm, cl_pm; bool nl, cl; }; TaskBar::~TaskBar() { } TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader) { Global::setBuiltinCommands(builtins); sm = new StartMenu( this ); inputMethods = new InputMethods( this ); connect( inputMethods, SIGNAL(inputToggled(bool)), this, SLOT(calcMaxWindowRect()) ); //new QuickLauncher( this ); stack = new QWidgetStack( this ); stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); label = new QLabel(stack); - mru = new MRUList( stack ); - stack->raiseWidget( mru ); + //mru = new MRUList( stack ); + //stack->raiseWidget( mru ); + + runningAppBar = new RunningAppBar(stack); + stack->raiseWidget(runningAppBar); waitIcon = new Wait( this ); (void) new AppIcons( this ); sysTray = new SysTray( this ); // ## make customizable in some way? #ifdef QT_QWS_CUSTOM lockState = new LockKeyState( this ); -#else +y#else lockState = 0; #endif #if defined(Q_WS_QWS) #if !defined(QT_NO_COP) QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); #endif #endif waitTimer = new QTimer( this ); connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) ); clearer = new QTimer( this ); QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar())); QObject::connect(clearer, SIGNAL(timeout()), sysTray, SLOT(show())); } void TaskBar::setStatusMessage( const QString &text ) { label->setText( text ); stack->raiseWidget( label ); if ( sysTray && ( label->fontMetrics().width( text ) > label->width() ) ) sysTray->hide(); clearer->start( 3000 ); } void TaskBar::clearStatusBar() { label->clear(); - stack->raiseWidget( mru ); + stack->raiseWidget(runningAppBar); + // stack->raiseWidget( mru ); } void TaskBar::startWait() { waitIcon->setWaiting( true ); // a catchall stop after 10 seconds... waitTimer->start( 10 * 1000, true ); } void TaskBar::stopWait(const QString& app) { waitTimer->stop(); - mru->addTask(sm->execToLink(app)); + //mru->addTask(sm->execToLink(app)); waitIcon->setWaiting( false ); } void TaskBar::stopWait() { waitTimer->stop(); + waitIcon->setWaiting( false ); } void TaskBar::resizeEvent( QResizeEvent *e ) { QHBox::resizeEvent( e ); calcMaxWindowRect(); } void TaskBar::styleChange( QStyle &s ) { QHBox::styleChange( s ); calcMaxWindowRect(); } void TaskBar::calcMaxWindowRect() { #ifdef Q_WS_QWS QRect wr; int displayWidth = qApp->desktop()->width(); QRect ir = inputMethods->inputRect(); if ( ir.isValid() ) { wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); } else { wr.setCoords( 0, 0, displayWidth-1, y()-1 ); } #if QT_VERSION < 300 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, QSize(qt_screen->width(),qt_screen->height())) ); #else QWSServer::setMaxWindowRect( wr ); #endif #endif } void TaskBar::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "message(QString)" ) { QString text; stream >> text; setStatusMessage( text ); } else if ( msg == "hideInputMethod()" ) { inputMethods->hideInputMethod(); } else if ( msg == "showInputMethod()" ) { inputMethods->showInputMethod(); } else if ( msg == "reloadInputMethods()" ) { inputMethods->loadInputMethods(); } else if ( msg == "reloadApplets()" ) { sysTray->loadApplets(); } else if ( msg == "soundAlarm()" ) { Desktop::soundAlarm(); } else if ( msg == "setLed(int,bool)" ) { int led, status; stream >> led >> status; - + ODevice::inst ( )-> setLed ( led, status ? OLED_BlinkSlow : OLED_Off ); } } QWidget *TaskBar::calibrate(bool) { #ifdef Q_WS_QWS Calibrate *c = new Calibrate; c->show(); return c; #else return 0; #endif } void TaskBar::toggleNumLockState() { if ( lockState ) lockState->toggleNumLockState(); } void TaskBar::toggleCapsLockState() { if ( lockState ) lockState->toggleCapsLockState(); } void TaskBar::toggleSymbolInput() { if ( inputMethods->currentShown() == "Unicode" ) { inputMethods->hideInputMethod(); } else { inputMethods->showInputMethod("Unicode"); } } bool TaskBar::recoverMemory() { - return mru->quitOldApps(); + //eturn mru->quitOldApps(); + return true; } diff --git a/core/launcher/taskbar.h b/core/launcher/taskbar.h index 40983af..cd631ef 100644 --- a/core/launcher/taskbar.h +++ b/core/launcher/taskbar.h @@ -1,82 +1,84 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef __TASKBAR_H__ #define __TASKBAR_H__ #include <qhbox.h> class QLabel; class QTimer; class InputMethods; class Wait; class SysTray; -class MRUList; +//class MRUList; +class RunningAppBar; class QWidgetStack; class QTimer; class QLabel; class StartMenu; class LockKeyState; class TaskBar : public QHBox { Q_OBJECT public: TaskBar(); ~TaskBar(); static QWidget *calibrate( bool ); bool recoverMemory(); StartMenu *startMenu() const { return sm; } public slots: void startWait(); void stopWait(const QString&); void stopWait(); void clearStatusBar(); void toggleNumLockState(); void toggleCapsLockState(); void toggleSymbolInput(); protected: void resizeEvent( QResizeEvent * ); void styleChange( QStyle & ); void setStatusMessage( const QString &text ); - + private slots: void calcMaxWindowRect(); void receive( const QCString &msg, const QByteArray &data ); private: - + QTimer *waitTimer; Wait *waitIcon; InputMethods *inputMethods; SysTray *sysTray; - MRUList *mru; + // MRUList *mru; + RunningAppBar* runningAppBar; QWidgetStack *stack; QTimer *clearer; QLabel *label; LockKeyState* lockState; StartMenu *sm; }; #endif // __TASKBAR_H__ |