1
/****************************************************************************************
2
 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
3
 *                                                                                      *
4
 * This program is free software; you can redistribute it and/or modify it under        *
5
 * the terms of the GNU General Public License as published by the Free Software        *
6
 * Foundation; either version 2 of the License, or (at your option) any later           *
7
 * version.                                                                             *
8
 *                                                                                      *
9
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12
 *                                                                                      *
13
 * You should have received a copy of the GNU General Public License along with         *
14
 * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15
 ****************************************************************************************/
16
 
17
#include "GlobalCollectionActions.h"
18
#include "core/meta/Meta.h"
19
20
21
namespace The
22
{
23
    static GlobalCollectionActions* s_GlobalCollectionActions_instance = 0;
24
25
    GlobalCollectionActions* globalCollectionActions()
26
    {
27
        if( !s_GlobalCollectionActions_instance )
28
            s_GlobalCollectionActions_instance = new GlobalCollectionActions();
29
30
        return s_GlobalCollectionActions_instance;
31
    }
32
}
33
34
GlobalCollectionActions::GlobalCollectionActions()
35
{}
36
37
38
GlobalCollectionActions::~GlobalCollectionActions()
39
{}
40
41
void
42
GlobalCollectionActions::addGenreAction( GlobalCollectionGenreAction * action )
43
{
44
    m_genreActions.append( action );
45
}
46
47
void
48
GlobalCollectionActions::addArtistAction( GlobalCollectionArtistAction * action )
49
{
50
    m_artistActions.append( action );
51
}
52
53
void
54
GlobalCollectionActions::addAlbumAction( GlobalCollectionAlbumAction * action )
55
{
56
    m_albumActions.append( action );
57
}
58
59
void
60
GlobalCollectionActions::addTrackAction( GlobalCollectionTrackAction * action )
61
{
62
    m_trackActions.append( action );
63
}
64
65
void
66
GlobalCollectionActions::addYearAction( GlobalCollectionYearAction * action )
67
{
68
    m_yearActions.append( action );
69
}
70
71
void
72
GlobalCollectionActions::addComposerAction( GlobalCollectionComposerAction * action )
73
{
74
    m_composerActions.append( action );
75
}
76
77
QList< QAction * > GlobalCollectionActions::actionsFor( Meta::DataPtr item )
78
{
79
80
    Meta::GenrePtr genrePtr = Meta::GenrePtr::dynamicCast( item );
81
    if ( genrePtr )
82
        return actionsFor( genrePtr );
83
84
    Meta::ArtistPtr artistPtr = Meta::ArtistPtr::dynamicCast( item );
85
    if ( artistPtr )
86
        return actionsFor( artistPtr );
87
88
    Meta::AlbumPtr albumPtr = Meta::AlbumPtr::dynamicCast( item );
89
    if ( albumPtr )
90
        return actionsFor( albumPtr );
91
92
    Meta::TrackPtr trackPtr = Meta::TrackPtr::dynamicCast( item );
93
    if ( trackPtr )
94
        return actionsFor( trackPtr );
95
96
    Meta::YearPtr yearPtr = Meta::YearPtr::dynamicCast( item );
97
    if ( yearPtr )
98
        return actionsFor( yearPtr );
99
100
    Meta::ComposerPtr composerPtr = Meta::ComposerPtr::dynamicCast( item );
101
    if ( composerPtr )
102
        return actionsFor( composerPtr );
103
104
    QList< QAction * > emptyList;
105
    return emptyList;
106
}
107
108
109
QList< QAction * >
110
GlobalCollectionActions::actionsFor( Meta::GenrePtr genre )
111
{
112
    QList< QAction * > returnList;
113
    foreach( GlobalCollectionGenreAction * genreAction, m_genreActions )
114
    {
115
        genreAction->setGenre( genre );
116
        returnList.append( genreAction );
117
    }
118
119
    return returnList;
120
}
121
122
QList< QAction * >
123
GlobalCollectionActions::actionsFor( Meta::ArtistPtr artist )
124
{
125
    QList< QAction * > returnList;
126
    foreach( GlobalCollectionArtistAction * artistAction, m_artistActions )
127
    {
128
        artistAction->setArtist( artist );
129
        returnList.append( artistAction );
130
    }
131
132
    return returnList;
133
}
134
135
QList< QAction * >
136
GlobalCollectionActions::actionsFor( Meta::AlbumPtr album )
137
{
138
    QList< QAction * > returnList;
139
    foreach( GlobalCollectionAlbumAction * albumAction, m_albumActions )
140
    {
141
        albumAction->setAlbum( album );
142
        returnList.append( albumAction );
143
    }
144
145
    return returnList;
146
}
147
148
QList< QAction * >
149
GlobalCollectionActions::actionsFor( Meta::TrackPtr track )
150
{
151
    QList< QAction * > returnList;
152
    foreach( GlobalCollectionTrackAction * trackAction, m_trackActions )
153
    {
154
        trackAction->setTrack( track );
155
        returnList.append( trackAction );
156
    }
157
158
    return returnList;
159
}
160
161
QList< QAction * >
162
GlobalCollectionActions::actionsFor( Meta::YearPtr year )
163
{
164
    QList< QAction * > returnList;
165
    foreach( GlobalCollectionYearAction * yearAction, m_yearActions )
166
    {
167
        yearAction->setYear( year );
168
        returnList.append( yearAction );
169
    }
170
171
    return returnList;
172
}
173
174
QList< QAction * >
175
GlobalCollectionActions::actionsFor( Meta::ComposerPtr composer )
176
{
177
    QList< QAction * > returnList;
178
    foreach( GlobalCollectionComposerAction * composerAction, m_composerActions )
179
    {
180
        composerAction->setComposer( composer );
181
        returnList.append( composerAction );
182
    }
183
184
    return returnList;
185
}
186
187
GlobalCollectionAction::GlobalCollectionAction( const QString &text, QObject * parent )
188
    : QAction( text, parent )
189
{}
190
191
GlobalCollectionGenreAction::GlobalCollectionGenreAction( const QString &text, QObject * parent )
192
    : GlobalCollectionAction( text, parent )
193
{}
194
195
void
196
GlobalCollectionGenreAction::setGenre( Meta::GenrePtr genre )
197
{
198
    m_currentGenre = genre;
199
}
200
201
Meta::GenrePtr GlobalCollectionGenreAction::genre()
202
{
203
    return m_currentGenre;
204
}
205
206
GlobalCollectionArtistAction::GlobalCollectionArtistAction( const QString &text, QObject * parent )
207
    : GlobalCollectionAction( text, parent )
208
{}
209
210
void
211
GlobalCollectionArtistAction::setArtist( Meta::ArtistPtr artist )
212
{
213
    m_currentArtist = artist;
214
}
215
216
Meta::ArtistPtr GlobalCollectionArtistAction::artist()
217
{
218
    return m_currentArtist;
219
}
220
221
GlobalCollectionAlbumAction::GlobalCollectionAlbumAction( const QString &text, QObject * parent )
222
    : GlobalCollectionAction( text, parent )
223
{}
224
225
void GlobalCollectionAlbumAction::setAlbum( Meta::AlbumPtr album )
226
{
227
    m_currentAlbum = album;
228
}
229
230
Meta::AlbumPtr GlobalCollectionAlbumAction::album()
231
{
232
    return m_currentAlbum;
233
}
234
235
GlobalCollectionTrackAction::GlobalCollectionTrackAction( const QString &text, QObject * parent )
236
    : GlobalCollectionAction( text, parent )
237
{}
238
239
void GlobalCollectionTrackAction::setTrack( Meta::TrackPtr track )
240
{
241
    m_currentTrack = track;
242
}
243
244
Meta::TrackPtr
245
GlobalCollectionTrackAction::track()
246
{
247
    return m_currentTrack;
248
}
249
250
GlobalCollectionYearAction::GlobalCollectionYearAction( const QString &text, QObject * parent )
251
    : GlobalCollectionAction( text, parent )
252
{}
253
254
void
255
GlobalCollectionYearAction::setYear( Meta::YearPtr year )
256
{
257
    m_currentYear = year;
258
}
259
260
Meta::YearPtr
261
GlobalCollectionYearAction::year()
262
{
263
    return m_currentYear;
264
}
265
266
GlobalCollectionComposerAction::GlobalCollectionComposerAction( const QString &text, QObject * parent )
267
    : GlobalCollectionAction( text, parent )
268
{}
269
270
void
271
GlobalCollectionComposerAction::setComposer(Meta::ComposerPtr composer)
272
{
273
    m_currentComposer = composer;
274
}
275
276
Meta::ComposerPtr
277
GlobalCollectionComposerAction::composer()
278
{
279
    return m_currentComposer;
280
}