~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
36
SourceInfoWidget::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
 
 
81
 
 
82
SourceInfoWidget::~SourceInfoWidget()
 
83
{
 
84
    delete ui;
 
85
}
 
86
 
 
87
 
 
88
void
 
89
SourceInfoWidget::onCollectionChanged()
 
90
{
 
91
    loadRecentAdditions();
 
92
}
 
93
 
 
94
 
 
95
void
 
96
SourceInfoWidget::loadRecentAdditions()
 
97
{
 
98
    m_recentAlbumModel->addFilteredCollection( m_source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
 
99
}
 
100
 
 
101
 
 
102
void
 
103
SourceInfoWidget::changeEvent( QEvent* e )
 
104
{
 
105
    QWidget::changeEvent( e );
 
106
    switch ( e->type() )
 
107
    {
 
108
        case QEvent::LanguageChange:
 
109
            ui->retranslateUi( this );
 
110
            break;
 
111
 
 
112
        default:
 
113
            break;
 
114
    }
 
115
}
 
116
 
 
117
 
 
118
QPixmap
 
119
SourceInfoWidget::pixmap() const
 
120
{
 
121
    return TomahawkUtils::defaultPixmap( TomahawkUtils::NewAdditions, TomahawkUtils::Original );
 
122
 
 
123
}