Applied latest source code
[apps/native/preloaded/Settings.git] / src / StAppSettingForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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  * @file                StAppSettingForm.cpp
19  * @brief               This is the implementation file for AppSettingForm class.
20  */
21
22 #include "StAppSettingForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Utility;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Io;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37 static const int APPSETTING_DEFAULT_COUNT = 1;
38 static const int ID_APPSETTTING_ARGUMENT_DEFAULT = 0;
39 static const int ID_APPSETTTING_ARGUMENT_APP_ID = 1;
40 static const int ID_APPSETTTING_ARGUMENT_COUNT = 2;
41
42 static const wchar_t* DEFAULT_VALUE_STRING = L"1";
43 static const wchar_t* ID_POST_FIX_BUTTON_DONE = L"DONE";
44 static const wchar_t* ID_POST_FIX_BUTTON_CANCEL = L"CANCEL";
45
46 static const wchar_t* ID_APPSETTING_ITEM_TYPE_BOOL = L"bool";
47 static const wchar_t* ID_APPSETTING_ITEM_TYPE_INTEGER = L"integer";
48 static const wchar_t* ID_APPSETTING_ITEM_TYPE_STRING = L"string";
49 static const wchar_t* ID_APPSETTING_ITEM_TYPE_LABEL = L"label";
50 static const wchar_t* ID_APPSETTING_ITEM_TYPE_EXPAND_LIST = L"expandlist";
51 static const wchar_t* ID_APPSETTING_ITEM_TYPE_EXPAND_ITEM = L"expanditem";
52 static const wchar_t* ID_APPSETTING_ITEM_TYPE_SEPARATOR = L"separator";
53
54 static const wchar_t* ID_APPSETTING_ATTRIBUTE_TYPE_TITLE = L"title";
55 static const wchar_t* ID_APPSETTING_ATTRIBUTE_TYPE_MIN = L"min";
56 static const wchar_t* ID_APPSETTING_ATTRIBUTE_TYPE_MAX = L"max";
57 static const wchar_t* ID_APPSETTING_ATTRIBUTE_TYPE_VALUE = L"value";
58 static const wchar_t* ID_APPSETTING_ATTRIBUTE_TYPE_MIN_LENGTH = L"minlength";
59 static const wchar_t* ID_APPSETTING_ATTRIBUTE_TYPE_MAX_LENGTH = L"maxlength";
60
61 static const int ITEM_WIDTH_GAP = 100;
62
63 AppSettingForm::AppSettingForm(void)
64         : __filePath(L"")
65         , __appId(L"")
66         , __isNoTitleGroup(true)
67         , __pIOAppSetting(null)
68         , __pGroupItemNodeList(null)
69         , __pTranslateTableIndexToHashCode(null)
70         , __pTranslateTableHashCodeToItemTag(null)
71         , __pItemHashcodeHashMap(null)
72 {
73 }
74
75 AppSettingForm::~AppSettingForm(void)
76 {
77 }
78
79 void
80 AppSettingForm::CreateFooter(void)
81 {
82         Footer* pFooter = GetFooter();
83         AppAssert(pFooter);
84
85         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
86         pFooter->AddActionEventListener(*this);
87         SetFormBackEventListener(this);
88 }
89
90 void
91 AppSettingForm::SetHeaderTitle(void)
92 {
93         if (__pGroupItemNodeList == null)
94         {
95                 AppLogDebug("__pGroupItemNodeList is null");
96                 CreateHeader(L"AppSettingDefault");
97                 return;
98         }
99
100         Node* pNode = null;
101         result r = __pGroupItemNodeList->GetAt(0, pNode);
102         if ((pNode == null)
103                 || (IsFailed(r)))
104         {
105                 if (pNode == null)
106                 {
107                         AppLogDebug("pNode is null");
108                 }
109                 else
110                 {
111                         AppLogDebug("GetAt fail [%s]", GetErrorMessage(r));
112                 }
113                 CreateHeader(L"AppSettingDefault");
114                 return;
115         }
116
117         Node* pParent = pNode->GetParent();
118         if ((pParent == null)
119                 || (!pParent->GetType().Equals(L"setting", false)))
120         {
121                 if (pParent == null)
122                 {
123                         AppLogDebug("pParent is null");
124                 }
125                 else
126                 {
127                         AppLogDebug("pParent is not setting element [%ls]", pParent->GetType().GetPointer());
128                 }
129                 CreateHeader(L"AppSettingDefault");
130                 return;
131         }
132
133         String* pTitle = pParent->GetAttributeN(L"title");
134         if (pTitle == null)
135         {
136                 AppLogDebug("pTitle is null");
137                 CreateHeader(L"AppSettingDefault");
138                 return;
139         }
140
141         CreateHeader(*pTitle);
142         delete pTitle;
143 }
144
145 result
146 AppSettingForm::OnInitializing(void)
147 {
148         return E_SUCCESS;
149 }
150
151 result
152 AppSettingForm::AppSettingManagerInit(Tizen::Base::String rootId, Tizen::Base::String filePath)
153 {
154         __pAppSettingManager = AppSettingManager::GetInstance();
155         if (__pAppSettingManager == null)
156         {
157                 AppLogDebug("AppSettingManager::GetInstance fail");
158                 return E_FAILURE;
159         }
160
161         ElementNode* pRoot = __pAppSettingManager->AddAppSettingRootNode(rootId);
162         result r = __pAppSettingManager->XmlAppSettingFileRead(filePath, pRoot);
163         if (IsFailed(r))
164         {
165                 __pAppSettingManager->RemoveAppSettingRootNode(rootId);
166                 AppLogDebug("XmlAppSettingFileRead fail [%s]", GetErrorMessage(r));
167                 return r;
168         }
169
170         return E_SUCCESS;
171 }
172
173 result
174 AppSettingForm::SetGroupItemNodeList(Tizen::Base::String rootId)
175 {
176         InitGroupItemNodeList();
177
178         if (__pAppSettingManager == null)
179         {
180                 AppLogDebug("__pAppSettingManager is null");
181                 return E_FAILURE;
182         }
183
184         ElementNode* pRoot = __pAppSettingManager->GetAppSettingRootNode(rootId);
185
186         if (pRoot == null)
187         {
188                 AppLogDebug("AppId is not found");
189                 return E_FAILURE;
190         }
191
192         bool isFindSttingElement = false;
193         Node* pNode = null;
194         Enumerator* pEnum = pRoot->CreateEnumerator();
195         while (pEnum->MoveNext() == E_SUCCESS)
196         {
197                 pNode = static_cast<Node*>(pEnum->GetCurrentObject());
198                 if (pNode->GetType().Equals(L"setting", false))
199                 {
200                         isFindSttingElement = true;
201                         break;
202                 }
203         }
204         delete pEnum;
205
206         if ((isFindSttingElement == false)
207                 || (pNode == null)
208                 || (pNode->GetNodeType() == Node::NODE_TYPE_LEAF))
209         {
210                 if (isFindSttingElement == false)
211                 {
212                         AppLogDebug("Setting Element is not found");
213                 }
214                 else
215                 {
216                         AppLogDebug("Child is not found");
217                 }
218                 return E_FAILURE;
219         }
220
221         ElementNode* pElementNode = dynamic_cast<ElementNode*>(pNode);
222         if (pElementNode == null)
223         {
224                 AppLogDebug("dynamic_cast<ElementNode*>(pNode) is null");
225                 return E_FAILURE;
226         }
227         unsigned int childCount = pElementNode->GetChildCount();
228         if (childCount == 0)
229         {
230                 AppLogDebug("Child is zero");
231                 return E_FAILURE;
232         }
233
234         result r = E_FAILURE;
235         for (unsigned int i = 0; i < childCount; i++)
236         {
237                 if (pElementNode->GetChild(i)->GetType().Equals(L"navigationbar", false))
238                 {
239                         continue;
240                 }
241
242                 r = __pGroupItemNodeList->Add(pElementNode->GetChild(i));
243                 if (IsFailed(r))
244                 {
245                         AppLogDebug("Add fail");
246                         RemoveAllGroupItemNodeList();
247                         break;
248                 }
249
250                 r = AddItemHashCodeMap(pElementNode->GetChild(i)->GetId().GetHashCode(), pElementNode->GetChild(i));
251                 if (IsFailed(r))
252                 {
253                         AppLogDebug("AddItemHashCodeMap fail");
254                         RemoveAllGroupItemNodeList();
255                         break;
256                 }
257         }
258
259         return r;
260 }
261
262 void
263 AppSettingForm::RemoveAllGroupItemNodeList(void)
264 {
265         if (__pGroupItemNodeList != null)
266         {
267                 __pGroupItemNodeList->RemoveAll();
268                 delete __pGroupItemNodeList;
269                 __pGroupItemNodeList = null;
270         }
271 }
272
273 result
274 AppSettingForm::InitGroupItemNodeList(void)
275 {
276         RemoveAllGroupItemNodeList();
277
278         __pGroupItemNodeList = new (std::nothrow) LinkedListT<Node*>;
279         if (__pGroupItemNodeList == null)
280         {
281                 AppLogDebug("__pGroupItemNodeList create fail");
282                 return E_FAILURE;
283         }
284
285         return E_SUCCESS;
286 }
287
288 result
289 AppSettingForm::InitItemHashCodeMap(void)
290 {
291         RemoveAllItemHashCodeMap();
292
293         __pItemHashcodeHashMap = new (std::nothrow) HashMapT<unsigned int, Node*>;
294         if (__pItemHashcodeHashMap == null)
295         {
296                 AppLogDebug("__pItemHashcodeHashMap create fail");
297                 return E_FAILURE;
298         }
299
300         result r = __pItemHashcodeHashMap->Construct();
301         if (IsFailed(r))
302         {
303                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
304                 RemoveAllItemHashCodeMap();
305         }
306
307         return r;
308 }
309
310 result
311 AppSettingForm::AddItemHashCodeMap(unsigned int hashCode, Node* pNode)
312 {
313         if (__pItemHashcodeHashMap == null)
314         {
315                 AppLogDebug("__pItemHashcodeHashMap is null");
316                 return E_FAILURE;
317         }
318
319         result r = __pItemHashcodeHashMap->Add(hashCode, pNode);
320
321         return r;
322 }
323
324 result
325 AppSettingForm::MakeTranslateTable(void)
326 {
327         if ((__pGroupItemNodeList == null)
328                 || (__pItemHashcodeHashMap == null))
329         {
330                 AppLogDebug("__pGroupItemNodeList or __pItemHashcodeHashMap is null");
331                 return E_FAILURE;
332         }
333
334         unsigned int groupItemListCount = __pGroupItemNodeList->GetCount();
335         if (groupItemListCount == 0)
336         {
337                 AppLogDebug("groupItemListCount is zero");
338                 return E_FAILURE;
339         }
340
341         result r = E_FAILURE;
342         Node* pNode = null;
343         Enumerator* pEnum = null;
344
345         for (unsigned int i = 0; i < groupItemListCount; i++)
346         {
347                 r = __pGroupItemNodeList->GetAt(i, pNode);
348                 if ((pNode == null)
349                         || (IsFailed(r)))
350                 {
351                         if (pNode == null)
352                         {
353                                 AppLogDebug("pNode is null");
354                                 r = E_FAILURE;
355                         }
356                         else
357                         {
358                                 AppLogDebug("GetAt fail [%s]", GetErrorMessage(r));
359                         }
360
361                         RemoveAllTranslateTableIndexToHashCode();
362                         RemoveAllItemHashCodeMap();
363
364                         return r;
365                 }
366
367                 ArrayListT<unsigned int>* pGroupItemHashCode = new (std::nothrow) ArrayListT<unsigned int>;
368                 if (pGroupItemHashCode == null)
369                 {
370                         AppLogDebug("pNode is null");
371
372                         RemoveAllTranslateTableIndexToHashCode();
373                         RemoveAllItemHashCodeMap();
374
375                         return E_FAILURE;
376                 }
377
378                 r = pGroupItemHashCode->Construct();
379                 if (IsFailed(r))
380                 {
381                         AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
382                         RemoveAllTranslateTableIndexToHashCode();
383                         RemoveAllItemHashCodeMap();
384
385                         pGroupItemHashCode->RemoveAll();
386                         delete pGroupItemHashCode;
387
388                         return E_FAILURE;
389                 }
390
391                 int enumLoopCount = 0;
392                 pEnum = pNode->CreateEnumerator();
393                 while (pEnum->MoveNext() == E_SUCCESS)
394                 {
395                         Node* pCurrent = static_cast<Node*>(pEnum->GetCurrentObject());
396                         if (pCurrent == null)
397                         {
398                                 AppLogDebug("pNode is null");
399                                 RemoveAllTranslateTableIndexToHashCode();
400                                 RemoveAllItemHashCodeMap();
401                                 delete pEnum;
402
403                                 pGroupItemHashCode->RemoveAll();
404                                 delete pGroupItemHashCode;
405
406                                 return E_FAILURE;
407                         }
408
409                         unsigned int idHashCode = pCurrent->GetId().GetHashCode();
410
411                         r = AddItemHashCodeMap(idHashCode, pCurrent);
412                         if (IsFailed(r))
413                         {
414                                 AppLogDebug("Add fail [%s]", GetErrorMessage(r));
415                                 RemoveAllTranslateTableIndexToHashCode();
416                                 RemoveAllItemHashCodeMap();
417                                 delete pEnum;
418
419                                 pGroupItemHashCode->RemoveAll();
420                                 delete pGroupItemHashCode;
421
422                                 return r;
423                         }
424
425                         r = pGroupItemHashCode->Add(idHashCode);
426                         if (IsFailed(r))
427                         {
428                                 AppLogDebug("Add fail [%s]", GetErrorMessage(r));
429                                 RemoveAllTranslateTableIndexToHashCode();
430                                 RemoveAllItemHashCodeMap();
431                                 delete pEnum;
432
433                                 pGroupItemHashCode->RemoveAll();
434                                 delete pGroupItemHashCode;
435
436                                 return r;
437                         }
438                         SetTranslateTableHashCodeToItemTag(idHashCode, new (std::nothrow) ItemTag(i, enumLoopCount));
439                         enumLoopCount = enumLoopCount + APPSETTING_DEFAULT_COUNT;
440                 }
441                 if (enumLoopCount == 0)
442                 {
443                         if (pNode)
444                         {
445                                 unsigned int idHashCode = pNode->GetId().GetHashCode();
446
447                                 r = pGroupItemHashCode->Add(idHashCode);
448                                 if (IsFailed(r))
449                                 {
450                                         AppLogDebug("Add fail [%s]", GetErrorMessage(r));
451                                         RemoveAllTranslateTableIndexToHashCode();
452                                         RemoveAllItemHashCodeMap();
453                                         delete pEnum;
454
455                                         pGroupItemHashCode->RemoveAll();
456                                         delete pGroupItemHashCode;
457
458                                         return r;
459                                 }
460                                 SetTranslateTableHashCodeToItemTag(idHashCode, new (std::nothrow) ItemTag(i, enumLoopCount));
461                         }
462                 }
463                 delete pEnum;
464
465                 r = SetTranslateTableIndexToHashCode(pGroupItemHashCode);
466                 if (IsFailed(r))
467                 {
468                         AppLogDebug("SetTranslateTableIndexToHashCode fail [%s]", GetErrorMessage(r));
469                         RemoveAllTranslateTableIndexToHashCode();
470                         RemoveAllItemHashCodeMap();
471
472                         pGroupItemHashCode->RemoveAll();
473                         delete pGroupItemHashCode;
474
475                         return r;
476                 }
477         }
478
479         return r;
480 }
481
482 Node*
483 AppSettingForm::GetItemHashCodeMap(unsigned int hashCode)
484 {
485         if (__pItemHashcodeHashMap == null)
486         {
487                 AppLogDebug("__pItemHashcodeHashMap is null");
488                 return null;
489         }
490
491         bool isFindKey = false;
492         result r = __pItemHashcodeHashMap->ContainsKey(hashCode, isFindKey);
493         if ((isFindKey == false)
494                 || (IsFailed(r)))
495         {
496                 if (isFindKey == false)
497                 {
498                         AppLogDebug("Key is not found");
499                 }
500                 else
501                 {
502                         AppLogDebug("ContainsKey fail [%s]", GetErrorMessage(r));
503                 }
504
505                 return null;
506         }
507
508         Node* pValueNode = null;
509         r = __pItemHashcodeHashMap->GetValue(hashCode, pValueNode);
510         if ((pValueNode == null)
511                 || (IsFailed(r)))
512         {
513                 if (pValueNode == null)
514                 {
515                         AppLogDebug("pValueNode is null");
516                 }
517                 else
518                 {
519                         AppLogDebug("GetValue fail [%s]", GetErrorMessage(r));
520                 }
521
522                 return null;
523         }
524
525         return pValueNode;
526 }
527
528 void
529 AppSettingForm::RemoveAllItemHashCodeMap(void) // must be modify
530 {
531         if (__pItemHashcodeHashMap != null)
532         {
533                 __pItemHashcodeHashMap->RemoveAll();
534                 delete __pItemHashcodeHashMap;
535                 __pItemHashcodeHashMap = null;
536         }
537 }
538
539 result
540 AppSettingForm::InitTranslateTableIndexToHashCode(void)
541 {
542         if (__pTranslateTableIndexToHashCode != null)
543         {
544                 AppLogDebug("__pTranslateTableIndexToHashCode is not null");
545                 return E_FAILURE;
546         }
547
548         __pTranslateTableIndexToHashCode = new (std::nothrow) ArrayListT<ArrayListT<unsigned int>*>;
549         if (__pTranslateTableIndexToHashCode == null)
550         {
551                 AppLogDebug("__pTranslateTableIndexToHashCode create fail");
552                 return E_FAILURE;
553         }
554
555         result r = __pTranslateTableIndexToHashCode->Construct();
556         if (IsFailed(r))
557         {
558                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
559                 RemoveAllTranslateTableIndexToHashCode();
560         }
561
562         return r;
563 }
564
565 result
566 AppSettingForm::InitTranslateTableHashCodeToItemTag(void)
567 {
568         if (__pTranslateTableHashCodeToItemTag != null)
569         {
570                 AppLogDebug("__pTranslateTableIndexToHashCode is not null");
571                 return E_FAILURE;
572         }
573         __pTranslateTableHashCodeToItemTag = new (std::nothrow) HashMapT<unsigned int, ItemTag*>;
574         if (__pTranslateTableHashCodeToItemTag == null)
575         {
576                 AppLogDebug("__pTranslateTableHashCodeToItemTag create fail");
577                 return E_FAILURE;
578         }
579         result r = __pTranslateTableHashCodeToItemTag->Construct();
580         if (IsFailed(r))
581         {
582                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
583                 RemoveAllTranslateTableHashCodeToItemTag();
584         }
585         return r;
586 }
587
588 result
589 AppSettingForm::SetTranslateTableHashCodeToItemTag(int hashCode, ItemTag* itemTag)
590 {
591         InitTranslateTableHashCodeToItemTag();
592         if (__pTranslateTableHashCodeToItemTag == null)
593         {
594                 AppLogDebug("__pTranslateTableHashCodeToItemTag is null");
595                 return E_FAILURE;
596         }
597         return __pTranslateTableHashCodeToItemTag->Add(hashCode, itemTag);
598 }
599
600 ItemTag*
601 AppSettingForm::GetTranslateTableHashCodeToItemTag(unsigned int hashCode)
602 {
603         if (__pTranslateTableHashCodeToItemTag == null)
604         {
605                 AppLogDebug("__pTranslateTableHashCodeToItemTag is null");
606                 return null;
607         }
608         bool isFindKey = false;
609         result r = __pTranslateTableHashCodeToItemTag->ContainsKey(hashCode, isFindKey);
610         if ((isFindKey == false)
611                 || (IsFailed(r)))
612         {
613                 if (isFindKey == false)
614                 {
615                         AppLogDebug("Key is not found");
616                 }
617                 else
618                 {
619                         AppLogDebug("ContainsKey fail [%s]", GetErrorMessage(r));
620                 }
621                 return null;
622         }
623         ItemTag* pValueItemTag = null;
624         r = __pTranslateTableHashCodeToItemTag->GetValue(hashCode, pValueItemTag);
625         if ((pValueItemTag == null)
626                 || (IsFailed(r)))
627         {
628                 if (pValueItemTag == null)
629                 {
630                         AppLogDebug("pValueItemTag is null");
631                 }
632                 else
633                 {
634                         AppLogDebug("GetValue fail [%s]", GetErrorMessage(r));
635                 }
636                 return null;
637         }
638         return pValueItemTag;
639 }
640
641 void
642 AppSettingForm::RemoveAllTranslateTableHashCodeToItemTag(void)
643 {
644         if (__pTranslateTableHashCodeToItemTag != null)
645         {
646                 __pTranslateTableHashCodeToItemTag->RemoveAll();
647                 delete __pTranslateTableHashCodeToItemTag;
648                 __pTranslateTableHashCodeToItemTag = null;
649         }
650 }
651
652 result
653 AppSettingForm::SetTranslateTableIndexToHashCode(Tizen::Base::Collection::ArrayListT<unsigned int>* groupItemHashCode)
654 {
655         InitTranslateTableIndexToHashCode();
656
657         if (__pTranslateTableIndexToHashCode == null)
658         {
659                 AppLogDebug("__pTranslateTableIndexToHashCode is null");
660                 return E_FAILURE;
661         }
662
663         result r = __pTranslateTableIndexToHashCode->Add(groupItemHashCode);
664         if (IsFailed(r))
665         {
666                 AppLogDebug("Add fail [%s]", GetErrorMessage(r));
667         }
668
669         return r;
670 }
671
672 unsigned int
673 AppSettingForm::GetTranslateTableIndexToHashCode(unsigned int groupIndex, unsigned int itemIndex)
674 {
675         unsigned int retHashCode = 0;
676
677         if (__pTranslateTableIndexToHashCode == null)
678         {
679                 AppLogDebug("__pTranslateTableIndexToHashCode is null");
680                 return retHashCode;
681         }
682
683         unsigned int groupCount = __pTranslateTableIndexToHashCode->GetCount();
684         if ((groupIndex >= groupCount)
685                 || (groupCount == 0))
686         {
687                 AppLogDebug("groupIndex is not found");
688                 return retHashCode;
689         }
690
691         ArrayListT<unsigned int>* pItemList = null;
692         result r = __pTranslateTableIndexToHashCode->GetAt(groupIndex, pItemList);
693         if ((pItemList == null)
694                 || (IsFailed(r)))
695         {
696                 if (pItemList == null)
697                 {
698                         AppLogDebug("pItemList is null");
699                 }
700                 else
701                 {
702                         AppLogDebug("GetAt fail [%s]", GetErrorMessage(r));
703                 }
704
705                 return retHashCode;
706         }
707
708         unsigned int itemCount = pItemList->GetCount();
709         if ((itemIndex >= itemCount)
710                 || (itemCount == 0))
711         {
712                 AppLogDebug("itemIndex is not found");
713                 return retHashCode;
714         }
715
716         r = pItemList->GetAt(itemIndex, retHashCode);
717         if (IsFailed(r))
718         {
719                 AppLogDebug("GetAt fail [%s]", GetErrorMessage(r));
720                 retHashCode = 0;
721
722                 return retHashCode;
723         }
724
725         return retHashCode;
726 }
727
728 unsigned int
729 AppSettingForm::GetItemCountByTranslateTable(unsigned int groupIndex)
730 {
731         unsigned int itemCount = 0;
732         if (__pTranslateTableIndexToHashCode == null)
733         {
734                 AppLogDebug("__pTranslateTableIndexToHashCode is null");
735                 return itemCount;
736         }
737
738         unsigned int groupCount = __pTranslateTableIndexToHashCode->GetCount();
739         if ((groupIndex >= groupCount)
740                 || (groupCount == 0))
741         {
742                 AppLogDebug("groupIndex is not found");
743                 return itemCount;
744         }
745
746         ArrayListT<unsigned int>* pItemList = null;
747         result r = __pTranslateTableIndexToHashCode->GetAt(groupIndex, pItemList);
748         if ((pItemList == null)
749                 || (IsFailed(r)))
750         {
751                 if (pItemList == null)
752                 {
753                         AppLogDebug("pItemList is null");
754                 }
755                 else
756                 {
757                         AppLogDebug("GetAt fail [%s]", GetErrorMessage(r));
758                 }
759
760                 return itemCount;
761         }
762
763         itemCount = pItemList->GetCount();
764         if (itemCount == 0)
765         {
766                 itemCount = APPSETTING_DEFAULT_COUNT;
767         }
768
769         return itemCount;
770 }
771
772 void
773 AppSettingForm::RemoveAllTranslateTableIndexToHashCode(void)
774 {
775         if (__pTranslateTableIndexToHashCode != null)
776         {
777                 unsigned int groupCount = __pTranslateTableIndexToHashCode->GetCount();
778                 if (groupCount != 0)
779                 {
780                         for (unsigned int i = 0; i < groupCount; i++)
781                         {
782                                 ArrayListT<unsigned int>* itemList = null;
783                                 __pTranslateTableIndexToHashCode->GetAt(i, itemList);
784
785                                 if (itemList != null)
786                                 {
787                                         itemList->RemoveAll();
788                                         delete itemList;
789                                 }
790                         }
791                 }
792
793                 __pTranslateTableIndexToHashCode->RemoveAll();
794                 delete __pTranslateTableIndexToHashCode;
795                 __pTranslateTableIndexToHashCode = null;
796         }
797 }
798
799 result
800 AppSettingForm::IOAppSettingInit(Tizen::Base::String appId)
801 {
802         __pIOAppSetting = new (std::nothrow) IOAppSetting();
803         if (__pIOAppSetting == null)
804         {
805                 AppLogDebug("__pIOAppSetting Create failed");
806                 return E_FAILURE;
807         }
808
809         result r = __pIOAppSetting->Constructor(appId);
810         if (IsFailed(r))
811         {
812                 RemoveIOAppSetting();
813         }
814
815         return r;
816 }
817
818 void
819 AppSettingForm::RemoveIOAppSetting(void)
820 {
821         if (__pIOAppSetting != null)
822         {
823                 delete __pIOAppSetting;
824                 __pIOAppSetting = null;
825         }
826 }
827
828 result
829 AppSettingForm::OnTerminating(void)
830 {
831         AppLog("Enter");
832         if (__pTableView)
833         {
834                 __pTableView->SetItemProvider(null);
835         }
836         else
837         {
838                 int contorlCount = GetControlCount();
839                 for (int i = 0; i < contorlCount; i++)
840                 {
841                         RemoveControl(GetControl(0));
842                 }
843 //              RemoveAllControls();
844         }
845         RemoveAllGroupItemNodeList();
846         RemoveAllItemHashCodeMap();
847         RemoveAllTranslateTableIndexToHashCode();
848         RemoveAllTranslateTableHashCodeToItemTag();
849         RemoveIOAppSetting();
850
851         if (__pAppSettingManager != null)
852         {
853         __pAppSettingManager->RemoveAppSettingRootNode(__appId);
854         __pAppSettingManager = null;
855         }
856
857         SceneManager* pSceneManager = SceneManager::GetInstance();
858         AppAssert(pSceneManager);
859
860         pSceneManager->UnregisterScene(__appId);
861
862         SetFormBackEventListener(null);
863         return E_SUCCESS;
864 }
865
866 void
867 AppSettingForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
868 {
869         Node* pRootNode = null;
870         Enumerator* pEnum = null;
871         String* pArgsValue[ID_APPSETTTING_ARGUMENT_COUNT] = {null, };
872         int argsCount = 0;
873
874         if (pArgs == null)
875         {
876                 AppLogDebug("pArgs is null");
877                 return;
878         }
879
880         argsCount = pArgs->GetCount();
881         if (argsCount != ID_APPSETTTING_ARGUMENT_COUNT)
882         {
883                 AppLogDebug("Wrong count of pArgs");
884                 delete pArgs;
885                 return;
886         }
887
888         for (int i = 0; i < argsCount; i++)
889         {
890                 pArgsValue[i] = static_cast<String*>(pArgs->GetAt(i));
891                 if (pArgsValue[i] == null)
892                 {
893                         AppLogDebug("pArgsValue[%d] is null", i);
894                         delete pArgs;
895                         return;
896                 }
897         }
898
899         String appId;
900         StringTokenizer stringTokenizer(*pArgsValue[ID_APPSETTTING_ARGUMENT_DEFAULT], L":");
901         result r = stringTokenizer.GetNextToken(appId);
902         TryCatch(r == E_SUCCESS, , "GetNextToken fail[%s]", GetErrorMessage(r));
903
904         r = stringTokenizer.GetNextToken(appId);
905         if ((IsFailed(r))
906                 || (appId.IsEmpty() == true))
907         {
908                 if (!IsFailed(r))
909                 {
910                         r = E_FAILURE;
911                 }
912                 TryCatch(r == E_SUCCESS, , "GetNextToken fail[%s]", GetErrorMessage(r));
913         }
914
915         if (__appId.IsEmpty() == true)
916         {
917                 __appId.Append(appId);
918         }
919
920         __filePath = *pArgsValue[ID_APPSETTTING_ARGUMENT_APP_ID];
921         r = AppSettingManagerInit(appId, __filePath);
922         TryCatch(r == E_SUCCESS, , "AppSettingManagerInit fail [%s]", GetErrorMessage(r));
923
924         InitItemHashCodeMap();
925         r = SetGroupItemNodeList(appId);
926         TryCatch(r == E_SUCCESS, , "SetGroupItemNodeList fail");
927
928         r = MakeTranslateTable();
929         TryCatch(r == E_SUCCESS, , "MakeTranslateTable fail");
930
931         IOAppSettingInit(__appId);
932
933         SetHeaderTitle();
934         CreateTableView();
935
936         __pTableView->UpdateTableView();
937         pRootNode = __pAppSettingManager->GetAppSettingRootNode(__appId);
938         pEnum = pRootNode->CreateEnumerator();
939         while (pEnum->MoveNext() == E_SUCCESS)
940         {
941                 Node* pCurrent = static_cast<Node*>(pEnum->GetCurrentObject());
942                 if (pCurrent->GetType().Equals(ID_APPSETTING_ITEM_TYPE_BOOL, false))
943                 {
944                         unsigned int hashCode = pCurrent->GetId().GetHashCode();
945                         ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
946                         if (itemTag == null)
947                         {
948                                 continue;
949                         }
950                         String* pValue = pCurrent->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
951                         if ((pValue->Equals(L"true", false))
952                                 || (pValue->Equals(L"1", false)))
953                         {
954                                 __pTableView->SetItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), true);
955                         }
956                         delete pValue;
957                 }
958                 else if (pCurrent->GetType().Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
959                 {
960                         int itemSelect = 0;
961                         ElementNode* pExpandListItem = dynamic_cast<ElementNode*>(pCurrent);
962                         if (pExpandListItem == null)
963                         {
964                                 continue;
965                         }
966                         String* pExpandListValue = pExpandListItem->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
967                         for (int i = 0; i < pExpandListItem->GetChildCount(); i++)
968                         {
969                                 ElementLeaf* pElementLeaf = dynamic_cast<ElementLeaf*>(pExpandListItem->GetChild(i));
970                                 if (pElementLeaf == null)
971                                 {
972                                         continue;
973                                 }
974                                 String* pExpandItemValue = pElementLeaf->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
975                                 if (!pExpandListValue->Equals(*pExpandItemValue, false))
976                                 {
977                                         delete pExpandItemValue;
978                                         continue;
979                                 }
980                                 itemSelect++;
981                                 unsigned int hashCode = pElementLeaf->GetId().GetHashCode();
982                                 ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
983                                 if (itemTag == null)
984                                 {
985                                         continue;
986                                 }
987                                 __pTableView->SetItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), true);
988                                 delete pExpandItemValue;
989                         }
990                         delete pExpandListValue;
991
992                         if (itemSelect == 0)
993                         {
994                                 ElementLeaf* pElementLeaf = dynamic_cast<ElementLeaf*>(pExpandListItem->GetChild(0));
995                                 unsigned int hashCode = pElementLeaf->GetId().GetHashCode();
996                                 String* value = pElementLeaf->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
997
998                                 AppLogDebug("value[%ls]", value->GetPointer());
999                                 ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
1000                                 if (itemTag == null)
1001                                 {
1002                                         AppLogDebug("itemTag == null");
1003                                 }
1004                                 __pTableView->SetItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), true);
1005                                 pExpandListItem->SetAttribute(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE, *value);
1006                                 RefreshExpandListItem(itemTag->GetGroupIndex());
1007                                 delete value;
1008                         }
1009                 }
1010         }
1011         delete pEnum;
1012         return;
1013
1014 CATCH:
1015         if (pArgs != null)
1016         {
1017                 pArgs->RemoveAll();
1018                 delete pArgs;
1019         }
1020
1021         CreateHeader(L"Error");
1022         CreateNoContents();
1023         AppLogDebug("AppSettingForm Initialize fail");
1024 }
1025
1026 void
1027 AppSettingForm::CreateNoContents(void)
1028 {
1029         Rectangle clientRect = GetClientAreaBounds();
1030         clientRect.y = 0;
1031         String labelText = ResourceManager::GetString(L"IDS_RSSR_BODY_INVALID_FORMAT");
1032
1033         if (labelText.IsEmpty())
1034         {
1035                 labelText = L"Invalid Format.. \ncheck XML file again";
1036         }
1037
1038         Label* pInvalidFormatLabel = new (std::nothrow) Label();
1039         pInvalidFormatLabel->Construct(clientRect, labelText);
1040         pInvalidFormatLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
1041         pInvalidFormatLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1042         pInvalidFormatLabel->SetTextConfig(GetFontSize(), LABEL_TEXT_STYLE_NORMAL);
1043         pInvalidFormatLabel->SetBackgroundColor(COLOR_BG_GROUP_ITEM_LISTITEM);
1044         pInvalidFormatLabel->SetName(L"InvalidFormat");
1045         AddControl(pInvalidFormatLabel);
1046         Invalidate(true);
1047 }
1048
1049 void
1050 AppSettingForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
1051 {
1052 }
1053
1054 void
1055 AppSettingForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
1056 {
1057         AppLog("Enter");
1058         bool errorStatus = false;
1059         int currentLength = 0;
1060         int stringLengthMax = 0;
1061         int stringLengthMin = 0;
1062
1063         if (__pIOAppSetting != null)
1064         {
1065                 Node* pRootNode = null;
1066                 Enumerator* pEnum = null;
1067                 pRootNode = __pAppSettingManager->GetAppSettingRootNode(__appId);
1068                 if (pRootNode)
1069                 {
1070                 pEnum = pRootNode->CreateEnumerator();
1071                 if (pEnum != null)
1072                 {
1073                 while (pEnum->MoveNext() == E_SUCCESS)
1074                 {
1075                         Node* pCurrent = static_cast<Node*>(pEnum->GetCurrentObject());
1076                         if (pCurrent->GetType().Equals(ID_APPSETTING_ITEM_TYPE_STRING, false))
1077                         {
1078                                 String* itemText = pCurrent->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1079                                 String* pMinLength = pCurrent->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MIN_LENGTH);
1080                                 String* pMaxLength = pCurrent->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MAX_LENGTH);
1081
1082                                 currentLength = itemText->GetLength();
1083                                 Integer::Parse(*pMinLength, stringLengthMin);
1084                                 Integer::Parse(*pMaxLength, stringLengthMax);
1085
1086                                 delete itemText;
1087                                 delete pMinLength;
1088                                 delete pMaxLength;
1089
1090                                 if ((currentLength > stringLengthMax) || (currentLength < stringLengthMin))
1091                                 {
1092                                         if (currentLength > stringLengthMax)
1093                                         {
1094                                                 AppLogDebug("value length(%d) greater than maximum range(%d), show popup", currentLength, stringLengthMax);
1095                                         }
1096                                         else
1097                                         {
1098                                                 AppLogDebug("value length(%d) smaller than minimum range(%d), show popup", currentLength, stringLengthMin);
1099                                         }
1100
1101                                         MessageBox messageBox;
1102                                         int result = E_SUCCESS;
1103
1104                                         messageBox.Construct(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_COM_POP_FAILED"), MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_2_SEC);
1105                                         messageBox.ShowAndWait(result);
1106
1107                                         errorStatus = true;
1108                                         break;
1109                                 }
1110                         }
1111                 }
1112                 delete pEnum;
1113                 }
1114                 }
1115
1116                 if (errorStatus == false)
1117                 {
1118                         __pIOAppSetting->UpdateChangedValue();
1119                         SceneManager* pSceneManager = SceneManager::GetInstance();
1120                         AppAssert(pSceneManager);
1121
1122                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
1123                         return;
1124                 }
1125                 else
1126                 {
1127                         return;
1128                 }
1129         }
1130         else
1131         {
1132                 SceneManager* pSceneManager = SceneManager::GetInstance();
1133                 AppAssert(pSceneManager);
1134                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
1135         }
1136 }
1137
1138 int
1139 AppSettingForm::GetGroupCount(void)
1140 {
1141         if (__pGroupItemNodeList != null)
1142         {
1143                 return __pGroupItemNodeList->GetCount();
1144         }
1145
1146         return APPSETTING_DEFAULT_COUNT;
1147 }
1148
1149 int
1150 AppSettingForm::GetItemCount(int groupIndex)
1151 {
1152         return GetItemCountByTranslateTable(groupIndex);
1153 }
1154
1155 TableViewGroupItem*
1156 AppSettingForm::CreateGroupItem(int groupIndex, int itemWidth)
1157 {
1158         AppLogDebug("ENTER");
1159
1160         int itemHeight = H_GROUP_INDEX_DEFAULT;
1161         int yItemOffset = Y_GROUP_INDEX_DEFAULT;
1162         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
1163         Rectangle itemMainRectangle;
1164         String* groupText = null;
1165         Node* pNode = null;
1166         Label* pLabel = null;
1167         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
1168
1169         __pGroupItemNodeList->GetAt(groupIndex, pNode);
1170
1171         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
1172         itemMainRectangle.y = yItemOffset;
1173         itemMainRectangle.width = itemWidth;
1174         itemMainRectangle.height = itemHeight;
1175
1176         itemHeight = H_GROUP_INDEX_DEFAULT;
1177         itemMainRectangle.y = H_GROUP_INDEX_TITLE_TEXT;
1178         itemMainRectangle.height = H_GROUP_INDEX_DEFAULT - H_GROUP_INDEX_TITLE_TEXT;
1179         groupText = pNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
1180         if (groupText == null)
1181         {
1182                 AppLogDebug("grpText null");
1183                 delete pItem;
1184                 return null;
1185         }
1186
1187         if (!pNode->GetType().Equals(L"group", false))
1188         {
1189                 if (__isNoTitleGroup == true)
1190                 {
1191                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
1192                         __isNoTitleGroup = false;
1193                 }
1194                 else
1195                 {
1196                         itemHeight = 0;
1197                 }
1198         }
1199         else
1200         {
1201                 __isNoTitleGroup = true;
1202         }
1203
1204         if (pNode->GetType().Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
1205         {
1206                 ItemTypeOneLine(itemMainRectangle);
1207                 itemHeight = itemMainRectangle.height;
1208         }
1209
1210         if ((pNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
1211         {
1212                 String* value = pNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1213                 String expendList;
1214
1215                 AppLogDebug("groupText [%ls] value [%ls]", groupText->GetPointer(), value->GetPointer());
1216
1217                 pNode->RegisterObserverlistener(__pIOAppSetting);
1218
1219                 pItem->Construct(Dimension(itemMainRectangle.width, itemMainRectangle.height));
1220                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
1221
1222                 expendList.Append(groupText->GetPointer());
1223                 expendList.Append(L" : ");
1224                 expendList.Append(value->GetPointer());
1225
1226                 delete value;
1227
1228                 pLabel = new (std::nothrow) Label();
1229                 pLabel->Construct(itemMainRectangle, expendList);
1230                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1231                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1232                 pLabel->SetName(pNode->GetId());
1233
1234                 pItem->AddControl(pLabel);
1235                 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1236                 pItem->SetEnabled(true);
1237                 delete groupText;
1238                 return pItem;
1239         }
1240         else
1241         {
1242                 pItem->Construct(Dimension(itemWidth, itemHeight));
1243                 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
1244
1245                 Label* pLabel = new (std::nothrow) Label();
1246
1247                 pLabel->Construct(itemMainRectangle, (*groupText).GetPointer());
1248                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1249                 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
1250
1251                 pItem->AddControl(pLabel);
1252
1253                 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
1254                 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
1255
1256                 pItem->SetEnabled(false);
1257
1258                 delete groupText;
1259                 return pItem;
1260         }
1261 }
1262
1263 TableViewItem*
1264 AppSettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
1265 {
1266         Rectangle itemMainRectangle;
1267         Label* pLabel = null;
1268         String itemType;
1269         String* itemText = null;
1270
1271         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
1272
1273         unsigned int hashCode = GetTranslateTableIndexToHashCode(groupIndex, itemIndex);
1274
1275         Node* pItemNode = GetItemHashCodeMap(hashCode);
1276         if (pItemNode == null)
1277         {
1278                 result r = __pGroupItemNodeList->GetAt(groupIndex, pItemNode);
1279                 if (IsFailed(r))
1280                 {
1281                         AppLogDebug("pItemNode is null");
1282                         return null;
1283                 }
1284
1285                 pItemNode = GetItemHashCodeMap(pItemNode->GetId().GetHashCode());
1286                 if (pItemNode == null)
1287                 {
1288                         AppLogDebug("pItemNode is null");
1289                         return null;
1290                 }
1291         }
1292
1293         TableViewItem* pItem = new (std::nothrow) TableViewItem();
1294
1295         itemText = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
1296         itemType = pItemNode->GetType();
1297         ItemTypeOneLine(itemMainRectangle);
1298
1299         if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_BOOL, false))
1300         {
1301                 bool toggleValue = false;
1302                 String* valueString = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1303
1304                 pItemNode->RegisterObserverlistener(__pIOAppSetting);
1305
1306                 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
1307
1308                 RelativeLayout relativeLayout;
1309                 relativeLayout.Construct();
1310
1311                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
1312                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
1313
1314                 pLabel = new (std::nothrow) Label();
1315                 pLabel->Construct(itemMainRectangle, (itemText)->GetPointer());
1316                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1317                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1318
1319                 pItem->AddControl(pLabel);
1320                 relativeLayout.SetMargin(*pLabel, 0, 150, 0, 0);
1321                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
1322                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
1323
1324                 
1325                 toggleValue = Boolean::Parse((*valueString).GetPointer(), true);
1326
1327                 if ((toggleValue != false) || (*valueString == DEFAULT_VALUE_STRING))
1328                 {
1329                         __pTableView->SetItemChecked(groupIndex, itemIndex, true);
1330                 }
1331                 delete valueString;
1332         }
1333         else if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_INTEGER, false))
1334         {
1335                 Slider* pSlider = null;
1336                 int minValue = 0;
1337                 int maxValue = 0;
1338                 int setValue = 0;
1339
1340                 pItemNode->RegisterObserverlistener(__pIOAppSetting);
1341
1342                 itemMainRectangle.width = (itemWidth - ITEM_WIDTH_GAP);
1343                 itemMainRectangle.height = H_GROUP_ITEM_DEFAULT_SLIDER;
1344
1345                 RelativeLayout relativeLayout;
1346                 relativeLayout.Construct();
1347                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
1348                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
1349
1350                 String* minValueString = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MIN);
1351                 String* maxValueString = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MAX);
1352                 String* setValueString = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1353
1354                 Integer::Parse((*minValueString).GetPointer(), minValue);
1355                 Integer::Parse((*maxValueString).GetPointer(), maxValue);
1356                 Integer::Parse((*setValueString).GetPointer(), setValue);
1357
1358                 pSlider = new (std::nothrow) Slider();
1359                 result r = pSlider->Construct(itemMainRectangle, BACKGROUND_STYLE_NONE, true, minValue, maxValue);
1360                 if (IsFailed(r))
1361                 {
1362                         delete minValueString;
1363                         delete maxValueString;
1364                         delete setValueString;
1365                         delete itemText;
1366                         delete pSlider;
1367                         return null;
1368                 }
1369                 pSlider->SetTitleText((*itemText).GetPointer());
1370                 pSlider->SetValue(setValue);
1371                 pSlider->AddAdjustmentEventListener(*this);
1372                 pSlider->AddSliderEventListener(*this);
1373                 pSlider->SetName(pItemNode->GetId());
1374
1375                 pItem->AddControl(pSlider);
1376                 pItem->SetIndividualSelectionEnabled(pSlider, true);
1377                 relativeLayout.SetMargin(*pSlider, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
1378                 relativeLayout.SetRelation(*pSlider, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
1379                 relativeLayout.SetRelation(*pSlider, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
1380
1381                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
1382                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1383                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED);
1384                 delete minValueString;
1385                 delete maxValueString;
1386                 delete setValueString;
1387         }
1388         else if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_STRING, false))
1389         {
1390                 itemMainRectangle.x = 0;
1391                 int stringLengthMin = 0;
1392                 int stringLengthMax = 0;
1393
1394                 String* pMinLength = static_cast<String*>(pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MIN_LENGTH));
1395                 if (pMinLength != null)
1396                 {
1397                         Integer::Parse(*pMinLength, stringLengthMin);
1398                         delete pMinLength;
1399                         AppLogDebug("max String size [%d]", stringLengthMin);
1400                 }
1401
1402                 String* pMaxLength = static_cast<String*>(pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MAX_LENGTH));
1403                 if (pMaxLength != null)
1404                 {
1405                         Integer::Parse(*pMaxLength, stringLengthMax);
1406                         delete pMaxLength;
1407                         AppLogDebug("max String size [%d]", stringLengthMax);
1408                 }
1409
1410                 if (stringLengthMax == 0)
1411                 {
1412                         delete pItem;
1413                         delete itemText;
1414                         return null;
1415                 }
1416                 RelativeLayout relativeLayout;
1417                 relativeLayout.Construct();
1418                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
1419                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
1420
1421                 pItemNode->RegisterObserverlistener(__pIOAppSetting);
1422
1423                 String id = pItemNode->GetId();
1424                 String setActionIdDone(id);
1425                 String setActionIdCancel(id);
1426
1427                 setActionIdDone.Append(ID_POST_FIX_BUTTON_DONE);
1428                 setActionIdCancel.Append(ID_POST_FIX_BUTTON_CANCEL);
1429
1430                 EditField* pEditField = new (std::nothrow) EditField();
1431                 String* secondLine = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1432
1433                 itemMainRectangle.x = X_GROUP_DEFAULT;
1434                 pEditField->Construct(Rectangle(itemMainRectangle.x, itemMainRectangle.y+H_ITEM_TYPE_GAP, itemMainRectangle.width,itemMainRectangle.height-Y_GROUP_ITEM_DEFAULT), EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, EDIT_FIELD_TITLE_STYLE_TOP, true, stringLengthMax, GROUP_STYLE_NONE);
1435                 pEditField->SetGuideText((*itemText).GetPointer());
1436                 pEditField->SetTitleText((*itemText).GetPointer());
1437                 pEditField->SetText((*secondLine).GetPointer());
1438                 delete secondLine;
1439
1440                 pEditField->SetTextSize(FONT_SIZE_SUB_TEXT);
1441                 pEditField->SetTitleTextColor(EDIT_STATUS_NORMAL, COLOR_HELP_TEXT_TYPE_01);
1442                 pEditField->SetTitleTextColor(EDIT_STATUS_PRESSED, COLOR_HELP_TEXT_TYPE_01);
1443                 pEditField->SetTitleTextColor(EDIT_STATUS_HIGHLIGHTED, COLOR_HELP_TEXT_TYPE_01);
1444                 pEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_BG_GROUP_ITEM_DEFAULT);
1445                 pEditField->SetColor(EDIT_STATUS_PRESSED, COLOR_BG_GROUP_ITEM_DEFAULT);
1446                 pEditField->SetColor(EDIT_STATUS_HIGHLIGHTED, COLOR_BG_GROUP_ITEM_DEFAULT);
1447                 pEditField->SetColor(EDIT_STATUS_DISABLED, COLOR_BG_GROUP_ITEM_DEFAULT);
1448                 pEditField->AddActionEventListener(*this);
1449                 pEditField->AddTextEventListener(*this);
1450                 pEditField->SetName(id);
1451                 pEditField->AddKeypadEventListener(*this);
1452
1453                 pItem->AddControl(pEditField);
1454                 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1455                 pItem->SetIndividualSelectionEnabled(pEditField, true);
1456
1457                 relativeLayout.SetMargin(*pEditField, Y_GROUP_ITEM_DEFAULT, 0, 0, 0);
1458                 relativeLayout.SetRelation(*pEditField, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
1459                 relativeLayout.SetRelation(*pEditField, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
1460         }
1461         else if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_LABEL, false))
1462         {
1463                 pItem->Construct(Dimension(itemWidth, itemMainRectangle.height), style);
1464                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
1465
1466                 pLabel = new (std::nothrow) Label();
1467                 pLabel->Construct(itemMainRectangle, (itemText)->GetPointer());
1468                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1469                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1470                 pLabel->SetName(pItemNode->GetId());
1471                 pItem->AddControl(pLabel);
1472                 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1473         }
1474         else if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
1475         {
1476                 IEnumerator* pCurrentIEnumerator =  pItemNode->GetCurrentIEnumerator();
1477
1478                 if (!((pCurrentIEnumerator != null)
1479                         && (pCurrentIEnumerator->MoveNext() == E_SUCCESS)))
1480                 {
1481                         AppLogDebug("Expandlist has no expandItems & remove");
1482                         delete pCurrentIEnumerator;
1483                         delete pItem;
1484                         delete itemText;
1485                         return null;
1486                 }
1487
1488                 String* value = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1489                 String expendList;
1490
1491                 pItemNode->RegisterObserverlistener(__pIOAppSetting);
1492
1493                 pItem->Construct(Dimension(itemWidth, itemMainRectangle.height), style);
1494                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
1495
1496                 expendList.Append(itemText->GetPointer());
1497                 expendList.Append(L" : ");
1498                 expendList.Append(value->GetPointer());
1499
1500                 delete value;
1501
1502                 pLabel = new (std::nothrow) Label();
1503                 pLabel->Construct(itemMainRectangle, expendList);
1504                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1505                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1506                 pLabel->SetName(pItemNode->GetId());
1507
1508                 pItem->AddControl(pLabel);
1509                 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1510         }
1511         else if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_ITEM, false))
1512         {
1513                 style = TABLE_VIEW_ANNEX_STYLE_RADIO;
1514
1515                 RelativeLayout relativeLayout;
1516                 relativeLayout.Construct();
1517                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), style);
1518                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_LISTITEM);
1519
1520                 Node* parent = pItemNode->GetParent();
1521
1522                 String* pParentValue = (parent->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE));
1523                 String* pCurrentValue = (pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE));
1524
1525                 if (pCurrentValue->Equals(*pParentValue, true))
1526                 {
1527                         __pTableView->SetItemChecked(groupIndex, itemIndex, true);
1528                 }
1529
1530                 pLabel = new (std::nothrow) Label();
1531                 pLabel->Construct(itemMainRectangle, (itemText)->GetPointer());
1532                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1533                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1534
1535                 pItem->AddControl(pLabel);
1536                 delete pParentValue;
1537                 delete pCurrentValue;
1538                 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
1539                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
1540                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
1541         }
1542         else if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_SEPARATOR, false))
1543         {
1544                 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_SEPARATOR);
1545                 itemMainRectangle.height = H_GROUP_INDEX_NO_TITLE_DEFAULT;
1546
1547                 if (pBitmap == null)
1548                 {
1549                         AppLogDebug("bitmap is null ");
1550                         AppLogDebug("separator id [%ls]", pItemNode->GetId().GetPointer());
1551                 }
1552
1553                 RelativeLayout relativeLayout;
1554                 relativeLayout.Construct();
1555                 pItem->Construct(relativeLayout, Dimension(itemWidth, itemMainRectangle.height), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1556
1557                 pLabel = new (std::nothrow) Label();
1558                 pLabel->Construct(itemMainRectangle, L" ");
1559                 pLabel->SetBackgroundBitmap(*pBitmap);
1560                 pItem->AddControl(pLabel);
1561
1562                 delete pBitmap;
1563                 pItem->SetEnabled(false);
1564
1565                 relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_RIGHT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
1566                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
1567                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
1568         }
1569         else
1570         {
1571                 AppLogDebug("pItem is null");
1572                 delete itemText;
1573                 delete pItem;
1574                 return null;
1575         }
1576         delete itemText;
1577         return pItem;
1578 }
1579
1580 bool
1581 AppSettingForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
1582 {
1583         delete pItem;
1584         pItem = null;
1585
1586         return true;
1587 }
1588
1589 bool
1590 AppSettingForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
1591 {
1592         delete pItem;
1593         pItem = null;
1594
1595         return true;
1596 }
1597
1598 void
1599 AppSettingForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1600 {
1601         unsigned int hashCode = GetTranslateTableIndexToHashCode(groupIndex, itemIndex);
1602         AppLogDebug("%d %d", groupIndex, itemIndex);
1603         Node* pItemNode = GetItemHashCodeMap(hashCode);
1604         if (pItemNode == null)
1605         {
1606                 AppLogDebug("pItemNode is null");
1607                 return;
1608         }
1609
1610         if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_ITEM, false))
1611         {
1612                 ElementNode* pParent = dynamic_cast<ElementNode*>(pItemNode->GetParent());
1613                 if (pParent == null)
1614                 {
1615                         AppLogDebug("pParent is null");
1616                         return;
1617                 }
1618
1619                 if (!pParent->GetType().Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
1620                 {
1621                         AppLogDebug("pParent is not ITEM_TYPE_EXPAND_LIST");
1622                         return;
1623                 }
1624
1625                 String* pValue = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
1626                 if (pValue == null)
1627                 {
1628                         AppLogDebug("pValue is null");
1629                         return;
1630                 }
1631
1632                 pParent->SetAttribute(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE, *pValue);
1633                 delete pValue;
1634
1635                 unsigned int hashCode = pParent->GetId().GetHashCode();
1636                 ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
1637
1638                 if (itemTag == null)
1639                 {
1640                         int itemCount = __pTableView->GetItemCountAt(groupIndex);
1641
1642                         for (int count = 0; count < itemCount; count++)
1643                         {
1644                                 bool itemSelectStatus = false;
1645                                 if (count == itemIndex)
1646                                 {
1647                                         itemSelectStatus = true;
1648                                 }
1649                                 __pTableView->SetItemChecked(groupIndex, count, itemSelectStatus);
1650                         }
1651                         RefreshExpandListItem(groupIndex);
1652
1653                         Invalidate(true);
1654                         return;
1655                 }
1656
1657                 int loopCount = pParent->GetChildCount() + itemTag->GetItemIndex() + APPSETTING_DEFAULT_COUNT;
1658
1659                 for (int pos = itemTag->GetItemIndex() + APPSETTING_DEFAULT_COUNT; pos < loopCount; pos++)
1660                 {
1661                         if (pos != itemIndex)
1662                         {
1663                                 __pTableView->SetItemChecked(groupIndex, pos, false);
1664                         }
1665                         else
1666                         {
1667                                 __pTableView->SetItemChecked(groupIndex, pos, true);
1668                         }
1669                 }
1670                 __pTableView->RefreshItem(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1671
1672                 if (__pIOAppSetting != null)
1673                 {
1674                         __pIOAppSetting->UpdateChangedValue();
1675                 }
1676
1677                 Invalidate(true);
1678                 //pItem->SetFocus();
1679         }
1680         else if (pItemNode->GetType().Equals(ID_APPSETTING_ITEM_TYPE_BOOL, false))
1681         {
1682                 bool itemSelectStatus = tableView.IsItemChecked(groupIndex, itemIndex);
1683
1684                 if (status == TABLE_VIEW_ITEM_STATUS_SELECTED)
1685                 {
1686                         itemSelectStatus = (!itemSelectStatus);
1687                 }
1688                 tableView.SetItemChecked(groupIndex, itemIndex, itemSelectStatus);
1689                 pItemNode->SetAttribute(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE, Boolean::ToString(itemSelectStatus));
1690
1691                 if (__pIOAppSetting != null)
1692                 {
1693                         __pIOAppSetting->UpdateChangedValue();
1694                 }
1695                 //pItem->SetFocus();
1696         }
1697         else
1698         {
1699                 AppLogDebug("null");
1700                 //pItem->SetFocus();
1701         }
1702 }
1703
1704 void
1705 AppSettingForm::OnActionPerformed(const Control& source, int actionId)
1706 {
1707         String sourceNametmp(source.GetName());
1708         String sourceName(L"");
1709
1710         StringTokenizer stringTokenizer(sourceNametmp, L":");
1711         stringTokenizer.GetNextToken(sourceName);
1712
1713         Node* pNode = GetItemHashCodeMap(sourceName.GetHashCode());
1714         if (pNode == null)
1715         {
1716                 AppLogDebug("pNode is null");
1717                 return;
1718         }
1719 }
1720
1721 int
1722 AppSettingForm::GetDefaultGroupItemHeight(void)
1723 {
1724         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
1725 }
1726
1727 int
1728 AppSettingForm::GetDefaultItemHeight(void)
1729 {
1730         return H_GROUP_ITEM_DEFAULT;
1731 }
1732
1733 void
1734 AppSettingForm::RefreshExpandListItem(int groupIndex)
1735 {
1736         int itemCount = __pTableView->GetItemCountAt(groupIndex);
1737
1738         for (int count = -1; count < itemCount; count++)
1739         {
1740                 __pTableView->RefreshItem(groupIndex, count, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1741         }
1742 }
1743
1744 void
1745 AppSettingForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
1746 {
1747         AppLog("Enter");
1748         Node* pNode = null;
1749         __pGroupItemNodeList->GetAt(groupIndex, pNode);
1750
1751         if (pNode->GetType().Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
1752         {
1753                 Label* pLabel = static_cast<Label*>(pItem->GetControl(0));
1754                 String expandList;
1755
1756                 String* groupText = pNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
1757                 String* value = pNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1758
1759                 expandList.Append(groupText->GetPointer());
1760                 expandList.Append(L" : ");
1761                 expandList.Append(value->GetPointer());
1762
1763                 AppLogDebug("itemChanged [%ls]", expandList.GetPointer());
1764                 pLabel->SetText(expandList);
1765                 pLabel->Invalidate(false);
1766                 delete groupText;
1767                 delete value;
1768         }
1769         pItem->Invalidate(false);
1770 }
1771
1772 void
1773 AppSettingForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
1774 {
1775         AppLog("Enter");
1776         unsigned int hashCode = GetTranslateTableIndexToHashCode(groupIndex, itemIndex);
1777         Node* pItemNode = GetItemHashCodeMap(hashCode);
1778         if (pItemNode == null)
1779         {
1780                 AppLogDebug("GetItemHashCodeMap is null");
1781                 return;
1782         }
1783
1784         Label* pLabel = static_cast<Label*>(pItem->GetControl(pItemNode->GetId(), false));
1785         if (pLabel != null)
1786         {
1787                 pLabel->SetSize(GetClientAreaBounds().width - TWO_LINE_ITEM_WIDTH_GAP,pLabel->GetHeight());
1788         }
1789         
1790         if (!pItemNode->GetType().Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
1791         {
1792                 if (pItemNode->GetType().Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_ITEM, false))
1793                 {
1794                         AppLogDebug("pItemNode->GetType not equal ID_APPSETTING_ITEM_TYPE_EXPAND_LIST [%ls]", pItemNode->GetType().GetPointer());
1795                         pItem->Invalidate(false);
1796                 }
1797                 else if ((pItemNode->GetType()).Equals(ID_APPSETTING_ITEM_TYPE_INTEGER, false))
1798                 {
1799                         Slider* pSlider = static_cast<Slider*>(pItem->GetControl(0));
1800                         pItem->SetIndividualSelectionEnabled(pSlider, true);
1801                 }
1802                 return;
1803         }
1804
1805         String* pTitle = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
1806         String* pValue = pItemNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
1807         if (pValue == null || pTitle == null)
1808         {
1809                 AppLogDebug("GetAttributeN is null");
1810                 delete pValue;
1811                 delete pTitle;
1812                 return;
1813         }
1814
1815         if (pLabel != null)
1816         {
1817                 String expendList(*pTitle);
1818                 expendList.Append(L" : ");
1819                 expendList.Append(*pValue);
1820
1821                 pLabel->SetText(expendList);
1822                 pLabel->Invalidate(false);
1823         }
1824
1825         pItem->Invalidate(false);
1826         delete pTitle;
1827         delete pValue;
1828 }
1829
1830 void
1831 AppSettingForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
1832 {
1833 }
1834
1835 void
1836 AppSettingForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1837 {
1838 }
1839
1840 void
1841 AppSettingForm::OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjustment)
1842 {
1843         String sourceName = source.GetName();
1844
1845         Node* pNode = GetItemHashCodeMap(sourceName.GetHashCode());
1846         if (pNode == null)
1847         {
1848                 AppLogDebug("pNode is null");
1849                 return;
1850         }
1851
1852         pNode->SetAttribute(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE, Integer::ToString(adjustment));
1853         
1854         if (__pIOAppSetting != null)
1855         {
1856                 __pIOAppSetting->UpdateChangedValue();
1857         }
1858 }
1859
1860 void
1861 AppSettingForm::OnSliderBarMoved(Tizen::Ui::Controls::Slider& source, int value)
1862 {
1863         //source.SetFocus();
1864 }
1865
1866 void
1867 AppSettingForm::OnTextValueChanged(const Tizen::Ui::Control& source)
1868 {
1869         String sourceName = source.GetName();
1870         String changedText;
1871         Node* pNode = GetItemHashCodeMap(sourceName.GetHashCode());
1872         if (pNode == null)
1873         {
1874                 AppLogDebug("pNode is null");
1875                 return;
1876         }
1877
1878         EditField* pEditField = static_cast<EditField*>(&const_cast<Control&>(source));
1879
1880         if (pEditField)
1881         {
1882                 changedText = pEditField->GetText();
1883         }
1884
1885         pNode->SetAttribute(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE, changedText);
1886
1887         String* pMin = pNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MIN_LENGTH);
1888         String* pMax = pNode->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_MAX_LENGTH);
1889
1890         int minLength = 0;
1891         int maxLength = 0;
1892         int currentLength = pEditField->GetTextLength();
1893
1894         Integer::Parse(*pMin, minLength);
1895         Integer::Parse(*pMax, maxLength);
1896
1897         if ((minLength <= currentLength) && (maxLength >= currentLength))
1898         {
1899                 if (__pIOAppSetting != null)
1900                 {
1901                         AppLogDebug(" current[%d]  min [%d] max[%d]", currentLength, minLength, maxLength);
1902                         __pIOAppSetting->UpdateChangedValue();
1903                 }
1904         }
1905
1906         delete pMin;
1907         delete pMax;
1908 }
1909
1910 void
1911 AppSettingForm::OnKeypadOpened(Tizen::Ui::Control& source)
1912 {
1913         unsigned int hashCode = source.GetName().GetHashCode();
1914         ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
1915         if (itemTag)
1916         {
1917                 __pTableView->ScrollToItem(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
1918         }
1919 }
1920
1921 void
1922 AppSettingForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1923 {
1924 }
1925
1926 void
1927 AppSettingForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
1928 {
1929         AppLog("Enter");
1930         if (__pTableView == null)
1931         {
1932                 Label* pLabel = static_cast<Label*>(GetControl(L"InvalidFormat"));
1933
1934                 if (pLabel)
1935                 {
1936                         Rectangle clientRect = GetClientAreaBounds();
1937                         Rectangle labelRect = pLabel->GetBounds();
1938
1939                         labelRect = clientRect;
1940                         labelRect.y = 0;
1941
1942                         pLabel->SetBounds(labelRect);
1943                         pLabel->Invalidate(false);
1944                 }
1945                 return;
1946         }
1947         if (__pTableView)
1948         {
1949                 __pTableView->RefreshAllItems();
1950         }
1951         Invalidate(true);
1952 }
1953
1954 void
1955 AppSettingForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
1956 {
1957         AppLog("Enter");
1958         result r = E_SUCCESS;
1959         Enumerator* pEnum = null;
1960         Node* pRootNode = null;
1961
1962         if (requestId == BACK_GROUND_EVENT)
1963         {
1964                 RemoveAllGroupItemNodeList();
1965                 RemoveAllItemHashCodeMap();
1966                 RemoveAllTranslateTableIndexToHashCode();
1967                 RemoveAllTranslateTableHashCodeToItemTag();
1968                 RemoveIOAppSetting();
1969
1970                 __pAppSettingManager->RemoveAppSettingRootNode(__appId);
1971                 __pAppSettingManager = null;
1972
1973                 AppLog("App going to background");
1974                 SetFocus();
1975                 return;
1976         }
1977         else
1978         {
1979                 AppLog("__appId = %S __filePath = %S",__appId.GetPointer(), __filePath.GetPointer());
1980                 r = AppSettingManagerInit(__appId, __filePath);
1981                 TryCatch(r == E_SUCCESS, , "AppSettingManagerInit fail [%s]", GetErrorMessage(r));
1982
1983                 InitItemHashCodeMap();
1984                 r = SetGroupItemNodeList(__appId);
1985                 TryCatch(r == E_SUCCESS, , "SetGroupItemNodeList fail");
1986
1987                 r = MakeTranslateTable();
1988                 TryCatch(r == E_SUCCESS, , "MakeTranslateTable fail");
1989
1990                 IOAppSettingInit(__appId);
1991
1992                 SetHeaderTitle();
1993
1994                 __pTableView->UpdateTableView();
1995                 __pTableView->SetFocus();
1996                 pRootNode = __pAppSettingManager->GetAppSettingRootNode(__appId);
1997                 if (pRootNode)
1998                 {
1999                         pEnum = pRootNode->CreateEnumerator();
2000                         while (pEnum->MoveNext() == E_SUCCESS)
2001                         {
2002                                 Node* pCurrent = static_cast<Node*>(pEnum->GetCurrentObject());
2003                                 if (pCurrent->GetType().Equals(ID_APPSETTING_ITEM_TYPE_BOOL, false))
2004                                 {
2005                                         unsigned int hashCode = pCurrent->GetId().GetHashCode();
2006                                         ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
2007                                         if (itemTag == null)
2008                                         {
2009                                                 continue;
2010                                         }
2011                                         String* pValue = pCurrent->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
2012                                         if ((pValue->Equals(L"true", false))
2013                                                         || (pValue->Equals(L"1", false)))
2014                                         {
2015                                                 if(__pTableView->IsItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex()) == false)
2016                                                 {
2017                                                         AppLog("Toggle buttonToggle button ++ %d %d", itemTag->GetGroupIndex(), itemTag->GetItemIndex());
2018                                                         r = __pTableView->SetItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), true);
2019                                                         AppLog("Toggle buttonToggle button ++ result = %s", GetErrorMessage(r));
2020                                                 }
2021                                         }
2022                                         else
2023                                         {
2024                                                 if(__pTableView->IsItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex()) == true)
2025                                                 {
2026                                                         __pTableView->SetItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), false);
2027                                                                 AppLog("Toggle button --%d %d", itemTag->GetGroupIndex(), itemTag->GetItemIndex());
2028                                                 }
2029                                         }
2030                                         delete pValue;
2031                                 }
2032                                 else if (pCurrent->GetType().Equals(ID_APPSETTING_ITEM_TYPE_EXPAND_LIST, false))
2033                                 {
2034                                         int itemSelect = 0;
2035                                         ElementNode* pExpandListItem = dynamic_cast<ElementNode*>(pCurrent);
2036                                         if (pExpandListItem == null)
2037                                         {
2038                                                 continue;
2039                                         }
2040                                         String* pExpandListValue = pExpandListItem->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE);
2041                                         for (int i = 0; i < pExpandListItem->GetChildCount(); i++)
2042                                         {
2043                                                 ElementLeaf* pElementLeaf = dynamic_cast<ElementLeaf*>(pExpandListItem->GetChild(i));
2044                                                 if (pElementLeaf == null)
2045                                                 {
2046                                                         continue;
2047                                                 }
2048                                                 String* pExpandItemValue = pElementLeaf->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
2049                                                 if (!pExpandListValue->Equals(*pExpandItemValue, false))
2050                                                 {
2051                                                         delete pExpandItemValue;
2052                                                         continue;
2053                                                 }
2054                                                 itemSelect++;
2055                                                 unsigned int hashCode = pElementLeaf->GetId().GetHashCode();
2056                                                 ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
2057                                                 if (itemTag == null)
2058                                                 {
2059                                                         continue;
2060                                                 }
2061                                                 int itemCount = __pTableView->GetItemCountAt(itemTag->GetGroupIndex());
2062
2063                                                 for (int count = -1; count < itemCount; count++)
2064                                                 {
2065                                                         AppLog("Toggle button -- %d %d", itemTag->GetGroupIndex(), count);
2066                                                         if(count > 0)
2067                                                         __pTableView->SetItemChecked(itemTag->GetGroupIndex(), count, false);
2068                                                 
2069                                                 }
2070                                                 AppLog("Toggle button ++ %d %d", itemTag->GetGroupIndex(), itemTag->GetItemIndex());
2071                                                 __pTableView->SetItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), true);
2072                                                 delete pExpandItemValue;
2073                                         }
2074                                         delete pExpandListValue;
2075
2076                                         if (itemSelect == 0)
2077                                         {
2078                                                 ElementLeaf* pElementLeaf = dynamic_cast<ElementLeaf*>(pExpandListItem->GetChild(0));
2079                                                 unsigned int hashCode = pElementLeaf->GetId().GetHashCode();
2080                                                 String* value = pElementLeaf->GetAttributeN(ID_APPSETTING_ATTRIBUTE_TYPE_TITLE);
2081
2082                                                 AppLogDebug("value[%ls]", value->GetPointer());
2083                                                 ItemTag* itemTag = GetTranslateTableHashCodeToItemTag(hashCode);
2084                                                 if (itemTag == null)
2085                                                 {
2086                                                         AppLogDebug("itemTag == null");
2087                                                 }
2088                                                 __pTableView->SetItemChecked(itemTag->GetGroupIndex(), itemTag->GetItemIndex(), true);
2089                                                 pExpandListItem->SetAttribute(ID_APPSETTING_ATTRIBUTE_TYPE_VALUE, *value);
2090                                                 RefreshExpandListItem(itemTag->GetGroupIndex());
2091                                                 delete value;
2092                                         }
2093                                 }
2094                         }
2095                         delete pEnum;
2096                         return;
2097                 }
2098         }
2099
2100         CATCH:
2101         AppLog("Enter Catch");
2102         SceneManager* pSceneManager = SceneManager::GetInstance();
2103         AppAssert(pSceneManager);
2104         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
2105         if (pArgs != null)
2106         {
2107                 pArgs->RemoveAll();
2108                 delete pArgs;
2109         }
2110 }
2111
2112 void
2113 ItemTag::SetItemTag(int groupIndex, int itemIndex)
2114 {
2115         __groupIndex = groupIndex;
2116         __itemIndex = itemIndex;
2117 }
2118
2119 void
2120 ItemTag::GetItemTag(int& groupIndex, int& itemIndex)
2121 {
2122         groupIndex = __groupIndex;
2123         itemIndex = __itemIndex;
2124 }