PageRenderTime 253ms CodeModel.GetById 120ms app.highlight 8ms RepoModel.GetById 83ms app.codeStats 0ms

/src/libtomahawk/resolvers/ScriptResolver.h

http://github.com/tomahawk-player/tomahawk
C Header | 111 lines | 65 code | 27 blank | 19 comment | 0 complexity | f294dfdf6ebf9653dfb6aceeaf254133 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, Leo Franchi            <lfranchi@kde.org>
  5 *   Copyright 2013,      Teo Mrnjavac           <teo@kde.org>
  6 *
  7 *   Tomahawk is free software: you can redistribute it and/or modify
  8 *   it under the terms of the GNU General Public License as published by
  9 *   the Free Software Foundation, either version 3 of the License, or
 10 *   (at your option) any later version.
 11 *
 12 *   Tomahawk is distributed in the hope that it will be useful,
 13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *   GNU General Public License for more details.
 16 *
 17 *   You should have received a copy of the GNU General Public License
 18 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21#ifndef SCRIPTRESOLVER_H
 22#define SCRIPTRESOLVER_H
 23
 24#include "Query.h"
 25#include "Artist.h"
 26#include "Album.h"
 27#include "collection/Collection.h"
 28#include "ExternalResolverGui.h"
 29#include "DllMacro.h"
 30
 31#include <QProcess>
 32
 33class QWidget;
 34
 35namespace Tomahawk
 36{
 37
 38class DLLEXPORT ScriptResolver : public Tomahawk::ExternalResolverGui
 39{
 40Q_OBJECT
 41
 42public:
 43    explicit ScriptResolver( const QString& exe );
 44    virtual ~ScriptResolver();
 45    static ExternalResolver* factory( const QString& accountId, const QString& exe, const QStringList& );
 46
 47    QString name() const Q_DECL_OVERRIDE { return m_name; }
 48    QPixmap icon( const QSize& size ) const Q_DECL_OVERRIDE;
 49    unsigned int weight() const Q_DECL_OVERRIDE { return m_weight; }
 50    virtual unsigned int preference() const { return m_preference; }
 51    unsigned int timeout() const Q_DECL_OVERRIDE { return m_timeout; }
 52    Capabilities capabilities() const Q_DECL_OVERRIDE { return m_capabilities; }
 53
 54    void setIcon( const QPixmap& icon ) Q_DECL_OVERRIDE;
 55
 56    AccountConfigWidget* configUI() const Q_DECL_OVERRIDE;
 57    void saveConfig() Q_DECL_OVERRIDE;
 58
 59    ExternalResolver::ErrorState error() const Q_DECL_OVERRIDE;
 60    void reload() Q_DECL_OVERRIDE;
 61
 62    bool running() const Q_DECL_OVERRIDE;
 63
 64    void sendMessage( const QVariantMap& map );
 65
 66    bool canParseUrl( const QString&, UrlType ) Q_DECL_OVERRIDE { return false; }
 67
 68signals:
 69    void terminated();
 70    void customMessage( const QString& msgType, const QVariantMap& msg );
 71
 72public slots:
 73    void stop() Q_DECL_OVERRIDE;
 74    void resolve( const Tomahawk::query_ptr& query ) Q_DECL_OVERRIDE;
 75    void start() Q_DECL_OVERRIDE;
 76
 77    void lookupUrl( const QString&  ) Q_DECL_OVERRIDE {}
 78
 79
 80private slots:
 81    void readStderr();
 82    void readStdout();
 83    void cmdExited( int code, QProcess::ExitStatus status );
 84
 85private:
 86    void sendConfig();
 87
 88    void handleMsg( const QByteArray& msg );
 89    void sendMsg( const QByteArray& msg );
 90    void doSetup( const QVariantMap& m );
 91    void setupConfWidget( const QVariantMap& m );
 92
 93    void startProcess();
 94
 95    QProcess m_proc;
 96    QString m_name;
 97    QPixmap m_icon;
 98    unsigned int m_weight, m_preference, m_timeout, m_num_restarts;
 99    Capabilities m_capabilities;
100    QPointer< AccountConfigWidget > m_configWidget;
101
102    quint32 m_msgsize;
103    QByteArray m_msg;
104
105    bool m_ready, m_stopped, m_configSent, m_deleting;
106    ExternalResolver::ErrorState m_error;
107};
108
109}
110
111#endif // SCRIPTRESOLVER_H