#pragma once #include #include #include "dialog_model.h" #include "event_bus.h" #include "key_event.h" #include "line_editor.h" #include "list_model.h" #include "saved_networks.h" #include "services/wifi_service.h" #include "settings.h" #include "ui/canvas.h" #include "ui/theme.h" namespace roro { // Settings → Wi-Fi: the On/Off switch, the connection and its details, DNS and NTP servers, and // the Saved Networks: adding one from a scan or by name (hidden), and each one's own page with its // IP setting, Automatic or Fixed (docs/milestones/S1.md, Q113). Owned by the Settings App. class WifiSettingsPage { public: WifiSettingsPage(Settings& settings, SavedNetworks& saved, WifiService& wifi, EventBus& bus) : settings_(settings), saved_(saved), wifi_(wifi), bus_(bus) {} void enter(); bool onKey(const KeyEvent& e); // false: leave the page bool textEntryActive() const { return view_ == View::Ssid || view_ == View::Password || view_ == View::Edit; } // Redraw periodically: the status, a scan, the connection details. bool live() const { return view_ == View::Main || view_ == View::Scan || view_ == View::Details; } void draw(Canvas& c); private: enum class View { Main, Scan, Ssid, Password, Details, Servers, Network, Edit }; enum Fixed { kToggle, kStatus, kServers, kAddScanned, kAddHidden, kFixedRows }; enum ServerRow { kDns1, kDns2, kDnsAlways, kNtp1, kNtp2, kServerRows }; // A Saved Network's page: with Automatic, only kIpMode and kForget are shown. enum NetworkRow { kIpMode, kAddress, kPrefix, kGateway, kForget }; enum class Field { Address, Prefix, Gateway, Dns1, Dns2, Ntp1, Ntp2 }; void refreshMain(); void warn(const std::string& text, NotificationLevel level = NotificationLevel::Warning); std::string statusText() const; bool mainKey(const KeyEvent& e); bool serversKey(const KeyEvent& e); bool networkKey(const KeyEvent& e); bool editKey(const KeyEvent& e); void openNetwork(const SavedNetwork& n); bool leaveNetwork(); // checks and applies the draft; false (with a Toast) when it's refused NetworkRow networkRow(int i) const; void edit(Field field, const std::string& title, const std::string& value, View from); void drawDetails(Canvas& c); Settings& settings_; SavedNetworks& saved_; WifiService& wifi_; EventBus& bus_; View view_ = View::Main; ListModel main_{theme::kContent.h / theme::kLineHeight}; ListModel scan_{theme::kContent.h / theme::kLineHeight}; ListModel servers_{theme::kContent.h / theme::kLineHeight}; ListModel network_{theme::kContent.h / theme::kLineHeight - 1}; LineEditor editor_{63}; std::string newSsid_; bool newHidden_ = false; std::unique_ptr forgetDialog_; // The Saved Network whose page is open, and its IP setting as being typed (a draft: applied on // leaving the page, so a half-typed address is never used). std::string netSsid_; bool draftFixed_ = false; std::string draftAddress_, draftPrefix_, draftGateway_; // The field being edited, and where Enter and Back return to. Field field_ = Field::Address; std::string editTitle_; View editFrom_ = View::Main; }; } // namespace roro