File: cli.h

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (68 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download
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
#ifndef CLI_H
#define CLI_H

#include "db/db.h"
#include <QObject>
#include <QTextStream>
#include <QStringList>
#include <QTime>

class QThread;
class QFile;
class DbManager;
class CliCommand;

class CLI : public QObject
{
    Q_OBJECT

    public:
        ~CLI();

        static CLI* getInstance();
        static void dispose();

        void start();
        void setCurrentDb(Db* db);
        Db* getCurrentDb() const;
        void exit();
        QStringList getHistory() const;
        QString getLine() const;
        void applyHistoryLimit();

    private:
        explicit CLI(QObject* parent = nullptr);

        void waitForExecution();
        bool isComplete(const QString& contents) const;
        void loadHistory();
        void addHistory(const QString& text);
        void println(const QString& msg = QString());
        int historyLength() const;

        static CLI* instance;

        QString lastHistoryEntry;
        QThread* thread = nullptr;
        Db* currentDb = nullptr;
        bool executionFinished = false;
        bool doExit = false;
        QString line;

    private slots:
        void printInfo(const QString& msg);
        void printWarn(const QString& msg);
        void printError(const QString& msg);

    public slots:
        void doWork();
        void done();
        void executionComplete();
        void clearHistory();
        bool openDbFile(const QString& path);

    signals:
        void execCommand(CliCommand* cmd);
};

#endif // CLI_H