~aleteoryx/muditaos

ae355210a8b52e7df92518fa7ae1718b5542f758 — marek303 5 years ago f1e68d2
[EGD-3315]Review changes (minor)
36 files changed, 104 insertions(+), 445 deletions(-)

M image/assets/lang/lang_de.json
M image/assets/lang/lang_en.json
M image/assets/lang/lang_pl.json
M image/assets/lang/lang_sp.json
M module-apps/application-calendar/data/dateCommon.hpp
M module-apps/application-calendar/models/EventDetailModel.hpp
D module-apps/application-calendar/widgets/AddRepeatedEvents.cpp
D module-apps/application-calendar/widgets/AddRepeatedEvents.hpp
M module-apps/application-calendar/widgets/CalendarStyle.hpp
M module-apps/application-calendar/widgets/DayEventsItem.cpp
M module-apps/application-calendar/windows/CalendarMainWindow.cpp
M module-apps/application-calendar/windows/EventReminderWindow.cpp
M module-apps/application-calendar/windows/EventReminderWindow.hpp
M module-apps/application-calendar/windows/NewEditEventWindow.cpp
M module-apps/application-calendar/windows/NewEditEventWindow.hpp
M module-apps/application-call/widgets/Icons.hpp
M module-apps/application-desktop/ApplicationDesktop.cpp
M module-apps/application-desktop/ApplicationDesktop.hpp
M module-apps/application-desktop/windows/DesktopMainWindow.cpp
M module-apps/application-desktop/windows/MenuWindow.cpp
M module-db/Interface/NotificationsRecord.hpp
M module-db/Tables/EventsTable.cpp
M module-db/Tables/NotificationsTable.cpp
M module-db/queries/calendar/QueryEventsSelectFirstUpcoming.hpp
M module-services/service-appmgr/ApplicationManager.cpp
M module-services/service-db/api/DBServiceAPI.cpp
M module-services/service-db/api/DBServiceAPI.hpp
M module-services/service-time/CMakeLists.txt
M module-services/service-time/ServiceTime.cpp
M module-services/service-time/ServiceTime.hpp
D module-services/service-time/api/TimeServiceAPI.cpp
D module-services/service-time/api/TimeServiceAPI.hpp
M module-services/service-time/timeEvents/CalendarTimeEvents.cpp
M module-services/service-time/timeEvents/CalendarTimeEvents.hpp
M module-services/service-time/timeEvents/TimeEvents.cpp
M module-services/service-time/timeEvents/TimeEvents.hpp
M image/assets/lang/lang_de.json => image/assets/lang/lang_de.json +0 -1
@@ 76,7 76,6 @@
    "app_desktop_pin_info2": "Allowed unlock attempts",
    "app_desktop_pin_blocked1": "Sorry, phone blocked",
    "app_desktop_unread_messages": "unread messages",
    "app_desktop_unread_calendar_events": "calendar events",
    "app_desktop_missed_calls": "missed calls",
    "app_desktop_menu_phone": "PHONE",
    "app_desktop_menu_contacts": "CONTACTS",

M image/assets/lang/lang_en.json => image/assets/lang/lang_en.json +0 -1
@@ 165,7 165,6 @@
    "app_desktop_sim_blocked_info2": "Please contact your service provider",

    "app_desktop_unread_messages": "Unread messages",
    "app_desktop_unread_calendar_events": "Calendar events",
    "app_desktop_missed_calls": "Missed calls",
    "app_desktop_menu_phone": "PHONE",
    "app_desktop_menu_contacts": "CONTACTS",

M image/assets/lang/lang_pl.json => image/assets/lang/lang_pl.json +0 -1
@@ 78,7 78,6 @@
    "app_desktop_pin_info2": "Pozostało prób",
    "app_desktop_pin_blocked1": "Telefon zablokowany",
    "app_desktop_unread_messages": "nieprzeczytane wiadomości",
    "app_desktop_unread_calendar_events": "wydarzenia",
    "app_desktop_missed_calls": "nieodebrane połączenia",
    
    "app_desktop_menu_phone": "TELEFON",

M image/assets/lang/lang_sp.json => image/assets/lang/lang_sp.json +0 -1
@@ 77,7 77,6 @@
    "app_desktop_pin_info2": "Allowed unlock attempts",
    "app_desktop_pin_blocked1": "Sorry, phone blocked",
    "app_desktop_unread_messages": "unread messages",
    "app_desktop_unread_calendar_events": "calendar events",
    "app_desktop_missed_calls": "missed calls",
    "app_desktop_menu_phone": "PHONE",
    "app_desktop_menu_contacts": "CONTACTS",

M module-apps/application-calendar/data/dateCommon.hpp => module-apps/application-calendar/data/dateCommon.hpp +14 -0
@@ 184,6 184,20 @@ inline std::string TimePointToString(const TimePoint &tp, date::months months)
    return date::format("%F %T", time_point_cast<seconds>(timePoint));
}

inline std::string TimePointToLocalizedDateString(const TimePoint &tp, const std::string format = "")
{
    auto time = TimePointToTimeT(tp);
    utils::time::Date timestamp(time);
    return timestamp.str(format);
}

inline std::string TimePointToLocalizedTimeString(const TimePoint &tp, const std::string format)
{
    auto time = TimePointToTimeT(tp);
    utils::time::Time timestamp(time);
    return timestamp.str(format);
}

inline TimePoint TimePointFromString(const char *s1)
{
    TimePoint tp;

M module-apps/application-calendar/models/EventDetailModel.hpp => module-apps/application-calendar/models/EventDetailModel.hpp +0 -1
@@ 6,7 6,6 @@
#include "Application.hpp"
#include "InternalModel.hpp"
#include <ListItemProvider.hpp>
#include <module-apps/application-calendar/ApplicationCalendar.hpp>

class EventDetailModel : public app::InternalModel<gui::CalendarListItem *>, public gui::ListItemProvider
{

D module-apps/application-calendar/widgets/AddRepeatedEvents.cpp => module-apps/application-calendar/widgets/AddRepeatedEvents.cpp +0 -124
@@ 1,124 0,0 @@
#include "AddRepeatedEvents.hpp"
#include <module-db/Interface/EventsRecord.hpp>
#include <module-services/service-db/api/DBServiceAPI.hpp>
#include <module-db/queries/calendar/QueryEventsAdd.hpp>
#include <module-apps/application-calendar/data/dateCommon.h>
#include "../data/OptionParser.hpp"

void AddRepeatedEvents::addDaily(std::shared_ptr<EventsRecord> event)
{
    auto record = event.get();
    for (uint32_t i = 1; i < 7; i++) {
        record->date_from += date::days{1};
        record->date_from += date::days{1};
        DBServiceAPI::GetQuery(
            application, db::Interface::Name::Events, std::make_unique<db::query::events::Add>(*record));
    }
}

void AddRepeatedEvents::addWeekly(std::shared_ptr<EventsRecord> event)
{
    auto record = event.get();
    for (uint32_t i = 1; i <= 4; i++) {
        record->date_from += date::days{7};
        record->date_from += date::days{7};
        DBServiceAPI::GetQuery(
            application, db::Interface::Name::Events, std::make_unique<db::query::events::Add>(*record));
    }
}
void AddRepeatedEvents::addTwoWeeks(std::shared_ptr<EventsRecord> event)
{
    auto record = event.get();
    for (uint32_t i = 1; i <= 4; i++) {
        record->date_from += date::days{14};
        record->date_from += date::days{14};
        DBServiceAPI::GetQuery(
            application, db::Interface::Name::Events, std::make_unique<db::query::events::Add>(*record));
    }
}
void AddRepeatedEvents::addMonth(std::shared_ptr<EventsRecord> event)
{
    auto record = event.get();
    for (uint32_t i = 1; i <= 4; i++) {
        record->date_from += date::months{1};
        record->date_from += date::months{1};
        DBServiceAPI::GetQuery(
            application, db::Interface::Name::Events, std::make_unique<db::query::events::Add>(*record));
    }
}
void AddRepeatedEvents::addYear(std::shared_ptr<EventsRecord> event)
{
    auto record = event.get();
    for (uint32_t i = 1; i <= 4; i++) {
        record->date_from += date::years{1};
        record->date_from += date::years{1};
        DBServiceAPI::GetQuery(
            application, db::Interface::Name::Events, std::make_unique<db::query::events::Add>(*record));
    }
}
void AddRepeatedEvents::addCustom(std::shared_ptr<EventsRecord> event)
{
    auto record                = event.get();
    uint32_t startWeekdayIndex = WeekdayIndexFromTimePoint(record->date_from);

    // Get table of weekdays to repeat
    OptionParser parser;
    auto weekDayRepeatData = std::make_unique<WeekDaysRepeatData>();
    assert(weekDayRepeatData != nullptr);
    auto weekDayData = parser.setWeekDayOptions(record->repeat, std::move(weekDayRepeatData));

    // Count num of weekdays to repeat
    uint32_t weekDayNum = 0;
    for (uint32_t i = 0; i < 7; i++) {
        if (weekDayData->getData(i))
            weekDayNum++;
    }
    // Num of entries to add
    uint32_t entriesToAdd = weekDayNum * 4;

    uint32_t currWeekdayIndex = startWeekdayIndex;
    // Add all entries
    while (entriesToAdd > 0) {
        if (weekDayData->getData(currWeekdayIndex)) {
            DBServiceAPI::GetQuery(
                application, db::Interface::Name::Events, std::make_unique<db::query::events::Add>(*record));

            entriesToAdd--;
        }

        record->date_from += date::days{1};
        record->date_till += date::days{1};
        currWeekdayIndex = (currWeekdayIndex + 1) % 7;
    }
}

void AddRepeatedEvents::addRepeatedEvents(std::shared_ptr<EventsRecord> event)
{
    switch (event->repeat) {
    case static_cast<unsigned int>(Repeat::Daily): {
        addDaily(event);
        break;
    }
    case static_cast<unsigned int>(Repeat::Weekly): {
        addWeekly(event);
        break;
    }
    case static_cast<unsigned int>(Repeat::TwoWeeks): {
        addTwoWeeks(event);
        break;
    }
    case static_cast<unsigned int>(Repeat::Month): {
        addMonth(event);
        break;
    }
    case static_cast<unsigned int>(Repeat::Year): {
        addYear(event);
        break;
    }
    default: {
        if (event->repeat > 0)
            addCustom(event);
        break;
    }
    }
}
\ No newline at end of file

D module-apps/application-calendar/widgets/AddRepeatedEvents.hpp => module-apps/application-calendar/widgets/AddRepeatedEvents.hpp +0 -31
@@ 1,31 0,0 @@
#pragma once
#include "Application.hpp"
#include <module-db/Interface/EventsRecord.hpp>

enum class Repeat
{
    Never = 0,
    Daily,
    Weekly,
    TwoWeeks,
    Month,
    Year,
    Custom
};

class AddRepeatedEvents
{
    app::Application *application = nullptr;
    Repeat repeatOption           = Repeat::Never;

  public:
    AddRepeatedEvents(app::Application *app) : application(app){};
    void addDaily(std::shared_ptr<EventsRecord> event);
    void addWeekly(std::shared_ptr<EventsRecord> event);
    void addTwoWeeks(std::shared_ptr<EventsRecord> event);
    void addMonth(std::shared_ptr<EventsRecord> event);
    void addYear(std::shared_ptr<EventsRecord> event);
    void addCustom(std::shared_ptr<EventsRecord> event);

    void addRepeatedEvents(std::shared_ptr<EventsRecord> event);
};

M module-apps/application-calendar/widgets/CalendarStyle.hpp => module-apps/application-calendar/widgets/CalendarStyle.hpp +0 -25
@@ 57,31 57,6 @@ namespace style
                const inline int max_minutes       = 59;
            } // namespace time

            namespace reminder
            {
                const inline int never              = 0xFFFFFF;
                const inline int event_time         = 0;
                const inline int five_min_before    = 5;
                const inline int fifteen_min_before = 15;
                const inline int thirty_min_before  = 30;
                const inline int one_hour_before    = 100;
                const inline int two_hour_before    = 200;
                const inline int one_day_before     = 10000;
                const inline int two_days_before    = 20000;
                const inline int one_week_before    = 70000;
            } // namespace reminder

            namespace repeat
            {
                const inline int never     = 0;
                const inline int daily     = 1;
                const inline int weekly    = 2;
                const inline int two_weeks = 3;
                const inline int month     = 4;
                const inline int year      = 5;
                const inline int custom    = 6;
            } // namespace repeat

            namespace item
            {
                namespace dayEvents

M module-apps/application-calendar/widgets/DayEventsItem.cpp => module-apps/application-calendar/widgets/DayEventsItem.cpp +0 -3
@@ 50,9 50,6 @@ namespace gui
            if (record->reminder == static_cast<uint32_t>(Reminder::never)) {
                clock->setVisible(false);
            }
            if (record->reminder == style::window::calendar::reminder::never) {
                clock->setVisible(false);
            }
        }
    }


M module-apps/application-calendar/windows/CalendarMainWindow.cpp => module-apps/application-calendar/windows/CalendarMainWindow.cpp +0 -1
@@ 2,7 2,6 @@
#include "application-calendar/ApplicationCalendar.hpp"
#include "application-calendar/models/MonthModel.hpp"
#include "application-calendar/widgets/CalendarStyle.hpp"
#include "application-calendar/models/AllEventsModel.hpp"
#include "application-calendar/data/CalendarData.hpp"
#include "NoEvents.hpp"
#include <module-services/service-db/messages/QueryMessage.hpp>

M module-apps/application-calendar/windows/EventReminderWindow.cpp => module-apps/application-calendar/windows/EventReminderWindow.cpp +0 -8
@@ 71,10 71,6 @@ namespace gui
        setFocusItem(nullptr);
    }

    void EventReminderWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
    }

    void EventReminderWindow::destroyInterface()
    {
        destroyTimer();


@@ 143,10 139,6 @@ namespace gui

        sapm::ApplicationManager::messageSwitchApplication(
            application, "ApplicationDesktop", gui::name::window::main_window, nullptr);

        // TODO: after rework of application switching we would switch here to the last opened window
        //  of the last active application
        // application sapm::ApplicationManager::messageSwitchPreviousApplication(application);
    }

} /* namespace gui */

M module-apps/application-calendar/windows/EventReminderWindow.hpp => module-apps/application-calendar/windows/EventReminderWindow.hpp +2 -4
@@ 31,11 31,9 @@ namespace gui

      public:
        EventReminderWindow(app::Application *app, std::string name);
        virtual ~EventReminderWindow() override;

        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        virtual void onClose() override;
        virtual ~EventReminderWindow();

        void onClose() override;
        bool onInput(const gui::InputEvent &inputEvent) override;
        void rebuild() override;
        void buildInterface() override;

M module-apps/application-calendar/windows/NewEditEventWindow.cpp => module-apps/application-calendar/windows/NewEditEventWindow.cpp +1 -0
@@ 101,6 101,7 @@ namespace gui
        if (data == nullptr) {
            return false;
        }

        if (data->getDescription() == style::window::calendar::edit_event) {
            eventAction = EventAction::Edit;
        }

M module-apps/application-calendar/windows/NewEditEventWindow.hpp => module-apps/application-calendar/windows/NewEditEventWindow.hpp +0 -1
@@ 12,7 12,6 @@
#include <gui/widgets/ListItem.hpp>
#include <ListView.hpp>
#include <Utils.hpp>
#include <module-apps/application-calendar/data/OptionParser.hpp>

namespace gui
{

M module-apps/application-call/widgets/Icons.hpp => module-apps/application-call/widgets/Icons.hpp +0 -20
@@ 96,24 96,4 @@ namespace gui
        {}
        ~SpeakerIcon() override = default;
    };

    enum class CalendarIconState
    {
        CALENDAR_SHOW
    };
    class CalendarIcon : public Icon<CalendarIconState>
    {
      protected:
        static const inline std::string callendarImg    = "calendar";
        static const inline std::string calendarShowStr = "app_call_calendar_show";
        static const inline Icon::IconMap iconMap       = {
            {CalendarIconState::CALENDAR_SHOW, {callendarImg, calendarShowStr}}};

      public:
        CalendarIcon() = delete;
        CalendarIcon(Item *parent, const uint32_t &x, const uint32_t &y)
            : Icon(parent, x, y, callAppStyle::icon::x_margin, CalendarIconState::CALENDAR_SHOW, iconMap)
        {}
        ~CalendarIcon() override = default;
    };
} // namespace gui

M module-apps/application-desktop/ApplicationDesktop.cpp => module-apps/application-desktop/ApplicationDesktop.cpp +2 -35
@@ 17,9 17,6 @@
#include <service-appmgr/ApplicationManager.hpp>
#include <service-cellular/ServiceCellular.hpp>
#include <application-calllog/ApplicationCallLog.hpp>
#include "application-calendar/ApplicationCalendar.hpp"
#include "application-calendar/widgets/CalendarStyle.hpp"

#include <messages/QueryMessage.hpp>
#include <module-db/queries/notifications/QueryNotificationsClear.hpp>



@@ 107,10 104,6 @@ namespace app
                notifications.notSeen.SMS = record.value;
                break;

            case NotificationsRecord::Key::CalendarEvents:
                notifications.notSeen.CalendarEvents = record.value;
                break;

            case NotificationsRecord::Key::NotValidKey:
            case NotificationsRecord::Key::NumberOfKeys:
                LOG_ERROR("Not a valid key");


@@ 135,8 128,6 @@ namespace app
            return requestNotSeenNotifications();
        }

        // mlucki
        // ToDo: calendarEvents
        if ((msg->interface == db::Interface::Name::Calllog || msg->interface == db::Interface::Name::SMSThread ||
             msg->interface == db::Interface::Name::SMS) &&
            msg->type != db::Query::Type::Read) {


@@ 174,17 165,6 @@ namespace app
            this, app::CallLogAppStr, gui::name::window::main_window, nullptr);
    }

    bool ApplicationDesktop::showAllCalendarEvents()
    {
        LOG_DEBUG("show all calendar events!");
        return sapm::ApplicationManager::messageSwitchApplication(
            // this, app::name_calendar, gui::name::window::main_window, nullptr);
            this,
            app::name_calendar,
            style::window::calendar::name::all_events_window,
            nullptr);
    }

    bool ApplicationDesktop::clearCallsNotification()
    {
        LOG_DEBUG("Clear Call notifications");


@@ 207,18 187,6 @@ namespace app
        return true;
    }

    bool ApplicationDesktop::clearCalendarEventsNotification()
    {
        LOG_DEBUG("Clear CalendarEvents notifications");
        DBServiceAPI::GetQuery(
            this,
            db::Interface::Name::Notifications,
            std::make_unique<db::query::notifications::Clear>(NotificationsRecord::Key::CalendarEvents));
        notifications.notSeen.CalendarEvents = 0;
        getCurrentWindow()->rebuild(); // triger rebuild - shouldn't be needed, but is
        return true;
    }

    bool ApplicationDesktop::requestNotSeenNotifications()
    {
        return DBServiceAPI::GetQuery(


@@ 227,9 195,8 @@ namespace app

    bool ApplicationDesktop::requestNotReadNotifications()
    {
        notifications.notRead.Calls          = DBServiceAPI::CalllogGetCount(this, EntryState::UNREAD);
        notifications.notRead.SMS            = DBServiceAPI::ThreadGetCount(this, EntryState::UNREAD);
        notifications.notRead.CalendarEvents = DBServiceAPI::CalendarEventsGetCount(this, EntryState::UNREAD);
        notifications.notRead.Calls = DBServiceAPI::CalllogGetCount(this, EntryState::UNREAD);
        notifications.notRead.SMS   = DBServiceAPI::ThreadGetCount(this, EntryState::UNREAD);

        return true;
    }

M module-apps/application-desktop/ApplicationDesktop.hpp => module-apps/application-desktop/ApplicationDesktop.hpp +1 -4
@@ 29,11 29,10 @@ namespace app
            {
                unsigned int SMS   = 0;
                unsigned int Calls = 0;
                unsigned int CalendarEvents = 0;

                auto areEmpty()
                {
                    return Calls == 0 && SMS == 0 && CalendarEvents == 0;
                    return Calls == 0 && SMS == 0;
                }
            };



@@ 69,10 68,8 @@ namespace app
        //	static bool messageLockPhone( sys::Service* sender, std::string application , const gui::InputEvent& event
        //);
        bool showCalls();
        bool showAllCalendarEvents();
        bool clearCallsNotification();
        bool clearMessagesNotification();
        bool clearCalendarEventsNotification();
        bool requestNotSeenNotifications();
        bool requestNotReadNotifications();


M module-apps/application-desktop/windows/DesktopMainWindow.cpp => module-apps/application-desktop/windows/DesktopMainWindow.cpp +11 -10
@@ 18,7 18,8 @@
#include "application-messages/ApplicationMessages.hpp"
#include "gui/widgets/Image.hpp"
#include "service-appmgr/ApplicationManager.hpp"
#include "service-time/api/TimeServiceAPI.hpp"
#include "service-time/ServiceTime.hpp"
#include "service-time/messages/TimeMessage.hpp"
#include <UiCommonActions.hpp>

#include "i18/i18.hpp"


@@ 101,16 102,16 @@ namespace gui
            setFocusItem(nullptr);
            erase(notifications);

            // TODO
            // Temporary solution: blocking of ServiceTime timers when phone becomes locked
            TimeServiceAPI::messageTimersProcessingStop(application);
            // TimeServiceAPI::messageTimersProcessingStop(application);
            auto msg = std::make_shared<TimersProcessingStopMessage>();
            sys::Bus::SendUnicast(msg, service::name::service_time, application);
        }
        else if (app->lockHandler.lock.isLocked()) {
            application->switchWindow(app::window::name::desktop_pin_lock);

            // TODO
            // Temporary solution: blocking of ServiceTime timers when phone becomes locked
            TimeServiceAPI::messageTimersProcessingStop(application);
            // TimeServiceAPI::messageTimersProcessingStop(application);
            auto msg = std::make_shared<TimersProcessingStopMessage>();
            sys::Bus::SendUnicast(msg, service::name::service_time, application);
        }
        else {
            bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("app_desktop_menu"));


@@ 123,9 124,9 @@ namespace gui
                    this->application, app::name_settings, app::sim_select, nullptr);
            }

            // TODO
            // Temporary solution: starting of ServiceTime timers when phone becomes unlocked
            TimeServiceAPI::messageTimersProcessingStart(application);
            // TimeServiceAPI::messageTimersProcessingStart(application);
            auto msg = std::make_shared<TimersProcessingStartMessage>();
            sys::Bus::SendUnicast(msg, service::name::service_time, application);
        }
    }


M module-apps/application-desktop/windows/MenuWindow.cpp => module-apps/application-desktop/windows/MenuWindow.cpp +0 -2
@@ 4,8 4,6 @@
#include "Item.hpp"
#include "Navigation.hpp"
#include "service-appmgr/ApplicationManager.hpp"
#include "module-apps/application-calendar/data/CalendarData.hpp"
#include "service-time/api/TimeServiceAPI.hpp"

#include <tools/Common.hpp>
#include <Style.hpp>

M module-db/Interface/NotificationsRecord.hpp => module-db/Interface/NotificationsRecord.hpp +0 -1
@@ 29,7 29,6 @@ struct NotificationsRecord : public Record
        NotValidKey = 0,
        Calls,
        Sms,
        CalendarEvents,
        NumberOfKeys // do not use directly
    };


M module-db/Tables/EventsTable.cpp => module-db/Tables/EventsTable.cpp +0 -8
@@ 541,19 541,11 @@ std::vector<EventsTableRow> EventsTable::SelectFirstUpcoming(TimePoint filter_fr
        db->query("SELECT DATETIME(date_from, '-' || reminder || ' minutes') AS calc_dt, * "
                  "FROM events "
                  "WHERE calc_dt >= '%q' "

                  // TODO
                  // Temporary calc_dt is not filtered as to be less-or-equal than date_from's end-of-day
                  // (until we have implemented a notification of 'new day' for ServiceTime/CalendarTimeEvents)
                  //"AND calc_dt <= DATETIME('%q', '+1 day', '-1 second') "

                  "AND reminder_fired = '%q' "
                  "AND reminder <> -1 "
                  "ORDER BY calc_dt "
                  "LIMIT 1 ",
                  TimePointToString(filter_from).c_str(),
                  // As in 'to do' above
                  // TimePointToString(filter_till).c_str(),
                  TimePointToString(TIME_POINT_INVALID).c_str());

    if ((retQuery == nullptr) || (retQuery->getRowCount() == 0)) {

M module-db/Tables/NotificationsTable.cpp => module-db/Tables/NotificationsTable.cpp +2 -5
@@ 15,13 15,10 @@ bool NotificationsTable::create()
        return false;
    }

    if (!add({{.ID = 0}, .key = static_cast<uint32_t>(NotificationsRecord::Key::Calls), .value = 2})) {
    if (!add({{.ID = 0}, .key = static_cast<uint32_t>(NotificationsRecord::Key::Calls), .value = 0})) {
        return false;
    }
    if (!add({{.ID = 0}, .key = static_cast<uint32_t>(NotificationsRecord::Key::Sms), .value = 3})) {
        return false;
    }
    if (!add({{.ID = 0}, .key = static_cast<uint32_t>(NotificationsRecord::Key::CalendarEvents), .value = 4})) {
    if (!add({{.ID = 0}, .key = static_cast<uint32_t>(NotificationsRecord::Key::Sms), .value = 0})) {
        return false;
    }


M module-db/queries/calendar/QueryEventsSelectFirstUpcoming.hpp => module-db/queries/calendar/QueryEventsSelectFirstUpcoming.hpp +2 -0
@@ 7,6 7,7 @@

namespace db::query::events
{
    /// Query for getting calendar event whose reminder is first in filtered time range
    class SelectFirstUpcoming : public Query
    {
      public:


@@ 17,6 18,7 @@ namespace db::query::events
        TimePoint filter_till;
    };

    /// Result of SelectFirstUpcoming query
    class SelectFirstUpcomingResult : public QueryResult
    {
        std::unique_ptr<std::vector<EventsRecord>> records;

M module-services/service-appmgr/ApplicationManager.cpp => module-services/service-appmgr/ApplicationManager.cpp +1 -7
@@ 484,13 484,7 @@ namespace sapm
        // this is applicable to all applications except desktop
        if ((focusApplicationName == msg->getName())) {
            LOG_WARN("Trying to return currently active application");

            // TODO
            // Before rework of ApplicationManager: there we have temporary simple switch to
            // currently focused application
            app::Application::messageSwitchApplication(
                this, msg->getName(), msg->getWindow(), std::move(msg->getData()));
            return true;
            return false;
        }

        // store the name of the application to be executed and start closing previous application

M module-services/service-db/api/DBServiceAPI.cpp => module-services/service-db/api/DBServiceAPI.cpp +0 -7
@@ 814,13 814,6 @@ bool DBServiceAPI::CalllogGetLimitOffset(sys::Service *serv, uint32_t offset, ui
    return true;
}

uint32_t DBServiceAPI::CalendarEventsGetCount(sys::Service *serv, EntryState state)
{
    // mlucki
    // ToDo: calendarEvents
    return 3;
}

uint32_t DBServiceAPI::GetCountryCodeByMCC(sys::Service *serv, uint32_t mcc)
{
    std::shared_ptr<DBCountryCodeMessage> msg =

M module-services/service-db/api/DBServiceAPI.hpp => module-services/service-db/api/DBServiceAPI.hpp +0 -3
@@ 152,9 152,6 @@ class DBServiceAPI
    static uint32_t CalllogGetCount(sys::Service *serv, EntryState state = EntryState::ALL);
    static bool CalllogGetLimitOffset(sys::Service *serv, uint32_t offset, uint32_t limit);

    /* calendar events */
    static uint32_t CalendarEventsGetCount(sys::Service *serv, EntryState state = EntryState::ALL);

    /* country codes */
    static uint32_t GetCountryCodeByMCC(sys::Service *serv, uint32_t mcc);


M module-services/service-time/CMakeLists.txt => module-services/service-time/CMakeLists.txt +0 -2
@@ 16,13 16,11 @@ target_sources( ${PROJECT_NAME}

	PRIVATE
		"${CMAKE_CURRENT_LIST_DIR}/ServiceTime.cpp"
		"${CMAKE_CURRENT_LIST_DIR}/api/TimeServiceAPI.cpp"
		"${CMAKE_CURRENT_LIST_DIR}/timeEvents/TimeEvents.cpp"
		"${CMAKE_CURRENT_LIST_DIR}/timeEvents/CalendarTimeEvents.cpp"

	PUBLIC
		"${CMAKE_CURRENT_LIST_DIR}/ServiceTime.hpp"
		"${CMAKE_CURRENT_LIST_DIR}/api/TimeServiceAPI.hpp"
		"${CMAKE_CURRENT_LIST_DIR}/timeEvents/TimeEvents.hpp"
		"${CMAKE_CURRENT_LIST_DIR}/timeEvents/CalendarTimeEvents.hpp"
)

M module-services/service-time/ServiceTime.cpp => module-services/service-time/ServiceTime.cpp +9 -8
@@ 8,8 8,7 @@

namespace stm
{
    ServiceTime::ServiceTime()
        : sys::Service(service::name::service_time, "", 4096 * 2, sys::ServicePriority::Idle), calendarEvents(this)
    ServiceTime::ServiceTime() : sys::Service(service::name::service_time), calendarEvents(this)
    {
        LOG_INFO("[ServiceTime] Initializing");
        busChannels.push_back(sys::BusChannels::ServiceDBNotifications);


@@ 51,19 50,22 @@ namespace stm
                (msg->type == db::Query::Type::Create || msg->type == db::Query::Type::Update ||
                 msg->type == db::Query::Type::Delete)) {

                calendarEvents.ProcessNextEvent();
                calendarEvents.processNextEvent();

                return responseMsg;
            }
        } break;
        case MessageType::ReloadTimers: {
            calendarEvents.ProcessNextEvent();
            calendarEvents.processNextEvent();
            return std::make_shared<sys::ResponseMessage>();
        } break;
        case MessageType::TimersProcessingStart: {
            calendarEvents.StartProcessing();
            calendarEvents.startProcessing();
            return std::make_shared<sys::ResponseMessage>();
        } break;
        case MessageType::TimersProcessingStop: {
            calendarEvents.StopProcessing();
            calendarEvents.stopProcessing();
            return std::make_shared<sys::ResponseMessage>();
        } break;
        default:
            break;


@@ 74,7 76,6 @@ namespace stm
            return responseMsg;
        }

        // handle database response
        bool responseHandled = false;
        if (resp != nullptr) {
            if (auto msg = dynamic_cast<db::QueryResponse *>(resp)) {


@@ 82,7 83,7 @@ namespace stm

                if (dynamic_cast<db::query::events::SelectFirstUpcomingResult *>(result.get())) {

                    calendarEvents.ReceiveNextEventQuery(std::move(result));
                    calendarEvents.receiveNextEventQuery(std::move(result));
                    responseHandled = true;
                }
            }

M module-services/service-time/ServiceTime.hpp => module-services/service-time/ServiceTime.hpp +0 -1
@@ 27,7 27,6 @@ namespace stm
        ServiceTime();
        ~ServiceTime();

        // Invoked during initialization
        sys::ReturnCodes InitHandler() override;
        sys::ReturnCodes DeinitHandler() override;
        sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final;

D module-services/service-time/api/TimeServiceAPI.cpp => module-services/service-time/api/TimeServiceAPI.cpp +0 -46
@@ 1,46 0,0 @@
/*
 *  @file TimeSerivceAPI.cpp
 *  @author
 *  @date 08.05.20
 *  @brief
 *  @copyright Copyright (C) 2019 mudita.com
 *  @details
 */

#include "TimeServiceAPI.hpp"
#include "Service/Bus.hpp"
#include "../ServiceTime.hpp"

bool TimeServiceAPI::messageReloadTimers(sys::Service *sender)
{
    auto msg = std::make_shared<ReloadTimersMessage>();
    return sys::Bus::SendUnicast(msg, service::name::service_time, sender);
}

bool TimeServiceAPI::messageTimersProcessingStart(sys::Service *sender)
{
    auto msg = std::make_shared<TimersProcessingStartMessage>();
    return sys::Bus::SendUnicast(msg, service::name::service_time, sender);
}

bool TimeServiceAPI::messageTimersProcessingStop(sys::Service *sender)
{
    auto msg = std::make_shared<TimersProcessingStopMessage>();
    return sys::Bus::SendUnicast(msg, service::name::service_time, sender);
}

/*namespace TimeServiceAPI
{

    uint32_t GetCurrentDT()
    {
        return 0;
    }

    int GetCurrentTimeZone()
    {
        return 0;
    }

} // namespace TimeServiceAPI
*/

D module-services/service-time/api/TimeServiceAPI.hpp => module-services/service-time/api/TimeServiceAPI.hpp +0 -29
@@ 1,29 0,0 @@
#pragma once

#include "../messages/TimeMessage.hpp"
#include <optional>

class TimeServiceAPI
{
  public:
    static bool messageReloadTimers(sys::Service *sender);
    static bool messageTimersProcessingStart(sys::Service *sender);
    static bool messageTimersProcessingStop(sys::Service *sender);
};

/*namespace TimeServiceAPI
{

    uint32_t GetCurrentDT();
    int GetCurrentTimeZone();

    class TimeServiceAPI
    {
      public:

        static bool messageReloadTimers(sys::Service *sender);
        static bool messageTimersProcessingStart(sys::Service *sender);
        static bool messageTimersProcessingStop(sys::Service *sender);

    };
}; // namespace TimeServiceAPI*/

M module-services/service-time/timeEvents/CalendarTimeEvents.cpp => module-services/service-time/timeEvents/CalendarTimeEvents.cpp +7 -7
@@ 17,7 17,7 @@ namespace stm
    CalendarTimeEvents::CalendarTimeEvents(sys::Service *service) : TimeEvents(service)
    {}

    bool CalendarTimeEvents::SendNextEventQuery()
    bool CalendarTimeEvents::sendNextEventQuery()
    {
        TimePoint filterFrom = TimePointNow();
        TimePoint filterTill = filterFrom;


@@ 26,12 26,12 @@ namespace stm
            filterTill = filterFrom;
        }

        return DBServiceAPI::GetQuery(Service(),
        return DBServiceAPI::GetQuery(service(),
                                      db::Interface::Name::Events,
                                      std::make_unique<db::query::events::SelectFirstUpcoming>(filterFrom, filterTill));
    }

    uint32_t CalendarTimeEvents::CalcToNextEventInterval(std::unique_ptr<db::QueryResult> nextEventQueryResult)
    uint32_t CalendarTimeEvents::calcToNextEventInterval(std::unique_ptr<db::QueryResult> nextEventQueryResult)
    {
        auto firstUpcomingQuery =
            dynamic_cast<db::query::events::SelectFirstUpcomingResult *>(nextEventQueryResult.get());


@@ 54,14 54,14 @@ namespace stm
        return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
    }

    bool CalendarTimeEvents::SendEventFiredQuery()
    bool CalendarTimeEvents::sendEventFiredQuery()
    {
        eventRecord.reminder_fired = TimePointNow();
        return DBServiceAPI::GetQuery(
            Service(), db::Interface::Name::Events, std::make_unique<db::query::events::Edit>(eventRecord));
            service(), db::Interface::Name::Events, std::make_unique<db::query::events::Edit>(eventRecord));
    }

    void CalendarTimeEvents::InvokeEvent()
    void CalendarTimeEvents::invokeEvent()
    {
        std::unique_ptr<EventRecordData> eventData = std::make_unique<EventRecordData>();
        eventData->setDescription(style::window::calendar::name::event_reminder_window);


@@ 69,6 69,6 @@ namespace stm
        eventData->setData(event);

        sapm::ApplicationManager::messageSwitchApplication(
            Service(), app::name_calendar, style::window::calendar::name::event_reminder_window, std::move(eventData));
            service(), app::name_calendar, style::window::calendar::name::event_reminder_window, std::move(eventData));
    }
} // namespace stm

M module-services/service-time/timeEvents/CalendarTimeEvents.hpp => module-services/service-time/timeEvents/CalendarTimeEvents.hpp +5 -5
@@ 11,15 11,15 @@ namespace stm
        TimePoint startTP = TIME_POINT_INVALID;

      protected:
        const std::string TimerName() override
        const std::string timerName() override
        {
            return "CalendarTimeEvents_timer";
        };
        uint32_t CalcToNextEventInterval(std::unique_ptr<db::QueryResult> nextEventQueryResult) override;
        uint32_t calcToNextEventInterval(std::unique_ptr<db::QueryResult> nextEventQueryResult) override;

        bool SendNextEventQuery() override;
        bool SendEventFiredQuery() override;
        void InvokeEvent() override;
        bool sendNextEventQuery() override;
        bool sendEventFiredQuery() override;
        void invokeEvent() override;

      public:
        CalendarTimeEvents() = delete;

M module-services/service-time/timeEvents/TimeEvents.cpp => module-services/service-time/timeEvents/TimeEvents.cpp +26 -26
@@ 4,83 4,83 @@ namespace stm
{
    constexpr static const int eventTimerInitInterval = 1000;

    TimeEvents::TimeEvents(sys::Service *service) : service(service)
    TimeEvents::TimeEvents(sys::Service *service) : serv(service)
    {}

    TimeEvents::~TimeEvents()
    {
        StopTimer();
        stopTimer();
    }

    std::unique_ptr<sys::Timer> &TimeEvents::Timer()
    std::unique_ptr<sys::Timer> &TimeEvents::timer()
    {
        if (fireEventTimer == nullptr) {
            fireEventTimer = std::make_unique<sys::Timer>(
                TimerName(), service, eventTimerInitInterval, sys::Timer::Type::SingleShot);
                timerName(), service(), eventTimerInitInterval, sys::Timer::Type::SingleShot);
        }
        return fireEventTimer;
    }

    void TimeEvents::StartProcessing()
    void TimeEvents::startProcessing()
    {
        timersProcessingStarted = true;
        ProcessNextEvent();
        processNextEvent();
    }

    void TimeEvents::StopProcessing()
    void TimeEvents::stopProcessing()
    {
        StopTimer();
        stopTimer();
        timersProcessingStarted = false;
    }

    void TimeEvents::ProcessNextEvent()
    void TimeEvents::processNextEvent()
    {
        StopTimer();
        if (!IsStarted()) {
        stopTimer();
        if (!isStarted()) {
            return;
        }

        SendNextEventQuery();
        sendNextEventQuery();
    }

    void TimeEvents::StopTimer()
    void TimeEvents::stopTimer()
    {
        Timer()->stop();
        timer()->stop();
    }

    void TimeEvents::RecreateTimer(uint32_t interval)
    void TimeEvents::recreateTimer(uint32_t interval)
    {
        StopTimer();
        if (!IsStarted()) {
        stopTimer();
        if (!isStarted()) {
            return;
        }

        Timer()->connect([=](sys::Timer &) { fireEventTimerCallback(); });
        Timer()->reload(interval);
        timer()->connect([=](sys::Timer &) { fireEventTimerCallback(); });
        timer()->reload(interval);
    }

    void TimeEvents::fireEventTimerCallback()
    {
        if (!IsStarted()) {
        if (!isStarted()) {
            return;
        }

        InvokeEvent();
        SendEventFiredQuery();
        invokeEvent();
        sendEventFiredQuery();
    }

    bool TimeEvents::ReceiveNextEventQuery(std::unique_ptr<db::QueryResult> nextEventQueryResult)
    bool TimeEvents::receiveNextEventQuery(std::unique_ptr<db::QueryResult> nextEventQueryResult)
    {
        if (!IsStarted()) {
        if (!isStarted()) {
            return true;
        }
        if (nextEventQueryResult == nullptr) {
            return false;
        }

        uint32_t interval = CalcToNextEventInterval(std::move(nextEventQueryResult));
        uint32_t interval = calcToNextEventInterval(std::move(nextEventQueryResult));
        if (interval > 0) {
            RecreateTimer(interval);
            recreateTimer(interval);
        }
        return true;
    }

M module-services/service-time/timeEvents/TimeEvents.hpp => module-services/service-time/timeEvents/TimeEvents.hpp +21 -17
@@ 10,37 10,41 @@ namespace stm
      private:
        bool timersProcessingStarted               = false;
        std::unique_ptr<sys::Timer> fireEventTimer = nullptr;
        sys::Service *service                      = nullptr;
        std::unique_ptr<sys::Timer> &Timer();
        sys::Service *serv                         = nullptr;
        std::unique_ptr<sys::Timer> &timer();

      protected:
        sys::Service *Service()
        sys::Service *service()
        {
            return service;
            return serv;
        };
        virtual const std::string TimerName() = 0;
        void StopTimer();
        void RecreateTimer(uint32_t interval);
        virtual const std::string timerName() = 0;
        void stopTimer();
        void recreateTimer(uint32_t interval);
        virtual void fireEventTimerCallback();
        virtual uint32_t CalcToNextEventInterval(std::unique_ptr<db::QueryResult> nextEventQueryResult) = 0;
        virtual uint32_t calcToNextEventInterval(std::unique_ptr<db::QueryResult> nextEventQueryResult) = 0;

        virtual bool SendNextEventQuery()  = 0;
        virtual bool SendEventFiredQuery() = 0;
        virtual void InvokeEvent(){};
        virtual bool sendNextEventQuery()  = 0;
        virtual bool sendEventFiredQuery() = 0;
        virtual void invokeEvent(){};

      public:
        TimeEvents() = delete;
        TimeEvents(sys::Service *service);
        ~TimeEvents();

        void StartProcessing();
        void StopProcessing();
        bool IsStarted()
        /// startProcessing - starts processing of events
        void startProcessing();
        /// stopProcessing - stops processing of events
        void stopProcessing();
        /// isStarted - returns events' processing state
        bool isStarted()
        {
            return timersProcessingStarted;
        };
        void ProcessNextEvent();

        virtual bool ReceiveNextEventQuery(std::unique_ptr<db::QueryResult> nextEventQueryResult);
        /// processNextEvent - starts next event query
        void processNextEvent();
        /// receiveNextEventQuery - receives result of next event query
        virtual bool receiveNextEventQuery(std::unique_ptr<db::QueryResult> nextEventQueryResult);
    };
} // namespace stm