minor fix
[platform/framework/native/appwidget-service.git] / src / FShell_AppWidgetPopupContext.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FShell_AppWidgetPopupContext.cpp
20  * @brief       This is the implementation for the _AppWidgetPopupContext class.
21  */
22
23 #include <stdlib.h>
24 #include <unique_ptr.h>
25
26 #include "provider_buffer.h"
27
28 #include <FBase.h>
29 #include <FBaseSysLog.h>
30 #include <FBase_StringConverter.h>
31
32 #include <FApp_AppControlManager.h>
33
34 #include "FShell_AppWidgetManagerService.h"
35 #include "FShell_AppWidgetPopupContext.h"
36
37 namespace Tizen { namespace Shell  { namespace App
38 {
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42
43
44 const char APPWIDGET_POPUP_ON_CREATE[] = "http://tizen.org/appcontrol/appwidgetpopup/create";
45 const char APPWIDGET_POPUP_ON_DESTROY[] = "http://tizen.org/appcontrol/appwidgetpopup/destroy";
46 const char APPWIDGET_POPUP_ON_TOUCH[] = "http://tizen.org/appcontrol/appwidgetpopup/touch";
47
48 const String ARG_KEY_X = L"_X";
49 const String ARG_KEY_Y = L"_Y";
50 const String ARG_KEY_WIDTH = L"_Width";
51 const String ARG_KEY_HEIGHT = L"_Height";
52
53
54 _AppWidgetPopupContext::_AppWidgetPopupContext(const String& info, const String& appId, const String& instanceId, int width, int height, int priority)
55 :_AppWidgetContextBase(TYPE_PD, info, appId, instanceId, width, height, priority)
56 {
57         SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
58 }
59
60 _AppWidgetPopupContext::~_AppWidgetPopupContext()
61 {
62         SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d))", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
63 }
64
65
66 void
67 _AppWidgetPopupContext::OnPopupCreated(double x, double y, int width, int height)
68 {
69         SysLog(NID_SHELL, "width(%d), height(%d)", width, height);
70         SendPopupCreateRequest(x, y, width, height);
71 }
72
73 void
74 _AppWidgetPopupContext::OnPopupDestoyed()
75 {
76         SysLog(NID_SHELL, "");
77         SendPopupDestroyRequest();
78 }
79
80 result
81 _AppWidgetPopupContext::SendPopupCreateRequest(double x, double y, int width, int height)
82 {
83         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
84
85         pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
86         pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
87         pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
88         pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
89
90         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_CREATE, pArgs.get());
91 }
92
93 result
94 _AppWidgetPopupContext::SendPopupDestroyRequest()
95 {
96         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
97
98         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_DESTROY, pArgs.get());
99 }
100
101 result
102 _AppWidgetPopupContext::SendTouchEvent(buffer_event event, double timestamp, double x, double y)
103 {
104         SysLog(NID_SHELL, "");
105         /*if( HasValidClientId() == false )
106         {
107                 std::unique_ptr<ArrayList, AllElementsDeleter> pArgs (new (std::nothrow) ArrayList);
108                 pArgs->Construct();
109                 pArgs->Add(*new String(__instanceId));
110                 pArgs->Add(*new String(__info));
111                 pArgs->Add(*new String(Integer::ToString(event)));
112                 pArgs->Add(*new String(Double::ToString(timestamp)));
113                 pArgs->Add(*new String(Double::ToString(x)));
114                 pArgs->Add(*new String(Double::ToString(y)));
115
116                 return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_TOUCH, pArgs.get());
117         }
118         else*/
119         {
120 //              SysAssertf( Tizen::App::AppManager::GetInstance()->IsRunning(__appId) == false, "application isn't running");
121                 AppWidgetManagerService::GetInstance()->SendTouchEventForPD(__ipcClientId, __instanceId, event, timestamp, x, y);
122         }
123         return E_SUCCESS;
124 }
125
126 result
127 _AppWidgetPopupContext::RequestUpdateRemote()
128 {
129         std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
130         std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
131
132         int ret = provider_send_desc_updated(packageName.get(), id.get(), null);
133         SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
134
135         SysLog(NID_SHELL, "Done");
136         return E_SUCCESS;
137 }
138
139 } } } // Tizen::Shell::App {
140