1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-28 11:42:42 +01:00

* Yay, even more WIP: New Home Screen.

This commit is contained in:
Christian Muehlhaeuser 2011-06-21 05:26:32 +02:00
parent c0a970872b
commit eb70419203
15 changed files with 242 additions and 90 deletions

View File

@ -84,7 +84,7 @@ DatabaseCommand_AllAlbums::execForCollection( DatabaseImpl* dbi )
{
TomahawkSqlQuery query = dbi->newquery();
QList<Tomahawk::album_ptr> al;
QString orderToken;
QString orderToken, sourceToken;
switch ( m_sortOrder )
{
@ -95,6 +95,9 @@ DatabaseCommand_AllAlbums::execForCollection( DatabaseImpl* dbi )
orderToken = "file.mtime";
}
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 sql = QString(
"SELECT DISTINCT album.id, album.name, album.artist, artist.name "
"FROM album, file, file_join "
@ -102,9 +105,9 @@ DatabaseCommand_AllAlbums::execForCollection( DatabaseImpl* dbi )
"ON album.artist = artist.id "
"WHERE file.id = file_join.file "
"AND file_join.album = album.id "
"AND file.source %1 "
"%1 "
"%2 %3 %4"
).arg( m_collection->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( m_collection->source()->id() ) )
).arg( sourceToken )
.arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( orderToken ) : QString() )
.arg( m_sortDescending ? "DESC" : QString() )
.arg( m_amount > 0 ? QString( "LIMIT 0, %1" ).arg( m_amount ) : QString() );

View File

@ -294,7 +294,7 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
QString artistName = criteria["artist"];
QString albumName = criteria["album"];
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&autocorrect=1&size=medium&api_key=7a90f6672a04b809ee309af169f34b8b";
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&autocorrect=1&size=large&api_key=7a90f6672a04b809ee309af169f34b8b";
QNetworkRequest req( imgurl.arg( artistName ).arg( albumName ) );
QNetworkReply* reply = m_nam.data()->get( req );
reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -37,6 +37,7 @@ AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel
, m_view( parent )
, m_model( proxy )
{
m_shadowPixmap = QPixmap( RESPATH "images/cover-shadow.png" );
}
@ -65,10 +66,10 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
}
painter->save();
painter->setRenderHint( QPainter::Antialiasing );
// painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( opt.palette.color( QPalette::Text ) );
painter->drawPixmap( option.rect.adjusted( 4, 4, -4, -38 ), QPixmap( RESPATH "images/cover-shadow.png" ) );
// painter->drawPixmap( option.rect.adjusted( 4, 4, -4, -38 ), m_shadowPixmap );
painter->drawPixmap( option.rect.adjusted( 6, 4, -6, -41 ), item->cover );
QTextOption to;

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -41,6 +41,8 @@ protected:
private:
QAbstractItemView* m_view;
AlbumProxyModel* m_model;
QPixmap m_shadowPixmap;
};
#endif // ALBUMITEMDELEGATE_H

View File

@ -29,6 +29,8 @@
#define LASTFM_DEFAULT_COVER "http://cdn.last.fm/flatness/catalogue/noimage"
static QString s_tmInfoIdentifier = QString( "ALBUMMODEL" );
using namespace Tomahawk;
@ -40,6 +42,12 @@ AlbumModel::AlbumModel( QObject* parent )
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
}
@ -109,6 +117,11 @@ AlbumModel::parent( const QModelIndex& child ) const
QVariant
AlbumModel::data( const QModelIndex& index, int role ) const
{
if ( role == Qt::SizeHintRole )
{
return QSize( 116, 150 );
}
AlbumItem* entry = itemFromIndex( index );
if ( !entry )
return QVariant();
@ -118,11 +131,6 @@ AlbumModel::data( const QModelIndex& index, int role ) const
return entry->cover;
}
if ( role == Qt::SizeHintRole )
{
return QSize( 116, 150 );
}
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
return QVariant();
@ -252,10 +260,10 @@ AlbumModel::addCollection( const collection_ptr& collection )
void
AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order )
{
qDebug() << Q_FUNC_INFO << collection->name()
/* qDebug() << Q_FUNC_INFO << collection->name()
<< collection->source()->id()
<< collection->source()->userName()
<< amount << order;
<< amount << order;*/
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
cmd->setLimit( amount );
@ -267,7 +275,10 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
m_title = tr( "All albums from %1" ).arg( collection->source()->friendlyName() );
if ( !collection.isNull() )
m_title = tr( "All albums from %1" ).arg( collection->source()->friendlyName() );
else
m_title = tr( "All albums" );
}
@ -291,12 +302,6 @@ AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums )
albumitem->cover = m_defaultCover;
albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem );
/* QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&size=large&api_key=7a90f6672a04b809ee309af169f34b8b";
QNetworkRequest req( imgurl.arg( album->artist()->name() ).arg( album->name() ) );
req.setAttribute( QNetworkRequest::User, (qlonglong)albumitem );
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
connect( reply, SIGNAL( finished() ), SLOT( onCoverArtDownloaded() ) );*/
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
}
@ -306,43 +311,51 @@ AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums )
void
AlbumModel::onCoverArtDownloaded()
AlbumModel::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData )
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
Q_UNUSED( customData );
qDebug() << Q_FUNC_INFO;
QUrl redir = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
if ( redir.isEmpty() )
if ( caller != s_tmInfoIdentifier ||
( type != Tomahawk::InfoSystem::InfoAlbumCoverArt && type != Tomahawk::InfoSystem::InfoArtistImages ) )
{
const QByteArray ba = reply->readAll();
if ( ba.length() )
{
QPixmap pm;
pm.loadFromData( ba );
qlonglong pptr = reply->request().attribute( QNetworkRequest::User ).toLongLong();
AlbumItem* ai = reinterpret_cast<AlbumItem*>(pptr);
if ( pm.isNull() || reply->url().toString().startsWith( LASTFM_DEFAULT_COVER ) )
{
ai->cover = m_defaultCover;
}
else
{
ai->setCover( pm.scaled( QSize( 150, 150 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
}
}
}
else
{
// Follow HTTP redirect
QNetworkRequest req( redir );
req.setAttribute( QNetworkRequest::User, reply->request().attribute( QNetworkRequest::User ) );
Q_ASSERT( TomahawkUtils::nam() != 0 );
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
connect( reply, SIGNAL( finished() ), SLOT( onCoverArtDownloaded() ) );
qDebug() << "Info of wrong type or not with our identifier";
return;
}
reply->deleteLater();
if ( !output.canConvert< Tomahawk::InfoSystem::InfoCustomData >() )
{
qDebug() << "Cannot convert fetched art from a QByteArray";
return;
}
Tomahawk::InfoSystem::InfoCriteriaHash pptr = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
Tomahawk::InfoSystem::InfoCustomData returnedData = output.value< Tomahawk::InfoSystem::InfoCustomData >();
const QByteArray ba = returnedData["imgbytes"].toByteArray();
if ( ba.length() )
{
QPixmap pm;
pm.loadFromData( ba );
bool ok;
qlonglong p = pptr["pptr"].toLongLong( &ok );
AlbumItem* ai = reinterpret_cast<AlbumItem*>(p);
if ( pm.isNull() )
ai->cover = m_defaultCover;
else
ai->cover = pm;
emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) );
}
}
void
AlbumModel::infoSystemFinished( QString target )
{
Q_UNUSED( target );
qDebug() << Q_FUNC_INFO;
}

View File

@ -26,6 +26,7 @@
#include "collection.h"
#include "playlistinterface.h"
#include "database/databasecommand_allalbums.h"
#include "infosystem/infosystem.h"
#include "albumitem.h"
@ -94,9 +95,11 @@ protected:
private slots:
void onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums );
void onCoverArtDownloaded();
void onDataChanged();
void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void infoSystemFinished( QString target );
private:
QPersistentModelIndex m_currentIndex;
AlbumItem* m_rootItem;

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -30,6 +30,10 @@
#include "albumitemdelegate.h"
#include "viewmanager.h"
static QString s_tmInfoIdentifier = QString( "ALBUMMODEL" );
#define SCROLL_TIMEOUT 280
using namespace Tomahawk;
@ -51,6 +55,12 @@ AlbumView::AlbumView( QWidget* parent )
setProxyModel( new AlbumProxyModel( this ) );
m_timer.setInterval( SCROLL_TIMEOUT );
connect( verticalScrollBar(), SIGNAL( rangeChanged( int, int ) ), SLOT( onViewChanged() ) );
connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), SLOT( onViewChanged() ) );
connect( &m_timer, SIGNAL( timeout() ), SLOT( onScrollTimeout() ) );
connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) );
}
@ -111,6 +121,55 @@ AlbumView::onItemActivated( const QModelIndex& index )
}
void
AlbumView::onViewChanged()
{
if ( m_timer.isActive() )
m_timer.stop();
m_timer.start();
}
void
AlbumView::onScrollTimeout()
{
qDebug() << Q_FUNC_INFO;
if ( m_timer.isActive() )
m_timer.stop();
if ( !m_proxyModel->rowCount() )
return;
QRect viewRect = viewport()->rect();
int rowHeight = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize().height();
viewRect.adjust( 0, -rowHeight, 0, rowHeight );
for ( int i = 0; i < m_proxyModel->rowCount(); i++ )
{
for ( int j = 0; j < m_proxyModel->columnCount(); j++ )
{
QModelIndex idx = m_proxyModel->index( i, j );
if ( !viewRect.contains( visualRect( idx ) ) )
break;
AlbumItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( idx ) );
if ( !item )
break;
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["artist"] = item->album()->artist()->name();
trackInfo["album"] = item->album()->name();
trackInfo["pptr"] = QString::number( (qlonglong)item );
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo(
s_tmInfoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() );
}
}
}
void
AlbumView::dragEnterEvent( QDragEnterEvent* event )
{

View File

@ -69,12 +69,17 @@ protected:
private slots:
void onFilterChanged( const QString& filter );
void onViewChanged();
void onScrollTimeout();
private:
QPixmap createDragPixmap( int itemCount ) const;
AlbumModel* m_model;
AlbumProxyModel* m_proxyModel;
// PlaylistItemDelegate* m_delegate;
QTimer m_timer;
};
#endif // ALBUMVIEW_H

View File

@ -232,6 +232,9 @@ ArtistView::onScrollTimeout()
if ( right.isValid() )
max = right.row() + 1;
if ( !max )
return;
for ( int i = left.row(); i < max; i++ )
{
TreeModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) );

View File

@ -133,7 +133,6 @@ TrackView::setTrackModel( TrackModel* model )
m_proxyModel->setSourceTrackModel( m_model );
}
if ( m_model && m_model->metaObject()->indexOfSignal( "itemSizeChanged(QModelIndex)" ) > -1 )
connect( m_model, SIGNAL( itemSizeChanged( QModelIndex ) ), SLOT( onItemResized( QModelIndex ) ) );
@ -145,7 +144,15 @@ TrackView::setTrackModel( TrackModel* model )
setAcceptDrops( true );
if ( model->style() == TrackModel::Short )
{
setHeaderHidden( true );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
}
else
{
setHeaderHidden( false );
setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
}
}

View File

@ -59,17 +59,11 @@ void
TreeModel::setCurrentItem( const QModelIndex& index )
{
qDebug() << Q_FUNC_INFO;
TreeModelItem* oldEntry = itemFromIndex( m_currentIndex );
if ( oldEntry )
{
// oldEntry->setIsPlaying( false );
}
TreeModelItem* entry = itemFromIndex( index );
if ( entry )
{
m_currentIndex = index;
// entry->setIsPlaying( true );
}
else
{

View File

@ -48,7 +48,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
m_historyModel = new PlaylistModel( ui->historyView );
m_historyModel->setStyle( TrackModel::Short );
ui->historyView->setPlaylistModel( m_historyModel );
m_historyModel->loadHistory( source );
m_historyModel->loadHistory( source, 25 );
connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ) );

View File

@ -23,6 +23,7 @@
#include "utils/tomahawkutils.h"
#include "viewmanager.h"
#include "playlist/albummodel.h"
#include "playlist/playlistmodel.h"
#include "widgets/overlaywidget.h"
@ -37,6 +38,8 @@
#define HISTORY_PLAYLIST_ITEMS 5
#define HISTORY_RESOLVING_TIMEOUT 2500
using namespace Tomahawk;
WelcomeWidget::WelcomeWidget( QWidget* parent )
: QWidget( parent )
@ -58,6 +61,10 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
ui->tracksView->overlay()->setEnabled( false );
ui->tracksView->setPlaylistModel( m_tracksModel );
m_recentAlbumsModel = new AlbumModel( ui->additionsView );
ui->additionsView->setAlbumModel( m_recentAlbumsModel );
m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime );
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) );

View File

@ -33,6 +33,7 @@
#include "dllmacro.h"
class AlbumModel;
class PlaylistModel;
class OverlayWidget;
@ -110,6 +111,8 @@ private:
Ui::WelcomeWidget *ui;
PlaylistModel* m_tracksModel;
AlbumModel* m_recentAlbumsModel;
QTimer* m_timer;
};

View File

@ -7,39 +7,86 @@
<x>0</x>
<y>0</y>
<width>985</width>
<height>460</height>
<height>459</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0,2">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="2,1">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Recently played playlists:</string>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWidget" name="">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Recent Additions</string>
</property>
</widget>
</item>
<item>
<widget class="AlbumView" name="additionsView"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Newest Stations &amp; Playlists</string>
</property>
</widget>
</item>
<item>
<widget class="PlaylistWidget" name="playlistWidget"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="PlaylistWidget" name="playlistWidget"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Recently played tracks:</string>
</property>
</widget>
</item>
<item>
<widget class="PlaylistView" name="tracksView"/>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Recently Played Tracks</string>
</property>
</widget>
</item>
<item>
<widget class="PlaylistView" name="tracksView">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@ -54,6 +101,11 @@
<extends>QListWidget</extends>
<header>widgets/welcomewidget.h</header>
</customwidget>
<customwidget>
<class>AlbumView</class>
<extends>QListView</extends>
<header>playlist/albumview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>