1 /*
2 * channel editor.
3 *
4 * (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
5 *
6 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <math.h>
13 #include <pthread.h>
14 #include <sys/time.h>
15
16 #include "config.h"
17
18 #include <X11/Intrinsic.h>
19 #include <X11/StringDefs.h>
20 #include <X11/Shell.h>
21 #include <X11/Xaw/XawInit.h>
22 #include <X11/Xaw/Form.h>
23 #include <X11/Xaw/Command.h>
24 #include <X11/Xaw/Viewport.h>
25 #include <X11/Xaw/List.h>
26 #include <X11/Xaw/AsciiText.h>
27
28 #include "grab-ng.h"
29 #include "channel.h"
30 #include "frequencies.h"
31 #include "wmhooks.h"
32 #include "commands.h"
33 #include "conf.h"
34
35 /*-------------------------------------------------------------------------*/
36
37 void pixit(void);
38 void set_channel(struct CHANNEL *channel);
39 void channel_menu(void);
40
41 extern Widget app_shell,conf_shell;
42 extern Display *dpy;
43 extern Atom wm_protocols[2];
44 extern int debug;
45 extern int stay_on_top;
46 extern XVisualInfo vinfo;
47 extern Colormap colormap;
48
49 Widget conf_channel, conf_name, conf_key, conf_list;
50
51 static Widget last_command, viewport;
52 static String *channel_list;
53
54 /*-------------------------------------------------------------------------*/
55
56 static void list_cb(Widget widget, XtPointer clientdata, XtPointer call_data)
57 {
58 XawListReturnStruct *lr = call_data;
59
60 if (channel_switch_hook)
61 channel_switch_hook();
62 do_va_cmd(2,"setstation",lr->string);
63 }
64
65 static void add_cb(Widget widget, XtPointer clientdata, XtPointer call_data)
66 {
67 struct CHANNEL *channel;
68 char *name,*key;
69
70 XtVaGetValues(conf_name,XtNstring,&name,NULL);
71 XtVaGetValues(conf_key,XtNlabel,&key,NULL);
72
73 if (0 == strlen(name))
74 return;
75
76 channel = add_channel(name);
77 if (strlen(key) > 0)
78 channel->key = strdup(key);
79 channel->cname = (cur_channel != -1) ? chanlist[cur_channel].name : "???";
80 channel->channel = cur_channel;
81 channel->input = cur_attrs[ATTR_ID_INPUT];
82 channel->fine = cur_fine;
83 fprintf(stderr,"add_cb #1: %d %s\n",channel->channel,channel->cname);
84 configure_channel(channel);
85 fprintf(stderr,"add_cb #2: %d %s\n",channel->channel,channel->cname);
86 channel_menu();
87 fprintf(stderr,"add_cb #3: %d %s\n",channel->channel,channel->cname);
88 }
89
90 static void del_cb(Widget widget, XtPointer clientdata, XtPointer call_data)
91 {
92 if(cur_sender == -1)
93 return;
94 XtDestroyWidget(channels[cur_sender]->button);
95 del_channel(cur_sender);
96 channel_menu();
97 cur_sender = -1;
98 conf_station_switched();
99 }
100
101 static void modify_cb(Widget widget, XtPointer clientdata, XtPointer call_data)
102 {
103 char *name,*key;
104
105 XtVaGetValues(conf_name,XtNstring,&name,NULL);
106 XtVaGetValues(conf_key,XtNlabel,&key,NULL);
107
108 if (0 == strlen(name))
109 return;
110
111 /* no channel yet ... */
112 if (-1 == cur_sender) {
113 add_cb(widget, clientdata, call_data);
114 return;
115 }
116
117 free(channels[cur_sender]->name);
118 channels[cur_sender]->name = strdup(name);
119
120 if (channels[cur_sender]->key)
121 free(channels[cur_sender]->key);
122 if (0 != strlen(key))
123 channels[cur_sender]->key = strdup(key);
124 else
125 channels[cur_sender]->key = 0;
126 hotkey_channel(channels[cur_sender]);
127 channel_menu();
128 conf_station_switched();
129 }
130
131 static void save_cb(Widget widget, XtPointer clientdata, XtPointer call_data)
132 {
133 save_config();
134 }
135
136 static void close_cb(Widget widget, XtPointer clientdata, XtPointer call_data)
137 {
138 XtCallActionProc(conf_shell,"Popup",NULL,NULL,0);
139 }
140
141 static void key_eh(Widget widget, XtPointer client_data,
142 XEvent *event, Boolean *cont)
143 {
144 XKeyEvent *ke = (XKeyEvent*)event;
145 KeySym sym;
146 char *key;
147 char line[64];
148
149 sym = XKeycodeToKeysym(dpy,ke->keycode,0);
150 if (NoSymbol == sym) {
151 fprintf(stderr,"can't translate keycode %d\n",ke->keycode);
152 return;
153 }
154 key = XKeysymToString(sym);
155
156 line[0] = '\0';
157 if (ke->state & ShiftMask) strcpy(line,"Shift+");
158 if (ke->state & ControlMask) strcpy(line,"Ctrl+");
159 strcat(line,key);
160 XtVaSetValues(conf_key,XtNlabel,line,NULL);
161 }
162
163 /*-------------------------------------------------------------------------*/
164
165 #define FIX_RIGHT_TOP \
166 XtNleft,XawChainRight, \
167 XtNright,XawChainRight, \
168 XtNtop,XawChainTop, \
169 XtNbottom,XawChainTop
170
171 void
172 create_confwin(void)
173 {
174 Widget form, label, command;
175
176 conf_shell = XtVaAppCreateShell("Config", "Xawtv",
177 topLevelShellWidgetClass,
178 dpy,
179 XtNclientLeader,app_shell,
180 XtNvisual,vinfo.visual,
181 XtNcolormap,colormap,
182 XtNdepth,vinfo.depth,
183 NULL);
184 XtOverrideTranslations(conf_shell, XtParseTranslationTable
185 ("<Message>WM_PROTOCOLS: Popup()"));
186 form = XtVaCreateManagedWidget("form", formWidgetClass, conf_shell,
187 NULL);
188
189 /* list */
190 viewport =
191 XtVaCreateManagedWidget("viewport", viewportWidgetClass, form,
192 XtNleft,XawChainLeft,
193 XtNright,XawChainRight,
194 XtNtop,XawChainTop,
195 XtNbottom,XawChainBottom,
196 NULL);
197 conf_list =
198 XtVaCreateManagedWidget("list", listWidgetClass, viewport,
199 NULL);
200 XtAddCallback(conf_list,XtNcallback,list_cb,(XtPointer)NULL);
201
202 /* Einstellungen */
203 label =
204 XtVaCreateManagedWidget("lchannel", labelWidgetClass, form,
205 FIX_RIGHT_TOP,
206 XtNfromHoriz, viewport,
207 NULL);
208 conf_channel =
209 XtVaCreateManagedWidget("channel", labelWidgetClass, form,
210 FIX_RIGHT_TOP,
211 XtNfromHoriz, viewport,
212 XtNfromVert, label,
213 NULL);
214 label =
215 XtVaCreateManagedWidget("lkey", labelWidgetClass, form,
216 FIX_RIGHT_TOP,
217 XtNfromHoriz, viewport,
218 XtNfromVert, conf_channel,
219 NULL);
220 conf_key =
221 XtVaCreateManagedWidget("key", labelWidgetClass, form,
222 FIX_RIGHT_TOP,
223 XtNfromHoriz, viewport,
224 XtNfromVert, label,
225 NULL);
226 label =
227 XtVaCreateManagedWidget("lname", labelWidgetClass, form,
228 FIX_RIGHT_TOP,
229 XtNfromHoriz, viewport,
230 XtNfromVert, conf_key,
231 NULL);
232 conf_name =
233 XtVaCreateManagedWidget("name", asciiTextWidgetClass, form,
234 FIX_RIGHT_TOP,
235 XtNfromHoriz, viewport,
236 XtNfromVert, label,
237 NULL);
238 XtAddEventHandler(conf_key, KeyPressMask, False, key_eh, NULL);
239
240 /* buttons */
241 command =
242 XtVaCreateManagedWidget("add", commandWidgetClass, form,
243 FIX_RIGHT_TOP,
244 XtNfromHoriz, viewport,
245 XtNfromVert, conf_name,
246 NULL);
247 XtAddCallback(command,XtNcallback,add_cb,(XtPointer)NULL);
248 command =
249 XtVaCreateManagedWidget("delete", commandWidgetClass, form,
250 FIX_RIGHT_TOP,
251 XtNfromHoriz, viewport,
252 XtNfromVert, command,
253 NULL);
254 XtAddCallback(command,XtNcallback,del_cb,(XtPointer)NULL);
255 command =
256 XtVaCreateManagedWidget("modify", commandWidgetClass, form,
257 FIX_RIGHT_TOP,
258 XtNfromHoriz, viewport,
259 XtNfromVert, command,
260 NULL);
261 XtAddCallback(command,XtNcallback,modify_cb,(XtPointer)NULL);
262 command =
263 XtVaCreateManagedWidget("save", commandWidgetClass, form,
264 FIX_RIGHT_TOP,
265 XtNfromHoriz, viewport,
266 XtNfromVert, command,
267 NULL);
268 XtAddCallback(command,XtNcallback,save_cb,(XtPointer)NULL);
269 last_command = command =
270 XtVaCreateManagedWidget("close", commandWidgetClass, form,
271 FIX_RIGHT_TOP,
272 XtNfromHoriz, viewport,
273 XtNfromVert, command,
274 NULL);
275 XtAddCallback(command,XtNcallback,close_cb,(XtPointer)NULL);
276
277 XtInstallAllAccelerators(conf_name, conf_shell);
278 }
279
280 /*-------------------------------------------------------------------------*/
281
282 void conf_station_switched(void)
283 {
284 char line[128] = "???";
285
286 /* channel */
287 if (cur_channel != -1) {
288 strcpy(line,chanlist[cur_channel].name);
289 if (cur_fine != 0)
290 sprintf(line+strlen(line)," (%+d)",cur_fine);
291 }
292 XtVaSetValues(conf_channel, XtNlabel, line, NULL);
293
294 if (cur_sender == -1) {
295 XtVaSetValues(conf_key, XtNlabel, "", NULL);
296 XtVaSetValues(conf_name, XtNstring, "", NULL);
297 XawListUnhighlight(conf_list);
298 } else {
299 if (channels[cur_sender]->key)
300 XtVaSetValues(conf_key,XtNlabel,channels[cur_sender]->key, NULL);
301 else
302 XtVaSetValues(conf_key,XtNlabel,"", NULL);
303 #if 0
304 /* This is needed for Xaw3d
305 libXaw3d doesn't get the memory management right with
306 the international ressource set to true. Keeps crashing
307 without the strdup() */
308 XtVaSetValues(conf_name,
309 XtNstring, strdup(channels[cur_sender]->name),
310 NULL);
311 #else
312 XtVaSetValues(conf_name, XtNstring, channels[cur_sender]->name, NULL);
313 #endif
314 XawListHighlight(conf_list,cur_sender);
315 }
316 }
317
318 void
319 conf_list_update(void)
320 {
321 int i;
322
323 if (channel_list)
324 free(channel_list);
325
326 XawListUnhighlight(conf_list);
327 if (count) {
328 /* rebuild list */
329 channel_list = malloc((count+1)*sizeof(String));
330 for (i = 0; i < count; i++)
331 channel_list[i] = channels[i]->name;
332 channel_list[i] = NULL;
333 } else {
334 /* empty list */
335 channel_list = malloc(2*sizeof(String));
336 channel_list[0] = "empty";
337 channel_list[1] = NULL;
338 }
339 XtVaSetValues(conf_list,
340 XtNlist, channel_list,
341 XtNnumberStrings, 0,
342 NULL);
343 }
344
|
This page was automatically generated by the
LXR engine.
|