1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 23:57:34 +02:00

Add possibility to start songs from QML

This commit is contained in:
Dominik Schmidt
2011-09-08 04:12:16 +02:00
parent 7185b4e778
commit cbb44907f4
2 changed files with 16 additions and 5 deletions

View File

@@ -27,7 +27,7 @@
#include "viewmanager.h" #include "viewmanager.h"
#include "libtomahawk/playlist/treemodel.h"" #include "libtomahawk/playlist/treeproxymodel.h"
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QtDeclarative> #include <QtDeclarative>
@@ -36,6 +36,7 @@
TomahawkTouchWindow::TomahawkTouchWindow() TomahawkTouchWindow::TomahawkTouchWindow()
: m_view(0) : m_view(0)
, m_currentPlaylistTreeModel(0)
{ {
QFileSystemWatcher* watcher = new QFileSystemWatcher; QFileSystemWatcher* watcher = new QFileSystemWatcher;
watcher->addPath( QMLGUI ); watcher->addPath( QMLGUI );
@@ -54,9 +55,14 @@ TomahawkTouchWindow::~TomahawkTouchWindow()
} }
void TomahawkTouchWindow::play(const QModelIndex& index) void TomahawkTouchWindow::play(const QModelIndex& index )
{ {
TreeModelItem* item = m_currentPlaylistTreeModel->sourceModel()->itemFromIndex( m_currentPlaylistTreeModel->mapToSource( index ) );
if ( item )
{
m_currentPlaylistTreeModel->sourceModel()->setCurrentItem( item->index );
AudioEngine::instance()->playItem( m_currentPlaylistTreeModel, item->result() );
}
} }
@@ -72,7 +78,10 @@ void TomahawkTouchWindow::activateItem(const QModelIndex& index)
tLog() << "Activate collectionItem!"; tLog() << "Activate collectionItem!";
Tomahawk::collection_ptr collection = collectionItem->source()->collection(); Tomahawk::collection_ptr collection = collectionItem->source()->collection();
m_view->rootContext()->setContextProperty( "currentPlaylistTreeModel", ViewManager::instance()->treeModelForCollection( collection ) ); delete m_currentPlaylistTreeModel;
m_currentPlaylistTreeModel = new TreeProxyModel();
m_currentPlaylistTreeModel->setSourceTreeModel( ViewManager::instance()->treeModelForCollection( collection ) );
m_view->rootContext()->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel );
} }
} }
@@ -103,7 +112,7 @@ TomahawkTouchWindow::loadQml()
context->setContextProperty( "audioEngine", AudioEngine::instance() ); context->setContextProperty( "audioEngine", AudioEngine::instance() );
context->setContextProperty( "globalActionManager", GlobalActionManager::instance() ); context->setContextProperty( "globalActionManager", GlobalActionManager::instance() );
context->setContextProperty( "sourcesModel", s_sourcesModel ); context->setContextProperty( "sourcesModel", s_sourcesModel );
context->setContextProperty( "currentPlaylistTreeModel", 0 ); context->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel );
tLog()<< Q_FUNC_INFO << "set source"; tLog()<< Q_FUNC_INFO << "set source";
m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) ); m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) );

View File

@@ -25,6 +25,7 @@
class TomahawkTouchWindow; class TomahawkTouchWindow;
class QFileSystemWatcher; class QFileSystemWatcher;
class TreeProxyModel;
class TomahawkTouchWindow : public TomahawkWindow class TomahawkTouchWindow : public TomahawkWindow
{ {
@@ -45,6 +46,7 @@ private:
QDeclarativeView* m_view; QDeclarativeView* m_view;
QFileSystemWatcher* m_watcher; QFileSystemWatcher* m_watcher;
TreeProxyModel* m_currentPlaylistTreeModel;
}; };
#endif // TOMAHAWKTOUCHWINDOW_H #endif // TOMAHAWKTOUCHWINDOW_H