~aleteoryx/muditaos

ref: 8e6490863a74d30442b434f91b90a2f07095e2d3 muditaos/module-apps/application-settings/windows/apps/MessagesWindow.cpp -rw-r--r-- 3.0 KiB
8e649086 — Mateusz Grzegorzek [BH-395] Librarize application-settings 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "MessagesWindow.hpp"

#include <application-settings/data/SoundSelectData.hpp>
#include <application-settings/windows/WindowNames.hpp>

namespace gui
{
    MessagesWindow::MessagesWindow(app::Application *app,
                                   std::unique_ptr<audio_settings::AbstractAudioSettingsModel> &&audioModel)
        : BaseSettingsWindow(app, gui::window::name::messages), mWidgetMaker(this), mAudioModel(std::move(audioModel))
    {
        mShowUnreadMessagesFirst = false;
        setTitle(utils::translate("app_settings_apps_messages"));
    }

    std::list<Option> MessagesWindow::buildOptionsList()
    {
        std::list<gui::Option> optionList;
        mVibrationsEnabled = mAudioModel->isVibrationEnabled();
        mSoundEnabled      = mAudioModel->isSoundEnabled();

        mWidgetMaker.addSwitchOption(optionList, utils::translate("app_settings_vibration"), mVibrationsEnabled, [&]() {
            switchVibrationState();
        });

        mWidgetMaker.addSwitchOption(
            optionList, utils::translate("app_settings_sound"), mSoundEnabled, [&]() { switchSoundState(); });

        if (mSoundEnabled) {
            mWidgetMaker.addSelectOption(
                optionList, utils::translate("app_settings_message_sound"), [&]() { openMessageSoundWindow(); }, true);
        }

#if DISABLED_SETTINGS_OPTIONS == 1
        mWidgetMaker.addSwitchOption(optionList,
                                     utils::translate("app_settings_show_unread_first"),
                                     mShowUnreadMessagesFirst,
                                     [&]() { switchShowUnreadFirst(); });

        mWidgetMaker.addSelectOption(
            optionList, utils::translate("app_settings_Templates"), [&]() { openMessageTemplates(); });
#endif // DISABLED_SETTINGS_OPTIONS

        return optionList;
    }

    void MessagesWindow::switchVibrationState()
    {
        (mVibrationsEnabled) ? mAudioModel->setVibrationDisabled() : mAudioModel->setVibrationEnabled();
        refreshOptionsList();
    }

    void MessagesWindow::switchSoundState()
    {
        mSoundEnabled ? mAudioModel->setSoundDisabled() : mAudioModel->setSoundEnabled();
        refreshOptionsList();
    }

    void MessagesWindow::switchShowUnreadFirst()
    {
        mShowUnreadMessagesFirst = !mShowUnreadMessagesFirst;
        LOG_INFO("switchSoundState %d", static_cast<int>(mSoundEnabled));
        refreshOptionsList();
    }

    void MessagesWindow::openMessageSoundWindow()
    {
        SoundSelectData::Info info;
        info.windowTitle = utils::translate("app_settings_message_sound");
        info.audioModel  = mAudioModel.get();

        application->switchWindow(gui::window::name::sound_select, std::make_unique<SoundSelectData>(info));
    }

    void MessagesWindow::openMessageTemplates()
    {
        this->application->switchWindow(gui::window::name::message_templates);
    }

} // namespace gui