~aleteoryx/muditaos

ref: 9fdb29846302f88321c23518a163e2c7a389d9e1 muditaos/module-apps/application-notes/NotesModel.cpp -rw-r--r-- 1.5 KiB
9fdb2984 — Roman Kubiak [EGD-4557] implement usb-deinit (#1101) 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <service-db/DBServiceAPI.hpp>
#include "widgets/NotesItem.hpp"

#include "NotesModel.hpp"
#include "ListView.hpp"

#include <module-utils/Utils.hpp>
#include <module-services/service-db/agents/settings/SystemSettings.hpp>

NotesModel::NotesModel(app::Application *app) : DatabaseModel(app)
{}

unsigned int NotesModel::requestRecordsCount()
{
    recordsCount = DBServiceAPI::NotesGetCount(application);
    return recordsCount;
}

void NotesModel::requestRecords(const uint32_t offset, const uint32_t limit)
{
    DBServiceAPI::NotesGetLimitOffset(application, offset, limit);
}

bool NotesModel::updateRecords(std::vector<NotesRecord> records)
{
#if DEBUG_DB_MODEL_DATA == 1
    LOG_DEBUG("Offset: %" PRIu32 ", Limit: %" PRIu32 " Count: %" PRIu32 "", offset, limit, count);
    for (uint32_t i = 0; i < records.get()->size(); ++i) {
        LOG_DEBUG("id: %" PRIu32 ", filename: %s",
                  records.get()->operator[](i).ID,
                  records.get()->operator[](i).path.c_str());
    }
#endif

    DatabaseModel::updateRecords(std::move(records));
    list->onProviderDataUpdate();

    return true;
}

unsigned int NotesModel::getMinimalItemHeight() const
{
    return 146;
}

gui::ListItem *NotesModel::getItem(gui::Order order)
{
    std::shared_ptr<NotesRecord> note = getRecord(order);

    auto *item = new gui::NotesItem(this, !(application->isTimeFormat12()));

    item->setNote(note);
    return item;
}