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