Debian Codegraph @

source/control.cc

raw
1 // ----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2003-2013 Fons Adriaensen <[email protected]>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // ----------------------------------------------------------------------------
19
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "control.h"
24 #include "global.h"
25
26
27 Control::Control (X_display *display, X_resman *resman) :
28 A_thread ("Control"),
29 _display (display),
30 _resman (resman),
31 _mainwin (0),
32 _captwin (0),
33 _filewin (0),
34 _sgenwin (0)
35 {
36 _rootwin = new X_rootwin (display);
37 _xhandler = new X_handler (display, this, EV_X11);
38 _xhandler->next_event ();
39
40 strcpy (_sessiondir, ".");
41 strcpy (_sweepfile, "");
42 }
43
44
45 Control::~Control (void)
46 {
47 delete _xhandler;
48 delete _rootwin;
49 }
50
51
52 void Control::stop (void)
53 {
54 _mainwin->stop ();
55 _captwin->stop ();
56 }
57
58
59 void Control::init (void)
60 {
61 const char *p;
62
63 _filewin = new Filewin (_rootwin, _resman);
64 _mainwin = new Mainwin (_rootwin, _resman, this, _filewin, this);
65 _captwin = new Captwin (_rootwin, _resman, this, _filewin);
66 _sgenwin = new Sgenwin (_rootwin, _resman, this);
67 p = getenv ("HOME");
68 _filewin->set_home (p ? p : ".");
69 }
70
71
72 void Control::fini (void)
73 {
74 delete _mainwin;
75 delete _captwin;
76 delete _filewin;
77 delete _sgenwin;
78 }
79
80
81 void Control::thr_main (void)
82 {
83 init ();
84 set_time ();
85 inc_time (100000);
86 while (_mainwin->running () || _captwin->running ())
87 {
88 handle_event (get_event_timed ());
89 }
90 fini ();
91 }
92
93
94 void Control::handle_event (int k)
95 {
96 switch (k)
97 {
98 case TO_CTRL:
99 handle_mesg (get_message ());
100 break;
101
102 case EV_X11:
103 _rootwin->handle_event ();
104 _xhandler->next_event ();
105 break;
106
107 case EV_PROG:
108 handle_prog ();
109 break;
110
111 case EV_TIME:
112 inc_time (50000);
113 handle_time ();
114 XFlush (_display->dpy ());
115 break;
116
117 default:
118 ;
119 }
120 }
121
122
123 void Control::handle_mesg (ITC_mesg *M)
124 {
125 _mainwin->handle_mesg (M);
126 }
127
128
129 void Control::handle_prog (void)
130 {
131 _mainwin->handle_prog ();
132 }
133
134
135 void Control::handle_time (void)
136 {
137 _mainwin->handle_time ();
138 _captwin->handle_time ();
139 }
140
141
142 void Control::handle_callb (int k, X_window *W, XEvent *E)
143 {
144 if (k == (BUTTON | X_button::RELSE)) k = ((X_button *) W)->cbid ();
145
146 switch (k)
147 {
148 case CB_MAIN_CLOSE:
149 stop ();
150 break;
151
152 case CB_CAPT_AVAIL:
153 _sgenwin->set_rate (_captwin->get_rate ());
154 _captwin->set_sess (_sessiondir);
155 break;
156
157 case CB_CAPT_NOTAV:
158 _captwin->stop ();
159 _captwin->hide ();
160 break;
161
162 case CB_CAPT_READY:
163 break;
164
165 case CB_SGEN_READY:
166 break;
167
168 case CB_OPEN_SGEN:
169 _sgenwin->show ();
170 break;
171
172 case CB_OPEN_CAPT:
173 _captwin->show ();
174 break;
175
176 case CB_FILE_SESS:
177 makesess ();
178 break;
179
180 default:
181 ;
182 }
183 }
184
185
186 void Control::makesess (void)
187 {
188 strcpy (_sessiondir, _filewin->wdir ());
189 chdir (_sessiondir);
190 mkdir ("sweep", 0777);
191 mkdir ("capture", 0777);
192 mkdir ("impresp", 0777);
193 mkdir ("edited", 0777);
194 _filewin->set_sess (_sessiondir);
195 _mainwin->set_sess (_sessiondir);
196 _sgenwin->set_sess (_sessiondir);
197 _captwin->set_sess (_sessiondir);
198 }
199