4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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.
23 #include "core/edbus-handler.h"
26 #define METHOD_COMPLETE_NOTI_ON "CompNotiOn"
27 #define METHOD_PROGRESS_NOTI_ON "ProgNotiOn"
28 #define METHOD_PROGRESS_NOTI_OFF "ProgNotiOff"
29 #define METHOD_PROGRESS_NOTI_UPDATE "ProgNotiUpdate"
30 #define METHOD_ERROR_NOTI_ON "ErrorNotiOn"
31 #define METHOD_ERROR_NOTI_OFF "ErrorNotiOff"
35 static const char *ode_type_str[] = {
36 [ENCRYPT_TYPE] = "encrypt",
37 [DECRYPT_TYPE] = "decrypt",
40 static int progress_h;
43 static int method_noti(const char *method, const char *sig, char *param[])
45 int ret, retry = RETRY_CNT;
48 ret = dbus_method_sync(POPUP_BUS_NAME,
60 int noti_progress_show(int type)
66 /* If ongoing noti already exists, delete the noti */
68 noti_progress_clear();
70 /* If error noti already exists, delete the noti */
74 snprintf(str_type, sizeof(str_type), "%s", ode_type_str[type]);
77 ret = method_noti(METHOD_PROGRESS_NOTI_ON, "s", arr);
82 _D("insert progress noti handle : %d", progress_h);
86 int noti_progress_clear(void)
92 if (progress_h <= 0) {
93 _D("already ongoing noti clear");
97 snprintf(str_h, sizeof(str_h), "%d", progress_h);
100 ret = method_noti(METHOD_PROGRESS_NOTI_OFF, "i", arr);
104 _D("delete progress noti handle : %d", progress_h);
109 int noti_progress_update(int rate)
115 if (progress_h <= 0) {
116 _E("need to create notification");
120 if (rate < 0 || rate > 100) {
121 _E("Invalid parameter");
125 snprintf(str_h, sizeof(str_h), "%d", progress_h);
127 snprintf(str_r, sizeof(str_r), "%d", rate);
130 return method_noti(METHOD_PROGRESS_NOTI_UPDATE, "ii", arr);
133 int noti_finish_show(int type)
139 snprintf(str_type, sizeof(str_type), "%s", ode_type_str[type]);
142 return method_noti(METHOD_COMPLETE_NOTI_ON, "s", arr);
145 int noti_error_show(int type, int state, int val)
147 char str_type[32], str_state[32], str_val[32];
151 /* If ongoing noti already exists, delete the noti */
155 snprintf(str_type, sizeof(str_type), "%s", ode_type_str[type]);
157 snprintf(str_state, sizeof(str_state), "%d", state);
159 snprintf(str_val, sizeof(str_val), "%d", val);
162 ret = method_noti(METHOD_ERROR_NOTI_ON, "sii", arr);
167 _D("insert error noti handle : %d", error_h);
171 int noti_error_clear(void)
178 _D("already ongoing noti clear");
182 snprintf(str_h, sizeof(str_h), "%d", error_h);
185 ret = method_noti(METHOD_ERROR_NOTI_OFF, "i", arr);
189 _D("delete error noti handle : %d", error_h);