PageRenderTime 87ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/RedBullPlayer/Modules/PlaylistUI/PlaylistUIModule.cpp

https://github.com/baoping/Red-Bull-Media-Player
C++ | 189 lines | 137 code | 33 blank | 19 comment | 40 complexity | cf08d3047db23b73a1f55158cbc63d49 MD5 | raw file
  1. /*
  2. * Red Bull Media Player
  3. * Copyright (C) 2011, Red Bull
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "PlaylistUIModule.h"
  19. // QT includes
  20. #include <QtPlugin>
  21. #include <QDebug>
  22. #include <QLayout>
  23. #include <QDesktopServices>
  24. // Project Includes
  25. #include "../../Container/Error.h"
  26. #include "../../Container/Constants.h"
  27. #include "../../EventAggregator/Aggregator.h"
  28. #include "../../Events/EventTypes.h"
  29. #include "../../Events/Playlist/PlaylistContentTypeChangedEvent.h"
  30. #include "../../Interfaces/ICoverViewPlaylist.h"
  31. #include "../../ToolLib/ConfigManager.h"
  32. using namespace RedBullPlayer::Modules::Playlist;
  33. using namespace RedBullPlayer::PlayerShell;
  34. using namespace RedBullPlayer::Container;
  35. using namespace RedBullPlayer::EventAggregator;
  36. using namespace RedBullPlayer::Events;
  37. using namespace RedBullPlayer::Modules::Playlist::CoverViewPlaylist;
  38. using namespace RedBullPlayer::Tools;
  39. PlaylistUIModule::PlaylistUIModule() : IPlaylistUI() {
  40. }
  41. void PlaylistUIModule::Setup( QObject* shell, QDomElement config ) {
  42. _shell = qobject_cast<Shell*>( shell );
  43. Q_ASSERT( _shell != 0 );
  44. Q_ASSERT( ! config.isNull() );
  45. QString regionName = config.attribute( "UIRegion" );
  46. Q_ASSERT( ! regionName.isNull() );
  47. _region = _shell->findRegion( regionName );
  48. Q_ASSERT( _region != 0 );
  49. _ui = new PlaylistUI( _shell, _region->widget() );
  50. if( _region->widget()->layout() == NULL ) {
  51. new QHBoxLayout( _region->widget() );
  52. }
  53. _region->widget()->layout()->setMargin( 0 );
  54. _region->widget()->layout()->setSpacing( 0 );
  55. _region->widget()->layout()->addWidget( _ui );
  56. Aggregator::instance()->registerListener( KeyPressed, this );
  57. Aggregator::instance()->registerListener( FocusedPlaylistItemChanged, this );
  58. Aggregator::instance()->registerListener( FunctionSelected, this );
  59. Aggregator::instance()->registerListener( CentralFocusChanged, this );
  60. Aggregator::instance()->registerListener( MainUIRegionFocusChanged, this );
  61. Aggregator::instance()->registerListener( EndOfPlaylist, this );
  62. Aggregator::instance()->registerListener( SearchPlaylistGenerationStarted, this );
  63. Aggregator::instance()->registerListener( SearchEnded, this );
  64. }
  65. void PlaylistUIModule:: SetupModuleConnections() {
  66. _ui->setupMediaLibraryConnection();
  67. _ui->resolveStyleFactory();
  68. _ui->setupStyle();
  69. }
  70. bool PlaylistUIModule::event ( QEvent * e ) {
  71. if( e->type() == KeyPressed ) {
  72. onKeyPressed( static_cast<KeyPressedEvent*>( e ) );
  73. }
  74. if( e->type() == FocusedPlaylistItemChanged ) {
  75. onFocusedPlaylistItemChanged( static_cast<FocusedPlayListItemChangedEvent*>( e ) );
  76. }
  77. if( e->type() == FunctionSelected ) {
  78. onFunctionSelected( static_cast<FunctionSelectedEvent*>( e ) );
  79. }
  80. if( e->type() == CentralFocusChanged ) {
  81. onCentralFocusChanged( static_cast<CentralFocusChangedEvent*>( e ) );
  82. }
  83. if( e->type() == MainUIRegionFocusChanged ) {
  84. onMainUIRegionFocusChanged( static_cast<MainUIRegionFocusChangedEvent*>( e ) );
  85. }
  86. if( e->type() == EndOfPlaylist ) {
  87. onEndOfPlaylist( static_cast<EndOfPlaylistEvent*>( e ) );
  88. }
  89. if( e->type() == SearchPlaylistGenerationStarted ) {
  90. onSearchPlaylistGenerationStarted( static_cast<SearchPlaylistGenerationStartedEvent*>( e ) );
  91. }
  92. return false;
  93. }
  94. void PlaylistUIModule::onSearchPlaylistGenerationStarted( SearchPlaylistGenerationStartedEvent *e ) {
  95. _ui->clearTitle();
  96. }
  97. void PlaylistUIModule::onKeyPressed( KeyPressedEvent *event ) {
  98. if( !_ui->hasMainFocus() || !_ui->hasCentralFocus() ) {
  99. return;
  100. }
  101. if( event->keyEvent()->key() == Qt::Key_Left ) {
  102. _ui->onLeftNavigationClicked();
  103. }
  104. if( event->keyEvent()->key() == Qt::Key_Right ) {
  105. _ui->onRightNavigationClicked();
  106. }
  107. if( event->keyEvent()->key() == Qt::Key_Backspace ||
  108. event->keyEvent()->key() == Qt::Key_Delete ||
  109. event->keyEvent()->key() == Qt::Key_Minus ) {
  110. _ui->minusClicked();
  111. }
  112. }
  113. void PlaylistUIModule::onFocusedPlaylistItemChanged( FocusedPlayListItemChangedEvent *event ) {
  114. _ui->handleFocusedPlaylistItemChanged( event->newTitle(), event->mediaId() );
  115. }
  116. void PlaylistUIModule::onEndOfPlaylist( EndOfPlaylistEvent *event ) {
  117. _ui->setNavigationKeysState( event->endOfPlayListDirection() );
  118. }
  119. void PlaylistUIModule::onMainUIRegionFocusChanged( MainUIRegionFocusChangedEvent *event ) {
  120. _ui->changeMainUIRegionFocusGraphics( event->uiRegion() );
  121. }
  122. void PlaylistUIModule::onFunctionSelected( FunctionSelectedEvent* e ) {
  123. if( e->functionTitle() != Constants::FUNCTION_SELECT_SERVUSTVB2B_TITLE )
  124. _ui->clearTitle();
  125. else
  126. QDesktopServices::openUrl( ConfigManager::instance()->getServusTvB2BUrl() );
  127. if( e->functionTitle() == Constants::FUNCTION_SELECT_MEDIA_TITLE ) {
  128. _ui->SetPlaylistType( PlaylistUI::MEDIA );
  129. PlaylistContentTypeChangedEvent e( PlaylistContentTypeChangedEvent::MEDIA );
  130. Aggregator::instance()->sendEvent( &e );
  131. }
  132. if( e->functionTitle() == Constants::FUNCTION_SELECT_TV_TITLE ) {
  133. _ui->SetPlaylistType( PlaylistUI::TV );
  134. PlaylistContentTypeChangedEvent e( PlaylistContentTypeChangedEvent::TV );
  135. Aggregator::instance()->sendEvent( &e );
  136. }
  137. if( e->functionTitle() == Constants::FUNCTION_SELECT_NEWS_TITLE ) {
  138. _ui->SetPlaylistType( PlaylistUI::NEWS );
  139. PlaylistContentTypeChangedEvent e( PlaylistContentTypeChangedEvent::NEWS );
  140. Aggregator::instance()->sendEvent( &e );
  141. }
  142. if( e->functionTitle() == Constants::FUNCTION_SELECT_ABOUT_TITLE ) {
  143. _ui->SetPlaylistType( PlaylistUI::ABOUT );
  144. PlaylistContentTypeChangedEvent e( PlaylistContentTypeChangedEvent::ABOUT );
  145. Aggregator::instance()->sendEvent( &e );
  146. }
  147. if( e->functionTitle() == Constants::FUNCTION_SELECT_SETTINGS_TITLE ) {
  148. _ui->SetPlaylistType( PlaylistUI::SETTINGS );
  149. PlaylistContentTypeChangedEvent e( PlaylistContentTypeChangedEvent::SETTINGS );
  150. Aggregator::instance()->sendEvent( &e );
  151. }
  152. }
  153. void PlaylistUIModule::onCentralFocusChanged( CentralFocusChangedEvent *e ) {
  154. _ui->handleCentralFocusChanged( e->widgetType() );
  155. }
  156. Q_EXPORT_PLUGIN2( PlaylistUIModule, RedBullPlayer::Modules::Playlist::PlaylistUIModule )