data: for getting app data by using pkgmgr-info 02/42402/1
authorHyojung Jo <hj903.jo@samsung.com>
Sat, 27 Jun 2015 08:06:53 +0000 (17:06 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Sat, 27 Jun 2015 08:06:53 +0000 (17:06 +0900)
Change-Id: I84ae3e921cbd26a7ab1aaf2f265423369c61c3f4
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
CMakeLists.txt
include/data/app.h [new file with mode: 0644]
packaging/org.tizen.apps.spec
src/data/app.c [new file with mode: 0644]

index 65d9e1cddfc746387de16d8fc5dace987f99270b..437f718b2f9b5652ff681ff930987a3c1e524e36 100644 (file)
@@ -22,6 +22,7 @@ pkg_check_modules(PKGS REQUIRED
                elementary
                capi-appfw-application
                app-utils
+               pkgmgr-info
                )
 
 IF(NOT DEFINED PACKAGE_NAME)
@@ -49,6 +50,7 @@ ENDIF(NOT DEFINED PACKAGEDIR)
 SET(SRCS
        src/main.c
        src/utils.c
+       src/data/app.c
        src/view/view_base.c
        src/view/view_action_menu.c
        src/layout/layout_myapps.c
diff --git a/include/data/app.h b/include/data/app.h
new file mode 100644 (file)
index 0000000..0ef2b15
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 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.
+ */
+
+#ifndef __AIR_APPS_APP_H__
+#define __AIR_APPS_APP_H__
+
+#include <Elementary.h>
+
+struct app_data;
+
+Eina_List *get_app_list(void);
+char *get_app_id(struct app_data *adata);
+char *get_app_name(struct app_data *adata);
+char *get_app_icon(struct app_data *adata);
+void free_app_list(Eina_List *list);
+
+#endif /* __AIR_APPS_APP_H__ */
index 4493141bb4dc4797c90a524ec272d2387d6495ca..5942fd59ffc392276b5e2154aeb4b3adda920d73 100644 (file)
@@ -11,6 +11,7 @@ BuildRequires: cmake
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(app-utils)
+BuildRequires: pkgconfig(pkgmgr-info)
 
 %define _appdir /usr/apps/%{name}
 %define _bindir %{_appdir}/bin
diff --git a/src/data/app.c b/src/data/app.c
new file mode 100644 (file)
index 0000000..67dff40
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2015 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.
+ */
+
+#include <pkgmgr-info.h>
+#include <app_contents.h>
+#include <app_debug.h>
+
+#include "data/app.h"
+
+struct app_data {
+       char *appid;
+       char *name;
+       char *icon;
+       bool is_locked;
+       bool is_favorite;
+};
+
+static int _get_app_data_foreach(pkgmgrinfo_appinfo_h handle, void *data)
+{
+       Eina_List **list;
+       struct app_data *adata;
+       char *appid, *name, *icon;
+       bool is_favorite;
+       int r;
+
+       if (!data)
+               return -1;
+
+       list = (Eina_List **)data;
+
+       if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK)
+               return -1;
+
+       if (pkgmgrinfo_appinfo_get_label(handle, &name) != PMINFO_R_OK)
+               return -1;
+
+       if (pkgmgrinfo_appinfo_get_icon(handle, &icon) != PMINFO_R_OK)
+               return -1;
+
+       r = app_contents_favorite_check(CONTENTS_APP, appid, &is_favorite);
+       if (r != APP_CONTENTS_ERROR_NONE)
+               return -1;
+
+       adata = calloc(1, sizeof(*adata));
+       if (!adata) {
+               _ERR("Calloc failed.");
+               return -1;
+       }
+
+       if (appid)
+               adata->appid = strdup(appid);
+       if (name)
+               adata->name = strdup(name);
+       if (icon)
+               adata->icon = strdup(icon);
+
+       adata->is_favorite = is_favorite;
+
+       *list = eina_list_append(*list, adata);
+
+       return 0;
+}
+
+Eina_List *get_app_list(void)
+{
+       Eina_List *list = NULL;
+
+       pkgmgrinfo_appinfo_get_usr_installed_list(_get_app_data_foreach,
+                       getuid(), &list);
+
+       return list;
+}
+
+char *get_app_id(struct app_data *adata)
+{
+       if (!adata) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       return adata->appid;
+}
+
+char *get_app_name(struct app_data *adata)
+{
+       if (!adata) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       return adata->name;
+}
+
+char *get_app_icon(struct app_data *adata)
+{
+       if (!adata) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       return adata->icon;
+}
+
+void free_app_list(Eina_List *list)
+{
+       struct app_data *adata;
+
+       if (!list)
+               return;
+
+       EINA_LIST_FREE(list, adata) {
+               if (!adata)
+                       continue;
+
+               free(adata->appid);
+               free(adata->name);
+               free(adata->icon);
+               free(adata);
+
+               adata = NULL;
+       }
+}