~jezra/vattery/trunk

« back to all changes in this revision

Viewing changes to src/battery.vala

  • Committer: jezra
  • Date: 2011-06-03 05:54:00 UTC
  • Revision ID: jezra@jezra.net-20110603055400-kzhhd2c479maad2m
Cleaned up some poopy doo

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
}
24
24
 
25
25
public struct BatteryData {
26
 
    public int percent;
27
 
    public string state;
 
26
        public int percent;
 
27
        public string state;
28
28
}
29
29
 
30
30
 
31
31
public class Battery {
32
 
        Regex bat_curr_regex;
33
 
        Regex bat_tot_regex;
 
32
        Regex bat_curr_regex_proc;
 
33
        Regex bat_tot_regex_proc;
34
34
        Regex ac_regex;
35
35
        int bat_percent;
36
36
        string ac_state;
39
39
        public Battery() {
40
40
                //create a regex to retrieve the current battery power
41
41
                try {
42
 
                        this.bat_curr_regex = new Regex(".*remaining.*:[ \t\n\r\f]*([0-9]*).*",GLib.RegexCompileFlags.CASELESS,RegexMatchFlags.NEWLINE_ANY);
 
42
                        this.bat_curr_regex_proc = new Regex(".*remaining.*:[ \t\n\r\f]*([0-9]*).*",GLib.RegexCompileFlags.CASELESS,RegexMatchFlags.NEWLINE_ANY);
43
43
                }catch(GLib.RegexError error) {
44
44
                        stdout.printf(error.message);
45
45
                }
46
46
                //create a regex to retrieve the last full capacity of the battery
47
47
                try {
48
 
                        this.bat_tot_regex = new Regex(".*last full capacity:[ \t\n\r\f]*([0-9]*).*",GLib.RegexCompileFlags.CASELESS,RegexMatchFlags.NEWLINE_ANY);
 
48
                        this.bat_tot_regex_proc = new Regex(".*last full capacity:[ \t\n\r\f]*([0-9]*).*",GLib.RegexCompileFlags.CASELESS,RegexMatchFlags.NEWLINE_ANY);
49
49
                } catch(GLib.RegexError error) {
50
50
                        stdout.printf(error.message);
51
51
                }
104
104
                                                        try{
105
105
                                                                if ( FileUtils.get_contents(state_file, out contents) ) {
106
106
                                                                        //regex to get current capacity
107
 
                                                                        this.bat_curr_regex.match(contents,GLib.RegexMatchFlags.NEWLINE_ANY, out match_info);
 
107
                                                                        this.bat_curr_regex_proc.match(contents,GLib.RegexMatchFlags.NEWLINE_ANY, out match_info);
108
108
                                                                        bat_curr = match_info.fetch(1);
109
109
                                                                        //regex to get the "charging" only if no ac state has been detected so far
110
110
                                                                        if (ac_state==""){
114
114
                                                                        //now check the info file to get the last recorded max capacity
115
115
                                                                        if(FileUtils.get_contents(info_file, out contents) ) {
116
116
                                                                                //regex to get total capacity
117
 
                                                                                this.bat_tot_regex.match(contents,GLib.RegexMatchFlags.NEWLINE_ANY,out match_info);
 
117
                                                                                this.bat_tot_regex_proc.match(contents,GLib.RegexMatchFlags.NEWLINE_ANY,out match_info);
118
118
                                                                                bat_total = match_info.fetch(1);
119
119
                                                                                //if we ever get this far, then data was found
120
120
                                                                                battery_data_found=true;