1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
/*
* Copyright (c) 2009-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 <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <Elementary.h>
#include <pkgmgr-info.h>
#include <tzsh.h>
#include <tzsh_quickpanel_service.h>
#include <E_DBus.h>
#include "common.h"
#include "quickpanel-ui.h"
static inline int _is_space(char in)
{
if ((in == _SPACE)) {
return 1;
} else {
return 0;
}
}
static inline int _l_trim(char *in)
{
int i, j;
short int done;
i = 0;
done = 0;
while (!done && in[i] != '\0') {
if (_is_space(in[i])) {
i++;
} else {
done = 1;
}
}
j = 0;
while (in[i] != '\0') {
in[j++] = in[i++];
}
in[j] = '\0';
return 0;
}
static inline int _r_trim(char *in)
{
int i;
short int done;
i = strlen(in) - 1;
done = 0;
while (!done && !(i < 0)) {
if (_is_space(in[i])) {
in[i--] = '\0';
} else {
done = 1;
}
}
return(0);
}
HAPI void quickpanel_common_util_char_trim(char *text)
{
retif(text == NULL, , "invalid argument");
_l_trim(text);
_r_trim(text);
}
HAPI void quickpanel_common_util_char_replace(char *text, char s, char t)
{
retif(text == NULL, , "invalid argument");
int i = 0, text_len = 0;
text_len = strlen(text);
for (i = 0; i < text_len; i++) {
if (*(text + i) == s) {
*(text + i) = t;
}
}
}
HAPI void quickpanel_common_util_add_char_to_each_charactor(char *dst, const char *src, char t)
{
retif(dst == NULL, , "invalid argument");
retif(src == NULL, , "invalid argument");
int i = 0, text_len = 0;
text_len = strlen(src);
for (i = 0; i < text_len; i++) {
*(dst + (i * 2)) = *(src + i);
*(dst + ((i * 2) + 1)) = t;
}
}
static void _char_set(char *dst, char s, int index, int size)
{
if (index < size) {
*(dst + index) = s;
}
}
HAPI void quickpanel_common_util_phone_number_tts_make(char *dst, const char *src, int size)
{
retif(dst == NULL, , "invalid argument");
retif(src == NULL, , "invalid argument");
int no_op = 0;
int i = 0, j = 0, text_len = 0;
text_len = strlen(src);
for (i = 0, j= 0; i < text_len; i++) {
if (no_op == 1) {
_char_set(dst, *(src + i), j++, size);
} else {
if (isdigit(*(src + i))) {
if (i + 1 < text_len) {
if (*(src + i + 1) == '-' || *(src + i + 1) == _SPACE) {
_char_set(dst, *(src + i), j++, size);
} else {
_char_set(dst, *(src + i), j++, size);
_char_set(dst, _SPACE, j++, size);
}
} else {
_char_set(dst, *(src + i), j++, size);
_char_set(dst, _SPACE, j++, size);
}
} else if (*(src + i) == '-') {
no_op = 1;
_char_set(dst, *(src + i), j++, size);
} else {
_char_set(dst, *(src + i), j++, size);
}
}
}
}
HAPI int quickpanel_common_util_is_phone_number(const char *address)
{
int digit_count = 0;
retif(address == NULL, 0, "address is NULL");
int addr_len = 0;
addr_len = strlen(address);
if (addr_len == 0) {
return 0;
}
/* length check phone address should be longer than 2 and shorter than 40 */
if (addr_len > 2 && addr_len <= QP_UTIL_PHONE_NUMBER_MAX_LEN) {
const char *pszOneChar = address;
while (*pszOneChar) {
if (isdigit(*pszOneChar)) {
digit_count++;
}
++pszOneChar;
}
pszOneChar = address;
if (*pszOneChar == '+') {
++pszOneChar;
}
while (*pszOneChar) {
if (!isdigit(*pszOneChar)
&& (*pszOneChar != '*') && (*pszOneChar != '#')
&& (*pszOneChar != ' ')
&& !((*pszOneChar == '-') && digit_count >= 7)) {
return 0;
}
++pszOneChar;
}
return 1;
} else {
DBG("invalid address length [%d]", addr_len);
return 0;
}
}
static void _current_popup_default_backkey_cb(void *data, Evas_Object *obj, void *event_info)
{
Evas_Object *popup = data;
retif(popup == NULL, , "invalid argument");
if (popup!= NULL) {
evas_object_del(popup);
popup = NULL;
}
}
static void _current_popup_deleted_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
retif(obj == NULL, , "obj is NULL");
struct appdata *ad = quickpanel_get_app_data();
retif(ad == NULL, , "invalid argument");
if (ad->popup == obj) {
ad->popup = NULL;
} else {
ERR("popup is created over the popup");
}
}
HAPI void quickpanel_common_ui_set_current_popup(Evas_Object *popup, Evas_Smart_Cb func_back)
{
retif(popup == NULL, , "invalid argument");
struct appdata *ad = quickpanel_get_app_data();
retif(ad == NULL, , "invalid argument");
ad->popup = popup;
evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _current_popup_deleted_cb, NULL);
if (func_back != NULL) {
evas_object_data_set(popup, EDATA_BACKKEY_CB, func_back);
} else {
evas_object_data_set(popup, EDATA_BACKKEY_CB, _current_popup_default_backkey_cb);
}
}
HAPI void quickpanel_common_ui_del_current_popup(void)
{
struct appdata *ad = quickpanel_get_app_data();
retif(ad == NULL, , "invalid argument");
if (ad->popup != NULL) {
evas_object_del(ad->popup);
ad->popup = NULL;
}
}
HAPI void *quickpanel_common_ui_get_buffer_from_image(const char *file_path, size_t *memfile_size, char *ext, int ext_size)
{
FILE *fp = NULL;
void *buffer = NULL;
char *buf_ext = NULL;
retif(file_path == NULL, NULL, "invalid data");
if (ext != NULL) {
buf_ext = ecore_file_strip_ext(file_path);
if (buf_ext != NULL) {
strncpy(ext, buf_ext, ext_size);
free(buf_ext);
}
}
fp = fopen(file_path, "r");
if (fp) {
struct stat stat_buf;
if (stat(file_path, &stat_buf) != 0) {
ERR("Getting file information Error");
goto err;
}
if (stat_buf.st_size > 0) {
buffer = (void *)calloc(1, (size_t)stat_buf.st_size + 1);
if (buffer == NULL) {
ERR("failed to alloc a buffer");
goto err;
}
int result = fread(buffer, sizeof(char), stat_buf.st_size, fp);
if (result != stat_buf.st_size) {
ERR("failed to read a file");
free(buffer);
buffer = NULL;
goto err;
}
if (memfile_size != NULL) {
*memfile_size = result;
}
} else {
if (memfile_size != NULL) {
*memfile_size = 0;
}
}
}
err:
if (fp) {
fclose(fp);
}
return buffer;
}
HAPI char *quickpanel_common_ui_get_pkginfo_icon(const char *pkgid)
{
int ret = 0;
char *icon_path = NULL;
char *icon_ret = NULL;
retif(pkgid == NULL, NULL, "invalid parameter");
pkgmgrinfo_appinfo_h appinfo_h = NULL;
ret = pkgmgrinfo_appinfo_get_appinfo(pkgid, &appinfo_h);
if (ret < 0) {
ERR("pkgmgrinfo_appinfo_get_appinfo is failed %d", ret);
return NULL;
}
//icon path
ret = pkgmgrinfo_appinfo_get_icon(appinfo_h, &icon_path);
if (ret < 0) {
ERR("pkgmgrinfo_appinfo_get_icon is failed %d", ret);
}
if (icon_path) {
icon_ret = (char*)strdup(icon_path);
}
if (appinfo_h) {
pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
}
return icon_ret;
}
HAPI char *quickpanel_common_ui_get_pkginfo_label(const char *pkgid)
{
int ret = 0;
char *label = NULL;
char *value_ret = NULL;
retif(pkgid == NULL, NULL, "invalid parameter");
pkgmgrinfo_appinfo_h appinfo_h = NULL;
ret = pkgmgrinfo_appinfo_get_appinfo(pkgid, &appinfo_h);
if (ret < 0) {
ERR("pkgmgrinfo_appinfo_get_appinfo is failed %d", ret);
return NULL;
}
//icon path
ret = pkgmgrinfo_appinfo_get_label(appinfo_h, &label);
if (ret < 0) {
ERR("pkgmgrinfo_appinfo_get_icon is failed %d", ret);
}
if (label) {
value_ret = (char*)strdup(label);
}
if (appinfo_h) {
pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
}
return value_ret;
}
HAPI int quickpanel_common_ui_is_package_exist(const char *pkgid)
{
int ret = 0;
retif(pkgid == NULL, 0, "invalid parameter");
pkgmgrinfo_appinfo_h appinfo_h = NULL;
ret = pkgmgrinfo_appinfo_get_appinfo(pkgid, &appinfo_h);
if (ret < 0) {
DBG("package %s isn't exist", pkgid);
return 0;
}
if (appinfo_h) {
pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
}
return 1;
}
|