Skip to content

Commit

Permalink
v0.38.4 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
martonborzak committed Feb 7, 2024
1 parent aaf460c commit 621a619
Show file tree
Hide file tree
Showing 36 changed files with 493 additions and 74 deletions.
18 changes: 18 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,12 @@ void Api::processResponseDocks(int reqId, int code, QVariant msgData) {
dock.state = Util::convertStringToEnum<DockEnums::DockState>(map.value("state").toString());
dock.learningActive = map.value("learning_active").toBool();
dock.description = map.value("descriptions").toString();
if (map.contains("led_brightness")) {
dock.ledBrightness = map.value("led_brightness").toInt();
}
if (map.contains("eth_led_brightness")) {
dock.ethLedBrightness = map.value("eth_led_brightness").toInt();
}

respList.append(dock);
}
Expand All @@ -2747,6 +2753,12 @@ void Api::processResponseDock(int reqId, int code, QVariant msgData) {
dock.state = Util::convertStringToEnum<DockEnums::DockState>(map.value("state").toString());
dock.learningActive = map.value("learning_active").toBool();
dock.description = map.value("descriptions").toString();
if (map.contains("led_brightness")) {
dock.ledBrightness = map.value("led_brightness").toInt();
}
if (map.contains("eth_led_brightness")) {
dock.ethLedBrightness = map.value("eth_led_brightness").toInt();
}

emit respDock(reqId, code, dock);
}
Expand Down Expand Up @@ -2850,6 +2862,12 @@ void Api::processDockChange(QVariant msgData) {
dock.state = Util::convertStringToEnum<DockEnums::DockState>(newState.value("state").toString());
dock.learningActive = newState.value("learning_active").toBool();
dock.description = newState.value("description").toString();
if (newState.contains("led_brightness")) {
dock.ledBrightness = newState.value("led_brightness").toInt();
}
if (newState.contains("eth_led_brightness")) {
dock.ethLedBrightness = newState.value("eth_led_brightness").toInt();
}

switch (eventType) {
case MsgEventTypes::NEW:
Expand Down
2 changes: 2 additions & 0 deletions src/core/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ struct DockConfiguration {
DockEnums::DockState state;
bool learningActive;
QString description;
int ledBrightness = -1;
int ethLedBrightness = -1;
};

struct DockDiscovery {
Expand Down
24 changes: 22 additions & 2 deletions src/dock/configuredDocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace dock {

ConfiguredDock::ConfiguredDock(const QString &id, const QString &name, const QString &customWsUrl, bool active,
const QString &model, const QString &connectionType, const QString &version, State state,
bool learningActive, const QString &description, QObject *parent)
bool learningActive, const QString &description, int ledBrightness, QObject *parent)
: QObject(parent),
m_id(id),
m_name(name),
Expand All @@ -21,7 +21,8 @@ ConfiguredDock::ConfiguredDock(const QString &id, const QString &name, const QSt
m_version(version),
m_state(state),
m_learningActive(learningActive),
m_description(description) {}
m_description(description),
m_ledBrightness(ledBrightness) {}

ConfiguredDock::~ConfiguredDock() {
qCDebug(lcDockController()) << "Configured dock destructor" << m_id;
Expand Down Expand Up @@ -67,6 +68,12 @@ void ConfiguredDock::setDescription(const QString &description) {
emit descriptionChanged();
}

void ConfiguredDock::setLedBrgithess(int brightness)
{
m_ledBrightness = brightness;
emit ledBrightnessChanged();
}

ConfiguredDocks::ConfiguredDocks(QObject *parent) : QAbstractListModel(parent), m_count(0) {}

int ConfiguredDocks::count() const {
Expand Down Expand Up @@ -123,6 +130,8 @@ QVariant ConfiguredDocks::data(const QModelIndex &index, int role) const {
return item->getLearningActive();
case DescriptionRole:
return item->getDescription();
case LedBrightnessRole:
return item->getLedBrightness();
}
return QVariant();
}
Expand All @@ -139,6 +148,7 @@ QHash<int, QByteArray> ConfiguredDocks::roleNames() const {
roles[StateRole] = "dockState";
roles[LearningActiveRole] = "dockLearningActive";
roles[DescriptionRole] = "dockDescription";
roles[LedBrightnessRole] = "dockLedBrightness";
return roles;
}

Expand Down Expand Up @@ -286,5 +296,15 @@ void ConfiguredDocks::updateDescription(const QString &key, const QString &descr
}
}

void ConfiguredDocks::updateLedBrightness(const QString &key, int brightness)
{
auto dock = get(key);

if (dock) {
dock->setLedBrgithess(brightness);
emit dataChanged(getModelIndexByKey(key), getModelIndexByKey(key));
}
}

} // namespace dock
} // namespace uc
9 changes: 8 additions & 1 deletion src/dock/configuredDocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ConfiguredDock : public QObject {
Q_PROPERTY(State state READ getState NOTIFY stateChanged)
Q_PROPERTY(bool learningActive READ getLearningActive NOTIFY learningActiveChanged)
Q_PROPERTY(QString description READ getDescription NOTIFY descriptionChanged)
Q_PROPERTY(int ledBrightness READ getLedBrightness NOTIFY ledBrightnessChanged)

public:
enum State {
Expand All @@ -36,7 +37,7 @@ class ConfiguredDock : public QObject {

explicit ConfiguredDock(const QString& id, const QString& name, const QString& customWsUrl, bool active,
const QString& model, const QString& connectionType, const QString& version, State state,
bool learningActive, const QString& description, QObject* parent = nullptr);
bool learningActive, const QString& description, int ledBrightness, QObject* parent = nullptr);
~ConfiguredDock();

QString getId() const { return m_id; }
Expand All @@ -57,6 +58,8 @@ class ConfiguredDock : public QObject {
void setLearningActive(bool learningActive);
QString getDescription() const { return m_description; }
void setDescription(const QString& description);
int getLedBrightness() const { return m_ledBrightness; }
void setLedBrgithess(int brightness);

signals:
void nameChanged();
Expand All @@ -67,6 +70,7 @@ class ConfiguredDock : public QObject {
void stateChanged();
void learningActiveChanged();
void descriptionChanged();
void ledBrightnessChanged();

private:
QString m_id;
Expand All @@ -79,6 +83,7 @@ class ConfiguredDock : public QObject {
State m_state;
bool m_learningActive;
QString m_description;
int m_ledBrightness;
};

class ConfiguredDocks : public QAbstractListModel {
Expand All @@ -98,6 +103,7 @@ class ConfiguredDocks : public QAbstractListModel {
StateRole,
LearningActiveRole,
DescriptionRole,
LedBrightnessRole,
};

explicit ConfiguredDocks(QObject* parent = nullptr);
Expand Down Expand Up @@ -137,6 +143,7 @@ class ConfiguredDocks : public QAbstractListModel {
void updateState(const QString& key, ConfiguredDock::State state);
void updateLearningActive(const QString& key, bool learningActive);
void updateDescription(const QString& key, const QString& description);
void updateLedBrightness(const QString &key, int brightness);

int totalPages = 0;
int lastPageLoaded = 0;
Expand Down
53 changes: 51 additions & 2 deletions src/dock/dockController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,52 @@ QObject *DockController::getConfiguredDock(const QString &dockId) {
return m_configuredDocks.get(dockId);
}

void DockController::getConfiguredDockFromCore(const QString &dockId)
{
int id = m_core->getDock(dockId);

m_core->onResponseWithErrorResult(
id, &core::Api::respDock, [=](core::DockConfiguration dock){
qCDebug(lcDockController()) << "Got dock from core with id:" << dock.id;

if (m_configuredDocks.contains(dockId)) {
m_configuredDocks.updateActive(dockId, dock.active);
m_configuredDocks.updateLearningActive(dockId, dock.learningActive);

if (!dock.name.isEmpty()) {
m_configuredDocks.updateName(dockId, dock.name);
}
if (!dock.customWsUrl.isEmpty()) {
m_configuredDocks.updateCustomWsUrl(dockId, dock.customWsUrl);
}
if (!dock.connectionType.isEmpty()) {
m_configuredDocks.updateConnectionType(dockId, dock.connectionType);
}
if (!dock.version.isEmpty()) {
m_configuredDocks.updateVersion(dockId, dock.version);
}
if (!dock.description.isEmpty()) {
m_configuredDocks.updateDescription(dockId, dock.description);
}
if (dock.ledBrightness != -1) {
m_configuredDocks.updateLedBrightness(dockId, dock.ledBrightness);
}

qCDebug(lcDockController()) << "Dock updated:" << dockId;
emit dockChanged(dockId);
emit gotDock(true, dockId);
} else {
qCWarning(lcDockController()) << "The dock with id" << dockId << "does not exists";
emit gotDock(false, dockId);
}

},[=](int code, QString message) {
// fail
qCWarning(lcDockController()) << "Failed to get dock from core with id:" << dockId << code << message;
emit gotDock(false, dockId);
});
}

void DockController::startDiscovery() {
m_discoveredDocks.clear();

Expand Down Expand Up @@ -263,7 +309,7 @@ void DockController::getDocks(int limit, int page) {
if (!m_configuredDocks.contains(i->id)) {
m_configuredDocks.append(new ConfiguredDock(
i->id, i->name, i->customWsUrl, i->active, i->model, i->connectionType, i->version,
static_cast<ConfiguredDock::State>(i->state), i->learningActive, i->description, this));
static_cast<ConfiguredDock::State>(i->state), i->learningActive, i->description, i->ledBrightness, this));
qCDebug(lcDockController()) << "Dock created:" << i->name << i->id;
}
}
Expand Down Expand Up @@ -382,7 +428,7 @@ void DockController::onDockAdded(QString dockId, core::DockConfiguration dock) {
if (!m_configuredDocks.contains(dockId)) {
m_configuredDocks.append(new ConfiguredDock(
dockId, dock.name, dock.customWsUrl, dock.active, dock.model, dock.connectionType, dock.version,
static_cast<ConfiguredDock::State>(dock.state), dock.learningActive, dock.description, this));
static_cast<ConfiguredDock::State>(dock.state), dock.learningActive, dock.description, dock.ledBrightness, this));

qCDebug(lcDockController()) << "Dock added:" << dockId;
emit dockAdded(dockId);
Expand All @@ -409,6 +455,9 @@ void DockController::onDockChanged(QString dockId, core::DockConfiguration dock)
if (!dock.description.isEmpty()) {
m_configuredDocks.updateDescription(dockId, dock.description);
}
if (dock.ledBrightness != -1) {
m_configuredDocks.updateLedBrightness(dockId, dock.ledBrightness);
}

qCDebug(lcDockController()) << "Dock updated:" << dockId;
emit dockChanged(dockId);
Expand Down
3 changes: 3 additions & 0 deletions src/dock/dockController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DockController : public QObject {

Q_INVOKABLE QObject* getDiscoveredDock(const QString& dockId);
Q_INVOKABLE QObject* getConfiguredDock(const QString& dockId);
Q_INVOKABLE void getConfiguredDockFromCore(const QString &dockId);

Q_INVOKABLE void startDiscovery();
Q_INVOKABLE void stopDiscovery();
Expand Down Expand Up @@ -70,6 +71,8 @@ class DockController : public QObject {
void dockPasswordChanged(QString dockId);
void error(QString messsage);

void gotDock(bool success, QString id);

private:
static DockController* s_instance;
core::Api* m_core;
Expand Down
24 changes: 12 additions & 12 deletions src/qml/components/ButtonNavigation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ Item {

function takeControl() {
ui.inputController.takeControl(String(buttonNavigation.parent));
console.debug("Button control enabled for: " + String(buttonNavigation.parent));
console.info("Button control enabled for: " + String(buttonNavigation.parent));
}

function releaseControl(newNavigation = "") {
ui.inputController.releaseControl(newNavigation);
console.debug("Button control disabled for: " + String(buttonNavigation.parent));
console.info("Button control disabled for: " + String(buttonNavigation.parent));
}

function extendDefaultConfig(config, overWrite = false) {
console.debug("Extending default config for: " + String(buttonNavigation.parent));
console.info("Extending default config for: " + String(buttonNavigation.parent));
buttonNavigation.defaultConfigOriginal = buttonNavigation.defaultConfig;

for (const [key, value] of Object.entries(config)) {
Expand All @@ -47,12 +47,12 @@ Item {
}

function restoreDefaultConfig() {
console.debug("Restoring default config for: " + String(buttonNavigation.parent));
console.info("Restoring default config for: " + String(buttonNavigation.parent));
buttonNavigation.defaultConfig = buttonNavigation.defaultConfigOriginal;
}

function extendOverrideConfig(config, overWrite = false) {
console.debug("Extending override config for: " + String(buttonNavigation.parent));
console.info("Extending override config for: " + String(buttonNavigation.parent));
buttonNavigation.overrideConfigOriginal = buttonNavigation.overrideConfig;

for (const [key, value] of Object.entries(config)) {
Expand All @@ -65,7 +65,7 @@ Item {
}

function restoreOverrideConfig() {
console.debug("Restoring override config for: " + String(buttonNavigation.parent));
console.info("Restoring override config for: " + String(buttonNavigation.parent));
buttonNavigation.overrideConfig = buttonNavigation.overrideConfigOriginal;
}

Expand All @@ -77,14 +77,14 @@ Item {
if (overrideConfig[key]) {
// execute override config
if (overrideConfig[key].pressed) {
console.debug("OVERRIDE PRESSED: " + key + " " + buttonNavigation.parent);
console.info("OVERRIDE PRESSED: " + key + " " + buttonNavigation.parent);
overrideConfig[key].pressed();
}

} else if (defaultConfig[key]) {
// execute default config
if (defaultConfig[key].pressed) {
console.debug("DEFAULT PRESSED: " + key + " " + buttonNavigation.parent);
console.info("DEFAULT PRESSED: " + key + " " + buttonNavigation.parent);
defaultConfig[key].pressed();
}
}
Expand All @@ -94,14 +94,14 @@ Item {
if (overrideConfig[key]) {
// execute override config
if (overrideConfig[key].long_press) {
console.debug("OVERRIDE LONG_PRESS: " + key + " " + buttonNavigation.parent);
console.info("OVERRIDE LONG_PRESS: " + key + " " + buttonNavigation.parent);
overrideConfig[key].long_press();
}

} else if (defaultConfig[key]) {
// execute default config
if (defaultConfig[key].long_press) {
console.debug("DEFAULT LONG_PRESS: " + key + " " + buttonNavigation.parent);
console.info("DEFAULT LONG_PRESS: " + key + " " + buttonNavigation.parent);
defaultConfig[key].long_press();
}
}
Expand All @@ -111,14 +111,14 @@ Item {
if (overrideConfig[key]) {
// execute override config
if (overrideConfig[key].released) {
console.debug("OVERRIDE RELEASED: " + key + " " + buttonNavigation.parent);
console.info("OVERRIDE RELEASED: " + key + " " + buttonNavigation.parent);
overrideConfig[key].released();
}

} else if (defaultConfig[key]) {
// execute default config
if (defaultConfig[key].released) {
console.debug("DEFAULT RELEASED: " + key + " " + buttonNavigation.parent);
console.info("DEFAULT RELEASED: " + key + " " + buttonNavigation.parent);
defaultConfig[key].released();
}
}
Expand Down
Loading

0 comments on commit 621a619

Please sign in to comment.