729616aceeb59fad8ebae2d0b03ea939a9a4706b
[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         AppLogDebug("Enter");
66         SetPropagatedKeyEventListener(this);
67
68         __pEditDate = dynamic_cast<EditDate*>(GetControl(L"IDC_EDITDATE"));
69         __pEditDate->SetYearRange(Calendarbook::GetMinDateTime().GetYear() + 1, Calendarbook::GetMaxDateTime().GetYear() - 1);
70         __pEditDate->SetDate(__date);
71
72         Locales::DateTimeFormatter* pDateFormatter = ResourceManager::CreateDateFormatterN(Locales::DATE_TIME_STYLE_DEFAULT);
73         String title;
74         pDateFormatter->Format(__date, title);
75         delete pDateFormatter;
76         SetTitleText(title);
77
78         Button* pButtonDone = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_DONE"));
79         pButtonDone->SetActionId(IDA_GO_TO_DATE_POPUP_DONE);
80         pButtonDone->AddActionEventListener(*this);
81
82         Button* pButtonCancel = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_CANCEL"));
83         pButtonCancel->SetActionId(IDA_GO_TO_DATE_POPUP_CANCEL);
84         pButtonCancel->AddActionEventListener(*this);
85
86         return E_SUCCESS;
87 }
88
89 result
90 GoToDatePopup::OnTerminating(void)
91 {
92         AppLogDebug("Enter");
93         SetPropagatedKeyEventListener(null);
94         return E_SUCCESS;
95 }
96
97 void
98 GoToDatePopup::OnActionPerformed(const Control& source, int actionId)
99 {
100         switch (actionId)
101         {
102         case IDA_GO_TO_DATE_POPUP_DONE:
103                 __date = __pEditDate->GetDate();
104                 if (__pTarget)
105                 {
106                         LinkedList* pArgs = new (std::nothrow) LinkedList();
107                         pArgs->Add(new (std::nothrow) DateTime(__date));
108                         __pTarget->SendUserEvent(IDA_GO_TO_DATE_POPUP_DONE, pArgs);
109                 }
110                 SetShowState(false);
111                 break;
112         case IDA_GO_TO_DATE_POPUP_CANCEL:
113                 SetShowState(false);
114                 break;
115         }
116 }
117
118 bool
119 GoToDatePopup::OnKeyReleased(Tizen::Ui::Control &source, const Tizen::Ui::KeyEventInfo &keyEventInfo)
120 {
121         AppLogDebug("%d", keyEventInfo.GetKeyCode());
122         if (keyEventInfo.GetKeyCode() == KEY_BACK)
123         {
124                 SetShowState(false);
125         }
126
127         return false;
128 }