extragear/multimedia/amarok/src

Jeff Mitchell kde-dev at emailgoeshere.com
Thu Nov 16 19:53:09 UTC 2006


Sweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet

Now to test...

:-)

On Thursday 16 November 2006 11:32, Adam Pigg wrote:
> SVN commit 605451 by piggz:
>
> Shoutcast support, yay
>
>  M  +1 -1      main.cpp
>  M  +4 -0      playlistbrowser.cpp
>  M  +2 -0      playlistbrowser.h
>  M  +167 -0    playlistbrowseritem.cpp
>  M  +53 -0     playlistbrowseritem.h
>
>
> --- trunk/extragear/multimedia/amarok/src/main.cpp #605450:605451
> @@ -60,7 +60,7 @@
>              I18N_NOOP( "DCOP, improvements, cleanups, i18n (berkus)" ),
> "berkus at madfire.net" );
>
>
> -    aboutData.addCredit( "Adam Pigg", I18N_NOOP( "Analyzers, patches" ),
> "adam at piggz.fsnet.co.uk" ); +    aboutData.addCredit( "Adam Pigg",
> I18N_NOOP( "Analyzers, patches, shoutcast" ), "adam at piggz.co.uk" );
> aboutData.addCredit( "Adeodato Simó", I18N_NOOP( "Patches" ),
> "asp16 at alu.ua.es" ); aboutData.addCredit( "Andreas Mair", I18N_NOOP( "MySQL
> support" ), "am_ml at linogate.com" ); aboutData.addCredit( "Andrew de
> Quincey", I18N_NOOP( "Postgresql support" ), "adq_dvb at lidskialf.net" ); ---
> trunk/extragear/multimedia/amarok/src/playlistbrowser.cpp #605450:605451 @@
> -5,6 +5,7 @@
>   *                        (c) 2005 Gábor Lehel <illissius at gmail.com>      
> * *                        (c) 2005 Christian Muehlhaeuser <chris at chris.de>
> * *                        (c) 2006 Alexandre Oliveira <aleprj at gmail.com>  
> * + *                        (c) 2006 Adam Pigg <adam at piggz.co.uk>         
>   * * See COPYING file for licensing information                           
>   *
> ***************************************************************************
>/
>
> @@ -143,6 +144,7 @@
>          , m_lastfmOpen( false )
>          , m_ac( new KActionCollection( this ) )
>          , m_podcastTimer( new QTimer( this ) )
> +
>  {
>      s_instance = this;
>
> @@ -259,6 +261,8 @@
>
>  #undef config
>
> +    m_shoutcastCategory = new ShoutcastBrowser(m_listview);
> +
>      m_streamsCategory  = loadStreams();
>      loadCoolStreams();
>      if( !AmarokConfig::scrobblerUsername().isEmpty() )
> --- trunk/extragear/multimedia/amarok/src/playlistbrowser.h #605450:605451
> @@ -3,6 +3,7 @@
>   *                        (c) 2004 Mark Kretschmann <markey at web.de>       
> * *                        (c) 2005-2006 Seb Ruiz <me at sebruiz.net>         
> * *                        (c) 2005 Gábor Lehel <illissius at gmail.com>      
> * + *                        (c) 2006 Adam Pigg <adam at piggz.co.uk>         
>  * * See COPYING file for licensing information                            
>  *
> ***************************************************************************
>/
>
> @@ -200,6 +201,7 @@
>          PlaylistCategory    *m_coolStreams;
>          PlaylistCategory    *m_smartDefaults;
>          PlaylistCategory    *m_lastfmCategory;
> +        ShoutcastBrowser    *m_shoutcastCategory;
>          PlaylistEntry       *m_lastPlaylist;
>
>          DynamicEntry        *m_randomDynamic;
> --- trunk/extragear/multimedia/amarok/src/playlistbrowseritem.cpp
> #605450:605451 @@ -6,6 +6,7 @@
>   *                        (c) 2006 Bart Cerneels <bart.cerneels at gmail.com>
> * *                        (c) 2006 Ian Monroe <ian at monroe.nu>             
> * *                        (c) 2006 Alexandre Oliveira <aleprj at gmail.com>  
> * + *                        (c) 2006 Adam Pigg <adam at piggz.co.uk>         
>   * * See COPYING file for licensing information                           
>   *
> ***************************************************************************
>/
>
> @@ -35,6 +36,7 @@
>  #include <qpixmap.h>           //paintCell()
>  #include <qregexp.h>
>
> +#include <kapplication.h>      //Used for Shoutcast random name generation
>  #include <kdeversion.h>        //KDE_VERSION ifndefs.  Remove this once we
> reach a kde 4 dep #include <kiconloader.h>       //smallIcon
>  #include <kio/jobclasses.h>    //podcast retrieval
> @@ -49,6 +51,7 @@
>  #include <ktrader.h>
>  #include <kurlrequester.h>
>
> +
> 
> ///////////////////////////////////////////////////////////////////////////
>// ///    CLASS PlaylistReader
> 
> ///////////////////////////////////////////////////////////////////////////
>/ @@ -3490,4 +3493,168 @@
>      xml().setAttribute( "name", newName );
>  }
>
> +ShoutcastBrowser::ShoutcastBrowser( QListView *lv ):PlaylistCategory( lv,
> 0, i18n( "Shoutcast Streams" )) +{
> +    m_downloading = false;
> +}
> +
> +void ShoutcastBrowser::slotDoubleClicked()
> +{
> +    debug() << "Downloading Genres" << endl;
> +
> +    if ( firstChild() )
> +        return;
> +
> +    QStringList tmpdirs = KGlobal::dirs()->resourceDirs( "tmp" );
> +    QString tmpfile = tmpdirs[0];
> +    tmpfile += "/amarok-genres-" + KApplication::randomString(10) +
> ".xml-"; +
> +    //get the genre list
> +    if ( !m_downloading )
> +    {
> +        m_downloading = true;
> +        m_cj = KIO::copy( "http://www.shoutcast.com/sbin/newxml.phtml",
> tmpfile, false ); +        connect( m_cj, SIGNAL( copyingDone( KIO::Job*,
> const KURL&, const KURL&, bool, bool)) +                , this,
> SLOT(doneGenreDownload(KIO::Job*, const KURL&, const KURL&, bool, bool )));
> +        connect( m_cj, SIGNAL( result( KIO::Job* )), this, SLOT(
> jobFinished( KIO::Job* ))); +    }
> +    else
> +    {
> +        debug() << "BUSY DOWNLOADING SOMETHING!!!!" << endl;
> +    }
> +
> +}
> +
> +void ShoutcastBrowser::doneGenreDownload( KIO::Job *job, const KURL &from,
> const KURL &to, bool   directory, bool renamed ) +{
> +    QDomDocument doc( "genres" );
> +    QFile file( to.path() );
> +    if ( !file.open( IO_ReadOnly ) )
> +    {
> +        debug() << "**************UNABLE TO OPEN GENRELIST XML
> FILE************" << endl; +        m_downloading = false;
> +        return;
> +    }
> +    if ( !doc.setContent( &file ) )
> +    {
> +        debug() << "**************UNABLE TO SET GENRELIST XML
> FILE*************" << endl; +        file.close();
> +        m_downloading = false;
> +        return;
> +    }
> +
> +    file.close();
> +
> +    KIO::del( to, false, false );
> +    m_downloading = false;
> +
> +    QDomElement docElem = doc.documentElement();
> +
> +    QDomNode n = docElem.firstChild();
> +    while( !n.isNull() )
> +    {
> +        QDomElement e = n.toElement(); // try to convert the node to an
> element. +        if( !e.attribute( "name" ).isNull() )
> +        {
> +            new ShoutcastGenre( this, e.attribute( "name" ));
> +        }
> +        n = n.nextSibling();
> +    }
> +    setOpen( true );
> +}
> +
> +void ShoutcastBrowser::jobFinished( KIO::Job *job )
> +{
> +    m_downloading = false;
> +
> +    if ( job->error() )
> +        job->showErrorDialog( 0 );
> +}
> +
> +ShoutcastGenre::ShoutcastGenre( ShoutcastBrowser *browser, const QString
> &g ) : PlaylistCategory(  browser, 0, g ) +{
> +    genre = g;
> +    m_downloading = false;
> +}
> +
> +void ShoutcastGenre::slotDoubleClicked()
> +{
> +
> +    QStringList tmpdirs = KGlobal::dirs()->resourceDirs( "tmp" );
> +    QString tmpfile = tmpdirs[0];
> +    tmpfile += "/amarok-list-" + genre + "-" + KApplication::randomString(
> 10) + ".xml"; +
> +    //get the genre list from shoutcast async, and when its done call the
> finish up functions to process +    if (!m_downloading)
> +    {
> +        m_downloading = true;
> +        m_cj = KIO::copy(
> "http://www.shoutcast.com/sbin/newxml.phtml?genre=" + genre, tmpfile, false
> ); +        debug() << "DOWNLOADING" << endl;
> +        connect( m_cj, SIGNAL( copyingDone( KIO::Job*, const KURL&, const
> KURL&, bool, bool )) +                , this, SLOT( doneListDownload(
> KIO::Job*, const KURL&, const KURL&, bool, bool ))); +        connect(
> m_cj, SIGNAL( result( KIO::Job* )), this, SLOT( jobFinished( KIO::Job* )
> )); +    }
> +    else
> +    {
> +        debug() << "BUSY DOWNLOADING SOMETHING!!!!" << endl;
> +    }
> +}
> +
> +void ShoutcastGenre::doneListDownload( KIO::Job *job, const KURL &from,
> const KURL &to, bool directory, bool renamed ) +{
> +
> +    QDomDocument doc( "list" );
> +    QFile file( to.path() );
> +    if ( !file.open( IO_ReadOnly ) )
> +    {
> +        debug() << "**************UNABLE TO OPEN PLAYLIST XML
> FILE**********" << endl; +        m_downloading = false;
> +        return;
> +    }
> +    if ( !doc.setContent( &file ) )
> +    {
> +        debug() << "**************UNABLE TO SET PLAYLIST XML
> FILE***********" << endl; +        file.close();
> +        m_downloading = false;
> +        return;
> +    }
> +
> +    file.close();
> +
> +    KIO::del(to, false, false);
> +
> +    //Clear any children
> +    while (firstChild())
> +        delete firstChild();
> +
> +    //Go through the XML file and add all the stations
> +    QDomElement docElem = doc.documentElement();
> +    QDomNode n = docElem.firstChild();
> +    while( !n.isNull() )
> +    {
> +        QDomElement e = n.toElement(); // try to convert the node to an
> element. +        if( e.hasAttribute( "name" ) )
> +        {
> +            if( !e.attribute( "name" ).isNull())
> +            {
> +                new StreamEntry( this, this,
> +                   
> "http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=" +               
>     + e.attribute( "id" ) + "&file=filename.pls", e.attribute( "name" )); +
>            }
> +        }
> +        n = n.nextSibling();
> +    }
> +    setOpen( true );
> +    m_downloading = false;
> +
> +}
> +
> +void ShoutcastGenre::jobFinished( KIO::Job *job )
> +{
> +    m_downloading = false;
> +
> +    if (job->error())
> +        job->showErrorDialog( 0 );
> +}
> +
>  #include "playlistbrowseritem.moc"
> --- trunk/extragear/multimedia/amarok/src/playlistbrowseritem.h
> #605450:605451 @@ -2,6 +2,7 @@
>   * copyright            : (c) 2004 Pierpaolo Di Panfilo                   
> * *                        (c) 2005-2006 Seb Ruiz <me at sebruiz.net>         
> * *                        (c) 2006 Bart Cerneels <bart.cerneels at gmail.com>
> * + *                        (c) 2006 Adam Pigg <adam at piggz.co.uk>         
>   * * See COPYING file for licensing information                           
>   *
> ***************************************************************************
>/
>
> @@ -591,5 +592,57 @@
>          int m_length;
>  };
>
> +/*!
> + at brief Implement a shoutcast playlist category
> +
> +On double click, download the shoutcast genre XML file.
> +
> +Process the file and add each genre as a ShoutcastGenre
> +style PlaylistCategory
> +*/
> +class ShoutcastBrowser : public PlaylistCategory
> +{
> +    Q_OBJECT
> +public:
> +    ShoutcastBrowser( QListView* );
> +
> +private:
> +    bool m_downloading;
> +    KIO::CopyJob *m_cj;
> +
> +public slots:
> +    virtual void slotDoubleClicked();
> +
> +private slots:
> +    void doneGenreDownload( KIO::Job *job, const KURL &from, const KURL
> &to, bool   directory, bool renamed ); +    void jobFinished( KIO::Job *job
> );
> +};
> +
> +/*!
> + at brief Implement a shoutcast genre category
> +
> +On double click, download the shoutcast station list XML file.
> +
> +Process the file and add each station as a StreamEntry
> +*/
> +class ShoutcastGenre : public PlaylistCategory
> +{
> +    Q_OBJECT
> +public:
> +    ShoutcastGenre( ShoutcastBrowser*,  const QString& );
> +
> +private:
> +    bool m_downloading;
> +    KIO::CopyJob *m_cj;
> +    QString genre;
> +
> +public slots:
> +    virtual void slotDoubleClicked();
> +
> +private slots:
> +    void doneListDownload( KIO::Job *job, const KURL &from, const KURL
> &to, bool   directory, bool renamed ); +    void jobFinished( KIO::Job *job
> );
> +};
> +
>  #endif



More information about the Amarok mailing list