Skip to content
Snippets Groups Projects
backend.h 2.96 KiB
/****************************************************************************
**
** Copyright (C) 2023 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Design Viewer of the Qt Toolkit.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#ifndef DV_ANDROID_H
#define DV_ANDROID_H

#include <QJsonArray>
#include <QThread>

#include "dsconnector/dsmanager.h"
#include "projectmanager.h"
#include "qrscanner.h"
#include "settings.h"

class Backend : public QObject
{
    Q_OBJECT
public:
    explicit Backend(QObject *parent = nullptr);
    ~Backend();

private:
    QScopedPointer<ProjectManager> m_projectManager;
    QThread m_projectManagerThread;

    QScopedPointer<DesignStudioManager> m_dsManager;
    QThread m_dsManagerThread;

    QScopedPointer<QrScanner> m_qrScanner;

    QString m_lastProjectSenderId;

    // Settings
    Settings m_settings;

    // member functions
    void updatePopupText(const QString &text, int timeout = 0);
    void updatePopupProgress(const int progress);

    void initDsManager();
    void initProjectManager();
    void setAndroidScreenOn(bool on);

    void runProject(const QString &id, const QByteArray &projectData);

signals:
    // UI signals - Popup
    void popupProgressIndeterminateChanged(bool indeterminate);
    void popupChangeText(QString text, int timeout = 0);
    void popupChangeProgress(int progress);
    void popupOpen();
    void popupClose();

    // UI signals - from DS Manager page
    void connectedChanged(bool connected);

    // UI signals - from UI
    void connectToDesignStudio(const QString &url);

public slots:
    QString buildInfo() const;
    void scanQrCode();
    void connectDesignStudio(const QString &ipAddr);
    void parseDesignViewerUrl(const QUrl &url);
    void popupInterrupted();
    QJsonArray getIpAddresses() const;

    bool autoScaleProject() const;
    void setAutoScaleProject(bool autoScaleProject);

    bool keepScreenOn() const;
    void setKeepScreenOn(bool keepScreenOn);

    QString lastDesignStudioIp() const;
};

#endif // DV_ANDROID_H