2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/input/tizen-wayland/autofill-group-impl-ecore-wl.h>
22 #include <cstring> // for strcmp
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali/internal/input/tizen-wayland/autofill-manager-impl-ecore-wl.h>
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_AUTOFILL");
46 return Dali::Internal::Adaptor::AutofillGroup::New( "" );
49 Dali::TypeRegistration type( typeid(Dali::AutofillGroup), typeid(Dali::BaseHandle), Create );
51 } // unnamed namespace
54 AutofillGroupEcoreWl::AutofillGroupEcoreWl( const std::string groupId )
55 : mAutofillItemList(),
58 #ifdef CAPI_AUTOFILL_SUPPORT
59 mAutofillGroupHandle = NULL;
60 mAutofillSaveGroupHandle = NULL;
61 #endif // CAPI_AUTOFILL_SUPPORT
64 AutofillGroupEcoreWl::~AutofillGroupEcoreWl()
66 #ifdef CAPI_AUTOFILL_SUPPORT
67 if( mAutofillGroupHandle )
69 autofill_view_info_destroy( mAutofillGroupHandle );
70 mAutofillGroupHandle = NULL;
72 if( mAutofillSaveGroupHandle )
74 autofill_save_view_info_destroy( mAutofillSaveGroupHandle );
75 mAutofillSaveGroupHandle = NULL;
77 #endif // CAPI_AUTOFILL_SUPPORT
81 Dali::AutofillGroup AutofillGroupEcoreWl::New( const std::string& groupId )
83 Dali::Internal::Adaptor::AutofillGroup* group = new Dali::Internal::Adaptor::AutofillGroupEcoreWl( groupId );
84 Dali::AutofillGroup handle = Dali::AutofillGroup( group );
90 void AutofillGroupEcoreWl::Initialize()
92 #ifdef CAPI_AUTOFILL_SUPPORT
93 int ret = autofill_view_info_create( &mAutofillGroupHandle );
94 if( ret != AUTOFILL_ERROR_NONE )
96 DALI_LOG_ERROR( "Failed to create autofill group info handle : %d \n", ret );
100 autofill_view_info_set_view_id( mAutofillGroupHandle, mGroupId.c_str() );
102 #endif // CAPI_AUTOFILL_SUPPORT
105 const std::string& AutofillGroupEcoreWl::GetId() const
107 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::GetId \n" );
111 #ifdef CAPI_AUTOFILL_SUPPORT
112 autofill_view_info_h AutofillGroupEcoreWl::GetAutofillGroupHandle()
114 return mAutofillGroupHandle;
117 autofill_save_view_info_h AutofillGroupEcoreWl::GetAutofillSaveGroupHandle()
119 return mAutofillSaveGroupHandle;
121 #endif // CAPI_AUTOFILL_SUPPORT
123 void AutofillGroupEcoreWl::AddAutofillItem( Dali::AutofillItem item )
125 #ifdef CAPI_AUTOFILL_SUPPORT
126 Internal::Adaptor::AutofillItem& itemImpl = Internal::Adaptor::GetImplementation( item );
127 Internal::Adaptor::AutofillItemEcorewWl& itemImplWl = static_cast<Internal::Adaptor::AutofillItemEcorewWl&>( itemImpl );
129 if( mAutofillGroupHandle && itemImplWl.GetAutofillItemHandle() )
131 autofill_view_info_add_item( mAutofillGroupHandle, itemImplWl.GetAutofillItemHandle() );
133 #endif // CAPI_AUTOFILL_SUPPORT
135 // Pushes back an AutofillItem to the ItemList of AutofillGroup.
136 mAutofillItemList.push_back( item );
139 Dali::AutofillItem AutofillGroupEcoreWl::GetAutofillItem( const std::string& id )
141 Dali::AutofillItem item = Dali::AutofillItem();
142 for( std::vector<Dali::AutofillItem>::iterator iter = mAutofillItemList.begin(), endIter = mAutofillItemList.end(); iter != endIter; ++iter )
144 const std::string& itemId = ( *iter ).GetId();
146 if( itemId.compare( id ) == 0 )
154 void AutofillGroupEcoreWl::ClearAutofillItemList()
156 for( std::vector<Dali::AutofillItem>::iterator iter = mAutofillItemList.begin(), endIter = mAutofillItemList.end(); iter != endIter; ++iter )
158 ( *iter ).ClearPresentationTextList();
159 ( *iter ).ClearFillValueList();
163 void AutofillGroupEcoreWl::SaveAutofillData()
165 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::SaveAutofillData\n" );
166 #ifdef CAPI_AUTOFILL_SUPPORT
167 // Creates autofill save view info handle.
168 autofill_save_view_info_create( &mAutofillSaveGroupHandle );
169 autofill_save_view_info_set_view_id( mAutofillSaveGroupHandle, mGroupId.c_str() );
171 for( std::vector<Dali::AutofillItem>::iterator iter = mAutofillItemList.begin(), endIter = mAutofillItemList.end(); iter != endIter; ++iter )
173 Internal::Adaptor::AutofillItem& itemImpl = Internal::Adaptor::GetImplementation( *iter );
174 Internal::Adaptor::AutofillItemEcorewWl& itemImplWl = static_cast<Internal::Adaptor::AutofillItemEcorewWl&>( itemImpl );
176 // Appends autofill save item in autofill save view.
177 autofill_save_view_info_add_item( mAutofillSaveGroupHandle, itemImplWl.GetAutofillSaveItemHandle() );
179 #endif // CAPI_AUTOFILL_SUPPORT
182 // If Autofill service sends authentication signal, AutofillManagerEcoreWl::ReceiveAuthInfo() would be called.
183 void AutofillGroupEcoreWl::RequestAuthentication()
185 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::RequestAuthentication\n" );
187 #ifdef CAPI_AUTOFILL_SUPPORT
188 Dali::AutofillManager manager = Dali::AutofillManager::Get();
189 Internal::Adaptor::AutofillManager& managerImpl = Internal::Adaptor::GetImplementation( manager );
190 Internal::Adaptor::AutofillManagerEcoreWl& managerImplWl = static_cast<Internal::Adaptor::AutofillManagerEcoreWl&>( managerImpl );
192 // Requests to invoke the authentication information.
193 // After requests of authentication, AutofillManagerEcoreWl::AuthInfoCallback would be called.
194 int ret = autofill_auth_info_request( managerImplWl.GetAutofillHandle(), mAutofillGroupHandle );
195 if( ret != AUTOFILL_ERROR_NONE )
197 DALI_LOG_ERROR( "Failed to request auth info. error : %d \n", ret );
199 #endif // CAPI_AUTOFILL_SUPPORT
202 // If Autofill service sends fill response signal, AutofillManagerEcoreWl::FillGroupItem() or
203 // AutofillManagerEcoreWl::FillMultipleGroupItem() would be called according to the number of group count.
204 void AutofillGroupEcoreWl::SendFillRequest()
206 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::SendFillRequest\n" );
208 #ifdef CAPI_AUTOFILL_SUPPORT
209 Dali::AutofillManager manager = Dali::AutofillManager::Get();
210 Internal::Adaptor::AutofillManager& managerImpl = Internal::Adaptor::GetImplementation( manager );
211 Internal::Adaptor::AutofillManagerEcoreWl& managerImplWl = static_cast<Internal::Adaptor::AutofillManagerEcoreWl&>( managerImpl );
213 // Removes all elements of each AutofillItem in AutofillGroup
214 ClearAutofillItemList();
216 // Sends fill request to fill out each input form.
217 // After request of fill data, AutofillManagerEcoreWl::FillResponseCallback would be called.
218 int ret = autofill_fill_request( managerImplWl.GetAutofillHandle(), mAutofillGroupHandle );
219 if( ret != AUTOFILL_ERROR_NONE )
221 DALI_LOG_ERROR( "Failed to request fill : %d \n", ret );
223 #endif // CAPI_AUTOFILL_SUPPORT