Tizen 2.1 release
[platform/core/uifw/e17.git] / src / modules / wizard / page_090.c
1 /* Setup if we need battery? */
2 #include "e.h"
3 #include "e_mod_main.h"
4
5 #ifdef __FreeBSD__
6 # include <sys/ioctl.h>
7 # include <sys/sysctl.h>
8 # ifdef __i386__
9 #  include <machine/apm_bios.h>
10 # endif
11 #endif
12
13 static char *
14 read_file(const char *file)
15 {
16    FILE *f = fopen(file, "r");
17    size_t len;
18    char buf[4096], *p;
19    if (!f) return NULL;
20    len = fread(buf, 1, sizeof(buf) - 1, f);
21    if (len == 0)
22      {
23         fclose(f);
24         return NULL;
25      }
26    buf[len] = 0;
27    for (p = buf; *p; p++)
28      {
29         if (p[0] == '\n') p[0] = 0;
30      }
31    fclose(f);
32    return strdup(buf);
33 }
34
35 EAPI int
36 wizard_page_init(E_Wizard_Page *pg __UNUSED__)
37 {
38    return 1;
39 }
40
41 EAPI int
42 wizard_page_shutdown(E_Wizard_Page *pg __UNUSED__)
43 {
44    return 1;
45 }
46
47 EAPI int
48 wizard_page_show(E_Wizard_Page *pg __UNUSED__)
49 {
50    int hav_bat = 0;
51    Eina_List *dir;
52    char buf[PATH_MAX], *file, *dname, *str;
53
54    dname = "/sys/class/power_supply";
55    dir = ecore_file_ls(dname);
56    if (dir)
57      {
58         EINA_LIST_FREE(dir, file)
59           {
60              snprintf(buf, sizeof(buf), "%s/%s/type", dname, file);
61              str = read_file(buf);
62              if (str)
63                {
64                   if (!strcasecmp(str, "Battery")) hav_bat = 1;
65                   free(str);
66                }
67           }
68      }
69    dname = "/proc/acpi/battery/";
70    dir = ecore_file_ls(dname);
71    if (dir)
72      {
73         EINA_LIST_FREE(dir, file)
74           {
75              snprintf(buf, sizeof(buf), "%s/%s/state", dname, file);
76              str = read_file(buf);
77              if (str)
78                {
79                   hav_bat = 1;
80                   free(str);
81                }
82           }
83      }
84 #ifdef __FreeBSD__
85    do {
86         int mib_state[4];
87         int state = 0;
88         size_t len;
89
90         /* Read some information on first run. */
91         len = 4;
92         sysctlnametomib("hw.acpi.battery.state", mib_state, &len);
93         len = sizeof(state);
94         if (sysctl(mib_state, 4, &state, &len, NULL, 0) != -1)
95           hav_bat = 1;
96      } while (0);
97 #endif
98    if (!hav_bat)
99      {
100         E_Config_Module *em;
101         Eina_List *l;
102
103         EINA_LIST_FOREACH(e_config->modules, l, em)
104           {
105              if (!em->name) continue;
106              if (!strcmp(em->name, "battery"))
107                {
108                   e_config->modules = eina_list_remove_list
109                       (e_config->modules, l);
110                   if (em->name) eina_stringshare_del(em->name);
111                   free(em);
112                   break;
113                }
114           }
115         e_config_save_queue();
116      }
117    return 0; /* 1 == show ui, and wait for user, 0 == just continue */
118 }
119
120 EAPI int
121 wizard_page_hide(E_Wizard_Page *pg __UNUSED__)
122 {
123    return 1;
124 }
125
126 EAPI int
127 wizard_page_apply(E_Wizard_Page *pg __UNUSED__)
128 {
129    return 1;
130 }
131