aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlpreview/qmlpreviewapplication.h
blob: 7e71c2dac518bace0869a4d137f6cb7d6fd2a478 (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
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#ifndef QMLPREVIEWAPPLICATION_H
#define QMLPREVIEWAPPLICATION_H

#include "qmlpreviewfilesystemwatcher.h"

#include <private/qqmlpreviewclient_p.h>
#include <private/qqmldebugconnection_p.h>

#include <QtCore/qcoreapplication.h>
#include <QtCore/qprocess.h>
#include <QtCore/qtimer.h>

#include <QtNetwork/qabstractsocket.h>

class QmlPreviewApplication : public QCoreApplication
{
    Q_OBJECT
public:
    QmlPreviewApplication(int &argc, char **argv);
    ~QmlPreviewApplication();

    void parseArguments();
    int exec();

private:
    void run();
    void tryToConnect();
    void processHasOutput();
    void processFinished();

    void logError(const QString &error);
    void logStatus(const QString &status);

    void serveRequest(const QString &request);
    bool sendFile(const QString &path);
    void sendDirectory(const QString &path);

    QString m_executablePath;
    QStringList m_arguments;
    QScopedPointer<QProcess> m_process;
    bool m_verbose;

    QString m_socketFile;

    QScopedPointer<QQmlDebugConnection> m_connection;
    QScopedPointer<QQmlPreviewClient> m_qmlPreviewClient;
    QmlPreviewFileSystemWatcher m_watcher;

    QTimer m_loadTimer;
    QTimer m_connectTimer;
    uint m_connectionAttempts;
};

#endif // QMLPREVIEWAPPLICATION_H