File indexing completed on 2024-04-21 04:47:50

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016  
0017 #include "GlobalCollectionActions.h"
0018 #include "core/meta/Meta.h"
0019 
0020 
0021 namespace The
0022 {
0023     static GlobalCollectionActions* s_GlobalCollectionActions_instance = nullptr;
0024 
0025     GlobalCollectionActions* globalCollectionActions()
0026     {
0027         if( !s_GlobalCollectionActions_instance )
0028             s_GlobalCollectionActions_instance = new GlobalCollectionActions();
0029 
0030         return s_GlobalCollectionActions_instance;
0031     }
0032 }
0033 
0034 GlobalCollectionActions::GlobalCollectionActions()
0035 {}
0036 
0037 
0038 GlobalCollectionActions::~GlobalCollectionActions()
0039 {}
0040 
0041 void
0042 GlobalCollectionActions::addGenreAction( GlobalCollectionGenreAction * action )
0043 {
0044     if( !action )
0045         return;
0046 
0047     m_genreActions.append( action );
0048     connect( action, &QObject::destroyed, this, [this, action]() { m_genreActions.removeAll( action ); } );
0049 }
0050 
0051 void
0052 GlobalCollectionActions::addArtistAction( GlobalCollectionArtistAction * action )
0053 {
0054     if( !action )
0055         return;
0056 
0057     m_artistActions.append( action );
0058     connect( action, &QObject::destroyed, this, [this, action]() { m_artistActions.removeAll( action ); } );
0059 }
0060 
0061 void
0062 GlobalCollectionActions::addAlbumAction( GlobalCollectionAlbumAction * action )
0063 {
0064     if( !action )
0065         return;
0066 
0067     m_albumActions.append( action );
0068     connect( action, &QObject::destroyed, this, [this, action]() { m_albumActions.removeAll( action ); } );
0069 }
0070 
0071 void
0072 GlobalCollectionActions::addTrackAction( GlobalCollectionTrackAction * action )
0073 {
0074     if( !action )
0075         return;
0076 
0077     m_trackActions.append( action );
0078     connect( action, &QObject::destroyed, this, [this, action]() { m_trackActions.removeAll( action ); } );
0079 }
0080 
0081 void
0082 GlobalCollectionActions::addYearAction( GlobalCollectionYearAction * action )
0083 {
0084     if( !action )
0085         return;
0086 
0087     m_yearActions.append( action );
0088     connect( action, &QObject::destroyed, this, [this, action]() { m_yearActions.removeAll( action ); } );
0089 }
0090 
0091 void
0092 GlobalCollectionActions::addComposerAction( GlobalCollectionComposerAction * action )
0093 {
0094     if( !action )
0095         return;
0096 
0097     m_composerActions.append( action );
0098     connect( action, &QObject::destroyed, this, [this, action]() { m_composerActions.removeAll( action ); } );
0099 }
0100 
0101 QList< QAction * > GlobalCollectionActions::actionsFor( const Meta::DataPtr &item )
0102 {
0103 
0104     Meta::GenrePtr genrePtr = Meta::GenrePtr::dynamicCast( item );
0105     if ( genrePtr )
0106         return actionsFor( genrePtr );
0107 
0108     Meta::ArtistPtr artistPtr = Meta::ArtistPtr::dynamicCast( item );
0109     if ( artistPtr )
0110         return actionsFor( artistPtr );
0111 
0112     Meta::AlbumPtr albumPtr = Meta::AlbumPtr::dynamicCast( item );
0113     if ( albumPtr )
0114         return actionsFor( albumPtr );
0115 
0116     Meta::TrackPtr trackPtr = Meta::TrackPtr::dynamicCast( item );
0117     if ( trackPtr )
0118         return actionsFor( trackPtr );
0119 
0120     Meta::YearPtr yearPtr = Meta::YearPtr::dynamicCast( item );
0121     if ( yearPtr )
0122         return actionsFor( yearPtr );
0123 
0124     Meta::ComposerPtr composerPtr = Meta::ComposerPtr::dynamicCast( item );
0125     if ( composerPtr )
0126         return actionsFor( composerPtr );
0127 
0128     QList< QAction * > emptyList;
0129     return emptyList;
0130 }
0131 
0132 
0133 QList< QAction * >
0134 GlobalCollectionActions::actionsFor( const Meta::GenrePtr &genre )
0135 {
0136     QList< QAction * > returnList;
0137     foreach( GlobalCollectionGenreAction * genreAction, m_genreActions )
0138     {
0139         genreAction->setGenre( genre );
0140         returnList.append( genreAction );
0141     }
0142 
0143     return returnList;
0144 }
0145 
0146 QList< QAction * >
0147 GlobalCollectionActions::actionsFor( const Meta::ArtistPtr &artist )
0148 {
0149     QList< QAction * > returnList;
0150     foreach( GlobalCollectionArtistAction * artistAction, m_artistActions )
0151     {
0152         artistAction->setArtist( artist );
0153         returnList.append( artistAction );
0154     }
0155 
0156     return returnList;
0157 }
0158 
0159 QList< QAction * >
0160 GlobalCollectionActions::actionsFor( const Meta::AlbumPtr &album )
0161 {
0162     QList< QAction * > returnList;
0163     foreach( GlobalCollectionAlbumAction * albumAction, m_albumActions )
0164     {
0165         albumAction->setAlbum( album );
0166         returnList.append( albumAction );
0167     }
0168 
0169     return returnList;
0170 }
0171 
0172 QList< QAction * >
0173 GlobalCollectionActions::actionsFor( const Meta::TrackPtr &track )
0174 {
0175     QList< QAction * > returnList;
0176     foreach( GlobalCollectionTrackAction * trackAction, m_trackActions )
0177     {
0178         trackAction->setTrack( track );
0179         returnList.append( trackAction );
0180     }
0181 
0182     return returnList;
0183 }
0184 
0185 QList< QAction * >
0186 GlobalCollectionActions::actionsFor( const Meta::YearPtr &year )
0187 {
0188     QList< QAction * > returnList;
0189     foreach( GlobalCollectionYearAction * yearAction, m_yearActions )
0190     {
0191         yearAction->setYear( year );
0192         returnList.append( yearAction );
0193     }
0194 
0195     return returnList;
0196 }
0197 
0198 QList< QAction * >
0199 GlobalCollectionActions::actionsFor( const Meta::ComposerPtr &composer )
0200 {
0201     QList< QAction * > returnList;
0202     foreach( GlobalCollectionComposerAction * composerAction, m_composerActions )
0203     {
0204         composerAction->setComposer( composer );
0205         returnList.append( composerAction );
0206     }
0207 
0208     return returnList;
0209 }
0210 
0211 GlobalCollectionAction::GlobalCollectionAction( const QString &text, QObject * parent )
0212     : QAction( text, parent )
0213 {}
0214 
0215 GlobalCollectionGenreAction::GlobalCollectionGenreAction( const QString &text, QObject * parent )
0216     : GlobalCollectionAction( text, parent )
0217 {}
0218 
0219 void
0220 GlobalCollectionGenreAction::setGenre( const Meta::GenrePtr &genre )
0221 {
0222     m_currentGenre = genre;
0223 }
0224 
0225 Meta::GenrePtr GlobalCollectionGenreAction::genre()
0226 {
0227     return m_currentGenre;
0228 }
0229 
0230 GlobalCollectionArtistAction::GlobalCollectionArtistAction( const QString &text, QObject * parent )
0231     : GlobalCollectionAction( text, parent )
0232 {}
0233 
0234 void
0235 GlobalCollectionArtistAction::setArtist( const Meta::ArtistPtr &artist )
0236 {
0237     m_currentArtist = artist;
0238 }
0239 
0240 Meta::ArtistPtr GlobalCollectionArtistAction::artist()
0241 {
0242     return m_currentArtist;
0243 }
0244 
0245 GlobalCollectionAlbumAction::GlobalCollectionAlbumAction( const QString &text, QObject * parent )
0246     : GlobalCollectionAction( text, parent )
0247 {}
0248 
0249 void GlobalCollectionAlbumAction::setAlbum( const Meta::AlbumPtr &album )
0250 {
0251     m_currentAlbum = album;
0252 }
0253 
0254 Meta::AlbumPtr GlobalCollectionAlbumAction::album()
0255 {
0256     return m_currentAlbum;
0257 }
0258 
0259 GlobalCollectionTrackAction::GlobalCollectionTrackAction( const QString &text, QObject * parent )
0260     : GlobalCollectionAction( text, parent )
0261 {}
0262 
0263 void GlobalCollectionTrackAction::setTrack( const Meta::TrackPtr &track )
0264 {
0265     m_currentTrack = track;
0266 }
0267 
0268 Meta::TrackPtr
0269 GlobalCollectionTrackAction::track()
0270 {
0271     return m_currentTrack;
0272 }
0273 
0274 GlobalCollectionYearAction::GlobalCollectionYearAction( const QString &text, QObject * parent )
0275     : GlobalCollectionAction( text, parent )
0276 {}
0277 
0278 void
0279 GlobalCollectionYearAction::setYear( const Meta::YearPtr &year )
0280 {
0281     m_currentYear = year;
0282 }
0283 
0284 Meta::YearPtr
0285 GlobalCollectionYearAction::year()
0286 {
0287     return m_currentYear;
0288 }
0289 
0290 GlobalCollectionComposerAction::GlobalCollectionComposerAction( const QString &text, QObject * parent )
0291     : GlobalCollectionAction( text, parent )
0292 {}
0293 
0294 void
0295 GlobalCollectionComposerAction::setComposer(const Meta::ComposerPtr &composer)
0296 {
0297     m_currentComposer = composer;
0298 }
0299 
0300 Meta::ComposerPtr
0301 GlobalCollectionComposerAction::composer()
0302 {
0303     return m_currentComposer;
0304 }
0305 
0306