deb fixes
[qbat.git] / common.cpp
blob5d54bba64fb49c93bbb46be35473923a4602084e
1 //
2 // C++ Implementation: common
3 //
4 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
5 //
6 // Copyright: See COPYING file that comes with this distribution
7 //
8 #include <cstdlib>
9 #include "common.h"
11 namespace qbat {
12 using namespace std;
14 bool readStringFromFile(char * buffer, const char * fileName) {
15 FILE *f = NULL;
16 f = fopen(fileName, "r");
17 if (f) {
18 fgets(buffer, BUF_SIZE, f);
19 fclose(f);
21 bool fill = false;
22 for (int i = 0; i < BUF_SIZE; i++) {
23 if (buffer[i] == '\n')
24 fill = true;
25 if (fill)
26 buffer[i] = '\0';
29 return true;
31 else
32 return false;
35 int readIntSysFile(const char * fileName) {
36 char buffer[BUF_SIZE];
37 readStringFromFile(buffer, fileName);
38 return atoi(buffer);
41 int toStatusInt(const char * status) {
42 if (strcmp(status, "Discharging") == 0)
43 return UI_BATTERY_DISCHARGING;
44 else if (strcmp(status, "Charging") == 0)
45 return UI_BATTERY_CHARGING;
46 else if (strcmp(status, "Full") == 0)
47 return UI_BATTERY_FULL;
48 else
49 return 0;