summaryrefslogtreecommitdiff
path: root/backend.h
blob: 997b5807d901770328f8c97db3e5efb244a821db (plain)
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
#include <QProcess>
#include <QQueue>
#include <QMap>
#include <QVector>

#ifndef BACKEND_H
#define BACKEND_H

class Backend : public QObject
{
    Q_OBJECT

public:
    static Backend* instance() {if(!_instance) _instance = new Backend(); return(_instance);}
    ~Backend();
    void init();
    void runBackend();
    void exec(QString command);
    void exitBackend();
    QString encryptPassword(QString password);
    QString cleanUsername(const QString &username);
    bool isBusy();
    bool flag(QString flag);
    void flag(QString flag, bool set);
    QString cfg(QString var);
    void cfg(QString var, QString value);
      
protected:
    QProcess* _process;

private slots:
    void slotProcessExited();
    void slotReceiveOutput();

private:
    static Backend *_instance;
    Backend();
    void processOutput(QString line);
    void _flag(QString flag, bool set);
    void _cfg(QString var, QString value);
    void dequeue();
    QMap<QString,QString> data;
    QString currentData;
    QMap<QString,QString> cfgMap;
    QVector<QString> flags;
    QQueue<QString> commandQueue;
    QString currentCommand;
    bool busy;
    
signals:
    void processExited();
    void receivedDataLine(QString data, QString line);
    void receivedProgress(int percent);
    void receivedCommand(QString command, QString args);
    void finishedCommand(QString command);
    void isBusy(bool busy);
};

#endif