2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FShell_ShortcutManagerImpl.cpp
19 * @brief This is the implementation for the _ShortcutManagerImpl class.
22 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
26 #include <FBase_StringConverter.h>
29 #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()
42 : __isListenerConstructed(false)
46 _ShortcutManagerImpl::~_ShortcutManagerImpl()
52 _ShortcutManagerImpl::GetInstance()
54 static _ShortcutManagerImpl* __pShortcutManagerImpl = null;
55 if( __pShortcutManagerImpl == null)
57 __pShortcutManagerImpl = new (std::nothrow)_ShortcutManagerImpl;
58 SysTryReturn(NID_SHELL, __pShortcutManagerImpl, null, E_OUT_OF_MEMORY, "Allocating new _AppWidgetManagerProxy failed.");
60 result r = __pShortcutManagerImpl->Construct();
61 SysTryReturn(NID_SHELL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
63 return __pShortcutManagerImpl;
66 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)
68 SysTryReturn(NID_SHELL, appId, 0, E_SYSTEM, "[E_SYSTEM] appId is null!");
69 SysLog(NID_SHELL, "Tizen::Shell::ShortcutManager - Shortcut request received.");
71 _ShortcutManagerImpl* pShortcutManager = static_cast<_ShortcutManagerImpl*>(data);
72 SysTryReturn(NID_SHELL, pShortcutManager, 0, E_SYSTEM, "[E_SYSTEM] pShortcutManager is null!");
74 const ArrayListT<IShortcutRequestListener*>* pListenerList = pShortcutManager->GetShortcutRequestListenerList();
75 IShortcutRequestListener* pListener;
77 SysLog(NID_SHELL, "There is(are) %d request handler(s).", pListenerList->GetCount());
78 for(int i = 0; i < pListenerList->GetCount(); i ++)
81 pListenerList->GetAt(i, pListener);
82 if( pListener != null)
84 if( type == SHORTCUT_REMOVE)
86 pListener->OnShortcutRemoveRequested(appId, text);
90 pListener->OnShortcutAddRequested(appId, text, icon, content_info);
95 SysLog(NID_SHELL, "Successed.");
99 // c - style callback for shortcut_set_request_cb
100 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)
102 SysTryReturn(NID_SHELL, appId, 0, E_SYSTEM, "[E_SYSTEM] providerId is null!");
104 if( type == SHORTCUT_PACKAGE
105 || type == SHORTCUT_DATA
106 || type == SHORTCUT_REMOVE)
108 ShortcutRequestEventHandlerCB(appId, text, type, content_info, icon, pid, period, allowDuplication, data);
112 if( __pAppWidgetRequestHandlerCallback != null)
114 SysLog(NID_SHELL, "Invoking appwidget request handler.");
115 __pAppWidgetRequestHandlerCallback(appId, text, type, content_info, icon, pid, period, allowDuplication, data);
119 SysLog(NID_SHELL, "Successed.");
124 _ShortcutManagerImpl::Construct()
130 _ShortcutManagerImpl::ConstructListener()
132 int ret = shortcut_set_request_cb(ShortcutRequestEventReceiverCB, this );
133 SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "failed to shortcut_set_request_cb (%d)", ret);
135 __shortcutRequestListenerList.Construct();
137 __isListenerConstructed = true;
138 SysLog(NID_SHELL, "Successed.");
144 _ShortcutManagerImpl::AddShortcut(const AppId& appId, const String& displayName, const String& iconFilePath, const String& uriData, bool allowDuplication)
146 SysTryReturnResult(NID_SHELL, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
148 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
149 std::unique_ptr<char[]> pIcon(_StringConverter::CopyToCharArrayN(iconFilePath));
150 std::unique_ptr<char[]> pName(_StringConverter::CopyToCharArrayN(displayName));
151 std::unique_ptr<char[]> pUriData(_StringConverter::CopyToCharArrayN(uriData));
152 int type = (uriData.IsEmpty())? LAUNCH_BY_PACKAGE : LAUNCH_BY_URI;
154 int ret = add_to_home_shortcut(pAppId.get(), pName.get(), type, pUriData.get(), pIcon.get(), allowDuplication, NULL, this);
155 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_COMM, E_SUCCESS, "It's failed to add_to_home_shortcut, but regarded as success.");
156 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_MEMORY, E_OUT_OF_MEMORY, "It's failed to add_to_home_shortcut.");
157 SysTryReturnResult(NID_SHELL, ret == SHORTCUT_SUCCESS, E_SYSTEM, "Failed to add_to_home_shortcut");
159 SysLog(NID_SHELL, "Successed.");
164 _ShortcutManagerImpl::RemoveShortcut(const Tizen::App::AppId& appId, const Tizen::Base::String& displayName)
166 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
167 std::unique_ptr<char[]> pName(_StringConverter::CopyToCharArrayN(displayName));
169 int ret = add_to_home_remove_shortcut(pAppId.get(), pName.get(), "", null, this);
170 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_COMM, E_SUCCESS, "It's failed to add_to_home_remove_shortcut, but regarded as success.");
171 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_MEMORY, E_OUT_OF_MEMORY, "It's failed to add_to_home_remove_shortcut.");
172 SysTryReturnResult(NID_SHELL, ret == SHORTCUT_SUCCESS, E_SYSTEM, "It's failed to add_to_home_remove_shortcut, with reason (%d)");
178 _ShortcutManagerImpl::AddShortcutRequestListener(IShortcutRequestListener& listener)
180 SysTryReturnResult(NID_SHELL, !__shortcutRequestListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
181 SysLog(NID_SHELL, "(%x)", &listener);
182 if( __isListenerConstructed == false)
186 return __shortcutRequestListenerList.Add(&listener);
190 _ShortcutManagerImpl::RemoveShortcutRequestListener(IShortcutRequestListener& listener)
192 SysLog(NID_SHELL, "(%x)", &listener);
193 return __shortcutRequestListenerList.Remove(&listener);
196 const Tizen::Base::Collection::ArrayListT<IShortcutRequestListener*>*
197 _ShortcutManagerImpl::GetShortcutRequestListenerList(void) const
199 return &__shortcutRequestListenerList;
203 _ShortcutManagerImpl::SetAppWidgetRequestHandlerCallback(request_cb_t pAppWidgetRequestHandlerFn)
205 if( __isListenerConstructed == false)
209 __pAppWidgetRequestHandlerCallback = pAppWidgetRequestHandlerFn;