Applied latest source code
[apps/native/preloaded/Clock.git] / src / ClkCityListForm.cpp
1 //
2 //  Tizen Native SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        CityListForm.cpp
20  * @brief       Used to define CityListForm
21  */
22
23 #include <FApp.h>
24 #include <FBase.h>
25 #include <FLocales.h>
26 #include <FSystem.h>
27
28 #include "ClkAlarm.h"
29 #include "ClkAlarmPresentationModel.h"
30 #include "ClkAlarmRepeatCustomItem.h"
31 #include "ClkCityListForm.h"
32 #include "ClkClockApp.h"
33 #include "ClkCommonLib.h"
34 #include "ClkCityListCustomItem.h"
35 #include "ClkSceneRegister.h"
36 #include "ClkWorldClockPresentationModel.h"
37
38 using namespace Tizen::App;
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Base::Runtime;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Locales;
44 using namespace Tizen::Ui;
45 using namespace Tizen::Ui::Controls;
46 using namespace Tizen::Ui::Scenes;
47 using namespace Tizen::System;
48
49 const RequestId REQUEST_ID_PROCESSING = 10000;
50 const wchar_t* NO_CITYS = L"No Alarms";
51
52 static const int IDA_FOOTER_NAME_CLICKED = 101;
53 static const int IDA_FOOTER_TIME_CLICKED = 102;
54 static const int IDA_SEARCH_CANCEL_CLICKED = 103;
55
56 NameComparer::NameComparer(void)
57 {
58
59 }
60
61 NameComparer::~NameComparer(void)
62 {
63
64 }
65
66 result
67 NameComparer::Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp)const
68 {
69         result r = E_SUCCESS;
70         TimeZone *pTz1 = dynamic_cast<TimeZone*>(const_cast<Object*>(&obj1));
71         TimeZone *pTz2 = dynamic_cast<TimeZone*>(const_cast<Object*>(&obj2));
72         String cityNameTz1;
73         String areaNameTz1;
74         String cityNameTz2;
75         String areaNameTz2;
76         int separatorIndex = 0;
77
78
79         if(pTz1 == null || pTz2 == null)
80         {
81                 return E_FAILURE;
82         }
83
84         pTz1->GetId().IndexOf(L"/", 0, separatorIndex);
85         pTz1->GetId().SubString(separatorIndex + 1, cityNameTz1);
86         pTz1->GetId().SubString(0, separatorIndex, areaNameTz1);
87
88         pTz2->GetId().IndexOf(L"/", 0, separatorIndex);
89         pTz2->GetId().SubString(separatorIndex + 1, cityNameTz2);
90         pTz2->GetId().SubString(0, separatorIndex, areaNameTz2);
91
92         cmp = cityNameTz1.CompareTo(cityNameTz2);
93         return r;
94 }
95
96 TimeComparer::TimeComparer(void)
97 {
98
99 }
100 TimeComparer::~TimeComparer(void)
101 {
102
103 }
104
105 result
106 TimeComparer::Compare(const Tizen::Base::Object& obj1, const Tizen::Base::Object& obj2, int& cmp)const
107 {
108         result r = E_SUCCESS;
109         TimeZone *pTz1 = dynamic_cast<TimeZone*>(const_cast<Object*>(&obj1));
110         TimeZone *pTz2 = dynamic_cast<TimeZone*>(const_cast<Object*>(&obj2));
111
112         if(pTz1 == null || pTz2 == null)
113         {
114                 return E_FAILURE;
115         }
116
117         cmp = pTz1->GetRawOffset() - pTz2->GetRawOffset();
118         return r;
119 }
120
121 CityListForm::CityListForm()
122 : __isOperationCompleted(true)
123 , __isProcessing(false)
124 , __modalMsgBoxResult(0)
125 , __pDataList(null)
126 , __pMsgBox(null)
127 , __pNameListview(null)
128 , __pSearchBar(null)
129 , __pTimeListview(null)
130 , __pTimer(null)
131 , __searchText("")
132
133 {
134
135 }
136
137 CityListForm::~CityListForm(void)
138 {
139         if ( __pTimer != null)
140         {
141                 delete __pTimer ;
142                 __pTimer = null;
143         }
144
145         if (__pMsgBox != null)
146         {
147                 delete __pMsgBox;
148                 __pMsgBox = null;
149         }
150 }
151
152 bool
153 CityListForm::Initialize(void)
154 {
155         Construct(L"IDL_CITY_LIST");
156
157         return true;
158 }
159
160 result
161 CityListForm::OnInitializing(void)
162 {
163         result r = E_SUCCESS;
164         String fastScrollIndex = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
165         String fastTimeScrollIndex = L"13121110987654321";
166         GetFooter()->SetItemSelected(0);
167         GetFooter()->AddActionEventListener(*this);
168         GetHeader()->SetTitleText(CommonUtil::GetString("IDS_WCL_HEADER_SELECT_TIME_ZONE"));
169
170         SetFormBackEventListener(this);
171         AddOrientationEventListener(*this);
172
173         SceneManager::GetInstance()->AddSceneEventListener(IDSCN_CITY_LIST, *this);
174
175         ClockApp* pClock = static_cast<ClockApp*>(ClockApp::GetInstance());
176         int heightOffset = pClock->GetHeightOffset();
177
178         __pSearchBar = dynamic_cast<SearchBar*>(GetControl(L"IDC_CITY_SEARCHBAR"));
179
180         if(__pSearchBar != null)
181         {
182                 __pSearchBar->AddActionEventListener(*this);
183                 __pSearchBar->AddSearchBarEventListener(*this);
184                 __pSearchBar->AddKeypadEventListener(*this);
185                 __pSearchBar->AddTextEventListener(*this);
186                 __pSearchBar->AddFocusEventListener(*this);
187         }
188
189         __pNameListview = dynamic_cast<ListView*>(GetControl(L"IDC_CITY_LISTVIEW"));
190
191         if(__pNameListview == null)
192         {
193                 return E_FAILURE;
194         }
195         __pNameListview->SetItemProvider(*this);
196         __pNameListview->AddListViewItemEventListener(*this);
197         __pNameListview->SetFastScrollIndex(fastScrollIndex, false);
198         __pNameListview->AddFastScrollListener(*this);
199
200
201         __pTimeListview = new ListView();
202
203         if(__pTimeListview == null)
204         {
205                 return E_FAILURE;
206         }
207
208         __pTimeListview->Construct(Rectangle(__pNameListview->GetX(), __pSearchBar->GetY() + __pSearchBar->GetHeight() + heightOffset, __pNameListview->GetWidth(), GetClientAreaBounds().height - __pSearchBar->GetHeight()- heightOffset), true, SCROLL_STYLE_FADE_OUT);
209         __pTimeListview->SetItemProvider(*this);
210         __pTimeListview->AddListViewItemEventListener(*this);
211         __pTimeListview->SetShowState(false);
212         __pTimeListview->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_COM_BODY_NO_SEARCH_RESULTS"));
213         AddControl(__pTimeListview);
214
215         __pTimer = new (std::nothrow) Timer();
216
217         if (__pTimer == null)
218         {
219                 return E_FAILURE;
220         }
221
222         r = __pTimer->Construct(*this);
223
224         return r;
225 }
226
227 result
228 CityListForm::OnTerminating(void)
229 {
230         __isOperationCompleted = true;
231         return E_SUCCESS;
232 }
233
234 void
235 CityListForm::OnActionPerformed(const Control& source, int actionId)
236 {
237         AppLogDebug("CityListForm::OnActionPerformed actionId = %d",actionId);
238         String fastScrollIndexName = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
239
240         switch (actionId)
241         {
242         case IDA_SEARCH_CANCEL_CLICKED:
243         {
244                 AppLog("came here");
245                 __searchText = L"";
246                 __pSearchBar->HideKeypad();
247                 __pSearchBar->Clear();
248
249                 if(__pNameListview->GetShowState())
250                 {
251                         __pNameListview->SetEnabled(true);
252                         __pNameListview->UpdateList();
253                 }
254                 else
255                 {
256                         __pTimeListview->SetEnabled(true);
257                         __pTimeListview->UpdateList();
258                 }
259
260         }
261         break;
262
263         case IDA_FOOTER_NAME_CLICKED:
264         {
265                 __pTimeListview->SetShowState(false);
266                 __pNameListview->SetShowState(true);
267
268                 if(__pDataList)
269                 {
270                         __pNameListview->UpdateList();
271                 }
272
273                 if(__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
274                 {
275                         if (__searchText != "")
276                         {
277                                 __pNameListview->SetEnabled(true);
278                         }
279                         __pSearchBar->SetMode(SEARCH_BAR_MODE_INPUT);
280                 }
281                 else
282                 {
283                         __pNameListview->SetEnabled(true);
284                         __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
285                 }
286                 __pNameListview->SetFastScrollIndex(fastScrollIndexName, false);
287
288         }
289         break;
290
291         case IDA_FOOTER_TIME_CLICKED:
292         {
293                 __pTimeListview->SetBounds(__pTimeListview->GetX(), __pSearchBar->GetY() + __pSearchBar->GetHeight(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
294
295                 __pNameListview->SetShowState(false);
296                 __pTimeListview->SetShowState(true);
297
298                 if(__pDataList)
299                 {
300                         __pTimeListview->UpdateList();
301                 }
302
303                 if(__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
304                 {
305                         if (__searchText != "")
306                         {
307                                 __pTimeListview->SetEnabled(true);
308                         }
309                         __pSearchBar->SetMode(SEARCH_BAR_MODE_INPUT);
310                 }
311                 else
312                 {
313                         __pTimeListview->SetEnabled(true);
314                         __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
315                 }
316                 //__pTimeListview->SetFastScrollIndex(fastScrollIndexTime, false);
317
318         }
319         break;
320
321         default:
322                 break;
323         };
324
325         Invalidate(true);
326
327 }
328
329 void
330 CityListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
331 {
332         String fontSizeStr = "";
333         int fontSize = 0;
334         SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
335
336         if(fontSizeStr == "medium")
337         {
338                 fontSize = 44;
339         }
340         else if(fontSizeStr == "huge")
341         {
342                 fontSize = 81;
343
344         }
345         else if(fontSizeStr == "giant")
346         {
347                 fontSize = 98;
348         }
349         else if(fontSizeStr == "small")
350         {
351                 fontSize = 36;
352         }
353         else if(fontSizeStr == "large")
354         {
355                 fontSize = 64;
356         }
357         else
358         {
359                 fontSize = 44;
360         }
361
362
363         __pTimeListview->SetBounds(__pTimeListview->GetX(), __pSearchBar->GetY() + __pSearchBar->GetHeight(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
364
365         Invalidate(true);
366 }
367
368 void
369 CityListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
370 {
371
372 }
373
374 void
375 CityListForm::OnFormBackRequested(Form& source)
376 {
377         AppLog("CityListForm::OnFormBackRequested");
378
379         if (__pSearchBar->GetMode() == SEARCH_BAR_MODE_NORMAL)
380         {
381                 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition());
382         }
383         else
384         {
385                 __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
386         }
387
388 }
389
390 ListItemBase *
391 CityListForm::CreateItem(int index, int itemWidth)
392 {
393         AppLog("CityListForm::CreateItem");
394         int itemHeight = 124;
395         int separatorIndex;
396         CityListCustomItem *pItem = new CityListCustomItem();
397         String cityName;
398         String areaName;
399         String gmtValue = L"GMT ";
400         AppLog("before cast index is %d", index);
401         TimeZone *pTimeZone = dynamic_cast<TimeZone*>(__pDataList->GetAt(index));
402         bool searchBarModeOn = false;
403
404         String fontSizeStr = "";
405         int fontSize = 0;
406         SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
407
408         if(fontSizeStr == "medium")
409         {
410                 fontSize = 44;
411         }
412         else if(fontSizeStr == "huge")
413         {
414                 fontSize = 81;
415
416         }
417         else if(fontSizeStr == "giant")
418         {
419                 fontSize = 98;
420         }
421         else if(fontSizeStr == "small")
422         {
423                 fontSize = 36;
424         }
425         else if(fontSizeStr == "large")
426         {
427                 fontSize = 64;
428         }
429         else
430         {
431                 fontSize = 44;
432         }
433
434         itemHeight += fontSize-44;
435
436         if ( pTimeZone == NULL)
437         {
438                 if( pItem != NULL)
439                 {
440                         delete pItem;
441                         pItem = NULL;
442                 }
443                 return null;
444         }
445
446         AppLog("after cast");
447         int offset = pTimeZone->GetRawOffset();
448
449         if(__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
450                 searchBarModeOn = true;
451         else
452                 searchBarModeOn = false;
453
454
455         result r = pItem->Construct(GetClientAreaBounds().width, itemHeight, searchBarModeOn);
456         AppLog("the result: %s",GetErrorMessage(r));
457         AppLog("Timezoneid: %ls", pTimeZone->GetId().GetPointer());
458         pTimeZone->GetId().IndexOf(L"/", 0, separatorIndex);
459         pTimeZone->GetId().SubString(separatorIndex + 1, cityName);
460         pTimeZone->GetId().SubString(0, separatorIndex, areaName);
461
462         cityName.Replace("_"," ");
463         areaName.Replace("_"," ");
464         if(offset >= 0)
465         {
466                 gmtValue.Append("+");
467         }
468         else
469         {
470                 gmtValue.Append("-");
471                 offset = 0 - offset;
472         }
473
474         gmtValue.Append(offset/60);
475
476         if (offset%60 != 0)
477         {
478                 gmtValue.Append(':');
479                 gmtValue.Append(offset%60);
480         }
481
482         pItem->SetText(cityName);
483         pItem->SetSubText(areaName);
484         pItem->SetRightSubText(gmtValue);
485         pItem->Make(__searchText,fontSize);
486
487         AppLog("CityListForm::CreateItem ending ");
488         return pItem;
489 }
490
491 bool
492 CityListForm::DeleteItem(int index, ListItemBase *pItem, int itemWidth)
493 {
494         delete pItem;
495         pItem = null;
496         return true;
497 }
498
499 int
500 CityListForm::GetItemCount(void)
501 {
502         AppLog("CityListForm::GetItemCount");
503         if(__pDataList)
504         {
505                 __pDataList->RemoveAll(true);
506         }
507
508         __pDataList = WorldClockPresentationModel::GetInstance()->GetCityList(__searchText);
509
510         if(GetFooter()->GetSelectedItemIndex() == 0)
511         {
512                 __pDataList->Sort(nameComparer);
513         }
514         else
515         {
516                 __pDataList->Sort(timeComparer);
517         }
518
519         AppLog("SearchText : %ls, Count : %d",__searchText.GetPointer(), __pDataList->GetCount());
520         return __pDataList->GetCount();
521 }
522
523 void
524 CityListForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus status)
525 {
526
527 }
528
529 void
530 CityListForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
531 {
532
533 }
534
535 void
536 CityListForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
537 {
538         result r = E_FAILURE;
539         int count ;
540         ArrayList worldClockList;
541         WorldClock* pWorldClock = null ;
542         String city;
543         String cityName;
544         WorldClockPresentationModel* pWorldClockPresentationModel = WorldClockPresentationModel::GetInstance();
545         pWorldClockPresentationModel->GetAddedClockCount(count);
546
547         // Only 20 cities allowed
548         if ( count > 20)
549         {
550                 String msg = CommonUtil::GetString(L"IDS_WCL_POP_UNABLE_TO_ADD_CITY_WORLD_CLOCK_LIST_FULL_DELETE_SOME_ITEMS_FIRST");
551                 if(__isOperationCompleted == true)
552                 {
553                         CreateMessage(msg);
554                 }
555                 return ;
556         }
557
558         pWorldClockPresentationModel->GetAddedWorldClock(0,count,worldClockList);
559
560
561
562         TimeZone *pTimeZone = dynamic_cast<TimeZone*>(__pDataList->GetAt(index));
563
564         if ( pTimeZone != null )
565         {
566                 AppLog("CityListForm::OnListViewItemStateChanged 1");
567                 int separatorIndex;
568                 pTimeZone->GetId().IndexOf(L"/", 0, separatorIndex);
569                 pTimeZone->GetId().SubString(separatorIndex + 1, cityName);
570                 String areaName;
571                 pTimeZone->GetId().SubString(0, separatorIndex, areaName);
572                 int offset = pTimeZone->GetRawOffset();
573
574                 for(int index = 0 ; index < count ; index ++)
575                 {
576                         pWorldClock = dynamic_cast< WorldClock* >(worldClockList.GetAt(index));
577
578                         if( pWorldClock == NULL)
579                         {
580                                 return ;
581                         }
582
583                         AppLog("CityListForm::OnListViewItemStateChanged 2");
584                         city = pWorldClock->GetWorldClockCity();
585                         city.Trim();
586                         cityName.Trim();
587
588                         if( city.Equals(cityName,false))
589                         {
590                                 String msg = CommonUtil::GetString(L"IDS_BODY_WORLD_CLOCK_EXIST");
591                                 if(__isOperationCompleted == true)
592                                 {
593                                         CreateMessage(msg);
594                                 }
595                                 return ;
596                         }
597                 }
598                 AppLog("CityListForm::OnListViewItemStateChanged 3 offset = %d", offset);
599                 WorldClock wc;
600                 wc.SetWorldClockCity(cityName);
601                 wc.SetWorldClockCountry(areaName);
602                 wc.SetTimeZone(offset);
603                 wc.SetDstTime(0);
604
605                 AppLog("cityName = %ls areaName = %ls offset = %d", cityName.GetPointer(), areaName.GetPointer(), offset);
606                 //save to DB
607                 r = pWorldClockPresentationModel->AddWorldClock(wc);
608                 AppLog("the result is %s", GetErrorMessage(r));
609                 if (r == E_STORAGE_FULL || r == E_INIT_FAILED || r == E_OUT_OF_MEMORY)
610                 {
611                         MessageBox msgBox;
612                         String msg = CommonUtil::GetString("IDS_MEMORY_FULL");
613                         r = msgBox.Construct(L"", msg, MSGBOX_STYLE_NONE, 3000);
614                         AppLog("the result is %s", GetErrorMessage(r));
615                         msgBox.ShowAndWait(__modalMsgBoxResult);
616                 }
617
618                 __isOperationCompleted = false;
619                 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition());
620         }
621         worldClockList.RemoveAll(true);
622 }
623
624 void
625 CityListForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
626 {
627
628 }
629
630 void
631 CityListForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, SearchBarMode mode)
632 {
633         if(mode == SEARCH_BAR_MODE_NORMAL)
634         {
635                 __searchText = L"";
636
637                 __pNameListview->SetEnabled(true);
638                 __pTimeListview->SetEnabled(true);
639                 if(__pNameListview->GetShowState())
640                 {
641                         __pNameListview->UpdateList();
642                 }
643                 else
644                 {
645                         __pTimeListview->UpdateList();
646                 }
647         }
648         else
649         {
650                 __pNameListview->SetEnabled(false);
651                 __pTimeListview->SetEnabled(false);
652                 if(__pNameListview->GetShowState())
653                 {
654                         __pNameListview->UpdateList();
655                 }
656                 else
657                 {
658                         __pTimeListview->UpdateList();
659                 }
660         }
661 }
662
663 void
664 CityListForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
665 {
666
667         if (GetFooter() != null)
668         {
669                 GetFooter()->SetShowState(true);
670                 GetFooter()->Invalidate(true);
671         }
672
673         if(__pTimeListview->GetShowState())
674         {
675                 __pTimeListview->SetBounds(__pTimeListview->GetX(), __pTimeListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
676         }
677
678         if(__pNameListview->GetShowState())
679         {
680                 __pNameListview->SetBounds(__pNameListview->GetX(), __pNameListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
681         }
682
683         Invalidate(true);
684 }
685 void
686 CityListForm::OnKeypadOpened(Tizen::Ui::Control& source)
687 {
688
689         GetFooter()->SetShowState(true);
690         GetFooter()->Invalidate(true);
691
692         __pNameListview->SetBounds(__pNameListview->GetX(), __pNameListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
693         __pTimeListview->SetBounds(__pTimeListview->GetX(), __pTimeListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
694
695         Invalidate(true);
696 }
697 void
698 CityListForm::OnKeypadClosed(Tizen::Ui::Control& source)
699 {
700         __pNameListview->SetBounds(__pNameListview->GetX(), __pNameListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
701         __pTimeListview->SetBounds(__pTimeListview->GetX(), __pTimeListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
702
703         Invalidate(true);
704 }
705
706 void
707 CityListForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
708 {
709         __pNameListview->SetBounds(__pNameListview->GetX(), __pNameListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
710         __pTimeListview->SetBounds(__pTimeListview->GetX(), __pTimeListview->GetY(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
711
712         Invalidate(true);
713 }
714
715 void
716 CityListForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
717 {
718         if(keypadAction == KEYPAD_ACTION_SEARCH)
719         {
720                 __searchText = __pSearchBar->GetText();
721
722                 if(__pNameListview->GetShowState() == true)
723                 {
724                         __pNameListview->UpdateList();
725                 }
726                 else
727                 {
728                         __pTimeListview->UpdateList();
729                 }
730
731                 __pSearchBar->HideKeypad();
732
733                 if(__searchText == L"")
734                 {
735                         AppLog("coming");
736                         __pNameListview->SetEnabled(false);
737                         __pTimeListview->SetEnabled(false);
738                 }
739
740         }
741
742         Invalidate(true);
743 }
744
745 void
746 CityListForm::OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index)
747 {
748         AppLog("OnFastScrollIndexSelected : %ls", index.GetPointer());
749         int orderby = GetFooter()->GetSelectedItemIndex();
750         int maxCount = 0;
751
752         if(__pDataList == null)
753         {
754                 return;
755         }
756         maxCount = __pDataList->GetCount();
757
758         for(int count = 0; count < maxCount; count++)
759         {
760                 TimeZone *pTimeZone = dynamic_cast<TimeZone*>(__pDataList->GetAt(count));
761
762                 if ( pTimeZone == NULL)
763                 {
764                         return;
765                 }
766
767                 if(orderby == 0)
768                 {
769                         int separatorIndex;
770                         pTimeZone->GetId().IndexOf(L"/", 0, separatorIndex);
771                         String cityName;
772                         pTimeZone->GetId().SubString(separatorIndex + 1, cityName);
773
774                         if(     cityName.StartsWith(index, 0) == true)
775                         {
776                                 __pNameListview->ScrollToItem(count);
777                                 __pNameListview->Invalidate(false);
778                                 break;
779                         }
780                 }
781         }
782 }
783
784 void
785 CityListForm::CreateMessage(String& str)
786 {
787         int modalMsgBoxResult = 0;
788
789         if (__pMsgBox != null)
790         {
791                 delete __pMsgBox;
792                 __pMsgBox = null;
793         }
794
795         __pMsgBox = new(std::nothrow) MessageBox;
796
797         if (__pMsgBox != null)
798         {
799                 __pMsgBox->Construct(L"", str, MSGBOX_STYLE_OK, 3000);
800         }
801
802         if (__pMsgBox != null)
803         {
804                 __pMsgBox->ShowAndWait(modalMsgBoxResult);
805
806                 if (__pMsgBox != null)
807                 {
808                         delete __pMsgBox;
809                         __pMsgBox = null;
810                 }
811         }
812
813
814         return;
815 }
816
817 void
818 CityListForm::OnTextValueChanged(const Control& source)
819 {
820         AppLog("CityListForm::OnTextValueChanged");
821
822         __searchText = __pSearchBar->GetText();
823
824         if (__searchText == "")
825         {
826                 __pNameListview->SetEnabled(false);
827                 __pNameListview->UpdateList();
828
829                 __pTimeListview->SetEnabled(false);
830                 __pTimeListview->UpdateList();
831         }
832         else
833         {
834                 if (__isProcessing == false)
835                 {
836                         if(__pTimer != null)
837                         {
838                                 __pTimer->Start(1);
839                         }
840                 }
841         }
842
843         AppLog("CityListForm::OnTextValueChanged end");
844 }
845
846 void
847 CityListForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
848 {
849         if (GetFooter() != null)
850         {
851                 GetFooter()->SetShowState(true);
852                 GetFooter()->Invalidate(true);
853         }
854
855         if(__pNameListview->GetShowState())
856         {
857                 __pNameListview->UpdateList();
858         }
859         else
860         {
861                 __pTimeListview->UpdateList();
862         }
863
864         String fontSizeStr = "";
865         int fontSize = 0;
866         SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
867
868         if(fontSizeStr == "medium")
869         {
870                 fontSize = 44;
871         }
872         else if(fontSizeStr == "huge")
873         {
874                 fontSize = 81;
875
876         }
877         else if(fontSizeStr == "giant")
878         {
879                 fontSize = 98;
880         }
881         else if(fontSizeStr == "small")
882         {
883                 fontSize = 36;
884         }
885         else if(fontSizeStr == "large")
886         {
887                 fontSize = 64;
888         }
889         else
890         {
891                 fontSize = 44;
892         }
893
894         __pTimeListview->SetBounds(__pTimeListview->GetX(), __pSearchBar->GetY() + __pSearchBar->GetHeight(), GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight());
895
896 }
897
898 void
899 CityListForm::OnFocusGained(const Tizen::Ui::Control& source)
900 {
901         if (__searchText == "")
902         {
903                 __pTimeListview->SetEnabled(false);
904                 __pNameListview->SetEnabled(false);
905         }
906 }
907
908 void
909 CityListForm::OnFocusLost(const Tizen::Ui::Control& source)
910 {
911         __pTimeListview->SetEnabled(true);
912         __pNameListview->SetEnabled(true);
913 }
914
915 void
916 CityListForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
917 {
918         __isProcessing = true;
919         AppLog("CityListForm::OnUserEventReceivedN");
920
921         if (requestId == REQUEST_ID_PROCESSING)
922         {
923                 if (GetFooter()->GetShowState() == false)
924                 {
925                         GetFooter()->SetShowState(true);
926                         GetFooter()->Invalidate(true);
927                 }
928
929                 __searchText = __pSearchBar->GetText();
930
931                 if (__searchText == "")
932                 {
933                         __pNameListview->SetEnabled(false);
934                         __pNameListview->UpdateList();
935
936                         __pTimeListview->SetEnabled(false);
937                         __pTimeListview->UpdateList();
938                 }
939                 else
940                 {
941                         __pNameListview->SetEnabled(true);
942                         __pNameListview->UpdateList();
943
944                         __pTimeListview->SetEnabled(true);
945                         __pTimeListview->UpdateList();
946                 }
947         }
948
949         AppLog("CityListForm::OnUserEventReceivedN end");
950         __isProcessing = false;
951 }
952
953 void
954 CityListForm::OnTimerExpired(Timer&  timer)
955 {
956         SendUserEvent(REQUEST_ID_PROCESSING, null);
957 }