Fix for N_SE-47107
[apps/osp/Calendar.git] / src / ClThreeButtonPopup.cpp
index 14ca18c..6a35ec9 100755 (executable)
@@ -1,7 +1,7 @@
 //
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -33,10 +33,8 @@ using namespace Tizen::Ui::Controls;
 static const int IDA_EVENT_POPUP_CANCEL = 11905;
 
 ThreeButtonPopup::ThreeButtonPopup(void)
-       : __pTitle(null)
-       , __pButtonOnlyThis(null)
-       , __pButtonAllEvents(null)
-       , __pTarget(null)
+       : __pTarget(null)
+       , __pCalendarbook(null)
        , __pEvent(null)
 {
 }
@@ -48,19 +46,7 @@ ThreeButtonPopup::~ThreeButtonPopup(void)
 result
 ThreeButtonPopup::Initialize(void)
 {
-       result r = Construct(L"IDL_THREE_BUTTON_POPUP");
-       if (r == E_SUCCESS)
-       {
-               __pTitle = dynamic_cast<Label*>(GetControl(L"IDC_LABEL"));
-               AppAssertf(__pTitle != null, "[E_FAILURE] Unable to get label.");
-
-               __pButtonOnlyThis = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_ONLY_THIS_EVENT"));
-               AppAssertf(__pButtonOnlyThis != null, "[E_FAILURE] Unable to get button.");
-
-               __pButtonAllEvents = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_ALL_EVENTS"));
-               AppAssertf(__pButtonAllEvents != null, "[E_FAILURE] Unable to get button.");
-       }
-       return r;
+       return Construct(L"IDL_THREE_BUTTON_POPUP");
 }
 
 void
@@ -69,21 +55,21 @@ ThreeButtonPopup::RequestPopup(ThreeButtonPopupStyle style, Control* pTarget, co
        switch (style)
        {
        case THREE_BUTTON_POPUP_STYLE_EDIT:
-               __pTitle->SetText(ResourceManager::GetString(IDS_POPUP_EDIT_EVENT_QUESTION));
-               __pButtonOnlyThis->SetActionId(IDA_EVENT_POPUP_ONLY_THIS_EVENT_EDIT);
-               __pButtonAllEvents->SetActionId(IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_EDIT);
+               __title = ResourceManager::GetString(IDS_POPUP_EDIT_EVENT_QUESTION);
+               __buttonOnlyThisActionId = IDA_EVENT_POPUP_ONLY_THIS_EVENT_EDIT;
+               __buttonAllEventsActionId = IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_EDIT;
                break;
        case THREE_BUTTON_POPUP_STYLE_DELETE:
-               __pTitle->SetText(ResourceManager::GetString(IDS_COM_POP_DELETE_Q));
-               __pButtonOnlyThis->SetActionId(IDA_EVENT_POPUP_ONLY_THIS_EVENT_DELETE);
-               __pButtonAllEvents->SetActionId(IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_DELETE);
+               __title = ResourceManager::GetString(IDS_COM_POP_DELETE_Q);
+               __buttonOnlyThisActionId = IDA_EVENT_POPUP_ONLY_THIS_EVENT_DELETE;
+               __buttonAllEventsActionId = IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_DELETE;
                break;
        }
 
        __pTarget = pTarget;
 
        delete __pEvent;
-       __pEvent = (pEvent != null) ? new (std::nothrow) CalEventInstance(*pEvent) : null;
+       __pEvent = pEvent ? new (std::nothrow) CalEventInstance(*pEvent) : null;
 
        SetShowState(true);
        Show();
@@ -92,11 +78,24 @@ ThreeButtonPopup::RequestPopup(ThreeButtonPopupStyle style, Control* pTarget, co
 result
 ThreeButtonPopup::OnInitializing(void)
 {
-       __pButtonOnlyThis->AddActionEventListener(*this);
-       __pButtonAllEvents->AddActionEventListener(*this);
+       AppLogDebug("Enter");
+       SetPropagatedKeyEventListener(this);
+
+       __pCalendarbook = new (std::nothrow) Calendarbook();
+       __pCalendarbook->Construct(*this);
+
+       Label* pTitle = dynamic_cast<Label*>(GetControl(L"IDC_LABEL"));
+       pTitle->SetText(__title);
+
+       Button* pButtonOnlyThis = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_ONLY_THIS_EVENT"));
+       pButtonOnlyThis->SetActionId(__buttonOnlyThisActionId);
+       pButtonOnlyThis->AddActionEventListener(*this);
+
+       Button* pButtonAllEvents = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_ALL_EVENTS"));
+       pButtonAllEvents->SetActionId(__buttonAllEventsActionId);
+       pButtonAllEvents->AddActionEventListener(*this);
 
        Button* pButtonCancel = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_CANCEL"));
-       AppAssertf(pButtonCancel != null, "[E_FAILURE] Unable to get button.");
        pButtonCancel->SetActionId(IDA_EVENT_POPUP_CANCEL);
        pButtonCancel->AddActionEventListener(*this);
 
@@ -106,6 +105,11 @@ ThreeButtonPopup::OnInitializing(void)
 result
 ThreeButtonPopup::OnTerminating(void)
 {
+       AppLogDebug("Enter");
+       SetPropagatedKeyEventListener(null);
+
+       delete __pCalendarbook;
+       __pCalendarbook = null;
        return E_SUCCESS;
 }
 
@@ -114,12 +118,12 @@ ThreeButtonPopup::OnActionPerformed(const Control& source, int actionId)
 {
        SetShowState(false);
 
-       if (actionId != IDA_EVENT_POPUP_CANCEL && actionId > 0 && __pTarget != null)
+       if (actionId != IDA_EVENT_POPUP_CANCEL && actionId > 0 && __pTarget)
        {
                LinkedList* pArgs = null;
-               if (__pEvent != null)
+               if (__pEvent)
                {
-                       pArgs = new (std::nothrow) LinkedList();
+                       pArgs = new (std::nothrow) LinkedList(SingleObjectDeleter);
                        pArgs->Add(__pEvent);
                        __pEvent = null;
                }
@@ -127,3 +131,46 @@ ThreeButtonPopup::OnActionPerformed(const Control& source, int actionId)
                __pTarget = null;
        }
 }
+
+void
+ThreeButtonPopup::OnCalendarEventsChanged(const Tizen::Base::Collection::IList &eventChangeInfoList)
+{
+       AppLogDebug("Enter");
+       if (__pEvent)
+       {
+               IEnumerator* pEnum = eventChangeInfoList.GetEnumeratorN();
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       CalEventChangeInfo* pInfo = static_cast<CalEventChangeInfo*>(pEnum->GetCurrent());
+                       if (pInfo->GetChangeType() == RECORD_CHANGE_TYPE_REMOVED && pInfo->GetEventId() == __pEvent->GetOriginalEventId())
+                       {
+                               AppLogDebug("this event is deleted.");
+                               delete pEnum;
+                               SetShowState(false);
+                               return;
+                       }
+               }
+               delete pEnum;
+       }
+}
+
+void
+ThreeButtonPopup::OnCalendarTodosChanged(const Tizen::Base::Collection::IList &todoChangeInfoList)
+{
+}
+
+bool
+ThreeButtonPopup::OnKeyReleased(Tizen::Ui::Control &source, const Tizen::Ui::KeyEventInfo &keyEventInfo)
+{
+       AppLogDebug("%d", keyEventInfo.GetKeyCode());
+       if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
+       {
+               SetShowState(false);
+               if (__pTarget)
+               {
+                       __pTarget->SendUserEvent(IDA_EVENT_POPUP_CANCEL, null);
+               }
+       }
+
+       return false;
+}