f79a3e81165bd2df63f49ecc79a2f6423e9c302d
[apps/osp/Calendar.git] / src / ClTwoButtonPopup.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        ClTwoButtonPopup.cpp
19  * @brief       This is the implementation file for the TwoButtonPopup class.
20  */
21
22 #include <FBase.h>
23
24 #include "ClTwoButtonPopup.h"
25 #include "ClResourceManager.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Social;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32
33 static const int IDA_EVENT_POPUP_CANCEL = 10902;
34
35 TwoButtonPopup::TwoButtonPopup(void)
36         : __pTitle(null)
37         , __pTarget(null)
38         , __pEvent(null)
39 {
40 }
41
42 TwoButtonPopup::~TwoButtonPopup(void)
43 {
44 }
45
46 result
47 TwoButtonPopup::Initialize(void)
48 {
49         result r = Construct(L"IDL_TWO_BUTTON_POPUP");
50         if (r == E_SUCCESS)
51         {
52                 __pTitle = dynamic_cast<Label*>(GetControl(L"IDC_LABEL"));
53                 AppAssertf(__pTitle != null, "[E_FAILURE] Unable to get label.");
54         }
55         return r;
56 }
57
58 void
59 TwoButtonPopup::RequestPopup(TwoButtonPopupStyle style, Control* pTarget, const CalEventInstance* pEvent)
60 {
61         switch (style)
62         {
63         case TWO_BUTTON_POPUP_STYLE_REPEATED_EVENT:
64                 __pTitle->SetText(ResourceManager::GetString(IDS_POPUP_DELETE_MULTIPLE_REPEATED_EVENT));
65                 break;
66         default:
67                 __pTitle->SetText(ResourceManager::GetString(IDS_COM_POP_DELETE_Q));
68                 break;
69         }
70
71         __pTarget = pTarget;
72
73         delete __pEvent;
74         __pEvent = (pEvent != null) ? new (std::nothrow) CalEventInstance(*pEvent) : null;
75
76         SetShowState(true);
77         Show();
78 }
79
80 result
81 TwoButtonPopup::OnInitializing(void)
82 {
83         Button* pButtonDone = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_DELETE"));
84         AppAssertf(pButtonDone != null, "[E_FAILURE] Unable to get button.");
85         pButtonDone->SetActionId(IDA_EVENT_POPUP_DELETE);
86         pButtonDone->AddActionEventListener(*this);
87
88         Button* pButtonCancel = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_CANCEL"));
89         AppAssertf(pButtonCancel != null, "[E_FAILURE] Unable to get button.");
90         pButtonCancel->SetActionId(IDA_EVENT_POPUP_CANCEL);
91         pButtonCancel->AddActionEventListener(*this);
92
93         return E_SUCCESS;
94 }
95
96 result
97 TwoButtonPopup::OnTerminating(void)
98 {
99         return E_SUCCESS;
100 }
101
102 void
103 TwoButtonPopup::OnActionPerformed(const Control& source, int actionId)
104 {
105         SetShowState(false);
106
107         if (actionId != IDA_EVENT_POPUP_CANCEL && actionId > 0 && __pTarget != null)
108         {
109                 LinkedList* pArgs = null;
110                 if (__pEvent != null)
111                 {
112                         pArgs = new (std::nothrow) LinkedList();
113                         pArgs->Add(__pEvent);
114                         __pEvent = null;
115                 }
116                 __pTarget->SendUserEvent(actionId, pArgs);
117                 __pTarget = null;
118         }
119 }