2 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "MetaQueryBuilder.h"
25 MetaQueryBuilder::MetaQueryBuilder( const QList
<Collection
*> &collections
)
27 , m_queryDoneCount( 0 )
28 , m_queryDoneCountMutex()
30 foreach( Collection
*c
, collections
)
32 QueryMaker
*b
= c
->queryMaker();
34 connect( b
, SIGNAL( queryDone() ), this, SLOT( slotQueryDone() ) );
35 //relay signals directly
36 connect( b
, SIGNAL( newResultReady( QString
, Meta::TrackList
) ), this, SIGNAL( newResultReady( QString
, Meta::TrackList
) ), Qt::DirectConnection
);
37 connect( b
, SIGNAL( newResultReady( QString
, Meta::ArtistList
) ), this, SIGNAL( newResultReady( QString
, Meta::ArtistList
) ), Qt::DirectConnection
);
38 connect( b
, SIGNAL( newResultReady( QString
, Meta::AlbumList
) ), this, SIGNAL( newResultReady( QString
, Meta::AlbumList
) ), Qt::DirectConnection
);
39 connect( b
, SIGNAL( newResultReady( QString
, Meta::GenreList
) ), this, SIGNAL( newResultReady( QString
, Meta::GenreList
) ), Qt::DirectConnection
);
40 connect( b
, SIGNAL( newResultReady( QString
, Meta::ComposerList
) ), this, SIGNAL( newResultReady( QString
, Meta::ComposerList
) ), Qt::DirectConnection
);
41 connect( b
, SIGNAL( newResultReady( QString
, Meta::YearList
) ), this, SIGNAL( newResultReady( QString
, Meta::YearList
) ), Qt::DirectConnection
);
42 connect( b
, SIGNAL( newResultReady( QString
, QStringList
) ), this, SIGNAL( newResultReady( QString
, QStringList
) ), Qt::DirectConnection
);
43 connect( b
, SIGNAL( newResultReady( QString
, Meta::DataList
) ), this, SIGNAL( newResultReady( QString
, Meta::DataList
) ), Qt::DirectConnection
);
47 MetaQueryBuilder::~MetaQueryBuilder()
49 foreach( QueryMaker
*b
, builders
)
54 MetaQueryBuilder::reset()
57 foreach( QueryMaker
*b
, builders
)
63 MetaQueryBuilder::run()
65 foreach( QueryMaker
*b
, builders
)
70 MetaQueryBuilder::abortQuery()
72 foreach( QueryMaker
*b
, builders
)
77 MetaQueryBuilder::resultCount() const
79 return builders
.count();
83 MetaQueryBuilder::startTrackQuery()
85 foreach( QueryMaker
*b
, builders
)
91 MetaQueryBuilder::startArtistQuery()
93 foreach( QueryMaker
*b
, builders
)
94 b
->startArtistQuery();
99 MetaQueryBuilder::startAlbumQuery()
101 foreach( QueryMaker
*b
, builders
)
102 b
->startAlbumQuery();
107 MetaQueryBuilder::startGenreQuery()
109 foreach( QueryMaker
*b
, builders
)
110 b
->startGenreQuery();
115 MetaQueryBuilder::startComposerQuery()
117 foreach( QueryMaker
*b
, builders
)
118 b
->startComposerQuery();
123 MetaQueryBuilder::startYearQuery()
125 foreach( QueryMaker
*b
, builders
)
131 MetaQueryBuilder::startCustomQuery()
133 foreach( QueryMaker
*b
, builders
)
134 b
->startCustomQuery();
139 MetaQueryBuilder::addReturnValue( qint64 value
)
141 foreach( QueryMaker
*b
, builders
)
142 b
->addReturnValue( value
);
147 MetaQueryBuilder::orderBy( qint64 value
, bool descending
)
149 foreach( QueryMaker
*b
, builders
)
150 b
->orderBy( value
, descending
);
155 MetaQueryBuilder::includeCollection( const QString
&collectionId
)
157 foreach( QueryMaker
*b
, builders
)
158 b
->includeCollection( collectionId
);
163 MetaQueryBuilder::excludeCollection( const QString
&collectionId
)
165 foreach( QueryMaker
*b
, builders
)
166 b
->excludeCollection( collectionId
);
171 MetaQueryBuilder::addFilter( qint64 value
, const QString
&filter
, bool matchBegin
, bool matchEnd
)
173 foreach( QueryMaker
*b
, builders
)
174 b
->addFilter( value
, filter
, matchBegin
, matchEnd
);
179 MetaQueryBuilder::excludeFilter( qint64 value
, const QString
&filter
, bool matchBegin
, bool matchEnd
)
181 foreach( QueryMaker
*b
, builders
)
182 b
->excludeFilter( value
, filter
, matchBegin
, matchEnd
);
187 MetaQueryBuilder::addMatch( const TrackPtr
&track
)
189 foreach( QueryMaker
*b
, builders
)
190 b
->addMatch( track
);
195 MetaQueryBuilder::addMatch( const ArtistPtr
&artist
)
197 foreach( QueryMaker
*b
, builders
)
198 b
->addMatch( artist
);
203 MetaQueryBuilder::addMatch( const AlbumPtr
&album
)
205 foreach( QueryMaker
*b
, builders
)
206 b
->addMatch( album
);
211 MetaQueryBuilder::addMatch( const GenrePtr
&genre
)
213 foreach( QueryMaker
*b
, builders
)
214 b
->addMatch( genre
);
219 MetaQueryBuilder::addMatch( const ComposerPtr
&composer
)
221 foreach( QueryMaker
*b
, builders
)
222 b
->addMatch( composer
);
227 MetaQueryBuilder::addMatch( const YearPtr
&year
)
229 foreach( QueryMaker
*b
, builders
)
235 MetaQueryBuilder::addMatch( const DataPtr
&data
)
237 DataPtr tmp
= const_cast<DataPtr
&>( data
);
238 foreach( QueryMaker
*b
, builders
)
239 tmp
->addMatchTo( b
);
244 MetaQueryBuilder::returnResultAsDataPtrs( bool resultAsDataPtrs
)
246 foreach( QueryMaker
*b
, builders
)
247 b
->returnResultAsDataPtrs( resultAsDataPtrs
);
252 MetaQueryBuilder::limitMaxResultSize( int size
)
254 foreach( QueryMaker
*b
, builders
)
255 b
->limitMaxResultSize( size
);
260 MetaQueryBuilder::beginAnd()
262 foreach( QueryMaker
*b
, builders
)
268 MetaQueryBuilder::beginOr()
270 foreach( QueryMaker
*b
, builders
)
276 MetaQueryBuilder::endAndOr()
278 foreach( QueryMaker
*b
, builders
)
284 MetaQueryBuilder::slotQueryDone()
286 m_queryDoneCountMutex
.lock();
288 if ( m_queryDoneCount
== builders
.size() )
290 //make sure we don't give control to code outside this class while holding the lock
291 m_queryDoneCountMutex
.unlock();
295 m_queryDoneCountMutex
.unlock();
298 #include "MetaQueryBuilder.moc"