+ // check battery
+ GDir *directory;
+ GError *error = NULL;
+ const char *entryname;
+ char *battery_dir = 0;
+
+ path_energy_now = path_energy_full = path_current_now = path_status = 0;
+ directory = g_dir_open("/sys/class/power_supply", 0, &error);
+ if (error)
+ g_error_free(error);
+ else {
+ while ((entryname=g_dir_read_name(directory))) {
+ if (strncmp(entryname,"AC", 2) == 0) continue;
+
+ char *path1 = g_build_filename("/sys/class/power_supply", entryname, "present", NULL);
+ if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
+ g_free(path1);
+ battery_dir = g_build_filename("/sys/class/power_supply", entryname, NULL);
+ break;
+ }
+ g_free(path1);
+ }
+ }
+ if (battery_dir != 0) {
+ path_energy_now = g_build_filename(battery_dir, "energy_now", NULL);
+ path_energy_full = g_build_filename(battery_dir, "energy_full", NULL);
+ path_current_now = g_build_filename(battery_dir, "current_now", NULL);
+ path_status = g_build_filename(battery_dir, "status", NULL);
+ }
+