merge with master
[apps/home/mobileprint.git] / mobileprint / app / pts_util.c
1 /*
2 *  Mobileprint
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.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
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_appdata_t *ad = pts_get_appdata();
29         //PTS_RET_IF(ad == NULL, "ad is NULL");
30         //PTS_RET_IF(ad->win == NULL, "ad->win is NULL");
31
32         PTS_RET_IF(parent == NULL, "");
33
34         Evas_Object *error_popup = elm_popup_add(parent);
35         PTS_RET_IF(error_popup == NULL, "error_popup is NULL");
36         evas_object_size_hint_weight_set(error_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
37         elm_object_text_set(error_popup, msg);
38         evas_object_show(error_popup);
39         evas_object_show(parent);
40         return;
41 }
42
43 Eina_Bool pts_util_supported_arch(void)
44 {
45         struct utsname buf;
46         int ret = uname(&buf);
47         if (ret == -1) {
48                 PTS_DEBUG("Failed to get uname");
49         } else if (strstr(buf.machine,"arm") == NULL) {
50                 PTS_DEBUG("No supported : %s", buf.machine);
51                 return EINA_FALSE;
52         } else {
53                 PTS_DEBUG("Supported : %s", buf.machine);
54         }
55         return EINA_TRUE;
56 }
57
58 void pts_util_remove_tmp_files(const char *path)
59 {
60         PTS_TRACE_BEGIN;
61         PTS_RET_IF(path == NULL, "path is NULL");
62         char *cwd;
63         struct dirent *entry;
64         int ret = 1;
65         int iret = -1;
66         DIR *dir;
67
68         cwd = get_current_dir_name();
69
70         errno = 0;
71         ret = chdir(path);
72         if (ret == 0) {
73                 dir = opendir(path);
74                 while ((entry = readdir(dir)) != NULL) {
75                         PTS_DEBUG("Remove %s", entry->d_name);
76                         iret = remove(entry->d_name);
77                         if (iret == -1) {
78                                 PTS_DEBUG("unable to remove %s",entry->d_name);
79                         }
80                 }
81                 closedir(dir);
82
83                 iret = chdir(cwd);
84                 PTS_IF_FREE_MEM(cwd);
85                 PTS_RET_IF(iret == -1, "unable to chdir");
86                 rmdir(path);
87         } else {
88                 if (errno == ENOENT) {
89                         PTS_DEBUG("Not existed %s, just skip", path);
90                 }
91         }
92         PTS_TRACE_END;
93         return;
94 }