Add popup package info class 43/72143/4
authorKyungwook Tak <k.tak@samsung.com>
Tue, 31 May 2016 02:10:50 +0000 (11:10 +0900)
committersangwan kwon <sangwan.kwon@samsung.com>
Tue, 31 May 2016 07:04:28 +0000 (00:04 -0700)
Package information needed for displaying on popup.
For now, only icon info is needed.

Change-Id: I01485bc24da86ff825de6b2ced7bdfe4da46d5c3
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/ui/popup/CMakeLists.txt
src/framework/ui/popup/package-info.cpp [new file with mode: 0644]
src/framework/ui/popup/package-info.h [new file with mode: 0644]
test/internals/CMakeLists.txt
test/internals/test-package-info.cpp [new file with mode: 0644]

index 0e25d17..80ba358 100644 (file)
@@ -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 (file)
index 0000000..c76de04
--- /dev/null
@@ -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 (file)
index 0000000..73127c1
--- /dev/null
@@ -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 <pkgmgr-info.h>
+
+#include <string>
+
+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
index 0bff779..2f8f198 100644 (file)
@@ -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 (file)
index 0000000..dc8f122
--- /dev/null
@@ -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 <package-info.h>
+
+#include <boost/test/unit_test.hpp>
+
+#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()