File indexing completed on 2025-02-23 04:28:33

0001 /****************************************************************************************
0002  * Copyright (c) 2013 Anmol Ahuja <darthcodus@gmail.com>                                *
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 #ifndef QUERYMAKER_EXPORTER_H
0018 #define QUERYMAKER_EXPORTER_H
0019 
0020 #include "amarok_export.h"
0021 #include "core/collections/QueryMaker.h"
0022 #include "core/meta/Meta.h"
0023 
0024 #include <QObject>
0025 #include <QPointer>
0026 #include <QString>
0027 
0028 namespace Collections
0029 {
0030     class QueryMaker;
0031 }
0032 class QJSEngine;
0033 
0034 namespace AmarokScript
0035 {
0036     // SCRIPTDOX PROTOTYPE Collections::QueryMaker QueryMaker
0037     #ifdef DEBUG
0038     class AMAROK_EXPORT
0039     #else
0040     class
0041     #endif
0042     QueryMakerPrototype : public QObject
0043     {
0044         Q_OBJECT
0045 
0046         /**
0047          * Indicates whether this query maker object is valid.
0048          */
0049         Q_PROPERTY( bool isValid READ isValid )
0050 
0051         /**
0052          * The current filter string.
0053          */
0054         Q_PROPERTY( QString filter READ filter )
0055 
0056     public:
0057         static void init( QJSEngine *engine );
0058         QueryMakerPrototype( Collections::QueryMaker *collection );
0059         ~QueryMakerPrototype() override;
0060         Collections::QueryMaker *data() const { return m_querymaker; }
0061 
0062         /**
0063          *  Starts the query. This method returns immediately. All processing is done in one or more
0064          *  separate worker thread(s). One of the newResultReady signals will be emitted at least once,
0065          *  followed by the queryDone() signal exactly once.
0066          */
0067         Q_INVOKABLE void run();
0068 
0069         /**
0070          * Block until the query completes, returns the tracklist.
0071          */
0072         Q_INVOKABLE Meta::TrackList blockingRun();
0073 
0074         /**
0075          *  Aborts a running query.
0076          */
0077         Q_INVOKABLE void abort();
0078 
0079         /**
0080          * Add a filter query to this query maker.
0081          */
0082         Q_INVOKABLE void addFilter( const QString &filter );
0083 
0084     private:
0085         QPointer<Collections::QueryMaker> m_querymaker;
0086         QString m_filter;
0087         Meta::TrackList m_result;
0088 
0089         bool isValid() const;
0090         QString filter() const;
0091 
0092     private Q_SLOTS:
0093         void slotResult( const Meta::TrackList &tracks );
0094 
0095     Q_SIGNALS:
0096         /**
0097          * newResultReady will be emitted every time new results from the query maker are received.
0098          * This signal can be emitted zero times (in case of no results) one (the usual case) or multiple times
0099          * (e.g. in case when the result is received in several batches).
0100          * The results will be terminated by a queryDone signal.
0101          */
0102         void newResultReady( Meta::TrackList );
0103 
0104         /**
0105          * This signal is emitted after all the results have been submitted via zero or more newResultReady signals.
0106          */
0107         void queryDone();
0108     };
0109 }
0110 
0111 #endif