-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserInterface.cc
More file actions
77 lines (66 loc) · 1.85 KB
/
UserInterface.cc
File metadata and controls
77 lines (66 loc) · 1.85 KB
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
// generated by Fast Light User Interface Designer (fluid) version 1.0302
#include "UserInterface.h"
#include <cstdio>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
void UserInterface::cb_m_btn_quit_i(Fl_Button*, void*) {
m_window->hide();
}
void UserInterface::cb_m_btn_quit(Fl_Button* o, void* v) {
((UserInterface*)(o->parent()->user_data()))->cb_m_btn_quit_i(o,v);
}
void UserInterface::cb_watch_fd(int fd, void* v) {
Fl_Progress *p = (Fl_Progress*)(v);
char buf[30];
float f;
char *pos = buf;
char *end = pos + 29;
while ((read(fd, pos, 1) > 0) && (*pos != '\n') && (pos != end)) {
pos++;
}
if (buf[0] == 'E') {
Fl::remove_fd(fd);
p->hide();
if(p->parent()) {
p->parent()->remove(p);
}
Fl::delete_widget(p);
} else {
// Read line as percent complete
sscanf(buf, "%f\n", &f);
p->value(f);
}
return;
}
UserInterface::UserInterface(int argc, char** argv) {
{ m_window = new Fl_Double_Window(440, 415, "Copy USB");
m_window->user_data((void*)(this));
{ m_pack = new Fl_Pack(0, 20, 440, 360, "Active Copies");
m_pack->end();
} // Fl_Pack* m_pack
{ m_btn_quit = new Fl_Button(380, 385, 55, 25, "Quit");
m_btn_quit->callback((Fl_Callback*)cb_m_btn_quit);
} // Fl_Button* m_btn_quit
m_window->end();
} // Fl_Double_Window* m_window
m_window->show(argc, argv);
}
Fl_Progress* UserInterface::add_progress_bar(const char *name)
{
Fl_Progress *o;
m_pack->begin();
o = new Fl_Progress(0, 20, 440, 25, name);
o->minimum(0);
o->maximum(100);
m_pack->end();
return o;
}
void UserInterface::watch_fd(const char *name, int fd)
{
// Memory leak, but needed, Fl_Progress doesn't make a copy
char *n = (char*)malloc(strlen(name) + 1);
memcpy(n, name, strlen(name)+1);
Fl_Progress *p = add_progress_bar(n);
Fl::add_fd(fd, FL_READ, cb_watch_fd, (void*)p);
}