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>
28 #include "FShell_ShortcutManagerImpl.h"
31 namespace Tizen { namespace Shell
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::App;
38 request_cb_t __pAppWidgetRequestHandlerCallback = null;
40 _ShortcutManagerImpl::_ShortcutManagerImpl()
41 : __isListenerConstructed(false)
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()
129 _ShortcutManagerImpl::ConstructListener()
131 int ret = shortcut_set_request_cb(ShortcutRequestEventReceiverCB, this );
132 SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "failed to shortcut_set_request_cb (%d)", ret);
134 __shortcutRequestListenerList.Construct();
136 __isListenerConstructed = true;
137 SysLog(NID_SHELL, "Successed.");
143 _ShortcutManagerImpl::AddShortcut(const AppId& appId, const String& displayName, const String& iconFilePath, const String& uriData, bool allowDuplication)
145 SysLog(NID_SHELL, "_ShortcutManagerImpl::AddShortcut enters.");
146 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
147 std::unique_ptr<char[]> pIcon(_StringConverter::CopyToCharArrayN(iconFilePath));
148 std::unique_ptr<char[]> pName(_StringConverter::CopyToCharArrayN(displayName));
149 std::unique_ptr<char[]> pUriData(_StringConverter::CopyToCharArrayN(uriData));
150 int type = (uriData.IsEmpty())? LAUNCH_BY_PACKAGE : LAUNCH_BY_URI;
152 int ret = add_to_home_shortcut(pAppId.get(), pName.get(), type, pUriData.get(), pIcon.get(), allowDuplication, NULL, this);
153 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_COMM, E_SUCCESS, "It's failed to add_to_home_shortcut, but regarded as success.");
154 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_MEMORY, E_OUT_OF_MEMORY, "It's failed to add_to_home_shortcut.");
155 SysTryReturnResult(NID_SHELL, ret == SHORTCUT_SUCCESS, E_SYSTEM, "Failed to add_to_home_shortcut");
156 SysLog(NID_SHELL, "_ShortcutManagerImpl::AddShortcut exits.");
161 _ShortcutManagerImpl::RemoveShortcut(const Tizen::App::AppId& appId, const Tizen::Base::String& displayName)
163 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
164 std::unique_ptr<char[]> pName(_StringConverter::CopyToCharArrayN(displayName));
166 int ret = add_to_home_remove_shortcut(pAppId.get(), pName.get(), "", null, this);
167 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_COMM, E_SUCCESS, "It's failed to add_to_home_remove_shortcut, but regarded as success.");
168 SysTryReturnResult(NID_SHELL, ret != SHORTCUT_ERROR_MEMORY, E_OUT_OF_MEMORY, "It's failed to add_to_home_remove_shortcut.");
169 SysTryReturnResult(NID_SHELL, ret == SHORTCUT_SUCCESS, E_SYSTEM, "It's failed to add_to_home_remove_shortcut, with reason (%d)");
175 _ShortcutManagerImpl::AddShortcutRequestListener(IShortcutRequestListener& listener)
177 SysTryReturnResult(NID_SHELL, !__shortcutRequestListenerList.Contains(&listener), E_OBJ_ALREADY_EXIST, "The listener is already added.");
178 SysLog(NID_SHELL, "(%x)", &listener);
179 if( __isListenerConstructed == false)
183 return __shortcutRequestListenerList.Add(&listener);
187 _ShortcutManagerImpl::RemoveShortcutRequestListener(IShortcutRequestListener& listener)
189 SysLog(NID_SHELL, "(%x)", &listener);
190 return __shortcutRequestListenerList.Remove(&listener);
193 const Tizen::Base::Collection::ArrayListT<IShortcutRequestListener*>*
194 _ShortcutManagerImpl::GetShortcutRequestListenerList(void) const
196 return &__shortcutRequestListenerList;
200 _ShortcutManagerImpl::SetAppWidgetRequestHandlerCallback(request_cb_t pAppWidgetRequestHandlerFn)
202 if( __isListenerConstructed == false)
206 __pAppWidgetRequestHandlerCallback = pAppWidgetRequestHandlerFn;