From f79141a882b2823a745bd62a1628ecb93393d890 Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Tue, 31 May 2016 11:10:50 +0900 Subject: [PATCH] Add popup package info class Package information needed for displaying on popup. For now, only icon info is needed. Change-Id: I01485bc24da86ff825de6b2ced7bdfe4da46d5c3 Signed-off-by: Kyungwook Tak --- src/framework/ui/popup/CMakeLists.txt | 2 ++ src/framework/ui/popup/package-info.cpp | 56 ++++++++++++++++++++++++++++++ src/framework/ui/popup/package-info.h | 50 +++++++++++++++++++++++++++ test/internals/CMakeLists.txt | 4 +++ test/internals/test-package-info.cpp | 61 +++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 src/framework/ui/popup/package-info.cpp create mode 100644 src/framework/ui/popup/package-info.h create mode 100644 test/internals/test-package-info.cpp diff --git a/src/framework/ui/popup/CMakeLists.txt b/src/framework/ui/popup/CMakeLists.txt index 0e25d17..80ba358 100644 --- a/src/framework/ui/popup/CMakeLists.txt +++ b/src/framework/ui/popup/CMakeLists.txt @@ -22,6 +22,7 @@ PKG_CHECK_MODULES(${TARGET_CSR_POPUP}_DEP elementary libsystemd-daemon vconf + pkgmgr-info ) INCLUDE_DIRECTORIES( @@ -35,6 +36,7 @@ SET(${TARGET_CSR_POPUP}_SRCS logic.cpp popup.cpp popup-service.cpp + package-info.cpp ${PROJECT_SOURCE_DIR}/src/framework/ui/common.cpp ) diff --git a/src/framework/ui/popup/package-info.cpp b/src/framework/ui/popup/package-info.cpp new file mode 100644 index 0000000..c76de04 --- /dev/null +++ b/src/framework/ui/popup/package-info.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +/* + * @file package-info.cpp + * @author Kyungwook Tak (k.tak@samsung.com) + * @version 1.0 + * @brief Package info getter for displaying detail of package on popup. + */ +#include "package-info.h" + +#include "common/exception.h" + +namespace Csr { +namespace Ui { + +PackageInfo::PackageInfo(const std::string &pkgid) +{ + auto ret = ::pkgmgrinfo_pkginfo_get_pkginfo(pkgid.c_str(), &this->m_handle); + if (ret != PMINFO_R_OK) + ThrowExc(InternalError, "Invalid package id: " << pkgid << " ret: " << ret); +} + +PackageInfo::~PackageInfo() +{ + ::pkgmgrinfo_pkginfo_destroy_pkginfo(this->m_handle); +} + +std::string PackageInfo::getIconPath(void) +{ + char *icon = nullptr; + auto ret = ::pkgmgrinfo_pkginfo_get_icon(this->m_handle, &icon); + if (ret != PMINFO_R_OK) + ThrowExc(InternalError, "Failed to get icon with pkginfo. ret: " << ret); + + if (icon == nullptr) + ThrowExc(InternalError, + "pkgmgrinfo_pkginfo_get_icon success but null returned on icon path."); + + return std::string(icon); +} + +} +} diff --git a/src/framework/ui/popup/package-info.h b/src/framework/ui/popup/package-info.h new file mode 100644 index 0000000..73127c1 --- /dev/null +++ b/src/framework/ui/popup/package-info.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +/* + * @file package-info.h + * @author Kyungwook Tak (k.tak@samsung.com) + * @version 1.0 + * @brief Package info getter for displaying detail of package on popup. + */ +#pragma once + +#include + +#include + +namespace Csr { +namespace Ui { + +class PackageInfo { +public: + PackageInfo(const std::string &pkgid); + virtual ~PackageInfo(); + + PackageInfo(const PackageInfo &) = delete; + PackageInfo &operator=(const PackageInfo &) = delete; + PackageInfo(PackageInfo &&) = delete; + PackageInfo &operator=(PackageInfo &&) = delete; + + std::string getIconPath(void); + +private: + pkgmgrinfo_pkginfo_h m_handle; + +}; + + +} // namespace Ui +} // namespace Csr diff --git a/test/internals/CMakeLists.txt b/test/internals/CMakeLists.txt index 0bff779..2f8f198 100644 --- a/test/internals/CMakeLists.txt +++ b/test/internals/CMakeLists.txt @@ -25,6 +25,7 @@ SET(CSR_FW_SRC_PATH ${PROJECT_SOURCE_DIR}/src/framework) PKG_CHECK_MODULES(${TARGET_CSR_INTERNAL_TEST}_DEP REQUIRED sqlite3 + pkgmgr-info ) SET(${TARGET_CSR_INTERNAL_TEST}_SRCS @@ -40,6 +41,7 @@ SET(${TARGET_CSR_INTERNAL_TEST}_SRCS ${CSR_FW_SRC_PATH}/service/wp-loader.cpp ${CSR_FW_SRC_PATH}/service/engine-error-converter.cpp ${CSR_FW_SRC_PATH}/client/canonicalize.cpp + ${CSR_FW_SRC_PATH}/ui/popup/package-info.cpp test-db.cpp test-cpucore.cpp @@ -49,6 +51,7 @@ SET(${TARGET_CSR_INTERNAL_TEST}_SRCS test-cs-loader.cpp test-wp-loader.cpp test-canonicalize.cpp + test-package-info.cpp test-main.cpp ) @@ -62,6 +65,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/include/csr ${PROJECT_SOURCE_DIR}/src/include/csre ${CSR_FW_SRC_PATH} + ${CSR_FW_SRC_PATH}/ui/popup ${CSR_TEST_SRC_PATH} ) diff --git a/test/internals/test-package-info.cpp b/test/internals/test-package-info.cpp new file mode 100644 index 0000000..dc8f122 --- /dev/null +++ b/test/internals/test-package-info.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +/* + * @file test-package-info.cpp + * @author Kyungwook Tak (k.tak@samsung.com) + * @version 1.0 + * @brief Package info class test + */ +#include + +#include + +#include "test-common.h" +#include "test-resource.h" + +using namespace Csr; + +BOOST_AUTO_TEST_SUITE(PACKAGE_INFO) + +BOOST_AUTO_TEST_CASE(get_icon_wgt) +{ + EXCEPTION_GUARD_START + + Test::uninstall_app(TEST_WGT_PKG_ID); + ASSERT_INSTALL_APP(TEST_WGT_PATH, TEST_WGT_TYPE); + + Ui::PackageInfo info(TEST_WGT_PKG_ID); + + BOOST_MESSAGE(info.getIconPath()); + + EXCEPTION_GUARD_END +} + +BOOST_AUTO_TEST_CASE(get_icon_tpk) +{ + EXCEPTION_GUARD_START + + Test::uninstall_app(TEST_TPK_PKG_ID); + ASSERT_INSTALL_APP(TEST_TPK_PATH, TEST_TPK_TYPE); + + Ui::PackageInfo info(TEST_TPK_PKG_ID); + + BOOST_MESSAGE(info.getIconPath()); + + EXCEPTION_GUARD_END +} + +BOOST_AUTO_TEST_SUITE_END() -- 2.7.4