SYNCML_DM_TextInputAlert.cc revision 3fa3e56afc259ce982ca4f8b51be7378b7e2021e
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17/*================================================================================================== 18 19 File Name: SYNCML_DM_TextInputAlert.cc 20 21 General Description: A class representing the alerts. 22 23==================================================================================================*/ 24 25#include "SYNCML_DM_TextInputAlert.H" 26#include "dmStringUtil.h" 27#include "dmtoken.h" 28 29 30SYNCML_DM_TextInputAlert::SYNCML_DM_TextInputAlert() 31{ 32 maxLength = 20; 33 inputType = XPL_DM_ALERT_I_ALPHA; 34 echoType = XPL_DM_ALERT_E_TEXT; 35 response.action = XPL_DM_ALERT_RES_TIMEOUT; 36} 37 38 39void SYNCML_DM_TextInputAlert::processParameter(CPCHAR name, CPCHAR value) 40{ 41 if ( DmStrcmp(name,SYNCML_DM_ALERT_OPTION_MAXDT) == 0 ) 42 setMaxDisplayTime(DmAtoi(value)); 43 else 44 if ( DmStrcmp(name,SYNCML_DM_ALERT_OPTION_DEFAULT_RESPONSE) == 0 ) 45 defaultResponse = value; 46 else 47 if ( DmStrcmp(name,SYNCML_DM_ALERT_OPTION_MAX_LENGTH) == 0 ) 48 maxLength = DmAtoi(value); 49 else 50 if ( DmStrcmp(name,SYNCML_DM_ALERT_OPTION_INPUT_TYPE) == 0 ) 51 inputType = convertInputType(value); 52 else 53 if ( DmStrcmp(name,SYNCML_DM_ALERT_OPTION_ECHO_TYPE) == 0 ) 54 echoType = convertEchoType(value); 55} 56 57 58SYNCML_DM_RET_STATUS_T SYNCML_DM_TextInputAlert::show() 59{ 60 61 SYNCML_DM_RET_STATUS_T ret_status; 62 63 defaultResponse.replaceAll('+',' '); 64 ret_status = XPL_DM_ShowTextInputAlert(maxDisplayTime, msg,defaultResponse, 65 maxLength, inputType, echoType, &response ); 66 67 defaultResponse.replaceAll(' ','+'); 68 if ( ret_status == SYNCML_DM_SUCCESS ) 69 { 70 response.response.replaceAll(' ','+'); 71 } 72 73 return ret_status; 74} 75 76XPL_DM_ALERT_RES_T SYNCML_DM_TextInputAlert::getAction() const 77{ 78 return response.action; 79} 80 81 82SYNCML_DM_RET_STATUS_T 83SYNCML_DM_TextInputAlert::getDefaultResponse(DMStringVector & userResponse) const 84{ 85 userResponse.push_back(defaultResponse); 86 return SYNCML_DM_SUCCESS; 87} 88 89SYNCML_DM_RET_STATUS_T 90SYNCML_DM_TextInputAlert::getResponse(DMStringVector & userResponse) const 91{ 92 userResponse.push_back(response.response); 93 return SYNCML_DM_SUCCESS; 94} 95 96 97XPL_DM_ALERT_INPUT_T SYNCML_DM_TextInputAlert::convertInputType(CPCHAR inputType) { 98 99 if (DmStrcmp(inputType,SYNCML_DM_ALERT_OPTION_IT_A) == 0) 100 { 101 return XPL_DM_ALERT_I_ALPHA; 102 } 103 else 104 if (DmStrcmp(inputType,SYNCML_DM_ALERT_OPTION_IT_N) == 0) 105 { 106 return XPL_DM_ALERT_I_NUMERIC; 107 } 108 else 109 if (DmStrcmp(inputType,SYNCML_DM_ALERT_OPTION_IT_D) == 0) 110 { 111 return XPL_DM_ALERT_I_DATE; 112 } 113 else 114 if (DmStrcmp(inputType,SYNCML_DM_ALERT_OPTION_IT_T) == 0) 115 { 116 return XPL_DM_ALERT_I_TIME; 117 } 118 else 119 if (DmStrcmp(inputType,SYNCML_DM_ALERT_OPTION_IT_P) == 0) 120 { 121 return XPL_DM_ALERT_I_PHONE_NUM; 122 } 123 else 124 if (DmStrcmp(inputType,SYNCML_DM_ALERT_OPTION_IT_I) == 0) 125 { 126 return XPL_DM_ALERT_I_IP_ADDR; 127 } 128 return XPL_DM_ALERT_I_ALPHA; 129} 130 131XPL_DM_ALERT_ECHO_T SYNCML_DM_TextInputAlert::convertEchoType(CPCHAR echoType) { 132 if (DmStrcmp(echoType,SYNCML_DM_ALERT_OPTION_ET_T) == 0) 133 { 134 return XPL_DM_ALERT_E_TEXT; 135 } 136 else { 137 if (DmStrcmp(echoType,SYNCML_DM_ALERT_OPTION_ET_P) == 0) 138 { 139 return XPL_DM_ALERT_E_PASSWD; 140 } 141 } 142 return XPL_DM_ALERT_E_TEXT; 143} 144