2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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_AppWidgetProviderInfoImpl.cpp
19 * @brief This is the implementation for the _AppWidgetProviderInfoImpl class.
22 #include <unique_ptr.h>
23 #include <livebox-service/livebox-service.h>
26 #include <FBaseSysLog.h>
27 #include <FBase_StringConverter.h>
28 #include <FApp_AppInfo.h>
30 #include <FAppPkg_PackageManagerImpl.h>
31 #include <FAppPkg_PackageInfoImpl.h>
32 #include <FShellAppWidgetProviderInfo.h>
33 #include <FShellAppWidgetSizeInfo.h>
34 #include "FShell_AppWidgetManagerImpl.h"
35 #include "FShell_AppWidgetProviderInfoImpl.h"
36 #include "FShell_AppWidgetSizeInfoImpl.h"
38 namespace Tizen { namespace Shell {
40 using namespace Tizen::App;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Graphics;
46 _AppWidgetProviderInfoImpl::_AppWidgetProviderInfoImpl(const Tizen::App::AppId& appId, const Tizen::Base::String& name)
50 ,__pConfigurationAppControlAppId(null)
55 String providerId = _AppWidgetManagerImpl::MakeProviderName(appId, name);
56 __pProviderId = _StringConverter::CopyToCharArrayN(providerId);
58 SysSecureLog(NID_SHELL, "appId(%ls), name(%ls), providerId(%s)", appId.GetPointer(), name.GetPointer(), __pProviderId);
61 _AppWidgetProviderInfoImpl::~_AppWidgetProviderInfoImpl()
63 delete[] __pProviderId;
64 delete __pDisplayName;
65 delete __pConfigurationAppControlAppId;
70 _AppWidgetProviderInfoImpl::GetAppId() const
76 _AppWidgetProviderInfoImpl::GetName() const
82 _AppWidgetProviderInfoImpl::GetDisplayName()
84 if (__pDisplayName == null)
86 std::unique_ptr<char> pDisplayName(livebox_service_i18n_name(__pProviderId, null));
87 __pDisplayName = new(std::nothrow) String(pDisplayName.get());
89 return *__pDisplayName;
93 _AppWidgetProviderInfoImpl::GetIconPath()
95 if (__pIconPath == null)
97 std::unique_ptr<char> pIconPath(livebox_service_i18n_icon(__pProviderId, null) );
98 __pIconPath = new(std::nothrow) String(pIconPath.get());
105 _AppWidgetProviderInfoImpl::GetConfigurationAppControlAppId()
107 if (__pConfigurationAppControlAppId == null)
109 std::unique_ptr<char> pSetUpAppId(livebox_service_setup_appid(__pProviderId));
110 __pConfigurationAppControlAppId = new(std::nothrow) String(pSetUpAppId.get());
112 return *__pConfigurationAppControlAppId;
116 _AppWidgetProviderInfoImpl::IsDefault() const
122 _AppWidgetProviderInfoImpl::GetPrivilegeLevel(const AppId& appId)
125 Package::_PackageManagerImpl* pPkg = Package::_PackageManagerImpl::GetInstance();
126 SysTryReturn(NID_APP, pPkg != null, _API_VISIBILITY_PUBLIC, E_INVALID_STATE, "Invalid PackageManager instance.");
128 String pkgId = Package::_PackageManagerImpl::GetPackageIdByAppId(appId);
129 SysTryReturn(NID_APP, !pkgId.IsEmpty(), _API_VISIBILITY_PUBLIC, E_INVALID_STATE, "Invalid appId(%ls).", appId.GetPointer() );
131 std::unique_ptr<Package::PackageInfo> pInfo (pPkg->GetPackageInfoN(pkgId) );
132 SysTryReturn(NID_APP, pInfo != null, _API_VISIBILITY_PUBLIC, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
134 const Package::_PackageInfoImpl* pPkgInfo = Package::_PackageInfoImpl::GetInstance(pInfo.get());
135 SysTryReturn(NID_APP, pPkgInfo != null, _API_VISIBILITY_PUBLIC, E_INVALID_STATE, "Invalid PackageInfo instance.");
137 return pPkgInfo->GetApiVisibility();
141 _AppWidgetProviderInfoImpl::IsValidSize(const AppId& appId, int w, int h)
143 if (IsInhouseApp(appId) == true)//TODO: remove this
148 // static const int UNIT_SIZE_BASE = 175;
149 static const int UNIT_SIZE_2 = 354;// UNIT_SIZE_BASE*n + 4*(n-1)
151 int privilegeLevel = GetPrivilegeLevel(appId);
152 if( privilegeLevel == _API_VISIBILITY_PUBLIC || privilegeLevel == _API_VISIBILITY_PARTNER)
154 if( h > UNIT_SIZE_2 || w > UNIT_SIZE_2)
156 SysLog(NID_SHELL, "%dx%d size is invalid for %d privilege", privilegeLevel);
160 /*else if( size.height > UNIT_SIZE_4 || size.width > UNIT_SIZE_4)
167 Tizen::Base::Collection::IList*
168 _AppWidgetProviderInfoImpl::GetSizeInfoListN() const
170 static const int MAX_SUPPORTED_SIZE_TYPE = NR_OF_SIZE_LIST;
172 int supportedSizeCount = MAX_SUPPORTED_SIZE_TYPE;
173 int widthArray[MAX_SUPPORTED_SIZE_TYPE];
174 int heightArray[MAX_SUPPORTED_SIZE_TYPE];
176 livebox_service_get_supported_sizes(__pProviderId, &supportedSizeCount , widthArray, heightArray);
178 SysTryReturn(NID_SHELL, supportedSizeCount > 0, null, E_SYSTEM, "[E_SYSTEM] There is no appwidget of provider(%s)",__pProviderId );
180 std::unique_ptr<ArrayList> pSizes(new (std::nothrow) ArrayList);
181 SysTryReturn(NID_SHELL, pSizes, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory for ArrayList." );
184 FloatDimension size(0, 0);
185 String previewImagePath;
187 for(int i = 0; i < supportedSizeCount; i++)
189 size.SetSize(widthArray[i], heightArray[i]);
190 previewImagePath = livebox_service_preview(__pProviderId, livebox_service_size_type(static_cast<int>(size.width), static_cast<int>(size.height) ) );
192 if( IsValidSize(__appId, size.width, size.height) == false )
197 int sizeType = livebox_service_size_type(size.width, size.height);
198 SysAssertf(sizeType != LB_SIZE_TYPE_UNKNOWN, "Failed to invoke livebox_service_size_type(%d, %d)", size.width, size.height);
199 bool useDecoration = livebox_service_need_frame(__pProviderId, sizeType);
201 std::unique_ptr<AppWidgetSizeInfo> pAppWidgetSizeInfo(_AppWidgetSizeInfoImpl::CreateAppWidgetSizeInfo(size, previewImagePath, useDecoration) );
202 SysTryReturn(NID_SHELL, pAppWidgetSizeInfo, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory for AppWidgetSizeInfo." );
203 pSizes->Add( *pAppWidgetSizeInfo.release() );
205 return pSizes.release();
208 AppWidgetProviderInfo*
209 _AppWidgetProviderInfoImpl::GetAppWidgetProviderInfoN(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName)
211 std::unique_ptr<char[]> pProviderId(_StringConverter::CopyToCharArrayN(_AppWidgetManagerImpl::MakeProviderName(appId, providerName)));
213 bool isDefault = livebox_service_is_primary(pProviderId.get());
214 return GetAppWidgetProviderInfoN(appId, providerName, isDefault);
217 AppWidgetProviderInfo*
218 _AppWidgetProviderInfoImpl::GetAppWidgetProviderInfoN(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, bool isDefault)
220 SysTryReturn(NID_SHELL, Tizen::App::_Aul::IsInstalled(appId) == true, null, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
221 SysTryReturn(NID_SHELL, IsExist(appId, providerName) == true, null, E_OBJ_NOT_FOUND, "The provider(%ls.%ls) isn't found.", appId.GetPointer(), providerName.GetPointer() );
223 AppWidgetProviderInfo* pInfo = new (std::nothrow) AppWidgetProviderInfo(appId, providerName);
224 SysTryReturn(NID_SHELL, pInfo, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory for AppWidgetProviderInfo." );
226 _AppWidgetProviderInfoImpl::GetImpl(*pInfo)->__isDefault = isDefault;
232 _AppWidgetProviderInfoImpl::IsExist(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName)
234 std::unique_ptr<char[]> pProviderId(_StringConverter::CopyToCharArrayN(_AppWidgetManagerImpl::MakeProviderName(appId, providerName)));
235 std::unique_ptr<char> pPackageId( livebox_service_appid(pProviderId.get()) );
236 SysTryReturn(NID_SHELL, pPackageId.get(), false, E_OBJ_NOT_FOUND, "The provider(%s) isn't found.", pProviderId.get() );
241 _AppWidgetProviderInfoImpl*
242 _AppWidgetProviderInfoImpl::GetImpl(const AppWidgetProviderInfo& appwidgetProviderInfo)
244 return static_cast<_AppWidgetProviderInfoImpl*>(appwidgetProviderInfo.__pAppWidgetProviderInfoImpl);
248 _AppWidgetProviderInfoImpl::IsInhouseApp(const Tizen::App::AppId& appId)
250 return (appId.StartsWith("com.samsung.", 0) == true);
253 } /* namespace AppWidget */
254 } /* namespace Samsung */