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

« back to all changes in this revision

Viewing changes to src/libtomahawk/playlist/PlaylistView.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
 *   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
 
 
20
#include "PlaylistView.h"
 
21
 
 
22
#include <QKeyEvent>
 
23
 
 
24
#include "ViewManager.h"
 
25
#include "PlaylistUpdaterInterface.h"
 
26
#include "Source.h"
 
27
#include "utils/TomahawkUtilsGui.h"
 
28
#include "utils/Logger.h"
 
29
 
 
30
using namespace Tomahawk;
 
31
 
 
32
 
 
33
PlaylistView::PlaylistView( QWidget* parent )
 
34
    : TrackView( parent )
 
35
    , m_model( 0 )
 
36
{
 
37
    connect( contextMenu(), SIGNAL( triggered( int ) ), SLOT( onMenuTriggered( int ) ) );
 
38
}
 
39
 
 
40
 
 
41
PlaylistView::~PlaylistView()
 
42
{
 
43
    qDebug() << Q_FUNC_INFO;
 
44
}
 
45
 
 
46
 
 
47
void
 
48
PlaylistView::setModel( QAbstractItemModel* model )
 
49
{
 
50
    Q_UNUSED( model );
 
51
    qDebug() << "Explicitly use setPlaylistModel instead";
 
52
    Q_ASSERT( false );
 
53
}
 
54
 
 
55
 
 
56
void
 
57
PlaylistView::setPlaylistModel( PlaylistModel* model )
 
58
{
 
59
    m_model = model;
 
60
 
 
61
    TrackView::setPlayableModel( m_model );
 
62
    setColumnHidden( PlayableModel::Age, true ); // Hide age column per default
 
63
    setColumnHidden( PlayableModel::Filesize, true ); // Hide filesize column per default
 
64
    setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default
 
65
 
 
66
    connect( m_model, SIGNAL( playlistDeleted() ), SLOT( onDeleted() ) );
 
67
    connect( m_model, SIGNAL( playlistChanged() ), SLOT( onChanged() ) );
 
68
 
 
69
    emit modelChanged();
 
70
}
 
71
 
 
72
 
 
73
void
 
74
PlaylistView::keyPressEvent( QKeyEvent* event )
 
75
{
 
76
    TrackView::keyPressEvent( event );
 
77
}
 
78
 
 
79
 
 
80
bool
 
81
PlaylistView::eventFilter( QObject* obj, QEvent* event )
 
82
{
 
83
    if ( event->type() == QEvent::DragEnter )
 
84
    {
 
85
        QDragEnterEvent* e = static_cast<QDragEnterEvent*>(event);
 
86
        dragEnterEvent( e );
 
87
        return true;
 
88
    }
 
89
    if ( event->type() == QEvent::DragMove )
 
90
    {
 
91
        QDragMoveEvent* e = static_cast<QDragMoveEvent*>(event);
 
92
        dragMoveEvent( e );
 
93
        return true;
 
94
    }
 
95
    if ( event->type() == QEvent::DragLeave )
 
96
    {
 
97
        QDragLeaveEvent* e = static_cast<QDragLeaveEvent*>(event);
 
98
        dragLeaveEvent( e );
 
99
        return true;
 
100
    }
 
101
    if ( event->type() == QEvent::Drop )
 
102
    {
 
103
        QDropEvent* e = static_cast<QDropEvent*>(event);
 
104
        dropEvent( e );
 
105
        return true;
 
106
    }
 
107
 
 
108
    return QObject::eventFilter( obj, event );
 
109
}
 
110
 
 
111
 
 
112
QList<PlaylistUpdaterInterface*>
 
113
PlaylistView::updaters() const
 
114
{
 
115
    if ( !m_model->playlist().isNull() )
 
116
        return m_model->playlist()->updaters();
 
117
 
 
118
    return QList<PlaylistUpdaterInterface*>();
 
119
}
 
120
 
 
121
 
 
122
void
 
123
PlaylistView::onDeleted()
 
124
{
 
125
    emit destroyed( widget() );
 
126
}
 
127
 
 
128
 
 
129
void
 
130
PlaylistView::onChanged()
 
131
{
 
132
    if ( m_model )
 
133
    {
 
134
        if ( m_model->isReadOnly() )
 
135
            setEmptyTip( tr( "This playlist is currently empty." ) );
 
136
        else
 
137
            setEmptyTip( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) );
 
138
        m_model->finishLoading();
 
139
 
 
140
        setGuid( proxyModel()->guid() );
 
141
 
 
142
        if ( !m_model->playlist().isNull() && ViewManager::instance()->currentPage() == this )
 
143
            emit nameChanged( m_model->playlist()->title() );
 
144
    }
 
145
}
 
146
 
 
147
 
 
148
bool
 
149
PlaylistView::isTemporaryPage() const
 
150
{
 
151
    return ( m_model && m_model->isTemporary() );
 
152
}
 
153
 
 
154
 
 
155
void
 
156
PlaylistView::onMenuTriggered( int action )
 
157
{
 
158
    switch ( action )
 
159
    {
 
160
        default:
 
161
            break;
 
162
    }
 
163
}
 
164
 
 
165
 
 
166
QPixmap
 
167
PlaylistView::pixmap() const
 
168
{
 
169
    return TomahawkUtils::defaultPixmap( TomahawkUtils::Playlist );
 
170
}