~aleteoryx/muditaos

ref: 5398907b6f137be5c1a35a622c7d51bc8a3595c0 muditaos/module-apps/application-messages/windows/OptionsMessages.cpp -rw-r--r-- 3.2 KiB
5398907b — Przemyslaw Brudny [EGD-7158] Added text paste into Phonebook 4 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SMSdata.hpp"

#include <apps-common/options/type/OptionCall.hpp>
#include <apps-common/options/type/OptionContact.hpp>
#include <Clipboard.hpp>
#include <i18n/i18n.hpp>
#include <Option.hpp>
#include <OptionsMessages.hpp>
#include <Text.hpp>
#include <tools/Common.hpp>

#include <memory>

std::list<gui::Option> smsWindowOptions(app::ApplicationMessages *app, const SMSRecord &record)
{
    auto contact = DBServiceAPI::MatchContactByPhoneNumber(app, record.number);
    if (contact == nullptr) {
        return {};
    }
    const auto isTempContact = contact->isTemporary();

    std::list<gui::Option> options;
    if (record.type == SMSType::FAILED) {
        options.emplace_back(utils::translate("sms_resend_failed"), [=, &record](gui::Item &item) {
            app->resendSms(record);
            app->returnToPreviousWindow();
            return true;
        });
    }

    if (isTempContact) {
        options.emplace_back(
            gui::Option{std::make_unique<gui::option::Call>(app, record.number.getFormatted(), record.number)});
        ContactRecord newContact;
        newContact.numbers.emplace_back(record.number);
        options.emplace_back(
            gui::Option{std::make_unique<gui::option::Contact>(app, gui::option::ContactOperation::Add, newContact)});
    }
    else {
        options.emplace_back(
            gui::Option{std::make_unique<gui::option::Call>(app, contact->getFormattedName(), record.number)});
        options.emplace_back(
            gui::Option{std::make_unique<gui::option::Contact>(app, gui::option::ContactOperation::Details, *contact)});
    }

    options.emplace_back(UTF8(utils::translate("sms_forward_message")), [=](gui::Item &item) {
        std::unique_ptr<gui::SwitchData> data = std::make_unique<SMSTextData>(record.body);
        app->switchWindow(gui::name::window::new_sms, std::move(data));
        return true;
    });

    options.emplace_back(UTF8(utils::translate("sms_copy")), [=](gui::Item &item) {
        Clipboard::getInstance().copy(record.body);
        app->returnToPreviousWindow();
        return true;
    });

    options.emplace_back(UTF8(utils::translate("sms_delete_message")),
                         [=](gui::Item &item) { return app->removeSms(record); });

    return options;
}

std::list<gui::Option> newMessageWindowOptions(app::ApplicationMessages *app,
                                               const std::string &requestingWindow,
                                               gui::Text *text)
{
    std::list<gui::Option> options;

    options.emplace_back(UTF8(utils::translate("sms_use_template")), [=](gui::Item &item) {
        std::unique_ptr<gui::SwitchData> data = std::make_unique<SMSTemplateRequest>(requestingWindow);
        app->switchWindow(gui::name::window::sms_templates, std::move(data));
        return true;
    });

    if (Clipboard::getInstance().gotData()) {
        options.emplace_back(utils::translate("sms_paste"), [=](gui::Item &item) {
            text->addText(Clipboard::getInstance().paste(), gui::AdditionType::perBlock);
            app->returnToPreviousWindow();
            return true;
        });
    }

    return options;
}