-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathJSResolverHelper.h
152 lines (118 loc) · 4.75 KB
/
JSResolverHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2014, Christian Muehlhaeuser <[email protected]>
* Copyright 2010-2011, Leo Franchi <[email protected]>
* Copyright 2013, Teo Mrnjavac <[email protected]>
* Copyright 2013, Uwe L. Korn <[email protected]>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JSRESOLVERHELPER_H
#define JSRESOLVERHELPER_H
#include "DllMacro.h"
#include "Typedefs.h"
#include "UrlHandler.h"
#include "database/fuzzyindex/FuzzyIndex.h"
#include "utils/NetworkReply.h"
#include <QObject>
#include <QVariantMap>
#include <functional>
Q_DECLARE_METATYPE( std::function< void( QSharedPointer< QIODevice >& ) > )
namespace Tomahawk
{
class JSResolver;
class DLLEXPORT JSResolverHelper : public QObject
{
Q_OBJECT
public:
JSResolverHelper( const QString& scriptPath, JSResolver* parent );
/**
* INTERNAL USE ONLY!
*/
void setResolverConfig( const QVariantMap& config );
void start();
void stop();
/**
* Get the instance unique account id for this resolver.
*
* INTERNAL USE ONLY!
*/
Q_INVOKABLE QString accountId();
/**
* Make Tomahawk assert the assertion is true, probably not to be used by resolvers directly
*/
Q_INVOKABLE void nativeAssert( bool assertion, const QString& message = QString() );
/**
* Retrieve metadata for a media stream.
*
* Current suported transport protocols are:
* * HTTP
* * HTTPS
*
* This method is asynchronous and will call
* Tomahawk.retrievedMetadata(metadataId, metadata, error)
* on completion. This method is an internal variant, JavaScript resolvers
* are advised to use Tomahawk.retrieveMetadata(url, options, callback).
*
* INTERNAL USE ONLY!
*/
Q_INVOKABLE void nativeRetrieveMetadata( int metadataId, const QString& url,
const QString& mimetype,
int sizehint,
const QVariantMap& options );
Q_INVOKABLE void invokeNativeScriptJob( int requestId,
const QString& methodName,
const QVariantMap& params );
/**
* Lucene++ indices for JS resolvers
**/
Q_INVOKABLE bool hasFuzzyIndex();
Q_INVOKABLE void createFuzzyIndex( const QVariantList& list );
Q_INVOKABLE void addToFuzzyIndex( const QVariantList& list );
Q_INVOKABLE QVariantList searchFuzzyIndex( const QString& query );
Q_INVOKABLE QVariantList resolveFromFuzzyIndex( const QString& artist, const QString& album, const QString& tracks );
Q_INVOKABLE void deleteFuzzyIndex();
/**
* This is horrible, we can use it to invalidate resolver results when the config changes
* TODO: register the resolver through registerPlugin and remove it through standard methods
*/
Q_INVOKABLE void readdResolver();
public slots:
QByteArray readRaw( const QString& fileName );
QString readBase64( const QString& fileName );
QString readCompressed( const QString& fileName );
QString uuid() const;
int currentCountry() const;
QString compress( const QString& data );
QVariantMap resolverData();
void log( const QString& message );
bool fakeEnv() { return false; }
void nativeReportCapabilities( const QVariant& capabilities );
void reportScriptJobResults( const QVariantMap& result );
void registerScriptPlugin( const QString& type, const QString& objectId );
void unregisterScriptPlugin( const QString& type, const QString& objectId );
private slots:
void nativeAsyncRequestDone( int requestId, NetworkReply* reply );
private:
bool indexDataFromVariant( const QVariantMap& map, struct Tomahawk::IndexData& indexData );
QVariantList searchInFuzzyIndex( const Tomahawk::query_ptr& query );
// native script jobs
void nativeAsyncRequest( int requestId, const QVariantMap& options );
QVariantMap m_resolverConfig;
JSResolver* m_resolver;
QString m_scriptPath;
bool m_stopped;
};
} // ns: Tomahawk
#endif // JSRESOLVERHELPER_H