1. Changed license year
[apps/home/mobileprint.git] / mobileprint / app / pts_util.c
1 /*
2 *  Mobileprint
3 *
4 * Copyright 2013  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.1 (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
9
10 * http://floralicense.org/license/
11
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.
17 *
18 */
19
20 #include <linux/unistd.h>
21 #include <sys/utsname.h>
22 #include <dirent.h>
23 #include "pts_common.h"
24 #include "pts_debug.h"
25
26 void pts_util_show_error_popup(Evas_Object *parent, const char *msg)
27 {
28         PTS_RET_IF(parent == NULL, "parent is NULL");
29         PTS_RET_IF(msg == NULL, "msg is NULL");
30
31         Evas_Object *error_popup = elm_popup_add(parent);
32         PTS_RET_IF(error_popup == NULL, "error_popup is NULL");
33         evas_object_size_hint_weight_set(error_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
34         elm_object_text_set(error_popup, msg);
35         evas_object_show(error_popup);
36         evas_object_show(parent);
37         return;
38 }
39
40 Eina_Bool pts_util_supported_arch(void)
41 {
42         struct utsname buf;
43         int ret = uname(&buf);
44         if (ret == -1) {
45                 PTS_DEBUG("Failed to get uname");
46         } else if (strstr(buf.machine,"arm") == NULL) {
47                 PTS_DEBUG("No supported : %s", buf.machine);
48                 return EINA_FALSE;
49         } else {
50                 PTS_DEBUG("Supported : %s", buf.machine);
51         }
52         return EINA_TRUE;
53 }
54
55 void pts_util_remove_tmp_files(const char *path)
56 {
57         PTS_TRACE_BEGIN;
58         PTS_RET_IF(path == NULL, "path is NULL");
59         char *cwd;
60         struct dirent *entry;
61         int ret = 1;
62         int iret = -1;
63         DIR *dir;
64
65         cwd = get_current_dir_name();
66         PTS_RET_IF(cwd == NULL, "cwd is NULL");
67
68         errno = 0;
69         ret = chdir(path);
70         if (ret == 0) {
71                 dir = opendir(path);
72                 if (dir == NULL) {
73                         PTS_IF_FREE_MEM(cwd);
74                         PTS_TRACE_END;
75                         return;
76                 }
77                 while ((entry = readdir(dir)) != NULL) {
78                         PTS_DEBUG("Remove %s", entry->d_name);
79                         iret = remove(entry->d_name);
80                         if (iret == -1) {
81                                 PTS_DEBUG("unable to remove %s",entry->d_name);
82                         }
83                 }
84                 closedir(dir);
85
86                 iret = chdir(cwd);
87                 if (iret == -1) {
88                         PTS_DEBUG("unable to chdir");
89                         PTS_IF_FREE_MEM(cwd);
90                         PTS_TRACE_END;
91                         return;
92                 }
93                 rmdir(path);
94         } else {
95                 if (errno == ENOENT) {
96                         PTS_DEBUG("Not existed %s, just skip", path);
97                 }
98         }
99         PTS_IF_FREE_MEM(cwd);
100         PTS_TRACE_END;
101         return;
102 }