File: convertwindow.fl

package info (click to toggle)
obdgpslogger 0.16-1.3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,160 kB
  • ctags: 7,498
  • sloc: ansic: 73,206; cpp: 2,055; php: 407; sh: 51; makefile: 4
file content (155 lines) | stat: -rw-r--r-- 3,901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# data file for the Fltk User Interface Designer (fluid)
version 1.0109 
header_name {.h} 
code_name {.cxx}
decl {\#include <stdio.h>} {} 

decl {\#include <stdlib.h>} {} 

decl {\#include <string.h>} {} 

decl {\#include <FL/Fl.H>} {} 

decl {\#include <FL/Fl_File_Chooser.H>} {} 

decl {\#include "obdgui.h"} {public
} 

decl {\#include "maindisplay.h"} {public
} 

class obdconvertwindow {open
} {
  Function {obdconvertwindow(OBDUI *obdui)} {open
  } {
    code {mConvertType = CONVERT_KML;} {}
    Fl_Window window {
      label {Convert OBD Log...} open
      xywh {749 124 555 195} type Double
      code0 {o->set_modal();}
      code1 {o->hide();} visible
    } {
      Fl_Group allcontrols {open
        xywh {95 10 310 135}
      } {
        Fl_File_Input logfilename {
          label {Log File}
          xywh {95 10 310 30}
          code0 {o->value(obdui->getLogfilename());}
        }
        Fl_File_Input outputfilename {
          label {Output File}
          xywh {95 45 310 30}
          code0 {o->value("./obdlogger.kml");}
        }
        Fl_Choice convertchoice {
          label {Convert to...} open
          xywh {95 85 310 25} down_box BORDER_BOX
        } {
          MenuItem {} {
            label {Google Earth (.kml)}
            callback {mConvertType = CONVERT_KML;}
            xywh {0 0 100 20}
          }
          MenuItem {} {
            label {CSV (.csv)}
            callback {mConvertType = CONVERT_CSV;}
            xywh {0 0 31 20}
          }
        }
        Fl_Button convertbutton {
          label Convert
          callback {convert();}
          xywh {180 120 105 25}
        }
        Fl_Button donebutton {
          label Done
          callback {window->hide();}
          xywh {295 120 105 25}
        }
      }
      Fl_Progress progressbar {
        label {Conversion Progress} selected
        xywh {25 160 510 25} selection_color 138
        code0 {o->value(0);}
      }
      Fl_Button logchooser {
        label {Choose...}
        callback {Fl_File_Chooser f(mMainui->getLogfilename(),
  "OBDGPS Logfiles (*.db)\\tAll Files (*)",
  Fl_File_Chooser::SINGLE, "Choose OBD GPS Logfile" );
f.show();
while(f.shown()) {
  Fl::check();
}
if(0 < f.count())
  logfilename->value(f.value());}
        private xywh {415 10 120 30}
      }
      Fl_Button outchooser {
        label {Choose...}
        callback {Fl_File_Chooser f(".",
  "Google Earth (*.kml)\\tCSV (*.csv)\\tAll Files (*)",
  Fl_File_Chooser::CREATE, "Choose Output Logfile" );
f.show();
while(f.shown()) {
  Fl::check();
}
if(0 < f.count())
  outputfilename->value(f.value());}
        private xywh {415 45 120 30}
      }
    }
    code {mMainui = obdui;} {}
  }
  decl {OBDUI *mMainui;} {}
  decl {enum obd_convert_type mConvertType;} {}
  Function {show()} {open
  } {
    code {window->show();} {}
  }
  Function {hide()} {open
  } {
    code {window->hide();} {}
  }
  Function {convert()} {open
  } {
    code {FILE *p;
float progresspercentage;
char line[255];
char cmd[1024] = "\\0";

allcontrols->deactivate();

switch(mConvertType) {
  case CONVERT_KML:
    //printf("Converting to KML\\n");
    snprintf(cmd, sizeof(cmd), "obd2kml -p -d %s -o %s",
      mMainui->getLogfilename(), outputfilename->value());
    break;
  case CONVERT_CSV:
    //printf("Converting to CSV\\n");
    snprintf(cmd, sizeof(cmd), "obd2csv -p -d %s -o %s",
      mMainui->getLogfilename(), outputfilename->value());
    break;
  default:
    //printf("Not converting anything\\n");
    break;
}

if(0 < strlen(cmd) && NULL == (p = popen(cmd, "r"))) {
  perror(cmd);
} else {
  while(NULL != fgets(line, sizeof(line), p)) {
    if(0 < sscanf(line, "%f", &progresspercentage)) {
      progressbar->value(progresspercentage);
      Fl::check();
    }
  }
  progressbar->value(100); // Because the conversion tools may not be 100% accurate
  pclose(p);
}

allcontrols->activate();} {}
  }
}