author | chicken <chicken> | 2004-03-01 17:07:58 (UTC) |
---|---|---|
committer | chicken <chicken> | 2004-03-01 17:07:58 (UTC) |
commit | 796de538b7b7bc7c3e2af3e8dd081000c21569ac (patch) (side-by-side diff) | |
tree | fbe33813de3cd593baa44bbf6d6340709b836490 | |
parent | 8de0eea414192d758746a5f3950b9765e9709bf9 (diff) | |
download | opie-796de538b7b7bc7c3e2af3e8dd081000c21569ac.zip opie-796de538b7b7bc7c3e2af3e8dd081000c21569ac.tar.gz opie-796de538b7b7bc7c3e2af3e8dd081000c21569ac.tar.bz2 |
fix includes
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 1 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 6 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayer.cpp | 7 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayerstate.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/modplug/load_j2b.cpp | 1 | ||||
-rw-r--r-- | core/multimedia/opieplayer/om3u.cpp | 15 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistselection.cpp | 8 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 25 | ||||
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 4 | ||||
-rw-r--r-- | core/opie-login/loginwindowimpl.cpp | 4 | ||||
-rw-r--r-- | core/opie-login/main.cpp | 4 | ||||
-rw-r--r-- | core/opie-login/opie-login.pro | 2 |
12 files changed, 2 insertions, 77 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index d296d27..355062b 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp @@ -1,323 +1,322 @@ /********************************************************************** ** 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. ** **********************************************************************/ // L.J.Potter added better error code Fri 02-15-2002 14:37:47 #include <stdlib.h> #include <stdio.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> -#include <qpe/custom.h> #include <qmessagebox.h> #include "audiodevice.h" #include <errno.h> #if !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif #if defined(Q_WS_X11) || defined(Q_WS_QWS) #include <fcntl.h> #include <sys/ioctl.h> #include <sys/soundcard.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #endif #ifdef OPIE_SOUND_FRAGMENT_SHIFT static const int sound_fragment_shift = OPIE_SOUND_FRAGMENT_SHIFT; #else static const int sound_fragment_shift = 16; #endif static const int sound_fragment_bytes = (1<<sound_fragment_shift); //#endif class AudioDevicePrivate { public: int handle; unsigned int frequency; unsigned int channels; unsigned int bytesPerSample; unsigned int bufferSize; //#ifndef Q_OS_WIN32 bool can_GETOSPACE; char* unwrittenBuffer; unsigned int unwritten; //#endif static int dspFd; static bool muted; static unsigned int leftVolume; static unsigned int rightVolume; }; #ifdef Q_WS_QWS // This is for keeping the device open in-between playing files when // the device makes clicks and it starts to drive you insane! :) // Best to have the device not open when not using it though //#define KEEP_DEVICE_OPEN #endif int AudioDevicePrivate::dspFd = 0; bool AudioDevicePrivate::muted = FALSE; unsigned int AudioDevicePrivate::leftVolume = 0; unsigned int AudioDevicePrivate::rightVolume = 0; void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { muted = AudioDevicePrivate::muted; unsigned int volume; #ifdef QT_QWS_DEVFS int mixerHandle = open( "/dev/sound/mixer", O_RDWR ); #else int mixerHandle = open( "/dev/mixer", O_RDWR ); #endif if ( mixerHandle >= 0 ) { if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) perror("ioctl(\"MIXER_READ\")"); close( mixerHandle ); } else perror("open(\"/dev/mixer\")"); leftVolume = ((volume & 0x00FF) << 16) / 101; rightVolume = ((volume & 0xFF00) << 8) / 101; } void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { AudioDevicePrivate::muted = muted; if ( muted ) { AudioDevicePrivate::leftVolume = leftVolume; AudioDevicePrivate::rightVolume = rightVolume; leftVolume = 0; rightVolume = 0; } else { leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); } // Volume can be from 0 to 100 which is 101 distinct values unsigned int rV = (rightVolume * 101) >> 16; # if 0 unsigned int lV = (leftVolume * 101) >> 16; unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); int mixerHandle = 0; #ifdef QT_QWS_DEVFS if ( ( mixerHandle = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { #else if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { #endif if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) perror("ioctl(\"MIXER_WRITE\")"); close( mixerHandle ); } else perror("open(\"/dev/mixer\")"); # else // This is the way this has to be done now I guess, doesn't allow for // independant right and left channel setting, or setting for different outputs Config cfg("qpe"); // qtopia is "Sound" cfg.setGroup("Volume"); // qtopia is "Settings" cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume # endif //#endif // qDebug( "setting volume to: 0x%x", volume ); #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) // Send notification that the volume has changed QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; #endif } AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { // qDebug("creating new audio device"); // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; d = new AudioDevicePrivate; d->frequency = f; d->channels = chs; d->bytesPerSample = bps; // qDebug("%d",bps); int format=0; if( bps == 8) format = AFMT_U8; else if( bps <= 0) format = AFMT_S16_LE; else format = AFMT_S16_LE; // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); int fragments = 0x10000 * 8 + sound_fragment_shift; int capabilities = 0; #ifdef KEEP_DEVICE_OPEN if ( AudioDevicePrivate::dspFd == 0 ) { #endif #ifdef QT_QWS_DEVFS if ( ( d->handle = ::open( "/dev/sound/dsp", O_WRONLY ) ) < 0 ) { #else if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { #endif perror("open(\"/dev/dsp\")"); QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); exit(-1); //harsh? } #ifdef KEEP_DEVICE_OPEN AudioDevicePrivate::dspFd = d->handle; } else { d->handle = AudioDevicePrivate::dspFd; } #endif if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); // qDebug("freq %d", d->frequency); if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) perror("ioctl(\"SNDCTL_DSP_SPEED\")"); // qDebug("channels %d",d->channels); if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { d->channels = ( d->channels == 1 ) ? 2 : d->channels; if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); } // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; d->bufferSize = sound_fragment_bytes; d->unwrittenBuffer = new char[d->bufferSize]; d->unwritten = 0; d->can_GETOSPACE = TRUE; // until we find otherwise //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); } AudioDevice::~AudioDevice() { // qDebug("destryo audiodevice"); // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; # ifndef KEEP_DEVICE_OPEN close( d->handle ); // Now it should be safe to shut the handle # endif delete d->unwrittenBuffer; delete d; // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; } void AudioDevice::volumeChanged( bool muted ) { AudioDevicePrivate::muted = muted; } void AudioDevice::write( char *buffer, unsigned int length ) { int t = ::write( d->handle, buffer, length ); if ( t<0 ) t = 0; if ( t != (int)length) { // qDebug("Ahhh!! memcpys 1"); memcpy(d->unwrittenBuffer,buffer+t,length-t); d->unwritten = length-t; } //#endif } unsigned int AudioDevice::channels() const { return d->channels; } unsigned int AudioDevice::frequency() const { return d->frequency; } unsigned int AudioDevice::bytesPerSample() const { return d->bytesPerSample; } unsigned int AudioDevice::bufferSize() const { return d->bufferSize; } unsigned int AudioDevice::canWrite() const { audio_buf_info info; if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { d->can_GETOSPACE = FALSE; fcntl( d->handle, F_SETFL, O_NONBLOCK ); } if ( d->can_GETOSPACE ) { int t = info.fragments * sound_fragment_bytes; return QMIN(t,(int)bufferSize()); } else { if ( d->unwritten ) { int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); if ( t<0 ) t = 0; if ( (unsigned)t!=d->unwritten ) { memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); d->unwritten -= t; } else { d->unwritten = 0; } } if ( d->unwritten ) return 0; else return d->bufferSize; } } int AudioDevice::bytesWritten() { int buffered = 0; if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { // qDebug( "failed to get audio device position" ); return -1; } return buffered; } diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index fbc5072..8bcc567 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp @@ -1,527 +1,521 @@ /********************************************************************** ** 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 <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/config.h> -#include <qwidget.h> -#include <qpixmap.h> -#include <qbutton.h> -#include <qpainter.h> -#include <qframe.h> -#include <qlayout.h> #include <qdir.h> #include "audiowidget.h" #include "mediaplayerstate.h" #include <stdlib.h> #include <stdio.h> extern MediaPlayerState *mediaPlayerState; static const int xo = -2; // movable x offset static const int yo = 22; // movable y offset struct MediaButton { bool isToggle, isHeld, isDown; }; //Layout information for the audioButtons (and if it is a toggle button or not) MediaButton audioButtons[] = { { TRUE, FALSE, FALSE }, // play { FALSE, FALSE, FALSE }, // stop { FALSE, FALSE, FALSE }, // next { FALSE, FALSE, FALSE }, // previous { FALSE, FALSE, FALSE }, // volume up { FALSE, FALSE, FALSE }, // volume down { TRUE, FALSE, FALSE }, // repeat/loop { FALSE, FALSE, FALSE }, // playlist { FALSE, FALSE, FALSE }, // forward { FALSE, FALSE, FALSE } // back }; const char *skin_mask_file_names[10] = { "play", "stop", "next", "prev", "up", "down", "loop", "playlist", "forward", "back" }; static void changeTextColor( QWidget *w ) { QPalette p = w->palette(); p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); w->setPalette( p ); } static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) { setCaption( tr("OpiePlayer") ); // qDebug("<<<<<audioWidget"); Config cfg("OpiePlayer"); cfg.setGroup("Options"); skin = cfg.readEntry("Skin","default"); //skin = "scaleTest"; // color of background, frame, degree of transparency // QString skinPath = "opieplayer/skins/" + skin; QString skinPath; skinPath = "opieplayer2/skins/" + skin; if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) skinPath = "opieplayer2/skins/default"; // qDebug("skin path " + skinPath); pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); imgButtonMask->fill( 0 ); for ( int i = 0; i < 10; i++ ) { QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; masks[i] = new QBitmap( filename ); if ( !masks[i]->isNull() ) { QImage imgMask = masks[i]->convertToImage(); uchar **dest = imgButtonMask->jumpTable(); for ( int y = 0; y < imgUp->height(); y++ ) { uchar *line = dest[y]; for ( int x = 0; x < imgUp->width(); x++ ) if ( !qRed( imgMask.pixel( x, y ) ) ) line[x] = i + 1; } } } for ( int i = 0; i < 11; i++ ) { buttonPixUp[i] = NULL; buttonPixDown[i] = NULL; } QWidget *d = QApplication::desktop(); int width = d->width(); int height = d->height(); if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { // qDebug("<<<<<<<< scale image >>>>>>>>>>>>"); QImage img; img = pixBg->convertToImage(); pixBg->convertFromImage( img.smoothScale( width, height)); } setBackgroundPixmap( *pixBg); songInfo.setFocusPolicy( QWidget::NoFocus ); // changeTextColor( &songInfo ); // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); // songInfo.setFrameStyle( QFrame::NoFrame); // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); //NoFrame // songInfo.setForegroundColor(Qt::white); slider.setFixedHeight( 20 ); slider.setMinValue( 0 ); slider.setMaxValue( 1 ); slider.setFocusPolicy( QWidget::NoFocus ); slider.setBackgroundPixmap( *pixBg ); time.setFocusPolicy( QWidget::NoFocus ); time.setAlignment( Qt::AlignCenter ); time.setFrame(FALSE); changeTextColor( &time ); resizeEvent( NULL ); connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); // Intialise state setLength( mediaPlayerState->length() ); setPosition( mediaPlayerState->position() ); setLooping( mediaPlayerState->fullscreen() ); // setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState->playing() ); this->setFocus(); } AudioWidget::~AudioWidget() { // setPlaying( false); for ( int i = 0; i < 10; i++ ) { if(buttonPixUp[i]) delete buttonPixUp[i]; if(buttonPixDown[i]) delete buttonPixDown[i]; } if(pixBg) delete pixBg; if(imgUp) delete imgUp; if(imgDn) delete imgDn; if(imgButtonMask) delete imgButtonMask; for ( int i = 0; i < 10; i++ ) { if(masks[i]) delete masks[i]; } } QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { QPixmap pix( img.width(), img.height() ); QPainter p( &pix ); p.drawTiledPixmap( pix.rect(), bg, offset ); p.drawImage( 0, 0, img ); return new QPixmap( pix ); } QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { QPixmap *pixmap = new QPixmap( pix ); pixmap->setMask( mask ); return pixmap; } void AudioWidget::resizeEvent( QResizeEvent * ) { int h = height(); int w = width(); songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); slider.setFixedWidth( w - 110 ); slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); slider.setBackgroundOrigin( QWidget::ParentOrigin ); time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); xoff = ( w - imgUp->width() ) / 2; yoff = (( h - imgUp->height() ) / 2) - 10; QPoint p( xoff, yoff ); QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); for ( int i = 0; i < 10; i++ ) { if ( !masks[i]->isNull() ) { delete buttonPixUp[i]; delete buttonPixDown[i]; buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); } } delete pixUp; delete pixDn; } static bool audioSliderBeingMoved = FALSE; void AudioWidget::sliderPressed() { audioSliderBeingMoved = TRUE; } void AudioWidget::sliderReleased() { audioSliderBeingMoved = FALSE; if ( slider.width() == 0 ) return; long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); mediaPlayerState->setPosition( val ); } void AudioWidget::setPosition( long i ) { // qDebug("set position %d",i); long length = mediaPlayerState->length(); updateSlider( i, length ); } void AudioWidget::setLength( long max ) { updateSlider( mediaPlayerState->position(), max ); } void AudioWidget::setView( char view ) { if (mediaPlayerState->isStreaming) { if( !slider.isHidden()) slider.hide(); disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); } else { // this stops the slider from being moved, thus // does not stop stream when it reaches the end slider.show(); connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); } if ( view == 'a' ) { startTimer( 150 ); // show(); QPEApplication::showWidget( this ); } else { killTimers(); hide(); } } static QString timeAsString( long length ) { length /= 44100; int minutes = length / 60; int seconds = length % 60; return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); } void AudioWidget::updateSlider( long i, long max ) { this->setFocus(); time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); if ( max == 0 ) return; // Will flicker too much if we don't do this // Scale to something reasonable int width = slider.width(); int val = int((double)i * width / max); if ( !audioSliderBeingMoved ) { if ( slider.value() != val ) slider.setValue( val ); if ( slider.maxValue() != width ) slider.setMaxValue( width ); } } void AudioWidget::setToggleButton( int i, bool down ) { if ( down != audioButtons[i].isDown ) toggleButton( i ); } void AudioWidget::toggleButton( int i ) { audioButtons[i].isDown = !audioButtons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void AudioWidget::paintButton( QPainter *p, int i ) { if ( audioButtons[i].isDown ) p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); else p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); } void AudioWidget::timerEvent( QTimerEvent * ) { /* int x = audioButtons[AudioPlay].xPos; int y = audioButtons[AudioPlay].yPos; QPainter p( this ); // Optimize to only draw the little bit of the changing images which is different p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); */ /* static int frame = 0; if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { frame = frame >= 7 ? 0 : frame + 1; } */ } void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { for ( int i = 0; i < numButtons; i++ ) { if ( event->state() == QMouseEvent::LeftButton ) { // The test to see if the mouse click is inside the button or not int x = event->pos().x() - xoff; int y = event->pos().y() - yoff; bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); // if ( isOnButton && i == AudioVolumeUp ) // qDebug("on up"); if ( isOnButton && !audioButtons[i].isHeld ) { audioButtons[i].isHeld = TRUE; toggleButton(i); switch (i) { case AudioVolumeUp: // qDebug("more clicked"); emit moreClicked(); return; case AudioVolumeDown: // qDebug("less clicked"); emit lessClicked(); return; case AudioForward: emit forwardClicked(); return; case AudioBack: emit backClicked(); return; } } else if ( !isOnButton && audioButtons[i].isHeld ) { audioButtons[i].isHeld = FALSE; toggleButton(i); } } else { if ( audioButtons[i].isHeld ) { audioButtons[i].isHeld = FALSE; if ( !audioButtons[i].isToggle ) setToggleButton( i, FALSE ); switch (i) { case AudioPlay: if( mediaPlayerState->isPaused ) { mediaPlayerState->setPaused( FALSE ); return; } else if( !mediaPlayerState->isPaused ) { mediaPlayerState->setPaused( TRUE ); return; } // case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; case AudioStop: mediaPlayerState->setPlaying(FALSE); return; // case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; case AudioNext: mediaPlayerState->setNext(); return; case AudioPrevious: mediaPlayerState->setPrev(); return; case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; case AudioVolumeUp: emit moreReleased(); return; case AudioVolumeDown: emit lessReleased(); return; case AudioPlayList: mediaPlayerState->setList(); return; } } } } } void AudioWidget::mousePressEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::showEvent( QShowEvent* ) { QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); mouseMoveEvent( &event ); } void AudioWidget::closeEvent( QCloseEvent* ) { mediaPlayerState->setList(); } void AudioWidget::paintEvent( QPaintEvent * pe) { if ( !pe->erased() ) { // Combine with background and double buffer QPixmap pix( pe->rect().size() ); QPainter p( &pix ); p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); for ( int i = 0; i < numButtons; i++ ) paintButton( &p, i ); QPainter p2( this ); p2.drawPixmap( pe->rect().topLeft(), pix ); } else { QPainter p( this ); for ( int i = 0; i < numButtons; i++ ) paintButton( &p, i ); } } void AudioWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_Home: break; case Key_F9: //activity hide(); // qDebug("Audio F9"); break; case Key_F10: //contacts break; case Key_F11: //menu break; case Key_F12: //home break; case Key_F13: //mail break; case Key_Space: { if(mediaPlayerState->playing()) { // toggleButton(1); mediaPlayerState->setPlaying(FALSE); // toggleButton(1); } else { // toggleButton(0); mediaPlayerState->setPlaying(TRUE); // toggleButton(0); } } break; case Key_Down: //volume // toggleButton(6); emit lessClicked(); emit lessReleased(); // toggleButton(6); break; case Key_Up: //volume // toggleButton(5); emit moreClicked(); emit moreReleased(); // toggleButton(5); break; case Key_Right: //next in playlist // toggleButton(3); mediaPlayerState->setNext(); // toggleButton(3); break; case Key_Left: // previous in playlist // toggleButton(4); mediaPlayerState->setPrev(); // toggleButton(4); break; case Key_Escape: break; }; } diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp index 753b2e3..b77708c 100644 --- a/core/multimedia/opieplayer/mediaplayer.cpp +++ b/core/multimedia/opieplayer/mediaplayer.cpp @@ -1,278 +1,271 @@ /********************************************************************** ** 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 <qpe/qpeapplication.h> -#include <qpe/qlibrary.h> -#include <qpe/resource.h> -#include <qpe/config.h> -#include <qmainwindow.h> #include <qmessagebox.h> -#include <qwidgetstack.h> -#include <qfile.h> #include "mediaplayer.h" #include "playlistwidget.h" #include "audiowidget.h" #include "loopcontrol.h" #include "audiodevice.h" #include "mediaplayerstate.h" extern AudioWidget *audioUI; extern PlayListWidget *playList; extern LoopControl *loopControl; extern MediaPlayerState *mediaPlayerState; MediaPlayer::MediaPlayer( QObject *parent, const char *name ) : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { // QPEApplication::grabKeyboard(); connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); } MediaPlayer::~MediaPlayer() { } void MediaPlayer::pauseCheck( bool b ) { // Only pause if playing if ( b && !mediaPlayerState->playing() ) mediaPlayerState->setPaused( FALSE ); } void MediaPlayer::play() { mediaPlayerState->setPlaying( FALSE ); mediaPlayerState->setPlaying( TRUE ); } void MediaPlayer::setPlaying( bool play ) { // qDebug("MediaPlayer setPlaying %d", play); if ( !play ) { mediaPlayerState->setPaused( FALSE ); loopControl->stop( FALSE ); return; } if ( mediaPlayerState->paused() ) { mediaPlayerState->setPaused( FALSE ); return; } // qDebug("about to ctrash"); const DocLnk *playListCurrent = playList->current(); if ( playListCurrent != NULL ) { loopControl->stop( TRUE ); currentFile = playListCurrent; } if ( currentFile == NULL ) { QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); mediaPlayerState->setPlaying( FALSE ); return; } if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" ); mediaPlayerState->setPlaying( FALSE ); return; } if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" ); mediaPlayerState->setPlaying( FALSE ); return; } if ( !loopControl->init( currentFile->file() ) ) { QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); mediaPlayerState->setPlaying( FALSE ); return; } long seconds = loopControl->totalPlaytime(); QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); QString tickerText; if( currentFile->file().left(4) == "http" ) tickerText= tr( " File: " ) + currentFile->name(); else tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); if ( !fileInfo.isEmpty() ) tickerText += ", " + fileInfo; audioUI->setTickerText( tickerText + "." ); loopControl->play(); mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); } void MediaPlayer::prev() { if ( playList->prev() ) play(); else if ( mediaPlayerState->looping() ) { if ( playList->last() ) play(); } else mediaPlayerState->setList(); } void MediaPlayer::next() { if ( playList->next() ) play(); else if ( mediaPlayerState->looping() ) { if ( playList->first() ) play(); } else mediaPlayerState->setList(); } void MediaPlayer::startDecreasingVolume() { volumeDirection = -1; startTimer( 100 ); AudioDevice::decreaseVolume(); } void MediaPlayer::startIncreasingVolume() { volumeDirection = +1; startTimer( 100 ); AudioDevice::increaseVolume(); } bool drawnOnScreenDisplay = FALSE; unsigned int onScreenDisplayVolume = 0; const int yoff = 110; void MediaPlayer::stopChangingVolume() { killTimers(); // Get rid of the on-screen display stuff drawnOnScreenDisplay = FALSE; onScreenDisplayVolume = 0; int w = audioUI->width(); int h = audioUI->height(); audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE ); } void MediaPlayer::timerEvent( QTimerEvent * ) { // qDebug("timer"); if ( volumeDirection == +1 ) AudioDevice::increaseVolume(); else if ( volumeDirection == -1 ) AudioDevice::decreaseVolume(); // Display an on-screen display volume unsigned int l, r, v; bool m; AudioDevice::getVolume( l, r, m ); v = ((l + r) * 11) / (2*0xFFFF); if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { // qDebug("returning %d, %d, %d, %d", v, l, r, m); return; } int w = audioUI->width(); int h = audioUI->height(); if ( drawnOnScreenDisplay ) { if ( onScreenDisplayVolume > v ) audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE ); } drawnOnScreenDisplay = TRUE; onScreenDisplayVolume = v; QPainter p( audioUI ); p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); QFont f; f.setPixelSize( 20 ); f.setBold( TRUE ); p.setFont( f ); p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); for ( unsigned int i = 0; i < 10; i++ ) { if ( v > i ) p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); else p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); } } void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_Home: break; case Key_F9: //activity break; case Key_F10: //contacts break; case Key_F11: //menu break; case Key_F12: //home // qDebug("Blank here"); break; case Key_F13: //mail break; } } void MediaPlayer::doBlank() { } void MediaPlayer::doUnblank() { } void MediaPlayer::cleanUp() { // QPEApplication::grabKeyboard(); // QPEApplication::ungrabKeyboard(); } diff --git a/core/multimedia/opieplayer/mediaplayerstate.cpp b/core/multimedia/opieplayer/mediaplayerstate.cpp index 6823076..5bfb87e 100644 --- a/core/multimedia/opieplayer/mediaplayerstate.cpp +++ b/core/multimedia/opieplayer/mediaplayerstate.cpp @@ -1,195 +1,193 @@ /********************************************************************** ** 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 <qpe/qpeapplication.h> #include <qpe/qlibrary.h> #include <qpe/config.h> -#include <qvaluelist.h> -#include <qobject.h> #include <qdir.h> #include <qpe/mediaplayerplugininterface.h> #include "mediaplayerstate.h" #ifdef QT_NO_COMPONENT // Plugins which are compiled in when no plugin architecture available #include "libmad/libmadpluginimpl.h" #include "libmpeg3/libmpeg3pluginimpl.h" #include "wavplugin/wavpluginimpl.h" #endif //#define MediaPlayerDebug(x) qDebug x #define MediaPlayerDebug(x) MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { Config cfg( "OpiePlayer" ); readConfig( cfg ); loadPlugins(); } MediaPlayerState::~MediaPlayerState() { Config cfg( "OpiePlayer" ); writeConfig( cfg ); } void MediaPlayerState::readConfig( Config& cfg ) { cfg.setGroup("Options"); isFullscreen = cfg.readBoolEntry( "FullScreen" ); isScaled = cfg.readBoolEntry( "Scaling" ); isLooping = cfg.readBoolEntry( "Looping" ); isShuffled = cfg.readBoolEntry( "Shuffle" ); usePlaylist = cfg.readBoolEntry( "UsePlayList" ); usePlaylist = TRUE; isPlaying = FALSE; isPaused = FALSE; curPosition = 0; curLength = 0; curView = 'l'; } void MediaPlayerState::writeConfig( Config& cfg ) const { cfg.setGroup("Options"); cfg.writeEntry("FullScreen", isFullscreen ); cfg.writeEntry("Scaling", isScaled ); cfg.writeEntry("Looping", isLooping ); cfg.writeEntry("Shuffle", isShuffled ); cfg.writeEntry("UsePlayList", usePlaylist ); } struct MediaPlayerPlugin { #ifndef QT_NO_COMPONENT QLibrary *library; #endif MediaPlayerPluginInterface *iface; MediaPlayerDecoder *decoder; MediaPlayerEncoder *encoder; }; static QValueList<MediaPlayerPlugin> pluginList; // Find the first decoder which supports this type of file MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { MediaPlayerDecoder *tmpDecoder = NULL; QValueList<MediaPlayerPlugin>::Iterator it; for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { if ( (*it).decoder->isFileSupported( file ) ) { tmpDecoder = (*it).decoder; break; } } if(file.left(4)=="http") isStreaming = TRUE; else isStreaming = FALSE; return decoder = tmpDecoder; } MediaPlayerDecoder *MediaPlayerState::curDecoder() { return decoder; } // ### hack to get true sample count MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { return libmpeg3decoder; } // ### hack to get true sample count // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { // return libwavdecoder; // } void MediaPlayerState::loadPlugins() { // qDebug("load plugins"); #ifndef QT_NO_COMPONENT QValueList<MediaPlayerPlugin>::Iterator mit; for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { (*mit).iface->release(); (*mit).library->unload(); delete (*mit).library; } pluginList.clear(); QString path = QPEApplication::qpeDir() + "/plugins/codecs"; QDir dir( path, "lib*.so" ); QStringList list = dir.entryList(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { MediaPlayerPluginInterface *iface = 0; QLibrary *lib = new QLibrary( path + "/" + *it ); // qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { // qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); MediaPlayerPlugin plugin; plugin.library = lib; plugin.iface = iface; plugin.decoder = plugin.iface->decoder(); plugin.encoder = plugin.iface->encoder(); pluginList.append( plugin ); // ### hack to get true sample count if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) libmpeg3decoder = plugin.decoder; } else { delete lib; } } #else pluginList.clear(); MediaPlayerPlugin plugin0; plugin0.iface = new LibMpeg3PluginImpl; plugin0.decoder = plugin0.iface->decoder(); plugin0.encoder = plugin0.iface->encoder(); pluginList.append( plugin0 ); MediaPlayerPlugin plugin1; plugin1.iface = new LibMadPluginImpl; plugin1.decoder = plugin1.iface->decoder(); plugin1.encoder = plugin1.iface->encoder(); pluginList.append( plugin1 ); MediaPlayerPlugin plugin2; plugin2.iface = new WavPluginImpl; plugin2.decoder = plugin2.iface->decoder(); plugin2.encoder = plugin2.iface->encoder(); pluginList.append( plugin2 ); #endif if ( pluginList.count() ) MediaPlayerDebug(( "%i decoders found", pluginList.count() )); else MediaPlayerDebug(( "No decoders found" )); } diff --git a/core/multimedia/opieplayer/modplug/load_j2b.cpp b/core/multimedia/opieplayer/modplug/load_j2b.cpp index 4f0b85c..8b4cccd 100644 --- a/core/multimedia/opieplayer/modplug/load_j2b.cpp +++ b/core/multimedia/opieplayer/modplug/load_j2b.cpp @@ -1,17 +1,16 @@ /* * This program is free software; you can redistribute it and 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. * * Authors: Olivier Lapicque <olivierl@jps.net> */ /////////////////////////////////////////////////// // // J2B module loader // /////////////////////////////////////////////////// -#include "stdafx.h" diff --git a/core/multimedia/opieplayer/om3u.cpp b/core/multimedia/opieplayer/om3u.cpp index 778eb22..ae89518 100644 --- a/core/multimedia/opieplayer/om3u.cpp +++ b/core/multimedia/opieplayer/om3u.cpp @@ -1,175 +1,162 @@ /* This file is part of the Opie Project Copyright (c) 2002 L. Potter <ljp@llornkcor.com> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "playlistwidget.h" #include "om3u.h" -#include <qpe/applnk.h> -#include <qpe/qpeapplication.h> -#include <qpe/storage.h> -#include <qpe/mimetype.h> -#include <qpe/global.h> -#include <qpe/resource.h> - -#include <qdir.h> -#include <qregexp.h> -#include <qstring.h> -#include <qtextstream.h> -#include <qstringlist.h> -#include <qcstring.h> + static inline QString fullBaseName ( const QFileInfo &fi ) { QString str = fi. fileName ( ); return str. left ( str. findRev ( '.' )); } //extern PlayListWidget *playList; Om3u::Om3u( const QString &filePath, int mode) : QStringList (){ //qDebug("<<<<<<<new m3u "+filePath); f.setName(filePath); f.open(mode); } Om3u::~Om3u(){} void Om3u::readM3u() { // qDebug("<<<<<<reading m3u "+f.name()); QTextStream t(&f); t.setEncoding(QTextStream::UnicodeUTF8); QString s; while ( !t.atEnd() ) { s=t.readLine(); // qDebug(s); if( s.find( "#", 0, TRUE) == -1 ) { if( s.left(2) == "E:" || s.left(2) == "P:" ) { s = s.right( s.length() -2 ); QFileInfo f( s ); QString name = fullBaseName ( f ); name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); s=s.replace( QRegExp( "\\" ), "/" ); append(s); // qDebug(s); } else { // is url s.replace( QRegExp( "%20" )," " ); QString name; // if( name.left( 4 ) == "http" ) { // name = s.right( s.length() - 7 ); // } else { name = s; // } append(name); // qDebug(name); } } } } void Om3u::readPls() { //it's a pls file QTextStream t( &f ); t.setEncoding(QTextStream::UnicodeUTF8); QString s; while ( !t.atEnd() ) { s = t.readLine(); if( s.left(4) == "File" ) { s = s.right( s.length() - 6 ); s.replace( QRegExp( "%20" )," "); // qDebug( "adding " + s + " to playlist" ); // numberofentries=2 // File1=http // Title // Length // Version // File2=http s = s.replace( QRegExp( "\\" ), "/" ); QFileInfo f( s ); QString name = fullBaseName ( f ); if( name.left( 4 ) == "http" ) { name = s.right( s.length() - 7); } else { name = s; } name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); if( s.at( s.length() - 4) == '.') // if this is probably a file append(s); else { //if its a url if( name.right( 1 ).find( '/' ) == -1) { s += "/"; } append(s); } } } } void Om3u::write() { //writes list to m3u file QString list; QTextStream t(&f); t.setEncoding(QTextStream::UnicodeUTF8); if(count()>0) { for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { // qDebug(*it); t << *it << "\n"; } } // f.close(); } void Om3u::add(const QString &filePath) { //adds to m3u file append(filePath); } void Om3u::remove(const QString &filePath) { //removes from m3u list QString list, currentFile; if(count()>0) { for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { currentFile=*it; // qDebug(*it); if( filePath != currentFile) list += currentFile+"\n"; } f.writeBlock( list, list.length() ); } } void Om3u::deleteFile(const QString &filePath) {//deletes m3u file f.close(); f.remove(); } void Om3u::close() { //closes m3u file f.close(); } diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp index 94567f2..ad831cf 100644 --- a/core/multimedia/opieplayer/playlistselection.cpp +++ b/core/multimedia/opieplayer/playlistselection.cpp @@ -1,216 +1,208 @@ /********************************************************************** ** 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 <qpe/applnk.h> -#include <qpe/resource.h> -#include <qpe/config.h> -#include <qpainter.h> -#include <qimage.h> #include <qheader.h> -#include <qlistview.h> -#include <qlist.h> -#include <qpixmap.h> #include "playlistselection.h" #include <stdlib.h> class PlayListSelectionItem : public QListViewItem { public: PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { setText( 0, f->name() ); setPixmap( 0, f->pixmap() ); } ~PlayListSelectionItem() { }; const DocLnk *file() const { return fl; } private: const DocLnk *fl; }; PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) : QListView( parent, name ) { // qDebug("starting playlistselector"); // #ifdef USE_PLAYLIST_BACKGROUND // setStaticBackground( TRUE ); // setBackgroundPixmap( Resource::loadPixmap( "opieplayer/background" ) ); // setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) ); // #endif // addColumn("Title",236); // setAllColumnsShowFocus( TRUE ); addColumn( tr( "Playlist Selection" ) ); header()->hide(); // setSorting( -1, FALSE ); // FIXME } PlayListSelection::~PlayListSelection() { } // #ifdef USE_PLAYLIST_BACKGROUND void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { // qDebug("drawBackground"); p->fillRect( r, QBrush( white ) ); // QImage logo = Resource::loadImage( "launcher/opielogo" ); // if ( !logo.isNull() ) // p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); } // #endif void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { if ( event->state() == QMouseEvent::LeftButton ) { QListViewItem *currentItem = selectedItem(); QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); if ( currentItem && currentItem->itemAbove() == itemUnder ) moveSelectedUp(); else if ( currentItem && currentItem->itemBelow() == itemUnder ) moveSelectedDown(); } } const DocLnk *PlayListSelection::current() { PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); if ( item ) return item->file(); return NULL; } void PlayListSelection::addToSelection( const DocLnk &lnk ) { PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); QListViewItem *current = selectedItem(); if ( current ) item->moveItem( current ); setSelected( item, TRUE ); ensureItemVisible( item); } void PlayListSelection::removeSelected() { QListViewItem *item = selectedItem(); if ( item ) delete item; setSelected( currentItem(), TRUE ); ensureItemVisible( selectedItem() ); } void PlayListSelection::moveSelectedUp() { QListViewItem *item = selectedItem(); if ( item && item->itemAbove() ) item->itemAbove()->moveItem( item ); ensureItemVisible( selectedItem() ); } void PlayListSelection::moveSelectedDown() { QListViewItem *item = selectedItem(); if ( item && item->itemBelow() ) item->moveItem( item->itemBelow() ); ensureItemVisible( selectedItem() ); } bool PlayListSelection::prev() { QListViewItem *item = selectedItem(); if ( item && item->itemAbove() ) setSelected( item->itemAbove(), TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::next() { QListViewItem *item = selectedItem(); if ( item && item->itemBelow() ) setSelected( item->itemBelow(), TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::first() { QListViewItem *item = firstChild(); if ( item ) setSelected( item, TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::last() { QListViewItem *prevItem = NULL; QListViewItem *item = firstChild(); while ( ( item = item->nextSibling() ) ) prevItem = item; if ( prevItem ) setSelected( prevItem, TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } void PlayListSelection::unSelect() { QListViewItem *item = selectedItem(); setSelected( currentItem(), FALSE); } void PlayListSelection::writeCurrent( Config& cfg ) { cfg.setGroup("PlayList"); QListViewItem *item = selectedItem(); if ( item ) cfg.writeEntry("current", item->text(0) ); // qDebug(item->text(0)); } void PlayListSelection::setSelectedItem(const QString &strk ) { unSelect(); QListViewItemIterator it( this ); for ( ; it.current(); ++it ) { // qDebug( it.current()->text(0)); if( strk == it.current()->text(0)) { // qDebug( "We have a match "+strk); setSelected( it.current(), TRUE); ensureItemVisible( it.current() ); return; } } // setSelected( item, TRUE ); // ensureItemVisible( selectedItem() ); } diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index db99866..a359843 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp @@ -1,566 +1,541 @@ /********************************************************************** ** 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. ** **********************************************************************/ // code added by L. J. Potter Sat 03-02-2002 06:17:54 #define QTOPIA_INTERNAL_FSLP -#include <qpe/qcopenvelope_qws.h> -#include <qmenubar.h> #include <qtoolbar.h> #include <qpe/qpemenubar.h> -#include <qpe/fileselector.h> -#include <qpe/qpeapplication.h> #include <qpe/lnkproperties.h> -#include <qpe/storage.h> -#include <qpe/applnk.h> -#include <qpe/config.h> -#include <qpe/global.h> -#include <qpe/resource.h> #include <qaction.h> -#include <qcursor.h> -#include <qimage.h> -#include <qfile.h> -#include <qdir.h> #include <qlayout.h> -#include <qlabel.h> -#include <qlist.h> -#include <qlistbox.h> -#include <qmainwindow.h> #include <qmessagebox.h> -#include <qtoolbutton.h> -#include <qtabwidget.h> -#include <qlistview.h> -#include <qpoint.h> -#include <qlineedit.h> -#include <qpushbutton.h> -#include <qregexp.h> -#include <qtextstream.h> //#include <qtimer.h> #include "playlistselection.h" #include "playlistwidget.h" #include "mediaplayerstate.h" #include "inputDialog.h" #include <stdlib.h> #include "audiowidget.h" #include "videowidget.h" #include <unistd.h> #include <sys/file.h> #include <sys/ioctl.h> #include <sys/soundcard.h> // for setBacklight() #include <linux/fb.h> #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> #define BUTTONS_ON_TOOLBAR #define SIDE_BUTTONS #define CAN_SAVE_LOAD_PLAYLISTS extern AudioWidget *audioUI; extern VideoWidget *videoUI; extern MediaPlayerState *mediaPlayerState; static inline QString fullBaseName ( const QFileInfo &fi ) { QString str = fi. fileName ( ); return str. left ( str. findRev ( '.' )); } QString audioMimes ="audio/mpeg;audio/x-wav;application/ogg;audio/x-mod"; // class myFileSelector { // }; class PlayListWidgetPrivate { public: QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; QFrame *playListFrame; FileSelector *files; PlayListSelection *selectedFiles; bool setDocumentUsed; DocLnk *current; }; class ToolButton : public QToolButton { public: ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) : QToolButton( parent, name ) { setTextLabel( name ); setPixmap( Resource::loadPixmap( icon ) ); setAutoRaise( TRUE ); setFocusPolicy( QWidget::NoFocus ); setToggleButton( t ); connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); QPEMenuToolFocusManager::manager()->addWidget( this ); } }; class MenuItem : public QAction { public: MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) : QAction( text, QString::null, 0, 0 ) { connect( this, SIGNAL( activated() ), handler, slot ); addTo( parent ); } }; PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) { d = new PlayListWidgetPrivate; d->setDocumentUsed = FALSE; d->current = NULL; fromSetDocument = FALSE; insanityBool=FALSE; audioScan = FALSE; videoScan = FALSE; // menuTimer = new QTimer( this ,"menu timer"), // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); channel = new QCopChannel( "QPE/Application/opieplayer", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); setBackgroundMode( PaletteButton ); setCaption( tr("OpiePlayer") ); setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); setToolBarsMovable( FALSE ); // Create Toolbar QToolBar *toolbar = new QToolBar( this ); toolbar->setHorizontalStretchable( TRUE ); // Create Menubar QMenuBar *menu = new QMenuBar( toolbar ); menu->setMargin( 0 ); QToolBar *bar = new QToolBar( this ); bar->setLabel( tr( "Play Operations" ) ); // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", // this , SLOT( addSelected()) ); tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); tbDeletePlaylist->setFlat(TRUE); tbDeletePlaylist->setFixedSize(20,20); d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", this , SLOT(addSelected()) ); d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", this , SLOT(removeSelected()) ); // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", this , SLOT( btnPlay(bool) ), TRUE ); d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", mediaPlayerState, SLOT(setLooping(bool)), TRUE ); tbDeletePlaylist->hide(); QPopupMenu *pmPlayList = new QPopupMenu( this ); menu->insertItem( tr( "File" ), pmPlayList ); new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); pmPlayList->insertSeparator(-1); new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); pmPlayList->insertSeparator(-1); new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); QPopupMenu *pmView = new QPopupMenu( this ); menu->insertItem( tr( "View" ), pmView ); fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); fullScreenButton->addTo(pmView); scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); scaleButton->addTo(pmView); skinsMenu = new QPopupMenu( this ); menu->insertItem( tr( "Skins" ), skinsMenu ); skinsMenu->isCheckable(); connect( skinsMenu, SIGNAL( activated( int ) ) , this, SLOT( skinsMenuActivated( int ) ) ); populateSkinsMenu(); QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); tabWidget = new QTabWidget( hbox6, "tabWidget" ); // tabWidget->setTabShape(QTabWidget::Triangular); QWidget *pTab; pTab = new QWidget( tabWidget, "pTab" ); // playlistView = new QListView( pTab, "playlistview" ); // playlistView->setMinimumSize(236,260); tabWidget->insertTab( pTab,"Playlist"); // Add the playlist area QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); d->playListFrame = vbox3; QGridLayout *layoutF = new QGridLayout( pTab ); layoutF->setSpacing( 2); layoutF->setMargin( 2); layoutF->addMultiCellWidget( d->playListFrame , 0, 0, 0, 1 ); QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); d->selectedFiles = new PlayListSelection( hbox2); QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch QWidget *aTab; aTab = new QWidget( tabWidget, "aTab" ); audioView = new QListView( aTab, "Audioview" ); QGridLayout *layoutA = new QGridLayout( aTab ); layoutA->setSpacing( 2); layoutA->setMargin( 2); layoutA->addMultiCellWidget( audioView, 0, 0, 0, 1 ); audioView->addColumn( tr("Title"),-1); audioView->addColumn(tr("Size"), -1); audioView->addColumn(tr("Media"),-1); audioView->addColumn( tr( "Path" ), -1 ); audioView->setColumnAlignment(1, Qt::AlignRight); audioView->setColumnAlignment(2, Qt::AlignRight); audioView->setAllColumnsShowFocus(TRUE); audioView->setMultiSelection( TRUE ); audioView->setSelectionMode( QListView::Extended); audioView->setSorting( 3, TRUE ); tabWidget->insertTab(aTab,tr("Audio")); QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); // audioView // populateAudioView(); // videowidget QWidget *vTab; vTab = new QWidget( tabWidget, "vTab" ); videoView = new QListView( vTab, "Videoview" ); QGridLayout *layoutV = new QGridLayout( vTab ); layoutV->setSpacing( 2); layoutV->setMargin( 2); layoutV->addMultiCellWidget( videoView, 0, 0, 0, 1 ); videoView->addColumn(tr("Title"),-1); videoView->addColumn(tr("Size"),-1); videoView->addColumn(tr("Media"),-1); videoView->addColumn(tr( "Path" ), -1 ); videoView->setColumnAlignment(1, Qt::AlignRight); videoView->setColumnAlignment(2, Qt::AlignRight); videoView->setAllColumnsShowFocus(TRUE); videoView->setMultiSelection( TRUE ); videoView->setSelectionMode( QListView::Extended); QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); tabWidget->insertTab( vTab,tr("Video")); QWidget *LTab; LTab = new QWidget( tabWidget, "LTab" ); playLists = new FileSelector( "playlist/plain;audio/x-mpegurl", LTab, "fileselector" , FALSE, FALSE); QGridLayout *layoutL = new QGridLayout( LTab ); layoutL->setSpacing( 2); layoutL->setMargin( 2); layoutL->addMultiCellWidget( playLists, 0, 0, 0, 1 ); tabWidget->insertTab(LTab,tr("Lists")); connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); ///audioView connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); connect( audioView, SIGNAL( returnPressed( QListViewItem *)), this,SLOT( playIt( QListViewItem *)) ); connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); //videoView connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); connect( videoView, SIGNAL( returnPressed( QListViewItem *)), this,SLOT( playIt( QListViewItem *)) ); connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); //playlists connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); setCentralWidget( vbox5 ); Config cfg( "OpiePlayer" ); readConfig( cfg ); currentPlayList = cfg.readEntry("CurrentPlaylist","default"); loadList(DocLnk( currentPlayList)); setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlayList))); initializeStates(); } PlayListWidget::~PlayListWidget() { Config cfg( "OpiePlayer" ); writeConfig( cfg ); if ( d->current ) delete d->current; if(d) delete d; } void PlayListWidget::initializeStates() { d->tbPlay->setOn( mediaPlayerState->playing() ); d->tbLoop->setOn( mediaPlayerState->looping() ); d->tbShuffle->setOn( mediaPlayerState->shuffled() ); setPlaylist( true); } void PlayListWidget::readConfig( Config& cfg ) { cfg.setGroup("PlayList"); QString currentString = cfg.readEntry("current", "" ); int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); for ( int i = 0; i < noOfFiles; i++ ) { QString entryName; entryName.sprintf( "File%i", i + 1 ); QString linkFile = cfg.readEntry( entryName ); DocLnk lnk( linkFile ); if ( lnk.isValid() ) { d->selectedFiles->addToSelection( lnk ); } } d->selectedFiles->setSelectedItem( currentString); } void PlayListWidget::writeConfig( Config& cfg ) const { d->selectedFiles->writeCurrent( cfg); cfg.setGroup("PlayList"); int noOfFiles = 0; d->selectedFiles->first(); do { const DocLnk *lnk = d->selectedFiles->current(); if ( lnk ) { QString entryName; entryName.sprintf( "File%i", noOfFiles + 1 ); // qDebug(entryName); cfg.writeEntry( entryName, lnk->linkFile() ); // if this link does exist, add it so we have the file // next time... if ( !QFile::exists( lnk->linkFile() ) ) { // the way writing lnks doesn't really check for out // of disk space, but check it anyway. // if ( !lnk->writeLink() ) { // QMessageBox::critical( 0, tr("Out of space"), // tr( "There was a problem saving " // "the playlist.\n" // "Your playlist " // "may be missing some entries\n" // "the next time you start it." ) // ); // } } noOfFiles++; } } while ( d->selectedFiles->next() ); cfg.writeEntry("NumberOfFiles", noOfFiles ); } void PlayListWidget::addToSelection( const DocLnk& lnk ) { d->setDocumentUsed = false; if ( mediaPlayerState->playlist() ) { if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) d->selectedFiles->addToSelection( lnk ); } else mediaPlayerState->setPlaying( true); } void PlayListWidget::clearList() { while ( first() ) d->selectedFiles->removeSelected(); Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); cfg.writeEntry("CurrentPlaylist",""); currentPlayList=""; } void PlayListWidget::addAllToList() { DocLnkSet filesAll; Global::findDocuments(&filesAll, "video/*;audio/*"); QListIterator<DocLnk> Adit( filesAll.children() ); for ( ; Adit.current(); ++Adit ) if(QFileInfo(Adit.current()->file()).exists()) d->selectedFiles->addToSelection( **Adit ); tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::addAllMusicToList() { QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) if(QFileInfo(dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::addAllVideoToList() { QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) if(QFileInfo( dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::setDocument(const QString& fileref) { fromSetDocument = true; d->setDocumentUsed = TRUE; setDocumentEx(fileref); } void PlayListWidget::setDocumentEx(const QString& fileref) { qDebug("opieplayer receive "+fileref); clearList(); DocLnk lnk; QFileInfo fileInfo(fileref); if ( !fileInfo.exists() ) { QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); return; } // qDebug("<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref); QString extension = fileInfo.extension(false); if( extension.find( "m3u", 0, false) != -1) { //is m3u readm3u( fileref); } else if( extension.find( "pls", 0, false) != -1 ) { //is pls readPls( fileref); } else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist clearList(); lnk.setName( fileInfo.baseName() ); //sets name lnk.setFile( fileref ); //sets file name lnk.setIcon("Sound"); //addToSelection( lnk ); loadList( lnk); d->selectedFiles->first(); } else { if( fileref.find(".desktop",0,TRUE) != -1) { lnk = DocLnk(fileref); } else { lnk.setName( fileInfo.baseName() ); //sets name lnk.setFile( fileref ); //sets file name lnk.setIcon("Sound"); } addToSelection( lnk ); // addToSelection( DocLnk( fileref ) ); lnk.removeLinkFile(); // qApp->processEvents(); } setCaption(tr("OpiePlayer")); d->setDocumentUsed = TRUE; d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true ); mediaPlayerState->setPlaying( FALSE ); qApp->processEvents(); mediaPlayerState->setPlaying( TRUE ); } void PlayListWidget::setActiveWindow() { // qDebug("SETTING active window"); // When we get raised we need to ensure that it switches views char origView = mediaPlayerState->view(); mediaPlayerState->setView( 'l' ); // invalidate mediaPlayerState->setView( origView ); // now switch back diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index 5273ad3..d002c42 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp @@ -1,542 +1,538 @@ /********************************************************************** ** 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 <qpe/resource.h> #include <qpe/mediaplayerplugininterface.h> #include <qpe/config.h> #include <qpe/qpeapplication.h> #include <qdir.h> -#include <qwidget.h> -#include <qpainter.h> -#include <qpixmap.h> #include <qslider.h> -#include <qdrawutil.h> #include "videowidget.h" #include "mediaplayerstate.h" #ifdef Q_WS_QWS # define USE_DIRECT_PAINTER # include <qdirectpainter_qws.h> # include <qgfxraster_qws.h> #endif extern MediaPlayerState *mediaPlayerState; static const int xo = 2; // movable x offset static const int yo = 0; // movable y offset struct MediaButton { // int xPos, yPos; bool isToggle, isHeld, isDown; // int controlType; }; // Layout information for the videoButtons (and if it is a toggle button or not) MediaButton videoButtons[] = { { FALSE, FALSE, FALSE }, // stop { FALSE, FALSE, FALSE }, // play { FALSE, FALSE, FALSE }, // previous { FALSE, FALSE, FALSE }, // next { FALSE, FALSE, FALSE }, // volUp { FALSE, FALSE, FALSE }, // volDown { TRUE, FALSE, FALSE } // fullscreen }; //static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); const char *skinV_mask_file_names[7] = { "stop","play","back","fwd","up","down","full" }; static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { setCaption( tr("OpiePlayer") ); Config cfg("OpiePlayer"); cfg.setGroup("Options"); skin = cfg.readEntry("Skin","default"); QString skinPath; skinPath = "opieplayer2/skins/" + skin; if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) skinPath = "opieplayer2/skins/default"; // qDebug("skin path " + skinPath); // QString skinPath = "opieplayer2/skins/" + skin; pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); imgButtonMask->fill( 0 ); for ( int i = 0; i < 7; i++ ) { QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); // qDebug("loading "+filename); masks[i] = new QBitmap( filename ); if ( !masks[i]->isNull() ) { QImage imgMask = masks[i]->convertToImage(); uchar **dest = imgButtonMask->jumpTable(); for ( int y = 0; y < imgUp->height(); y++ ) { uchar *line = dest[y]; for ( int x = 0; x < imgUp->width(); x++ ) { if ( !qRed( imgMask.pixel( x, y ) ) ) line[x] = i + 1; } } } } // qDebug("finished loading first pics"); for ( int i = 0; i < 7; i++ ) { buttonPixUp[i] = NULL; buttonPixDown[i] = NULL; } QWidget *d = QApplication::desktop(); int width = d->width(); int height = d->height(); if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { // qDebug("<<<<<<<< scale image >>>>>>>>>>>>"); QImage img; img = pixBg->convertToImage(); pixBg->convertFromImage( img.smoothScale( width, height)); } setBackgroundPixmap( *pixBg ); currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); slider = new QSlider( Qt::Horizontal, this ); slider->setMinValue( 0 ); slider->setMaxValue( 1 ); slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); slider->setFocusPolicy( QWidget::NoFocus ); // slider->setGeometry( QRect( 7, 250, 220, 20 ) ); connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); // Intialise state setLength( mediaPlayerState->length() ); setPosition( mediaPlayerState->position() ); setFullscreen( mediaPlayerState->fullscreen() ); // setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState->playing() ); } VideoWidget::~VideoWidget() { for ( int i = 0; i < 7; i++ ) { delete buttonPixUp[i]; delete buttonPixDown[i]; } delete pixBg; delete imgUp; delete imgDn; delete imgButtonMask; for ( int i = 0; i < 7; i++ ) { delete masks[i]; } // for ( int i = 0; i < 3; i++ ) // delete pixmaps[i]; // delete currentFrame; } static bool videoSliderBeingMoved = FALSE; QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { QPixmap pix( img.width(), img.height() ); QPainter p( &pix ); p.drawTiledPixmap( pix.rect(), bg, offset ); p.drawImage( 0, 0, img ); return new QPixmap( pix ); } QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { QPixmap *pixmap = new QPixmap( pix ); pixmap->setMask( mask ); return pixmap; } void VideoWidget::resizeEvent( QResizeEvent * ) { int h = height(); int w = width(); //int Vh = 160; //int Vw = 220; slider->setFixedWidth( w - 20 ); slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); slider->setBackgroundOrigin( QWidget::ParentOrigin ); slider->setFocusPolicy( QWidget::NoFocus ); slider->setBackgroundPixmap( *pixBg ); xoff = 0;// ( imgUp->width() ) / 2; if(w>h) yoff = 0; else yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; QPoint p( xoff, yoff ); QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); for ( int i = 0; i < 7; i++ ) { if ( !masks[i]->isNull() ) { delete buttonPixUp[i]; delete buttonPixDown[i]; buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); } } delete pixUp; delete pixDn; } void VideoWidget::sliderPressed() { videoSliderBeingMoved = TRUE; } void VideoWidget::sliderReleased() { videoSliderBeingMoved = FALSE; if ( slider->width() == 0 ) return; long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); mediaPlayerState->setPosition( val ); } void VideoWidget::setPosition( long i ) { updateSlider( i, mediaPlayerState->length() ); } void VideoWidget::setLength( long max ) { updateSlider( mediaPlayerState->position(), max ); } void VideoWidget::setView( char view ) { if ( view == 'v' ) { makeVisible(); } else { // Effectively blank the view next time we show it so it looks nicer scaledWidth = 0; scaledHeight = 0; hide(); } } void VideoWidget::updateSlider( long i, long max ) { // Will flicker too much if we don't do this if ( max == 0 ) return; int width = slider->width(); int val = int((double)i * width / max); if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { if ( slider->value() != val ) slider->setValue( val ); if ( slider->maxValue() != width ) slider->setMaxValue( width ); } } void VideoWidget::setToggleButton( int i, bool down ) { if ( down != videoButtons[i].isDown ) toggleButton( i ); } void VideoWidget::toggleButton( int i ) { videoButtons[i].isDown = !videoButtons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void VideoWidget::paintButton( QPainter *p, int i ) { if ( videoButtons[i].isDown ) { p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); } else { p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); } } void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { for ( int i = 0; i < numVButtons; i++ ) { if ( event->state() == QMouseEvent::LeftButton ) { // The test to see if the mouse click is inside the button or not int x = event->pos().x() - xoff; int y = event->pos().y() - yoff; bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); if ( isOnButton && !videoButtons[i].isHeld ) { videoButtons[i].isHeld = TRUE; toggleButton(i); switch (i) { case VideoVolUp: emit moreClicked(); return; case VideoVolDown: emit lessClicked(); return; } } else if ( !isOnButton && videoButtons[i].isHeld ) { videoButtons[i].isHeld = FALSE; toggleButton(i); } } else { if ( videoButtons[i].isHeld ) { videoButtons[i].isHeld = FALSE; if ( !videoButtons[i].isToggle ) { setToggleButton( i, FALSE ); } switch(i) { case VideoPlay: { // qDebug("play"); if( !mediaPlayerState->playing()) { mediaPlayerState->setPlaying( true); setToggleButton( i-1, false ); setToggleButton( i, false ); return; } if( mediaPlayerState->isPaused ) { // qDebug("isPaused"); setToggleButton( i, FALSE ); mediaPlayerState->setPaused( FALSE ); return; } else if( !mediaPlayerState->isPaused ) { // qDebug("is not paused"); setToggleButton( i, TRUE ); mediaPlayerState->setPaused( TRUE ); return; } else { return; } } case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; case VideoNext: mediaPlayerState->setNext(); return; case VideoPrevious: mediaPlayerState->setPrev(); return; case VideoVolUp: emit moreReleased(); return; case VideoVolDown: emit lessReleased(); return; case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; } } } } } void VideoWidget::mousePressEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { if ( mediaPlayerState->fullscreen() ) { mediaPlayerState->setFullscreen( FALSE ); makeVisible(); } mouseMoveEvent( event ); // } } void VideoWidget::makeVisible() { if ( mediaPlayerState->fullscreen() ) { setBackgroundMode( QWidget::NoBackground ); showFullScreen(); resize( qApp->desktop()->size() ); slider->hide(); } else { setBackgroundPixmap( *pixBg ); showNormal(); QPEApplication::showWidget( this ); slider->show(); } } void VideoWidget::paintEvent( QPaintEvent * pe) { QPainter p( this ); if ( mediaPlayerState->fullscreen() ) { // Clear the background p.setBrush( QBrush( Qt::black ) ); p.drawRect( rect() ); } else { if ( !pe->erased() ) { // Combine with background and double buffer QPixmap pix( pe->rect().size() ); QPainter p( &pix ); p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); for ( int i = 0; i < numVButtons; i++ ) { paintButton( &p, i ); } QPainter p2( this ); p2.drawPixmap( pe->rect().topLeft(), pix ); } else { QPainter p( this ); for ( int i = 0; i < numVButtons; i++ ) paintButton( &p, i ); } slider->repaint( TRUE ); } } void VideoWidget::closeEvent( QCloseEvent* ) { mediaPlayerState->setList(); } bool VideoWidget::playVideo() { bool result = FALSE; // qDebug("<<<<<<<<<<<<<<<< play video"); int stream = 0; int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); int dd = QPixmap::defaultDepth(); int w = height(); int h = width(); ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; if ( mediaPlayerState->fullscreen() ) { #ifdef USE_DIRECT_PAINTER QDirectPainter p(this); if ( ( qt_screen->transformOrientation() == 3 ) && ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { w = 320; h = 240; if ( mediaPlayerState->scaled() ) { // maintain aspect ratio if ( w * sh > sw * h ) w = sw * h / sh; else h = sh * w / sw; } else { w = sw; h = sh; } w--; // we can't allow libmpeg to overwrite. QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); int ox = roff.x() - height() + 2 + (height() - w) / 2; int oy = roff.y() + (width() - h) / 2; int sx = 0, sy = 0; uchar* fp = p.frameBuffer() + p.lineStep() * oy; fp += dd * ox / 8; uchar **jt = new uchar*[h]; for ( int i = h; i; i-- ) { jt[h - i] = fp; fp += p.lineStep(); } result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; delete [] jt; } else { #endif QPainter p(this); w = 320; h = 240; if ( mediaPlayerState->scaled() ) { // maintain aspect ratio if ( w * sh > sw * h ) w = sw * h / sh; else h = sh * w / sw; } else { w = sw; h = sh; diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp index 330fac5..3037ba3 100644 --- a/core/opie-login/loginwindowimpl.cpp +++ b/core/opie-login/loginwindowimpl.cpp @@ -1,254 +1,250 @@ /* =. This file is part of the OPIE Project .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qpe/version.h> -#include <qapplication.h> #include <qpushbutton.h> #include <qlayout.h> -#include <qframe.h> #include <qlineedit.h> #include <qtimer.h> #include <qcombobox.h> -#include <qpixmap.h> #include <qlabel.h> #include <qpopupmenu.h> #include <qmessagebox.h> -#include <qimage.h> #if QT_VERSION < 300 #include <qgfx_qws.h> #endif #include <qwindowsystem_qws.h> #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/config.h> #include <opie/odevice.h> #include <stdio.h> #include <stdlib.h> #include "loginwindowimpl.h" #include "loginapplication.h" #include "inputmethods.h" using namespace Opie; LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) { QPopupMenu *pop = new QPopupMenu ( this ); pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); pop-> insertItem ( tr( "Quit" ), this, SLOT( quit ( ))); m_menu-> setPopup ( pop ); QCopChannel *channel = new QCopChannel ( "QPE/TaskBar", this ); connect ( channel, SIGNAL( received ( const QCString &, const QByteArray & )), this, SLOT( receive ( const QCString &, const QByteArray & ))); QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); m_input = new InputMethods ( m_taskbar ); connect ( m_input, SIGNAL( inputToggled ( bool )), this, SLOT( calcMaxWindowRect ( ))); lay-> addWidget ( m_input ); lay-> addStretch ( 10 ); setActiveWindow ( ); m_password-> setFocus ( ); m_user-> insertStringList ( lApp-> allUsers ( )); //there is no point in displaying the IM for a zaurus if (ODevice::inst ( )-> series ( ) != Model_Zaurus){ QTimer::singleShot ( 0, this, SLOT( showIM ( ))); } QString opiedir = ::getenv ( "OPIEDIR" ); QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); if ( !bgpix. isNull ( )) { setBackgroundPixmap ( bgpix ); m_caption-> setBackgroundPixmap ( bgpix); TextLabel1-> setBackgroundPixmap ( bgpix); TextLabel2-> setBackgroundPixmap ( bgpix); } m_caption-> setText ( tr("<center>Welcome to OPIE %1</center><center>& %2 %3</center>"). arg(QPE_VERSION). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); Config cfg ( "opie-login" ); cfg. setGroup ( "General" ); QString last = cfg. readEntry ( "LastLogin" ); if ( !last. isEmpty ( )) m_user-> setEditText ( last ); calcMaxWindowRect ( ); } LoginWindowImpl::~LoginWindowImpl ( ) { } void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data ) { QDataStream stream ( data, IO_ReadOnly ); if ( msg == "hideInputMethod()" ) m_input-> hideInputMethod ( ); else if ( msg == "showInputMethod()" ) m_input-> showInputMethod ( ); else if ( msg == "reloadInputMethods()" ) m_input-> loadInputMethods ( ); } void LoginWindowImpl::calcMaxWindowRect ( ) { #ifdef Q_WS_QWS QRect wr; int displayWidth = qApp-> desktop ( )-> width ( ); QRect ir = m_input-> inputRect ( ); if ( ir.isValid() ) wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); else wr.setCoords( 0, 0, displayWidth-1, m_taskbar->y()-1 ); #if QT_VERSION < 300 wr = qt_screen-> mapToDevice ( wr, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); #endif QWSServer::setMaxWindowRect( wr ); #endif } void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) { switch ( e-> key ( )) { case HardKey_Suspend: suspend ( ); break; case HardKey_Backlight: backlight ( ); break; default: e-> ignore ( ); break; } LoginWindow::keyPressEvent ( e ); } void LoginWindowImpl::toggleEchoMode ( bool t ) { m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); } void LoginWindowImpl::showIM ( ) { m_input-> showInputMethod ( ); } void LoginWindowImpl::restart ( ) { qApp-> quit ( ); } void LoginWindowImpl::quit ( ) { lApp-> quitToConsole ( ); } void LoginWindowImpl::suspend ( ) { ODevice::inst ( )-> suspend ( ); QCopEnvelope e("QPE/System", "setBacklight(int)"); e << -3; // Force on } void LoginWindowImpl::backlight ( ) { QCopEnvelope e("QPE/System", "setBacklight(int)"); e << -2; // toggle } class WaitLogo : public QLabel { public: WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool ) { QImage img = Resource::loadImage ( "launcher/new_wait" ); QPixmap pix; pix. convertFromImage ( img ); setPixmap ( pix ); setAlignment ( AlignCenter ); move ( 0, 0 ); resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( )); m_visible = false; show ( ); } virtual void showEvent ( QShowEvent *e ) { QLabel::showEvent ( e ); m_visible = true; } virtual void paintEvent ( QPaintEvent *e ) { QLabel::paintEvent ( e ); if ( m_visible ) qApp-> quit ( ); } private: bool m_visible; }; void LoginWindowImpl::login ( ) { const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); if ( !user || !user [0] ) return; if ( !pass ) pass = ""; if ( lApp-> checkPassword ( user, pass )) { Config cfg ( "opie-login" ); cfg. setGroup ( "General" ); cfg. writeEntry ( "LastLogin", user ); cfg. write ( ); lApp-> setLoginAs ( user ); // Draw a big wait icon, the image can be altered in later revisions m_input-> hideInputMethod ( ); new WaitLogo ( ); // WaitLogo::showEvent() calls qApp-> quit() } else { QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); m_password-> clear ( ); } } diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 7d2ed63..bf98735 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp @@ -1,386 +1,382 @@ /* =. This file is part of the OPIE Project .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define _GNU_SOURCE #include <sys/types.h> #include <time.h> #include <sys/time.h> #include <sys/resource.h> #include <unistd.h> #include <syslog.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <getopt.h> #include <string.h> -#include <qpe/qpeapplication.h> -#include <qpe/qcopenvelope_qws.h> #include <qpe/qpestyle.h> #include <qpe/power.h> #include <qpe/config.h> #include <opie/odevice.h> #include <qwindowsystem_qws.h> -#include <qwsmouse_qws.h> #include <qmessagebox.h> #include <qlabel.h> #include <qtimer.h> #include <qfile.h> -#include <qtextstream.h> #include "loginapplication.h" #include "loginwindowimpl.h" #include "calibrate.h" using namespace Opie; int login_main ( int argc, char **argv, pid_t ppid ); void sigterm ( int sig ); void sigint ( int sig ); void exit_closelog ( ); static struct option long_options [] = { { "autologin", 1, 0, 'a' }, { 0, 0, 0, 0 } }; int main ( int argc, char **argv ) { int userExited = 0; pid_t ppid = ::getpid ( ); if ( ::geteuid ( ) != 0 ) { ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); return 1; } if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and ::setuid ( 0 ); // messes up things like config files char *autolog = 0; int c; while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { switch ( c ) { case 'a': autolog = optarg; break; default: ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); return 2; } } // struct rlimit rl; // ::getrlimit ( RLIMIT_NOFILE, &rl ); // for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) // ::close ( i ); ::setpgid ( 0, 0 ); ::setsid ( ); ::signal ( SIGTERM, sigterm ); ::signal ( SIGINT, sigterm ); ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); ::atexit ( exit_closelog ); while ( true ) { pid_t child = ::fork ( ); if ( child < 0 ) { ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); break; } else if ( child > 0 ) { int status = 0; time_t started = ::time ( 0 ); while ( ::waitpid ( child, &status, 0 ) < 0 ) { } LoginApplication::logout ( ); if (( ::time ( 0 ) - started ) < 3 ) { if ( autolog ) { ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); autolog = 0; } else { ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); break; } } int killedbysig = 0; userExited=0; if (WIFEXITED(status)!=0 ) { if (WEXITSTATUS(status)==137) { userExited=1; } } if ( WIFSIGNALED( status )) { switch ( WTERMSIG( status )) { case SIGTERM: case SIGINT : case SIGKILL: break; default : killedbysig = WTERMSIG( status ); break; } } if ( killedbysig ) { // qpe was killed by an uncaught signal qApp = 0; ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); QWSServer::setDesktopBackground ( QImage ( )); QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); app-> setFont ( QFont ( "Helvetica", 10 )); app-> setStyle ( new QPEStyle ( )); const char *sig = ::strsignal ( killedbysig ); QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); l-> setAlignment ( Qt::AlignCenter ); l-> move ( 0, 0 ); l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); l-> show ( ); QTimer::singleShot ( 3000, app, SLOT( quit ( ))); app-> exec ( ); delete app; qApp = 0; } } else { if ( !autolog ) { QString confFile=QPEApplication::qpeDir() + "/etc/opie-login.conf"; Config cfg ( confFile, Config::File ); cfg. setGroup ( "General" ); QString user = cfg. readEntry ( "AutoLogin" ); if ( !user. isEmpty ( )) autolog = ::strdup ( user. latin1 ( )); } if ( autolog && !userExited ) { QWSServer::setDesktopBackground( QImage() ); ODevice::inst ( )-> setDisplayStatus ( true ); ODevice::inst ( )-> setSoftSuspend ( false ); LoginApplication *app = new LoginApplication ( argc, argv, ppid ); LoginApplication::setLoginAs ( autolog ); if ( LoginApplication::changeIdentity ( )) ::exit ( LoginApplication::login ( )); else ::exit ( 0 ); } else { ::exit ( login_main ( argc, argv, ppid )); } } } return 0; } void sigterm ( int /*sig*/ ) { ::exit ( 0 ); } void exit_closelog ( ) { ::closelog ( ); } class LoginScreenSaver : public QWSScreenSaver { public: LoginScreenSaver ( ) { m_lcd_status = true; m_backlight_bright = -1; m_backlight_forcedoff = false; // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) ODevice::inst ( )-> setDisplayStatus ( true ); } void restore() { if ( !m_lcd_status ) // We must have turned it off ODevice::inst ( ) -> setDisplayStatus ( true ); setBacklight ( -3 ); } bool save( int level ) { switch ( level ) { case 0: if ( backlight() > 1 ) setBacklight( 1 ); // lowest non-off return true; break; case 1: setBacklight( 0 ); // off return true; break; case 2: // We're going to suspend the whole machine if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); return true; } break; } return false; } private: public: void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) { int v [4]; v [ 0 ] = QMAX( 1000 * i1, 100 ); v [ 1 ] = QMAX( 1000 * i2, 100 ); v [ 2 ] = QMAX( 1000 * i3, 100 ); v [ 3 ] = 0; if ( !i1 && !i2 && !i3 ) QWSServer::setScreenSaverInterval ( 0 ); else QWSServer::setScreenSaverIntervals ( v ); } int backlight ( ) { if ( m_backlight_bright == -1 ) m_backlight_bright = 255; return m_backlight_bright; } void setBacklight ( int bright ) { if ( bright == -3 ) { // Forced on m_backlight_forcedoff = false; bright = -1; } if ( m_backlight_forcedoff && bright != -2 ) return ; if ( bright == -2 ) { // Toggle between off and on bright = m_backlight_bright ? 0 : -1; m_backlight_forcedoff = !bright; } m_backlight_bright = bright; bright = backlight ( ); ODevice::inst ( ) -> setDisplayBrightness ( bright ); m_backlight_bright = bright; } private: bool m_lcd_status; int m_backlight_bright; bool m_backlight_forcedoff; }; namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting int login_main ( int argc, char **argv, pid_t ppid ) { QWSServer::setDesktopBackground( QImage() ); LoginApplication *app = new LoginApplication ( argc, argv, ppid ); Opie::force_appearance = 0; app-> setFont ( QFont ( "Helvetica", 10 )); app-> setStyle ( new QPEStyle ( )); ODevice::inst ( )-> setSoftSuspend ( true ); if ( QWSServer::mouseHandler() && QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { if ( !QFile::exists ( "/etc/pointercal" )) { // Make sure calibration widget starts on top. Calibrate *cal = new Calibrate; cal-> exec ( ); delete cal; } } LoginScreenSaver *saver = new LoginScreenSaver; saver-> setIntervals ( ); QWSServer::setScreenSaver ( saver ); saver-> restore ( ); LoginWindowImpl *lw = new LoginWindowImpl ( ); app-> setMainWidget ( lw ); lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); lw-> show ( ); int rc = app-> exec ( ); ODevice::inst ( )-> setSoftSuspend ( false ); if ( app-> loginAs ( )) { if ( app-> changeIdentity ( )) { app-> login ( ); // if login succeeds, it never comes back QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); rc = 1; } else { QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); rc = 2; } } return rc; } diff --git a/core/opie-login/opie-login.pro b/core/opie-login/opie-login.pro index f9dbe2b..0fdd8e1 100644 --- a/core/opie-login/opie-login.pro +++ b/core/opie-login/opie-login.pro @@ -1,28 +1,28 @@ TEMPLATE = app -CONFIG = qt warn_on debug usepam +CONFIG = qt warn_on debug HEADERS = loginwindowimpl.h \ loginapplication.h \ ../launcher/inputmethods.h \ ../apps/calibrate/calibrate.h SOURCES = loginwindowimpl.cpp \ loginapplication.cpp \ ../launcher/inputmethods.cpp \ ../apps/calibrate/calibrate.cpp \ main.cpp INTERFACES = loginwindow.ui INCLUDEPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate DEPENDPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate LIBS += -lqpe -lopie usepam:LIBS += -lpam usepam:DEFINES += USEPAM DESTDIR = $(OPIEDIR)/bin TARGET = opie-login include ( $(OPIEDIR)/include.pro ) |