/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 117 lines · 76 code · 24 blank · 17 comment · 2 complexity · e61d4d1590c9b06659d4f5c5ed18748b MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. *
  5. * Tomahawk 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. * Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "SourceInfoWidget.h"
  19. #include "ui_SourceInfoWidget.h"
  20. #include "Source.h"
  21. #include "ViewManager.h"
  22. #include "playlist/AlbumModel.h"
  23. #include "playlist/RecentlyAddedModel.h"
  24. #include "playlist/RecentlyPlayedModel.h"
  25. #include "database/Database.h"
  26. #include "database/DatabaseCommand_AllAlbums.h"
  27. #include "utils/TomahawkUtilsGui.h"
  28. #include "utils/Logger.h"
  29. SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent )
  30. : QWidget( parent )
  31. , ui( new Ui::SourceInfoWidget )
  32. , m_source( source )
  33. {
  34. ui->setupUi( this );
  35. TomahawkUtils::unmarginLayout( layout() );
  36. TomahawkUtils::unmarginLayout( ui->horizontalLayout );
  37. TomahawkUtils::unmarginLayout( ui->verticalLayout );
  38. TomahawkUtils::unmarginLayout( ui->verticalLayout_2 );
  39. TomahawkUtils::unmarginLayout( ui->verticalLayout_3 );
  40. ui->splitter->setStretchFactor( 0, 0 );
  41. ui->splitter->setStretchFactor( 1, 1 );
  42. m_recentTracksModel = new RecentlyAddedModel( ui->recentCollectionView );
  43. ui->recentCollectionView->proxyModel()->setStyle( PlayableProxyModel::Short );
  44. ui->recentCollectionView->setPlayableModel( m_recentTracksModel );
  45. ui->recentCollectionView->sortByColumn( PlayableModel::Age, Qt::DescendingOrder );
  46. m_recentTracksModel->setSource( source );
  47. m_historyModel = new RecentlyPlayedModel( ui->historyView );
  48. ui->historyView->proxyModel()->setStyle( PlayableProxyModel::Short );
  49. ui->historyView->setPlaylistModel( m_historyModel );
  50. m_historyModel->setSource( source );
  51. m_recentAlbumModel = new AlbumModel( ui->recentAlbumView );
  52. ui->recentAlbumView->setPlayableModel( m_recentAlbumModel );
  53. ui->recentAlbumView->proxyModel()->sort( -1 );
  54. onCollectionChanged();
  55. connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) );
  56. m_title = tr( "New Additions" );
  57. if ( source->isLocal() )
  58. {
  59. m_description = tr( "My recent activity" );
  60. }
  61. else
  62. {
  63. m_description = tr( "Recent activity from %1" ).arg( source->friendlyName() );
  64. }
  65. m_pixmap.load( RESPATH "images/new-additions.png" );
  66. }
  67. SourceInfoWidget::~SourceInfoWidget()
  68. {
  69. delete ui;
  70. }
  71. void
  72. SourceInfoWidget::onCollectionChanged()
  73. {
  74. loadRecentAdditions();
  75. }
  76. void
  77. SourceInfoWidget::loadRecentAdditions()
  78. {
  79. m_recentAlbumModel->addFilteredCollection( m_source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
  80. }
  81. void
  82. SourceInfoWidget::changeEvent( QEvent* e )
  83. {
  84. QWidget::changeEvent( e );
  85. switch ( e->type() )
  86. {
  87. case QEvent::LanguageChange:
  88. ui->retranslateUi( this );
  89. break;
  90. default:
  91. break;
  92. }
  93. }