/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. #ifndef VIEWMANAGER_H
  20. #define VIEWMANAGER_H
  21. #include "Artist.h"
  22. #include "ViewPage.h"
  23. #include "ViewPagePlugin.h"
  24. #include "collection/Collection.h"
  25. #include "PlaylistInterface.h"
  26. #include "playlist/QueueView.h"
  27. #include <QObject>
  28. #include <QHash>
  29. #include <QStackedWidget>
  30. #include "DllMacro.h"
  31. #include <functional>
  32. class AlbumModel;
  33. class GridView;
  34. class AlbumInfoWidget;
  35. class ArtistInfoWidget;
  36. class CollectionModel;
  37. class PlaylistViewPage;
  38. class CollectionViewPage;
  39. class PlaylistModel;
  40. class TrackProxyModel;
  41. class TrackModel;
  42. class TreeProxyModel;
  43. class TreeModel;
  44. class TrackView;
  45. class SourceInfoWidget;
  46. class TrackInfoWidget;
  47. class QPushButton;
  48. class InboxModel;
  49. namespace Tomahawk
  50. {
  51. class DynamicWidget;
  52. }
  53. class DLLEXPORT ViewManager : public QObject
  54. {
  55. Q_OBJECT
  56. public:
  57. static ViewManager* instance();
  58. explicit ViewManager( QObject* parent = 0 );
  59. virtual ~ViewManager();
  60. QWidget* widget() const { return m_widget; }
  61. QueueView* queue() const { return m_queue; }
  62. void setQueue( QueueView* queue ) { m_queue = queue; }
  63. Tomahawk::playlistinterface_ptr currentPlaylistInterface() const;
  64. Tomahawk::ViewPage* currentPage() const;
  65. Tomahawk::ViewPage* pageForInterface( Tomahawk::playlistinterface_ptr plInterface ) const;
  66. Tomahawk::ViewPage* show( Tomahawk::ViewPage* page );
  67. Tomahawk::ViewPage* inboxWidget() const;
  68. Tomahawk::ViewPage* dynamicPageWidget( const QString& pageName ) const;
  69. InboxModel* inboxModel();
  70. /// Get the view page for the given item. Not pretty...
  71. Tomahawk::ViewPage* pageForPlaylist( const Tomahawk::playlist_ptr& pl ) const;
  72. Tomahawk::ViewPage* pageForDynPlaylist( const Tomahawk::dynplaylist_ptr& pl ) const;
  73. /// Get a playlist (or dynamic playlist ) from a ViewPage* if the page is PlaylistViewPage or DynamicWidget.
  74. /// Lives here but used by SourcesModel
  75. Tomahawk::playlist_ptr playlistForPage( Tomahawk::ViewPage* ) const;
  76. // only use this is you need to create a playlist and show it directly and want it to be
  77. // linked to the sidebar. call it right after creating the playlist
  78. PlaylistViewPage* createPageForPlaylist( const Tomahawk::playlist_ptr& playlist );
  79. PlaylistViewPage* createPageForList( const QString& title, const QList< Tomahawk::query_ptr >& queries );
  80. void addDynamicPage( Tomahawk::ViewPagePlugin* viewPage, const QString& pageName = QString() );
  81. signals:
  82. void playClicked();
  83. void pauseClicked();
  84. void tempPageActivated( Tomahawk::ViewPage* );
  85. void viewPageActivated( Tomahawk::ViewPage* );
  86. void viewPageAboutToBeDestroyed( Tomahawk::ViewPage* );
  87. void viewPageDestroyed();
  88. void historyBackAvailable( bool avail );
  89. void historyForwardAvailable( bool avail );
  90. void viewPageAdded( const QString& pageName, Tomahawk::ViewPage* page, int sortValue );
  91. public slots:
  92. Tomahawk::ViewPage* showInboxPage();
  93. Tomahawk::ViewPage* showQueuePage();
  94. // void addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, function< Tomahawk::ViewPage*() > instanceLoader, int sortValue = 0 );
  95. Tomahawk::ViewPage* showDynamicPage( const QString& pageName );
  96. void showCurrentTrack();
  97. // Returns the shown viewpage
  98. Tomahawk::ViewPage* show( const Tomahawk::playlist_ptr& playlist );
  99. Tomahawk::ViewPage* show( const Tomahawk::dynplaylist_ptr& playlist );
  100. Tomahawk::ViewPage* show( const Tomahawk::artist_ptr& artist );
  101. Tomahawk::ViewPage* show( const Tomahawk::album_ptr& album );
  102. Tomahawk::ViewPage* show( const Tomahawk::query_ptr& query );
  103. Tomahawk::ViewPage* show( const Tomahawk::collection_ptr& collection );
  104. Tomahawk::ViewPage* show( const Tomahawk::source_ptr& source );
  105. void historyBack();
  106. void historyForward();
  107. QList< Tomahawk::ViewPage* > allPages() const;
  108. QList< Tomahawk::ViewPage* > historyPages() const;
  109. void destroyPage( Tomahawk::ViewPage* page );
  110. bool destroyCurrentPage();
  111. void playlistInterfaceChanged( Tomahawk::playlistinterface_ptr );
  112. private slots:
  113. void onWidgetDestroyed( QWidget* widget );
  114. private:
  115. void setPage( Tomahawk::ViewPage* page, bool trackHistory = true );
  116. Tomahawk::playlist_ptr playlistForInterface( Tomahawk::playlistinterface_ptr plInterface ) const;
  117. Tomahawk::dynplaylist_ptr dynamicPlaylistForInterface( Tomahawk::playlistinterface_ptr plInterface ) const;
  118. QWidget* m_widget;
  119. QStackedWidget* m_stack;
  120. QueueView* m_queue;
  121. Tomahawk::ViewPage* m_inboxWidget;
  122. InboxModel* m_inboxModel;
  123. QHash< QString, Tomahawk::ViewPage* > m_dynamicPages;
  124. QHash< QString, QPointer< Tomahawk::ViewPagePlugin > > m_dynamicPagePlugins;
  125. QHash< QString, std::function< Tomahawk::ViewPage*() > > m_dynamicPagesInstanceLoaders;
  126. QHash< Tomahawk::dynplaylist_ptr, QPointer<Tomahawk::DynamicWidget> > m_dynamicWidgets;
  127. QHash< Tomahawk::collection_ptr, QPointer<CollectionViewPage> > m_collectionViews;
  128. QHash< Tomahawk::artist_ptr, QPointer<ArtistInfoWidget> > m_artistViews;
  129. QHash< Tomahawk::album_ptr, QPointer<AlbumInfoWidget> > m_albumViews;
  130. QHash< Tomahawk::query_ptr, QPointer<TrackInfoWidget> > m_trackViews;
  131. QHash< Tomahawk::playlist_ptr, QPointer<PlaylistViewPage> > m_playlistViews;
  132. QHash< Tomahawk::source_ptr, QPointer<SourceInfoWidget> > m_sourceViews;
  133. QList<Tomahawk::ViewPage*> m_pageHistoryBack;
  134. QList<Tomahawk::ViewPage*> m_pageHistoryFwd;
  135. Tomahawk::ViewPage* m_currentPage;
  136. Tomahawk::collection_ptr m_currentCollection;
  137. static ViewManager* s_instance;
  138. };
  139. #endif // VIEWMANAGER_H