Tizen 2.0 Release
[framework/web/wrt-plugins-common.git] / src / wrt-popup / wrt / popup-bin / YesNoPopup.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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  * @file        YesNoPopup.cpp
18  * @author      Andrzej Surdej (a.surdej@samsung.com)
19  * @version     1.0
20  * @brief       Popup that contains 'Yes' and 'No' buttons. Inplementation
21  */
22
23 #include "YesNoPopup.h"
24 #include <memory>
25 #include <string.h>
26 #include "popup_manager.h"
27 #include "PopupSerializer.h"
28
29 namespace Wrt {
30 namespace Popup {
31
32 void YesNoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent)
33 {
34     LogDebug("Entered");
35     m_parent = parent;
36     Renderer::CtrlPopupPtr popup = createPopup(data);
37     ListenForAnswer(popup);
38
39     Renderer::ShowPopupEventShort event(popup,
40                                         MakeAnswerCallback(
41                                             this,
42                                             &YesNoPopup::responseCallback));
43
44     CONTROLLER_POST_EVENT(Renderer::PopupController,
45                           event);
46
47     LogDebug("Exited");
48     return;
49 }
50
51 void YesNoPopup::responseCallback(const Renderer::AnswerCallbackData &answer)
52 {
53     bool result = (POPUP_YES_VALUE == answer.buttonAnswer);
54     DPL::BinaryQueue retValue;
55     PopupSerializer::appendArg(result, retValue);
56     m_parent->response(retValue);
57 }
58
59 YesNoPopup::~YesNoPopup()
60 {
61 }
62
63 Renderer::CtrlPopupPtr YesNoPopup::createPopup(DPL::BinaryQueueAutoPtr data)
64 {
65     std::string title = PopupSerializer::getStringArg(*data);
66     std::string message = PopupSerializer::getStringArg(*data);
67     Assert(data->Empty());
68     LogDebug("title: " << title << " message: " << message);
69     Renderer::CtrlPopupPtr popup =
70         Renderer::PopupControllerSingleton::Instance().CreatePopup();
71
72     popup->SetTitle(title);
73     popup->Append(new Renderer::PopupObject::Label(message));
74
75     popup->Append(new Renderer::PopupObject::Button(YES_LABEL, POPUP_YES_VALUE));
76     popup->Append(new Renderer::PopupObject::Button(NO_LABEL, POPUP_NO_VALUE));
77     return popup;
78 }
79
80 } // Popup
81 } // Wrt