Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

xinecontrol.cpp

Go to the documentation of this file.
00001 /*
00002                             This file is part of the Opie Project
00003 
00004                              Copyright (c)  2002 Max Reiss <harlekin@handhelds.org>
00005                              Copyright (c)  2002 L. Potter <ljp@llornkcor.com>
00006                              Copyright (c)  2002 Holger Freyther <zecke@handhelds.org>
00007               =.
00008             .=l.
00009            .>+-=
00010  _;:,     .>    :=|.         This program is free software; you can
00011 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00012 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00013 .="- .-=="i,     .._         License as published by the Free Software
00014  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00015      ._= =}       :          or (at your option) any later version.
00016     .%`+i>       _;_.
00017     .i_,=:_.      -<s.       This program is distributed in the hope that
00018      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00019     : ..    .:,     . . .    without even the implied warranty of
00020     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00021   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00022 ..}^=.=       =       ;      General Public License for more
00023 ++=   -.     .`     .:       details.
00024  :     =  ...= . :.=-
00025  -.   .:....=;==+<;          You should have received a copy of the GNU
00026   -_. . .   )=.  =           General Public License along with
00027     --        :-=`           this library; see the file COPYING.LIB.
00028                              If not, write to the Free Software Foundation,
00029                              Inc., 59 Temple Place - Suite 330,
00030                              Boston, MA 02111-1307, USA.
00031 
00032 */
00033 
00034 #include "xinecontrol.h"
00035 #include "xinevideowidget.h"
00036 
00037 /* OPIE */
00038 #include <opie2/odebug.h>
00039 #include <qpe/qcopenvelope_qws.h>
00040 #include <qpe/qpeapplication.h>
00041 using namespace Opie::Core;
00042 
00043 /* QT */
00044 #include <qtimer.h>
00045 #include <qmessagebox.h>
00046 
00047 XineControl::XineControl( XINE::Lib *xine, XineVideoWidget *xineWidget,
00048                           MediaPlayerState &_mediaPlayerState,
00049                           QObject *parent, const char *name )
00050     : QObject( parent, name ), libXine( xine ), mediaPlayerState( _mediaPlayerState ), xineVideoWidget( xineWidget )
00051 {
00052     m_wasError = false;
00053 
00054     xine->ensureInitialized();
00055 
00056     xine->setWidget( xineWidget );
00057 
00058     init();
00059 }
00060 
00061 void XineControl::init()
00062 {
00063     connect( &mediaPlayerState, SIGNAL( pausedToggled(bool) ),  this, SLOT( pause(bool) ) );
00064     connect( this, SIGNAL( positionChanged(long) ), &mediaPlayerState, SLOT( updatePosition(long) ) );
00065     connect( &mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( stop(bool) ) );
00066     connect( &mediaPlayerState, SIGNAL( fullscreenToggled(bool) ), this, SLOT( setFullscreen(bool) ) );
00067     connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),  this,  SLOT( seekTo(long) ) );
00068     connect( &mediaPlayerState,  SIGNAL( videoGammaChanged(int) ), this,  SLOT( setGamma(int) ) );
00069     connect( libXine, SIGNAL( stopped() ), this, SLOT( nextMedia() ) );
00070     connect( xineVideoWidget, SIGNAL( videoResized(const QSize&) ), this, SLOT( videoResized(const QSize&) ) );
00071 
00072     disabledSuspendScreenSaver = FALSE;
00073 }
00074 
00075 XineControl::~XineControl() {
00076 #if !defined(QT_NO_COP)
00077     if ( disabledSuspendScreenSaver ) {
00078         disabledSuspendScreenSaver = FALSE;
00079         // Re-enable the suspend mode
00080         QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
00081     }
00082 #endif
00083     delete libXine;
00084 }
00085 
00086 void XineControl::play( const QString& fileName ) {
00087 
00088     hasVideoChannel = FALSE;
00089     hasAudioChannel = FALSE;
00090     m_fileName = fileName;
00091     m_wasError = false;
00092 
00093 
00094     /*
00095      * If Playing Fails we will fire up an MessgaeBox
00096      * but present the AudioWidget so the User can
00097      * either Quit and change the Playlist or Continue
00098      */
00099     if ( !libXine->play( fileName, 0, 0 ) ) {
00100         QMessageBox::warning( 0l , tr( "Failure" ), getErrorCode() );
00101         m_wasError = true;
00102     }
00103     mediaPlayerState.setPlaying( true );
00104 
00105     MediaPlayerState::DisplayType displayType;
00106     if ( !libXine->hasVideo() ) {
00107         displayType = MediaPlayerState::Audio;
00108         libXine->setShowVideo( false );
00109         hasAudioChannel = TRUE;
00110     } else {
00111         displayType = MediaPlayerState::Video;
00112         libXine->setShowVideo( true );
00113         hasVideoChannel = TRUE;
00114     }
00115     // determine if slider is shown
00116     mediaPlayerState.setIsSeekable( libXine->isSeekable() );
00117 
00118     // which gui (video / audio)
00119     mediaPlayerState.setDisplayType( displayType );
00120 
00121 #if defined(Q_WS_QWS) && !defined(QT_NO_COP)
00122     if ( !disabledSuspendScreenSaver ) {
00123         disabledSuspendScreenSaver = TRUE;
00124         // Stop the screen from blanking and power saving state
00125         QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" )
00126             << ( displayType == MediaPlayerState::Video ? QPEApplication::Disable : QPEApplication::DisableSuspend );
00127     }
00128 #endif
00129 
00130     length();
00131     position();
00132 }
00133 
00134 void XineControl::nextMedia() {
00135     mediaPlayerState.setNext();
00136 }
00137 
00138 void XineControl::setGamma( int value ) {
00139     libXine->setGamma( value );
00140 }
00141 
00142 void XineControl::stop( bool isSet ) {
00143     if ( !isSet ) {
00144         libXine->stop();
00145 
00146 #if !defined(QT_NO_COP)
00147         if ( disabledSuspendScreenSaver ) {
00148             disabledSuspendScreenSaver = FALSE;
00149             // Re-enable the suspend mode
00150             QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
00151         }
00152 #endif
00153     }
00154 }
00155 
00160 void XineControl::pause( bool isSet) {
00161     libXine->pause( isSet );
00162 }
00163 
00164 
00168 long XineControl::currentTime() {
00169     // todo: jede sekunde überprüfen
00170     m_currentTime = libXine->currentTime();
00171     return m_currentTime;
00172 }
00173 
00177 void  XineControl::length() {
00178     m_length = libXine->length();
00179     mediaPlayerState.setLength( m_length );
00180 }
00181 
00182 
00187 long XineControl::position() {
00188     m_position = ( currentTime() );
00189     mediaPlayerState.updatePosition( m_position );
00190     long emitPos = (long)m_position;
00191     emit positionChanged( emitPos );
00192     if( mediaPlayerState.isPlaying() ) {
00193     // needs to be stopped the media is stopped
00194         QTimer::singleShot( 1000, this, SLOT( position() ) );
00195     }
00196     return m_position;
00197 }
00198 
00203 void XineControl::setFullscreen( bool isSet ) {
00204     libXine->showVideoFullScreen( isSet );
00205 }
00206 
00207 
00208 QString XineControl::getMetaInfo() {
00209 
00210     QString returnString;
00211 
00212     /*
00213      * If there was an error let us
00214      * change the Meta Info to contain the Error Message
00215      */
00216     if ( m_wasError ) {
00217         returnString = tr("Error on file '%1' with reason: ",
00218                           "Error when playing a file" ).arg( m_fileName );
00219         returnString += getErrorCode();
00220         returnString.replace( QRegExp("<qt>",  false), "" );
00221         returnString.replace( QRegExp("</qt>", false), "" );
00222         return returnString;
00223     }
00224 
00225     if ( !libXine->metaInfo( 0 ).isEmpty() ) {
00226         returnString += tr( " Title: " + libXine->metaInfo( 0 ) );
00227     }
00228 
00229     if ( !libXine->metaInfo( 1 ).isEmpty() ) {
00230         returnString += tr( " Comment: " + libXine->metaInfo( 1 ) );
00231     }
00232 
00233     if ( !libXine->metaInfo( 2 ).isEmpty() ) {
00234         returnString += tr( " Artist: " + libXine->metaInfo( 2 ) );
00235     }
00236 
00237     if ( !libXine->metaInfo( 3 ).isEmpty() ) {
00238         returnString += tr( " Genre: " + libXine->metaInfo( 3 ) );
00239     }
00240 
00241     if ( !libXine->metaInfo( 4 ).isEmpty() ) {
00242         returnString += tr( " Album: " + libXine->metaInfo( 4 ) );
00243     }
00244 
00245     if ( !libXine->metaInfo( 5 ).isEmpty() ) {
00246         returnString += tr( " Year: " + libXine->metaInfo( 5 ) );
00247     }
00248     return returnString;
00249 }
00250 
00251 QString XineControl::getErrorCode() {
00252 
00253     int errorCode = libXine->error();
00254 
00255     odebug << QString("ERRORCODE: %1 ").arg(errorCode) << oendl;
00256 
00257     if ( errorCode == 1 ) {
00258         return tr( "<qt>No input plugin found for this media type</qt>" );
00259     } else if ( errorCode == 2 ) {
00260         return tr( "<qt>No demux plugin found for this media type</qt>" );
00261     } else if ( errorCode == 3 ) {
00262         return tr( "<qt>Demuxing failed for this media type</qt>" );
00263     } else if ( errorCode == 4 ) {
00264         return tr( "<qt>Malformed MRL</qt>" );
00265     } else if ( errorCode == 5 ) {
00266         return tr( "<qt>Input failed</qt>" );
00267     } else {
00268         return tr( "<qt>Some other error</qt>" );
00269     }
00270 }
00271 
00276 void XineControl::seekTo( long second ) {
00277     libXine->seekTo( (int)second );
00278 }
00279 
00280 void XineControl::videoResized ( const QSize &s ) {
00281     libXine->resize( s );
00282 }

Generated on Sat Nov 5 16:17:33 2005 for OPIE by  doxygen 1.4.2