~aleteoryx/muditaos

ref: dbc5da5f9d8e11dd45e081334f59c1658a76bb78 muditaos/module-db/Interface/SettingsRecord.cpp -rw-r--r-- 3.3 KiB
dbc5da5f — Roman Kubiak [EGD-4158] network access technology added to deviceInfo endpoint (#921) 5 years ago
                                                                                
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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SettingsRecord.hpp"

SettingsRecord::ActiveSim SettingsRecord::to(const uint32_t sim)
{
    if (sim <= static_cast<uint32_t>(ActiveSim::SIM2)) {
        return ActiveSim(sim);
    }
    return ActiveSim::NONE;
}

uint32_t SettingsRecord::from(const ActiveSim sim)
{
    return static_cast<uint32_t>(sim);
}

SettingsRecordInterface::SettingsRecordInterface(SettingsDB *db) : settingsDB(db)
{}

SettingsRecordInterface::~SettingsRecordInterface()
{}

SettingsRecord SettingsRecordInterface::GetByID(uint32_t id)
{

    auto rec = settingsDB->settings.getById(1);

    return SettingsRecord{.dbID            = rec.ID,
                          .timeFormat12    = rec.timeFormat12,
                          .timeAuto        = rec.timeAuto,
                          .timeDateFormat  = rec.timeDateFormat,
                          .brightnessAuto  = rec.brightnessAuto,
                          .brightnessLevel = rec.brightnessLevel,
                          .fontSize        = rec.fontSize,
                          .pinMode         = rec.pinMode,
                          .pinDays         = rec.pinDays,
                          .pinDaysLeft     = rec.pinDaysLeft,
                          .pin1            = rec.pin1,
                          .pin2            = rec.pin2,
                          .activeSIM       = SettingsRecord::to(rec.activeSIM),
                          .networkOperator = rec.networkOperator,
                          .lockPassHash    = rec.lockPassHash,
                          .lockTime        = rec.lockTime,
                          .language        = rec.language};
}

bool SettingsRecordInterface::Update(const SettingsRecord &rec)
{

    return settingsDB->settings.update(SettingsTableRow{.ID              = rec.dbID,
                                                        .timeFormat12    = rec.timeFormat12,
                                                        .timeAuto        = rec.timeAuto,
                                                        .timeDateFormat  = rec.timeDateFormat,
                                                        .brightnessAuto  = rec.brightnessAuto,
                                                        .brightnessLevel = rec.brightnessLevel,
                                                        .fontSize        = rec.fontSize,
                                                        .pinMode         = rec.pinMode,
                                                        .pinDays         = rec.pinDays,
                                                        .pinDaysLeft     = rec.pinDaysLeft,
                                                        .pin1            = rec.pin1,
                                                        .pin2            = rec.pin2,
                                                        .activeSIM       = SettingsRecord::from(rec.activeSIM),
                                                        .networkOperator = rec.networkOperator,
                                                        .lockPassHash    = rec.lockPassHash,
                                                        .lockTime        = rec.lockTime,
                                                        .language        = rec.language});
}