File size: 1,655 Bytes
b6bd94d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
 * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */

#pragma once

#include <QProcess>
#include "dictionary.hh"
#include "config.hh"

/// Support for arbitrary programs.
namespace Programs {

using std::vector;
using std::string;

vector< sptr< Dictionary::Class > > makeDictionaries( const Config::Programs & );

class RunInstance: public QObject
{
  Q_OBJECT
  QProcess process;

public:

  RunInstance();

  // Starts the process. Should only be used once. The finished() signal will
  // be emitted once it finishes. If there's an error, returns false and the
  // description is saved to 'error'.
  bool start( const Config::Program &, const QString & word, QString & error );

signals:
  // Connect to this signal to get run results
  void finished( QByteArray output, QString error );

  // Used internally only
signals:
  void processFinished();
private slots:

  void handleProcessFinished();
};

class ProgramDataRequest: public Dictionary::DataRequest
{
  Q_OBJECT
  Config::Program prg;
  RunInstance instance;

public:

  ProgramDataRequest( const QString & word, const Config::Program & );

  virtual void cancel();

private slots:

  void instanceFinished( QByteArray output, QString error );
};

class ProgramWordSearchRequest: public Dictionary::WordSearchRequest
{
  Q_OBJECT
  Config::Program prg;
  RunInstance instance;

public:

  ProgramWordSearchRequest( const QString & word, const Config::Program & );

  virtual void cancel();

private slots:

  void instanceFinished( QByteArray output, QString error );
};

} // namespace Programs