diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 1eaff36d8..63c2af3c8 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -27,6 +27,7 @@ set( libSources query.cpp result.cpp source.cpp + sourceplaylistinterface.cpp viewpage.cpp viewmanager.cpp globalactionmanager.cpp @@ -189,6 +190,7 @@ set( libHeaders resolver.h result.h source.h + sourceplaylistinterface.h viewpage.h viewmanager.h globalactionmanager.h diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index 2071c79f3..4bf42f537 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -146,7 +146,9 @@ void AudioEngine::previous() { qDebug() << Q_FUNC_INFO; - loadPreviousTrack(); + if ( !m_playlist->skipSeekRestrictions() == PlaylistInterface::NoSkip && + !m_playlist->skipSeekRestrictions() == PlaylistInterface::NoSkipSeek ) + loadPreviousTrack(); } @@ -154,13 +156,19 @@ void AudioEngine::next() { qDebug() << Q_FUNC_INFO; - loadNextTrack(); + if ( !m_playlist->skipSeekRestrictions() == PlaylistInterface::NoSkip && + !m_playlist->skipSeekRestrictions() == PlaylistInterface::NoSkipSeek ) + loadNextTrack(); } void AudioEngine::seek( int ms ) { + if ( m_playlist->skipSeekRestrictions() == PlaylistInterface::NoSeek || + m_playlist->skipSeekRestrictions() == PlaylistInterface::NoSkipSeek ) + return; + if ( isPlaying() || isPaused() ) { qDebug() << Q_FUNC_INFO << ms; diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 1c71735e6..3064089b5 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -35,6 +35,7 @@ class DLLEXPORT PlaylistInterface public: enum RepeatMode { NoRepeat, RepeatOne, RepeatAll }; enum ViewMode { Unknown, Tree, Flat, Album }; + enum SkipSeekRestrictions { NoRestrictions, NoSkip, NoSeek, NoSkipSeek }; PlaylistInterface( QObject* parent = 0 ) : m_object( parent ) {} virtual ~PlaylistInterface() {} @@ -51,6 +52,7 @@ public: virtual PlaylistInterface::RepeatMode repeatMode() const = 0; virtual bool shuffled() const = 0; virtual PlaylistInterface::ViewMode viewMode() const { return Unknown; } + virtual PlaylistInterface::SkipSeekRestrictions skipSeekRestrictions() const { return NoRestrictions; } virtual QString filter() const { return m_filter; } virtual void setFilter( const QString& pattern ) { m_filter = pattern; } diff --git a/src/libtomahawk/source.cpp b/src/libtomahawk/source.cpp index e852e0c83..8b11b7de9 100644 --- a/src/libtomahawk/source.cpp +++ b/src/libtomahawk/source.cpp @@ -20,6 +20,7 @@ #include "collection.h" #include "sourcelist.h" +#include "sourceplaylistinterface.h" #include "network/controlconnection.h" #include "database/databasecommand_addsource.h" @@ -267,6 +268,18 @@ Source::trackCount() const } +Tomahawk::playlistinterface_ptr +Source::getPlaylistInterface() +{ + if ( m_playlistInterface.isNull() ) + { + Tomahawk::source_ptr source = SourceList::instance()->get( id() ); + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::SourcePlaylistInterface( source ) ); + } + + return m_playlistInterface; +} + void Source::onPlaybackStarted( const Tomahawk::query_ptr& query ) { diff --git a/src/libtomahawk/source.h b/src/libtomahawk/source.h index 1179fd267..9b4454a69 100644 --- a/src/libtomahawk/source.h +++ b/src/libtomahawk/source.h @@ -77,6 +77,8 @@ public: Tomahawk::query_ptr currentTrack() const { return m_currentTrack; } QString textStatus() const { return m_textStatus; } + Tomahawk::playlistinterface_ptr getPlaylistInterface(); + signals: void syncedWithDatabase(); void online(); @@ -124,6 +126,8 @@ private: ControlConnection* m_cc; QPixmap* m_avatar; + + Tomahawk::playlistinterface_ptr m_playlistInterface; }; }; diff --git a/src/libtomahawk/sourceplaylistinterface.cpp b/src/libtomahawk/sourceplaylistinterface.cpp new file mode 100644 index 000000000..0b145bbc2 --- /dev/null +++ b/src/libtomahawk/sourceplaylistinterface.cpp @@ -0,0 +1,62 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "sourceplaylistinterface.h" + +#include + +#include "source.h" +#include "pipeline.h" + +using namespace Tomahawk; + +SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::source_ptr& source ) + : PlaylistInterface( this ) + , m_source( source ) +{ + connect( source.data(), SIGNAL( playbackStarted( const Tomahawk::query_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::query_ptr& ) ) ); +} + + +Tomahawk::result_ptr +SourcePlaylistInterface::siblingItem( int itemsAway ) +{ + Q_UNUSED( itemsAway ); + return m_source->currentTrack()->results().first(); +} + + +Tomahawk::result_ptr +SourcePlaylistInterface::nextItem() +{ + return m_source->currentTrack()->results().first(); +} + + +QList +SourcePlaylistInterface::tracks() +{ + return m_source->collection()->tracks(); +} + + +void +SourcePlaylistInterface::onSourcePlaybackStarted( const Tomahawk::query_ptr& query ) const +{ + Pipeline::instance()->resolve( query, true ); +} diff --git a/src/libtomahawk/sourceplaylistinterface.h b/src/libtomahawk/sourceplaylistinterface.h new file mode 100644 index 000000000..1779a977e --- /dev/null +++ b/src/libtomahawk/sourceplaylistinterface.h @@ -0,0 +1,74 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef TOMAHAWKSOURCEPLAYLISTINTERFACE_H +#define TOMAHAWKSOURCEPLAYLISTINTERFACE_H + +#include +#include + +#include "typedefs.h" +#include "collection.h" +#include "playlistinterface.h" + +#include "dllmacro.h" + +namespace Tomahawk +{ + +class DLLEXPORT SourcePlaylistInterface : public QObject, public PlaylistInterface +{ +Q_OBJECT + +public: + SourcePlaylistInterface( Tomahawk::source_ptr& source ); + + QList tracks(); + + virtual int trackCount() const { return 1; } + virtual int unfilteredTrackCount() const { return 1; } + + virtual Tomahawk::result_ptr siblingItem( int itemsAway ); + virtual Tomahawk::result_ptr nextItem(); + + virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; } + virtual PlaylistInterface::SkipSeekRestrictions skipSeekRestrictions() const { return PlaylistInterface::NoSkipSeek; } + + virtual bool shuffled() const { return false; } + virtual void setFilter( const QString& /*pattern*/ ) {} + +public slots: + virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {} + virtual void setShuffled( bool ) {} + +signals: + void repeatModeChanged( PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + +private slots: + void onSourcePlaybackStarted( const Tomahawk::query_ptr& query ) const; + +private: + Tomahawk::source_ptr m_source; +}; + +}; // ns + +#endif