mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 14:46:33 +02:00
Use ViewPagePlugin and ViewPageLazyLoader as base for Dashboard
This commit is contained in:
@@ -13,7 +13,7 @@ list(APPEND ${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND ${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_UI
|
list(APPEND ${TOMAHAWK_WIDGETS_LIBRARY_TARGET}_UI
|
||||||
Dashboard.ui
|
DashboardWidget.ui
|
||||||
NetworkActivityWidget.ui
|
NetworkActivityWidget.ui
|
||||||
SocialPlaylistWidget.ui
|
SocialPlaylistWidget.ui
|
||||||
)
|
)
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Dashboard.h"
|
#include "Dashboard.h"
|
||||||
#include "ui_Dashboard.h"
|
#include "ui_DashboardWidget.h"
|
||||||
|
|
||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
@@ -52,8 +52,19 @@ using namespace Tomahawk::Widgets;
|
|||||||
|
|
||||||
|
|
||||||
Dashboard::Dashboard( QWidget* parent )
|
Dashboard::Dashboard( QWidget* parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Dashboard::~Dashboard()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DashboardWidget::DashboardWidget( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, ui( new Ui::Dashboard )
|
, ui( new Ui::DashboardWidget )
|
||||||
{
|
{
|
||||||
QWidget* widget = new QWidget;
|
QWidget* widget = new QWidget;
|
||||||
ui->setupUi( widget );
|
ui->setupUi( widget );
|
||||||
@@ -182,7 +193,7 @@ Dashboard::Dashboard( QWidget* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Dashboard::~Dashboard()
|
DashboardWidget::~DashboardWidget()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
@@ -191,17 +202,17 @@ Dashboard::~Dashboard()
|
|||||||
Tomahawk::playlistinterface_ptr
|
Tomahawk::playlistinterface_ptr
|
||||||
Dashboard::playlistInterface() const
|
Dashboard::playlistInterface() const
|
||||||
{
|
{
|
||||||
return m_playlistInterface;
|
return m_widget->m_playlistInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Dashboard::jumpToCurrentTrack()
|
Dashboard::jumpToCurrentTrack()
|
||||||
{
|
{
|
||||||
if ( ui->tracksView->jumpToCurrentTrack() )
|
if ( m_widget->ui->tracksView->jumpToCurrentTrack() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( ui->additionsView->jumpToCurrentTrack() )
|
if ( m_widget->ui->additionsView->jumpToCurrentTrack() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -211,15 +222,15 @@ Dashboard::jumpToCurrentTrack()
|
|||||||
bool
|
bool
|
||||||
Dashboard::isBeingPlayed() const
|
Dashboard::isBeingPlayed() const
|
||||||
{
|
{
|
||||||
if ( ui->additionsView->isBeingPlayed() )
|
if ( m_widget->ui->additionsView->isBeingPlayed() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return AudioEngine::instance()->currentTrackPlaylist() == ui->tracksView->playlistInterface();
|
return AudioEngine::instance()->currentTrackPlaylist() == m_widget->ui->tracksView->playlistInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Dashboard::onSourcesReady()
|
DashboardWidget::onSourcesReady()
|
||||||
{
|
{
|
||||||
foreach ( const source_ptr& source, SourceList::instance()->sources() )
|
foreach ( const source_ptr& source, SourceList::instance()->sources() )
|
||||||
onSourceAdded( source );
|
onSourceAdded( source );
|
||||||
@@ -229,21 +240,21 @@ Dashboard::onSourcesReady()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Dashboard::onSourceAdded( const Tomahawk::source_ptr& source )
|
DashboardWidget::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||||
{
|
{
|
||||||
connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( updateRecentAdditions() ), Qt::UniqueConnection );
|
connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( updateRecentAdditions() ), Qt::UniqueConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Dashboard::updateRecentAdditions()
|
DashboardWidget::updateRecentAdditions()
|
||||||
{
|
{
|
||||||
m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
|
m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Dashboard::updatePlaylists()
|
DashboardWidget::updatePlaylists()
|
||||||
{
|
{
|
||||||
int num = ui->playlistWidget->model()->rowCount( QModelIndex() );
|
int num = ui->playlistWidget->model()->rowCount( QModelIndex() );
|
||||||
if ( num == 0 )
|
if ( num == 0 )
|
||||||
@@ -257,7 +268,7 @@ Dashboard::updatePlaylists()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Dashboard::onPlaylistActivated( const QModelIndex& item )
|
DashboardWidget::onPlaylistActivated( const QModelIndex& item )
|
||||||
{
|
{
|
||||||
Tomahawk::playlist_ptr pl = item.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >();
|
Tomahawk::playlist_ptr pl = item.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >();
|
||||||
if ( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() )
|
if ( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() )
|
||||||
@@ -268,7 +279,7 @@ Dashboard::onPlaylistActivated( const QModelIndex& item )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Dashboard::changeEvent( QEvent* e )
|
DashboardWidget::changeEvent( QEvent* e )
|
||||||
{
|
{
|
||||||
QWidget::changeEvent( e );
|
QWidget::changeEvent( e );
|
||||||
switch ( e->type() )
|
switch ( e->type() )
|
||||||
@@ -283,9 +294,4 @@ Dashboard::changeEvent( QEvent* e )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QPixmap
|
Q_EXPORT_PLUGIN2( ViewPagePlugin, Dashboard )
|
||||||
Dashboard::pixmap() const
|
|
||||||
{
|
|
||||||
return ImageRegistry::instance()->pixmap( RESPATH "images/dashboard.svg",
|
|
||||||
TomahawkUtils::DpiScaler::scaled( this, 80, 80 ) );
|
|
||||||
}
|
|
||||||
|
@@ -20,18 +20,19 @@
|
|||||||
#ifndef DASHBOARD_H
|
#ifndef DASHBOARD_H
|
||||||
#define DASHBOARD_H
|
#define DASHBOARD_H
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QListWidgetItem>
|
|
||||||
#include <QStyledItemDelegate>
|
|
||||||
|
|
||||||
#include "PlaylistInterface.h"
|
#include "PlaylistInterface.h"
|
||||||
|
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "ViewPage.h"
|
#include "ViewPagePlugin.h"
|
||||||
|
#include "ViewPageLazyLoader.h"
|
||||||
|
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
#include "WidgetsDllMacro.h"
|
#include "WidgetsDllMacro.h"
|
||||||
|
|
||||||
class AlbumModel;
|
class AlbumModel;
|
||||||
@@ -41,7 +42,7 @@ class BasicHeader;
|
|||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class Dashboard;
|
class DashboardWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
@@ -49,31 +50,16 @@ namespace Tomahawk
|
|||||||
namespace Widgets
|
namespace Widgets
|
||||||
{
|
{
|
||||||
|
|
||||||
class TOMAHAWK_WIDGETS_EXPORT Dashboard : public QWidget, public Tomahawk::ViewPage
|
|
||||||
|
class DashboardWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
friend class Dashboard;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Dashboard( QWidget* parent = 0 );
|
DashboardWidget( QWidget* parent = 0 );
|
||||||
virtual ~Dashboard();
|
virtual ~DashboardWidget();
|
||||||
|
|
||||||
virtual QWidget* widget() { return this; }
|
|
||||||
virtual Tomahawk::playlistinterface_ptr playlistInterface() const;
|
|
||||||
|
|
||||||
virtual QString title() const { return tr( "Dashboard" ); }
|
|
||||||
virtual QString description() const { return tr( "An overview of your recent activity" ); }
|
|
||||||
virtual QPixmap pixmap() const;
|
|
||||||
|
|
||||||
virtual bool showInfoBar() const { return true; }
|
|
||||||
virtual bool isBeingPlayed() const;
|
|
||||||
|
|
||||||
virtual bool jumpToCurrentTrack();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void changeEvent( QEvent* e );
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void destroyed( QWidget* widget );
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updatePlaylists();
|
void updatePlaylists();
|
||||||
@@ -84,14 +70,44 @@ private slots:
|
|||||||
void onSourceAdded( const Tomahawk::source_ptr& source );
|
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||||
void onPlaylistActivated( const QModelIndex& );
|
void onPlaylistActivated( const QModelIndex& );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent( QEvent* e );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Dashboard *ui;
|
Ui::DashboardWidget *ui;
|
||||||
|
|
||||||
RecentlyPlayedModel* m_tracksModel;
|
RecentlyPlayedModel* m_tracksModel;
|
||||||
AlbumModel* m_recentAlbumsModel;
|
AlbumModel* m_recentAlbumsModel;
|
||||||
Tomahawk::playlistinterface_ptr m_playlistInterface;
|
Tomahawk::playlistinterface_ptr m_playlistInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const QString DASHBOARD_VIEWPAGE_NAME = "dashboard";
|
||||||
|
|
||||||
|
class TOMAHAWK_WIDGETS_EXPORT Dashboard : public Tomahawk::ViewPageLazyLoader< DashboardWidget >
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES( Tomahawk::ViewPagePlugin )
|
||||||
|
|
||||||
|
public:
|
||||||
|
Dashboard( QWidget* parent = 0 );
|
||||||
|
virtual ~Dashboard();
|
||||||
|
|
||||||
|
virtual Tomahawk::playlistinterface_ptr playlistInterface() const;
|
||||||
|
|
||||||
|
virtual const QString defaultName() { return DASHBOARD_VIEWPAGE_NAME; }
|
||||||
|
virtual QString title() const { return tr( "Dashboard" ); }
|
||||||
|
virtual QString description() const { return tr( "An overview of your recent activity" ); }
|
||||||
|
virtual const QString pixmapPath() const { return ( RESPATH "images/dashboard.svg" ); }
|
||||||
|
|
||||||
|
virtual int sortValue() { return 1; }
|
||||||
|
|
||||||
|
virtual bool showInfoBar() const { return true; }
|
||||||
|
virtual bool isBeingPlayed() const;
|
||||||
|
|
||||||
|
virtual bool jumpToCurrentTrack();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}; // Widgets
|
}; // Widgets
|
||||||
}; // Tomahawk
|
}; // Tomahawk
|
||||||
#endif // DASHBOARD_H
|
#endif // DASHBOARD_H
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>Dashboard</class>
|
<class>DashboardWidget</class>
|
||||||
<widget class="QWidget" name="Dashboard">
|
<widget class="QWidget" name="DashboardWidget">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
@@ -339,16 +339,11 @@ SourcesModel::appendGroups()
|
|||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
// addDynamicPage takes care of begin/endInsertRows itself
|
// addDynamicPage takes care of begin/endInsertRows itself
|
||||||
ViewManager::instance()->addDynamicPage( "dashboard",
|
ViewManager::instance()->addDynamicPage( new Tomahawk::Widgets::Dashboard, Tomahawk::Widgets::DASHBOARD_VIEWPAGE_NAME );
|
||||||
tr( "Dashboard" ),
|
|
||||||
ImageRegistry::instance()->icon( RESPATH "images/dashboard.svg" ),
|
|
||||||
boost::lambda::bind( boost::lambda::new_ptr< Tomahawk::Widgets::Dashboard >() ),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
|
|
||||||
//HACK: this may not belong here, but adding the pages probably doesn't belong here either
|
//HACK: this may not belong here, but adding the pages probably doesn't belong here either
|
||||||
//TODO: find a good place for this
|
//TODO: find a good place for this
|
||||||
ViewManager::instance()->showDynamicPage("dashboard");
|
ViewManager::instance()->showDynamicPage( Tomahawk::Widgets::DASHBOARD_VIEWPAGE_NAME );
|
||||||
|
|
||||||
ViewManager::instance()->addDynamicPage("network_activity",
|
ViewManager::instance()->addDynamicPage("network_activity",
|
||||||
tr( "Network Activity" ),
|
tr( "Network Activity" ),
|
||||||
|
Reference in New Issue
Block a user