Skip to content
Snippets Groups Projects
backend.h 2.82 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 <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:
    // Other members
    std::unique_ptr<ProjectManager> m_projectManager;
    std::unique_ptr<QrScanner> m_qrScanner;

    // DS Connector
    QScopedPointer<DesignStudioManager> m_dsManager;
    QThread m_dsManagerThread;
    QString m_lastProjectSenderId;

    // Settings
    Settings m_settings;

    // member functions
    void updatePopup(const QString &text, bool indeterminate = true);
    QByteArray getDeviceSerial();
    QString getDeviceUuid();

    void initDsManager();
    void initializeProjectManager();

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

signals:
    // UI signals - Popup
    void popupProgressIndeterminateChanged(bool indeterminate);
    void popupTextChanged(QString text);
    void popupOpen(const QString &text = {}, int timeout = 0);
    void popupClose();

    // UI signals - from DS Manager page
    void connectedChanged(bool connected, const QString &ipAddr);

    // 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();

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

    QString lastDesignStudioIp() const;
};

#endif // DV_ANDROID_H