File indexing completed on 2024-05-19 04:50:24
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Matěj Laitl <matej@laitl.cz> * 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 #define DEBUG_PREFIX "ScriptableServiceCollectionTreeModel" 0018 0019 #include "ScriptableServiceCollectionTreeModel.h" 0020 0021 #include "AmarokMimeData.h" 0022 #include "core/support/Debug.h" 0023 #include "core-impl/collections/support/TextualQueryFilter.h" 0024 #include "services/scriptable/ScriptableServiceMeta.h" 0025 #include "services/scriptable/ScriptableServiceQueryMaker.h" 0026 0027 ScriptableServiceCollectionTreeModel::ScriptableServiceCollectionTreeModel( 0028 Collections::Collection *collection, 0029 const QList<CategoryId::CatMenuId> &levelType ) 0030 : SingleCollectionTreeItemModel( collection, levelType ) 0031 { 0032 } 0033 0034 QMimeData * 0035 ScriptableServiceCollectionTreeModel::mimeData( const QList<CollectionTreeItem *> &items ) const 0036 { 0037 // this is basically a copy of superclass method with a couple of changes: 0038 // 1. we don't reuse tracks already in the model 0039 // 2. we tell the querymaker to masquerade special tracks 0040 0041 using namespace Collections; 0042 Meta::TrackList tracks; 0043 QList<QueryMaker *> queries; 0044 foreach( CollectionTreeItem *item, items ) 0045 { 0046 if( item->isTrackItem() ) 0047 { 0048 using namespace Meta; 0049 const ScriptableServiceTrack *serviceTrack = 0050 dynamic_cast<const ScriptableServiceTrack *>( item->data().data() ); 0051 if( !serviceTrack ) 0052 { 0053 error() << "failed to convert generic track" << item->data() << "to ScriptableServiceTrack"; 0054 continue; 0055 } 0056 tracks << serviceTrack->playableTrack(); 0057 continue; 0058 } 0059 0060 ScriptableServiceQueryMaker *qm = qobject_cast<ScriptableServiceQueryMaker *>( item->queryMaker() ); 0061 if( !qm ) 0062 { 0063 error() << "failed to convert generic QueryMaker to ScriptableService one"; 0064 continue; 0065 } 0066 qm->setConvertToMultiTracks( true ); 0067 for( CollectionTreeItem *tmp = item; tmp; tmp = tmp->parent() ) 0068 tmp->addMatch( qm, levelCategory( tmp->level() - 1 ) ); 0069 Collections::addTextualFilter( qm, m_currentFilter ); 0070 queries.append( qm ); 0071 } 0072 0073 if( queries.isEmpty() && tracks.isEmpty() ) 0074 return nullptr; 0075 0076 AmarokMimeData *mimeData = new AmarokMimeData(); 0077 mimeData->setTracks( tracks ); 0078 mimeData->setQueryMakers( queries ); 0079 mimeData->startQueries(); 0080 return mimeData; 0081 }