From cbb44907f452c4cdbf7f1f1181ade07ca77f2ba0 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Thu, 8 Sep 2011 04:12:16 +0200 Subject: [PATCH] Add possibility to start songs from QML --- src/active/tomahawktouchwindow.cpp | 19 ++++++++++++++----- src/active/tomahawktouchwindow.h | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/active/tomahawktouchwindow.cpp b/src/active/tomahawktouchwindow.cpp index 9e87cc2f5..a08d2b060 100644 --- a/src/active/tomahawktouchwindow.cpp +++ b/src/active/tomahawktouchwindow.cpp @@ -27,7 +27,7 @@ #include "viewmanager.h" -#include "libtomahawk/playlist/treemodel.h"" +#include "libtomahawk/playlist/treeproxymodel.h" #include #include @@ -36,6 +36,7 @@ TomahawkTouchWindow::TomahawkTouchWindow() : m_view(0) + , m_currentPlaylistTreeModel(0) { QFileSystemWatcher* watcher = new QFileSystemWatcher; 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!"; 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( "globalActionManager", GlobalActionManager::instance() ); context->setContextProperty( "sourcesModel", s_sourcesModel ); - context->setContextProperty( "currentPlaylistTreeModel", 0 ); + context->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel ); tLog()<< Q_FUNC_INFO << "set source"; m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) ); diff --git a/src/active/tomahawktouchwindow.h b/src/active/tomahawktouchwindow.h index 77563c04c..d191521f6 100644 --- a/src/active/tomahawktouchwindow.h +++ b/src/active/tomahawktouchwindow.h @@ -25,6 +25,7 @@ class TomahawkTouchWindow; class QFileSystemWatcher; +class TreeProxyModel; class TomahawkTouchWindow : public TomahawkWindow { @@ -45,6 +46,7 @@ private: QDeclarativeView* m_view; QFileSystemWatcher* m_watcher; + TreeProxyModel* m_currentPlaylistTreeModel; }; #endif // TOMAHAWKTOUCHWINDOW_H