1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 22:56:42 +02:00

* Added a WIP short style for our TrackViews.

This commit is contained in:
Christian Muehlhaeuser
2011-06-17 01:44:22 +02:00
parent 32f6a42791
commit d7d97d60db
17 changed files with 250 additions and 83 deletions

View File

@@ -39,7 +39,7 @@ Database::Database( const QString& dbname, QObject* parent )
{ {
s_instance = this; s_instance = this;
m_maxConcurrentThreads = qBound( DEFAULT_WORKER_THREADS, QThread::idealThreadCount() * 2, MAX_WORKER_THREADS ); m_maxConcurrentThreads = qBound( DEFAULT_WORKER_THREADS, QThread::idealThreadCount(), MAX_WORKER_THREADS );
qDebug() << Q_FUNC_INFO << "Using" << m_maxConcurrentThreads << "threads"; qDebug() << Q_FUNC_INFO << "Using" << m_maxConcurrentThreads << "threads";
connect( m_impl, SIGNAL( indexReady() ), SIGNAL( indexReady() ) ); connect( m_impl, SIGNAL( indexReady() ), SIGNAL( indexReady() ) );

View File

@@ -21,6 +21,7 @@
#include <QSqlQuery> #include <QSqlQuery>
#include "databaseimpl.h" #include "databaseimpl.h"
#include "sourcelist.h"
void void
@@ -36,7 +37,7 @@ DatabaseCommand_PlaybackHistory::exec( DatabaseImpl* dbi )
} }
QString sql = QString( QString sql = QString(
"SELECT track, playtime, secs_played " "SELECT track, playtime, secs_played, source "
"FROM playback_log " "FROM playback_log "
"%1 " "%1 "
"ORDER BY playtime DESC " "ORDER BY playtime DESC "
@@ -63,6 +64,16 @@ DatabaseCommand_PlaybackHistory::exec( DatabaseImpl* dbi )
if ( query_track.next() ) if ( query_track.next() )
{ {
Tomahawk::query_ptr q = Tomahawk::Query::get( query_track.value( 1 ).toString(), query_track.value( 0 ).toString(), QString(), uuid() ); Tomahawk::query_ptr q = Tomahawk::Query::get( query_track.value( 1 ).toString(), query_track.value( 0 ).toString(), QString(), uuid() );
if ( query.value( 3 ).toUInt() == 0 )
{
q->setPlayedBy( SourceList::instance()->getLocal() );
}
else
{
q->setPlayedBy( SourceList::instance()->get( query.value( 3 ).toUInt() ) );
}
ql << q; ql << q;
} }
} }

View File

@@ -24,6 +24,9 @@
#include "query.h" #include "query.h"
#include "result.h" #include "result.h"
#include "artist.h"
#include "source.h"
#include "sourcelist.h"
#include "trackmodelitem.h" #include "trackmodelitem.h"
#include "trackproxymodel.h" #include "trackproxymodel.h"
@@ -37,7 +40,6 @@
PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel* proxy ) PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel* proxy )
: QStyledItemDelegate( (QObject*)parent ) : QStyledItemDelegate( (QObject*)parent )
, m_style( Detailed )
, m_view( parent ) , m_view( parent )
, m_model( proxy ) , m_model( proxy )
{ {
@@ -45,13 +47,6 @@ PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel*
} }
void
PlaylistItemDelegate::setStyle( PlaylistItemDelegate::PlaylistItemStyle style )
{
m_style = style;
}
void void
PlaylistItemDelegate::updateRowSize( const QModelIndex& index ) PlaylistItemDelegate::updateRowSize( const QModelIndex& index )
{ {
@@ -63,6 +58,14 @@ QSize
PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
QSize size = QStyledItemDelegate::sizeHint( option, index ); QSize size = QStyledItemDelegate::sizeHint( option, index );
if ( index.isValid() )
{
int style = index.data( TrackModel::StyleRole ).toInt();
if ( style == TrackModel::Short )
size.setHeight( 48 );
}
return size; return size;
} }
@@ -77,16 +80,50 @@ PlaylistItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem&
} }
void
PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index ) const
{
initStyleOption( option, index );
TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
if ( item->isPlaying() )
{
option->palette.setColor( QPalette::Highlight, option->palette.color( QPalette::Mid ) );
option->state |= QStyle::State_Selected;
}
if ( item->isPlaying() || index.column() == TrackModel::Score )
option->text.clear();
if ( option->state & QStyle::State_Selected )
{
option->palette.setColor( QPalette::Text, option->palette.color( QPalette::HighlightedText ) );
}
else
{
float opacity = 0.0;
if ( item->query()->results().count() )
opacity = item->query()->results().first()->score();
opacity = qMax( (float)0.3, opacity );
QColor textColor = TomahawkUtils::alphaBlend( option->palette.color( QPalette::Foreground ), option->palette.color( QPalette::Background ), opacity );
option->palette.setColor( QPalette::Text, textColor );
}
}
void void
PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
switch ( m_style ) int style = index.data( TrackModel::StyleRole ).toInt();
switch ( style )
{ {
case Detailed: case TrackModel::Detailed:
paintDetailed( painter, option, index ); paintDetailed( painter, option, index );
break; break;
case Short: case TrackModel::Short:
paintShort( painter, option, index ); paintShort( painter, option, index );
break; break;
} }
@@ -96,7 +133,85 @@ PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& opti
void void
PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
Q_ASSERT( item );
QStyleOptionViewItemV4 opt = option;
prepareStyleOption( &opt, index );
opt.text.clear();
qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
if ( m_view->header()->visualIndex( index.column() ) > 0 )
return;
QPixmap pixmap;
QString artist, track, upperText, lowerText;
if ( item->query()->results().count() )
{
artist = item->query()->results().first()->artist()->name();
track = item->query()->results().first()->track();
}
else
{
artist = item->query()->artist();
track = item->query()->track();
}
if ( item->query()->playedBy().isNull() )
{
upperText = artist;
lowerText = track;
}
else
{
upperText = QString( "%1 - %2" ).arg( artist ).arg( track );
if ( item->query()->playedBy() == SourceList::instance()->getLocal() )
lowerText = QString( "played by you" );
else
lowerText = QString( "played by %1" ).arg( item->query()->playedBy()->friendlyName() );
pixmap = item->query()->playedBy()->avatar();
}
if ( pixmap.isNull() )
pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" );
painter->save();
{
QRect r = opt.rect.adjusted( 3, 6, 0, -6 );
// Paint Now Playing Speaker Icon
if ( item->isPlaying() )
{
r.adjust( 0, 0, 0, 0 );
QRect npr = r.adjusted( 3, r.height() / 2 - m_nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() + m_nowPlayingIcon.height() / 2 );
painter->drawPixmap( npr, m_nowPlayingIcon );
r.adjust( 22, 0, 0, 0 );
}
painter->setPen( opt.palette.text().color() );
QRect ir = r.adjusted( 4, 0, -option.rect.width() + option.rect.height() - 8 + r.left(), 0 );
painter->drawPixmap( ir, pixmap );
//painter->drawPixmap( ir, item->cover );
QFont boldFont = opt.font;
boldFont.setBold( true );
r.adjust( ir.width() + 12, 0, 0, 0 );
QTextOption to( Qt::AlignTop );
QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() - 3 );
painter->setFont( boldFont );
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to );
to.setAlignment( Qt::AlignBottom );
text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() - 3 );
painter->setFont( opt.font );
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to );
}
painter->restore();
} }
@@ -104,30 +219,10 @@ void
PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) ); TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
if ( !item || item->query().isNull() ) Q_ASSERT( item );
return;
float opacity = 0.0;
if ( item->query()->results().count() )
opacity = item->query()->results().first()->score();
opacity = qMax( (float)0.3, opacity );
QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity );
QStyleOptionViewItemV4 opt = option; QStyleOptionViewItemV4 opt = option;
initStyleOption( &opt, index ); prepareStyleOption( &opt, index );
if ( item->isPlaying() )
{
opt.palette.setColor( QPalette::Highlight, opt.palette.color( QPalette::Mid ) );
opt.state |= QStyle::State_Selected;
}
if ( item->isPlaying() || index.column() == TrackModel::Score )
opt.text.clear();
if ( opt.state & QStyle::State_Selected )
opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
else
opt.palette.setColor( QPalette::Text, textColor );
qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
@@ -139,7 +234,7 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
else else
painter->setPen( opt.palette.highlight().color() ); painter->setPen( opt.palette.highlight().color() );
QRect r = opt.rect.adjusted( 3, 3, -6, -5 ); QRect r = opt.rect.adjusted( 3, 3, -6, -4 );
painter->drawRect( r ); painter->drawRect( r );
QRect fillR = r; QRect fillR = r;
@@ -172,16 +267,6 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 ); QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to ); painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to );
} }
// Paint Now Playing Frame
/* {
QRect r = QRect( 3, opt.rect.y() + 1, m_view->viewport()->width() - 6, opt.rect.height() - 2 );
painter->setPen( opt.palette.highlight().color() );
QPen pen = painter->pen();
pen.setWidth( 1.0 );
painter->setPen( pen );
painter->drawRoundedRect( r, 3.0, 3.0 );
}*/
} }
painter->restore(); painter->restore();
} }

View File

@@ -21,6 +21,8 @@
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include "trackmodel.h"
#include "dllmacro.h" #include "dllmacro.h"
class TrackProxyModel; class TrackProxyModel;
@@ -31,12 +33,8 @@ class DLLEXPORT PlaylistItemDelegate : public QStyledItemDelegate
Q_OBJECT Q_OBJECT
public: public:
enum PlaylistItemStyle
{ Detailed = 0, Short = 1 };
PlaylistItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 ); PlaylistItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 );
void setStyle( PlaylistItemDelegate::PlaylistItemStyle style );
void updateRowSize( const QModelIndex& index ); void updateRowSize( const QModelIndex& index );
public slots: public slots:
@@ -48,13 +46,14 @@ protected:
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private: private:
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index ) const;
void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
void paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; void paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
unsigned int m_removalProgress; unsigned int m_removalProgress;
QPixmap m_nowPlayingIcon; QPixmap m_nowPlayingIcon;
PlaylistItemStyle m_style;
TrackView* m_view; TrackView* m_view;
TrackProxyModel* m_model; TrackProxyModel* m_model;
}; };

View File

@@ -72,7 +72,7 @@ PlaylistView::setPlaylistModel( PlaylistModel* model )
setGuid( QString( "playlistview/%1" ).arg( m_model->playlist()->guid() ) ); setGuid( QString( "playlistview/%1" ).arg( m_model->playlist()->guid() ) );
else else
{ {
setGuid( "playlistview" ); setGuid( QString( "playlistview/%1" ).arg( m_model->columnCount() ) );
} }
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) ); connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );

View File

@@ -87,7 +87,7 @@ TrackHeader::checkState()
else else
{ {
QList< double > m_columnWeights; QList< double > m_columnWeights;
m_columnWeights << 0.20 << 0.20 << 0.18 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.12; // << 0.05; m_columnWeights << 0.20 << 0.20 << 0.18 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.10; // << 0.05;
for ( int i = 0; i < count() - 1; i++ ) for ( int i = 0; i < count() - 1; i++ )
{ {

View File

@@ -35,6 +35,7 @@ TrackModel::TrackModel( QObject* parent )
: QAbstractItemModel( parent ) : QAbstractItemModel( parent )
, m_rootItem( new TrackModelItem( 0, this ) ) , m_rootItem( new TrackModelItem( 0, this ) )
, m_readOnly( true ) , m_readOnly( true )
, m_style( Detailed )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
@@ -82,7 +83,18 @@ int
TrackModel::columnCount( const QModelIndex& parent ) const TrackModel::columnCount( const QModelIndex& parent ) const
{ {
Q_UNUSED( parent ); Q_UNUSED( parent );
switch ( m_style )
{
case Short:
return 1;
break;
case Detailed:
default:
return 10; return 10;
break;
}
} }
@@ -123,6 +135,11 @@ TrackModel::data( const QModelIndex& index, int role ) const
return QSize( 0, 18 ); return QSize( 0, 18 );
} }
if ( role == StyleRole )
{
return m_style;
}
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole ) if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
return QVariant(); return QVariant();
@@ -373,3 +390,10 @@ TrackModel::ensureResolved()
Pipeline::instance()->resolve( query ); Pipeline::instance()->resolve( query );
} }
} }
void
TrackModel::setStyle( TrackModel::TrackItemStyle style )
{
m_style = style;
}

View File

@@ -33,6 +33,12 @@ class DLLEXPORT TrackModel : public QAbstractItemModel
Q_OBJECT Q_OBJECT
public: public:
enum TrackItemStyle
{ Detailed = 0, Short = 1 };
enum TrackModelRole
{ StyleRole = Qt::UserRole + 1 };
enum Columns { enum Columns {
Artist = 0, Artist = 0,
Track = 1, Track = 1,
@@ -49,6 +55,9 @@ public:
explicit TrackModel( QObject* parent = 0 ); explicit TrackModel( QObject* parent = 0 );
virtual ~TrackModel(); virtual ~TrackModel();
TrackModel::TrackItemStyle style() const { return m_style; }
void setStyle( TrackModel::TrackItemStyle style );
virtual QModelIndex index( int row, int column, const QModelIndex& parent ) const; virtual QModelIndex index( int row, int column, const QModelIndex& parent ) const;
virtual QModelIndex parent( const QModelIndex& child ) const; virtual QModelIndex parent( const QModelIndex& child ) const;
@@ -116,6 +125,8 @@ private:
QString m_title; QString m_title;
QString m_description; QString m_description;
TrackItemStyle m_style;
}; };
#endif // TRACKMODEL_H #endif // TRACKMODEL_H

View File

@@ -140,6 +140,9 @@ TrackView::setTrackModel( TrackModel* model )
connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) ); connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) );
setAcceptDrops( true ); setAcceptDrops( true );
if ( model->style() == TrackModel::Short )
setHeaderHidden( true );
} }
@@ -179,6 +182,7 @@ TrackView::onItemResized( const QModelIndex& index )
m_delegate->updateRowSize( index ); m_delegate->updateRowSize( index );
} }
void void
TrackView::playItem() TrackView::playItem()
{ {

View File

@@ -38,7 +38,7 @@ class DLLEXPORT TrackView : public QTreeView
Q_OBJECT Q_OBJECT
public: public:
explicit TrackView( QWidget* parent = 0 ); explicit TrackView( QWidget* parent = 0 );
~TrackView(); ~TrackView();
virtual QString guid() const { return m_guid; } virtual QString guid() const { return m_guid; }

View File

@@ -100,20 +100,15 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setPen( opt.palette.color( QPalette::Text ) ); painter->setPen( opt.palette.color( QPalette::Text ) );
QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 ); QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 );
// painter->drawPixmap( option.rect.adjusted( 4, 4, -4, -38 ), QPixmap( RESPATH "images/cover-shadow.png" ) ); // painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) );
painter->drawPixmap( r, item->cover ); painter->drawPixmap( r, item->cover );
QTextOption to; QTextOption to;
to.setAlignment( Qt::AlignVCenter ); to.setAlignment( Qt::AlignVCenter );
QFont font = opt.font;
QFont boldFont = opt.font;
boldFont.setBold( true );
r = option.rect.adjusted( option.rect.height(), 6, -4, -option.rect.height() + 22 ); r = option.rect.adjusted( option.rect.height(), 6, -4, -option.rect.height() + 22 );
text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() ); text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() );
painter->drawText( r, text, to ); painter->drawText( r, text, to );
// painter->setFont( boldFont );
painter->restore(); painter->restore();
} }

View File

@@ -91,6 +91,7 @@ SourceList::setSources( const QList<Tomahawk::source_ptr>& sources )
} }
qDebug() << Q_FUNC_INFO << "- Total sources now:" << m_sources.size(); qDebug() << Q_FUNC_INFO << "- Total sources now:" << m_sources.size();
emit ready();
} }

View File

@@ -76,6 +76,7 @@ TomahawkSettings::~TomahawkSettings()
s_instance = 0; s_instance = 0;
} }
void void
TomahawkSettings::doInitialSetup() TomahawkSettings::doInitialSetup()
{ {
@@ -236,18 +237,21 @@ TomahawkSettings::setWatchForChanges( bool watch )
setValue( "scanner/watchforchanges", watch ); setValue( "scanner/watchforchanges", watch );
} }
void void
TomahawkSettings::setAcceptedLegalWarning( bool accept ) TomahawkSettings::setAcceptedLegalWarning( bool accept )
{ {
setValue( "acceptedLegalWarning", accept ); setValue( "acceptedLegalWarning", accept );
} }
bool bool
TomahawkSettings::acceptedLegalWarning() const TomahawkSettings::acceptedLegalWarning() const
{ {
return value( "acceptedLegalWarning", false ).toBool(); return value( "acceptedLegalWarning", false ).toBool();
} }
bool bool
TomahawkSettings::httpEnabled() const TomahawkSettings::httpEnabled() const
{ {
@@ -429,18 +433,21 @@ TomahawkSettings::setPlaylistColumnSizes( const QString& playlistid, const QByte
setValue( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ), state ); setValue( QString( "ui/playlist/%1/columnSizes" ).arg( playlistid ), state );
} }
bool bool
TomahawkSettings::shuffleState( const QString& playlistid ) const TomahawkSettings::shuffleState( const QString& playlistid ) const
{ {
return value( QString( "ui/playlist/%1/shuffleState" ).arg( playlistid )).toBool(); return value( QString( "ui/playlist/%1/shuffleState" ).arg( playlistid )).toBool();
} }
void void
TomahawkSettings::setShuffleState( const QString& playlistid, bool state) TomahawkSettings::setShuffleState( const QString& playlistid, bool state)
{ {
setValue( QString( "ui/playlist/%1/shuffleState" ).arg( playlistid ), state ); setValue( QString( "ui/playlist/%1/shuffleState" ).arg( playlistid ), state );
} }
void void
TomahawkSettings::removePlaylistSettings( const QString& playlistid ) TomahawkSettings::removePlaylistSettings( const QString& playlistid )
{ {
@@ -448,27 +455,30 @@ TomahawkSettings::removePlaylistSettings( const QString& playlistid )
remove( QString( "ui/playlist/%1/repeatMode" ).arg( playlistid ) ); remove( QString( "ui/playlist/%1/repeatMode" ).arg( playlistid ) );
} }
void void
TomahawkSettings::setRepeatMode( const QString& playlistid, PlaylistInterface::RepeatMode mode ) TomahawkSettings::setRepeatMode( const QString& playlistid, Tomahawk::PlaylistInterface::RepeatMode mode )
{ {
setValue( QString( "ui/playlist/%1/repeatMode" ).arg( playlistid ), (int)mode ); setValue( QString( "ui/playlist/%1/repeatMode" ).arg( playlistid ), (int)mode );
} }
PlaylistInterface::RepeatMode
Tomahawk::PlaylistInterface::RepeatMode
TomahawkSettings::repeatMode( const QString& playlistid ) TomahawkSettings::repeatMode( const QString& playlistid )
{ {
return (PlaylistInterface::RepeatMode)value( QString( "ui/playlist/%1/repeatMode" ).arg( playlistid )).toInt(); return (PlaylistInterface::RepeatMode)value( QString( "ui/playlist/%1/repeatMode" ).arg( playlistid )).toInt();
} }
QList<Tomahawk::playlist_ptr> QList<Tomahawk::playlist_ptr>
TomahawkSettings::recentlyPlayedPlaylists() const TomahawkSettings::recentlyPlayedPlaylists() const
{ {
QStringList playlist_guids = value( "playlists/recentlyPlayed" ).toStringList(); QStringList playlist_guids = value( "playlists/recentlyPlayed" ).toStringList();
QList<Tomahawk::playlist_ptr> playlists; QList<playlist_ptr> playlists;
foreach( const QString& guid, playlist_guids ) foreach( const QString& guid, playlist_guids )
{ {
Tomahawk::playlist_ptr pl = Tomahawk::Playlist::load( guid ); playlist_ptr pl = Playlist::load( guid );
if ( !pl.isNull() ) if ( !pl.isNull() )
playlists << pl; playlists << pl;
} }
@@ -476,6 +486,7 @@ TomahawkSettings::recentlyPlayedPlaylists() const
return playlists; return playlists;
} }
QStringList QStringList
TomahawkSettings::recentlyPlayedPlaylistGuids( unsigned int amount ) const TomahawkSettings::recentlyPlayedPlaylistGuids( unsigned int amount ) const
{ {
@@ -501,42 +512,49 @@ TomahawkSettings::appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& pl
emit recentlyPlayedPlaylistAdded( playlist ); emit recentlyPlayedPlaylistAdded( playlist );
} }
QString QString
TomahawkSettings::bookmarkPlaylist() const TomahawkSettings::bookmarkPlaylist() const
{ {
return value( "playlists/bookmark", QString() ).toString(); return value( "playlists/bookmark", QString() ).toString();
} }
void void
TomahawkSettings::setBookmarkPlaylist( const QString& guid ) TomahawkSettings::setBookmarkPlaylist( const QString& guid )
{ {
setValue( "playlists/bookmark", guid ); setValue( "playlists/bookmark", guid );
} }
QStringList QStringList
TomahawkSettings::sipPlugins() const TomahawkSettings::sipPlugins() const
{ {
return value( "sip/allplugins", QStringList() ).toStringList(); return value( "sip/allplugins", QStringList() ).toStringList();
} }
void void
TomahawkSettings::setSipPlugins( const QStringList& plugins ) TomahawkSettings::setSipPlugins( const QStringList& plugins )
{ {
setValue( "sip/allplugins", plugins ); setValue( "sip/allplugins", plugins );
} }
QStringList QStringList
TomahawkSettings::enabledSipPlugins() const TomahawkSettings::enabledSipPlugins() const
{ {
return value( "sip/enabledplugins", QStringList() ).toStringList(); return value( "sip/enabledplugins", QStringList() ).toStringList();
} }
void void
TomahawkSettings::setEnabledSipPlugins( const QStringList& list ) TomahawkSettings::setEnabledSipPlugins( const QStringList& list )
{ {
setValue( "sip/enabledplugins", list ); setValue( "sip/enabledplugins", list );
} }
void void
TomahawkSettings::enableSipPlugin( const QString& pluginId ) TomahawkSettings::enableSipPlugin( const QString& pluginId )
{ {
@@ -545,6 +563,7 @@ TomahawkSettings::enableSipPlugin( const QString& pluginId )
setEnabledSipPlugins( list ); setEnabledSipPlugins( list );
} }
void void
TomahawkSettings::disableSipPlugin( const QString& pluginId ) TomahawkSettings::disableSipPlugin( const QString& pluginId )
{ {
@@ -553,6 +572,7 @@ TomahawkSettings::disableSipPlugin( const QString& pluginId )
setEnabledSipPlugins( list ); setEnabledSipPlugins( list );
} }
void void
TomahawkSettings::addSipPlugin( const QString& pluginId, bool enable ) TomahawkSettings::addSipPlugin( const QString& pluginId, bool enable )
{ {
@@ -564,6 +584,7 @@ TomahawkSettings::addSipPlugin( const QString& pluginId, bool enable )
enableSipPlugin( pluginId ); enableSipPlugin( pluginId );
} }
void void
TomahawkSettings::removeSipPlugin( const QString& pluginId ) TomahawkSettings::removeSipPlugin( const QString& pluginId )
{ {
@@ -589,40 +610,47 @@ TomahawkSettings::setExternalAddressMode( ExternalAddressMode externalAddressMod
setValue( "network/external-address-mode", externalAddressMode ); setValue( "network/external-address-mode", externalAddressMode );
} }
bool TomahawkSettings::preferStaticHostPort() const bool TomahawkSettings::preferStaticHostPort() const
{ {
return value( "network/prefer-static-host-and-port" ).toBool(); return value( "network/prefer-static-host-and-port" ).toBool();
} }
void TomahawkSettings::setPreferStaticHostPort( bool prefer ) void TomahawkSettings::setPreferStaticHostPort( bool prefer )
{ {
setValue( "network/prefer-static-host-and-port", prefer ); setValue( "network/prefer-static-host-and-port", prefer );
} }
QString QString
TomahawkSettings::externalHostname() const TomahawkSettings::externalHostname() const
{ {
return value( "network/external-hostname" ).toString(); return value( "network/external-hostname" ).toString();
} }
void void
TomahawkSettings::setExternalHostname(const QString& externalHostname) TomahawkSettings::setExternalHostname(const QString& externalHostname)
{ {
setValue( "network/external-hostname", externalHostname ); setValue( "network/external-hostname", externalHostname );
} }
int int
TomahawkSettings::defaultPort() const TomahawkSettings::defaultPort() const
{ {
return 50210; return 50210;
} }
int int
TomahawkSettings::externalPort() const TomahawkSettings::externalPort() const
{ {
return value( "network/external-port", 50210 ).toInt(); return value( "network/external-port", 50210 ).toInt();
} }
void void
TomahawkSettings::setExternalPort(int externalPort) TomahawkSettings::setExternalPort(int externalPort)
{ {
@@ -674,6 +702,7 @@ TomahawkSettings::setLastFmUsername( const QString& username )
setValue( "lastfm/username", username ); setValue( "lastfm/username", username );
} }
bool bool
TomahawkSettings::scrobblingEnabled() const TomahawkSettings::scrobblingEnabled() const
{ {
@@ -743,18 +772,21 @@ TomahawkSettings::setXmppBotPort( const int port )
setValue( "xmppBot/port", port ); setValue( "xmppBot/port", port );
} }
void void
TomahawkSettings::addScriptResolver(const QString& resolver) TomahawkSettings::addScriptResolver(const QString& resolver)
{ {
setValue( "script/resolvers", allScriptResolvers() << resolver ); setValue( "script/resolvers", allScriptResolvers() << resolver );
} }
QStringList QStringList
TomahawkSettings::allScriptResolvers() const TomahawkSettings::allScriptResolvers() const
{ {
return value( "script/resolvers" ).toStringList(); return value( "script/resolvers" ).toStringList();
} }
void void
TomahawkSettings::setAllScriptResolvers( const QStringList& resolver ) TomahawkSettings::setAllScriptResolvers( const QStringList& resolver )
{ {
@@ -768,12 +800,14 @@ TomahawkSettings::enabledScriptResolvers() const
return value( "script/loadedresolvers" ).toStringList(); return value( "script/loadedresolvers" ).toStringList();
} }
void void
TomahawkSettings::setEnabledScriptResolvers( const QStringList& resolvers ) TomahawkSettings::setEnabledScriptResolvers( const QStringList& resolvers )
{ {
setValue( "script/loadedresolvers", resolvers ); setValue( "script/loadedresolvers", resolvers );
} }
bool bool
TomahawkSettings::nowPlayingEnabled() const TomahawkSettings::nowPlayingEnabled() const
{ {

View File

@@ -41,23 +41,17 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
ui->historyView->overlay()->setEnabled( false ); ui->historyView->overlay()->setEnabled( false );
m_recentCollectionModel = new CollectionFlatModel( ui->recentCollectionView ); m_recentCollectionModel = new CollectionFlatModel( ui->recentCollectionView );
m_recentCollectionModel->setStyle( TrackModel::Short );
ui->recentCollectionView->setTrackModel( m_recentCollectionModel ); ui->recentCollectionView->setTrackModel( m_recentCollectionModel );
m_recentCollectionModel->addFilteredCollection( source->collection(), 250, DatabaseCommand_AllTracks::ModificationTime ); m_recentCollectionModel->addFilteredCollection( source->collection(), 250, DatabaseCommand_AllTracks::ModificationTime );
m_historyModel = new PlaylistModel( ui->historyView ); m_historyModel = new PlaylistModel( ui->historyView );
m_historyModel->setStyle( TrackModel::Short );
ui->historyView->setPlaylistModel( m_historyModel ); ui->historyView->setPlaylistModel( m_historyModel );
m_historyModel->loadHistory( source ); m_historyModel->loadHistory( source );
connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ) ); 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 ); m_recentAlbumModel = new AlbumModel( ui->recentAlbumView );
ui->recentAlbumView->setAlbumModel( m_recentAlbumModel ); ui->recentAlbumView->setAlbumModel( m_recentAlbumModel );
m_recentAlbumModel->addFilteredCollection( source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime ); m_recentAlbumModel->addFilteredCollection( source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime );

View File

@@ -50,19 +50,19 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
ui->playlistWidget->setItemDelegate( new PlaylistDelegate() ); ui->playlistWidget->setItemDelegate( new PlaylistDelegate() );
ui->playlistWidget->setModel( model ); ui->playlistWidget->setModel( model );
ui->playlistWidget->overlay()->resize( 380, 86 ); ui->playlistWidget->overlay()->resize( 380, 86 );
ui->tracksView->overlay()->setEnabled( false );
connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) ); connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) );
m_tracksModel = new PlaylistModel( ui->tracksView ); m_tracksModel = new PlaylistModel( ui->tracksView );
m_tracksModel->setStyle( TrackModel::Short );
ui->tracksView->overlay()->setEnabled( false );
ui->tracksView->setPlaylistModel( m_tracksModel ); ui->tracksView->setPlaylistModel( m_tracksModel );
m_tracksModel->loadHistory( Tomahawk::source_ptr(), HISTORY_TRACK_ITEMS );
m_timer = new QTimer( this ); m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) ); connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) );
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( updateRecentTracks() ) );
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) ); connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
connect( AudioEngine::instance() ,SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( updatePlaylists() ), Qt::QueuedConnection ); connect( AudioEngine::instance() ,SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( updatePlaylists() ), Qt::QueuedConnection );
} }
@@ -74,6 +74,13 @@ WelcomeWidget::~WelcomeWidget()
} }
void
WelcomeWidget::updateRecentTracks()
{
m_tracksModel->loadHistory( Tomahawk::source_ptr(), HISTORY_TRACK_ITEMS );
}
void void
WelcomeWidget::updatePlaylists() WelcomeWidget::updatePlaylists()
{ {
@@ -100,6 +107,7 @@ WelcomeWidget::updatePlaylists()
ui->playlistWidget->overlay()->hide(); ui->playlistWidget->overlay()->hide();
} }
void void
WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source ) WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source )
{ {

View File

@@ -96,6 +96,7 @@ signals:
void destroyed( QWidget* widget ); void destroyed( QWidget* widget );
public slots: public slots:
void updateRecentTracks();
void updatePlaylists(); void updatePlaylists();
private slots: private slots: