PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 11ms RepoModel.GetById 29ms app.codeStats 0ms

/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
 19#include "SourceInfoWidget.h"
 20#include "ui_SourceInfoWidget.h"
 21
 22#include "Source.h"
 23#include "ViewManager.h"
 24
 25#include "playlist/AlbumModel.h"
 26#include "playlist/RecentlyAddedModel.h"
 27#include "playlist/RecentlyPlayedModel.h"
 28
 29#include "database/Database.h"
 30#include "database/DatabaseCommand_AllAlbums.h"
 31
 32#include "utils/TomahawkUtilsGui.h"
 33#include "utils/Logger.h"
 34
 35
 36SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* parent )
 37    : QWidget( parent )
 38    , ui( new Ui::SourceInfoWidget )
 39    , m_source( source )
 40{
 41    ui->setupUi( this );
 42
 43    TomahawkUtils::unmarginLayout( layout() );
 44    TomahawkUtils::unmarginLayout( ui->horizontalLayout );
 45    TomahawkUtils::unmarginLayout( ui->verticalLayout );
 46    TomahawkUtils::unmarginLayout( ui->verticalLayout_2 );
 47    TomahawkUtils::unmarginLayout( ui->verticalLayout_3 );
 48
 49    ui->splitter->setStretchFactor( 0, 0 );
 50    ui->splitter->setStretchFactor( 1, 1 );
 51
 52    m_recentTracksModel = new RecentlyAddedModel( ui->recentCollectionView );
 53    ui->recentCollectionView->proxyModel()->setStyle( PlayableProxyModel::Short );
 54    ui->recentCollectionView->setPlayableModel( m_recentTracksModel );
 55    ui->recentCollectionView->sortByColumn( PlayableModel::Age, Qt::DescendingOrder );
 56    m_recentTracksModel->setSource( source );
 57
 58    m_historyModel = new RecentlyPlayedModel( ui->historyView );
 59    ui->historyView->proxyModel()->setStyle( PlayableProxyModel::Short );
 60    ui->historyView->setPlaylistModel( m_historyModel );
 61    m_historyModel->setSource( source );
 62
 63    m_recentAlbumModel = new AlbumModel( ui->recentAlbumView );
 64    ui->recentAlbumView->setPlayableModel( m_recentAlbumModel );
 65    ui->recentAlbumView->proxyModel()->sort( -1 );
 66
 67    onCollectionChanged();
 68    connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) );
 69
 70    m_title = tr( "New Additions" );
 71    if ( source->isLocal() )
 72    {
 73        m_description = tr( "My recent activity" );
 74    }
 75    else
 76    {
 77        m_description = tr( "Recent activity from %1" ).arg( source->friendlyName() );
 78    }
 79
 80    m_pixmap.load( RESPATH "images/new-additions.png" );
 81}
 82
 83
 84SourceInfoWidget::~SourceInfoWidget()
 85{
 86    delete ui;
 87}
 88
 89
 90void
 91SourceInfoWidget::onCollectionChanged()
 92{
 93    loadRecentAdditions();
 94}
 95
 96
 97void
 98SourceInfoWidget::loadRecentAdditions()
 99{
100    m_recentAlbumModel->addFilteredCollection( m_source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
101}
102
103
104void
105SourceInfoWidget::changeEvent( QEvent* e )
106{
107    QWidget::changeEvent( e );
108    switch ( e->type() )
109    {
110        case QEvent::LanguageChange:
111            ui->retranslateUi( this );
112            break;
113
114        default:
115            break;
116    }
117}