~aleteoryx/muditaos

ref: 192f5bc85453c1c6909767451a73871a4f6f26a0 muditaos/module-apps/windows/Options.cpp -rw-r--r-- 3.3 KiB
192f5bc8 — Lucjan Bryndza [EGD-4331] Strict check fat handles (#1034) 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Options.hpp"
#include "Text.hpp"
#include "tools/Common.hpp"
#include <UiCommonActions.hpp>
#include <cassert>
#include <i18/i18.hpp>
#include <utility>
#include <FontManager.hpp>

namespace style::option
{
    const inline gui::Length text_left_padding = 10;
}

namespace gui::option
{
    /// builder for call option
    /// creates text with caller in bold
    class Call : public Base
    {
      private:
        app::Application *app = nullptr;
        ContactRecord contact;

      public:
        Call(app::Application *app, ContactRecord contact) : app(app), contact(std::move(contact))
        {}

        [[nodiscard]] auto build() const -> Item * override
        {
            auto *rect     = new gui::Rect(nullptr,
                                       style::window::default_left_margin,
                                       0,
                                       style::window_width - 2 * style::window::default_right_margin,
                                       style::window::label::big_h);
            auto font      = FontManager::getInstance().getFont(style::window::font::medium);
            auto font_bold = FontManager::getInstance().getFont(style::window::font::mediumbold);
            auto text      = new Text(nullptr, style::option::text_left_padding, 0, 0, 0);
            text->setMaximumSize(rect->getWidth(), rect->getHeight());
            text->setEditMode(EditMode::BROWSE);
            text->setText(std::make_unique<TextDocument>(std::list<TextBlock>(
                {{utils::localize.get("sms_call_text"), font}, {contact.getFormattedName(), font_bold}})));
            style::window::decorate(rect);
            auto l_app              = app;
            auto l_contact          = contact;
            rect->activatedCallback = [l_app, l_contact](gui::Item &item) { return app::call(l_app, l_contact); };
            rect->addWidget(text);
            center(rect, text, Axis::Y);
            return rect;
        }
    };

}; // namespace gui::option

namespace gui::options
{
    using namespace app;

    Option call(Application *app, CallOperation callOperation, const ContactRecord &contact)
    {
        assert(app != nullptr);
        return Option{std::make_unique<gui::option::Call>(app, contact)};
    }

    Option contact(Application *app,
                   ContactOperation contactOperation,
                   const ContactRecord &contactRec,
                   gui::Arrow arrow)
    {
        assert(app != nullptr);

        std::string str;
        switch (contactOperation) {
        case ContactOperation::Details:
            str = utils::localize.get("app_options_contact_details");
            break;

        case ContactOperation::Add:
            str = utils::localize.get("app_options_contact_add");
            break;

        case ContactOperation::Edit:
            str = utils::localize.get("app_options_contact_edit");
            break;

        default:
            str = utils::localize.get("app_options_invalid_option");
            LOG_WARN("ContactOperation %d not supported", static_cast<int>(contactOperation));
            break;
        }

        return {str, [=](gui::Item &item) { return app::contact(app, contactOperation, contactRec); }, arrow};
    }
} // namespace gui::options