示例#1
0
void
ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents )
{
    Tomahawk::dynplaylist_ptr p = Tomahawk::dynplaylist_ptr( new Tomahawk::DynamicPlaylist( src, contents.toMap().value( "type", QString() ).toString()  ) );
    QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() );
    p->reportCreated( p );
}
DynamicSetupWidget::DynamicSetupWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget* parent )
    : QWidget( parent )
    , m_playlist( playlist )
    , m_headerText( 0 )
    , m_layout( new QHBoxLayout )
    , m_generatorCombo( 0 )
    , m_logo( 0 )
    , m_generateButton( 0 )
    , m_genNumber( 0 )
{
    
    setContentsMargins( 0, 0, 0, 0 );
    m_headerText = new QLabel( tr( "Type:" ), this );
    m_layout->addWidget( m_headerText );
    
    QComboBox * genCombo = new QComboBox( this );
    foreach( const QString& type, GeneratorFactory::types() )
        genCombo->addItem( type );
    m_generatorCombo = new ReadOrWriteWidget( genCombo, m_playlist->author()->isLocal(), this );
    m_generatorCombo->setLabel( playlist->generator()->type().replace( 0, 1, playlist->generator()->type().at( 0 ).toUpper() ) );
    
    m_layout->addWidget( m_generatorCombo );
    
    m_generateButton = new QPushButton( tr( "Generate" ), this );
    m_generateButton->setAttribute( Qt::WA_LayoutUsesWidgetRect );
    connect( m_generateButton, SIGNAL( clicked( bool ) ), this, SLOT( generatePressed( bool ) ) );
    if( m_playlist->mode() == OnDemand )
        m_generateButton->hide();
    else
        m_layout->addWidget( m_generateButton );
    
    
    m_genNumber = new QSpinBox( this );
    m_genNumber->setValue( 15 );
    m_genNumber->setMinimum( 0 );
    if( m_playlist->mode() == OnDemand )
        m_genNumber->hide();
    else
        m_layout->addWidget( m_genNumber );
    
    m_layout->addSpacing( 30 );
    
    m_logo = new QLabel( this );
    if( !m_playlist->generator()->logo().isNull() ) {
        QPixmap p = m_playlist->generator()->logo().scaledToHeight( 22, Qt::SmoothTransformation );
        m_logo->setPixmap( p );
    }
    m_layout->addWidget(m_logo);
    
    setLayout( m_layout );
    
    m_fadeAnim = new QPropertyAnimation( this, "opacity" );
    m_fadeAnim->setDuration( 250 );
    m_fadeAnim->setStartValue( 0.00 );
    m_fadeAnim->setEndValue( .86 );
    
    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
    resize( sizeHint() );
}
示例#3
0
void
DynamicPlaylist::reportDeleted( const Tomahawk::dynplaylist_ptr& self )
{
//    qDebug() << Q_FUNC_INFO;
    Q_ASSERT( self.data() == this );
    // will emit Collection::playlistDeleted(...)
    if( self->mode() == Static )
        author()->collection()->deleteAutoPlaylist( self );
    else
        author()->collection()->deleteStation( self );

    emit deleted( self );
}
示例#4
0
void
ViewManager::loadCurrentPlaylistSettings()
{
    TomahawkSettings* s = TomahawkSettings::instance();
    Tomahawk::playlist_ptr pl = playlistForInterface( currentPlaylistInterface() );
    if ( !pl.isNull() ) {
        currentPlaylistInterface()->setShuffled( s->shuffleState( pl->guid() ));
        currentPlaylistInterface()->setRepeatMode( s->repeatMode( pl->guid() ));
    } else {
        Tomahawk::dynplaylist_ptr dynPl = dynamicPlaylistForInterface( currentPlaylistInterface() );
        if ( !dynPl.isNull() ) {
            currentPlaylistInterface()->setShuffled( s->shuffleState( dynPl->guid() ));
        }
    }
}
示例#5
0
void
DynamicPlaylist::reportCreated( const Tomahawk::dynplaylist_ptr& self )
{
//    qDebug() << Q_FUNC_INFO;
    Q_ASSERT( self.data() == this );
    Q_ASSERT( !author().isNull() );
    Q_ASSERT( !author()->collection().isNull() );
    // will emit Collection::playlistCreated(...)
    //    qDebug() << "Creating dynplaylist belonging to:" << author().data() << author().isNull();
    //    qDebug() << "REPORTING DYNAMIC PLAYLIST CREATED:" << this << author()->friendlyName();
    if( self->mode() == Static )
        author()->collection()->addAutoPlaylist( self );
    else
        author()->collection()->addStation( self );
}
示例#6
0
bool
DynamicPlaylist::remove( const Tomahawk::dynplaylist_ptr& playlist )
{
    DatabaseCommand_DeletePlaylist* cmd = new DatabaseCommand_DeleteDynamicPlaylist( playlist->author(), playlist->guid() );
    Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );

    return false;
}
示例#7
0
void
Collection::deleteAutoPlaylist( const Tomahawk::dynplaylist_ptr& p )
{
    QList<dynplaylist_ptr> todelete;
    todelete << p;
    m_autoplaylists.remove( p->guid() );

/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
                            << "from source id" << source()->id()
                            << "numplaylists:" << m_playlists.count();*/
    emit autoPlaylistsDeleted( todelete );
}
示例#8
0
void
Collection::addAutoPlaylist( const Tomahawk::dynplaylist_ptr& p )
{
    QList<dynplaylist_ptr> toadd;
    toadd << p;
    m_autoplaylists.insert( p->guid(), p );

/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
                            << "from source id" << source()->id()
                            << "numplaylists:" << m_playlists.count();*/
    emit autoPlaylistsAdded( toadd );
}
示例#9
0
bool 
PlaylistManager::show( const Tomahawk::dynplaylist_ptr& playlist )
{
    if ( !m_dynamicWidgets.contains( playlist ) )
    {
       m_dynamicWidgets[ playlist ] = new Tomahawk::DynamicWidget( playlist, m_stack );

       playlist->resolve();
    }
    
    setPage( m_dynamicWidgets.value( playlist ) );

    if ( playlist->mode() == Tomahawk::OnDemand )
        m_queueView->hide();
    else
        m_queueView->show();
    
    TomahawkSettings::instance()->appendRecentlyPlayedPlaylist( playlist );
    emit numSourcesChanged( SourceList::instance()->count() );

    return true;
}
示例#10
0
QModelIndex
SourcesModel::dynamicPlaylistToIndex( const Tomahawk::dynplaylist_ptr& playlist )
{
    for ( int i = 0; i < rowCount(); i++ )
    {
        QModelIndex pidx = index( i, 0 );
        
        for ( int j = 0; j < rowCount( pidx ); j++ )
        {
            QModelIndex idx = index( j, 0, pidx );
            SourcesModel::SourceType type = SourcesModel::indexType( idx );
            
            if ( type == SourcesModel::DynamicPlaylistSource )
            {
                playlist_ptr p = SourcesModel::indexToDynamicPlaylist( idx );
                if ( playlist.data() == p.data() )
                    return idx;
            }
        }
    }
    
    return QModelIndex();
}
示例#11
0
void
DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
{
    // special case: if we have launched multiple setRevision calls, and the number of controls is different, it means that we're getting an intermediate setRevision
    //  called after the user has already created more revisions. ignore in that case.
    if( m_playlist.data() == playlist.data() && m_seqRevLaunched > 0
        && m_controls->controls().size() != playlist->generator()->controls().size() // different number of controls
        && qAbs( m_playlist->generator()->controls().size() - playlist->generator()->controls().size() ) < m_seqRevLaunched ) { // difference in controls has to be less than how many revisions we launched
        return;
    }
    m_seqRevLaunched = 0;

    // if we're being told to load the same dynamic playlist over again, only do it if the controls have a different number
    if( !m_playlist.isNull() && ( m_playlist.data() == playlist.data() ) // same playlist pointer
        && m_playlist->generator()->controls().size() == playlist->generator()->controls().size() ) {
        // we can skip our work. just let the dynamiccontrollist show the difference
        m_controls->setControls( m_playlist, m_playlist->author()->isLocal() );

        m_playlist = playlist;

        if( !m_runningOnDemand ) {
            m_model->loadPlaylist( m_playlist );
        } else if( !m_controlsChanged ) { // if the controls changed, we already dealt with that and don't want to change station yet
            m_model->changeStation();
        }
        m_controlsChanged = false;

        return;
    }

    if( !m_playlist.isNull() ) {
        disconnect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
        disconnect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ), this, SLOT(onRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ) );
        disconnect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), this, SLOT( generatorError( QString, QString ) ) );
        disconnect( m_playlist.data(), SIGNAL( deleted( Tomahawk::dynplaylist_ptr ) ), this, SLOT( onDeleted() ) );
        disconnect( m_playlist.data(), SIGNAL( changed() ), this, SLOT( onChanged() ) );
    }


    m_playlist = playlist;
    m_view->setOnDemand( m_playlist->mode() == OnDemand );
    m_view->setReadOnly( !m_playlist->author()->isLocal() );
    m_model->loadPlaylist( m_playlist );
    m_controlsChanged = false;
    m_setup->setPlaylist( m_playlist );


    if( !m_playlist->author()->isLocal() ) { // hide controls, as we show the description in the summary
            m_layout->removeWidget( m_controls );
    } else if( m_layout->indexOf( m_controls ) == -1 ) {
        m_layout->insertWidget( 0, m_controls );
    }

    if( m_playlist->mode() == OnDemand && !m_playlist->generator()->controls().isEmpty() )
        showPreview();

    if( !m_playlist.isNull() )
        m_controls->setControls( m_playlist, m_playlist->author()->isLocal() );

    connect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
    connect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ) );
    connect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), this, SLOT( generatorError( QString, QString ) ) );
    connect( m_playlist.data(), SIGNAL( deleted( Tomahawk::dynplaylist_ptr ) ), this, SLOT( onDeleted() ) );
    connect( m_playlist.data(), SIGNAL( changed() ), this, SLOT( onChanged() ) );
}