Resolved issue N_SE-39048
[apps/osp/Calendar.git] / src / ClGoToDatePopup.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        ClGoToDatePopup.cpp
19  * @brief       This is the implementation file for the GoToDatePopup class.
20  */
21
22 #include <FLocales.h>
23 #include <FSocial.h>
24
25 #include "ClGoToDatePopup.h"
26 #include "ClResourceManager.h"
27 #include "ClTypes.h"
28
29 using namespace Tizen;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Social;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35
36 GoToDatePopup::GoToDatePopup(void)
37         : __pEditDate(null)
38         , __pTarget(null)
39 {
40 }
41
42 GoToDatePopup::~GoToDatePopup(void)
43 {
44 }
45
46 result
47 GoToDatePopup::Initialize(void)
48 {
49         return Construct(L"IDL_GO_TO_DATE_POPUP");
50 }
51
52 void
53 GoToDatePopup::RequestPopup(const DateTime& initialDate, Control* pTarget)
54 {
55         __date = initialDate;
56         __pTarget = pTarget;
57
58         SetShowState(true);
59         Show();
60 }
61
62 result
63 GoToDatePopup::OnInitializing(void)
64 {
65         __pEditDate = dynamic_cast<EditDate*>(GetControl(L"IDC_EDITDATE"));
66         __pEditDate->SetYearRange(Calendarbook::GetMinDateTime().GetYear() + 1, Calendarbook::GetMaxDateTime().GetYear() - 1);
67         __pEditDate->SetDate(__date);
68
69         Locales::DateTimeFormatter* pDateFormatter = ResourceManager::CreateDateFormatterN(Locales::DATE_TIME_STYLE_DEFAULT);
70         String title;
71         pDateFormatter->Format(__date, title);
72         delete pDateFormatter;
73         SetTitleText(title);
74
75         Button* pButtonDone = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_DONE"));
76         pButtonDone->SetActionId(IDA_GO_TO_DATE_POPUP_DONE);
77         pButtonDone->AddActionEventListener(*this);
78
79         Button* pButtonCancel = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_CANCEL"));
80         pButtonCancel->SetActionId(IDA_GO_TO_DATE_POPUP_CANCEL);
81         pButtonCancel->AddActionEventListener(*this);
82
83         return E_SUCCESS;
84 }
85
86 result
87 GoToDatePopup::OnTerminating(void)
88 {
89         return E_SUCCESS;
90 }
91
92 void
93 GoToDatePopup::OnActionPerformed(const Control& source, int actionId)
94 {
95         switch (actionId)
96         {
97         case IDA_GO_TO_DATE_POPUP_DONE:
98                 __date = __pEditDate->GetDate();
99                 if (__pTarget)
100                 {
101                         LinkedList* pArgs = new (std::nothrow) LinkedList();
102                         pArgs->Add(new (std::nothrow) DateTime(__date));
103                         __pTarget->SendUserEvent(IDA_GO_TO_DATE_POPUP_DONE, pArgs);
104                 }
105                 SetShowState(false);
106                 break;
107         case IDA_GO_TO_DATE_POPUP_CANCEL:
108                 SetShowState(false);
109                 break;
110         }
111 }