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