1 /* 2 * Copyright (C) 2005-2018 Team Kodi 3 * This file is part of Kodi - https://kodi.tv 4 * 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 * See LICENSES/README.md for more information. 7 */ 8 9 #pragma once 10 11 #include "XBDateTime.h" 12 #include "guilib/GUIDialog.h" 13 14 #include <cstdint> 15 16 enum class InputVerificationResult 17 { 18 CANCELED, 19 FAILED, 20 SUCCESS 21 }; 22 23 class CGUIDialogNumeric : 24 public CGUIDialog 25 { 26 public: 27 enum INPUT_MODE { INPUT_TIME = 1, INPUT_DATE, INPUT_IP_ADDRESS, INPUT_PASSWORD, INPUT_NUMBER, INPUT_TIME_SECONDS }; 28 CGUIDialogNumeric(void); 29 ~CGUIDialogNumeric(void) override; 30 bool OnMessage(CGUIMessage& message) override; 31 bool OnAction(const CAction &action) override; 32 bool OnBack(int actionID) override; 33 void FrameMove() override; 34 35 bool IsConfirmed() const; 36 bool IsCanceled() const; IsInputHidden()37 bool IsInputHidden() const { return m_mode == INPUT_PASSWORD; }; 38 39 static bool ShowAndVerifyNewPassword(std::string& strNewPassword); 40 static int ShowAndVerifyPassword(std::string& strPassword, const std::string& strHeading, int iRetries); 41 static InputVerificationResult ShowAndVerifyInput(std::string& strPassword, const std::string& strHeading, bool bGetUserInput); 42 43 void SetHeading(const std::string &strHeading); 44 void SetMode(INPUT_MODE mode, const KODI::TIME::SystemTime& initial); 45 void SetMode(INPUT_MODE mode, const std::string &initial); 46 KODI::TIME::SystemTime GetOutput() const; 47 std::string GetOutputString() const; 48 49 static bool ShowAndGetTime(KODI::TIME::SystemTime& time, const std::string& heading); 50 static bool ShowAndGetDate(KODI::TIME::SystemTime& date, const std::string& heading); 51 static bool ShowAndGetIPAddress(std::string &IPAddress, const std::string &heading); 52 static bool ShowAndGetNumber(std::string& strInput, const std::string &strHeading, unsigned int iAutoCloseTimeoutMs = 0, bool bSetHidden = false); 53 static bool ShowAndGetSeconds(std::string& timeString, const std::string &heading); 54 55 protected: 56 void OnInitWindow() override; 57 void OnDeinitWindow(int nextWindowID) override; 58 59 void OnNumber(uint32_t num); 60 void VerifyDate(bool checkYear); 61 void OnNext(); 62 void OnPrevious(); 63 void OnBackSpace(); 64 void OnOK(); 65 void OnCancel(); 66 67 void HandleInputIP(uint32_t num); 68 void HandleInputDate(uint32_t num); 69 void HandleInputSeconds(uint32_t num); 70 void HandleInputTime(uint32_t num); 71 72 bool m_bConfirmed; 73 bool m_bCanceled; 74 75 INPUT_MODE m_mode; // the current input mode 76 KODI::TIME::SystemTime m_datetime; // for time and date modes 77 uint8_t m_ip[4]; // for ip address mode 78 uint32_t m_block; // for time, date, and IP methods. 79 uint32_t m_lastblock; 80 bool m_dirty; // true if the current block has been changed. 81 std::string m_number; ///< for number or password input 82 }; 83