2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FShell_ShortcutManagerImpl.cpp
20 * @brief This is the implementation for the _ShortcutManagerImpl class.
23 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
30 #include "FShell_ShortcutManagerImpl.h"
32 namespace Tizen { namespace Shell
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::App;
39 request_cb_t __pAppWidgetRequestHandlerCallback = null;
41 _ShortcutManagerImpl::_ShortcutManagerImpl()
45 _ShortcutManagerImpl::~_ShortcutManagerImpl()
51 _ShortcutManagerImpl::GetInstance()
53 static _ShortcutManagerImpl* __pShortcutManagerImpl = null;
54 if( __pShortcutManagerImpl == null)
56 __pShortcutManagerImpl = new (std::nothrow)_ShortcutManagerImpl;
57 SysTryReturn(NID_SHELL, __pShortcutManagerImpl, null, E_OUT_OF_MEMORY, "Allocating new _AppWidgetManagerProxy failed.");
59 result r = __pShortcutManagerImpl->Construct();
60 SysTryReturn(NID_SHELL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
62 return __pShortcutManagerImpl;
65 int ShortcutRequestEventHandlerCB(const char* appId, const char* text, int type, const char* content_info, const char* icon, int pid, double period, bool allowDuplication, void *data)
67 SysTryReturn(NID_SHELL, appId, 0, E_SYSTEM, "[E_SYSTEM] appId is null!");
68 SysLog(NID_SHELL, "Tizen::Shell::ShortcutManager - Shortcut request received.");
70 _ShortcutManagerImpl* pShortcutManager = static_cast<_ShortcutManagerImpl*>(data);
71 SysTryReturn(NID_SHELL, pShortcutManager, 0, E_SYSTEM, "[E_SYSTEM] pShortcutManager is null!");
73 const ArrayListT<IShortcutRequestListener*>* pListenerList = pShortcutManager->GetShortcutRequestListenerList();
74 IShortcutRequestListener* pListener;
76 SysLog(NID_SHELL, "There is(are) %d request handler(s).", pListenerList->GetCount());
77 for(int i = 0; i < pListenerList->GetCount(); i ++)
80 pListenerList->GetAt(i, pListener);
81 if( pListener != null)
83 if( type == SHORTCUT_REMOVE)
85 pListener->OnShortcutRemoveRequested(appId, text);
89 pListener->OnShortcutAddRequested(appId, text, icon, content_info);
94 SysLog(NID_SHELL, "Successed.");
98 // c - style callback for shortcut_set_request_cb
99 int ShortcutRequestEventReceiverCB(const char* appId, const char* text, int type, const char* content_info, const char* icon, int pid, double period, int allowDuplication, void *data)
101 SysTryReturn(NID_SHELL, appId, 0, E_SYSTEM, "[E_SYSTEM] providerId is null!");
103 if( type == SHORTCUT_PACKAGE
104 || type == SHORTCUT_DATA
105 || type == SHORTCUT_REMOVE)
107 ShortcutRequestEventHandlerCB(appId, text, type, content_info, icon, pid, period, allowDuplication, data);
111 if( __pAppWidgetRequestHandlerCallback != null)
113 SysLog(NID_SHELL, "Invoking appwidget request handler.");
114 __pAppWidgetRequestHandlerCallback(appId, text, type, content_info, icon, pid, period, allowDuplication, data);
118 SysLog(NID_SHELL, "Successed.");
123 _ShortcutManagerImpl::Construct()
125 int ret = shortcut_set_request_cb(ShortcutRequestEventReceiverCB, this );
126 SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "failed to shortcut_set_request_cb (%d)", ret);
128 __shortcutRequestListenerList.Construct();
129 SysLog(NID_SHELL, "Successed.");
136 _ShortcutManagerImpl::AddShortcutRequestListener(IShortcutRequestListener& listener)
138 SysTryReturnResult(NID_SHELL, !__shortcutRequestListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
139 SysLog(NID_SHELL, "(%x)", &listener);
140 return __shortcutRequestListenerList.Add(&listener);
144 _ShortcutManagerImpl::RemoveShortcutRequestListener(IShortcutRequestListener& listener)
146 SysLog(NID_SHELL, "(%x)", &listener);
147 return __shortcutRequestListenerList.Remove(&listener);
150 const Tizen::Base::Collection::ArrayListT<IShortcutRequestListener*>*
151 _ShortcutManagerImpl::GetShortcutRequestListenerList(void) const
153 return &__shortcutRequestListenerList;
157 _ShortcutManagerImpl::SetAppWidgetRequestHandlerCallback(request_cb_t pAppWidgetRequestHandlerFn)
159 __pAppWidgetRequestHandlerCallback = pAppWidgetRequestHandlerFn;