~aleteoryx/muditaos

ref: 78904a6b5d80ab55e1fbf2861ab3a905c96ae94d muditaos/module-apps/application-calendar/models/CalendarEventsModel.cpp -rw-r--r-- 1.6 KiB
78904a6b — Tomas Rogala [EGD-3307] Review changes 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
#include "CalendarEventsModel.hpp"
#include "application-calendar/widgets/CalendarItem.hpp"

#include <ListView.hpp>

CalendarEventsModel::CalendarEventsModel(app::Application *app) : DatabaseModel(app)
{
    application = app;
}

void CalendarEventsModel::requestRecords(const uint32_t offset, const uint32_t limit)
{
    list->onProviderDataUpdate();
}

unsigned int CalendarEventsModel::getMinimalItemHeight() const
{
    return style::window::calendar::item::height;
}

gui::ListItem *CalendarEventsModel::getItem(gui::Order order)
{
    gui::CalendarItem *item = new gui::CalendarItem();

    auto record = getRecord(order);
    if (record != nullptr) {
        item->setEvent(record);
    }
    else {
        LOG_DEBUG("Empty record in EventsModel::GetItem");
        return nullptr;
    }
    LOG_DEBUG("Created new item in calendar day listView");
    item->activatedCallback = [=](gui::Item &item) {
        LOG_INFO("Switch to options/delete window");
        application->switchWindow(style::window::calendar::name::events_options);
        return true;
    };
    return item;
}
bool CalendarEventsModel::updateRecords(std::unique_ptr<std::vector<EventsRecord>> records,
                                        uint32_t offset,
                                        uint32_t limit,
                                        uint32_t count)
{
    DatabaseModel::updateRecords(std::move(records), offset, limit, count);
    modelIndex = 0;
    list->onProviderDataUpdate();

    return true;
}

void CalendarEventsModel::setRecordsCount(const uint32_t &count)
{
    recordsCount = count;
}