[appwidget-service] Remove Open Service Platform words
[framework/osp/appwidget-service.git] / src / FShell_AppWidgetPopupContext.cpp
1 //
2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /**
18  * @file        FShell_AppWidgetPopupContext.cpp
19  * @brief       This is the implementation for the _AppWidgetPopupContext class.
20  */
21
22 #include <stdlib.h>
23 #include <unique_ptr.h>
24
25 #include "provider_buffer.h"
26
27 #include <FBase.h>
28 #include <FBaseSysLog.h>
29 #include <FBase_StringConverter.h>
30
31 #include <FApp_AppControlManager.h>
32
33 #include "FShell_AppWidgetManagerService.h"
34 #include "FShell_AppWidgetContext.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
49 _AppWidgetPopupContext::_AppWidgetPopupContext(const String& info, const String& appId, const String& instanceId, int width, int height, int priority, _AppWidgetContext* pParent)
50 :_AppWidgetContextBase(TYPE_PD, info, appId, instanceId, width, height, priority)
51 {
52         __pParent = pParent;
53         SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
54 }
55
56 _AppWidgetPopupContext::~_AppWidgetPopupContext()
57 {
58         SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d))", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
59 }
60
61
62 void
63 _AppWidgetPopupContext::OnPopupCreated(double x, double y, int width, int height)
64 {
65         SysLog(NID_SHELL, "width(%d), height(%d)", width, height);
66         SendPopupCreateRequest(x, y, width, height);
67 }
68
69 void
70 _AppWidgetPopupContext::OnPopupDestoyed()
71 {
72         SysLog(NID_SHELL, "");
73         SendPopupDestroyRequest();
74 }
75
76 result
77 _AppWidgetPopupContext::SendPopupCreateRequest(double x, double y, int width, int height)
78 {
79         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
80
81         pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
82         pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
83         pArgs->Add(new String(ARG_KEY_POPUP_WIDTH), new String(Integer::ToString(width)));
84         pArgs->Add(new String(ARG_KEY_POPUP_HEIGHT), new String(Integer::ToString(height)));
85
86         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_CREATE, pArgs.get());
87 }
88
89 result
90 _AppWidgetPopupContext::SendPopupDestroyRequest()
91 {
92         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
93
94         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_DESTROY, pArgs.get());
95 }
96
97 result
98 _AppWidgetPopupContext::SendTouchEvent(buffer_event event, double timestamp, double x, double y)
99 {
100         SysLog(NID_SHELL, "");
101         /*if( HasValidClientId() == false )
102         {
103                 std::unique_ptr<ArrayList, AllElementsDeleter> pArgs (new (std::nothrow) ArrayList);
104                 pArgs->Construct();
105                 pArgs->Add(*new String(__instanceId));
106                 pArgs->Add(*new String(__info));
107                 pArgs->Add(*new String(Integer::ToString(event)));
108                 pArgs->Add(*new String(Double::ToString(timestamp)));
109                 pArgs->Add(*new String(Double::ToString(x)));
110                 pArgs->Add(*new String(Double::ToString(y)));
111
112                 return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_TOUCH, pArgs.get());
113         }
114         else*/
115         {
116 //              SysAssertf( Tizen::App::AppManager::GetInstance()->IsRunning(__appId) == false, "application isn't running");
117                 AppWidgetManagerService::GetInstance()->SendTouchEventForPD(__ipcClientId, __instanceId, event, timestamp, x, y);
118         }
119         return E_SUCCESS;
120 }
121
122 result
123 _AppWidgetPopupContext::RequestUpdateRemote()
124 {
125         std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
126         std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
127
128         int ret = provider_send_desc_updated(packageName.get(), id.get(), null);
129         SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
130
131         SysLog(NID_SHELL, "Done");
132         return E_SUCCESS;
133 }
134
135 Tizen::Base::Collection::HashMap*
136 _AppWidgetPopupContext::CreateRequestArgs(void)
137 {
138         HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
139         pArgs->Construct();
140         pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(__instanceId));
141         pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(__providerName));
142         pArgs->Add(new String(ARG_KEY_USER_INFO), new String(__userInfo));
143         pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(__pParent->__width)));
144         pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(__pParent->__height)));
145
146         return pArgs;
147 }
148
149 } } } // Tizen::Shell::App {
150