File: devicestate.cpp

package info (click to toggle)
qflipper 1.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,320 kB
  • sloc: cpp: 18,500; sh: 247; ansic: 191; xml: 38; python: 14; makefile: 5
file content (190 lines) | stat: -rw-r--r-- 3,742 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "devicestate.h"

#include <QDebug>
#include <QLoggingCategory>

Q_DECLARE_LOGGING_CATEGORY(CATEGORY_DEBUG)

using namespace Flipper;
using namespace Zero;

DeviceState::DeviceState(const DeviceInfo &deviceInfo, QObject *parent):
    QObject(parent),
    m_deviceInfo(deviceInfo),
    m_isPersistent(false),
    m_isOnline(false),
    m_isAllowVirtualDisplay(true),
    m_error(BackendError::NoError),
    m_progress(-1.0)
{
    connect(this, &DeviceState::deviceInfoChanged, this, &DeviceState::onDeviceInfoChanged);
    connect(this, &DeviceState::isOnlineChanged, this, &DeviceState::onIsOnlineChanged);

    onDeviceInfoChanged();
}

const DeviceInfo &DeviceState::deviceInfo() const
{
    return m_deviceInfo;
}

void DeviceState::setDeviceInfo(const DeviceInfo &newDeviceInfo)
{
    if(m_isOnline) {
        qCDebug(CATEGORY_DEBUG) << "Received a DeviceInfo too early, queueing it...";
        m_queue.enqueue(newDeviceInfo);
        return;
    }

    if(newDeviceInfo.usbInfo.productID() == 0xdf11) {
        // Keep most of the data from previous session
        m_deviceInfo.usbInfo = newDeviceInfo.usbInfo;
        m_deviceInfo.portInfo = newDeviceInfo.portInfo;

    } else {
        m_deviceInfo = newDeviceInfo;
    }

    emit deviceInfoChanged();
}

void DeviceState::setStorageInfo(const StorageInfo &newStorageInfo)
{
    m_deviceInfo.storage = newStorageInfo;
    emit deviceInfoChanged();
}

bool DeviceState::isPersistent() const
{
    return m_isPersistent;
}

void DeviceState::setPersistent(bool set)
{
    if(m_isPersistent == set) {
        return;
    }

    m_isPersistent = set;
    emit isPersistentChanged();
}

bool DeviceState::isOnline() const
{
    return m_isOnline;
}

void DeviceState::setOnline(bool set)
{
    if(m_isOnline == set) {
        return;
    }

    m_isOnline = set;
    emit isOnlineChanged();
}

bool DeviceState::isError() const
{
    return m_error != BackendError::NoError;
}

bool DeviceState::isRecoveryMode() const
{
    return m_deviceInfo.usbInfo.productID() == 0xdf11;
}

bool DeviceState::isAllowVirtualDisplay() const
{
    return m_isAllowVirtualDisplay;
}

void DeviceState::setAllowVirtualDisplay(bool set)
{
    if(m_isAllowVirtualDisplay == set) {
        return;
    }

    m_isAllowVirtualDisplay = set;
}

double DeviceState::progress() const
{
    return m_progress;
}

void DeviceState::setProgress(double newProgress)
{
    if(qFuzzyCompare(m_progress, newProgress)) {
        return;
    }

    m_progress = newProgress;
    emit progressChanged();
}

const QString &DeviceState::statusString() const
{
    return m_statusString;
}

void DeviceState::setStatusString(const QString &newStatusString)
{
    if(m_statusString == newStatusString) {
        return;
    }

    m_statusString = newStatusString;
    emit statusStringChanged();
}

const QString &DeviceState::errorString() const
{
    return m_errorString;
}

BackendError::ErrorType DeviceState::error() const
{
    return m_error;
}

void DeviceState::setError(BackendError::ErrorType error, const QString &errorString)
{
    m_error = error;
    m_errorString = errorString;

    emit isErrorChanged();
}

void DeviceState::clearError()
{
    m_error = BackendError::NoError;
    m_errorString.clear();

    emit isErrorChanged();
}

const QString &DeviceState::name() const
{
    return m_deviceInfo.name;
}

void DeviceState::onDeviceInfoChanged()
{
    clearError();
    setProgress(-1.0);
}

void DeviceState::onIsOnlineChanged()
{
    processQueue();
}

void DeviceState::processQueue()
{
    if(!m_isOnline && !m_queue.isEmpty()) {
        qCDebug(CATEGORY_DEBUG) << "Took the latest DeviceInfo from the queue";
        setDeviceInfo(m_queue.takeLast());
        m_queue.clear();
    }
}