~aleteoryx/muditaos

39e6f1b18a93471342a4f8cce3810dee0e7948be — RobertPiet 4 years ago 6bc6ecc
[EGD-5902] Phone Modes Windows

Windows for phone modes created.
Offline:FightMode/messages only ServiceCellularApi created.
ConnectionFrequency and DND options settings throught AppSettings.
25 files changed, 654 insertions(+), 7 deletions(-)

M image/assets/lang/English.json
M image/user/db/settings_v2_002.sql
M module-apps/application-settings-new/ApplicationSettings.cpp
M module-apps/application-settings-new/ApplicationSettings.hpp
M module-apps/application-settings-new/CMakeLists.txt
M module-apps/application-settings-new/widgets/SettingsStyle.hpp
A module-apps/application-settings-new/windows/ConnectionFrequencyWindow.cpp
A module-apps/application-settings-new/windows/ConnectionFrequencyWindow.hpp
A module-apps/application-settings-new/windows/DoNotDisturbWindow.cpp
A module-apps/application-settings-new/windows/DoNotDisturbWindow.hpp
A module-apps/application-settings-new/windows/OfflineWindow.cpp
A module-apps/application-settings-new/windows/OfflineWindow.hpp
A module-apps/application-settings-new/windows/PhoneModesWindow.cpp
A module-apps/application-settings-new/windows/PhoneModesWindow.hpp
M module-apps/options/OptionStyle.hpp
M module-apps/options/type/OptionSetting.cpp
M module-apps/options/type/OptionSetting.hpp
M module-gui/gui/widgets/Style.hpp
M module-services/service-cellular/CellularServiceAPI.cpp
M module-services/service-cellular/ServiceCellular.cpp
M module-services/service-cellular/service-cellular/CellularMessage.hpp
M module-services/service-cellular/service-cellular/CellularServiceAPI.hpp
M module-services/service-cellular/service-cellular/ServiceCellular.hpp
M module-services/service-db/agents/settings/SystemSettings.hpp
M source/MessageType.hpp
M image/assets/lang/English.json => image/assets/lang/English.json +14 -1
@@ 28,6 28,7 @@
  "common_connect": "CONNECT",
  "common_disconnect": "DISCONNECT",
  "common_forget": "FORGET",
  "common_adjust": "ADJUST",
  "common_mo": "MO",
  "common_tu": "TU",
  "common_we": "WE",


@@ 434,6 435,19 @@
  "app_settings_title_color_test": "Display available colors",
  "app_settings_toolbar_reset": "RESET",
  "app_settings_option_connected": "<text font='gt_pressura' weight='regular' size='27'>CONNECTED</text>",
  "app_settings_title_phone_modes": "Phone modes",
  "app_settings_title_do_not_disturb": "Do not disturb",
  "app_settings_title_offline": "Offline",
  "app_settings_title_connection_frequency": "Connection frequency",
  "app_settings_connected": "Connected",
  "app_settings_notifications_when_locked": "Notifications when locked",
  "app_settings_calls_from_favorites": "Calls from favorites",
  "app_settings_allow": "Allow",
  "app_settings_no_network_connection_flight_mode": "No network connection (flight mode)",
  "app_settings_messages_only": "Messages only",
  "app_settings_info_dnd": "This mode enables Pure to silently receive all notifications. You can allow notifications when favorite contacts call you.",
  "app_settings_info_offline_flight_mode": "This mode causes your Pure to be fully disconnected. You can safely use it as flight mode. Calls, messages and tethering are unavailable.",
  "app_settings_info_offline_messages_only": "Pure will log into the network to send and download messages based on connection frequency. Calls and tethering are unavailable.",
  "app_phonebook_title_main": "Contacts",
  "app_phonebook_search_win_contacts": "Contacts",
  "common_search_uc": "Search",


@@ 520,7 534,6 @@
  "app_desktop_update_to": "Update to",
  "app_desktop_update_apply": "Do you want to apply this update?",
  "app_desktop_update_current": "Current",
  "app_desktop_update_apply": "Apply update?",
  "app_desktop_update_start": "Update start",
  "app_desktop_update_size": "size",
  "app_desktop_update_bytes": "bytes",

M image/user/db/settings_v2_002.sql => image/user/db/settings_v2_002.sql +6 -1
@@ 28,5 28,10 @@ INSERT OR IGNORE INTO settings_tab (path, value) VALUES
    ('bt_device_visibility', '0'),
    ('bt_device_name', 'PurePhone'),
    ('bt_bonded_devices', ''),
    ('battery_critical_level', '0');
    ('battery_critical_level', '0'),
    ('cl_offline_mode', '0'),
    ('off_connection_frequency', '0'),
    ('off_notifications_when_locked', '0'),
    ('off_calls_from_favorites', '0');



M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +79 -0
@@ 37,6 37,10 @@
#include "windows/ChangeTimeZone.hpp"
#include "windows/ChangeDateAndTimeWindow.hpp"
#include <application-settings-new/models/QuotesRepository.hpp>
#include "windows/PhoneModesWindow.hpp"
#include "windows/DoNotDisturbWindow.hpp"
#include "windows/OfflineWindow.hpp"
#include "windows/ConnectionFrequencyWindow.hpp"

#include "Dialog.hpp"
#include "DialogMetadataMessage.hpp"


@@ 349,6 353,23 @@ namespace app
            [this](std::string value) { usbSecured = utils::getNumericValue<bool>(value); },
            ::settings::SettingsScope::Global);
        */
        settings->registerValueChange(
            ::settings::Cellular::offlineMode,
            [this](const std::string &value) { flightModeOn = utils::getNumericValue<bool>(value); },
            ::settings::SettingsScope::Global);

        settings->registerValueChange(
            ::settings::Offline::callsFromFavorites,
            [this](const std::string &value) { callsFromFavorites = utils::getNumericValue<bool>(value); },
            ::settings::SettingsScope::Global);
        settings->registerValueChange(
            ::settings::Offline::connectionFrequency,
            [this](const std::string &value) { utils::toNumeric(value, connectionFrequency); },
            ::settings::SettingsScope::Global);
        settings->registerValueChange(
            ::settings::Offline::notificationsWhenLocked,
            [this](const std::string &value) { notificationsWhenLocked = utils::getNumericValue<bool>(value); },
            ::settings::SettingsScope::Global);

        return ret;
    }


@@ 473,6 494,19 @@ namespace app
        });

        attachPopups({gui::popup::ID::Volume});
        windowsFactory.attach(gui::window::name::phone_modes, [](Application *app, const std::string &name) {
            return std::make_unique<gui::PhoneModesWindow>(
                app, static_cast<ApplicationSettingsNew *>(app), static_cast<ApplicationSettingsNew *>(app));
        });
        windowsFactory.attach(gui::window::name::do_not_disturb, [](Application *app, const std::string &name) {
            return std::make_unique<gui::DoNotDisturbWindow>(app, static_cast<ApplicationSettingsNew *>(app));
        });
        windowsFactory.attach(gui::window::name::offline, [](Application *app, const std::string &name) {
            return std::make_unique<gui::OfflineWindow>(app, static_cast<ApplicationSettingsNew *>(app));
        });
        windowsFactory.attach(gui::window::name::connection_frequency, [](Application *app, const std::string &name) {
            return std::make_unique<gui::ConnectionFrequencyWindow>(app, static_cast<ApplicationSettingsNew *>(app));
        });
    }

    void ApplicationSettingsNew::destroyUserInterface()


@@ 624,4 658,49 @@ namespace app
        settings->setValue(
            ::settings::SystemProperties::usbSecurity, std::to_string(security), ::settings::SettingsScope::Global);
    }

    auto ApplicationSettingsNew::getNotificationsWhenLocked() const noexcept -> bool
    {
        return notificationsWhenLocked;
    }
    void ApplicationSettingsNew::setNotificationsWhenLocked(bool on) noexcept
    {
        notificationsWhenLocked = on;
        settings->setValue(
            ::settings::Offline::notificationsWhenLocked, std::to_string(on), ::settings::SettingsScope::Global);
    }
    auto ApplicationSettingsNew::getCallsFromFavourite() const noexcept -> bool
    {
        return callsFromFavorites;
    }
    void ApplicationSettingsNew::setCallsFromFavourite(bool on) noexcept
    {
        callsFromFavorites = on;
        settings->setValue(
            ::settings::Offline::callsFromFavorites, std::to_string(on), ::settings::SettingsScope::Global);
    }

    auto ApplicationSettingsNew::isFlightMode() const noexcept -> bool
    {
        return flightModeOn;
    }

    void ApplicationSettingsNew::setFlightMode(bool flightModeOn) noexcept
    {
        this->flightModeOn = flightModeOn;
        CellularServiceAPI::SetFlightMode(this, flightModeOn);
    }

    auto ApplicationSettingsNew::getConnectionFrequency() const noexcept -> uint8_t
    {
        return connectionFrequency;
    }

    void ApplicationSettingsNew::setConnectionFrequency(uint8_t val) noexcept
    {
        connectionFrequency = val;
        settings->setValue(
            ::settings::Offline::connectionFrequency, std::to_string(val), ::settings::SettingsScope::Global);
    }

} /* namespace app */

M module-apps/application-settings-new/ApplicationSettings.hpp => module-apps/application-settings-new/ApplicationSettings.hpp +49 -1
@@ 65,6 65,10 @@ namespace gui::window::name
    inline constexpr auto new_apn = "NewApn";
    inline constexpr auto bluetooth_check_passkey = "BluetoothCheckPasskey";

    inline constexpr auto do_not_disturb       = "DoNotDisturb";
    inline constexpr auto offline              = "Offline";
    inline constexpr auto connection_frequency = "ConnectionFrequency";

} // namespace gui::window::name

namespace app


@@ 124,6 128,32 @@ namespace app
            virtual void setUSBSecurity(bool security) = 0;
        };

        class DndSettings
        {
          public:
            virtual ~DndSettings() = default;

            virtual auto getNotificationsWhenLocked() const noexcept -> bool = 0;
            virtual void setNotificationsWhenLocked(bool on) noexcept        = 0;
            virtual auto getCallsFromFavourite() const noexcept -> bool      = 0;
            virtual void setCallsFromFavourite(bool on) noexcept             = 0;
        };

        class ConnectionSettings
        {
          public:
            virtual ~ConnectionSettings() = default;

            virtual auto getConnectionFrequency() const noexcept -> uint8_t = 0;
            virtual void setConnectionFrequency(uint8_t val) noexcept       = 0;
        };

        class OfflineSettings
        {
          public:
            virtual auto isFlightMode() const noexcept -> bool     = 0;
            virtual void setFlightMode(bool flightModeOn) noexcept = 0;
        };
    }; // namespace settingsInterface

    class ApplicationSettingsNew : public app::Application,


@@ 131,7 161,10 @@ namespace app
                                   public settingsInterface::OperatorsSettings,
                                   public settingsInterface::ScreenLightSettings,
                                   public settingsInterface::KeypdBacklightSettings,
                                   public settingsInterface::SecuritySettings
                                   public settingsInterface::SecuritySettings,
                                   public settingsInterface::DndSettings,
                                   public settingsInterface::OfflineSettings,
                                   public settingsInterface::ConnectionSettings
    {
      public:
        ApplicationSettingsNew(std::string name                    = name_settings_new,


@@ 179,6 212,17 @@ namespace app
        void setLockScreenPasscodeOn(bool passcodeOn);
        auto isLockScreenPasscodeOn() const -> bool;

        auto getNotificationsWhenLocked() const noexcept -> bool override;
        void setNotificationsWhenLocked(bool on) noexcept override;
        auto getCallsFromFavourite() const noexcept -> bool override;
        void setCallsFromFavourite(bool on) noexcept override;

        auto isFlightMode() const noexcept -> bool override;
        void setFlightMode(bool flightModeOn) noexcept override;

        auto getConnectionFrequency() const noexcept -> uint8_t override;
        void setConnectionFrequency(uint8_t val) noexcept override;

      private:
        void attachQuotesWindows();



@@ 190,6 234,10 @@ namespace app
        bool usbSecured               = true;
        bool lockScreenPasscodeOn     = true;
        unsigned int lockPassHash     = 0;
        bool notificationsWhenLocked  = true;
        bool callsFromFavorites       = false;
        int connectionFrequency       = 0;
        bool flightModeOn             = true;
    };

    template <> struct ManifestTraits<ApplicationSettingsNew>

M module-apps/application-settings-new/CMakeLists.txt => module-apps/application-settings-new/CMakeLists.txt +4 -0
@@ 66,6 66,10 @@ target_sources( ${PROJECT_NAME}
        windows/BluetoothCheckPasskeyWindow.cpp
        windows/EditQuotesWindow.cpp
        windows/QuoteCategoriesWindow.cpp
        windows/ConnectionFrequencyWindow.cpp
        windows/DoNotDisturbWindow.cpp
        windows/OfflineWindow.cpp
        windows/PhoneModesWindow.cpp

    PUBLIC
        ApplicationSettings.hpp

M module-apps/application-settings-new/widgets/SettingsStyle.hpp => module-apps/application-settings-new/widgets/SettingsStyle.hpp +12 -0
@@ 116,6 116,18 @@ namespace style
                    } // namespace text
                }     // namespace passkey
            }         // namespace bluetooth

            namespace offline
            {
                inline constexpr auto body_offset = 155;

                inline constexpr auto bar_y = 396;
                inline constexpr auto bar_h = 1;

                inline constexpr auto description_y = 375;
                inline constexpr auto description_h = 150;
            } // namespace offline

        }     // namespace window
    };        // namespace settings
    namespace quotes::categories

A module-apps/application-settings-new/windows/ConnectionFrequencyWindow.cpp => module-apps/application-settings-new/windows/ConnectionFrequencyWindow.cpp +63 -0
@@ 0,0 1,63 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ConnectionFrequencyWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "OptionSetting.hpp"
#include <i18n/i18n.hpp>

namespace gui
{
    ConnectionFrequencyWindow::ConnectionFrequencyWindow(app::Application *app,
                                                         app::settingsInterface::ConnectionSettings *connectionSettings)
        : BaseSettingsWindow(app, gui::window::name::connection_frequency), connectionSettings(connectionSettings)
    {}
    void ConnectionFrequencyWindow::onBeforeShow(ShowMode m, SwitchData *d)
    {
        rebuild();
    }
    auto ConnectionFrequencyWindow::buildOptionsList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optList;
        std::vector<uint8_t> frequency{0, 15, 30, 45, 60};

        auto intervalText = [](uint8_t value) {
            if (value == 0) {
                return utils::localize.get("app_alarm_clock_repeat_never");
            }
            const std::string toReplace = "%0";
            std::string temp            = utils::translateI18("app_meditation_interval_every_x_minutes");
            temp.replace(temp.find(toReplace), toReplace.size(), std::to_string(value));
            return temp;
        };

        for (auto freq : frequency) {
            optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                intervalText(freq),
                [=](gui::Item &item) {
                    updateInterval(freq);
                    return true;
                },
                nullptr,
                nullptr,
                (freq == connectionSettings->getConnectionFrequency()) ? option::SettingRightItem::Checked
                                                                       : option::SettingRightItem::Disabled));
        }

        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::select));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));

        return optList;
    }
    void ConnectionFrequencyWindow::rebuild()
    {
        clearOptions();
        addOptions(buildOptionsList());
    }
    void ConnectionFrequencyWindow::updateInterval(uint8_t value)
    {
        connectionSettings->setConnectionFrequency(value);
        refreshOptionsList();
    }

} // namespace gui

A module-apps/application-settings-new/windows/ConnectionFrequencyWindow.hpp => module-apps/application-settings-new/windows/ConnectionFrequencyWindow.hpp +34 -0
@@ 0,0 1,34 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "BaseSettingsWindow.hpp"

namespace app::settingsInterface
{
    class ConnectionSettings;
}; // namespace app::settingsInterface

namespace gui
{

    namespace window
    {
        inline constexpr auto connection_frequency_window = "ConnectionFrequency";
    };

    class ConnectionFrequencyWindow : public BaseSettingsWindow
    {
      private:
        auto buildOptionsList() -> std::list<gui::Option> override;
        void rebuild() override;
        app::settingsInterface::ConnectionSettings *connectionSettings;
        void updateInterval(uint8_t value);

      public:
        ConnectionFrequencyWindow(app::Application *app,
                                  app::settingsInterface::ConnectionSettings *connectionSettings);
        void onBeforeShow(ShowMode m, SwitchData *d) override;
    };
} // namespace gui

A module-apps/application-settings-new/windows/DoNotDisturbWindow.cpp => module-apps/application-settings-new/windows/DoNotDisturbWindow.cpp +72 -0
@@ 0,0 1,72 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "DoNotDisturbWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/widgets/SettingsStyle.hpp"

#include "OptionSetting.hpp"

#include <i18n/i18n.hpp>

namespace gui
{
    DoNotDisturbWindow::DoNotDisturbWindow(app::Application *app, app::settingsInterface::DndSettings *dndSettings)
        : BaseSettingsWindow(app, gui::window::name::do_not_disturb), dndSettings(dndSettings)
    {
        buildInterface();
    }

    void DoNotDisturbWindow::buildInterface()
    {
        setTitle(utils::translateI18("app_settings_title_do_not_disturb"));
        optionsList->setSize(optionsList->getWidth(),
                             optionsList->getHeight() - style::settings::window::offline::body_offset);
        bar = new Rect(this,
                       style::window::default_left_margin,
                       style::settings::window::offline::bar_y,
                       style::window::default_body_width,
                       style::settings::window::offline::bar_h);
        bar->setVisible(true);
        descriptionText = new Text(this,
                                   style::window::default_left_margin,
                                   style::settings::window::offline::description_y,
                                   style::window::default_body_width,
                                   style::settings::window::offline::description_h);
        descriptionText->setFont(style::window::font::medium);
        descriptionText->setText(utils::translateI18("app_settings_info_dnd"));
        descriptionText->setVisible(true);
    }

    auto DoNotDisturbWindow::buildOptionsList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optList;
        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_notifications_when_locked"),
            [=](gui::Item &item) {
                dndSettings->setNotificationsWhenLocked(!dndSettings->getNotificationsWhenLocked());
                refreshOptionsList();
                return true;
            },
            nullptr,
            this,
            (dndSettings->getNotificationsWhenLocked()) ? gui::option::SettingRightItem::On
                                                        : gui::option::SettingRightItem::Off));

        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_calls_from_favorites"),
            [=](gui::Item &item) {
                dndSettings->setCallsFromFavourite(!dndSettings->getCallsFromFavourite());
                refreshOptionsList();
                return true;
            },
            nullptr,
            this,
            (dndSettings->getCallsFromFavourite()) ? gui::option::SettingRightItem::On
                                                   : gui::option::SettingRightItem::Off));

        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::Switch));
        return optList;
    }
} // namespace gui

A module-apps/application-settings-new/windows/DoNotDisturbWindow.hpp => module-apps/application-settings-new/windows/DoNotDisturbWindow.hpp +35 -0
@@ 0,0 1,35 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "BaseSettingsWindow.hpp"

#include <Text.hpp>

namespace app::settingsInterface
{
    class DndSettings;
} // namespace app::settingsInterface

namespace gui
{

    namespace window
    {
        inline constexpr auto do_not_disturb_window = "DoNotDisturb";
    };

    class DoNotDisturbWindow : public BaseSettingsWindow
    {
      public:
        DoNotDisturbWindow(app::Application *app, app::settingsInterface::DndSettings *dndSettings);
        void buildInterface() override;

      private:
        app::settingsInterface::DndSettings *dndSettings = nullptr;
        Rect *bar                                        = nullptr;
        Text *descriptionText                            = nullptr;
        auto buildOptionsList() -> std::list<Option> override;
    };
} // namespace gui

A module-apps/application-settings-new/windows/OfflineWindow.cpp => module-apps/application-settings-new/windows/OfflineWindow.cpp +87 -0
@@ 0,0 1,87 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "OfflineWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "application-settings-new/widgets/SettingsStyle.hpp"

#include "OptionSetting.hpp"

#include <i18n/i18n.hpp>

namespace gui
{

    OfflineWindow::OfflineWindow(app::Application *app, app::settingsInterface::OfflineSettings *offlineSettings)
        : BaseSettingsWindow(app, gui::window::name::offline), offlineSettings(offlineSettings)
    {
        isFlightMode = offlineSettings->isFlightMode();
        buildInterface();
    }

    void OfflineWindow::buildInterface()
    {
        setTitle(utils::translateI18("app_settings_title_offline"));
        optionsList->setSize(optionsList->getWidth(),
                             optionsList->getHeight() - style::settings::window::offline::body_offset);

        bar = new Rect(this,
                       style::window::default_left_margin,
                       style::settings::window::offline::bar_y,
                       style::window::default_body_width,
                       style::settings::window::offline::bar_h);
        bar->setVisible(true);
        descriptionText = new Text(this,
                                   style::window::default_left_margin,
                                   style::settings::window::offline::description_y,
                                   style::window::default_body_width,
                                   style::settings::window::offline::description_h);
        descriptionText->setFont(style::window::font::medium);
        descriptionText->setText(utils::translateI18(isFlightMode ? "app_settings_info_offline_flight_mode"
                                                                  : "app_settings_info_offline_messages_only"));
        descriptionText->setVisible(true);
    }

    auto OfflineWindow::buildOptionsList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optList;
        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_allow"),
            [=](gui::Item &item) { return changeFlightMode(!isFlightMode); },
            nullptr,
            nullptr,
            gui::option::SettingRightItem::Text,
            false,
            utils::translateI18(isFlightMode ? "app_settings_no_network_connection_flight_mode"
                                             : "app_settings_messages_only"),
            false));

        if (!isFlightMode) {
            optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                utils::translateI18("app_settings_title_connection_frequency"),
                [=](gui::Item &item) {
                    this->application->switchWindow(gui::window::name::connection_frequency, nullptr);
                    return true;
                },
                nullptr,
                nullptr,
                gui::option::SettingRightItem::ArrowWhite));
        }

        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::Switch));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));

        return optList;
    }

    bool OfflineWindow::changeFlightMode(bool isFlightMode)
    {
        this->isFlightMode = isFlightMode;
        offlineSettings->setFlightMode(isFlightMode);
        descriptionText->setText(utils::translateI18(isFlightMode ? "app_settings_info_offline_flight_mode"
                                                                  : "app_settings_info_offline_messages_only"));
        rebuildOptionList();
        return true;
    }

} // namespace gui

A module-apps/application-settings-new/windows/OfflineWindow.hpp => module-apps/application-settings-new/windows/OfflineWindow.hpp +31 -0
@@ 0,0 1,31 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "BaseSettingsWindow.hpp"

#include <Text.hpp>

namespace app::settingsInterface
{
    class OfflineSettings;
} // namespace app::settingsInterface

namespace gui
{
    class OfflineWindow : public BaseSettingsWindow
    {
      public:
        OfflineWindow(app::Application *app, app::settingsInterface::OfflineSettings *offlineSettings);
        void buildInterface() override;

      private:
        app::settingsInterface::OfflineSettings *offlineSettings;
        Rect *bar             = nullptr;
        Text *descriptionText = nullptr;
        auto buildOptionsList() -> std::list<Option> override;
        bool changeFlightMode(bool isFlightMode);
        bool isFlightMode = true;
    };
}; // namespace gui

A module-apps/application-settings-new/windows/PhoneModesWindow.cpp => module-apps/application-settings-new/windows/PhoneModesWindow.cpp +79 -0
@@ 0,0 1,79 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PhoneModesWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"

#include "OptionSetting.hpp"

#include <i18n/i18n.hpp>

namespace gui
{
    PhoneModesWindow::PhoneModesWindow(app::Application *app,
                                       app::settingsInterface::SimParams *simParams,
                                       app::settingsInterface::OperatorsSettings *operatorsSettings)
        : OptionWindow(app, gui::window::name::phone_modes), simParams(simParams), operatorsSettings(operatorsSettings)
    {}
    void PhoneModesWindow::onBeforeShow(ShowMode m, SwitchData *d)
    {
        rebuild();
    }
    auto PhoneModesWindow::modesOptList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optList;

        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_connected"),
            [=](gui::Item &item) { return true; },
            [=](gui::Item &item) {
                if (item.focus) {
                    this->clearBottomBarText(BottomBar::Side::CENTER);
                }
                return true;
            },
            this));

        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_title_do_not_disturb"),
            [=](gui::Item &item) {
                this->application->switchWindow(gui::window::name::do_not_disturb, nullptr);
                return true;
            },
            [=](gui::Item &item) {
                if (item.focus) {
                    this->setBottomBarText(utils::localize.get(style::strings::common::adjust),
                                           BottomBar::Side::CENTER);
                }
                return true;
            },
            this,
            gui::option::SettingRightItem::ArrowWhite));

        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translateI18("app_settings_title_offline"),
            [=](gui::Item &item) {
                this->application->switchWindow(gui::window::name::offline, nullptr);
                return true;
            },
            [=](gui::Item &item) {
                if (item.focus) {
                    this->setBottomBarText(utils::localize.get(style::strings::common::adjust),
                                           BottomBar::Side::CENTER);
                }
                return true;
            },
            this,
            gui::option::SettingRightItem::ArrowWhite));

        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));

        return optList;
    }
    void PhoneModesWindow::rebuild()
    {
        clearOptions();
        addOptions(modesOptList());
    }

} // namespace gui

A module-apps/application-settings-new/windows/PhoneModesWindow.hpp => module-apps/application-settings-new/windows/PhoneModesWindow.hpp +37 -0
@@ 0,0 1,37 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "OptionWindow.hpp"
#include "Application.hpp"

namespace app::settingsInterface
{
    class SimParams;
    class OperatorsSettings;
}; // namespace app::settingsInterface

namespace gui
{

    namespace window
    {
        inline constexpr auto phone_modes_window = "PhoneModes";
    };

    class PhoneModesWindow : public OptionWindow
    {
      private:
        auto modesOptList() -> std::list<gui::Option>;
        app::settingsInterface::SimParams *simParams;
        void rebuild() override;
        app::settingsInterface::OperatorsSettings *operatorsSettings;

      public:
        PhoneModesWindow(app::Application *app,
                         app::settingsInterface::SimParams *simParams,
                         app::settingsInterface::OperatorsSettings *operatorsSettings);
        void onBeforeShow(ShowMode m, SwitchData *d) override;
    };
} // namespace gui

M module-apps/options/OptionStyle.hpp => module-apps/options/OptionStyle.hpp +1 -0
@@ 39,6 39,7 @@ namespace gui::option
        inline constexpr gui::Length option_right_margin = 10;
        inline constexpr gui::Length option_bottom_margin  = style::margins::big;
        inline constexpr gui::Length option_right_min_size = 150;
        inline constexpr gui::Length option_rightbig_min_size = 350;
        inline constexpr uint32_t optionsListTopMargin   = 10U;
        inline constexpr uint32_t optionsListX           = style::window::default_left_margin;
        inline constexpr uint32_t optionsListY           = style::header::height + optionsListTopMargin;

M module-apps/options/type/OptionSetting.cpp => module-apps/options/type/OptionSetting.cpp +5 -2
@@ 59,11 59,14 @@ namespace gui::option
        case SettingRightItem::Text: {
            auto optionTextRight = new TextFixedSize(optionBodyHBox, 0, 0, 0, 0);
            optionTextRight->setUnderline(false);
            optionTextRight->setMinimumSize(gui::option::window::option_right_min_size, style::window::label::big_h);
            optionTextRight->setMinimumSize((textOnRightIsSmall) ? gui::option::window::option_right_min_size
                                                                 : gui::option::window::option_rightbig_min_size,
                                            style::window::label::big_h);
            optionTextRight->setAlignment(
                gui::Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
            optionTextRight->setMargins(Margins(0, 0, window::option_right_margin, 0));
            optionTextRight->setFont(style::window::font::medium);
            optionTextRight->setFont((textOnRightIsSmall) ? style::window::font::medium
                                                          : style::window::font::verysmall);
            optionTextRight->setRichText(textOnRight);
            break;
        }

M module-apps/options/type/OptionSetting.hpp => module-apps/options/type/OptionSetting.hpp +4 -2
@@ 18,6 18,7 @@ namespace gui::option
        SettingRightItem rightItem                       = SettingRightItem::Disabled;
        bool indent                                      = false;
        UTF8 textOnRight;
        bool textOnRightIsSmall = true;

      public:
        OptionSettings(UTF8 text,


@@ 26,10 27,11 @@ namespace gui::option
                       AppWindow *app,
                       SettingRightItem rightItem = SettingRightItem::Disabled,
                       bool indent                = false,
                       UTF8 textOnRight           = UTF8())
                       UTF8 textOnRight           = UTF8(),
                       bool textOnRightIsSmall    = true)
            : text(std::move(text)), activatedCallback(std::move(activatedCallback)),
              focusChangedCallback(std::move(focusChangedCallback)), app(app), rightItem(rightItem), indent(indent),
              textOnRight(std::move(textOnRight))
              textOnRight(std::move(textOnRight)), textOnRightIsSmall(textOnRightIsSmall)
        {}
        [[nodiscard]] auto build() const -> ListItem * override;
        [[nodiscard]] auto str() const -> std::string override

M module-gui/gui/widgets/Style.hpp => module-gui/gui/widgets/Style.hpp +1 -0
@@ 165,6 165,7 @@ namespace style
            inline constexpr auto accept         = "common_accept";
            inline constexpr auto retry          = "common_retry";
            inline constexpr auto abort          = "common_abort";
            inline constexpr auto adjust         = "common_adjust";
            // days
            inline constexpr auto Monday    = "common_monday";
            inline constexpr auto Tuesday   = "common_tuesday";

M module-services/service-cellular/CellularServiceAPI.cpp => module-services/service-cellular/CellularServiceAPI.cpp +6 -0
@@ 341,3 341,9 @@ bool CellularServiceAPI::ChangeModulePowerState(sys::Service *serv, cellular::St
{
    return serv->bus.sendUnicast(std::make_shared<CellularPowerStateChange>(newState), ServiceCellular::serviceName);
}

bool CellularServiceAPI::SetFlightMode(sys::Service *serv, bool flightModeOn)
{
    return serv->bus.sendUnicast(std::make_shared<CellularSetFlightModeMessage>(flightModeOn),
                                 ServiceCellular::serviceName);
}

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +13 -0
@@ 403,6 403,11 @@ void ServiceCellular::registerMessageHandlers()
        return std::make_shared<CellularResponseMessage>(true);
    });

    connect(typeid(CellularSetFlightModeMessage), [&](sys::Message *request) -> sys::MessagePointer {
        auto msg = static_cast<CellularSetFlightModeMessage *>(request);
        return handleCellularSetFlightModeMessage(msg);
    });

    connect(typeid(CellularPowerStateChange), [&](sys::Message *request) -> sys::MessagePointer {
        auto msg       = static_cast<CellularPowerStateChange *>(request);
        nextPowerState = msg->getNewState();


@@ 2503,3 2508,11 @@ auto ServiceCellular::handleSimNotReadyNotification(sys::Message *msg) -> std::s
{
    return std::make_shared<CellularResponseMessage>(false);
}

auto ServiceCellular::handleCellularSetFlightModeMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>
{
    auto setMsg = static_cast<CellularSetFlightModeMessage *>(msg);
    settings->setValue(
        settings::Cellular::offlineMode, std::to_string(setMsg->flightModeOn), settings::SettingsScope::Global);
    return std::make_shared<CellularResponseMessage>(true);
}

M module-services/service-cellular/service-cellular/CellularMessage.hpp => module-services/service-cellular/service-cellular/CellularMessage.hpp +9 -0
@@ 925,6 925,15 @@ class CellularGetAntennaMessage : public CellularMessage
    {}
};

class CellularSetFlightModeMessage : public CellularMessage
{
  public:
    explicit CellularSetFlightModeMessage(bool flightModeOn)
        : CellularMessage(MessageType::CellularSetFlightMode), flightModeOn(flightModeOn)
    {}
    bool flightModeOn;
};

class CellularCallActiveNotification : public CellularNotificationMessage
{
  public:

M module-services/service-cellular/service-cellular/CellularServiceAPI.hpp => module-services/service-cellular/service-cellular/CellularServiceAPI.hpp +2 -0
@@ 140,4 140,6 @@ namespace CellularServiceAPI

    bool ChangeModulePowerState(sys::Service *serv, cellular::State::PowerState newState);

    bool SetFlightMode(sys::Service *serv, bool flightModeOn);

}; // namespace CellularServiceAPI

M module-services/service-cellular/service-cellular/ServiceCellular.hpp => module-services/service-cellular/service-cellular/ServiceCellular.hpp +2 -0
@@ 361,6 361,8 @@ class ServiceCellular : public sys::Service
    auto handleSignalStrengthUpdateNotification(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleNetworkStatusUpdateNotification(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
    auto handleSimNotReadyNotification(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;

    auto handleCellularSetFlightModeMessage(sys::Message *msg) -> std::shared_ptr<sys::ResponseMessage>;
};

namespace sys

M module-services/service-db/agents/settings/SystemSettings.hpp => module-services/service-db/agents/settings/SystemSettings.hpp +8 -0
@@ 44,6 44,7 @@ namespace settings
    {
        constexpr inline auto volte_on = "cl_volte_on";
        constexpr inline auto apn_list = "cl_apn_list";
        constexpr inline auto offlineMode = "cl_offline_mode";
    } // namespace Cellular

    namespace Battery


@@ 51,4 52,11 @@ namespace settings
        constexpr inline auto batteryCriticalLevel = "battery_critical_level";
    } // namespace Battery

    namespace Offline
    {
        constexpr inline auto connectionFrequency     = "off_connection_frequency";
        constexpr inline auto notificationsWhenLocked = "off_notifications_when_locked";
        constexpr inline auto callsFromFavorites      = "off_calls_from_favorites";
    } // namespace Offline

}; // namespace settings

M source/MessageType.hpp => source/MessageType.hpp +1 -0
@@ 83,6 83,7 @@ enum class MessageType
    CellularSimResponse,         // Send to PIN window (show, error state, hide)
    CellularSimVerifyPinRequest, // Send from PIN window with PIN, PUK, ... number
    CellularSetVoLTE,
    CellularSetFlightMode,

    CellularPacketData, ///< for all PacketData messages