28 files changed, 1 insertions, 110 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp index fed9b34..b2cef55 100644 --- a/core/applets/batteryapplet/battery.cpp +++ b/core/applets/batteryapplet/battery.cpp @@ -1,183 +1,182 @@ /********************************************************************** ** 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 "battery.h" #include "batterystatus.h" /* OPIE */ #include <opie2/otaskbarapplet.h> #include <qpe/applnk.h> #include <qpe/config.h> #include <qpe/power.h> -#include <qpe/qpeapplication.h> /* QT */ #include <qpainter.h> #include <qtimer.h> BatteryMeter::BatteryMeter( QWidget *parent ) : QWidget( parent ), charging(false) { ps = new PowerStatus; startTimer( 10000 ); setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); setFixedHeight( AppLnk::smallIconSize() ); chargeTimer = new QTimer( this ); connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); timerEvent(0); QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); Config c( "qpe" ); c.setGroup( "Battery" ); style = c.readNumEntry( "Style", 0 ); } BatteryMeter::~BatteryMeter() { delete ps; } QSize BatteryMeter::sizeHint() const { return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); } void BatteryMeter::mousePressEvent( QMouseEvent* e ) { if ( e->button() == RightButton ) { style = 1-style; Config c( "qpe" ); c.setGroup( "Battery" ); c.writeEntry( "Style", style ); repaint( true ); } QWidget::mousePressEvent( e ); } void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) { if ( batteryView && batteryView->isVisible() ) { delete (QWidget *) batteryView; } else { if ( !batteryView ) batteryView = new BatteryStatus( ps ); QPEApplication::showWidget( batteryView ); batteryView->raise(); batteryView->show(); } } void BatteryMeter::timerEvent( QTimerEvent * ) { PowerStatus prev = *ps; *ps = PowerStatusManager::readStatus(); if ( prev != *ps ) { percent = ps->batteryPercentRemaining(); if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { percent = 0; charging = true; chargeTimer->start( 500 ); } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { charging = false; chargeTimer->stop(); if ( batteryView ) batteryView->updatePercent( percent ); } repaint( style != 0 ); if ( batteryView ) batteryView->repaint(); } } void BatteryMeter::chargeTimeout() { percent += 20; if ( percent > 100 ) percent = 0; repaint(FALSE); if ( batteryView ) batteryView->updatePercent( percent ); } void BatteryMeter::paintEvent( QPaintEvent* ) { if ( style == 1 ) { QPainter p(this); QFont f( "Fixed", AppLnk::smallIconSize()/2 ); QFontMetrics fm( f ); p.setFont( f ); p.drawText( 0, height()/2, QString::number( percent ) ); p.drawText( width()/4, height(), "%" ); return; } QPainter p(this); QColor color; QColor g = gray.light( 160 ); switch ( ps->acStatus() ) { case PowerStatus::Offline: color = blue.light( 150 ); break; case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; default: color = red.light( 160 ); } int w = height() / 2; if ( !(w%2) ) w--; // should have an odd value to get a real middle line int h = height() - 4; int pix = (percent * h) / 100; int y2 = height() -2; int y = y2 - pix; int x1 = (width() - w ) / 2; p.setPen(QColor(80,80,80)); p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header p.drawRect(x1,1,w,height()-1); // corpus p.setBrush(color); //int extra = ((percent * h) % 100)/(100/4); int middle = w/2; for ( int i = 0; i < middle; i++ ) { p.setPen( gray.dark( 100+i*20 ) ); p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); p.setPen( color.dark( 100+i*20 ) ); p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); } } int BatteryMeter::position() { return 8; } Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( OTaskbarAppletWrapper<BatteryMeter> ); } diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp index b9ca7b5..ea11495 100644 --- a/core/applets/batteryapplet/batterystatus.cpp +++ b/core/applets/batteryapplet/batterystatus.cpp @@ -1,207 +1,205 @@ #include "batterystatus.h" /* OPIE */ #include <opie2/odevice.h> #include <qpe/power.h> /* QT */ -#include <qpainter.h> #include <qpushbutton.h> #include <qdrawutil.h> #include <qfile.h> #include <qlayout.h> #include <qtextstream.h> -#include <qapplication.h> #include <qmessagebox.h> using namespace Opie; BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { setCaption( tr("Battery status") ); setMinimumSize( 150, 200 ); QPushButton *pb = new QPushButton( tr("Close"), this ); QVBoxLayout *layout = new QVBoxLayout ( this ); jackPercent = 0; pb->setMaximumSize( 120, 40 ); pb->show(); layout->addStretch(); layout->addWidget( pb ); if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { getProcApmStatusIpaq(); } connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); percent = ps->batteryPercentRemaining(); show(); } BatteryStatus::~BatteryStatus() { } /* * Make use of the advanced apm interface of the ipaq */ bool BatteryStatus::getProcApmStatusIpaq() { bat2 = false; QFile procApmIpaq("/proc/hal/battery"); if (procApmIpaq.open(IO_ReadOnly) ) { QStringList list; // since it is /proc we _must_ use QTextStream QTextStream stream ( &procApmIpaq); QString streamIn; streamIn = stream.read(); list = QStringList::split("\n", streamIn); for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { // not nice, need a rewrite later if( (*line).startsWith(" Percentage") ){ if (bat2 == true) { perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); } else { perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); } }else if( (*line).startsWith(" Life") ){ if (bat2 == true) { sec2 = (*line).mid(((*line).find(':')+2), 5 ); } else { sec1 = (*line).mid(((*line).find(':')+2), 5 ); } }else if( (*line).startsWith("Battery #1") ){ bat2 = true; }else if( (*line).startsWith(" Status") ){ if (bat2 == true) { jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); } else { ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); } }else if( (*line).startsWith(" Chemistry") ) { if (bat2 == true) { jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); } else { ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); } } } } else { QMessageBox::warning(this, tr("Failure"),tr("could not open file")); } procApmIpaq.close(); jackPercent = perc2.toInt(); ipaqPercent = perc1.toInt(); if (perc2.isEmpty()) { perc2 = tr("no data"); } else { perc2 += " %"; } if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { sec2 = tr("no data"); } else { sec2 += " min"; } jackStatus == (" ( " + jackStatus + " )"); return true; } void BatteryStatus::updatePercent( int pc ) { percent = pc; repaint(FALSE); } void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; topgrad.hsv( &h1, &s1, &v1 ); botgrad.hsv( &h2, &s2, &v2 ); for ( int j = 0; j < hy-2; j++ ) { p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); } for ( int j = 0; j < hh; j++ ) { p->setPen( highlight ); p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); } for ( int j = 0; j < ng-hy-hh; j++ ) { p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); } } void BatteryStatus::paintEvent( QPaintEvent * ) { QPainter p(this); QString text; if ( ps->batteryStatus() == PowerStatus::Charging ) { if (bat2) { text = tr("Charging both devices"); } else { text = tr("Charging"); } } else if ( ps->batteryPercentAccurate() ) { text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); } else { text = tr("Battery status: "); switch ( ps->batteryStatus() ) { case PowerStatus::High: text += tr("Good"); break; case PowerStatus::Low: text += tr("Low"); break; case PowerStatus::VeryLow: text += tr("Very Low"); break; case PowerStatus::Critical: text += tr("Critical"); break; default: // NotPresent, etc. text += tr("Unknown"); } } p.drawText( 10, 90, text ); if ( ps->acStatus() == PowerStatus::Backup ) p.drawText( 10, 110, tr("On backup power") ); else if ( ps->acStatus() == PowerStatus::Online ) p.drawText( 10, 110, tr("Power on-line") ); else if ( ps->acStatus() == PowerStatus::Offline ) p.drawText( 10, 110, tr("External power disconnected") ); if ( ps->batteryTimeRemaining() >= 0 ) { text.sprintf( tr("Battery time remaining") + ": %im %02is", ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); p.drawText( 10, 130, text ); } QColor c; QColor darkc; QColor lightc; if ( ps->acStatus() == PowerStatus::Offline ) { c = blue.light(120); darkc = c.dark(280); lightc = c.light(145); } else if ( ps->acStatus() == PowerStatus::Online ) { c = green.dark(130); darkc = c.dark(200); lightc = c.light(220); } else { c = red; diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index 8ffaada..7625545 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp @@ -1,223 +1,221 @@ /* * cardmon.cpp * * --------------------- * * copyright : (c) 2002 by Maximilian Reiss * email : max.reiss@gmx.de * based on two apps by Devin Butterfield */ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "cardmon.h" /* OPIE */ #include <opie2/odevice.h> #include <opie2/otaskbarapplet.h> #include <qpe/applnk.h> #include <qpe/resource.h> /* QT */ -#include <qapplication.h> #include <qcopchannel_qws.h> #include <qpainter.h> -#include <qmessagebox.h> #include <qfile.h> #include <qtextstream.h> #include <qsound.h> #include <qtimer.h> /* STD */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <sys/vfs.h> #include <mntent.h> #endif using namespace Opie; CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); connect( pcmciaChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), this, SLOT( cardMessage( const QCString &, const QByteArray & ) ) ); QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); connect( sdChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), this, SLOT( cardMessage( const QCString &, const QByteArray & ) ) ); cardInPcmcia0 = FALSE; cardInPcmcia1 = FALSE; cardInSd = FALSE; setFocusPolicy( NoFocus ); setFixedWidth ( AppLnk::smallIconSize() ); setFixedHeight ( AppLnk::smallIconSize() ); getStatusPcmcia( TRUE ); getStatusSd( TRUE ); repaint( FALSE ); popupMenu = 0; } CardMonitor::~CardMonitor() { if ( popupMenu ) { delete popupMenu; } } void CardMonitor::popUp( QString message, QString icon ) { if ( !popupMenu ) { popupMenu = new QPopupMenu( this ); } popupMenu->clear(); if ( icon.isEmpty() ) { popupMenu->insertItem( message, 0 ); } else { popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), message, 0 ); } QPoint p = mapToGlobal( QPoint( 0, 0 ) ); QSize s = popupMenu->sizeHint(); popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); } void CardMonitor::popupTimeout() { popupMenu->hide(); } void CardMonitor::mousePressEvent( QMouseEvent * ) { QPopupMenu * menu = new QPopupMenu( this ); QString cmd; int err = 0; if ( cardInSd ) { menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), tr( "Eject SD/MMC card" ), 0 ); } if ( cardInPcmcia0 ) { menu-> insertItem( QIconSet ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); } if ( cardInPcmcia1 ) { menu-> insertItem( QIconSet ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); } QPoint p = mapToGlobal( QPoint( 0, 0 ) ); QSize s = menu->sizeHint(); int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); if ( opt == 1 ) { cmd = "/sbin/cardctl eject 0"; err = system( ( const char * ) cmd ); if ( err != 0 ) { qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", err ); popUp( tr( "CF/PCMCIA card eject failed!" ) ); } } else if ( opt == 0 ) { if ( ODevice::inst() ->system() == System_Familiar ) { cmd = "umount /dev/mmc/part1"; } else { cmd = "umount /dev/mmcda1"; } err = system( ( const char * ) cmd ); if ( err != 0 ) { popUp( tr( "SD/MMC card eject failed!" ) ); } } else if ( opt == 2 ) { cmd = "/sbin/cardctl eject 1"; err = system( ( const char * ) cmd ); if ( err != 0 ) { qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", err ); popUp( tr( "CF/PCMCIA card eject failed!" ) ); } } delete menu; } void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) { if ( msg == "stabChanged()" ) { // qDebug("Pcmcia: stabchanged"); getStatusPcmcia(); } else if ( msg == "mtabChanged()" ) { // qDebug("CARDMONAPPLET: mtabchanged"); getStatusSd(); } } bool CardMonitor::getStatusPcmcia( int showPopUp ) { bool cardWas0 = cardInPcmcia0; // remember last state bool cardWas1 = cardInPcmcia1; QString fileName; // one of these 3 files should exist if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; diff --git a/core/applets/homeapplet/home.cpp b/core/applets/homeapplet/home.cpp index 455575f..8a930be 100644 --- a/core/applets/homeapplet/home.cpp +++ b/core/applets/homeapplet/home.cpp @@ -1,87 +1,85 @@ #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <qapplication.h> -#include <qiconset.h> -#include <qpopupmenu.h> #include "home.h" HomeApplet::HomeApplet ( ) : QObject ( 0, "HomeApplet" ) { } HomeApplet::~HomeApplet ( ) { } int HomeApplet::position ( ) const { return 4; } QString HomeApplet::name ( ) const { return tr( "Home shortcut" ); } QString HomeApplet::text ( ) const { return tr( "Desktop" ); } QString HomeApplet::tr( const char* s ) const { return qApp->translate( "HomeApplet", s, 0 ); } QString HomeApplet::tr( const char* s, const char* p ) const { return qApp->translate( "HomeApplet", s, p ); } QIconSet HomeApplet::icon ( ) const { QPixmap pix; QImage img = Resource::loadImage ( "home" ); if ( !img. isNull ( )) pix. convertFromImage ( img. smoothScale ( 14, 14 )); return pix; } QPopupMenu *HomeApplet::popup ( QWidget * ) const { return 0; } void HomeApplet::activated ( ) { // to desktop (home) QCopEnvelope ( "QPE/Application/qpe", "raise()" ); } QRESULT HomeApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) { *iface = 0; if ( uuid == IID_QUnknown ) *iface = this; else if ( uuid == IID_MenuApplet ) *iface = this; else return QS_FALSE; if ( *iface ) (*iface)-> addRef ( ); return QS_OK; } Q_EXPORT_INTERFACE( ) { Q_CREATE_INSTANCE( HomeApplet ) } diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index f850424..a47f33d 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp @@ -1,221 +1,216 @@ /********************************************************************** ** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org> ** Max Reiss <harlekin@handhelds.org> [trivial stuff] ** Robert Griebl <sandman@handhelds.org> ** Holger Freyther <zecke@handhelds.org> QCOP Interface ** ** 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. ** **********************************************************************/ -#include <qcopchannel_qws.h> -#include <qpe/qpeapplication.h> #include <qpe/resource.h> -#include <qpe/ir.h> #include <qpe/qcopenvelope_qws.h> -#include <qpe/sound.h> #include <qpainter.h> #include <qfile.h> #include <qtimer.h> #include <qtextstream.h> -#include <qpopupmenu.h> #include <unistd.h> #include <net/if.h> #include <netinet/in.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include "irda.h" //=========================================================================== IrdaApplet::IrdaApplet ( QWidget *parent, const char *name ) : QWidget ( parent, name ) { setFixedHeight ( 18 ); setFixedWidth ( 14 ); m_sockfd = ::socket ( PF_INET, SOCK_DGRAM, IPPROTO_IP ); m_irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); m_irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); m_irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); m_receiveActivePixmap = Resource::loadPixmap( "irdaapplet/receive" ); m_irda_active = false; m_irda_discovery_active = false; m_receive_active = false; m_receive_state_changed = false; m_popup = 0; m_wasOn = false; m_wasDiscover = false; QCopChannel* chan = new QCopChannel("QPE/IrDaApplet", this ); connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), this, SLOT(slotMessage(const QCString&, const QByteArray& ) ) ); } void IrdaApplet::show() { QWidget::show ( ); startTimer ( 2000 ); } IrdaApplet::~IrdaApplet() { if ( m_sockfd >= 0 ) ::close ( m_sockfd ); } void IrdaApplet::popup ( QString message, QString icon ) { if ( !m_popup ) m_popup = new QPopupMenu ( this ); m_popup-> clear ( ); if ( icon. isEmpty ( )) m_popup-> insertItem ( message, 0 ); else m_popup-> insertItem ( QIconSet ( Resource::loadPixmap ( icon )), message, 0 ); QPoint p = mapToGlobal ( QPoint ( 0, 0 )); QSize s = m_popup-> sizeHint ( ); m_popup-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ))); QTimer::singleShot ( 2000, this, SLOT( popupTimeout ( ))); } void IrdaApplet::popupTimeout ( ) { m_popup-> hide ( ); } bool IrdaApplet::checkIrdaStatus ( ) { struct ifreq ifr; strcpy ( ifr. ifr_name, "irda0" ); if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) return false; return ( ifr. ifr_flags & IFF_UP ); } bool IrdaApplet::setIrdaStatus ( bool b ) { struct ifreq ifr; strcpy ( ifr. ifr_name, "irda0" ); if ( ::ioctl ( m_sockfd, SIOCGIFFLAGS, &ifr ) < 0 ) return false; if ( b ) { ifr. ifr_flags |= IFF_UP; } else { setIrdaDiscoveryStatus ( 0 ); setIrdaReceiveStatus ( 0 ); ifr. ifr_flags &= ~IFF_UP; } if ( ::ioctl ( m_sockfd, SIOCSIFFLAGS, &ifr ) < 0 ) return false; return true; } bool IrdaApplet::checkIrdaDiscoveryStatus ( ) { QFile discovery ( "/proc/sys/net/irda/discovery" ); QString streamIn = "0"; if ( discovery. open ( IO_ReadOnly )) { QTextStream stream ( &discovery ); streamIn = stream. read ( ); } return streamIn. toInt ( ) > 0; } bool IrdaApplet::setIrdaDiscoveryStatus ( bool d ) { QFile discovery ( "/proc/sys/net/irda/discovery" ); if ( discovery. open ( IO_WriteOnly | IO_Raw )) { discovery.putch ( d ? '1' : '0' ); return true; } return false; } bool IrdaApplet::setIrdaReceiveStatus ( bool d ) { QCopEnvelope e ( "QPE/Obex", "receive(int)" ); e << ( d ? 1 : 0 ); m_receive_active = d; m_receive_state_changed = true; return true; } void IrdaApplet::showDiscovered ( ) { // static Sound snd_found ( "irdaapplet/irdaon" ); // static Sound snd_lost ( "irdaapplet/irdaoff" ); QFile discovery ( "/proc/net/irda/discovery" ); if ( discovery. open ( IO_ReadOnly )) { bool qcopsend = false; QString discoveredDevice; QString deviceAddr; // since it is /proc we _must_ use QTextStream QStringList list = QStringList::split ( "\n", QTextStream ( &discovery ). read ( )); QMap <QString, QString>::Iterator it; for ( it = m_devices. begin ( ); it != m_devices. end ( ); ++it ) it. data ( ). prepend ( "+++" ); for ( QStringList::Iterator lit = list. begin ( ); lit != list. end ( ); ++lit ) { const QString &line = *lit; if ( line. startsWith ( "nickname:" )) { discoveredDevice = line. mid ( line. find ( ':' ) + 2, line. find ( ',' ) - line. find ( ':' ) - 2 ); deviceAddr = line. mid ( line. find ( "daddr:" ) + 9, 8 ); // qDebug(discoveredDevice + "(" + deviceAddr + ")"); if ( !m_devices. contains ( deviceAddr )) { popup ( tr( "Found:" ) + " " + discoveredDevice ); //snd_found. play ( ); qcopsend = true; } m_devices. replace ( deviceAddr, discoveredDevice ); } } for ( it = m_devices. begin ( ); it != m_devices. end ( ); ) { // qDebug("IrdaMon: delete " + it.currentKey() + "=" + *devicesAvailable[it.currentKey()] + "?"); if ( it. data ( ). left ( 3 ) == "+++" ) { popup ( tr( "Lost:" ) + " " + it. data ( ). mid ( 3 )); diff --git a/core/applets/logoutapplet/logout.cpp b/core/applets/logoutapplet/logout.cpp index 92222c9..0ac0067 100644 --- a/core/applets/logoutapplet/logout.cpp +++ b/core/applets/logoutapplet/logout.cpp @@ -1,126 +1,124 @@ #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <qapplication.h> -#include <qiconset.h> -#include <qpopupmenu.h> #include <qmessagebox.h> #include <unistd.h> #include "logout.h" LogoutApplet::LogoutApplet ( ) : QObject ( 0, "LogoutApplet" ) { } LogoutApplet::~LogoutApplet ( ) { } int LogoutApplet::position ( ) const { return 0; } QString LogoutApplet::name ( ) const { return tr( "Logout shortcut" ); } QString LogoutApplet::text ( ) const { return tr( "Logout" ); } QString LogoutApplet::tr( const char* s ) const { return qApp->translate( "LogoutApplet", s, 0 ); } QString LogoutApplet::tr( const char* s, const char* p ) const { return qApp->translate( "LogoutApplet", s, p ); } QIconSet LogoutApplet::icon ( ) const { QPixmap pix; QImage img = Resource::loadImage ( "logout" ); if ( !img. isNull ( )) pix. convertFromImage ( img. smoothScale ( 14, 14 )); return pix; } QPopupMenu *LogoutApplet::popup ( QWidget * ) const { return 0; } // 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() class HackApplication : public QApplication { public: HackApplication ( ) : QApplication ( dummy, 0 ) { } void emit_about_to_quit ( ) { emit aboutToQuit ( ); } int dummy; }; void LogoutApplet::activated ( ) { QMessageBox mb ( tr( "Logout" ), tr( "Do you really want to\nend this session ?" ), QMessageBox::NoIcon, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton ); mb. setButtonText ( QMessageBox::Yes, "Yes" ); mb. setButtonText ( QMessageBox::No, "No" ); mb. setIconPixmap ( icon ( ). pixmap ( )); if ( mb. exec ( ) == QMessageBox::Yes ) { { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); } qApp-> processEvents ( ); // ensure the message goes out. sleep ( 1 ); // You have 1 second to comply. ((HackApplication *) qApp )-> emit_about_to_quit ( ); qApp-> quit(); } } QRESULT LogoutApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) { *iface = 0; if ( uuid == IID_QUnknown ) *iface = this; else if ( uuid == IID_MenuApplet ) *iface = this; else return QS_FALSE; if ( *iface ) (*iface)-> addRef ( ); return QS_OK; } Q_EXPORT_INTERFACE( ) { Q_CREATE_INSTANCE( LogoutApplet ) } diff --git a/core/applets/multikeyapplet/multikey.cpp b/core/applets/multikeyapplet/multikey.cpp index b36ee12..b17498d 100644 --- a/core/applets/multikeyapplet/multikey.cpp +++ b/core/applets/multikeyapplet/multikey.cpp @@ -1,149 +1,143 @@ /********************************************************************** ** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru ** All rights reserved. ** ** 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. ** **********************************************************************/ #include "multikey.h" /* OPIE */ #include <opie2/otaskbarapplet.h> -#include <qpe/global.h> -#include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> -#include <qpe/qpeapplication.h> /* QT */ -#include <qlabel.h> #include <qdir.h> -#include <qfileinfo.h> -#include <qcopchannel_qws.h> Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") { QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(message(const QCString &, const QByteArray &))); setFont( QFont( "Helvetica", 10, QFont::Normal ) ); QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); lang = 0; QCopEnvelope e("MultiKey/Keyboard", "getmultikey()"); setText("EN"); popupMenu.insertItem("EN", 0); show(); } void Multikey::mousePressEvent(QMouseEvent *ev) { if (!sw_maps.count()) return; if (ev->button() == RightButton) { QPoint p = mapToGlobal(QPoint(0, 0)); QSize s = popupMenu.sizeHint(); int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), p.y() - s.height()), 0); if (opt == -1) return; lang = opt; QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); e << sw_maps[lang]; setText(labels[lang]); } QWidget::mousePressEvent(ev); } void Multikey::mouseReleaseEvent(QMouseEvent *ev) { if (!sw_maps.count()) return; lang = lang < sw_maps.count()-1 ? lang+1 : 0; QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii()); e << sw_maps[lang]; setText(labels[lang]); } void Multikey::message(const QCString &message, const QByteArray &data) { if ( message == "setsw(QString,QString)" ) { QDataStream stream(data, IO_ReadOnly); QString maps, current_map; stream >> maps >> current_map; QStringList sw = QStringList::split(QChar('|'), maps); sw.append(current_map); QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap"); lang = 0; labels.clear(); sw_maps.clear(); popupMenu.clear(); for (uint i = 0; i < sw.count(); ++i) { QString keymap_map; if (sw[i][0] != '/') { keymap_map = map_dir.absPath() + "/" + sw[i]; } else { if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) && i != sw.count()-1) || !QFile::exists(sw[i])) { continue; } keymap_map = sw[i]; } QFile map(keymap_map); if (map.open(IO_ReadOnly)) { QString line; map.readLine(line, 1024); while (!map.atEnd()) { if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { if (i != sw.count()-1) { if (keymap_map == current_map) { lang = i; } sw_maps.append(keymap_map); labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); } else { current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); } break; } map.readLine(line, 1024); } map.close(); } } setText(current); } } int Multikey::position() { return 10; } Q_EXPORT_INTERFACE() { Q_CREATE_INSTANCE( OTaskbarAppletWrapper<Multikey> ); } diff --git a/core/launcher/applauncher.cpp b/core/launcher/applauncher.cpp index c3584ad..7d3c032 100644 --- a/core/launcher/applauncher.cpp +++ b/core/launcher/applauncher.cpp @@ -1,252 +1,248 @@ /********************************************************************** ** 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 QTOPIA_INTERNAL_PRELOADACCESS #define QTOPIA_INTERNAL_PRELOADACCESS #endif #ifndef QTOPIA_INTERNAL_FILEOPERATIONS #define QTOPIA_INTERNAL_FILEOPERATIONS #endif #ifndef QTOPIA_PROGRAM_MONITOR #define QTOPIA_PROGRAM_MONITOR #endif #include <opie2/oglobal.h> #ifndef Q_OS_WIN32 #include <sys/stat.h> #include <sys/wait.h> #include <sys/file.h> #include <unistd.h> #include <sys/time.h> #include <sys/resource.h> #include <errno.h> #else #include <process.h> #include <windows.h> #include <winbase.h> #endif #include <signal.h> #include <sys/types.h> #include <stdlib.h> #include <qtimer.h> #include <qwindowsystem_qws.h> #include <qmessagebox.h> -#include <qfile.h> #include <qfileinfo.h> #include <qtopia/qcopenvelope_qws.h> -#include <qtopia/applnk.h> #include <qtopia/qpeapplication.h> -#include <qtopia/config.h> -#include <qtopia/global.h> #include "applauncher.h" #include "documentlist.h" const int AppLauncher::RAISE_TIMEOUT_MS = 5000; //--------------------------------------------------------------------------- static AppLauncher* appLauncherPtr; const int appStopEventID = 1290; class AppStoppedEvent : public QCustomEvent { public: AppStoppedEvent(int pid, int status) : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { } int pid() { return mPid; } int status() { return mStatus; } private: int mPid, mStatus; }; AppLauncher::AppLauncher(QObject *parent, const char *name) : QObject(parent, name), qlPid(0), qlReady(FALSE), appKillerBox(0) { 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&)) ); channel = new QCopChannel( "QPE/Server", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(received(const QCString&, const QByteArray&)) ); #ifndef Q_OS_WIN32 signal(SIGCHLD, signalHandler); #else runningAppsProc.setAutoDelete( TRUE ); #endif QString tmp = qApp->argv()[0]; int pos = tmp.findRev('/'); if ( pos > -1 ) tmp = tmp.mid(++pos); runningApps[::getpid()] = tmp; appLauncherPtr = this; QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) ); } AppLauncher::~AppLauncher() { appLauncherPtr = 0; #ifndef Q_OS_WIN32 signal(SIGCHLD, SIG_DFL); #endif if ( qlPid ) { int status; ::kill( qlPid, SIGTERM ); waitpid( qlPid, &status, 0 ); } } /* We use the QCopChannel of the app as an indicator of when it has been launched so that we can disable the busy indicators */ void AppLauncher::newQcopChannel(const QString& channelName) { // qDebug("channel %s added", channelName.data() ); QString prefix("QPE/Application/"); if (channelName.startsWith(prefix)) { { QCopEnvelope e("QPE/System", "newChannel(QString)"); e << channelName; } QString appName = channelName.mid(prefix.length()); if ( appName != "quicklauncher" ) { emit connected( appName ); QCopEnvelope e("QPE/System", "notBusy(QString)"); e << appName; } } else if (channelName.startsWith("QPE/QuickLauncher-")) { qDebug("Registered %s", channelName.latin1()); int pid = channelName.mid(18).toInt(); if (pid == qlPid) qlReady = TRUE; } } void AppLauncher::removedQcopChannel(const QString& channelName) { if (channelName.startsWith("QPE/Application/")) { QCopEnvelope e("QPE/System", "removedChannel(QString)"); e << channelName; } } void AppLauncher::received(const QCString& msg, const QByteArray& data) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "execute(QString)" ) { QString t; stream >> t; if ( !executeBuiltin( t, QString::null ) ) execute(t, QString::null); } else if ( msg == "execute(QString,QString)" ) { QString t,d; stream >> t >> d; if ( !executeBuiltin( t, d ) ) execute( t, d ); } else if ( msg == "processQCop(QString)" ) { // from QPE/Server QString t; stream >> t; if ( !executeBuiltin( t, QString::null ) ) execute( t, QString::null, TRUE); } else if ( msg == "raise(QString)" ) { QString appName; stream >> appName; if ( !executeBuiltin( appName, QString::null ) ) { if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { //qDebug( "Raising: %s", appName.latin1() ); QCString channel = "QPE/Application/"; channel += appName.latin1(); // Need to lock it to avoid race conditions with QPEApplication::processQCopFile QFile f("/tmp/qcop-msg-" + appName); if ( f.open(IO_WriteOnly | IO_Append) ) { #ifndef Q_OS_WIN32 flock(f.handle(), LOCK_EX); #endif QDataStream ds(&f); QByteArray b; QDataStream bstream(b, IO_WriteOnly); ds << channel << QCString("raise()") << b; f.flush(); #ifndef Q_OS_WIN32 flock(f.handle(), LOCK_UN); #endif f.close(); } bool alreadyRunning = isRunning( appName ); if ( execute(appName, QString::null) ) { int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0); waitingHeartbeat.insert( appName, id ); } } } } else if ( msg == "sendRunningApps()" ) { QStringList apps; QMap<int,QString>::Iterator it; for( it = runningApps.begin(); it != runningApps.end(); ++it ) apps.append( *it ); QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" ); e << apps; } else if ( msg == "appRaised(QString)" ) { QString appName; stream >> appName; qDebug("Got a heartbeat from %s", appName.latin1()); QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName); if ( it != waitingHeartbeat.end() ) { killTimer( *it ); waitingHeartbeat.remove(it); } // Check to make sure we're not waiting on user input... if ( appKillerBox && appName == appKillerName ) { // 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 appKillerBox; appKillerBox = 0; appKillerName = QString::null; } } } void AppLauncher::signalHandler(int) { #ifndef Q_OS_WIN32 int status; pid_t pid = waitpid(-1, &status, WNOHANG); /* if (pid == 0 || &status == 0 ) { qDebug("hmm, could not get return value from signal"); } */ QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) ); #else qDebug("Unhandled signal see by AppLauncher::signalHandler(int)"); #endif diff --git a/core/launcher/firstuse.cpp b/core/launcher/firstuse.cpp index e07920f..50ae6c2 100644 --- a/core/launcher/firstuse.cpp +++ b/core/launcher/firstuse.cpp @@ -1,253 +1,245 @@ /********************************************************************** ** 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. ** **********************************************************************/ // I need access to some things you don't normally get access to. #ifndef _MSC_VER //### revise to allow removal of translators under MSVC #define private public #define protected public #endif #include "firstuse.h" #include "inputmethods.h" #include "applauncher.h" #include "serverapp.h" //#include <qtopia/custom.h> #include "calibrate.h" #include "documentlist.h" #include <qtopia/resource.h> #include <qtopia/qcopenvelope_qws.h> -#include <qtopia/qpeapplication.h> #include <qtopia/config.h> -#include <qtopia/applnk.h> -#include <qtopia/mimetype.h> #include <qtopia/fontmanager.h> -#include <qapplication.h> #include <qfile.h> #include <qpainter.h> -#include <qcstring.h> #include <qsimplerichtext.h> -#include <qcolor.h> #include <qpushbutton.h> -#include <qhbox.h> #include <qlabel.h> #include <qtimer.h> #if defined( Q_WS_QWS ) #include <qwsdisplay_qws.h> #include <qgfx_qws.h> #endif -#include <qwindowsystem_qws.h> #include <stdlib.h> #include <sys/types.h> #if defined(Q_OS_LINUX) || defined(_OS_LINUX_) #include <unistd.h> #endif struct { bool enabled; const char *app; const char *start; const char *stop; const char *desc; } settingsTable [] = { { FALSE, "language", "raise()", "accept()", // No tr QT_TR_NOOP("Language") }, { FALSE, "doctab", "raise()", "accept()", // No tr QT_TR_NOOP("DocTab") }, #ifndef Q_OS_WIN32 { FALSE, "systemtime", "raise()", "accept()", // No tr QT_TR_NOOP("Time and Date") }, #endif { FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr QT_TR_NOOP("Personal Information") }, { FALSE, 0, 0, 0, 0 } }; FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) : QDialog( parent, name, TRUE, wf), transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1), waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE) { ServerApplication::allowRestart = FALSE; // we force our height beyound the maximum (which we set anyway) QRect desk = qApp->desktop()->geometry(); setGeometry( 0, 0, desk.width(), desk.height() ); connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); // Create a DocumentList so appLauncher has appLnkSet to search docList = new DocumentList( 0, FALSE ); appLauncher = new AppLauncher( this ); connect( appLauncher, SIGNAL(terminated(int, const QString&)), this, SLOT(terminated(int, const QString&)) ); // more hackery // I will be run as either the main server or as part of the main server QWSServer::setScreenSaverIntervals(0); loadPixmaps(); //check if there is a language program #ifndef Q_OS_WIN32 QString exeSuffix; #else QString exeSuffix(".exe"); #endif for ( int i = 0; settingsTable[i].app; i++ ) { QString file = QPEApplication::qpeDir() + "bin/"; file += settingsTable[i].app; file += exeSuffix; if ( QFile::exists(file) ) settingsTable[i].enabled = TRUE; } setFocusPolicy(NoFocus); taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader); inputMethods = new InputMethods(taskBar); connect(inputMethods, SIGNAL(inputToggled(bool)), this, SLOT(calcMaxWindowRect())); back = new QPushButton(tr("<< Back"), taskBar); back->setFocusPolicy(NoFocus); connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) ); next = new QPushButton(tr("Next >>"), taskBar); next->setFocusPolicy(NoFocus); connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) ); // need to set the geom to lower corner QSize sz = inputMethods->sizeHint(); int buttonWidth = (width() - sz.width()) / 2; int x = 0; controlHeight = back->sizeHint().height(); inputMethods->setGeometry(0,0, sz.width(), controlHeight ); x += sz.width(); back->setGeometry(x, 0, buttonWidth, controlHeight); x += buttonWidth; next->setGeometry(x, 0, buttonWidth, controlHeight); taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight); taskBar->hide(); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) qDebug("Setting up QCop to QPE/System"); QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); connect(sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(message(const QCString &, const QByteArray &)) ); #endif calcMaxWindowRect(); m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false; if ( m_calHandler) { if ( !QFile::exists("/etc/pointercal") ) { needCalibrate = TRUE; grabMouse(); } } Config config("locale"); config.setGroup( "Language"); lang = config.readEntry( "Language", "en"); defaultFont = font(); //###language/font hack; should look it up somewhere #ifdef Q_WS_QWS if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { QFont fn = FontManager::unicodeFont( FontManager::Proportional ); qApp->setFont( fn, TRUE ); } #endif } FirstUse::~FirstUse() { delete appLauncher; delete docList; delete taskBar; ServerApplication::allowRestart = TRUE; } void FirstUse::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, qApp->desktop()->height() - controlHeight-1); } #if QT_VERSION < 0x030000 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, QSize(qt_screen->width(),qt_screen->height())) ); #else QWSServer::setMaxWindowRect( wr ); #endif #endif } /* cancel current dialog, and bring up next */ void FirstUse::nextDialog() { int prevApp = currApp; do { currApp++; qDebug( "currApp = %d", currApp ); if ( settingsTable[currApp].app == 0 ) { if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { // The last application is still running. // Tell it to stop, and when its done we'll come back // to nextDialog and exit. qDebug( "Waiting for %s to exit", settingsTable[prevApp].app ); QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, settingsTable[prevApp].stop ); currApp = prevApp; } else { qDebug( "Done!" ); Config config( "qpe" ); config.setGroup( "Startup" ); config.writeEntry( "FirstUse", FALSE ); QPixmap pix = Resource::loadPixmap("bigwait"); QLabel *lblWait = new QLabel(0, "wait hack!", // No tr QWidget::WStyle_Customize | QWidget::WDestructiveClose | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool | QWidget::WStyle_StaysOnTop); diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp index 5d8faf7..683f1e2 100644 --- a/core/launcher/inputmethods.cpp +++ b/core/launcher/inputmethods.cpp @@ -1,230 +1,224 @@ /********************************************************************** ** 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_LANGLIST #include "inputmethods.h" #include <qtopia/config.h> #include <qtopia/qpeapplication.h> -#include <qtopia/inputmethodinterface.h> -#include <qtopia/global.h> #include <qpopupmenu.h> -#include <qpushbutton.h> #include <qtoolbutton.h> #include <qwidgetstack.h> -#include <qwidget.h> #include <qlayout.h> -#include <qtimer.h> #include <qdir.h> #include <stdlib.h> -#include <qtranslator.h> #include <qtl.h> #ifdef Q_WS_QWS #include <qwindowsystem_qws.h> #include <qwsevent_qws.h> #include <qcopchannel_qws.h> #endif /* ### SingleFloppy if someone is interested? */ #if 0 #ifdef QT_NO_COMPONENT #include "../plugins/inputmethods/handwriting/handwritingimpl.h" #include "../plugins/inputmethods/keyboard/keyboardimpl.h" #include "../3rdparty/plugins/inputmethods/pickboard/pickboardimpl.h" #endif #endif /* XPM */ static const char * tri_xpm[]={ "9 9 2 1", "a c #000000", ". c None", ".........", ".........", ".........", "....a....", "...aaa...", "..aaaaa..", ".aaaaaaa.", ".........", "........."}; int InputMethod::operator <(const InputMethod& o) const { return name() < o.name(); } int InputMethod::operator >(const InputMethod& o) const { return name() > o.name(); } int InputMethod::operator <=(const InputMethod& o) const { return name() <= o.name(); } /* Slightly hacky: We use WStyle_Tool as a flag to say "this widget belongs to the IM system, so clicking it should not cause a reset". */ class IMToolButton : public QToolButton { public: IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) { setWFlags( WStyle_Tool ); } }; InputMethods::InputMethods( QWidget *parent ) : QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), mkeyboard(0), imethod(0) { Config cfg( "Launcher" ); cfg.setGroup( "InputMethods" ); inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool; inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0; inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); setBackgroundMode( PaletteBackground ); QHBoxLayout *hbox = new QHBoxLayout( this ); kbdButton = new IMToolButton( this); kbdButton->setFocusPolicy(NoFocus); kbdButton->setToggleButton( TRUE ); if (parent->sizeHint().height() > 0) kbdButton->setFixedHeight( parent->sizeHint().height() ); kbdButton->setFixedWidth( 32 ); kbdButton->setAutoRaise( TRUE ); kbdButton->setUsesBigPixmap( TRUE ); hbox->addWidget( kbdButton ); connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); kbdChoice = new IMToolButton( this ); kbdChoice->setFocusPolicy(NoFocus); kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); if (parent->sizeHint().height() > 0) kbdChoice->setFixedHeight( parent->sizeHint().height() ); kbdChoice->setFixedWidth( 13 ); kbdChoice->setAutoRaise( TRUE ); hbox->addWidget( kbdChoice ); connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), this, SLOT(resetStates()) ); imButton = new QWidgetStack( this ); // later a widget stack imButton->setFocusPolicy(NoFocus); if (parent->sizeHint().height() > 0) imButton->setFixedHeight( parent->sizeHint().height() ); hbox->addWidget(imButton); imChoice = new QToolButton( this ); imChoice->setFocusPolicy(NoFocus); imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); if (parent->sizeHint().height() > 0) imChoice->setFixedHeight( parent->sizeHint().height() ); imChoice->setFixedWidth( 13 ); imChoice->setAutoRaise( TRUE ); hbox->addWidget( imChoice ); connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) ); loadInputMethods(); QCopChannel *channel = new QCopChannel( "QPE/IME", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(qcopReceive(const QCString&, const QByteArray&)) ); } InputMethods::~InputMethods() { Config cfg("qpe"); cfg.setGroup("InputMethod"); if (imethod) cfg.writeEntry("im", imethod->name() ); if (mkeyboard) cfg.writeEntry("current", mkeyboard->name() ); unloadInputMethods(); } void InputMethods::hideInputMethod() { kbdButton->setOn( FALSE ); } void InputMethods::showInputMethod() { kbdButton->setOn( TRUE ); } void InputMethods::showInputMethod(const QString& name) { int i = 0; QValueList<InputMethod>::Iterator it; InputMethod *im = 0; for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1); if ( (*it).name() == name || lname == name ) { im = &(*it); break; } } if ( im ) chooseKeyboard(im); } void InputMethods::resetStates() { if ( mkeyboard && !mkeyboard->newIM ) mkeyboard->interface->resetState(); } QRect InputMethods::inputRect() const { if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() ) return QRect(); else return mkeyboard->widget->geometry(); } void InputMethods::unloadInputMethods() { unloadMethod( inputMethodList ); unloadMethod( inputModifierList ); inputMethodList.clear(); inputModifierList.clear(); } void InputMethods::unloadMethod( QValueList<InputMethod>& list ) { QValueList<InputMethod>::Iterator it; for (it = list.begin(); it != list.end(); ++it ) (*it).releaseInterface(); } QStringList InputMethods::plugins()const { QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; #ifdef Q_OS_MACX diff --git a/core/launcher/irserver.cpp b/core/launcher/irserver.cpp index 63f8d05..a0e9c16 100644 --- a/core/launcher/irserver.cpp +++ b/core/launcher/irserver.cpp @@ -1,77 +1,76 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "irserver.h" #include <qtopia/qlibrary.h> #include <qtopia/qpeapplication.h> -#include <qtranslator.h> #include "obexinterface.h" #include <qdir.h> IrServer::IrServer( QObject *parent, const char *name ) : QObject( parent, name ), obexIface(0) { lib = 0; obexIface = 0; QString path = QPEApplication::qpeDir() + "/plugins/obex/"; #ifdef Q_OS_MACX QDir dir( path, "lib*.dylib" ); #else QDir dir( path, "lib*.so" ); #endif /* Q_OS_MACX */ QStringList list = dir.entryList(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { QLibrary *trylib = new QLibrary( path + *it ); //qDebug("trying lib %s", (path + (*it)).latin1() ); if ( trylib->queryInterface( IID_ObexInterface, (QUnknownInterface**)&obexIface ) == QS_OK ) { lib = trylib; //qDebug("found obex lib" ); QString lang = getenv( "LANG" ); QTranslator * trans = new QTranslator(qApp); QString type = (*it).left( (*it).find(".") ); QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; //qDebug("tr fpr obex: %s", tfn.latin1() ); if ( trans->load( tfn )) qApp->installTranslator( trans ); else delete trans; break; } else { delete lib; } } if ( !lib ) qDebug("could not load IR plugin" ); } IrServer::~IrServer() { if ( obexIface ) obexIface->release(); delete lib; } diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp index 984a57d..54efb0b 100644 --- a/core/launcher/launcher.cpp +++ b/core/launcher/launcher.cpp @@ -1,238 +1,236 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include <qtopia/global.h> #ifdef Q_WS_QWS #include <qtopia/qcopenvelope_qws.h> #endif #include <qtopia/resource.h> #include <qtopia/applnk.h> #include <qtopia/config.h> -#include <qtopia/global.h> #include <qtopia/qpeapplication.h> #include <qtopia/mimetype.h> #include <qtopia/private/categories.h> //#include <qtopia/custom.h> #include <qdir.h> #ifdef Q_WS_QWS #include <qwindowsystem_qws.h> #endif #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 <qpopupmenu.h> #include "startmenu.h" #include "taskbar.h" #include "serverinterface.h" #include "launcherview.h" #include "launcher.h" #include "server.h" #define QTOPIA_INTERNAL_FSLP #include <qtopia/lnkproperties.h> #include <stdlib.h> #include <assert.h> #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <unistd.h> #include <stdio.h> #include <sys/vfs.h> #include <mntent.h> #endif #ifdef Q_WS_QWS #include <qkeyboard_qws.h> #include <qpe/lnkproperties.h> #endif static bool isVisibleWindow( int ); //=========================================================================== LauncherTabWidget::LauncherTabWidget( Launcher* parent ) : QVBox( parent ), docview( 0 ) { docLoadingWidgetEnabled = false; docLoadingWidget = 0; docLoadingWidgetProgress = 0; launcher = parent; categoryBar = new LauncherTabBar( 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 ); stack = new QWidgetStack(this); connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) ); categoryBar->show(); stack->show(); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) QCopChannel *channel = new QCopChannel( "QPE/Launcher", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(launcherMessage(const QCString&, const QByteArray&)) ); connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&))); #endif createDocLoadingWidget(); } void LauncherTabWidget::createDocLoadingWidget() { // Construct the 'doc loading widget' shown when finding documents // ### LauncherView class needs changing to be more generic so // this widget can change its background similar to the iconviews // so the background for this matches docLoadingWidget = new LauncherView( stack ); docLoadingWidget->hideIcons(); QVBox *docLoadingVBox = new QVBox( docLoadingWidget ); docLoadingVBox->setSpacing( 20 ); docLoadingVBox->setMargin( 10 ); QWidget *space1 = new QWidget( docLoadingVBox ); docLoadingVBox->setStretchFactor( space1, 1 ); QLabel *waitPixmap = new QLabel( docLoadingVBox ); waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) ); waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) ); waitPixmap->setAlignment( int( QLabel::AlignCenter ) ); Config cfg( "Launcher" ); cfg.setGroup( "DocTab" ); bool docTabEnabled = cfg.readBoolEntry( "Enable", true ); QLabel *textLabel = new QLabel( docLoadingVBox ); textLabel->setAlignment( int( QLabel::AlignCenter ) ); docLoadingWidgetProgress = new QProgressBar( docLoadingVBox ); docLoadingWidgetProgress->setProgress( 0 ); docLoadingWidgetProgress->setCenterIndicator( TRUE ); docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker setProgressStyle(); if ( docTabEnabled ) { textLabel->setText( tr( "<b>Finding Documents...</b>" ) ); } else { textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>" "Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) ); docLoadingWidgetProgress->hide(); docLoadingWidgetEnabled = true; } QWidget *space2 = new QWidget( docLoadingVBox ); docLoadingVBox->setStretchFactor( space2, 1 ); cfg.setGroup( "Tab Documents" ); // No tr setTabViewAppearance( docLoadingWidget, cfg ); stack->addWidget( docLoadingWidget, 0 ); } void LauncherTabWidget::initLayout() { layout()->activate(); docView()->setFocus(); categoryBar->showTab("Documents"); } void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&) { if ( message == "nextView()" ) categoryBar->nextTab(); } void LauncherTabWidget::raiseTabWidget() { if ( categoryBar->currentView() == docView() && docLoadingWidgetEnabled ) { stack->raiseWidget( docLoadingWidget ); docLoadingWidget->updateGeometry(); } else { stack->raiseWidget( categoryBar->currentView() ); } } void LauncherTabWidget::tabProperties() { LauncherView *view = categoryBar->currentView(); QPopupMenu *m = new QPopupMenu( this ); m->insertItem( tr("Icon View"), LauncherView::Icon ); m->insertItem( tr("List View"), LauncherView::List ); m->setItemChecked( (int)view->viewMode(), TRUE ); int rv = m->exec( QCursor::pos() ); if ( rv >= 0 && rv != view->viewMode() ) { view->setViewMode( (LauncherView::ViewMode)rv ); } delete m; } void LauncherTabWidget::deleteView( const QString& id ) { LauncherTab *t = categoryBar->launcherTab(id); if ( t ) { stack->removeWidget( t->view ); delete t->view; categoryBar->removeTab( t ); } } LauncherView* LauncherTabWidget::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*))); int n = categoryBar->count(); stack->addWidget( view, n ); LauncherTab *tab = new LauncherTab( id, view, pm, label ); categoryBar->insertTab( tab, n-1 ); if ( id == "Documents" ) docview = view; qDebug("inserting %s at %d", id.latin1(), n-1 ); Config cfg("Launcher"); setTabAppearance( tab, cfg ); cfg.setGroup( "GUI" ); diff --git a/core/launcher/launcherglobal.cpp b/core/launcher/launcherglobal.cpp index 84caa93..9abcae9 100644 --- a/core/launcher/launcherglobal.cpp +++ b/core/launcher/launcherglobal.cpp @@ -1,83 +1,79 @@ /* * GPLv2 only * * TT 2002-2002,2003 */ -#include <qstring.h> -#include <qcstring.h> -#include <qwidget.h> -#include <qguardedptr.h> #include <qfile.h> #include <qtextstream.h> #include <qtopia/mimetype.h> #include "launcherglobal.h" bool Opie::Global::isAppLnkFileName( const QString& file ) { if ( file.right(1) == "/" ) return FALSE; return file.find(MimeType::appsFolderName()+"/")==0; } QString Opie::Global::tempDir() { return QString::fromLatin1("/tmp/"); } Global::Command* Opie::Global::builtinCommands() { return builtin; } QGuardedPtr<QWidget>* Opie::Global::builtinRunning() { return running; } QString Opie::Global::uuid() { QFile file( "/proc/sys/kernel/random/uuid" ); if (!file.open(IO_ReadOnly ) ) return QString::null; QTextStream stream(&file); return "{" + stream.read().stripWhiteSpace() + "}"; } QByteArray Opie::Global::encodeBase64(const QByteArray& origData ) { // follows simple algorithm from rsync code uchar *in = (uchar*)origData.data(); int inbytes = origData.size(); int outbytes = ((inbytes * 8) + 5) / 6; int padding = 4-outbytes%4; if ( padding == 4 ) padding = 0; QByteArray outbuf(outbytes+padding); uchar* out = (uchar*)outbuf.data(); const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; for (int i = 0; i < outbytes; i++) { int byte = (i * 6) / 8; int bit = (i * 6) % 8; if (bit < 3) { if (byte < inbytes) *out = (b64[(in[byte] >> (2 - bit)) & 0x3F]); } else { if (byte + 1 == inbytes) { *out = (b64[(in[byte] << (bit - 2)) & 0x3F]); } else { *out = (b64[(in[byte] << (bit - 2) | in[byte + 1] >> (10 - bit)) & 0x3F]); } } ++out; } ASSERT(out == (uchar*)outbuf.data() + outbuf.size() - padding); while ( padding-- ) *out++='='; return outbuf; } diff --git a/core/launcher/launchertab.cpp b/core/launcher/launchertab.cpp index 10cfd5f..710f259 100644 --- a/core/launcher/launchertab.cpp +++ b/core/launcher/launchertab.cpp @@ -1,216 +1,213 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "launchertab.h" #include <qapplication.h> -#include <qstyle.h> -#include <qpainter.h> -#include <qbitmap.h> LauncherTabBar::LauncherTabBar( QWidget *parent, const char *name ) : QTabBar( parent, name ) { setFocusPolicy( NoFocus ); connect( this, SIGNAL( selected(int) ), this, SLOT( layoutTabs() ) ); } LauncherTabBar::~LauncherTabBar() { } void LauncherTabBar::insertTab( LauncherTab *t, int index ) { if ( index < 0 ) items.append( t ); else items.insert( (uint)index, t ); tabs.insert( t->type, t ); QTabBar::insertTab( t, index ); } void LauncherTabBar::removeTab( QTab *tab ) { LauncherTab *t = (LauncherTab *)tab; tabs.remove( t->type ); items.remove( t ); QTabBar::removeTab( t ); } void LauncherTabBar::prevTab() { int n = count(); int tab = currentTab(); if ( tab >= 0 ) setCurrentTab( (tab - 1 + n)%n ); } void LauncherTabBar::nextTab() { int n = count(); int tab = currentTab(); setCurrentTab( (tab + 1)%n ); } void LauncherTabBar::showTab( const QString& id ) { setCurrentTab( tabs[id] ); } void LauncherTabBar::layoutTabs() { if ( !count() ) return; int available = width()-1; QFontMetrics fm = fontMetrics(); int hiddenTabWidth = -12; LauncherTab *current = currentLauncherTab(); int hframe, vframe, overlap; style().tabbarMetrics( this, hframe, vframe, overlap ); int x = 0; QRect r; LauncherTab *t; QListIterator< LauncherTab > it( items ); int required = 0; int eventabwidth = (width()-1)/count(); enum Mode { HideBackText, Pack, Even } mode=Even; for (it.toFirst(); it.current(); ++it ) { t = it.current(); if ( !t ) continue; int iw = fm.width( t->text() ) + hframe - overlap; if ( t != current ) { available -= hiddenTabWidth + hframe - overlap; if ( t->iconSet() != 0 ) available -= t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); } if ( t->iconSet() != 0 ) iw += t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width(); required += iw; // As space gets tight, packed looks better than even. "10" must be at least 0. if ( iw >= eventabwidth-10 ) mode = Pack; } if ( mode == Pack && required > width()-1 ) mode = HideBackText; for ( it.toFirst(); it.current(); ++it ) { t = it.current(); if ( !t ) continue; if ( mode != HideBackText ) { 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; QRect totr(x, 0, mode == Even ? eventabwidth : w * (width()-1)/required, h); t->setRect(totr); x += totr.width() - overlap; r = r.unite(totr); } else if ( t != current ) { 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 ih = 0; if ( t->iconSet() != 0 ) { ih = t->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); } int h = QMAX( fm.height(), ih ); h = QMAX( h, QApplication::globalStrut().height() ); h += vframe; t->setRect( QRect(x, 0, available, h) ); x += t->rect().width() - overlap; r = r.unite( t->rect() ); } } t = it.toLast(); if (t) { QRect rr = t->rect(); rr.setRight(width()-1); t->setRect( rr ); } for (it.toFirst(); it.current(); ++it ) { t = it.current(); QRect tr = t->rect(); tr.setHeight( r.height() ); t->setRect( tr ); } update(); } void LauncherTabBar::paint( QPainter * p, QTab * t, bool selected ) const { LauncherTabBar *that = (LauncherTabBar *) this; LauncherTab *ct = (LauncherTab *)t; QPalette pal = palette(); bool setPal = FALSE; if ( ct->bgColor.isValid() ) { pal.setColor( QPalette::Active, QColorGroup::Background, ct->bgColor ); pal.setColor( QPalette::Active, QColorGroup::Button, ct->bgColor ); pal.setColor( QPalette::Inactive, QColorGroup::Background, ct->bgColor ); pal.setColor( QPalette::Inactive, QColorGroup::Button, ct->bgColor ); that->setUpdatesEnabled( FALSE ); that->setPalette( pal ); setPal = TRUE; } #if QT_VERSION >= 0x030000 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 ); if ( ct->fgColor.isValid() ) { diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 62c678d..513b1bd 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp @@ -1,238 +1,224 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "launcherview.h" #include <qtopia/qpeapplication.h> -#include <qtopia/applnk.h> -#include <qtopia/qpedebug.h> #include <qtopia/private/categories.h> #include <qtopia/categoryselect.h> -#include <qtopia/menubutton.h> #include <qtopia/mimetype.h> #include <qtopia/resource.h> -#include <qtopia/qpetoolbar.h> //#include <qtopia/private/palmtoprecord.h> #include <qtimer.h> -#include <qtextstream.h> -#include <qdict.h> -#include <qfile.h> #include <qfileinfo.h> -#include <qhbox.h> #include <qiconview.h> -#include <qwidgetstack.h> -#include <qpainter.h> -#include <qregexp.h> -#include <qtoolbutton.h> -#include <qimage.h> -#include <qlabel.h> #include <qobjectlist.h> // These define how the busy icon is animated and highlighted #define BRIGHTEN_BUSY_ICON //#define ALPHA_FADE_BUSY_ICON //#define USE_ANIMATED_BUSY_ICON_OVERLAY #define BOUNCE_BUSY_ICON class BgPixmap { public: BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} QPixmap pm; int ref; }; static QMap<QString,BgPixmap*> *bgCache = 0; static void cleanup_cache() { QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); while ( it != bgCache->end() ) { QMap<QString,BgPixmap*>::Iterator curr = it; ++it; delete (*curr); bgCache->remove( curr ); } delete bgCache; bgCache = 0; } class LauncherItem : public QIconViewItem { public: LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); ~LauncherItem(); AppLnk *appLnk() const { return app; } AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } void animateIcon(); void resetIcon(); virtual int compare ( QIconViewItem * i ) const; void paintItem( QPainter *p, const QColorGroup &cg ); void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } protected: bool isBigIcon; int iteration; AppLnk* app; private: void paintAnimatedIcon( QPainter *p ); BusyIndicatorType busyType; }; class LauncherIconView : public QIconView { public: LauncherIconView( QWidget* parent, const char* name=0 ) : QIconView(parent,name), tf(""), cf(0), bsy(0), busyTimer(0), bigIcns(TRUE), bgColor(white) { sortmeth = Name; hidden.setAutoDelete(TRUE); ike = FALSE; calculateGrid( Bottom ); } ~LauncherIconView() { #if 0 // debuggery QListIterator<AppLnk> it(hidden); AppLnk* l; while ((l=it.current())) { ++it; //qDebug("%p: hidden (should remove)",l); } #endif } QIconViewItem* busyItem() const { return bsy; } #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY QPixmap busyPixmap() const { return busyPix; } #endif void setBigIcons( bool bi ) { bigIcns = bi; #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY busyPix.resize(0,0); #endif } void updateCategoriesAndMimeTypes(); void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } void doAutoScroll() { // We don't want rubberbanding (yet) } void setBusy(bool on) { #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY if ( busyPix.isNull() ) { int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); } #endif if ( on ) { busyTimer = startTimer( 100 ); } else { if ( busyTimer ) { killTimer( busyTimer ); busyTimer = 0; } } LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; if ( bsy != c ) { LauncherItem *oldBusy = bsy; bsy = c; if ( oldBusy ) { oldBusy->resetIcon(); } if ( bsy ) { bsy->setBusyIndicatorType( busyType ) ; bsy->animateIcon(); } } } bool inKeyEvent() const { return ike; } void keyPressEvent(QKeyEvent* e) { ike = TRUE; if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { if ( (e->state() & ShiftButton) ) emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); else returnPressed(currentItem()); } QIconView::keyPressEvent(e); ike = FALSE; } void addItem(AppLnk* app, bool resort=TRUE); bool removeLink(const QString& linkfile); QStringList mimeTypes() const; QStringList categories() const; void clear() { mimes.clear(); cats.clear(); QIconView::clear(); hidden.clear(); } void addCatsAndMimes(AppLnk* app) { // QStringList c = app->categories(); // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { // cats.replace(*cit,(void*)1); // } QString maj=app->type(); int sl=maj.find('/'); if (sl>=0) { QString k; k = maj.left(12) == "application/" ? maj : maj.left(sl); mimes.replace(k,(void*)1); } } void setBackgroundOrigin( QWidget::BackgroundOrigin ) { } void setBackgroundPixmap( const QPixmap &pm ) { bgPixmap = pm; } diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp index 9e53bb0..c136bd9 100644 --- a/core/launcher/main.cpp +++ b/core/launcher/main.cpp @@ -1,231 +1,226 @@ /********************************************************************** ** 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 QTOPIA_INTERNAL_FILEOPERATIONS #define QTOPIA_INTERNAL_FILEOPERATIONS #endif #include "server.h" #include "serverapp.h" -#include "taskbar.h" #include "stabmon.h" -#include "launcher.h" #include "firstuse.h" #include <opie2/oglobal.h> -#include <qtopia/qpeapplication.h> #include <qtopia/network.h> -#include <qtopia/config.h> //#include <qtopia/custom.h> -#include <qfile.h> #include <qdir.h> #ifdef QWS #include <qwindowsystem_qws.h> #include <qtopia/qcopenvelope_qws.h> #endif #include <qtopia/alarmserver.h> #include <stdlib.h> #include <stdio.h> #include <signal.h> #ifndef Q_OS_WIN32 #include <unistd.h> #else #include <process.h> #endif #include "calibrate.h" #ifdef QT_QWS_LOGIN #include "../login/qdmdialogimpl.h" #endif #ifdef Q_WS_QWS #include <qkeyboard_qws.h> #endif #include <qmessagebox.h> #include <opie2/odevice.h> using namespace Opie; static void cleanup() { QDir dir( "/tmp", "qcop-msg-*" ); QStringList stale = dir.entryList(); QStringList::Iterator it; for ( it = stale.begin(); it != stale.end(); ++it ) { dir.remove( *it ); } } static void refreshTimeZoneConfig() { /* ### FIXME timezone handling */ #if 0 // We need to help WorldTime in setting up its configuration for // the current translation // BEGIN no tr const char *defaultTz[] = { "America/New_York", "America/Los_Angeles", "Europe/Oslo", "Asia/Tokyo", "Asia/Hong_Kong", "Australia/Brisbane", 0 }; // END no tr TimeZone curZone; QString zoneID; int zoneIndex; Config cfg = Config( "WorldTime" ); cfg.setGroup( "TimeZones" ); if (!cfg.hasKey( "Zone0" )){ // We have no existing timezones use the defaults which are untranslated strings QString currTz = TimeZone::current().id(); QStringList zoneDefaults; zoneDefaults.append( currTz ); for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) { if ( defaultTz[i] != currTz ) zoneDefaults.append( defaultTz[i] ); } zoneIndex = 0; for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){ cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it); zoneIndex++; } } // We have an existing list of timezones refresh the // translations of TimeZone name zoneIndex = 0; while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){ zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex )); curZone = TimeZone( zoneID ); if ( !curZone.isValid() ){ qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() ); break; } cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() ); zoneIndex++; } #endif } void initEnvironment() { #ifdef Q_OS_WIN32 // Config file requires HOME dir which uses QDir which needs the winver qt_init_winver(); #endif Config config("locale"); config.setGroup( "Location" ); QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); // if not timezone set, pick New York if (tz.isNull() || tz.isEmpty()) tz = "America/New_York"; setenv( "TZ", tz, 1 ); config.writeEntry( "Timezone", tz); config.setGroup( "Language" ); QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); if( lang.isNull() || lang.isEmpty()) lang = "en_US"; setenv( "LANG", lang, 1 ); config.writeEntry("Language", lang); config.write(); #if 0 setenv( "QWS_SIZE", "240x320", 0 ); #endif QString env(getenv("QWS_DISPLAY")); if (env.contains("Transformed")) { int rot; // transformed driver default rotation is controlled by the hardware. Config config("qpe"); config.setGroup( "Rotation" ); if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 ) rot = ODevice::inst ( )-> rotation ( ) * 90; setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ } } static void initKeyboard() { Config config("qpe"); config.setGroup( "Keyboard" ); int ard = config.readNumEntry( "RepeatDelay" ); int arp = config.readNumEntry( "RepeatPeriod" ); if ( ard > 0 && arp > 0 ) qwsSetKeyboardAutoRepeat( ard, arp ); QString layout = config.readEntry( "Layout", "us101" ); Server::setKeyboardLayout( layout ); } static bool firstUse() { bool needFirstUse = FALSE; if ( QWSServer::mouseHandler() && QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { if ( !QFile::exists( "/etc/pointercal" ) ) needFirstUse = TRUE; } { Config config( "qpe" ); config.setGroup( "Startup" ); needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); } if ( !needFirstUse ) return FALSE; FirstUse *fu = new FirstUse(); fu->exec(); bool rs = fu->restartNeeded(); delete fu; return rs; } int initApplication( int argc, char ** argv ) { cleanup(); initEnvironment(); //Don't flicker at startup: diff --git a/core/launcher/packageslave.cpp b/core/launcher/packageslave.cpp index bf34368..321b5dd 100644 --- a/core/launcher/packageslave.cpp +++ b/core/launcher/packageslave.cpp @@ -1,226 +1,224 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "packageslave.h" #include <qtopia/qprocess.h> #ifdef Q_WS_QWS #include <qtopia/qcopenvelope_qws.h> #endif -#include <qdatastream.h> #ifdef Q_WS_QWS #include <qcopchannel_qws.h> #endif #include <qtextstream.h> -#include <qdir.h> #include <stdlib.h> #include <sys/stat.h> // mkdir() #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <unistd.h> #include <sys/vfs.h> #include <mntent.h> #elif defined(Q_OS_WIN32) #include <windows.h> #include <winbase.h> #elif defined(Q_OS_MACX) #include <unistd.h> #endif PackageHandler::PackageHandler( QObject *parent, char* name ) : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE ) { // setup qcop channel #ifndef QT_NO_COP packageChannel = new QCopChannel( "QPE/Package", this ); connect( packageChannel, SIGNAL( received(const QCString &, const QByteArray &) ), this, SLOT( qcopMessage( const QCString &, const QByteArray &) ) ); #endif } void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "installPackage(QString)" ) { QString file; stream >> file; installPackage( file ); } else if ( msg == "removePackage(QString)" ) { QString file; stream >> file; removePackage( file ); } else if ( msg == "addPackageFiles(QString,QString)" ) { QString location, listfile; stream >> location >> listfile; addPackageFiles( location, listfile); } else if ( msg == "addPackages(QString)" ) { QString location; stream >> location; addPackages( location ); } else if ( msg == "cleanupPackageFiles(QString)" ) { QString listfile; stream >> listfile; cleanupPackageFiles( listfile ); } else if ( msg == "cleanupPackages(QString)" ) { QString location; stream >> location; cleanupPackages( location ); } else if ( msg == "prepareInstall(QString,QString)" ) { QString size, path; stream >> size; stream >> path; prepareInstall( size, path ); } } void PackageHandler::installPackage( const QString &package ) { if ( mNoSpaceLeft ) { mNoSpaceLeft = FALSE; // Don't emit that for now, I still couldn't test it (Wener) //sendReply( "installFailed(QString)", package ); //return; } currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) ); connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); currentPackage = package; currentProcessError=""; sendReply( "installStarted(QString)", package ); currentProcess->start(); } void PackageHandler::removePackage( const QString &package ) { currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) ); connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); currentPackage = package; currentProcessError=""; sendReply( "removeStarted(QString)", package ); currentProcess->start(); } void PackageHandler::sendReply( const QCString& msg, const QString& arg ) { #ifndef QT_NO_COP QCopEnvelope e( "QPE/Desktop", msg ); e << arg; #endif } void PackageHandler::addPackageFiles( const QString &location, const QString &listfile ) { QFile f(listfile); #ifndef Q_OS_WIN32 //make a copy so we can remove the symlinks later mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); #else QDir d; //#### revise qDebug("Copy file at %s: %s", __FILE__, __LINE__ ); d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); #endif if ( f.open(IO_ReadOnly) ) { QTextStream ts(&f); QString s; while ( !ts.eof() ) { // until end of file... s = ts.readLine(); // line of text excluding '\n' // for s, do link/mkdir. if ( s.right(1) == "/" ) { qDebug("do mkdir for %s", s.ascii()); #ifndef Q_OS_WIN32 mkdir( s.ascii(), 0777 ); //possible optimization: symlink directories //that don't exist already. -- Risky. #else d.mkdir( s.ascii()); #endif } else { #ifndef Q_OS_WIN32 qDebug("do symlink for %s", s.ascii()); symlink( (location + s).ascii(), s.ascii() ); #else qDebug("Copy file instead of a symlink for WIN32"); if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) qWarning("Unable to create symlinkfor %s", (location + s).ascii()); #endif } } f.close(); } } void PackageHandler::addPackages( const QString &location ) { // get list of *.list in location/usr/lib/ipkg/info/*.list QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr QDir::Name, QDir::Files); if ( !dir.exists() ) return; QStringList packages = dir.entryList(); for ( QStringList::Iterator it = packages.begin(); it != packages.end(); ++it ) { addPackageFiles( location, *it ); } } void PackageHandler::cleanupPackageFiles( const QString &listfile ) { QFile f(listfile); if ( f.open(IO_ReadOnly) ) { QTextStream ts(&f); QString s; while ( !ts.eof() ) { // until end of file... s = ts.readLine(); // line of text excluding '\n' // for s, do link/mkdir. if ( s.right(1) == "/" ) { //should rmdir if empty, after all files have been removed } else { #ifndef Q_OS_WIN32 qDebug("remove symlink for %s", s.ascii()); //check if it is a symlink first (don't remove /etc/passwd...) char buf[10]; //we don't care about the contents if ( ::readlink( s.ascii(),buf, 10 >= 0 ) ) ::unlink( s.ascii() ); #else // ### revise diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp index 9bca360..24f471d 100644 --- a/core/launcher/qcopbridge.cpp +++ b/core/launcher/qcopbridge.cpp @@ -1,233 +1,225 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "qcopbridge.h" #include "transferserver.h" #include <opie2/oglobal.h> #ifdef Q_WS_QWS #include <qtopia/qcopenvelope_qws.h> #endif #include <qtopia/qpeapplication.h> #include <qtopia/version.h> -#include <qtopia/config.h> -#include <qdir.h> -#include <qfile.h> #include <qtextstream.h> -#include <qdatastream.h> -#include <qcstring.h> -#include <qstringlist.h> -#include <qfileinfo.h> -#include <qregexp.h> #include <qtimer.h> #ifdef Q_WS_QWS #include <qcopchannel_qws.h> #endif #ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE #endif #ifndef Q_OS_WIN32 #include <pwd.h> #include <unistd.h> #include <sys/types.h> #endif #if defined(_OS_LINUX_) #include <shadow.h> #endif //#define INSECURE const int block_size = 51200; QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, const char* name ) : QServerSocket( port, 1, parent, name ), desktopChannel( 0 ), cardChannel( 0 ) { if ( !ok() ) qWarning( "Failed to bind to port %d", port ); else { #ifndef QT_NO_COP desktopChannel = new QCopChannel( "QPE/Desktop", this ); connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); cardChannel = new QCopChannel( "QPE/Card", this ); connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); #endif } sendSync = FALSE; openConnections.setAutoDelete( TRUE ); authorizeConnections(); } QCopBridge::~QCopBridge() { #ifndef QT_NO_COP delete desktopChannel; #endif } void QCopBridge::authorizeConnections() { Config cfg("Security"); cfg.setGroup("SyncMode"); m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); 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 ) { QCopBridgePI *pi = new QCopBridgePI( socket, this ); openConnections.append( pi ); connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); /* ### libqtopia merge FIXME */ #if 0 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); #endif #ifndef QT_NO_COP QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; #endif if ( sendSync ) { pi ->startSync(); sendSync = FALSE; } } void QCopBridge::closed( QCopBridgePI *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; #endif } } void QCopBridge::closeOpenConnections() { QCopBridgePI *pi; for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) pi->close(); } void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) { if ( command == "startSync()" ) { // we need to buffer it a bit sendSync = TRUE; startTimer( 20000 ); } if ( m_mode & Qtopia1_7 ) { // send the command to all open connections QCopBridgePI *pi; for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { pi->sendDesktopMessage( command, data ); } } if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) ) sendDesktopMessageOld( command, data ); } #ifndef OPIE_NO_OLD_SYNC_CODE /* * Old compat mode */ void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { 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;" ); diff --git a/core/launcher/runningappbar.cpp b/core/launcher/runningappbar.cpp index 1fda5a4..11d10dc 100644 --- a/core/launcher/runningappbar.cpp +++ b/core/launcher/runningappbar.cpp @@ -1,179 +1,172 @@ /********************************************************************** ** 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 -#include <qtopia/global.h> #include <stdlib.h> -#include <qtimer.h> -#include <qpopupmenu.h> #include <qpainter.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), selectedAppIndex(-1) { 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::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()); appList.prepend(newApp); 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(); } 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. 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; } } } else { break; } } selectedAppIndex = -1; repaint( FALSE ); } void RunningAppBar::mouseReleaseEvent(QMouseEvent *e) { 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(); } } 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(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; } } } QSize RunningAppBar::sizeHint() const { return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 ); } void RunningAppBar::applicationLaunched(const QString &appName) { qDebug("desktop:: app: %s launched with pid ", appName.data() ); const AppLnk* newGuy = ServerInterface::appLnks().findExec(appName); if ( newGuy && !newGuy->isPreloaded() ) { addTask( *newGuy ); } } void RunningAppBar::applicationTerminated(const QString &app) { const AppLnk* gone = ServerInterface::appLnks().findExec(app); if ( gone ) { removeTask(*gone); } } diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index 1146dcd..e544c61 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp @@ -1,197 +1,196 @@ #include "screensaver.h" #include <qpe/config.h> -#include <qpe/power.h> #include <qpe/network.h> #include <opie2/odevice.h> using namespace Opie; OpieScreenSaver::OpieScreenSaver ( ) : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) { m_disable_suspend = 100; m_enable_dim = false; m_enable_lightoff = false; m_enable_suspend = false; m_onlylcdoff = false; m_enable_dim_ac = false; m_enable_lightoff_ac = false; m_enable_suspend_ac = false; m_onlylcdoff_ac = false; m_use_light_sensor = false; m_backlight_sensor = -1; ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); m_lcd_status = true; m_backlight_normal = -1; m_backlight_current = -1; m_backlight_forcedoff = false; m_on_ac = false; m_level = -1; // 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 ); setBacklight ( -1 ); } /** * Stops the screen saver */ void OpieScreenSaver::restore() { m_level = -1; if ( !m_lcd_status ) { // We must have turned it off ODevice::inst ( ) -> setDisplayStatus ( true ); m_lcd_status = true; } setBacklightInternal ( -1 ); } /** * Starts the screen saver * * @param level what level of screen saving should happen (0=lowest non-off, 1=off, * 2=suspend whole machine) * @returns true on success */ bool OpieScreenSaver::save( int level ) { m_level = level; switch ( level ) { case 0: if (( m_on_ac && m_enable_dim_ac ) || ( !m_on_ac && m_enable_dim )) { if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) setBacklightInternal ( 1 ); // lowest non-off } return true; break; case 1: if (( m_on_ac && m_enable_lightoff_ac ) || ( !m_on_ac && m_enable_lightoff )) { if ( m_disable_suspend > 1 ) setBacklightInternal ( 0 ); // off } return true; break; case 2: if (( m_on_ac && !m_enable_suspend_ac ) || ( !m_on_ac && !m_enable_suspend )) { return true; } if (( m_on_ac && m_onlylcdoff_ac ) || ( !m_on_ac && m_onlylcdoff )) { ODevice::inst ( ) -> setDisplayStatus ( false ); m_lcd_status = false; return true; } // We're going to suspend the whole machine if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { // TODO: why is this key F34 hard coded? -- schurig // Does this now only work an devices with a ODevice::filter? QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); return true; } break; } return false; } /** * Set intervals in seconds for automatic dimming, light off and suspend * * This function also sets the member variables m_m_enable_dim[_ac], * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac] * * @param dim time in seconds to dim, -1 to read value from config file, * 0 to disable * @param lightoff time in seconds to turn LCD backlight off, -1 to * read value from config file, 0 to disable * @param suspend time in seconds to do an APM suspend, -1 to * read value from config file, 0 to disable */ void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) { Config config ( "apm" ); config. setGroup ( m_on_ac ? "AC" : "Battery" ); int v[ 4 ]; if ( dim < 0 ) dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); if ( lightoff < 0 ) lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); if ( suspend < 0 ) suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); if ( m_on_ac ) { m_enable_dim_ac = ( dim > 0 ); m_enable_lightoff_ac = ( lightoff > 0 ); m_enable_suspend_ac = ( suspend > 0 ); m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); } else { m_enable_dim = ( dim > 0 ); m_enable_lightoff = ( lightoff > 0 ); m_enable_suspend = ( suspend > 0 ); m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); } //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend); v [ 0 ] = QMAX( 1000 * dim, 100 ); v [ 1 ] = QMAX( 1000 * lightoff, 100 ); v [ 2 ] = QMAX( 1000 * suspend, 100 ); v [ 3 ] = 0; if ( !dim && !lightoff && !suspend ) QWSServer::setScreenSaverInterval( 0 ); else QWSServer::setScreenSaverIntervals( v ); } /** * Set suspend time. Will read the dim and lcd-off times from the config file. * * @param suspend time in seconds to go into APM suspend, -1 to * read value from config file, 0 to disable */ void OpieScreenSaver::setInterval ( int interval ) { setIntervals ( -1, -1, interval ); } void OpieScreenSaver::setMode ( int mode ) { if ( mode > m_disable_suspend ) setInterval ( -1 ); m_disable_suspend = mode; } /** * Set display brightness diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp index 32fcdd0..068d716 100644 --- a/core/launcher/server.cpp +++ b/core/launcher/server.cpp @@ -1,224 +1,223 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "server.h" #include "serverapp.h" -#include "launcher.h" #include "startmenu.h" +#include "launcher.h" #include "transferserver.h" #include "qcopbridge.h" #include "irserver.h" #include "packageslave.h" #include "calibrate.h" #include "qrsync.h" #include "syncdialog.h" -#include "launcher.h" #include "shutdownimpl.h" #include "applauncher.h" #if 0 #include "suspendmonitor.h" #endif #include "documentlist.h" #include <qtopia/applnk.h> #include <qtopia/private/categories.h> #include <qtopia/mimetype.h> #include <qtopia/config.h> #include <qtopia/resource.h> #include <qtopia/version.h> #include <qtopia/storage.h> #include <qtopia/qcopenvelope_qws.h> #include <qwindowsystem_qws.h> #include <qgfx_qws.h> #include <qtopia/global.h> //#include <qtopia/custom.h> #include <opie2/odevicebutton.h> #include <opie2/odevice.h> #include <unistd.h> #include <qmainwindow.h> #include <qmessagebox.h> #include <qtimer.h> #include <qtextstream.h> #include <stdlib.h> extern QRect qt_maxWindowRect; using namespace Opie; static QWidget *calibrate(bool) { #ifdef Q_WS_QWS Calibrate *c = new Calibrate; c->show(); return c; #else return 0; #endif } #define FACTORY(T) \ static QWidget *new##T( bool maximized ) { \ QWidget *w = new T( 0, 0, 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 "apps.h" #undef APP #endif // SINGLE_APP static Global::Command builtins[] = { #ifdef SINGLE_APP #define APP(a,b,c,d) { a, new##b, c, d }, #include "apps.h" #undef APP #endif /* FIXME defines need to be defined*/ #if !defined(OPIE_NO_BUILTIN_CALIBRATE) { "calibrate", calibrate, 1, 0 }, // No tr #endif #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) { "shutdown", Global::shutdown, 1, 0 }, // No tr // { "run", run, 1, 0 }, // No tr #endif { 0, calibrate, 0, 0 }, }; //--------------------------------------------------------------------------- //=========================================================================== Server::Server() : QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), qcopBridge( 0 ), transferServer( 0 ), packageHandler( 0 ), syncDialog( 0 ) { Global::setBuiltinCommands(builtins); tid_xfer = 0; /* ### FIXME ### */ /* tid_today = startTimer(3600*2*1000);*/ last_today_show = QDate::currentDate(); #if 0 tsmMonitor = new TempScreenSaverMode(); connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); #endif serverGui = new Launcher; serverGui->createGUI(); docList = new DocumentList( serverGui ); appLauncher = new AppLauncher(this); connect(appLauncher, SIGNAL(launched(int, const QString &)), this, SLOT(applicationLaunched(int, const QString &)) ); connect(appLauncher, SIGNAL(terminated(int, const QString &)), this, SLOT(applicationTerminated(int, const QString &)) ); connect(appLauncher, SIGNAL(connected(const QString &)), this, SLOT(applicationConnected(const QString &)) ); storage = new StorageInfo( this ); connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); // start services startTransferServer(); (void) new IrServer( this ); packageHandler = new PackageHandler( this ); connect(qApp, SIGNAL(activate(const Opie::ODeviceButton*,bool)), this,SLOT(activate(const Opie::ODeviceButton*,bool))); setGeometry( -10, -10, 9, 9 ); QCopChannel *channel = new QCopChannel("QPE/System", this); connect(channel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(systemMsg(const QCString &, const QByteArray &)) ); QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); connect( tbChannel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receiveTaskBar(const QCString&, const QByteArray&)) ); connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); preloadApps(); } void Server::show() { ServerApplication::login(TRUE); QWidget::show(); } Server::~Server() { serverGui->destroyGUI(); delete docList; delete qcopBridge; delete transferServer; delete serverGui; #if 0 delete tsmMonitor; #endif } static bool hasVisibleWindow(const QString& clientname, bool partial) { #ifdef QWS const QList<QWSWindow> &list = qwsServer->clientWindows(); QWSWindow* w; for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { if ( w->client()->identity() == clientname ) { if ( partial && !w->isFullyObscured() ) return TRUE; if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { # if QT_VERSION < 0x030000 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, QSize(qt_screen->width(),qt_screen->height()) ); # else QRect mwr = qt_maxWindowRect; # endif if ( mwr.contains(w->requested().boundingRect()) ) return TRUE; } } } #endif return FALSE; } diff --git a/core/launcher/shutdownimpl.cpp b/core/launcher/shutdownimpl.cpp index 899d9ac..f43a2a3 100644 --- a/core/launcher/shutdownimpl.cpp +++ b/core/launcher/shutdownimpl.cpp @@ -1,174 +1,173 @@ /********************************************************************** ** 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 "shutdownimpl.h" #include <qpe/global.h> #include <qpe/qcopenvelope_qws.h> #include <qtimer.h> #include <qprogressbar.h> #include <qpushbutton.h> #include <qbuttongroup.h> #include <qlabel.h> #include <qlayout.h> -#include <qpalette.h> static void changeButtonColor ( QPushButton *btn, const QColor &col ) { QPalette pal = btn-> palette ( ); pal. setColor ( QPalette::Active, QColorGroup::Button, col ); pal. setColor ( QPalette::Disabled, QColorGroup::Button, col ); pal. setColor ( QPalette::Inactive, QColorGroup::Button, col ); btn-> setPalette ( pal ); } ShutdownImpl::ShutdownImpl( QWidget* parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) { setCaption ( tr( "Shutdown..." ) ); QVBoxLayout *vbox = new QVBoxLayout ( this ); vbox-> setSpacing ( 3 ); vbox-> setMargin ( 6 ); QButtonGroup *btngrp = new QButtonGroup ( this ); btngrp-> setTitle ( tr( "Terminate" ) ); btngrp-> setColumnLayout ( 0, Qt::Vertical ); btngrp-> layout ( ) -> setSpacing ( 0 ); btngrp-> layout ( ) -> setMargin ( 0 ); QGridLayout *grid = new QGridLayout ( btngrp-> layout ( ) ); grid-> setAlignment ( Qt::AlignTop ); grid-> setSpacing ( 3 ); grid-> setMargin ( 7 ); QPushButton *quit = new QPushButton ( tr( "Terminate Opie" ), btngrp, "quit" ); changeButtonColor ( quit, QColor ( 236, 236, 179 ) ); btngrp-> insert ( quit, 4 ); grid-> addWidget ( quit, 1, 1 ); QPushButton *reboot = new QPushButton ( tr( "Reboot" ), btngrp, "reboot" ); changeButtonColor ( reboot, QColor( 236, 183, 181 ) ); btngrp-> insert ( reboot, 2 ); grid-> addWidget( reboot, 1, 0 ); QPushButton *restart = new QPushButton ( tr( "Restart Opie" ), btngrp, "restart" ); changeButtonColor ( restart, QColor( 236, 236, 179 ) ); btngrp-> insert ( restart, 3 ); grid-> addWidget ( restart, 0, 1 ); QPushButton *shutdown = new QPushButton( tr( "Shutdown" ), btngrp, "shutdown" ); changeButtonColor ( shutdown, QColor( 236, 183, 181 ) ); btngrp-> insert ( shutdown, 1 ); grid-> addWidget ( shutdown, 0, 0 ); vbox-> addWidget ( btngrp ); m_info = new QLabel ( this, "info" ); m_info-> setText( tr( "<p>\n" "These termination options are provided primarily for use while developing and testing the Opie system. In a normal environment, these concepts are unnecessary." ) ); vbox-> addWidget ( m_info ); m_progress = new QProgressBar ( this, "progressBar" ); m_progress-> setFrameShape ( QProgressBar::Panel ); m_progress-> setFrameShadow ( QProgressBar::Sunken ); m_progress-> setTotalSteps ( 20 ); m_progress-> setIndicatorFollowsStyle ( false ); vbox-> addWidget ( m_progress ); vbox-> addItem ( new QSpacerItem ( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); QPushButton *cancel = new QPushButton ( tr( "Cancel" ), this, "cancel" ); changeButtonColor ( cancel, QColor( 181, 222, 178 ) ); cancel-> setDefault ( true ); cancel-> setSizePolicy ( QSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding, cancel-> sizePolicy ( ). hasHeightForWidth ( ) ) ); vbox-> addWidget ( cancel ); m_timer = new QTimer ( this ); connect ( m_timer, SIGNAL( timeout ( ) ), this, SLOT( timeout ( ) ) ); connect ( btngrp, SIGNAL( clicked ( int ) ), this, SLOT( buttonClicked ( int ) ) ); connect ( cancel, SIGNAL( clicked ( ) ), this, SLOT( cancelClicked ( ) ) ); m_progress-> hide ( ); Global::hideInputMethod ( ); } void ShutdownImpl::buttonClicked ( int b ) { m_counter = 0; switch ( b ) { case 1: m_operation = ShutdownSystem; break; case 2: m_operation = RebootSystem; break; case 3: m_operation = RestartDesktop; break; case 4: m_operation = TerminateDesktop; break; } m_info-> hide ( ); m_progress-> show ( ); m_timer-> start ( 300 ); timeout ( ); } void ShutdownImpl::cancelClicked ( ) { m_progress-> hide ( ); m_info-> show ( ); if ( m_timer-> isActive ( ) ) m_timer-> stop ( ); else close ( ); } void ShutdownImpl::timeout ( ) { if ( ( m_counter += 2 ) > m_progress-> totalSteps ( ) ) { m_progress-> hide ( ); m_timer-> stop ( ); emit shutdown ( m_operation ); } else m_progress-> setProgress ( m_counter ); } void ShutdownImpl::hide ( ) { if ( isVisible ( )) { // hack - shutdown is a launcher dialog, but treated like a standalone app QCopEnvelope e( "QPE/System", "closing(QString)" ); e << QString ( "shutdown" ); } QWidget::hide ( ); } diff --git a/core/launcher/stabmon.cpp b/core/launcher/stabmon.cpp index 4e5f290..f2d694b 100644 --- a/core/launcher/stabmon.cpp +++ b/core/launcher/stabmon.cpp @@ -1,102 +1,101 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "stabmon.h" #ifdef QWS #include <qtopia/qcopenvelope_qws.h> #endif #include <qfile.h> -#include <qcstring.h> #include <sys/stat.h> #if defined(Q_OS_LINUX) || defined(_OS_LINUX_) #include <unistd.h> #endif #include <stdlib.h> SysFileMonitor::SysFileMonitor(QObject* parent) : QObject(parent) { startTimer(2000); } const char * stab0 = "/var/run/stab"; const char * stab1 = "/var/state/pcmcia/stab"; const char * stab2 = "/var/lib/pcmcia/stab"; void SysFileMonitor::timerEvent(QTimerEvent*) { struct stat s; static const char * tab [] = { stab0, stab1, stab2 }; static const int nstab = sizeof(tab)/sizeof(const char *); static int last[nstab]; bool ch = FALSE; for ( int i=0; i<nstab; i++ ) { if ( ::stat(tab[i], &s)==0 && (long)s.st_mtime != last[i] ) { last[i] = (long)s.st_mtime; ch=TRUE; } if ( ch ) { #ifndef QT_NO_COP QCopEnvelope("QPE/Card", "stabChanged()" ); #endif break; } } // st_size is no use, it's 0 for /proc/mounts too. Read it all. static int mtabSize = 0; QFile f( "/proc/mounts" ); if ( f.open(IO_ReadOnly) ) { #if 0 // readAll does not work correctly on sequential devices (as eg. /proc files) QByteArray ba = f.readAll(); if ( (int)ba.size() != mtabSize ) { mtabSize = (int)ba.size(); #ifndef QT_NO_COP QCopEnvelope("QPE/Card", "mtabChanged()" ); #endif } #else QString s; while( !f.atEnd() ) { QString tmp; f.readLine( tmp, 1024 ); s += tmp; } if ( (int)s.length() != mtabSize ) { mtabSize = (int)s.length(); #ifndef QT_NO_COP QCopEnvelope("QPE/Card", "mtabChanged()" ); #endif } #endif } } diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp index c199063..f3a7651 100644 --- a/core/launcher/startmenu.cpp +++ b/core/launcher/startmenu.cpp @@ -1,231 +1,227 @@ /**********************************************************************
** 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.
**
**********************************************************************/
// TODO. During startup
// Launcher::typeAdded
// is called for each new tab and calls then each time the refresh of startmenu
// suboptimal
#define INCLUDE_MENUITEM_DEF
#include "startmenu.h"
#include <qtopia/qpeapplication.h>
#include <qtopia/config.h>
-#include <qtopia/applnk.h>
-#include <qtopia/global.h>
#include <qtopia/resource.h>
#include <qtopia/mimetype.h>
#include <qtopia/qlibrary.h>
-#include <qdict.h>
-#include <qdir.h>
//#include <qpainter.h>
//#include <stdlib.h>
#define APPLNK_ID_OFFSET 250
#define NO_ID -1
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 );
}
}
//---------------------------------------------------------------------------
StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
{
startButtonPixmap = "go"; // No tr
int sz = AppLnk::smallIconSize()+3;
QPixmap pm;
pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) );
setPixmap(pm);
setFocusPolicy( NoFocus );
useWidePopupMenu = true;
launchMenu = 0;
refreshMenu();
}
void StartMenu::mousePressEvent( QMouseEvent * )
{
launch();
}
StartMenu::~StartMenu()
{
clearApplets();
}
void StartMenu::createMenu()
{
clearApplets();
delete launchMenu;
launchMenu = new StartPopupMenu( this );
loadMenu( launchMenu );
loadApplets();
bool result = currentItem || menuApplets.count();
if ( result )
connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
}
void StartMenu::refreshMenu()
{
Config cfg( "StartMenu" );
cfg.setGroup( "Menu" );
bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE );
bool lot = cfg.readBoolEntry( "LauncherOther", TRUE );
useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
if ( launchMenu && !(ltabs || lot) ) return; // nothing to do
createMenu();
}
void StartMenu::itemSelected( int id )
{
if ( id == NO_ID ) return;
if ( id < 0 ) {
MenuApplet *applet = menuApplets.find( id );
if ( applet ) {
applet->iface->activated();
}
} else if ( id >= APPLNK_ID_OFFSET ) {
AppLnk * appLnk = appLnks.find( id );
if ( appLnk ) {
appLnk->execute();
}
} else {
QString *tabName = tabNames.find( id );
if ( tabName ) {
emit tabSelected( *tabName );
}
}
}
void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
{
if ( file.right(8) == ".desktop" ) {
AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
if ( !applnk->isValid() ) {
delete applnk;
return;
}
if ( applnk->type() == "Separator" ) { // No tr
menu->insertSeparator();
delete applnk;
} else {
QPixmap test;
QImage img = Resource::loadImage( applnk->icon() );
if(!img.isNull() )
test.convertFromImage(
img.smoothScale(
AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
menu->insertItem( test, applnk->name(),
currentItem + APPLNK_ID_OFFSET );
appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
currentItem++;
}
}
}
void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
{
// do some sanity checks and collect information
if ( file == "." || file == ".." ) return;
Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
if ( !cfg.isValid() ) return;
QString name = cfg.readEntry( "Name" );
QString icon = cfg.readEntry( "Icon" );
if ( !name || !icon ) return;
QDir subdir = QDir( dir );
subdir.cd( file );
subdir.setFilter( QDir::Files );
subdir.setNameFilter( "*.desktop" );
// we don' t show the menu if there are no entries
// perhaps one should check if there exist subsubdirs with entries...
if ( subdir.entryList().isEmpty() ) return;
// checks were ok
QPixmap test;
test.convertFromImage( Resource::loadImage( icon ).smoothScale(
AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
if ( useWidePopupMenu ) {
// generate submenu
QPopupMenu *submenu = new QPopupMenu( menu );
connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
menu->insertItem( test, name, submenu, NO_ID );
// ltabs is true cause else we wouldn't stuck around..
createMenuEntries( submenu, subdir, true, lot );
} else {
// no submenus - just bring corresponding tab to front
menu->insertItem( test, name, currentItem );
tabNames.insert( currentItem, new QString( file ) );
currentItem++;
}
}
void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
{
if ( lot ) {
dir.setFilter( QDir::Files );
dir.setNameFilter( "*.desktop" );
QStringList files = dir.entryList();
files.sort();
for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
createAppEntry( menu, dir, *it );
}
}
if ( ltabs ) {
dir.setNameFilter( "*" );
dir.setFilter( QDir::Dirs );
QStringList dirs = dir.entryList();
dirs.sort();
for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
createDirEntry( menu, dir, *it, lot );
}
}
diff --git a/core/launcher/syncdialog.cpp b/core/launcher/syncdialog.cpp index 6f6c781..4a2b8ff 100644 --- a/core/launcher/syncdialog.cpp +++ b/core/launcher/syncdialog.cpp @@ -1,184 +1,183 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "syncdialog.h" #include <qtopia/resource.h> -#include <qimage.h> #include <qpainter.h> #include <qapplication.h> #include <qpushbutton.h> #include <qfile.h> SyncDialog::SyncDialog( QWidget *parent, const QString &w ) : QDialog( parent, "SyncDialog", FALSE, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop ), what(w), nextPt(0), rev(FALSE), hideDot(TRUE) { QFont f( font() ); f.setPointSize( 16 ); setFont(f); loadPath(); QSize ds = qApp->desktop()->size(); setGeometry( 0, 0, ds.width(), ds.height() ); img = Resource::loadImage( "SyncScreen" ); if ( img.width() > ds.width() || img.height() > ds.height() ) { path = scalePath( path, ds.width(), img.width(), ds.height(), img.height() ); img = img.smoothScale( ds.width(), ds.height() ); } dot = Resource::loadImage( "syncdot" ); setBackgroundColor( white ); QPushButton *pb = new QPushButton( tr("Abort"), this, "CancelSync" ); QSize bs = pb->sizeHint(); bs.rwidth() += 10; bs.rheight() += 5; pb->setGeometry( (ds.width()-bs.width())/2, 4*ds.height()/5, bs.width(), bs.height() ); connect( pb, SIGNAL(clicked()), this, SIGNAL(cancel()) ); if ( path.count() >= 2 ) { path = generatePath( path, 8 ); startTimer( 200 ); } } void SyncDialog::paintEvent( QPaintEvent *pe ) { QPainter p(this ); p.setClipRect( pe->rect() ); int ox = (width() - img.width())/2; int oy = (height() - img.height())/2; QRect ir = QRect(ox, oy, img.width(), img.height()) & pe->rect(); if ( ir.isValid() ) p.drawImage( ir.x(), ir.y(), img, ir.x()-ox, ir.y()-oy, ir.width(), ir.height() ); QString syncMsg = tr("Syncing:"); p.setPen( black ); QRect r( 0, 0, width()/2-5, QMAX(oy,80) ); p.drawText( r, AlignRight | AlignVCenter, syncMsg ); r.moveBy( width()/2, 0 ); QFont f( font() ); f.setWeight( QFont::Bold ); p.setFont( f ); p.drawText( r, AlignLeft | AlignVCenter, what ); if ( !hideDot ) p.drawImage( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2, dot ); } void SyncDialog::timerEvent( QTimerEvent * ) { int ox = (width() - img.width())/2; int oy = (height() - img.height())/2; int oldPt = nextPt; if ( !rev ) { nextPt++; if ( nextPt == (int)path.count() ) { nextPt -= 2; rev = TRUE; } } else { nextPt--; if ( nextPt < 0 ) { nextPt = 1; rev = FALSE; } } hideDot = FALSE; repaint( ox+path[nextPt].x()-dot.width()/2, oy+path[nextPt].y()-dot.height()/2, dot.width(), dot.height() ); hideDot = TRUE; repaint( ox+path[oldPt].x()-dot.width()/2, oy+path[oldPt].y()-dot.height()/2, dot.width(), dot.height() ); } void SyncDialog::loadPath() { QString pfile = Resource::findPixmap( "syncdot" ); if ( pfile.isEmpty() ) return; int dp = pfile.findRev('.'); pfile.replace( dp, pfile.length()-dp, ".path" ); int count = 0; QFile file( pfile ); if ( file.open( IO_ReadOnly ) ) { QString line; while ( file.readLine( line, 256 ) > 0 ) { int x, y; if ( sscanf( line.latin1(), "%d %d", &x, &y ) == 2 ) { path.resize( count+1 ); path[count++] = QPoint(x, y); } } } } QPointArray SyncDialog::scalePath( const QPointArray &pa, int xn, int xd, int yn, int yd ) { QPointArray sa( pa.size() ); for ( unsigned i = 0; i < pa.count(); i++ ) { int x = xn * pa[int(i)].x() / xd; int y = yn * pa[int(i)].y() / yd; sa[int(i)] = QPoint( x, y ); } return sa; } QPointArray SyncDialog::generatePath( const QPointArray &pa, int dist ) { if ( pa.count() < 2 ) return pa; QPointArray fa; int count = 0; fa.resize( count+1 ); fa[count++] = pa[0]; for ( unsigned i = 0; i < pa.count()-1; i++ ) { int x1 = pa[int(i)].x(); int y1 = pa[int(i)].y(); int x2 = pa[int(i+1)].x(); int y2 = pa[int(i+1)].y(); int dx = x2 - x1; int dy = y2 - y1; int pts = (QMAX(QABS(dx),QABS(dy)) + dist/2 )/dist; for ( int j = 1; j < pts; j++ ) { int x = j * dx / pts; int y = j * dy / pts; fa.resize( count+1 ); fa[count++] = pa[int(i)] + QPoint( x, y ); } fa.resize( count+1 ); fa[count++] = pa[int(i+1)]; } return fa; } diff --git a/core/launcher/systray.cpp b/core/launcher/systray.cpp index 691f6b8..6cc1446 100644 --- a/core/launcher/systray.cpp +++ b/core/launcher/systray.cpp @@ -1,154 +1,152 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include <qtopia/qpeapplication.h> #include <qtopia/qlibrary.h> #include <qtopia/config.h> #include <qlayout.h> #include <qdir.h> -#include <qmessagebox.h> -#include <qtranslator.h> #include "systray.h" #include <stdlib.h> /* ### Single build floppies ### */ #if 0 #ifdef QT_NO_COMPONENTS #include "../plugins/applets/clockapplet/clockappletimpl.h" #endif #endif SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0) { //setFrameStyle( QFrame::Panel | QFrame::Sunken ); loadApplets(); } SysTray::~SysTray() { clearApplets(); } static int compareAppletPositions(const void *a, const void *b) { const TaskbarApplet* aa = *(const TaskbarApplet**)a; const TaskbarApplet* ab = *(const TaskbarApplet**)b; int d = ab->iface->position() - aa->iface->position(); if ( d ) return d; return QString::compare(ab->name,aa->name); } void SysTray::loadApplets() { hide(); clearApplets(); addApplets(); } void SysTray::clearApplets() { #ifndef QT_NO_COMPONENTS /* * Note on clearing. SOme applets delete their * applets themselves some don't do it * and on restart this can crash. If we delete it * here we might end up in a double deletion. We could * use QGuardedPtr but that would be one QOBject * for every applet more but only useful for restart */ QValueList<TaskbarApplet>::Iterator mit; for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) { (*mit).iface->release(); (*mit).library->unload(); delete (*mit).library; } #endif appletList.clear(); if ( layout ) delete layout; layout = new QHBoxLayout( this, 0, 1 ); layout->setAutoAdd(TRUE); } void SysTray::addApplets() { hide(); #ifndef QT_NO_COMPONENTS Config cfg( "Taskbar" ); cfg.setGroup( "Applets" ); QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); QString lang = getenv( "LANG" ); QString path = QPEApplication::qpeDir() + "/plugins/applets"; #ifdef Q_OS_MACX QDir dir( path, "lib*.dylib" ); #else QDir dir( path, "lib*.so" ); #endif /* Q_OS_MACX */ QStringList list = dir.entryList(); QStringList::Iterator it; int napplets=0; TaskbarApplet* *applets = new TaskbarApplet*[list.count()]; for ( it = list.begin(); it != list.end(); ++it ) { if ( exclude.find( *it ) != exclude.end() ) continue; qWarning( "Found Applet: %s", (*it).latin1() ); TaskbarAppletInterface *iface = 0; QLibrary *lib = new QLibrary( path + "/" + *it ); if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { TaskbarApplet *applet = new TaskbarApplet; applets[napplets++] = applet; applet->library = lib; applet->iface = iface; QTranslator *trans = new QTranslator(qApp); QString type = (*it).left( (*it).find(".") ); QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; if ( trans->load( tfn )) qApp->installTranslator( trans ); else delete trans; } else { exclude += *it; delete lib; } } cfg.writeEntry( "ExcludeApplets", exclude, ',' ); qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions); while (napplets--) { TaskbarApplet *applet = applets[napplets]; applet->applet = applet->iface->applet( this ); appletList.append(*applet); } delete [] applets; #else /* ## FIXME single app */ TaskbarApplet * const applet = new TaskbarApplet(); applet->iface = new ClockAppletImpl(); applet->applet = applet->iface->applet( this ); appletList.append( applet ); #endif show(); } diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index 8367a62..b998e95 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp @@ -1,252 +1,242 @@ /********************************************************************** ** 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 _XOPEN_SOURCE #include <opie2/oglobal.h> -#include <qtopia/qpeapplication.h> #ifndef Q_OS_WIN32 #include <pwd.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #ifndef Q_OS_MACX #include <shadow.h> #include <crypt.h> #endif /* Q_OS_MACX */ #else #include <stdlib.h> #include <time.h> #endif #if defined(_OS_LINUX_) #include <shadow.h> #endif -#include <qdir.h> -#include <qfile.h> #include <qtextstream.h> -#include <qdatastream.h> #include <qmessagebox.h> -#include <qstringlist.h> -#include <qfileinfo.h> -#include <qregexp.h> //#include <qtopia/qcopchannel_qws.h> #include <qtopia/process.h> -#include <qtopia/global.h> -#include <qtopia/config.h> #include <qtopia/private/contact.h> -#include <qtopia/quuid.h> #include <qtopia/version.h> #ifdef Q_WS_QWS #include <qtopia/qcopenvelope_qws.h> #endif #include "transferserver.h" #include <qtopia/qprocess.h> const int block_size = 51200; TransferServer::TransferServer( Q_UINT16 port, QObject *parent, const char* name) : QServerSocket( port, 1, parent, name ) { connections.setAutoDelete( TRUE ); if ( !ok() ) qWarning( "Failed to bind to port %d", port ); } void TransferServer::authorizeConnections() { QListIterator<ServerPI> it(connections); while ( it.current() ) { if ( !it.current()->verifyAuthorised() ) { disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); connections.removeRef( it.current() ); } else ++it; } } void TransferServer::closed(ServerPI *item) { connections.removeRef(item); } TransferServer::~TransferServer() { } void TransferServer::newConnection( int socket ) { ServerPI *ptr = new ServerPI( socket, this ); connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); connections.append( ptr ); } QString SyncAuthentication::serverId() { Config cfg("Security"); cfg.setGroup("Sync"); QString r = cfg.readEntry("serverid"); if ( r.isEmpty() ) { r = OGlobal::generateUuid(); cfg.writeEntry("serverid", r ); } return r; } QString SyncAuthentication::ownerName() { QString vfilename = Global::applicationFileName("addressbook", "businesscard.vcf"); if (QFile::exists(vfilename)) { Contact c; c = Contact::readVCard( vfilename )[0]; return c.fullName(); } return QString::null; } QString SyncAuthentication::loginName() { struct passwd *pw = 0L; #ifndef Q_OS_WIN32 pw = getpwuid( geteuid() ); return QString::fromLocal8Bit( pw->pw_name ); #else //### revise return QString(); #endif } int SyncAuthentication::isAuthorized(QHostAddress peeraddress) { Config cfg("Security"); cfg.setGroup("Sync"); // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); // QHostAddress allowed; // allowed.setAddress(allowedstr); // uint auth_peer = allowed.ip4Addr(); uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); return (peeraddress.ip4Addr() & mask) == auth_peer; } bool SyncAuthentication::checkUser( const QString& user ) { if ( user.isEmpty() ) return FALSE; QString euser = loginName(); return user == euser; } bool SyncAuthentication::checkPassword( const QString& password ) { #ifdef ALLOW_UNIX_USER_FTP // First, check system password... struct passwd *pw = 0; struct spwd *spw = 0; pw = getpwuid( geteuid() ); spw = getspnam( pw->pw_name ); QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); if ( cpwd == "x" && spw ) cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); // Note: some systems use more than crypt for passwords. QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); if ( cpwd == cpassword ) return TRUE; #endif static int lastdenial=0; static int denials=0; int now = time(0); Config cfg("Security"); cfg.setGroup("SyncMode"); int mode = cfg.readNumEntry("Mode", 0x02 ); //No pass word needed if the user really needs it if (mode & 0x04) { QMessageBox unauth( tr("Sync Connection"), tr("<qt><p>An unauthorized system is requesting access to this device." "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ), QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton, 0, QString::null, TRUE, WStyle_StaysOnTop); unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) ); unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); switch( unauth.exec() ) { case QMessageBox::Ok: return TRUE; break; case QMessageBox::Cancel: default: denials++; lastdenial=now; return FALSE; } } // Detect old Qtopia Desktop (no password) and fail if ( password.isEmpty() ) { if ( denials < 3 || now > lastdenial+600 ) { QMessageBox unauth( tr("Sync Connection"), tr("<p>An unauthorized system is requesting access to this device." "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " "please upgrade or change the security setting to use IntelliSync." ), QMessageBox::Warning, QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 0, QString::null, TRUE, WStyle_StaysOnTop); unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); unauth.exec(); denials++; lastdenial=now; } return FALSE; } // Second, check sync password... static int lock=0; if ( lock ) return FALSE; ++lock; /* * we need to support old Sync software and QtopiaDesktop diff --git a/core/launcher/wait.cpp b/core/launcher/wait.cpp index 34ffd1a..4148e57 100644 --- a/core/launcher/wait.cpp +++ b/core/launcher/wait.cpp @@ -1,78 +1,74 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "wait.h" -#include <qtopia/resource.h> #include <qtopia/config.h> #include <opie2/owait.h> -#include <qwidget.h> -#include <qpixmap.h> -#include <qpainter.h> Wait *lastWaitObject = NULL; Wait::Wait( QWidget *parent ) : QWidget( parent ), pm( Resource::loadPixmap( "wait" ) ), waiting( FALSE ) { setFixedSize( pm.size() ); lastWaitObject = this; m_centralWait = new OWait( 0l ); m_centralWait->hide(); hide(); } Wait *Wait::getWaitObject() { return lastWaitObject; } void Wait::setWaiting( bool w ) { Config cfg ( "Launcher" ); cfg.setGroup("GUI"); waiting = w; if ( w ) { if ( cfg. readBoolEntry( "BigBusy" ) ) m_centralWait->show(); else show(); }else{ m_centralWait->hide(); hide(); } } void Wait::paintEvent( QPaintEvent * ) { QPainter p( this ); p.drawPixmap( 0, 0, pm ); } |