-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 16 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 33 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 24 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol_threaded.cpp | 578 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayer.cpp | 6 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayerstate.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/om3u.cpp | 60 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistselection.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 1300 | ||||
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 16 |
10 files changed, 1006 insertions, 1031 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 73e41dc..d01d2ba 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp @@ -1,313 +1,313 @@ /********************************************************************** ** 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 <qmessagebox.h> #include "audiodevice.h" #include <errno.h> #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !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 # if defined(QT_QWS_IPAQ) static const int sound_fragment_shift = 14; # 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; int mixerHandle = open( "/dev/mixer", O_RDWR ); 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; if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 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"); + // 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); + // 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); + // 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 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { // perror("open(\"/dev/dsp\") sending to /dev/null instead"); 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? // d->handle = ::open( "/dev/null", O_WRONLY ); // WTF?!?! } #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); + // 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); + // 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"); + // 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"); + // 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" ); + // 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 a1973e9..b187cb4 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp @@ -1,513 +1,516 @@ /********************************************************************** ** 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"); + // 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); + // 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; } 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++ ) { - delete buttonPixUp[i]; - delete buttonPixDown[i]; + if(buttonPixUp[i]) delete buttonPixUp[i]; + if(buttonPixDown[i]) delete buttonPixDown[i]; } - delete pixBg; - delete imgUp; - delete imgDn; - delete imgButtonMask; + if(pixBg) delete pixBg; + if(imgUp) delete imgUp; + if(imgDn) delete imgDn; + if(imgButtonMask) delete imgButtonMask; for ( int i = 0; i < 10; i++ ) { - delete masks[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(); showMaximized(); } 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 ) { - time.setText( timeAsString( i ) + " / " + timeAsString( 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 && i == AudioVolumeUp ) +// qDebug("on up"); if ( isOnButton && !audioButtons[i].isHeld ) { audioButtons[i].isHeld = TRUE; toggleButton(i); switch (i) { case AudioVolumeUp: - qDebug("more clicked"); + // qDebug("more clicked"); emit moreClicked(); return; case AudioVolumeDown: - qDebug("less clicked"); + // 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/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 8cf0a75..82242a3 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp @@ -1,485 +1,485 @@ /********************************************************************** ** 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 changes Fri 02-15-2002 #include <qpe/qpeapplication.h> #ifdef Q_WS_QWS #include <qpe/qcopenvelope_qws.h> #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <errno.h> #include <unistd.h> #include "loopcontrol.h" #include "videowidget.h" #include "audiodevice.h" #include <qpe/mediaplayerplugininterface.h> #include "mediaplayerstate.h" extern VideoWidget *videoUI; // now only needed to tell it to play a frame extern MediaPlayerState *mediaPlayerState; //#define DecodeLoopDebug(x) qDebug x #define DecodeLoopDebug(x) static char *audioBuffer = NULL; static AudioDevice *audioDevice = NULL; static bool disabledSuspendScreenSaver = FALSE; static bool previousSuspendMode = FALSE; pthread_t audio_tid; pthread_attr_t audio_attr; bool threadOkToGo = FALSE; class Mutex { public: Mutex() { pthread_mutexattr_t attr; pthread_mutexattr_init( &attr ); pthread_mutex_init( &mutex, &attr ); pthread_mutexattr_destroy( &attr ); } ~Mutex() { pthread_mutex_destroy( &mutex ); } void lock() { pthread_mutex_lock( &mutex ); } void unlock() { pthread_mutex_unlock( &mutex ); } private: pthread_mutex_t mutex; }; void *startAudioThread( void *ptr ) { LoopControl *mpegView = (LoopControl *)ptr; while ( TRUE ) { if ( threadOkToGo && mpegView->moreAudio ) mpegView->startAudio(); else usleep( 10000 ); // Semi-buzy-wait till we are playing again } return 0; } Mutex *audioMutex; LoopControl::LoopControl( QObject *parent, const char *name ) : QObject( parent, name ) { isMuted = FALSE; connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); -qDebug("starting loopcontrol"); + //qDebug("starting loopcontrol"); audioMutex = new Mutex; pthread_attr_init(&audio_attr); #define USE_REALTIME_AUDIO_THREAD #ifdef USE_REALTIME_AUDIO_THREAD // Attempt to set it to real-time round robin if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { sched_param params; params.sched_priority = 50; pthread_attr_setschedparam(&audio_attr,¶ms); } else { - qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); + // qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); pthread_attr_destroy(&audio_attr); pthread_attr_init(&audio_attr); } #endif -qDebug("create audio thread"); + //qDebug("create audio thread"); pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); } LoopControl::~LoopControl() { stop(); } static long prev_frame = 0; static int currentSample = 0; void LoopControl::timerEvent( QTimerEvent *te ) { if ( te->timerId() == videoId ) startVideo(); if ( te->timerId() == sliderId ) { if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { mediaPlayerState->updatePosition( audioSampleCounter ); } else if ( hasVideoChannel && moreVideo ) { mediaPlayerState->updatePosition( current_frame ); } } if ( !moreVideo && !moreAudio ) { mediaPlayerState->setPlaying( FALSE ); mediaPlayerState->setNext(); } } void LoopControl::setPosition( long pos ) { audioMutex->lock(); // qDebug("Loop control %d", pos); if ( hasVideoChannel && hasAudioChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); current_frame = pos + 1; mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); prev_frame = current_frame - 1; currentSample = (int)( (double)current_frame * freq / framerate ); mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); audioSampleCounter = currentSample - 1; } else if ( hasVideoChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); current_frame = pos + 1; mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); prev_frame = current_frame - 1; } else if ( hasAudioChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); currentSample = pos + 1; mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); audioSampleCounter = currentSample - 1; } audioMutex->unlock(); } void LoopControl::startVideo() { if ( moreVideo ) { if ( mediaPlayerState->curDecoder() ) { if ( hasAudioChannel && !isMuted ) { current_frame = long( playtime.elapsed() * framerate / 1000 ); if ( prev_frame != -1 && current_frame <= prev_frame ) return; } else { // Don't skip current_frame++; } if ( prev_frame == -1 || current_frame > prev_frame ) { if ( current_frame > prev_frame + 1 ) { mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); } moreVideo = videoUI->playVideo(); prev_frame = current_frame; } } else { moreVideo = FALSE; killTimer( videoId ); } } } void LoopControl::startAudio() { audioMutex->lock(); if ( moreAudio ) { if ( !isMuted && mediaPlayerState->curDecoder() ) { currentSample = audioSampleCounter + 1; - if ( currentSample != audioSampleCounter + 1 ) - qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); +// if ( currentSample != audioSampleCounter + 1 ) +// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); long samplesRead = 0; bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; long sampleWaitTime = currentSample - sampleWeShouldBeAt; // this causes drop outs not sure why its even here if ( hasVideoChannel ) { if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); } else if ( sampleWaitTime <= -5000 ) { - qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); + // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); currentSample = sampleWeShouldBeAt; } } audioDevice->write( audioBuffer, samplesRead * 2 * channels ); if( mediaPlayerState->isStreaming == FALSE) audioSampleCounter = currentSample + samplesRead - 1; moreAudio = readOk && (audioSampleCounter <= total_audio_samples); } else { moreAudio = FALSE; } } audioMutex->unlock(); } void LoopControl::killTimers() { audioMutex->lock(); if ( hasVideoChannel ) killTimer( videoId ); killTimer( sliderId ); threadOkToGo = FALSE; audioMutex->unlock(); } void LoopControl::startTimers() { audioMutex->lock(); moreVideo = FALSE; moreAudio = FALSE; if ( hasVideoChannel ) { moreVideo = TRUE; int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value videoId = startTimer( mSecsBetweenFrames ); } if ( hasAudioChannel ) { moreAudio = TRUE; threadOkToGo = TRUE; } sliderId = startTimer( 300 ); // update slider every 1/3 second audioMutex->unlock(); } void LoopControl::setPaused( bool pause ) { if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) return; if ( pause ) { killTimers(); } else { // Force an update of the position mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); // Just like we never stopped startTimers(); } } void LoopControl::stop( bool willPlayAgainShortly ) { #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { disabledSuspendScreenSaver = FALSE; // Re-enable the suspend mode QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } #endif if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { killTimers(); audioMutex->lock(); mediaPlayerState->curDecoder()->close(); if ( audioDevice ) { delete audioDevice; delete audioBuffer; audioDevice = 0; audioBuffer = 0; } audioMutex->unlock(); } audioSampleCounter=0; current_frame=0; total_audio_samples=0; } bool LoopControl::init( const QString& filename ) { stop(); audioMutex->lock(); fileName = filename; stream = 0; // only play stream 0 for now current_frame = total_video_frames = total_audio_samples = 0; - qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); + // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin // if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { // if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { // total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); // mediaPlayerState->libMpeg3Decoder()->close(); // } // } if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { audioMutex->unlock(); return FALSE; } hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; if ( hasAudioChannel ) { int astream = 0; if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) channels = 2; //dont akx me why, but it needs this hack else channels = mediaPlayerState->curDecoder()->audioChannels( astream ); - qDebug( "LC- channels = %d", channels ); + // qDebug( "LC- channels = %d", channels ); // if ( !total_audio_samples ) total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); total_audio_samples += 1000; - qDebug("total samples %d", total_audio_samples); + // qDebug("total samples %d", total_audio_samples); mediaPlayerState->setLength( total_audio_samples ); freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); - qDebug( "LC- frequency = %d", freq ); + // qDebug( "LC- frequency = %d", freq ); audioSampleCounter = 0; int bits_per_sample; if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); - qDebug("using stupid hack"); + // qDebug("using stupid hack"); } else { bits_per_sample=0; } audioDevice = new AudioDevice( freq, channels, bits_per_sample); audioBuffer = new char[ audioDevice->bufferSize() ]; channels = audioDevice->channels(); //### must check which frequency is actually used. static const int size = 1; short int buf[size]; long samplesRead = 0; mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); } if ( hasVideoChannel ) { total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); mediaPlayerState->setLength( total_video_frames ); framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); if ( framerate <= 1.0 ) { DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); framerate = 25; } if ( total_video_frames == 1 ) { DecodeLoopDebug(( "Cannot seek to frame" )); } } current_frame = 0; prev_frame = -1; connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); audioMutex->unlock(); return TRUE; } void LoopControl::play() { - qDebug("LC- play"); + // qDebug("LC- play"); mediaPlayerState->setPosition( 0); //uglyhack #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { disabledSuspendScreenSaver = TRUE; previousSuspendMode = hasVideoChannel; // Stop the screen from blanking and power saving state QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); } #endif playtime.start(); startTimers(); } void LoopControl::setMute( bool on ) { if ( on != isMuted ) { isMuted = on; if ( !on ) { // Force an update of the position mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); // Resume playing audio moreAudio = TRUE; } } } diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp index e99c97b..364e77b 100644 --- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp +++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp @@ -1,625 +1,625 @@ /********************************************************************** ** 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. ** **********************************************************************/ #define _REENTRANT #include <qpe/qpeapplication.h> #include <qimage.h> #include <qpainter.h> #ifdef Q_WS_QWS #include <qpe/qcopenvelope_qws.h> #endif #include "mediaplayerplugininterface.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include <pthread.h> #include "loopcontrol.h" #include "audiodevice.h" #include "videowidget.h" #include "audiowidget.h" #include "mediaplayerstate.h" #if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) || defined(QT_QWS_RAMSES) #define USE_REALTIME_AUDIO_THREAD #endif extern VideoWidget *videoUI; // now only needed to tell it to play a frame extern MediaPlayerState *mediaPlayerState; #define DecodeLoopDebug(x) qDebug x //#define DecodeLoopDebug(x) -static char *audioBuffer = NULL; +static char *audioBuffer = NULL; static AudioDevice *audioDevice = NULL; -static bool disabledSuspendScreenSaver = FALSE; +static bool disabledSuspendScreenSaver = FALSE; -pthread_t video_tid; +pthread_t video_tid; pthread_attr_t video_attr; -pthread_t audio_tid; +pthread_t audio_tid; pthread_attr_t audio_attr; bool emitPlayFinished = FALSE; bool emitChangePos = FALSE; class Mutex { public: Mutex() { - pthread_mutexattr_t attr; - pthread_mutexattr_init( &attr ); - pthread_mutex_init( &mutex, &attr ); - pthread_mutexattr_destroy( &attr ); + pthread_mutexattr_t attr; + pthread_mutexattr_init( &attr ); + pthread_mutex_init( &mutex, &attr ); + pthread_mutexattr_destroy( &attr ); } ~Mutex() { - pthread_mutex_destroy( &mutex ); + pthread_mutex_destroy( &mutex ); } void lock() { - pthread_mutex_lock( &mutex ); + pthread_mutex_lock( &mutex ); } void unlock() { - pthread_mutex_unlock( &mutex ); + pthread_mutex_unlock( &mutex ); } /* bool locked() { - switch ( pthread_mutex_trylock( &mutex ) ) { - case EBUSY: - return TRUE; - case 0: - pthread_mutex_unlock( &mutex ); - default: - return FALSE; - } + switch ( pthread_mutex_trylock( &mutex ) ) { + case EBUSY: + return TRUE; + case 0: + pthread_mutex_unlock( &mutex ); + default: + return FALSE; + } } */ private: pthread_mutex_t mutex; }; class currentFrameObj { public: currentFrameObj() : value( 0 ) { } void set( long f ) { - mutex.lock(); - value = f; - mediaPlayerState->curDecoder()->videoSetFrame( f, 0 ); - mutex.unlock(); + mutex.lock(); + value = f; + mediaPlayerState->curDecoder()->videoSetFrame( f, 0 ); + mutex.unlock(); } long get() { - return value; + return value; } private: long value; Mutex mutex; }; Mutex *videoMutex; Mutex *audioMutex; Mutex *globalMutex; -clock_t begin; +clock_t begin; LoopControl::LoopControl( QObject *parent, const char *name ) : QObject( parent, name ) { isMuted = FALSE; connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); timerid = startTimer( 200 ); videoMutex = new Mutex; audioMutex = new Mutex; globalMutex = new Mutex; //begin = clock(); } LoopControl::~LoopControl() { stop(); killTimer( timerid ); } static bool sendingNewPos = FALSE; static long prev_frame = 0; static int currentSample = 0; void LoopControl::timerEvent( QTimerEvent* ) { // We need to emit playFinished from the main thread, not one of the // decoding threads else we'll have all kinds of yucky things happen (reentrance). // playFinished will eventually call stop() which stops these threads. if ( emitPlayFinished ) { - emitPlayFinished = FALSE; + emitPlayFinished = FALSE; mediaPlayerState->setPlaying( FALSE ); } if ( emitChangePos ) { - emitChangePos = FALSE; + emitChangePos = FALSE; - if ( hasVideoChannel && hasAudioChannel ) { - sendingNewPos = TRUE; - mediaPlayerState->setPosition( current_frame ); - } else if ( hasVideoChannel ) { - sendingNewPos = TRUE; - mediaPlayerState->setPosition( current_frame ); - } else if ( hasAudioChannel ) { - sendingNewPos = TRUE; - mediaPlayerState->setPosition( audioSampleCounter ); - } + if ( hasVideoChannel && hasAudioChannel ) { + sendingNewPos = TRUE; + mediaPlayerState->setPosition( current_frame ); + } else if ( hasVideoChannel ) { + sendingNewPos = TRUE; + mediaPlayerState->setPosition( current_frame ); + } else if ( hasAudioChannel ) { + sendingNewPos = TRUE; + mediaPlayerState->setPosition( audioSampleCounter ); + } } } void LoopControl::setPosition( long pos ) { if ( sendingNewPos ) { - sendingNewPos = FALSE; - return; + sendingNewPos = FALSE; + return; } if ( hasVideoChannel && hasAudioChannel ) { - videoMutex->lock(); - audioMutex->lock(); -qDebug("setting position"); - playtime.restart(); - playtime = playtime.addMSecs( -pos * 1000 / framerate ); - //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; - current_frame = pos + 1; - mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); - prev_frame = current_frame - 1; - currentSample = (int)( current_frame * freq / framerate ); - mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); - audioSampleCounter = currentSample - 1; - audioMutex->unlock(); - videoMutex->unlock(); + videoMutex->lock(); + audioMutex->lock(); + //qDebug("setting position"); + playtime.restart(); + playtime = playtime.addMSecs( -pos * 1000 / framerate ); + //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; + current_frame = pos + 1; + mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); + prev_frame = current_frame - 1; + currentSample = (int)( current_frame * freq / framerate ); + mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); + audioSampleCounter = currentSample - 1; + audioMutex->unlock(); + videoMutex->unlock(); } else if ( hasVideoChannel ) { - videoMutex->lock(); - playtime.restart(); - playtime = playtime.addMSecs( -pos * 1000 / framerate ); - //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; - current_frame = pos + 1; - mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); - videoMutex->unlock(); - prev_frame = current_frame - 1; + videoMutex->lock(); + playtime.restart(); + playtime = playtime.addMSecs( -pos * 1000 / framerate ); + //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; + current_frame = pos + 1; + mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); + videoMutex->unlock(); + prev_frame = current_frame - 1; } else if ( hasAudioChannel ) { - audioMutex->lock(); - playtime.restart(); - playtime = playtime.addMSecs( -pos * 1000 / freq ); - //begin = clock() - (double)pos * CLOCKS_PER_SEC / freq; - currentSample = pos + 1; // (int)( current_frame * freq / framerate ); - mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); - audioSampleCounter = currentSample - 1; - audioMutex->unlock(); + audioMutex->lock(); + playtime.restart(); + playtime = playtime.addMSecs( -pos * 1000 / freq ); + //begin = clock() - (double)pos * CLOCKS_PER_SEC / freq; + currentSample = pos + 1; // (int)( current_frame * freq / framerate ); + mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); + audioSampleCounter = currentSample - 1; + audioMutex->unlock(); } } void *startVideoThread( void *ptr ) { LoopControl *mpegView = (LoopControl *)ptr; mpegView->startVideo(); return 0; } void *startAudioThread( void *ptr ) { LoopControl *mpegView = (LoopControl *)ptr; mpegView->startAudio(); return 0; } void LoopControl::startVideo() { moreVideo = TRUE; while ( moreVideo ) { if ( mediaPlayerState->curDecoder() && hasVideoChannel ) { - if ( hasAudioChannel && !isMuted ) { + if ( hasAudioChannel && !isMuted ) { - bool done = FALSE; + bool done = FALSE; - do { + do { /* - videoMutex->lock(); - current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); - //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; - - // Sync to Audio -// current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq); - - long mSecsToNextFrame = 0; - - if ( current_frame == prev_frame ) { - int nf = current_frame + 1; - if ( nf > 0 && nf != total_video_frames ) - // mSecsToNextFrame = long(double(nf * CLOCKS_PER_SEC) / framerate) - ( clock() - begin ); - mSecsToNextFrame = long(double(nf * 1000) / framerate) - ( playtime.elapsed() ); - } - videoMutex->unlock(); - - if ( mSecsToNextFrame ) { - usleep( mSecsToNextFrame ); // wait a bit - - videoMutex->lock(); - // This should now be the next frame - current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); - //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; - videoMutex->unlock(); - } - - videoMutex->lock(); - done = current_frame >= prev_frame; - videoMutex->unlock(); + videoMutex->lock(); + current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); + //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; + + // Sync to Audio +// current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq); + + long mSecsToNextFrame = 0; + + if ( current_frame == prev_frame ) { + int nf = current_frame + 1; + if ( nf > 0 && nf != total_video_frames ) + // mSecsToNextFrame = long(double(nf * CLOCKS_PER_SEC) / framerate) - ( clock() - begin ); + mSecsToNextFrame = long(double(nf * 1000) / framerate) - ( playtime.elapsed() ); + } + videoMutex->unlock(); + + if ( mSecsToNextFrame ) { + usleep( mSecsToNextFrame ); // wait a bit + + videoMutex->lock(); + // This should now be the next frame + current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); + //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; + videoMutex->unlock(); + } + + videoMutex->lock(); + done = current_frame >= prev_frame; + videoMutex->unlock(); */ - videoMutex->lock(); - current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); - done = current_frame >= prev_frame; - videoMutex->unlock(); - if ( !done ) - usleep( 1000 ); // wait a bit - - } while ( !done ); - -// qDebug("elapsed: %i %i (%f)", int( playtime.elapsed() ), current_frame, framerate ); - - } else { - videoMutex->lock(); - current_frame++; - videoMutex->unlock(); - } - - videoMutex->lock(); - bool check = current_frame && current_frame > prev_frame; - videoMutex->unlock(); - - if ( check ) { - videoMutex->lock(); - if ( current_frame > prev_frame + 1 ) { - qDebug("skipped a frame"); - mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); - } - prev_frame = current_frame; - if ( moreVideo = videoUI->playVideo() ) - emitChangePos = TRUE; - videoMutex->unlock(); - } - - } else - moreVideo = FALSE; + videoMutex->lock(); + current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); + done = current_frame >= prev_frame; + videoMutex->unlock(); + if ( !done ) + usleep( 1000 ); // wait a bit + + } while ( !done ); + +// qDebug("elapsed: %i %i (%f)", int( playtime.elapsed() ), current_frame, framerate ); + + } else { + videoMutex->lock(); + current_frame++; + videoMutex->unlock(); + } + + videoMutex->lock(); + bool check = current_frame && current_frame > prev_frame; + videoMutex->unlock(); + + if ( check ) { + videoMutex->lock(); + if ( current_frame > prev_frame + 1 ) { + // qDebug("skipped a frame"); + mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); + } + prev_frame = current_frame; + if ( moreVideo = videoUI->playVideo() ) + emitChangePos = TRUE; + videoMutex->unlock(); + } + + } else + moreVideo = FALSE; } if ( !moreVideo && !moreAudio ) - emitPlayFinished = TRUE; + emitPlayFinished = TRUE; pthread_exit(NULL); } void LoopControl::startAudio() { moreAudio = TRUE; while ( moreAudio ) { - if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { + if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { - audioMutex->lock(); - currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); + audioMutex->lock(); + currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); - if ( currentSample == 0 ) - currentSample = audioSampleCounter + 1; + if ( currentSample == 0 ) + currentSample = audioSampleCounter + 1; - if ( currentSample != audioSampleCounter + 1 ) - qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); - audioMutex->unlock(); +// if ( currentSample != audioSampleCounter + 1 ) +// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); + audioMutex->unlock(); /* - int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000; + int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000; - if ( sampleWeShouldBeAt - currentSample > 20000 ) { - mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); - currentSample = sampleWeShouldBeAt; - } + if ( sampleWeShouldBeAt - currentSample > 20000 ) { + mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); + currentSample = sampleWeShouldBeAt; + } */ - long samplesRead = 0; - - const long samples = 1024; - - moreAudio = !mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, samples, samplesRead, stream ); - - audioMutex->lock(); - long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; - //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC; - long sampleWaitTime = currentSample - sampleWeShouldBeAt; - audioMutex->unlock(); - - if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) { - //qDebug("sampleWaitTime: %i", sampleWaitTime); - usleep( ( sampleWaitTime * 1000000 ) / ( freq ) ); - } else { - audioMutex->lock(); - if ( sampleWaitTime <= -2000 ) { - qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); - mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); - currentSample = sampleWeShouldBeAt; - } - audioMutex->unlock(); - } + long samplesRead = 0; + + const long samples = 1024; + + moreAudio = !mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, samples, samplesRead, stream ); + + audioMutex->lock(); + long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; + //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC; + long sampleWaitTime = currentSample - sampleWeShouldBeAt; + audioMutex->unlock(); + + if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) { + //qDebug("sampleWaitTime: %i", sampleWaitTime); + usleep( ( sampleWaitTime * 1000000 ) / ( freq ) ); + } else { + audioMutex->lock(); + if ( sampleWaitTime <= -2000 ) { + // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); + mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); + currentSample = sampleWeShouldBeAt; + } + audioMutex->unlock(); + } - audioDevice->write( audioBuffer, samplesRead * 2 * channels ); + audioDevice->write( audioBuffer, samplesRead * 2 * channels ); - audioMutex->lock(); -// audioSampleCounter += samplesRead; - audioSampleCounter = currentSample + samplesRead - 1; - audioMutex->unlock(); + audioMutex->lock(); +// audioSampleCounter += samplesRead; + audioSampleCounter = currentSample + samplesRead - 1; + audioMutex->unlock(); - if ( !hasVideoChannel ) - emitChangePos = TRUE; + if ( !hasVideoChannel ) + emitChangePos = TRUE; - //qDebug("currentSample: %i audioSampleCounter: %i total_audio_samples: %i", currentSample, audioSampleCounter, total_audio_samples); -// qDebug("current: %i counter: %i total: %i", currentSample, audioSampleCounter, (int)total_audio_samples); - moreAudio = audioSampleCounter <= total_audio_samples; + //qDebug("currentSample: %i audioSampleCounter: %i total_audio_samples: %i", currentSample, audioSampleCounter, total_audio_samples); +// qDebug("current: %i counter: %i total: %i", currentSample, audioSampleCounter, (int)total_audio_samples); + moreAudio = audioSampleCounter <= total_audio_samples; - } else { + } else { - if ( mediaPlayerState->curDecoder() && hasAudioChannel ) - usleep( 100000 ); // Check every 1/10 sec to see if mute is off - else - moreAudio = FALSE; + if ( mediaPlayerState->curDecoder() && hasAudioChannel ) + usleep( 100000 ); // Check every 1/10 sec to see if mute is off + else + moreAudio = FALSE; - } + } } - qDebug( "End of file" ); + // qDebug( "End of file" ); if ( !moreVideo && !moreAudio ) - emitPlayFinished = TRUE; + emitPlayFinished = TRUE; pthread_exit(NULL); } void LoopControl::killTimers() { if ( hasVideoChannel ) { - if ( pthread_self() != video_tid ) { - if ( pthread_cancel(video_tid) == 0 ) { - void *thread_result = 0; - if ( pthread_join(video_tid,&thread_result) != 0 ) - qDebug("thread join error 1"); - pthread_attr_destroy(&video_attr); - } - } + if ( pthread_self() != video_tid ) { + if ( pthread_cancel(video_tid) == 0 ) { + void *thread_result = 0; + if ( pthread_join(video_tid,&thread_result) != 0 ) + // qDebug("thread join error 1"); + pthread_attr_destroy(&video_attr); + } + } } if ( hasAudioChannel ) { - if ( pthread_self() != audio_tid ) { - if ( pthread_cancel(audio_tid) == 0 ) { - void *thread_result = 0; - if ( pthread_join(audio_tid,&thread_result) != 0 ) - qDebug("thread join error 2"); - pthread_attr_destroy(&audio_attr); - } - } + if ( pthread_self() != audio_tid ) { + if ( pthread_cancel(audio_tid) == 0 ) { + void *thread_result = 0; + if ( pthread_join(audio_tid,&thread_result) != 0 ) + // qDebug("thread join error 2"); + pthread_attr_destroy(&audio_attr); + } + } } } void LoopControl::startTimers() { moreVideo = FALSE; moreAudio = FALSE; if ( hasVideoChannel ) { - moreVideo = TRUE; - pthread_attr_init(&video_attr); - pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this); + moreVideo = TRUE; + pthread_attr_init(&video_attr); + pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this); } if ( hasAudioChannel ) { - moreAudio = TRUE; - pthread_attr_init(&audio_attr); + moreAudio = TRUE; + pthread_attr_init(&audio_attr); #ifdef USE_REALTIME_AUDIO_THREAD - pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin - //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) ); - sched_param params; - params.sched_priority = 50; - pthread_attr_setschedparam(&audio_attr,¶ms); + pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin + //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) ); + sched_param params; + params.sched_priority = 50; + pthread_attr_setschedparam(&audio_attr,¶ms); #endif - pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); + pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); } } void LoopControl::setPaused( bool pause ) { static int whenPaused = 0; if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) - return; + return; if ( pause ) { - // Remember where we are - whenPaused = playtime.elapsed(); - killTimers(); + // Remember where we are + whenPaused = playtime.elapsed(); + killTimers(); } else { - // Just like we never stopped - playtime.restart(); - playtime = playtime.addMSecs( -whenPaused ); - whenPaused = 0; - startTimers(); + // Just like we never stopped + playtime.restart(); + playtime = playtime.addMSecs( -whenPaused ); + whenPaused = 0; + startTimers(); } } void LoopControl::stop( bool willPlayAgainShortly ) { #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { - disabledSuspendScreenSaver = FALSE; - // Re-enable the suspend mode - QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; + disabledSuspendScreenSaver = FALSE; + // Re-enable the suspend mode + QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } #endif if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { - killTimers(); + killTimers(); - mediaPlayerState->curDecoder()->close(); + mediaPlayerState->curDecoder()->close(); - if ( audioDevice ) { - delete audioDevice; - delete audioBuffer; - audioDevice = 0; - audioBuffer = 0; - } + if ( audioDevice ) { + delete audioDevice; + delete audioBuffer; + audioDevice = 0; + audioBuffer = 0; + } } } bool LoopControl::init( const QString& filename ) { stop(); fileName = filename; stream = 0; // only play stream 0 for now current_frame = total_video_frames = total_audio_samples = 0; - qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); + // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { - if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { - total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); - mediaPlayerState->libMpeg3Decoder()->close(); - } + if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { + total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); + mediaPlayerState->libMpeg3Decoder()->close(); + } } if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) - return FALSE; + return FALSE; hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; if ( hasAudioChannel ) { - int astream = 0; + int astream = 0; - channels = mediaPlayerState->curDecoder()->audioChannels( astream ); - DecodeLoopDebug(( "channels = %d\n", channels )); - - if ( !total_audio_samples ) - total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); + channels = mediaPlayerState->curDecoder()->audioChannels( astream ); + DecodeLoopDebug(( "channels = %d\n", channels )); + + if ( !total_audio_samples ) + total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); - mediaPlayerState->setLength( total_audio_samples ); - - freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); - DecodeLoopDebug(( "frequency = %d\n", freq )); + mediaPlayerState->setLength( total_audio_samples ); + + freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); + DecodeLoopDebug(( "frequency = %d\n", freq )); - audioSampleCounter = 0; + audioSampleCounter = 0; - static const int bytes_per_sample = 2; //16 bit + static const int bytes_per_sample = 2; //16 bit - audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); - audioBuffer = new char[ audioDevice->bufferSize() ]; - channels = audioDevice->channels(); + audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); + audioBuffer = new char[ audioDevice->bufferSize() ]; + channels = audioDevice->channels(); - //### must check which frequency is actually used. - static const int size = 1; - short int buf[size]; - long samplesRead = 0; - mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); + //### must check which frequency is actually used. + static const int size = 1; + short int buf[size]; + long samplesRead = 0; + mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); } if ( hasVideoChannel ) { - total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); + total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); - mediaPlayerState->setLength( total_video_frames ); + mediaPlayerState->setLength( total_video_frames ); - framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); - DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); + framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); + DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); - if ( framerate <= 1.0 ) { - DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); - framerate = 25; - } + if ( framerate <= 1.0 ) { + DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); + framerate = 25; + } - if ( total_video_frames == 1 ) { - DecodeLoopDebug(( "Cannot seek to frame" )); - } + if ( total_video_frames == 1 ) { + DecodeLoopDebug(( "Cannot seek to frame" )); + } } videoMutex->lock(); current_frame = 0; prev_frame = -1; videoMutex->unlock(); connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); //setBackgroundColor( black ); return TRUE; } void LoopControl::play() { #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( !disabledSuspendScreenSaver ) { - disabledSuspendScreenSaver = TRUE; + disabledSuspendScreenSaver = TRUE; // Stop the screen from blanking and power saving state - QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) - << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); + QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) + << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); } #endif //begin = clock(); playtime.start(); startTimers(); //updateGeometry(); } void LoopControl::setMute( bool on ) { if ( isMuted != on ) { - isMuted = on; - if ( isMuted ) { - } else { - int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream ); - playtime.restart(); - playtime = playtime.addMSecs( -frame * 1000 / framerate ); - //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate; - mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream ); - } + isMuted = on; + if ( isMuted ) { + } else { + int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream ); + playtime.restart(); + playtime = playtime.addMSecs( -frame * 1000 / framerate ); + //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate; + mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream ); + } } } diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp index 4f3823a..753b2e3 100644 --- a/core/multimedia/opieplayer/mediaplayer.cpp +++ b/core/multimedia/opieplayer/mediaplayer.cpp @@ -1,278 +1,278 @@ /********************************************************************** ** 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"); + // 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"); + // 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"); + // 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 cf166d6..6823076 100644 --- a/core/multimedia/opieplayer/mediaplayerstate.cpp +++ b/core/multimedia/opieplayer/mediaplayerstate.cpp @@ -1,195 +1,195 @@ /********************************************************************** ** 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"); + // 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/om3u.cpp b/core/multimedia/opieplayer/om3u.cpp index 3541e5f..8b92a8c 100644 --- a/core/multimedia/opieplayer/om3u.cpp +++ b/core/multimedia/opieplayer/om3u.cpp @@ -1,172 +1,172 @@ /* 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 ( '.' )); + 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); - 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); - } - } - } + QTextStream t(&f); + 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 ); 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; if(count()>0) { for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { - qDebug(*it); + // qDebug(*it); list += *it+"\n"; } f.writeBlock( list, list.length() ); } // 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 67187f8..94567f2 100644 --- a/core/multimedia/opieplayer/playlistselection.cpp +++ b/core/multimedia/opieplayer/playlistselection.cpp @@ -1,216 +1,216 @@ /********************************************************************** ** 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)); + // 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 7ea95ab..1fc7dd8 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp @@ -1,1506 +1,1478 @@ /********************************************************************** ** 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 <qpe/qpemenubar.h> #include <qpe/qpetoolbar.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;audio/x-ogg;audio/x-mod;audio/x-ogg"; // 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 QPEToolBar *toolbar = new QPEToolBar( this ); toolbar->setHorizontalStretchable( TRUE ); // Create Menubar QPEMenuBar *menu = new QPEMenuBar( toolbar ); menu->setMargin( 0 ); QPEToolBar *bar = new QPEToolBar( 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", LTab, "fileselector" , FALSE, FALSE); //buggy + 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 ); -// playLists->setMinimumSize(233,260); 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 ); - QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); - loadList(DocLnk( currentPlaylist)); - setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlaylist))); + + currentPlayList = cfg.readEntry("CurrentPlaylist","default"); + loadList(DocLnk( currentPlayList)); + setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlayList))); initializeStates(); - // audioUI->setFocus(); } 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." ) - ); - } +// 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(); + 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; - d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true ); - mediaPlayerState->setPlaying( FALSE ); - qApp->processEvents(); - mediaPlayerState->setPlaying( TRUE ); + setDocumentEx(fileref); } void PlayListWidget::setDocumentEx(const QString& fileref) { - - 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 + 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(); - DocLnk lnk; - lnk.setName( fileInfo.baseName() ); //sets name - lnk.setFile( fileref ); //sets file name - //addToSelection( lnk ); - - loadList( lnk); - d->selectedFiles->first(); - } else { - clearList(); - DocLnk lnk; - lnk.setName( fileInfo.baseName() ); //sets name - lnk.setFile( fileref ); //sets file name - addToSelection( lnk ); -// addToSelection( DocLnk( fileref ) ); - d->setDocumentUsed = TRUE; - mediaPlayerState->setPlaying( FALSE ); - qApp->processEvents(); - mediaPlayerState->setPlaying( TRUE ); - // qApp->processEvents(); - setCaption(tr("OpiePlayer")); - } + } + 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"); - + // 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 } void PlayListWidget::useSelectedDocument() { d->setDocumentUsed = FALSE; } const DocLnk *PlayListWidget::current() { // this is fugly - -// if( fromSetDocument) { -// qDebug("from setDoc"); -// DocLnkSet files; -// Global::findDocuments(&files, "video/*;audio/*"); -// QListIterator<DocLnk> dit( files.children() ); -// for ( ; dit.current(); ++dit ) { -// if(dit.current()->linkFile() == setDocFileRef) { -// qDebug(setDocFileRef); -// return dit; -// } -// } -// } else - - qDebug("current"); - - switch (tabWidget->currentPageIndex()) { - case 0: //playlist - { - qDebug("playlist"); - if ( mediaPlayerState->playlist() ) { - return d->selectedFiles->current(); - } - else if ( d->setDocumentUsed && d->current ) { - return d->current; - } else { - return &(d->files->selectedDocument()); - } + switch (tabWidget->currentPageIndex()) { + case 0: //playlist + { + // qDebug("playlist"); + if ( mediaPlayerState->playlist() ) { + return d->selectedFiles->current(); } - break; - case 1://audio - { - qDebug("audioView"); - QListIterator<DocLnk> dit( files.children() ); - for ( ; dit.current(); ++dit ) { - if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { - qDebug("here"); - insanityBool=TRUE; - return dit; - } - } - } - break; - case 2: // video - { - qDebug("videoView"); - QListIterator<DocLnk> Vdit( vFiles.children() ); - for ( ; Vdit.current(); ++Vdit ) { - if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { - insanityBool=TRUE; - return Vdit; - } - } + else if ( d->setDocumentUsed && d->current ) { + return d->current; + } else { + return &(d->files->selectedDocument()); } - break; - }; - return 0; + } + break; + case 1://audio + { + // qDebug("audioView"); + QListIterator<DocLnk> dit( files.children() ); + for ( ; dit.current(); ++dit ) { + if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { + insanityBool=TRUE; + return dit; + } + } + } + break; + case 2: // video + { + QListIterator<DocLnk> Vdit( vFiles.children() ); + for ( ; Vdit.current(); ++Vdit ) { + if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { + insanityBool=TRUE; + return Vdit; + } + } + } + break; + }; + return 0; } bool PlayListWidget::prev() { - if ( mediaPlayerState->playlist() ) { - if ( mediaPlayerState->shuffled() ) { - const DocLnk *cur = current(); - int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); - for ( int i = 0; i < j; i++ ) { - if ( !d->selectedFiles->next() ) - d->selectedFiles->first(); + if ( mediaPlayerState->playlist() ) { + if ( mediaPlayerState->shuffled() ) { + const DocLnk *cur = current(); + int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); + for ( int i = 0; i < j; i++ ) { + if ( !d->selectedFiles->next() ) + d->selectedFiles->first(); + } + if ( cur == current() ) + if ( !d->selectedFiles->next() ) + d->selectedFiles->first(); + return TRUE; + } else { + if ( !d->selectedFiles->prev() ) { + if ( mediaPlayerState->looping() ) { + return d->selectedFiles->last(); + } else { + return FALSE; } - if ( cur == current() ) - if ( !d->selectedFiles->next() ) - d->selectedFiles->first(); - return TRUE; - } else { - if ( !d->selectedFiles->prev() ) { - if ( mediaPlayerState->looping() ) { - return d->selectedFiles->last(); - } else { - return FALSE; - } - } - return TRUE; - } - } else { - return mediaPlayerState->looping(); - } + } + return TRUE; + } + } else { + return mediaPlayerState->looping(); + } } bool PlayListWidget::next() { - if ( mediaPlayerState->playlist() ) { - if ( mediaPlayerState->shuffled() ) { - return prev(); - } else { - if ( !d->selectedFiles->next() ) { - if ( mediaPlayerState->looping() ) { - return d->selectedFiles->first(); - } else { - return FALSE; - } + if ( mediaPlayerState->playlist() ) { + if ( mediaPlayerState->shuffled() ) { + return prev(); + } else { + if ( !d->selectedFiles->next() ) { + if ( mediaPlayerState->looping() ) { + return d->selectedFiles->first(); + } else { + return FALSE; } - return TRUE; - } - } else { - return mediaPlayerState->looping(); - } + } + return TRUE; + } + } else { + return mediaPlayerState->looping(); + } } bool PlayListWidget::first() { - if ( mediaPlayerState->playlist() ) - return d->selectedFiles->first(); - else - return mediaPlayerState->looping(); + if ( mediaPlayerState->playlist() ) + return d->selectedFiles->first(); + else + return mediaPlayerState->looping(); } bool PlayListWidget::last() { - if ( mediaPlayerState->playlist() ) - return d->selectedFiles->last(); - else - return mediaPlayerState->looping(); + if ( mediaPlayerState->playlist() ) + return d->selectedFiles->last(); + else + return mediaPlayerState->looping(); } void PlayListWidget::saveList() { writem3u(); } void PlayListWidget::loadList( const DocLnk & lnk) { - QString name = lnk.name(); -// qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); - - if( name.length()>0) { - setCaption("OpiePlayer: "+name); -// qDebug("<<<<<<<<<<<<load list "+ lnk.file()); - clearList(); - readm3u(lnk.file()); - tabWidget->setCurrentPage(0); - } + QString name = lnk.name(); + // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); + + if( name.length()>0) { + setCaption("OpiePlayer: "+name); + // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); + clearList(); + readm3u(lnk.file()); + tabWidget->setCurrentPage(0); + } } void PlayListWidget::setPlaylist( bool shown ) { - if ( shown ) - d->playListFrame->show(); - else - d->playListFrame->hide(); + if ( shown ) + d->playListFrame->show(); + else + d->playListFrame->hide(); } void PlayListWidget::setView( char view ) { - if ( view == 'l' ) - showMaximized(); - else - hide(); + if ( view == 'l' ) + showMaximized(); + else + hide(); } void PlayListWidget::addSelected() { - qDebug("addSelected"); - DocLnk lnk; - QString filename; - switch (tabWidget->currentPageIndex()) { - - case 0: //playlist - return; - break; - case 1: { //audio + DocLnk lnk; + QString filename; + switch (tabWidget->currentPageIndex()) { + + case 0: //playlist + return; + break; + case 1: { //audio QListViewItemIterator it( audioView ); for ( ; it.current(); ++it ) { - if ( it.current()->isSelected() ) { - filename = it.current()->text(3); - lnk.setName( QFileInfo(filename).baseName() ); //sets name - lnk.setFile( filename ); //sets file name - d->selectedFiles->addToSelection( lnk); - } + if ( it.current()->isSelected() ) { + filename = it.current()->text(3); + lnk.setName( QFileInfo(filename).baseName() ); //sets name + lnk.setFile( filename ); //sets file name + d->selectedFiles->addToSelection( lnk); + } } audioView->clearSelection(); - // d->selectedFiles->next(); - } - break; + // d->selectedFiles->next(); + } + break; - case 2: { // video + case 2: { // video QListViewItemIterator it( videoView ); for ( ; it.current(); ++it ) { - if ( it.current()->isSelected() ) { + if ( it.current()->isSelected() ) { - filename = it.current()->text(3); - lnk.setName( QFileInfo(filename).baseName() ); //sets name - lnk.setFile( filename ); //sets file name - d->selectedFiles->addToSelection( lnk); - } + filename = it.current()->text(3); + lnk.setName( QFileInfo(filename).baseName() ); //sets name + lnk.setFile( filename ); //sets file name + d->selectedFiles->addToSelection( lnk); + } } videoView->clearSelection(); - } - break; - }; -// tabWidget->setCurrentPage(0); - writeCurrentM3u(); + } + break; + }; + // tabWidget->setCurrentPage(0); + writeCurrentM3u(); } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); } void PlayListWidget::playIt( QListViewItem *) { -// d->setDocumentUsed = FALSE; -// mediaPlayerState->curPosition =0; - qDebug("playIt"); - // mediaPlayerState->setPlaying(FALSE); - mediaPlayerState->setPlaying(TRUE); - d->selectedFiles->unSelect(); + // d->setDocumentUsed = FALSE; + // mediaPlayerState->curPosition =0; + // mediaPlayerState->setPlaying(FALSE); + mediaPlayerState->setPlaying(TRUE); + d->selectedFiles->unSelect(); } void PlayListWidget::addToSelection( QListViewItem *it) { - d->setDocumentUsed = FALSE; + d->setDocumentUsed = FALSE; - if(it) { - switch ( tabWidget->currentPageIndex()) { - case 0: //playlist - return; - break; - }; - // case 1: { - DocLnk lnk; - QString filename; - - filename=it->text(3); - lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name - lnk.setFile( filename ); //sets file name - d->selectedFiles->addToSelection( lnk); + if(it) { + switch ( tabWidget->currentPageIndex()) { + case 0: //playlist + return; + break; + }; + // case 1: { + DocLnk lnk; + QString filename; + + filename=it->text(3); + lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name + lnk.setFile( filename ); //sets file name + d->selectedFiles->addToSelection( lnk); - if(tabWidget->currentPageIndex() == 0) - writeCurrentM3u(); -// tabWidget->setCurrentPage(0); + if(tabWidget->currentPageIndex() == 0) + writeCurrentM3u(); + // tabWidget->setCurrentPage(0); - } + } } void PlayListWidget::tabChanged(QWidget *) { - switch ( tabWidget->currentPageIndex()) { - case 0: - { - if( !tbDeletePlaylist->isHidden()) - tbDeletePlaylist->hide(); - d->tbRemoveFromList->setEnabled(TRUE); - d->tbAddToList->setEnabled(FALSE); - } - break; - case 1: - { - audioView->clear(); - populateAudioView(); - - if( !tbDeletePlaylist->isHidden()) - tbDeletePlaylist->hide(); - d->tbRemoveFromList->setEnabled(FALSE); - d->tbAddToList->setEnabled(TRUE); - } - break; - case 2: - { - videoView->clear(); - populateVideoView(); - if( !tbDeletePlaylist->isHidden()) - tbDeletePlaylist->hide(); - d->tbRemoveFromList->setEnabled(FALSE); - d->tbAddToList->setEnabled(TRUE); - } - break; - case 3: - { - if( tbDeletePlaylist->isHidden()) - tbDeletePlaylist->show(); - playLists->reread(); - } - break; - }; + switch ( tabWidget->currentPageIndex()) { + case 0: + { + if( !tbDeletePlaylist->isHidden()) + tbDeletePlaylist->hide(); + d->tbRemoveFromList->setEnabled(TRUE); + d->tbAddToList->setEnabled(FALSE); + } + break; + case 1: + { + audioView->clear(); + populateAudioView(); + + if( !tbDeletePlaylist->isHidden()) + tbDeletePlaylist->hide(); + d->tbRemoveFromList->setEnabled(FALSE); + d->tbAddToList->setEnabled(TRUE); + } + break; + case 2: + { + videoView->clear(); + populateVideoView(); + if( !tbDeletePlaylist->isHidden()) + tbDeletePlaylist->hide(); + d->tbRemoveFromList->setEnabled(FALSE); + d->tbAddToList->setEnabled(TRUE); + } + break; + case 3: + { + if( tbDeletePlaylist->isHidden()) + tbDeletePlaylist->show(); + playLists->reread(); + } + break; + }; } void PlayListWidget::btnPlay(bool b) { - qDebug("<<<<<<<<<<<<<<<BtnPlay %d", b); -// mediaPlayerState->setPlaying(b); - switch ( tabWidget->currentPageIndex()) { - case 0: - { - qDebug("1"); -// if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 -// if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { -// QMessageBox::message("Note","You are trying to play\na malformed url."); -// } else { - mediaPlayerState->setPlaying(b); - insanityBool=FALSE; - qDebug("insanity"); -// } - } - break; - case 1: - { - qDebug("2"); -// d->selectedFiles->unSelect(); - addToSelection( audioView->currentItem() ); - mediaPlayerState->setPlaying( b); - d->selectedFiles->removeSelected( ); - d->selectedFiles->unSelect(); - tabWidget->setCurrentPage(1); - insanityBool=FALSE; - }// audioView->clearSelection(); - break; - case 2: - { - qDebug("3"); + // mediaPlayerState->setPlaying(b); + switch ( tabWidget->currentPageIndex()) { + case 0: + { + // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 + // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { + // QMessageBox::message("Note","You are trying to play\na malformed url."); + // } else { + mediaPlayerState->setPlaying(b); + insanityBool=FALSE; + qDebug("insanity"); + // } + } + break; + case 1: + { + // d->selectedFiles->unSelect(); + addToSelection( audioView->currentItem() ); + mediaPlayerState->setPlaying( b); + d->selectedFiles->removeSelected( ); + d->selectedFiles->unSelect(); + tabWidget->setCurrentPage(1); + insanityBool=FALSE; + }// audioView->clearSelection(); + break; + case 2: + { - addToSelection( videoView->currentItem() ); - mediaPlayerState->setPlaying( b); -// qApp->processEvents(); - d->selectedFiles->removeSelected( ); - d->selectedFiles->unSelect(); - tabWidget->setCurrentPage(2); - insanityBool=FALSE; - }// videoView->clearSelection(); - break; - }; + addToSelection( videoView->currentItem() ); + mediaPlayerState->setPlaying( b); + // qApp->processEvents(); + d->selectedFiles->removeSelected( ); + d->selectedFiles->unSelect(); + tabWidget->setCurrentPage(2); + insanityBool=FALSE; + }// videoView->clearSelection(); + break; + }; } void PlayListWidget::deletePlaylist() { - switch( QMessageBox::information( this, (tr("Remove Playlist?")), - (tr("You really want to delete\nthis playlist?")), - (tr("Yes")), (tr("No")), 0 )){ - case 0: // Yes clicked, - QFile().remove(playLists->selectedDocument().file()); - QFile().remove(playLists->selectedDocument().linkFile()); - playLists->reread(); - break; - case 1: // Cancel - break; - }; + switch( QMessageBox::information( this, (tr("Remove Playlist?")), + (tr("You really want to delete\nthis playlist?")), + (tr("Yes")), (tr("No")), 0 )){ + case 0: // Yes clicked, + QFile().remove(playLists->selectedDocument().file()); + QFile().remove(playLists->selectedDocument().linkFile()); + playLists->reread(); + break; + case 1: // Cancel + break; + }; } void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) { - switch (mouse) { - case 1: - break; - case 2:{ - - QPopupMenu m; - m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); - m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); - m.insertSeparator(); - if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) - m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); + switch (mouse) { + case 1: + break; + case 2:{ + + QPopupMenu m; + m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); + m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); + m.insertSeparator(); + if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) + m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); - m.exec( QCursor::pos() ); - } + m.exec( QCursor::pos() ); + } break; - }; + }; } void PlayListWidget::playSelected() { - qDebug("playSelected"); btnPlay( true); // d->selectedFiles->unSelect(); } void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) { - switch (mouse) { - case 1: + switch (mouse) { + case 1: - break; - case 2:{ - QPopupMenu m; - m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); - m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); -// m.insertSeparator(); -// m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); - m.exec( QCursor::pos() ); - } break; - }; + case 2:{ + QPopupMenu m; + m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); + m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); + // m.insertSeparator(); + // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); + m.exec( QCursor::pos() ); + } + break; + }; } void PlayListWidget::listDelete() { - Config cfg( "OpiePlayer" ); - cfg.setGroup("PlayList"); - QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); - QString file; -// int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); - switch ( tabWidget->currentPageIndex()) { - case 0: - break; - case 1: - { - file = audioView->currentItem()->text(0); - QListIterator<DocLnk> Pdit( files.children() ); - for ( ; Pdit.current(); ++Pdit ) { - if( Pdit.current()->name() == file) { - LnkProperties prop( Pdit.current() ); - prop.showMaximized(); - prop.exec(); - } - } - populateAudioView(); - } + Config cfg( "OpiePlayer" ); + cfg.setGroup("PlayList"); + currentPlayList = cfg.readEntry("CurrentPlaylist",""); + QString file; + // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); + switch ( tabWidget->currentPageIndex()) { + case 0: break; - case 2: - { -// file = videoView->selectedItem()->text(0); -// for ( int i = 0; i < noOfFiles; i++ ) { -// QString entryName; -// entryName.sprintf( "File%i", i + 1 ); -// QString linkFile = cfg.readEntry( entryName ); -// AppLnk lnk( AppLnk(linkFile)); -// if( lnk.name() == file ) { -// LnkProperties prop( &lnk); -// // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); -// prop.showMaximized(); -// prop.exec(); -// } -// } + case 1: + { + file = audioView->currentItem()->text(0); + QListIterator<DocLnk> Pdit( files.children() ); + for ( ; Pdit.current(); ++Pdit ) { + if( Pdit.current()->name() == file) { + LnkProperties prop( Pdit.current() ); + prop.showMaximized(); + prop.exec(); + } } - break; - }; + populateAudioView(); + } + break; + case 2: + { + // file = videoView->selectedItem()->text(0); + // for ( int i = 0; i < noOfFiles; i++ ) { + // QString entryName; + // entryName.sprintf( "File%i", i + 1 ); + // QString linkFile = cfg.readEntry( entryName ); + // AppLnk lnk( AppLnk(linkFile)); + // if( lnk.name() == file ) { + // LnkProperties prop( &lnk); + // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); + // prop.showMaximized(); + // prop.exec(); + // } + // } + } + break; + }; } void PlayListWidget::scanForAudio() { -// qDebug("scan for audio"); - files.detachChildren(); - QListIterator<DocLnk> sdit( files.children() ); - for ( ; sdit.current(); ++sdit ) { - delete sdit.current(); - } - Global::findDocuments( &files, audioMimes); + // qDebug("scan for audio"); + files.detachChildren(); + QListIterator<DocLnk> sdit( files.children() ); + for ( ; sdit.current(); ++sdit ) { + delete sdit.current(); + } + Global::findDocuments( &files, audioMimes); audioScan = true; } void PlayListWidget::scanForVideo() { -// qDebug("scan for video"); - vFiles.detachChildren(); - QListIterator<DocLnk> sdit( vFiles.children() ); - for ( ; sdit.current(); ++sdit ) { - delete sdit.current(); - } - Global::findDocuments(&vFiles, "video/*"); - videoScan = true; + // qDebug("scan for video"); + vFiles.detachChildren(); + QListIterator<DocLnk> sdit( vFiles.children() ); + for ( ; sdit.current(); ++sdit ) { + delete sdit.current(); + } + Global::findDocuments(&vFiles, "video/*"); + videoScan = true; } void PlayListWidget::populateAudioView() { - audioView->clear(); - StorageInfo storageInfo; - const QList<FileSystem> &fs = storageInfo.fileSystems(); - if(!audioScan) scanForAudio(); + audioView->clear(); + StorageInfo storageInfo; + const QList<FileSystem> &fs = storageInfo.fileSystems(); + if(!audioScan) scanForAudio(); - QListIterator<DocLnk> dit( files.children() ); - QListIterator<FileSystem> it ( fs ); + QListIterator<DocLnk> dit( files.children() ); + QListIterator<FileSystem> it ( fs ); - QString storage; - for ( ; dit.current(); ++dit ) { - for( ; it.current(); ++it ){ - const QString name = (*it)->name(); - const QString path = (*it)->path(); - if(dit.current()->file().find(path) != -1 ) storage=name; - } + QString storage; + for ( ; dit.current(); ++dit ) { + for( ; it.current(); ++it ){ + const QString name = (*it)->name(); + const QString path = (*it)->path(); + if(dit.current()->file().find(path) != -1 ) storage=name; + } - QListViewItem * newItem; - if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { - long size; - if( dit.current()->file().left(4) == "http" ) - size=0; - else - size = QFile( dit.current()->file() ).size(); -// qDebug(dit.current()->name()); - newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), - QString::number(size ), storage, dit.current()->file()); - newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); - } - } + QListViewItem * newItem; + if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { + long size; + if( dit.current()->file().left(4) == "http" ) + size=0; + else + size = QFile( dit.current()->file() ).size(); + // qDebug(dit.current()->name()); + newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), + QString::number(size ), storage, dit.current()->file()); + newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); + } + } } void PlayListWidget::populateVideoView() { videoView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); if(!videoScan ) scanForVideo(); QListIterator<DocLnk> Vdit( vFiles.children() ); QListIterator<FileSystem> it ( fs ); videoView->clear(); QString storage; for ( ; Vdit.current(); ++Vdit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if( Vdit.current()->file().find(path) != -1 ) storage=name; } QListViewItem * newItem; if ( QFile( Vdit.current()->file()).exists() ) { newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file() ).size() ), storage, Vdit.current()->file()); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); } } } void PlayListWidget::openFile() { - qDebug("<<<<<<<<<OPEN File"); - QString filename, name; - InputDialog *fileDlg; - fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); - fileDlg->exec(); - if( fileDlg->result() == 1 ) { - filename = fileDlg->text(); - qDebug( "Selected filename is " + filename ); -// Om3u *m3uList; - DocLnk lnk; - Config cfg( "OpiePlayer" ); - cfg.setGroup("PlayList"); - - QString m3uFile; - m3uFile = filename; - if(filename.left(4) == "http") { - if(filename.find(":",8,TRUE) != -1) { //found a port - -// m3uFile = filename.left( filename.find( ":",8,TRUE)); - m3uFile = filename; - if( m3uFile.right( 1 ).find( '/' ) == -1) { - m3uFile += "/"; - } - filename = m3uFile; -// qDebug("1 "+m3uFile); -// } else if(filename.left(4) == "http"){ -// m3uFile=filename; -// m3uFile = m3uFile.right( m3uFile.length() - 7); -// qDebug("2 "+m3uFile); -// } else{ -// m3uFile=filename; -// qDebug("3 "+m3uFile); - } - lnk.setName( m3uFile ); //sets name - lnk.setFile( filename ); //sets file name - lnk.setIcon("opieplayer2/musicfile"); - d->selectedFiles->addToSelection( lnk ); - writeCurrentM3u(); - } - else if( filename.right( 3) == "m3u" ) { - readm3u( filename ); + QString filename, name; + InputDialog *fileDlg; + fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); + fileDlg->exec(); + if( fileDlg->result() == 1 ) { + filename = fileDlg->text(); + // qDebug( "Selected filename is " + filename ); + DocLnk lnk; + Config cfg( "OpiePlayer" ); + cfg.setGroup("PlayList"); - } else if( filename.right(3) == "pls" ) { - readPls( filename ); - } else { - lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name - lnk.setFile( filename ); //sets file name - d->selectedFiles->addToSelection( lnk); - writeCurrentM3u(); - } - } + QString m3uFile; + m3uFile = filename; + if(filename.left(4) == "http") { + if(filename.find(":",8,TRUE) != -1) { //found a port + + m3uFile = filename; + if( m3uFile.right( 1 ).find( '/' ) == -1) { + m3uFile += "/"; + } + filename = m3uFile; + = } + lnk.setName( m3uFile ); //sets name + lnk.setFile( filename ); //sets file name + lnk.setIcon("opieplayer2/musicfile"); + d->selectedFiles->addToSelection( lnk ); + writeCurrentM3u(); + } + else if( filename.right( 3) == "m3u" ) { + readm3u( filename ); + + } else if( filename.right(3) == "pls" ) { + readPls( filename ); + } else { + lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name + lnk.setFile( filename ); //sets file name + d->selectedFiles->addToSelection( lnk); + lnk.removeLinkFile(); + writeCurrentM3u(); + } + } - if( fileDlg ) { - delete fileDlg; - } + if( fileDlg ) { + delete fileDlg; + } } /* reads m3u and shows files/urls to playlist widget */ void PlayListWidget::readm3u( const QString &filename ) { - qDebug( "read m3u filename " + filename ); - - Om3u *m3uList; - QString s, name; - m3uList = new Om3u( filename, IO_ReadOnly ); - m3uList->readM3u(); - DocLnk lnk; - for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { - s = *it; -// qDebug("reading "+ s); - if(s.left(4)=="http") { - lnk.setName( s ); //sets file name - lnk.setIcon("opieplayer2/musicfile"); - -// if(s.right(4) != '.' || s.right(5) != '.') - if(s.right(4) != '.' || s.right(5) != '.' ) - if( s.right(1) != "/") - lnk.setFile( s+"/"); //if url with no extension - else - lnk.setFile( s ); //sets file name + // qDebug( "read m3u filename " + filename ); + + Om3u *m3uList; + QString s, name; + m3uList = new Om3u( filename, IO_ReadOnly ); + m3uList->readM3u(); + DocLnk lnk; + for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { + s = *it; + // qDebug("reading "+ s); + if(s.left(4)=="http") { + lnk.setName( s ); //sets file name + lnk.setIcon("opieplayer2/musicfile"); + + // if(s.right(4) != '.' || s.right(5) != '.') + if(s.right(4) != '.' || s.right(5) != '.' ) + if( s.right(1) != "/") + lnk.setFile( s+"/"); //if url with no extension + else + lnk.setFile( s ); //sets file name - } else { - // if( QFileInfo( s ).exists() ) { - lnk.setName( fullBaseName ( QFileInfo(s))); - // if(s.right(4) == '.') {//if regular file - if(s.left(1) != "/") { + } else { + // if( QFileInfo( s ).exists() ) { + lnk.setName( fullBaseName ( QFileInfo(s))); + // if(s.right(4) == '.') {//if regular file + if(s.left(1) != "/") { // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); lnk.setIcon("SoundPlayer"); - } else { + } else { // qDebug("set link2 "+s); lnk.setFile( s); lnk.setIcon("SoundPlayer"); - } - } - d->selectedFiles->addToSelection( lnk ); - } - Config config( "OpiePlayer" ); - config.setGroup( "PlayList" ); + } + } + d->selectedFiles->addToSelection( lnk ); + } + Config config( "OpiePlayer" ); + config.setGroup( "PlayList" ); - config.writeEntry("CurrentPlaylist",filename); - config.write(); - currentPlayList=filename; + config.writeEntry("CurrentPlaylist",filename); + config.write(); + currentPlayList=filename; // m3uList->write(); - m3uList->close(); - if(m3uList) delete m3uList; + m3uList->close(); + if(m3uList) delete m3uList; - d->selectedFiles->setSelectedItem( s); - setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); + d->selectedFiles->setSelectedItem( s); + setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); } /* reads pls and adds files/urls to playlist */ void PlayListWidget::readPls( const QString &filename ) { - qDebug( "pls filename is " + filename ); - Om3u *m3uList; - QString s, name; - m3uList = new Om3u( filename, IO_ReadOnly ); - m3uList->readPls(); - - for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { - s = *it; - // s.replace( QRegExp( "%20" )," " ); - DocLnk lnk( s ); - QFileInfo f( s ); - QString name = fullBaseName ( f); - - if( name.left( 4 ) == "http" ) { - name = s.right( s.length() - 7); - } else { - name = s; - } + // qDebug( "pls filename is " + filename ); + Om3u *m3uList; + QString s, name; + m3uList = new Om3u( filename, IO_ReadOnly ); + m3uList->readPls(); + + for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { + s = *it; + // s.replace( QRegExp( "%20" )," " ); + DocLnk lnk( s ); + 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 ); + name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); - lnk.setName( name ); - if( s.at( s.length() - 4) == '.') {// if this is probably a file - lnk.setFile( s ); - } else { //if its a url - if( name.right( 1 ).find( '/' ) == -1) { - s += "/"; - } - lnk.setFile( s ); - } - lnk.setType( "audio/x-mpegurl" ); + lnk.setName( name ); + if( s.at( s.length() - 4) == '.') {// if this is probably a file + lnk.setFile( s ); + } else { //if its a url + if( name.right( 1 ).find( '/' ) == -1) { + s += "/"; + } + lnk.setFile( s ); + } + lnk.setType( "audio/x-mpegurl" ); - lnk.writeLink(); - d->selectedFiles->addToSelection( lnk ); - } + lnk.writeLink(); + d->selectedFiles->addToSelection( lnk ); + } - m3uList->close(); - if(m3uList) delete m3uList; + m3uList->close(); + if(m3uList) delete m3uList; } /* writes current playlist to current m3u file */ void PlayListWidget::writeCurrentM3u() { - qDebug("writing to current m3u"); + // qDebug("writing to current m3u"); Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); - QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); + currentPlayList = cfg.readEntry("CurrentPlaylist",""); Om3u *m3uList; - m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); + m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); if( d->selectedFiles->first()) { do { - qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); + // qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); m3uList->add( d->selectedFiles->current()->file() ); } while ( d->selectedFiles->next() ); - qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); + // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); m3uList->write(); m3uList->close(); if(m3uList) delete m3uList; } } /* writes current playlist to m3u file */ void PlayListWidget::writem3u() { - InputDialog *fileDlg; - fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); - fileDlg->exec(); - QString name, filename, list; - Om3u *m3uList; - - if( fileDlg->result() == 1 ) { - name = fileDlg->text(); -// qDebug( filename ); - if( name.find("/",0,true) != -1) {// assume they specify a file path - filename = name; - name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); - } - else //otherwise dump it somewhere noticable - filename = QPEApplication::documentDir() + "/" + name; + InputDialog *fileDlg; + fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); + fileDlg->exec(); + QString name, filename, list; + Om3u *m3uList; + + if( fileDlg->result() == 1 ) { + name = fileDlg->text(); + // qDebug( filename ); + if( name.find("/",0,true) != -1) {// assume they specify a file path + filename = name; + name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); + } + else //otherwise dump it somewhere noticable + filename = QPEApplication::documentDir() + "/" + name; - if( filename.right( 3 ) != "m3u" ) //needs filename extension - filename += ".m3u"; + if( filename.right( 3 ) != "m3u" ) //needs filename extension + filename += ".m3u"; - if( d->selectedFiles->first()) { - m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); + if( d->selectedFiles->first()) { + m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); - do { + do { m3uList->add( d->selectedFiles->current()->file()); - } - while ( d->selectedFiles->next() ); - // qDebug( list ); - m3uList->write(); - m3uList->close(); - if(m3uList) delete m3uList; + } + while ( d->selectedFiles->next() ); + // qDebug( list ); + m3uList->write(); + m3uList->close(); + if(m3uList) delete m3uList; - if(fileDlg) delete fileDlg; + if(fileDlg) delete fileDlg; - DocLnk lnk; - lnk.setFile( filename); - lnk.setIcon("opieplayer2/playlist2"); - lnk.setName( name); //sets file name + DocLnk lnk; + lnk.setFile( filename); + lnk.setIcon("opieplayer2/playlist2"); + lnk.setName( name); //sets file name - // qDebug(filename); - Config config( "OpiePlayer" ); - config.setGroup( "PlayList" ); + // qDebug(filename); + Config config( "OpiePlayer" ); + config.setGroup( "PlayList" ); - config.writeEntry("CurrentPlaylist",filename); - currentPlayList=filename; + config.writeEntry("CurrentPlaylist",filename); + currentPlayList=filename; - if(!lnk.writeLink()) { - qDebug("Writing doclink did not work"); - } + if(!lnk.writeLink()) { + // qDebug("Writing doclink did not work"); + } - setCaption(tr("OpiePlayer: ") + name); - } - } + setCaption(tr("OpiePlayer: ") + name); + } + } } void PlayListWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_F9: //activity // if(audioUI->isHidden()) // audioUI->showMaximized(); break; case Key_F10: //contacts // if( videoUI->isHidden()) // videoUI->showMaximized(); break; case Key_F11: //menu break; case Key_F12: //home // doBlank(); break; case Key_F13: //mail // doUnblank(); break; case Key_Q: //add to playlist - qDebug("Add"); addSelected(); break; case Key_R: //remove from playlist removeSelected(); break; // case Key_P: //play // qDebug("Play"); // playSelected(); // break; case Key_Space: - qDebug("Play"); // playSelected(); puh break; case Key_1: tabWidget->setCurrentPage(0); break; case Key_2: tabWidget->setCurrentPage(1); break; case Key_3: tabWidget->setCurrentPage(2); break; case Key_4: tabWidget->setCurrentPage(3); break; case Key_Down: if ( !d->selectedFiles->next() ) d->selectedFiles->first(); break; case Key_Up: if ( !d->selectedFiles->prev() ) // d->selectedFiles->last(); break; } } void PlayListWidget::keyPressEvent( QKeyEvent *) { // qDebug("Key press"); // switch ( e->key() ) { // ////////////////////////////// Zaurus keys // case Key_A: //add to playlist // qDebug("Add"); // addSelected(); // break; // case Key_R: //remove from playlist // removeSelected(); // break; // case Key_P: //play // qDebug("Play"); // playSelected(); // break; // case Key_Space: // qDebug("Play"); // playSelected(); // break; // } } void PlayListWidget::doBlank() { - qDebug("do blanking"); - fd=open("/dev/fb0",O_RDWR); - if (fd != -1) { - ioctl(fd,FBIOBLANK,1); -// close(fd); - } + // qDebug("do blanking"); + fd=open("/dev/fb0",O_RDWR); + if (fd != -1) { + ioctl(fd,FBIOBLANK,1); + // close(fd); + } } void PlayListWidget::doUnblank() { - // this crashes opieplayer with a segfault -// int fd; -// fd=open("/dev/fb0",O_RDWR); - qDebug("do unblanking"); - if (fd != -1) { - ioctl(fd,FBIOBLANK,0); - close(fd); - } - QCopEnvelope h("QPE/System", "setBacklight(int)"); - h <<-3;// v[1]; // -3 Force on + // this crashes opieplayer with a segfault + // int fd; + // fd=open("/dev/fb0",O_RDWR); + // qDebug("do unblanking"); + if (fd != -1) { + ioctl(fd,FBIOBLANK,0); + close(fd); + } + QCopEnvelope h("QPE/System", "setBacklight(int)"); + h <<-3;// v[1]; // -3 Force on } void PlayListWidget::populateSkinsMenu() { - int item = 0; - defaultSkinIndex = 0; - QString skinName; - Config cfg( "OpiePlayer" ); - cfg.setGroup("Options" ); - QString skin = cfg.readEntry( "Skin", "default" ); - - QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); - skinsDir.setFilter( QDir::Dirs ); - skinsDir.setSorting(QDir::Name ); - const QFileInfoList *skinslist = skinsDir.entryInfoList(); - QFileInfoListIterator it( *skinslist ); - QFileInfo *fi; - while ( ( fi = it.current() ) ) { - skinName = fi->fileName(); -// qDebug( fi->fileName() ); - if( skinName != "." && skinName != ".." && skinName !="CVS" ) { - item = skinsMenu->insertItem( fi->fileName() ) ; - } - if( skinName == "default" ) { - defaultSkinIndex = item; - } - if( skinName == skin ) { - skinsMenu->setItemChecked( item, TRUE ); - } - ++it; - } + int item = 0; + defaultSkinIndex = 0; + QString skinName; + Config cfg( "OpiePlayer" ); + cfg.setGroup("Options" ); + QString skin = cfg.readEntry( "Skin", "default" ); + + QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); + skinsDir.setFilter( QDir::Dirs ); + skinsDir.setSorting(QDir::Name ); + const QFileInfoList *skinslist = skinsDir.entryInfoList(); + QFileInfoListIterator it( *skinslist ); + QFileInfo *fi; + while ( ( fi = it.current() ) ) { + skinName = fi->fileName(); + // qDebug( fi->fileName() ); + if( skinName != "." && skinName != ".." && skinName !="CVS" ) { + item = skinsMenu->insertItem( fi->fileName() ) ; + } + if( skinName == "default" ) { + defaultSkinIndex = item; + } + if( skinName == skin ) { + skinsMenu->setItemChecked( item, TRUE ); + } + ++it; + } } void PlayListWidget::skinsMenuActivated( int item ) { - for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { - skinsMenu->setItemChecked( i, FALSE ); - } - skinsMenu->setItemChecked( item, TRUE ); + for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { + skinsMenu->setItemChecked( i, FALSE ); + } + skinsMenu->setItemChecked( item, TRUE ); - Config cfg( "OpiePlayer" ); - cfg.setGroup("Options"); - cfg.writeEntry("Skin", skinsMenu->text( item ) ); + Config cfg( "OpiePlayer" ); + cfg.setGroup("Options"); + cfg.writeEntry("Skin", skinsMenu->text( item ) ); } void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { - qDebug("qcop message "+msg ); + // qDebug("qcop message "+msg ); QDataStream stream ( data, IO_ReadOnly ); if ( msg == "play()" ) { //plays current selection btnPlay( true); } else if ( msg == "stop()" ) { mediaPlayerState->setPlaying( false); } else if ( msg == "togglePause()" ) { mediaPlayerState->togglePaused(); } else if ( msg == "next()" ) { //select next in lis mediaPlayerState->setNext(); } else if ( msg == "prev()" ) { //select previous in list mediaPlayerState->setPrev(); } else if ( msg == "toggleLooping()" ) { //loop or not loop mediaPlayerState->toggleLooping(); } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled mediaPlayerState->toggleShuffled(); } else if ( msg == "volUp()" ) { //volume more -// emit moreClicked(); -// emit moreReleased(); + // emit moreClicked(); + // emit moreReleased(); } else if ( msg == "volDown()" ) { //volume less -// emit lessClicked(); -// emit lessReleased(); + // emit lessClicked(); + // emit lessReleased(); } else if ( msg == "play(QString)" ) { //play this now QString file; stream >> file; setDocumentEx( (const QString &) file); } else if ( msg == "add(QString)" ) { //add to playlist QString file; stream >> file; QFileInfo fileInfo(file); DocLnk lnk; lnk.setName( fileInfo.baseName() ); //sets name lnk.setFile( file ); //sets file name addToSelection( lnk ); } else if ( msg == "rem(QString)" ) { //remove from playlist QString file; stream >> file; - } else if ( msg == "setDocument(QString)" ) { //loop or not loop - QCopEnvelope h("QPE/Application/opieplayer", "raise()"); + QCopEnvelope h("QPE/Application/opieplayer", "raise()"); } - } diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index 48104ca..02c8568 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp @@ -1,671 +1,671 @@ /********************************************************************** ** 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); + // 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); + // 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"); + // qDebug("finished loading first pics"); for ( int i = 0; i < 7; i++ ) { buttonPixUp[i] = NULL; buttonPixDown[i] = NULL; } 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"); + // qDebug("play"); if( !mediaPlayerState->playing()) { mediaPlayerState->setPlaying( true); setToggleButton( i-1, false ); setToggleButton( i, false ); return; } if( mediaPlayerState->isPaused ) { - qDebug("isPaused"); + // qDebug("isPaused"); setToggleButton( i, FALSE ); mediaPlayerState->setPaused( FALSE ); return; } else if( !mediaPlayerState->isPaused ) { - qDebug("is not paused"); + // qDebug("is not paused"); setToggleButton( i, TRUE ); mediaPlayerState->setPaused( TRUE ); return; } else { return; } } - case VideoStop: qDebug("stop"); mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; - case VideoNext: mediaPlayerState->setNext(); 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(); showMaximized(); 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; } int bytes = ( dd == 16 ) ? 2 : 4; QImage tempFrame( w, h, bytes << 3 ); result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; if ( result && mediaPlayerState->fullscreen() ) { int rw = h, rh = w; QImage rotatedFrame( rw, rh, bytes << 3 ); ushort* in = (ushort*)tempFrame.bits(); ushort* out = (ushort*)rotatedFrame.bits(); int spl = rotatedFrame.bytesPerLine() / bytes; for (int x=0; x<h; x++) { if ( bytes == 2 ) { ushort* lout = out++ + (w - 1)*spl; for (int y=0; y<w; y++) { *lout=*in++; lout-=spl; } } else { ulong* lout = ((ulong *)out)++ + (w - 1)*spl; for (int y=0; y<w; y++) { *lout=*((ulong*)in)++; lout-=spl; } } } p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); } #ifdef USE_DIRECT_PAINTER } #endif } else { w = 220; h = 160; // maintain aspect ratio if ( w * sh > sw * h ) w = sw * h / sh; else h = sh * w / sw; result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; QPainter p( this ); int deskW = qApp->desktop()->width(); // Image changed size, therefore need to blank the possibly unpainted regions first if ( scaledWidth != w || scaledHeight != h ) { p.setBrush( QBrush( Qt::black ) ); p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 ); } scaledWidth = w; scaledHeight = h; if ( result ) { p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); } } return result; } void VideoWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_Home: break; case Key_F9: //activity break; case Key_F10: //contacts // hide(); break; case Key_F11: //menu break; case Key_F12: //home break; case Key_F13: //mail break; case Key_Space: { if(mediaPlayerState->playing()) { mediaPlayerState->setPlaying(FALSE); } else { mediaPlayerState->setPlaying(TRUE); } } break; case Key_Down: // toggleButton(6); // emit lessClicked(); // emit lessReleased(); // toggleButton(6); break; case Key_Up: // toggleButton(5); // emit moreClicked(); // emit moreReleased(); // toggleButton(5); break; case Key_Right: mediaPlayerState->setNext(); break; case Key_Left: mediaPlayerState->setPrev(); break; case Key_Escape: break; }; } |