3a642c54620594d595fe02ff18891830b2184694
[framework/osp/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.1 (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_AppWidgetContext.h"
36 #include "FShell_AppWidgetPopupContext.h"
37
38 namespace Tizen { namespace Shell  { namespace App
39 {
40
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43
44
45 const char APPWIDGET_POPUP_ON_CREATE[] = "http://tizen.org/appcontrol/appwidgetpopup/create";
46 const char APPWIDGET_POPUP_ON_DESTROY[] = "http://tizen.org/appcontrol/appwidgetpopup/destroy";
47 const char APPWIDGET_POPUP_ON_TOUCH[] = "http://tizen.org/appcontrol/appwidgetpopup/touch";
48
49
50 _AppWidgetPopupContext::_AppWidgetPopupContext(const String& info, const String& appId, const String& instanceId, int width, int height, int priority, _AppWidgetContext* pParent)
51 :_AppWidgetContextBase(TYPE_PD, info, appId, instanceId, width, height, priority)
52 {
53         __pParent = pParent;
54         SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
55 }
56
57 _AppWidgetPopupContext::~_AppWidgetPopupContext()
58 {
59         SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d))", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
60 }
61
62
63 void
64 _AppWidgetPopupContext::OnPopupCreated(double x, double y, int width, int height)
65 {
66         SysLog(NID_SHELL, "width(%d), height(%d)", width, height);
67         SendPopupCreateRequest(x, y, width, height);
68 }
69
70 void
71 _AppWidgetPopupContext::OnPopupDestoyed()
72 {
73         SysLog(NID_SHELL, "");
74         SendPopupDestroyRequest();
75 }
76
77 result
78 _AppWidgetPopupContext::SendPopupCreateRequest(double x, double y, int width, int height)
79 {
80         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
81
82         pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
83         pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
84         pArgs->Add(new String(ARG_KEY_POPUP_WIDTH), new String(Integer::ToString(width)));
85         pArgs->Add(new String(ARG_KEY_POPUP_HEIGHT), new String(Integer::ToString(height)));
86
87         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_CREATE, pArgs.get());
88 }
89
90 result
91 _AppWidgetPopupContext::SendPopupDestroyRequest()
92 {
93         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
94
95         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_DESTROY, pArgs.get());
96 }
97
98 result
99 _AppWidgetPopupContext::SendTouchEvent(buffer_event event, double timestamp, double x, double y)
100 {
101         SysLog(NID_SHELL, "");
102         /*if( HasValidClientId() == false )
103         {
104                 std::unique_ptr<ArrayList, AllElementsDeleter> pArgs (new (std::nothrow) ArrayList);
105                 pArgs->Construct();
106                 pArgs->Add(*new String(__instanceId));
107                 pArgs->Add(*new String(__info));
108                 pArgs->Add(*new String(Integer::ToString(event)));
109                 pArgs->Add(*new String(Double::ToString(timestamp)));
110                 pArgs->Add(*new String(Double::ToString(x)));
111                 pArgs->Add(*new String(Double::ToString(y)));
112
113                 return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_TOUCH, pArgs.get());
114         }
115         else*/
116         {
117 //              SysAssertf( Tizen::App::AppManager::GetInstance()->IsRunning(__appId) == false, "application isn't running");
118                 AppWidgetManagerService::GetInstance()->SendTouchEventForPD(__ipcClientId, __instanceId, event, timestamp, x, y);
119         }
120         return E_SUCCESS;
121 }
122
123 result
124 _AppWidgetPopupContext::RequestUpdateRemote()
125 {
126         std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
127         std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
128
129         int ret = provider_send_desc_updated(packageName.get(), id.get(), null);
130         SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
131
132         SysLog(NID_SHELL, "Done");
133         return E_SUCCESS;
134 }
135
136 Tizen::Base::Collection::HashMap*
137 _AppWidgetPopupContext::CreateRequestArgs(void)
138 {
139         HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
140         pArgs->Construct();
141         pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(__instanceId));
142         pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(__providerName));
143         pArgs->Add(new String(ARG_KEY_USER_INFO), new String(__userInfo));
144         pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(__pParent->__width)));
145         pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(__pParent->__height)));
146
147         return pArgs;
148 }
149
150 } } } // Tizen::Shell::App {
151