[Tizen] Add DALi Autofill implementation
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / ubuntu-x11 / autofill-manager-impl-x.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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 // CLASS HEADER
19 #include <dali/internal/input/ubuntu-x11/autofill-manager-impl-x.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/adaptor/common/adaptor-impl.h>
27 #include <dali/internal/system/common/singleton-service-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 namespace
39 {
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_AUTOFILL");
42 #endif
43
44 // Signals
45 const char* const SIGNAL_AUTHENTICATION_RECEIVED = "authenticationReceived";
46 const char* const SIGNAL_FILL_RESPONSE_RECEIVED = "fillResponseReceived";
47 const char* const SIGNAL_LIST_RECEIVED = "listReceived";
48
49 BaseHandle Create()
50 {
51   return Dali::AutofillManager::Get();
52 }
53
54 Dali::TypeRegistration typeRegistration( typeid(Dali::AutofillManager), typeid(Dali::BaseHandle), Create );
55
56 Dali::SignalConnectorType signalConnector1( typeRegistration, SIGNAL_AUTHENTICATION_RECEIVED, Dali::Internal::Adaptor::AutofillManagerX::DoConnectSignal );
57 Dali::SignalConnectorType signalConnector2( typeRegistration, SIGNAL_FILL_RESPONSE_RECEIVED, Dali::Internal::Adaptor::AutofillManagerX::DoConnectSignal );
58 Dali::SignalConnectorType signalConnector3( typeRegistration, SIGNAL_LIST_RECEIVED, Dali::Internal::Adaptor::AutofillManagerX::DoConnectSignal );
59
60 } // unnamed namespace
61
62
63
64 Dali::AutofillManager AutofillManagerX::Get()
65 {
66   Dali::AutofillManager autofill;
67   AutofillManagerX *autofillPtr = NULL;
68
69   Dali::SingletonService service( SingletonService::Get() );
70   if( service )
71   {
72     // Check whether the singleton is already created
73     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AutofillManager ) );
74     if( handle )
75     {
76       // If so, downcast the handle
77       autofillPtr = dynamic_cast< AutofillManagerX* >( handle.GetObjectPtr() );
78       autofill = Dali::AutofillManager( autofillPtr );
79     }
80     else if( Adaptor::IsAvailable() )
81     {
82       // Create instance and register singleton only if the adaptor is available
83       autofillPtr = new AutofillManagerX();
84       autofill = Dali::AutofillManager( autofillPtr );
85       service.Register( typeid( autofill ), autofill );
86     }
87   }
88
89   return autofill;
90 }
91
92 AutofillManagerX::AutofillManagerX()
93 : mAutofillGroup(),
94   mAuthenticationServiceName(""),
95   mAuthenticationServiceMessage(""),
96   mAuthenticationServiceImagePath(""),
97   mFillItemId(""),
98   mFillItemPresentationText(""),
99   mFillItemValue(""),
100   mIsDataPresent( false ),
101   mIsAuthNeeded( false )
102 {
103 }
104
105 AutofillManagerX::~AutofillManagerX()
106 {
107   DeleteContext();
108 }
109
110 void AutofillManagerX::ConnectCallbacks()
111 {
112 }
113
114 void AutofillManagerX::CreateContext()
115 {
116 }
117
118 void AutofillManagerX::DeleteContext()
119 {
120   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerX::DeleteContext\n" );
121   // Do Nothing
122 }
123
124
125 /////////////////////////////////////////////// Autofill Item and Group ///////////////////////////////////////////////
126
127 Dali::AutofillItem AutofillManagerX::CreateAutofillItem( const std::string& id, const std::string& label, Dali::AutofillItem::Hint hint, bool isSensitive )
128 {
129   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerX::CreateAutofillItem \n" );
130
131   Dali::AutofillItem item = AutofillItem::New( id, label, hint, isSensitive );
132   mAutofillItemList.push_back( item );
133
134   return mAutofillItemList.back();
135 }
136
137 Dali::AutofillGroup AutofillManagerX::CreateAutofillGroup( const std::string& groupId )
138 {
139   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerX::CreateAutofillGroup \n" );
140
141   Dali::AutofillGroup group = AutofillGroup::New( groupId );
142   mAutofillGroupList.push_back( group );
143
144   return mAutofillGroupList.back();
145 }
146
147
148 /////////////////////////////////////////////// Autofill Authentication Information ///////////////////////////////////////////////
149
150 bool AutofillManagerX::IsAutofillDataPresent() const
151 {
152   return mIsDataPresent;
153 }
154
155 bool AutofillManagerX::IsAuthenticationNeeded() const
156 {
157   return mIsAuthNeeded;
158 }
159
160 const std::string& AutofillManagerX::GetAuthenticationServiceName() const
161 {
162   return mAuthenticationServiceName;
163 }
164
165 const std::string& AutofillManagerX::GetAuthenticationServiceMessage() const
166 {
167   return mAuthenticationServiceMessage;
168 }
169
170 const std::string& AutofillManagerX::GetAuthenticationServiceImagePath() const
171 {
172   return mAuthenticationServiceImagePath;
173 }
174
175
176 /////////////////////////////////////////////// Autofill Fill Response ///////////////////////////////////////////////
177
178 const std::string& AutofillManagerX::GetFillItemId() const
179 {
180   return mFillItemId;
181 }
182
183 const std::string& AutofillManagerX::GetFillItemPresentationText() const
184 {
185   return mFillItemPresentationText;
186 }
187
188 const std::string& AutofillManagerX::GetFillItemValue() const
189 {
190   return mFillItemValue;
191 }
192
193 void AutofillManagerX::SaveAutofillData( Dali::AutofillGroup group )
194 {
195   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerX::SaveAutofillData\n" );
196   // Do Nothing
197 }
198
199 // Signals
200 AutofillManagerX::AuthSignalType& AutofillManagerX::AuthenticationReceivedSignal()
201 {
202   return mAuthReceivedSignal;
203 }
204
205 AutofillManagerX::FillSignalType& AutofillManagerX::FillResponseReceivedSignal()
206 {
207   return mFillReceivedSignal;
208 }
209
210 AutofillManagerX::ListSignalType& AutofillManagerX::ListEventSignal()
211 {
212   return mListReceivedSignal;
213 }
214
215 bool AutofillManagerX::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
216 {
217   Dali::BaseHandle handle( object );
218
219   bool connected( true );
220   AutofillManagerX* manager = dynamic_cast< AutofillManagerX* >( object );
221
222   if( manager )
223   {
224     if( 0 == signalName.compare( SIGNAL_AUTHENTICATION_RECEIVED ) )
225     {
226       manager->AuthenticationReceivedSignal().Connect( tracker, functor );
227     }
228     else if( 0 == signalName.compare( SIGNAL_FILL_RESPONSE_RECEIVED ) )
229     {
230       manager->FillResponseReceivedSignal().Connect( tracker, functor );
231     }
232     else if( 0 == signalName.compare( SIGNAL_LIST_RECEIVED ) )
233     {
234       manager->ListEventSignal().Connect( tracker, functor );
235     }
236     else
237     {
238       // signalName does not match any signal
239       connected = false;
240     }
241   }
242
243   return connected;
244 }
245
246
247
248 } // Adaptor
249
250 } // Internal
251
252 } // Dali