/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. #ifndef SCRIPTRESOLVER_H
  21. #define SCRIPTRESOLVER_H
  22. #include "Query.h"
  23. #include "Artist.h"
  24. #include "Album.h"
  25. #include "collection/Collection.h"
  26. #include "ExternalResolverGui.h"
  27. #include "DllMacro.h"
  28. #include <QProcess>
  29. class QWidget;
  30. namespace Tomahawk
  31. {
  32. class DLLEXPORT ScriptResolver : public Tomahawk::ExternalResolverGui
  33. {
  34. Q_OBJECT
  35. public:
  36. explicit ScriptResolver( const QString& exe );
  37. virtual ~ScriptResolver();
  38. static ExternalResolver* factory( const QString& accountId, const QString& exe, const QStringList& );
  39. QString name() const Q_DECL_OVERRIDE { return m_name; }
  40. QPixmap icon( const QSize& size ) const Q_DECL_OVERRIDE;
  41. unsigned int weight() const Q_DECL_OVERRIDE { return m_weight; }
  42. virtual unsigned int preference() const { return m_preference; }
  43. unsigned int timeout() const Q_DECL_OVERRIDE { return m_timeout; }
  44. Capabilities capabilities() const Q_DECL_OVERRIDE { return m_capabilities; }
  45. void setIcon( const QPixmap& icon ) Q_DECL_OVERRIDE;
  46. AccountConfigWidget* configUI() const Q_DECL_OVERRIDE;
  47. void saveConfig() Q_DECL_OVERRIDE;
  48. ExternalResolver::ErrorState error() const Q_DECL_OVERRIDE;
  49. void reload() Q_DECL_OVERRIDE;
  50. bool running() const Q_DECL_OVERRIDE;
  51. void sendMessage( const QVariantMap& map );
  52. bool canParseUrl( const QString&, UrlType ) Q_DECL_OVERRIDE { return false; }
  53. signals:
  54. void terminated();
  55. void customMessage( const QString& msgType, const QVariantMap& msg );
  56. public slots:
  57. void stop() Q_DECL_OVERRIDE;
  58. void resolve( const Tomahawk::query_ptr& query ) Q_DECL_OVERRIDE;
  59. void start() Q_DECL_OVERRIDE;
  60. void lookupUrl( const QString& ) Q_DECL_OVERRIDE {}
  61. private slots:
  62. void readStderr();
  63. void readStdout();
  64. void cmdExited( int code, QProcess::ExitStatus status );
  65. private:
  66. void sendConfig();
  67. void handleMsg( const QByteArray& msg );
  68. void sendMsg( const QByteArray& msg );
  69. void doSetup( const QVariantMap& m );
  70. void setupConfWidget( const QVariantMap& m );
  71. void startProcess();
  72. QProcess m_proc;
  73. QString m_name;
  74. QPixmap m_icon;
  75. unsigned int m_weight, m_preference, m_timeout, m_num_restarts;
  76. Capabilities m_capabilities;
  77. QPointer< AccountConfigWidget > m_configWidget;
  78. quint32 m_msgsize;
  79. QByteArray m_msg;
  80. bool m_ready, m_stopped, m_configSent, m_deleting;
  81. ExternalResolver::ErrorState m_error;
  82. };
  83. }
  84. #endif // SCRIPTRESOLVER_H