Tizen 2.0 Release
[apps/home/settings.git] / setting-memory / src / setting-memory-common.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <setting-memory-common.h>
18 #include<sys/wait.h>
19
20 int setting_memory_update_popup_with_progress_bar(void *data)
21 {
22         SETTING_TRACE_BEGIN;
23         SettingMemoryUG *ad = (SettingMemoryUG *) data;
24
25         if (ad->progress_bar != NULL) {
26                 SETTING_TRACE("ad->progress_bar_rate = %f",
27                               (float)ad->progress_bar_rate);
28                 elm_progressbar_value_set(ad->progress_bar,
29                                           ad->progress_bar_rate);
30         }
31
32         if (ad->progress_bar_timer != NULL) {
33                 ecore_timer_del(ad->progress_bar_timer);
34                 ad->progress_bar_timer = NULL;
35         }
36
37         return 0;
38 }
39
40 void setting_memory_hide_popup_with_progress_bar(SettingMemoryUG *ad)
41 {
42         SETTING_TRACE_BEGIN;
43         if (ad->progress_bar) {
44                 elm_progressbar_value_set(ad->progress_bar, 1.0);
45
46                 evas_object_del(ad->progress_bar);
47                 ad->progress_bar = NULL;
48         }
49         if (ad->popup) {
50                 evas_object_del(ad->popup);
51                 ad->popup = NULL;
52         }
53
54         if (ad->popup_timer) {
55                 ecore_timer_del(ad->popup_timer);
56                 ad->popup_timer = NULL;
57         }
58 }
59
60 /** not used now */
61 int setting_system_command(const char *command)
62 {
63         SETTING_TRACE_BEGIN;
64         int pid = 0, status = 0;
65         char *const environ[] = { NULL };
66
67         if (command == 0) {
68                 return 1;
69         }
70
71         pid = fork();
72
73         if (pid == -1) {
74                 return SETTING_RETURN_FAIL;
75         }
76
77         if (pid == 0) {
78                 char *argv[SETTING_MEMORY_SYS_COMMAND_ARGV_LEN];
79
80                 argv[0] = "sh";
81                 argv[1] = "-c";
82                 argv[2] = (char *)command;
83                 argv[3] = 0;
84
85                 execve("/bin/sh", argv, environ);
86                 /* exit(127); */
87                 abort();
88         }
89
90         do {
91                 if (waitpid(pid, &status, 0) == -1) {
92                         if (errno != EINTR) {
93                                 return SETTING_RETURN_FAIL;
94                         }
95                 } else {
96                         return status;
97                 }
98
99         } while (1);
100 }