SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent )
    : QWidget( parent )
    , ui( new Ui::SourceInfoWidget )
{
    ui->setupUi( this );

    ui->historyView->overlay()->setEnabled( false );

    m_recentCollectionModel = new CollectionFlatModel( ui->recentCollectionView );
    ui->recentCollectionView->setModel( m_recentCollectionModel );
    m_recentCollectionModel->addFilteredCollection( source->collection(), 250, DatabaseCommand_AllTracks::ModificationTime );

    m_historyModel = new PlaylistModel( ui->historyView );
    ui->historyView->setModel( m_historyModel );
    m_historyModel->loadHistory( source );

    connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ) );

    ui->recentCollectionView->setColumnHidden( TrackModel::Bitrate, true );
    ui->recentCollectionView->setColumnHidden( TrackModel::Origin, true );
    ui->recentCollectionView->setColumnHidden( TrackModel::Filesize, true );

    ui->historyView->setColumnHidden( TrackModel::Bitrate, true );
    ui->historyView->setColumnHidden( TrackModel::Origin, true );
    ui->historyView->setColumnHidden( TrackModel::Filesize, true );

    m_recentAlbumModel = new AlbumModel( ui->recentAlbumView );
    ui->recentAlbumView->setModel( m_recentAlbumModel );
    m_recentAlbumModel->addFilteredCollection( source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime );

    m_title = tr( "Info about %1" ).arg( source->isLocal() ? tr( "Your Collection" ) : source->friendlyName() );
}
SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent )
    : QWidget( parent )
    , ui( new Ui::SourceInfoWidget )
{
    ui->setupUi( this );

    ui->historyView->setFrameShape( QFrame::NoFrame );
    ui->historyView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
    ui->recentAlbumView->setFrameShape( QFrame::NoFrame );
    ui->recentAlbumView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
    ui->recentCollectionView->setFrameShape( QFrame::NoFrame );
    ui->recentCollectionView->setAttribute( Qt::WA_MacShowFocusRect, 0 );

    TomahawkUtils::unmarginLayout( layout() );

    ui->historyView->overlay()->setEnabled( false );

    m_recentCollectionModel = new CollectionFlatModel( ui->recentCollectionView );
    m_recentCollectionModel->setStyle( TrackModel::Short );
    ui->recentCollectionView->setTrackModel( m_recentCollectionModel );
    m_recentCollectionModel->addFilteredCollection( source->collection(), 250, DatabaseCommand_AllTracks::ModificationTime );

    m_historyModel = new PlaylistModel( ui->historyView );
    m_historyModel->setStyle( TrackModel::Short );
    ui->historyView->setPlaylistModel( m_historyModel );
    m_historyModel->loadHistory( source, 25 );

    connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ) );

    m_recentAlbumModel = new AlbumModel( ui->recentAlbumView );
    ui->recentAlbumView->setAlbumModel( m_recentAlbumModel );
    m_recentAlbumModel->addFilteredCollection( source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime );

    m_title = tr( "New Additions" );
    m_description = tr( "Recent activity from %1" ).arg( source->isLocal() ? tr( "Your Collection" ) : source->friendlyName() );
    m_pixmap.load( RESPATH "images/new-additions.png" );
}
Exemple #3
0
SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent )
    : QWidget( parent )
    , ui( new Ui::SourceInfoWidget )
    , m_source( source )
{
    ui->setupUi( this );

    ui->historyView->setFrameShape( QFrame::NoFrame );
    ui->historyView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
    ui->recentAlbumView->setFrameShape( QFrame::NoFrame );
    ui->recentAlbumView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
    ui->recentCollectionView->setFrameShape( QFrame::NoFrame );
    ui->recentCollectionView->setAttribute( Qt::WA_MacShowFocusRect, 0 );

    TomahawkUtils::unmarginLayout( layout() );

    ui->historyView->overlay()->setEnabled( false );

    m_recentCollectionModel = new CollectionFlatModel( ui->recentCollectionView );
    m_recentCollectionModel->setStyle( TrackModel::Short );
    ui->recentCollectionView->setTrackModel( m_recentCollectionModel );
    ui->recentCollectionView->sortByColumn( TrackModel::Age, Qt::DescendingOrder );

    m_historyModel = new PlaylistModel( ui->historyView );
    m_historyModel->setStyle( TrackModel::Short );
    ui->historyView->setPlaylistModel( m_historyModel );
    m_historyModel->loadHistory( source, 25 );

    m_recentAlbumModel = new AlbumModel( ui->recentAlbumView );
    ui->recentAlbumView->setAlbumModel( m_recentAlbumModel );
    ui->recentAlbumView->proxyModel()->sort( -1 );

    onCollectionChanged();

    connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) );
    connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ) );

    m_title = tr( "New Additions" );
    if ( source->isLocal() )
    {
        m_description = tr( "My recent activity" );
    }
    else
    {
        m_description = tr( "Recent activity from %1" ).arg( source->friendlyName() );
    }

    m_pixmap.load( RESPATH "images/new-additions.png" );
}
Exemple #4
0
SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent )
    : QWidget( parent )
    , ui( new Ui::SourceInfoWidget )
    , m_source( source )
{
    ui->setupUi( this );

    TomahawkUtils::unmarginLayout( layout() );
    TomahawkUtils::unmarginLayout( ui->horizontalLayout );
    TomahawkUtils::unmarginLayout( ui->verticalLayout );
    TomahawkUtils::unmarginLayout( ui->verticalLayout_2 );
    TomahawkUtils::unmarginLayout( ui->verticalLayout_3 );

    ui->splitter->setStretchFactor( 0, 0 );
    ui->splitter->setStretchFactor( 1, 1 );

    ui->historyView->overlay()->setEnabled( false );

    m_recentTracksModel = new RecentlyAddedModel( source, ui->recentCollectionView );
    m_recentTracksModel->setStyle( PlayableModel::Short );
    ui->recentCollectionView->setPlayableModel( m_recentTracksModel );
    ui->recentCollectionView->sortByColumn( PlayableModel::Age, Qt::DescendingOrder );

    m_historyModel = new RecentlyPlayedModel( source, ui->historyView );
    m_historyModel->setStyle( PlayableModel::Short );
    ui->historyView->setPlaylistModel( m_historyModel );

    m_recentAlbumModel = new AlbumModel( ui->recentAlbumView );
    ui->recentAlbumView->setAlbumModel( m_recentAlbumModel );
    ui->recentAlbumView->proxyModel()->sort( -1 );

    onCollectionChanged();
    connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) );

    m_title = tr( "New Additions" );
    if ( source->isLocal() )
    {
        m_description = tr( "My recent activity" );
    }
    else
    {
        m_description = tr( "Recent activity from %1" ).arg( source->friendlyName() );
    }

    m_pixmap.load( RESPATH "images/new-additions.png" );
}
Exemple #5
0
SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahawk::source_ptr& source )
    : SourceTreeItem( mdl, parent, SourcesModel::Collection )
    , m_source( source )
    , m_playlists( 0 )
    , m_stations( 0 )
    , m_latchedOn( false )
    , m_sourceInfoItem( 0 )
    , m_coolPlaylistsItem( 0 )
    , m_collectionPage( 0 )
    , m_sourceInfoPage( 0 )
    , m_coolPlaylistsPage( 0 )
    , m_lovedTracksPage( 0 )
    , m_latestAdditionsPage( 0 )
    , m_recentPlaysPage( 0 )
    , m_whatsHotPage( 0 )
{
    if ( m_source.isNull() )
    {
        m_superCol = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/supercollection.png" ) );
        return;
    }

    m_collectionItem = new GenericPageItem( model(), this, tr( "Collection" ), QIcon( RESPATH "images/collection.png" ), //FIXME different icon
                                            boost::bind( &SourceItem::collectionClicked, this ),
                                            boost::bind( &SourceItem::getCollectionPage, this ) );

/*    m_sourceInfoItem = new GenericPageItem( model(), this, tr( "New Additions" ), QIcon( RESPATH "images/new-additions.png" ),
                                            boost::bind( &SourceItem::sourceInfoClicked, this ),
                                            boost::bind( &SourceItem::getSourceInfoPage, this ) );*/

    m_latestAdditionsItem = new GenericPageItem( model(), this, tr( "Latest Additions" ), QIcon( RESPATH "images/new-additions.png" ),
                                                 boost::bind( &SourceItem::latestAdditionsClicked, this ),
                                                 boost::bind( &SourceItem::getLatestAdditionsPage, this ) );

    m_recentPlaysItem = new GenericPageItem( model(), this, tr( "Recently Played" ), QIcon( RESPATH "images/recently-played.png" ),
                                             boost::bind( &SourceItem::recentPlaysClicked, this ),
                                             boost::bind( &SourceItem::getRecentPlaysPage, this ) );

    m_lovedTracksItem = new GenericPageItem( model(), this, tr( "Loved Tracks" ), QIcon( RESPATH "images/loved_playlist.png" ),
                                             boost::bind( &SourceItem::lovedTracksClicked, this ),
                                             boost::bind( &SourceItem::getLovedTracksPage, this ) );

    m_collectionItem->setSortValue( -350 );
//    m_sourceInfoItem->setSortValue( -300 );
    m_latestAdditionsItem->setSortValue( -250 );
    m_recentPlaysItem->setSortValue( -200 );
    m_lovedTracksItem->setSortValue( -150 );

    // create category items if there are playlists to show, or stations to show
    QList< playlist_ptr > playlists = source->collection()->playlists();
    QList< dynplaylist_ptr > autoplaylists = source->collection()->autoPlaylists();
    QList< dynplaylist_ptr > stations = source->collection()->stations();

    if ( !playlists.isEmpty() || !autoplaylists.isEmpty() || source->isLocal() )
    {
        m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source->isLocal() );
        onPlaylistsAdded( playlists );
        onAutoPlaylistsAdded( autoplaylists );
    }
    if ( !stations.isEmpty() || source->isLocal() )
    {
        m_stations = new CategoryItem( model(), this, SourcesModel::StationsCategory, source->isLocal() );
        onStationsAdded( stations );
    }

    if ( ViewManager::instance()->pageForCollection( source->collection() ) )
        model()->linkSourceItemToPage( this, ViewManager::instance()->pageForCollection( source->collection() ) );

    m_defaultAvatar = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) );

    // load auto playlists and stations!

    connect( source.data(), SIGNAL( stats( QVariantMap ) ), SIGNAL( updated() ) );
    connect( source.data(), SIGNAL( syncedWithDatabase() ), SIGNAL( updated() ) );
    connect( source.data(), SIGNAL( playbackStarted( Tomahawk::query_ptr ) ), SIGNAL( updated() ) );
    connect( source.data(), SIGNAL( stateChanged() ), SIGNAL( updated() ) );
    connect( source.data(), SIGNAL( offline() ), SIGNAL( updated() ) );
    connect( source.data(), SIGNAL( online() ), SIGNAL( updated() ) );
    connect( SourceList::instance(), SIGNAL( sourceLatchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) );
    connect( SourceList::instance(), SIGNAL( sourceLatchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) );

    connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ),
             SLOT( onPlaylistsAdded( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
    connect( source->collection().data(), SIGNAL( autoPlaylistsAdded( QList< Tomahawk::dynplaylist_ptr > ) ),
             SLOT( onAutoPlaylistsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
    connect( source->collection().data(), SIGNAL( stationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ),
             SLOT( onStationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );

    if ( m_source->isLocal() )
        QTimer::singleShot( 0, this, SLOT( requestExpanding() ) );
}
void
DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
{
    TomahawkSqlQuery query = dbi->newquery();
    QList<Tomahawk::query_ptr> ql;

    QString m_orderToken, sourceToken;
    switch ( m_sortOrder )
    {
        case 0:
            break;

        case Album:
            m_orderToken = "album.name, file_join.albumpos";
            break;

        case ModificationTime:
            m_orderToken = "file.mtime";
            break;

        case AlbumPosition:
            m_orderToken = "file_join.albumpos";
            break;
    }

    if ( !m_collection.isNull() )
        sourceToken = QString( "AND file.source %1" ).arg( m_collection->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( m_collection->source()->id() ) );

    QString albumToken;
    if ( m_album )
    {
        if ( m_album->id() == 0 )
        {
            m_artist = m_album->artist().data();
            albumToken = QString( "AND album.id IS NULL" );
        }
        else
            albumToken = QString( "AND album.id = %1" ).arg( m_album->id() );
    }

    QString sql = QString(
            "SELECT file.id, artist.name, album.name, track.name, file.size, "
                   "file.duration, file.bitrate, file.url, file.source, file.mtime, file.mimetype, file_join.albumpos, artist.id, album.id, track.id "
            "FROM file, artist, track, file_join "
            "LEFT OUTER JOIN album "
            "ON file_join.album = album.id "
            "WHERE file.id = file_join.file "
            "AND file_join.artist = artist.id "
            "AND file_join.track = track.id "
            "%1 "
            "%2 %3 "
            "%4 %5 %6"
            ).arg( sourceToken )
             .arg( !m_artist ? QString() : QString( "AND artist.id = %1" ).arg( m_artist->id() ) )
             .arg( !m_album ? QString() : albumToken )
             .arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( m_orderToken ) : QString() )
             .arg( m_sortDescending ? "DESC" : QString() )
             .arg( m_amount > 0 ? QString( "LIMIT 0, %1" ).arg( m_amount ) : QString() );

    query.prepare( sql );
    query.exec();

    while( query.next() )
    {
        Tomahawk::result_ptr result = Tomahawk::result_ptr( new Tomahawk::Result() );
        Tomahawk::source_ptr s;

        if( query.value( 8 ).toUInt() == 0 )
        {
            s = SourceList::instance()->getLocal();
            result->setUrl( query.value( 7 ).toString() );
        }
        else
        {
            s = SourceList::instance()->get( query.value( 8 ).toUInt() );
            if( s.isNull() )
            {
                Q_ASSERT( false );
                continue;
            }

            result->setUrl( QString( "servent://%1\t%2" ).arg( s->userName() ).arg( query.value( 7 ).toString() ) );
        }

        QString artist, track, album;
        artist = query.value( 1 ).toString();
        album = query.value( 2 ).toString();
        track = query.value( 3 ).toString();

        Tomahawk::query_ptr qry = Tomahawk::Query::get( artist, track, album );
        Tomahawk::artist_ptr artistptr = Tomahawk::Artist::get( query.value( 12 ).toUInt(), artist );
        Tomahawk::album_ptr albumptr = Tomahawk::Album::get( query.value( 13 ).toUInt(), album, artistptr );

        result->setId( query.value( 14 ).toUInt() );
        result->setArtist( artistptr );
        result->setAlbum( albumptr );
        result->setTrack( query.value( 3 ).toString() );
        result->setSize( query.value( 4 ).toUInt() );
        result->setDuration( query.value( 5 ).toUInt() );
        result->setBitrate( query.value( 6 ).toUInt() );
        result->setModificationTime( query.value( 9 ).toUInt() );
        result->setMimetype( query.value( 10 ).toString() );
        result->setAlbumPos( query.value( 11 ).toUInt() );
        result->setScore( 1.0 );
        result->setCollection( s->collection() );

        TomahawkSqlQuery attrQuery = dbi->newquery();
        QVariantMap attr;

        attrQuery.prepare( "SELECT k, v FROM track_attributes WHERE id = ?" );
        attrQuery.bindValue( 0, result->dbid() );
        attrQuery.exec();
        while ( attrQuery.next() )
        {
            attr[ attrQuery.value( 0 ).toString() ] = attrQuery.value( 1 ).toString();
        }

        result->setAttributes( attr );

        QList<Tomahawk::result_ptr> results;
        results << result;
        qry->addResults( results );
        qry->setResolveFinished( true );

        ql << qry;
    }

    qDebug() << Q_FUNC_INFO << ql.length();

    emit tracks( ql, data() );
    emit done( m_collection );
}
void
RecentlyAddedModel::onSourceAdded( const Tomahawk::source_ptr& source )
{
    connect( source->collection().data(), SIGNAL( changed() ), SLOT( loadHistory() ) );
}
Exemple #8
0
void
WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source )
{
    connect( source->collection().data(), SIGNAL( changed() ), SLOT( updateRecentAdditions() ), Qt::UniqueConnection );
}