mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
* Added basic WelcomeWidget, which gets shown when Tomahawk starts up. Again, work in progress.
This commit is contained in:
@@ -97,6 +97,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
|||||||
infowidgets/sourceinfowidget.cpp
|
infowidgets/sourceinfowidget.cpp
|
||||||
|
|
||||||
widgets/newplaylistwidget.cpp
|
widgets/newplaylistwidget.cpp
|
||||||
|
widgets/welcomewidget.cpp
|
||||||
|
|
||||||
transferview.cpp
|
transferview.cpp
|
||||||
tomahawkwindow.cpp
|
tomahawkwindow.cpp
|
||||||
@@ -176,6 +177,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
|||||||
infowidgets/sourceinfowidget.h
|
infowidgets/sourceinfowidget.h
|
||||||
|
|
||||||
widgets/newplaylistwidget.h
|
widgets/newplaylistwidget.h
|
||||||
|
widgets/welcomewidget.h
|
||||||
|
|
||||||
transferview.h
|
transferview.h
|
||||||
tomahawkwindow.h
|
tomahawkwindow.h
|
||||||
@@ -194,6 +196,7 @@ SET( tomahawkUI ${tomahawkUI}
|
|||||||
topbar/topbar.ui
|
topbar/topbar.ui
|
||||||
infowidgets/sourceinfowidget.ui
|
infowidgets/sourceinfowidget.ui
|
||||||
widgets/newplaylistwidget.ui
|
widgets/newplaylistwidget.ui
|
||||||
|
widgets/welcomewidget.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(
|
INCLUDE_DIRECTORIES(
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include "database/databasecommand_renameplaylist.h"
|
#include "database/databasecommand_renameplaylist.h"
|
||||||
|
|
||||||
#include "pipeline.h"
|
#include "pipeline.h"
|
||||||
|
#include "source.h"
|
||||||
#include "sourcelist.h"
|
#include "sourcelist.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
@@ -101,6 +102,22 @@ Playlist::create( const source_ptr& author,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
playlist_ptr
|
||||||
|
Playlist::load( const QString& guid )
|
||||||
|
{
|
||||||
|
playlist_ptr p;
|
||||||
|
|
||||||
|
foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() )
|
||||||
|
{
|
||||||
|
p = source->collection()->playlist( guid );
|
||||||
|
if ( !p.isNull() )
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Playlist::remove( const playlist_ptr& playlist )
|
Playlist::remove( const playlist_ptr& playlist )
|
||||||
{
|
{
|
||||||
|
@@ -90,6 +90,8 @@ friend class ::DatabaseCommand_SetPlaylistRevision;
|
|||||||
friend class ::DatabaseCommand_CreatePlaylist;
|
friend class ::DatabaseCommand_CreatePlaylist;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static Tomahawk::playlist_ptr load( const QString& guid );
|
||||||
|
|
||||||
// one CTOR is private, only called by DatabaseCommand_LoadAllPlaylists
|
// one CTOR is private, only called by DatabaseCommand_LoadAllPlaylists
|
||||||
static Tomahawk::playlist_ptr create( const source_ptr& author,
|
static Tomahawk::playlist_ptr create( const source_ptr& author,
|
||||||
const QString& guid,
|
const QString& guid,
|
||||||
|
@@ -198,6 +198,35 @@ TomahawkSettings::setPlaylistColumnSizes( const QList<QVariant>& cols )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList<Tomahawk::playlist_ptr>
|
||||||
|
TomahawkSettings::recentlyPlayedPlaylists() const
|
||||||
|
{
|
||||||
|
QStringList playlist_guids = value( "playlists/recentlyPlayed" ).toStringList();
|
||||||
|
|
||||||
|
QList<Tomahawk::playlist_ptr> playlists;
|
||||||
|
foreach( const QString& guid, playlist_guids )
|
||||||
|
{
|
||||||
|
Tomahawk::playlist_ptr pl = Tomahawk::Playlist::load( guid );
|
||||||
|
if ( !pl.isNull() )
|
||||||
|
playlists << pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return playlists;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TomahawkSettings::appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist )
|
||||||
|
{
|
||||||
|
QStringList playlist_guids = value( "playlists/recentlyPlayed" ).toStringList();
|
||||||
|
|
||||||
|
playlist_guids.removeAll( playlist->guid() );
|
||||||
|
playlist_guids.append( playlist->guid() );
|
||||||
|
|
||||||
|
setValue( "playlists/recentlyPlayed", playlist_guids );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TomahawkSettings::jabberAutoConnect() const
|
TomahawkSettings::jabberAutoConnect() const
|
||||||
{
|
{
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
|
#include "playlist.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience wrapper around QSettings for tomahawk-specific config
|
* Convenience wrapper around QSettings for tomahawk-specific config
|
||||||
*/
|
*/
|
||||||
@@ -29,9 +31,13 @@ public:
|
|||||||
QByteArray mainWindowState() const;
|
QByteArray mainWindowState() const;
|
||||||
void setMainWindowState( const QByteArray& state );
|
void setMainWindowState( const QByteArray& state );
|
||||||
|
|
||||||
|
/// Playlist stuff
|
||||||
QList<QVariant> playlistColumnSizes() const;
|
QList<QVariant> playlistColumnSizes() const;
|
||||||
void setPlaylistColumnSizes( const QList<QVariant>& cols );
|
void setPlaylistColumnSizes( const QList<QVariant>& cols );
|
||||||
|
|
||||||
|
QList<Tomahawk::playlist_ptr> recentlyPlayedPlaylists() const;
|
||||||
|
void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||||
|
|
||||||
/// Jabber settings
|
/// Jabber settings
|
||||||
bool jabberAutoConnect() const; /// true by default
|
bool jabberAutoConnect() const; /// true by default
|
||||||
void setJabberAutoConnect( bool autoconnect = false );
|
void setJabberAutoConnect( bool autoconnect = false );
|
||||||
|
@@ -17,9 +17,12 @@
|
|||||||
#include "albumproxymodel.h"
|
#include "albumproxymodel.h"
|
||||||
#include "albummodel.h"
|
#include "albummodel.h"
|
||||||
#include "sourcelist.h"
|
#include "sourcelist.h"
|
||||||
|
#include "tomahawksettings.h"
|
||||||
|
|
||||||
#include "infowidgets/sourceinfowidget.h"
|
#include "infowidgets/sourceinfowidget.h"
|
||||||
|
|
||||||
|
#include "widgets/welcomewidget.h"
|
||||||
|
|
||||||
#define FILTER_TIMEOUT 280
|
#define FILTER_TIMEOUT 280
|
||||||
|
|
||||||
|
|
||||||
@@ -63,11 +66,10 @@ PlaylistManager::PlaylistManager( QObject* parent )
|
|||||||
|
|
||||||
m_stack->addWidget( m_superCollectionView );
|
m_stack->addWidget( m_superCollectionView );
|
||||||
m_stack->addWidget( m_superAlbumView );
|
m_stack->addWidget( m_superAlbumView );
|
||||||
m_currentInterface = m_superCollectionView->proxyModel();
|
|
||||||
|
show( new WelcomeWidget() );
|
||||||
|
|
||||||
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
|
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
|
||||||
|
|
||||||
linkPlaylist();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -116,6 +118,8 @@ PlaylistManager::show( const Tomahawk::playlist_ptr& playlist )
|
|||||||
m_modesAvailable = false;
|
m_modesAvailable = false;
|
||||||
linkPlaylist();
|
linkPlaylist();
|
||||||
|
|
||||||
|
TomahawkSettings::instance()->appendRecentlyPlayedPlaylist( playlist );
|
||||||
|
|
||||||
emit numSourcesChanged( SourceList::instance()->count() );
|
emit numSourcesChanged( SourceList::instance()->count() );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
164
src/widgets/welcomewidget.cpp
Normal file
164
src/widgets/welcomewidget.cpp
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
#include "welcomewidget.h"
|
||||||
|
#include "ui_welcomewidget.h"
|
||||||
|
|
||||||
|
#include "tomahawk/tomahawkapp.h"
|
||||||
|
#include "utils/tomahawkutils.h"
|
||||||
|
|
||||||
|
#include "playlist/playlistmanager.h"
|
||||||
|
#include "playlist/playlistmodel.h"
|
||||||
|
|
||||||
|
#include "sourcelist.h"
|
||||||
|
#include "tomahawksettings.h"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
#define FILTER_TIMEOUT 280
|
||||||
|
|
||||||
|
|
||||||
|
WelcomeWidget::WelcomeWidget( QWidget* parent )
|
||||||
|
: QWidget( parent )
|
||||||
|
, ui( new Ui::WelcomeWidget )
|
||||||
|
{
|
||||||
|
ui->setupUi( this );
|
||||||
|
ui->playlistWidget->setItemDelegate( new PlaylistDelegate() );
|
||||||
|
|
||||||
|
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
||||||
|
|
||||||
|
connect( ui->playlistWidget, SIGNAL( itemActivated( QListWidgetItem* ) ), SLOT( onPlaylistActivated( QListWidgetItem* ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WelcomeWidget::~WelcomeWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
WelcomeWidget::updatePlaylists()
|
||||||
|
{
|
||||||
|
ui->playlistWidget->clear();
|
||||||
|
|
||||||
|
QList<Tomahawk::playlist_ptr> playlists = TomahawkSettings::instance()->recentlyPlayedPlaylists();
|
||||||
|
|
||||||
|
foreach( const Tomahawk::playlist_ptr& playlist, playlists )
|
||||||
|
{
|
||||||
|
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( updatePlaylists() ) );
|
||||||
|
|
||||||
|
PlaylistWidgetItem* item = new PlaylistWidgetItem( playlist );
|
||||||
|
ui->playlistWidget->addItem( item );
|
||||||
|
item->setData( Qt::DisplayRole, playlist->title() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||||
|
{
|
||||||
|
connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ), SLOT( updatePlaylists() ) );
|
||||||
|
connect( source->collection().data(), SIGNAL( playlistsDeleted( QList<Tomahawk::playlist_ptr> ) ), SLOT( updatePlaylists() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
WelcomeWidget::onPlaylistActivated( QListWidgetItem* item )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
PlaylistWidgetItem* pwi = dynamic_cast<PlaylistWidgetItem*>(item);
|
||||||
|
APP->playlistManager()->show( pwi->playlist() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
WelcomeWidget::changeEvent( QEvent* e )
|
||||||
|
{
|
||||||
|
QWidget::changeEvent( e );
|
||||||
|
switch ( e->type() )
|
||||||
|
{
|
||||||
|
case QEvent::LanguageChange:
|
||||||
|
ui->retranslateUi( this );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
PlaylistWidgetItem::data( int role ) const
|
||||||
|
{
|
||||||
|
if ( role == ArtistRole )
|
||||||
|
{
|
||||||
|
if ( m_artists.isEmpty() )
|
||||||
|
{
|
||||||
|
QStringList artists;
|
||||||
|
|
||||||
|
foreach( const Tomahawk::plentry_ptr& entry, m_playlist->entries() )
|
||||||
|
{
|
||||||
|
if ( !artists.contains( entry->query()->artist() ) )
|
||||||
|
artists << entry->query()->artist();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_artists = artists.join( ", " );
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_artists;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( role == TrackCountRole )
|
||||||
|
{
|
||||||
|
return m_playlist->entries().count();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( role == Qt::DisplayRole )
|
||||||
|
{
|
||||||
|
return m_playlist->title();
|
||||||
|
}
|
||||||
|
|
||||||
|
return QListWidgetItem::data( role );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSize
|
||||||
|
PlaylistDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
return QSize( 0, 64 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption( &opt, QModelIndex() );
|
||||||
|
APP->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
|
||||||
|
|
||||||
|
if ( option.state & QStyle::State_Selected )
|
||||||
|
{
|
||||||
|
opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
painter->setRenderHint( QPainter::Antialiasing );
|
||||||
|
painter->setPen( opt.palette.color( QPalette::Text ) );
|
||||||
|
|
||||||
|
QTextOption to;
|
||||||
|
to.setAlignment( Qt::AlignCenter );
|
||||||
|
QFont font = opt.font;
|
||||||
|
QFont boldFont = opt.font;
|
||||||
|
boldFont.setBold( true );
|
||||||
|
|
||||||
|
painter->drawPixmap( option.rect.adjusted( 10, 12, -option.rect.width() + 42, -12 ), m_playlistIcon );
|
||||||
|
|
||||||
|
painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), index.data( PlaylistWidgetItem::ArtistRole ).toString() );
|
||||||
|
|
||||||
|
QString trackCount = tr( "%1 tracks" ).arg( index.data( PlaylistWidgetItem::TrackCountRole ).toString() );
|
||||||
|
painter->drawText( option.rect.adjusted( option.rect.width() - 96, 2, 0, -2 ), trackCount, to );
|
||||||
|
|
||||||
|
painter->setFont( boldFont );
|
||||||
|
painter->drawText( option.rect.adjusted( 56, 6, -100, -option.rect.height() + 20 ), index.data().toString() );
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
85
src/widgets/welcomewidget.h
Normal file
85
src/widgets/welcomewidget.h
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#ifndef WELCOMEWIDGET_H
|
||||||
|
#define WELCOMEWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include "tomahawk/tomahawkapp.h"
|
||||||
|
#include "playlistinterface.h"
|
||||||
|
|
||||||
|
#include "playlist.h"
|
||||||
|
#include "result.h"
|
||||||
|
|
||||||
|
class PlaylistModel;
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class WelcomeWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlaylistDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
PlaylistDelegate()
|
||||||
|
{
|
||||||
|
m_playlistIcon = QPixmap( RESPATH "images/playlist-icon.png" );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPixmap m_playlistIcon;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class PlaylistWidgetItem : public QListWidgetItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum ItemRoles
|
||||||
|
{ ArtistRole = Qt::UserRole, TrackCountRole };
|
||||||
|
|
||||||
|
PlaylistWidgetItem( const Tomahawk::playlist_ptr& playlist ) : QListWidgetItem() { m_playlist = playlist; }
|
||||||
|
~PlaylistWidgetItem() {}
|
||||||
|
|
||||||
|
virtual QVariant data( int role ) const;
|
||||||
|
|
||||||
|
Tomahawk::playlist_ptr playlist() const { return m_playlist; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Tomahawk::playlist_ptr m_playlist;
|
||||||
|
|
||||||
|
mutable QString m_artists;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class WelcomeWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
WelcomeWidget( QWidget* parent = 0 );
|
||||||
|
~WelcomeWidget();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent( QEvent* e );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void destroyed( QWidget* widget );
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updatePlaylists();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||||
|
void onPlaylistActivated( QListWidgetItem* item );
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::WelcomeWidget *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WELCOMEWIDGET_H
|
50
src/widgets/welcomewidget.ui
Normal file
50
src/widgets/welcomewidget.ui
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>WelcomeWidget</class>
|
||||||
|
<widget class="QWidget" name="WelcomeWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>985</width>
|
||||||
|
<height>460</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="captionLabel">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>20</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Welcome to Tomahawk!</string>
|
||||||
|
</property>
|
||||||
|
<property name="scaledContents">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>14</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Recently played playlists:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="playlistWidget"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Reference in New Issue
Block a user