2 * Tizen Krate Setup-Wizard application
4 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include <notification.h>
20 #include "krate-setup.h"
22 #define KRATE_METADATA_PATH "data/KrateManifest.xml"
24 static char *__get_krate_metadata(void)
27 char *res_path = NULL;
28 char *metadata = NULL;
29 char metadata_path[PATH_MAX] = "\0";
33 res_path = app_get_resource_path();
34 if (res_path == NULL) {
35 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get resource path");
38 snprintf(metadata_path, PATH_MAX, "%s%s", res_path, KRATE_METADATA_PATH);
41 fp = fopen(metadata_path, "r");
43 if (fseek(fp, 0, SEEK_END) == -1)
44 dlog_print(DLOG_ERROR, LOG_TAG, "failed to fseek");
48 dlog_print(DLOG_ERROR, LOG_TAG, "failed to get file size");
53 metadata = malloc(fsize + 1);
54 if (metadata == NULL) {
55 dlog_print(DLOG_ERROR, LOG_TAG, "failed to allocate memory");
59 memset(metadata, 0, fsize + 1);
60 if (fseek(fp, 0, SEEK_SET) == -1) {
61 dlog_print(DLOG_ERROR, LOG_TAG, "failed to fseek");
67 ret = fread(metadata, fsize, 1, fp);
69 dlog_print(DLOG_ERROR, LOG_TAG, "failed to read metadata file");
75 dlog_print(DLOG_ERROR, LOG_TAG, "failed to open metadata file");
84 int _send_krate_create_request(appdata_s *ad)
87 char *metadata = NULL;
89 metadata = __get_krate_metadata();
90 if (metadata == NULL) {
91 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get krate metadata");
95 ret = krate_manager_create_krate(ad->krate_manager, ad->krate_name, metadata);
96 if (ret != KRATE_ERROR_NONE) {
105 int _send_krate_remove_request(appdata_s *ad)
109 ret = krate_manager_destroy_krate(ad->krate_manager, ad->krate_name);
110 if (ret != KRATE_ERROR_NONE) {
117 static int __set_notification(notification_h noti_handle, app_control_h app_control)
121 char *noti_text[2][2] = {
122 {"IDS_TPLATFORM_HEADER_SEPARATE_ZONE_ABB", "IDS_TPLATFORM_SBODY_TAP_HERE_TO_CREATE_PS_ABB"},
123 {"IDS_TPLATFORM_HEADER_SEPARATE_ZONE_ABB", "IDS_TPLATFORM_SBODY_TAP_HERE_TO_DELETE_PS_ABB"}
126 char noti_content_text[PATH_MAX] = "";
127 char *krate_name = NULL;
129 if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE)
132 if (!strcmp(mode, "create"))
137 ret = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, __(text[0]), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
138 if (ret != NOTIFICATION_ERROR_NONE)
141 ret = app_control_get_extra_data(app_control, "krate", &krate_name);
142 if (ret != APP_CONTROL_ERROR_NONE)
145 snprintf(noti_content_text, PATH_MAX, __(text[1]), krate_name);
147 ret = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, noti_content_text, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
148 if (ret != NOTIFICATION_ERROR_NONE)
151 ret = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ALL);
152 if (ret != NOTIFICATION_ERROR_NONE)
155 ret = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, DPM_SYSPOPUP_ICON_PATH);
156 if (ret != NOTIFICATION_ERROR_NONE)
159 ret = notification_set_launch_option(noti_handle, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, app_control);
160 if (ret != NOTIFICATION_ERROR_NONE)
166 void _create_notification(app_control_h app_control)
168 notification_h noti_handle = NULL;
171 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
173 ret = __set_notification(noti_handle, app_control);
174 if (ret != NOTIFICATION_ERROR_NONE) {
175 notification_free(noti_handle);
176 app_control_destroy(app_control);
180 notification_post(noti_handle);
181 notification_free(noti_handle);
182 app_control_destroy(app_control);