PageRenderTime 36ms CodeModel.GetById 16ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libtomahawk/ViewManager.h

http://github.com/tomahawk-player/tomahawk
C Header | 182 lines | 114 code | 43 blank | 25 comment | 0 complexity | ecb828d540c231e9e7dfce16776b847b MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#ifndef VIEWMANAGER_H
 21#define VIEWMANAGER_H
 22
 23#include "Artist.h"
 24#include "ViewPage.h"
 25#include "ViewPagePlugin.h"
 26#include "collection/Collection.h"
 27#include "PlaylistInterface.h"
 28#include "playlist/QueueView.h"
 29
 30#include <QObject>
 31#include <QHash>
 32#include <QStackedWidget>
 33
 34#include "DllMacro.h"
 35
 36#include <functional>
 37
 38class AlbumModel;
 39class GridView;
 40class AlbumInfoWidget;
 41class ArtistInfoWidget;
 42class CollectionModel;
 43class PlaylistViewPage;
 44class CollectionViewPage;
 45class PlaylistModel;
 46class TrackProxyModel;
 47class TrackModel;
 48class TreeProxyModel;
 49class TreeModel;
 50class TrackView;
 51class SourceInfoWidget;
 52class TrackInfoWidget;
 53class QPushButton;
 54class InboxModel;
 55
 56namespace Tomahawk
 57{
 58    class DynamicWidget;
 59}
 60
 61class DLLEXPORT ViewManager : public QObject
 62{
 63Q_OBJECT
 64
 65public:
 66    static ViewManager* instance();
 67
 68    explicit ViewManager( QObject* parent = 0 );
 69    virtual ~ViewManager();
 70
 71    QWidget* widget() const { return m_widget; }
 72
 73    QueueView* queue() const { return m_queue; }
 74    void setQueue( QueueView* queue ) { m_queue = queue; }
 75
 76    Tomahawk::playlistinterface_ptr currentPlaylistInterface() const;
 77    Tomahawk::ViewPage* currentPage() const;
 78    Tomahawk::ViewPage* pageForInterface( Tomahawk::playlistinterface_ptr plInterface ) const;
 79
 80    Tomahawk::ViewPage* show( Tomahawk::ViewPage* page );
 81
 82    Tomahawk::ViewPage* inboxWidget() const;
 83    Tomahawk::ViewPage* dynamicPageWidget( const QString& pageName ) const;
 84
 85    InboxModel* inboxModel();
 86
 87    /// Get the view page for the given item. Not pretty...
 88    Tomahawk::ViewPage* pageForPlaylist( const Tomahawk::playlist_ptr& pl ) const;
 89    Tomahawk::ViewPage* pageForDynPlaylist( const Tomahawk::dynplaylist_ptr& pl ) const;
 90
 91    /// Get a playlist (or dynamic playlist ) from a ViewPage* if the page is PlaylistViewPage or DynamicWidget.
 92    /// Lives here but used by SourcesModel
 93    Tomahawk::playlist_ptr playlistForPage( Tomahawk::ViewPage* ) const;
 94
 95    // only use this is you need to create a playlist and show it directly and want it to be
 96    // linked to the sidebar. call it right after creating the playlist
 97    PlaylistViewPage* createPageForPlaylist( const Tomahawk::playlist_ptr& playlist );
 98
 99    PlaylistViewPage* createPageForList( const QString& title, const QList< Tomahawk::query_ptr >& queries );
100
101    void addDynamicPage( Tomahawk::ViewPagePlugin* viewPage, const QString& pageName = QString() );
102
103signals:
104    void playClicked();
105    void pauseClicked();
106
107    void tempPageActivated( Tomahawk::ViewPage* );
108    void viewPageActivated( Tomahawk::ViewPage* );
109    void viewPageAboutToBeDestroyed( Tomahawk::ViewPage* );
110    void viewPageDestroyed();
111
112    void historyBackAvailable( bool avail );
113    void historyForwardAvailable( bool avail );
114
115    void viewPageAdded( const QString& pageName, Tomahawk::ViewPage* page, int sortValue );
116
117public slots:
118    Tomahawk::ViewPage* showInboxPage();
119    Tomahawk::ViewPage* showQueuePage();
120
121//    void addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, function< Tomahawk::ViewPage*() > instanceLoader, int sortValue = 0 );
122    Tomahawk::ViewPage* showDynamicPage( const QString& pageName );
123
124    void showCurrentTrack();
125
126    // Returns the shown viewpage
127    Tomahawk::ViewPage* show( const Tomahawk::playlist_ptr& playlist );
128    Tomahawk::ViewPage* show( const Tomahawk::dynplaylist_ptr& playlist );
129    Tomahawk::ViewPage* show( const Tomahawk::artist_ptr& artist );
130    Tomahawk::ViewPage* show( const Tomahawk::album_ptr& album );
131    Tomahawk::ViewPage* show( const Tomahawk::query_ptr& query );
132    Tomahawk::ViewPage* show( const Tomahawk::collection_ptr& collection );
133    Tomahawk::ViewPage* show( const Tomahawk::source_ptr& source );
134
135    void historyBack();
136    void historyForward();
137
138    QList< Tomahawk::ViewPage* > allPages() const;
139    QList< Tomahawk::ViewPage* > historyPages() const;
140    void destroyPage( Tomahawk::ViewPage* page );
141    bool destroyCurrentPage();
142
143    void playlistInterfaceChanged( Tomahawk::playlistinterface_ptr );
144
145private slots:
146    void onWidgetDestroyed( QWidget* widget );
147
148private:
149    void setPage( Tomahawk::ViewPage* page, bool trackHistory = true );
150
151    Tomahawk::playlist_ptr playlistForInterface( Tomahawk::playlistinterface_ptr plInterface ) const;
152    Tomahawk::dynplaylist_ptr dynamicPlaylistForInterface( Tomahawk::playlistinterface_ptr plInterface ) const;
153
154    QWidget* m_widget;
155    QStackedWidget* m_stack;
156
157    QueueView* m_queue;
158    Tomahawk::ViewPage* m_inboxWidget;
159    InboxModel* m_inboxModel;
160
161    QHash< QString, Tomahawk::ViewPage* > m_dynamicPages;
162    QHash< QString, QPointer< Tomahawk::ViewPagePlugin > > m_dynamicPagePlugins;
163    QHash< QString, std::function< Tomahawk::ViewPage*() > > m_dynamicPagesInstanceLoaders;
164
165    QHash< Tomahawk::dynplaylist_ptr, QPointer<Tomahawk::DynamicWidget> > m_dynamicWidgets;
166    QHash< Tomahawk::collection_ptr, QPointer<CollectionViewPage> > m_collectionViews;
167    QHash< Tomahawk::artist_ptr, QPointer<ArtistInfoWidget> > m_artistViews;
168    QHash< Tomahawk::album_ptr, QPointer<AlbumInfoWidget> > m_albumViews;
169    QHash< Tomahawk::query_ptr, QPointer<TrackInfoWidget> > m_trackViews;
170    QHash< Tomahawk::playlist_ptr, QPointer<PlaylistViewPage> > m_playlistViews;
171    QHash< Tomahawk::source_ptr, QPointer<SourceInfoWidget> > m_sourceViews;
172
173    QList<Tomahawk::ViewPage*> m_pageHistoryBack;
174    QList<Tomahawk::ViewPage*> m_pageHistoryFwd;
175    Tomahawk::ViewPage* m_currentPage;
176
177    Tomahawk::collection_ptr m_currentCollection;
178
179    static ViewManager* s_instance;
180};
181
182#endif // VIEWMANAGER_H