libaurum: apply smart pointer wider and extract impl out
[platform/core/uifw/aurum.git] / org.tizen.aurum-bootstrap / src / Commands / ClearCommand.cc
1 #include "ClearCommand.h"
2 #include <UiObject.h>
3 #include <loguru.hpp>
4 #include <string>
5
6 ClearCommand::ClearCommand(const ::aurum::ReqClear* request,
7                            ::aurum::RspClear*       response)
8     : mRequest{request}, mResponse{response}
9 {
10 }
11
12 bool ClearCommand::hasHintText(std::shared_ptr<UiObject> obj)
13 {
14     if (!obj) return false;
15
16     auto old_text = obj->getText();
17     obj->setText("");
18     if (!old_text.compare(obj->getText())) {
19         return true;
20     } else {
21         obj->setText(old_text);
22         return false;
23     }
24 }
25
26 ::grpc::Status ClearCommand::execute()
27 {
28     LOG_SCOPE_F(INFO, "Clear --------------- ");
29     ObjectMapper* mObjMap = ObjectMapper::getInstance();
30     std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
31
32     if (obj) {
33         obj->setText("");
34         obj->refresh();
35         auto text = obj->getText();
36         if (text.length() != 0) {
37             if (hasHintText(obj)) {
38                 mResponse->set_status(::aurum::RspStatus::OK);
39             } else {
40                 mResponse->set_status(::aurum::RspStatus::ERROR);
41             }
42         } else {
43             mResponse->set_status(::aurum::RspStatus::OK);
44         }
45     }
46
47     return grpc::Status::OK;
48 }