libdockapp: Fix for missing windowname and one more.
[dockapps.git] / ascd / ascd / wings_main.c
blob9d467dc55da2ceec802b8b0344e9edfdcfa16a16
1 /* ===========================================================================
2 * AScd: the AfterStep and WindowMaker CD player
3 * gui_wings.c: window handling using WINGs toolkit
4 * ===========================================================================
5 * Copyright (c) 1999 Denis Bourez and Rob Malda. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Denis Bourez & Rob Malda
19 * 4. Neither the name of the author nor the names of any co-contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY DENIS BOUREZ AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL DENIS BOUREZ, ROB MALDA OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 * ===========================================================================
37 #include <dirent.h>
38 #include <WINGs.h>
39 #include "ext.h"
41 /*int old_track = 0;*/
43 void close_win(WMWidget *self, void *data) {
44 WMCloseWindow(win);
45 en_vue = FALSE;
46 muted_volume = atoi(WMGetTextFieldText(b_mutedvol));
47 min_volume = atoi(WMGetTextFieldText(b_minvol));
48 max_volume = atoi(WMGetTextFieldText(b_maxvol));
49 cue_time = atoi(WMGetTextFieldText(b_cuetime));
50 fade_step = atoi(WMGetTextFieldText(b_fadestep));
53 void close_aboutwin(WMWidget *self, void *data) {
54 WMCloseWindow(aboutwin);
55 about_en_vue = FALSE;
58 void close_dbwin(WMWidget *self, void *data) {
59 char txt[127];
60 char txt2 [127];
62 WMCloseWindow(dbwin);
63 strcpy(cd->artist, WMGetTextFieldText(db_artist));
64 strcpy(cd->cdname, WMGetTextFieldText(db_title));
65 if (strlen(WMGetTextFieldText(db_track)) > 0) {
66 cd->trk[db_curtrack - 1].songname = malloc(strlen(WMGetTextFieldText(db_track)) + 1);
67 strcpy(cd->trk[db_curtrack - 1].songname, WMGetTextFieldText(db_track));
70 save();
71 load();
73 if (cd->artist != NULL) {
74 strcpy(txt, cd->artist);
75 if (strcmp(txt, "") == 0) strcpy(txt, "unknown artist");
76 } else {
77 strcpy(txt, "unknown artist");
80 strcat(txt, "\n");
82 if (cd->cdname != NULL) {
83 strcpy(txt2, cd->cdname);
84 if (strcmp(txt2, "") == 0) strcpy(txt2, "unknown album");
85 } else {
86 strcpy(txt2, "unknown album");
89 strcat(txt, txt2);
90 WMSetButtonText(b_title, txt);
92 db_en_vue = FALSE;
95 void quit_ascd(WMWidget *self, void *data) {
96 exit(0);
99 void save_cb(WMWidget *self, void *data) {
100 muted_volume = atoi(WMGetTextFieldText(b_mutedvol));
101 min_volume = atoi(WMGetTextFieldText(b_minvol));
102 max_volume = atoi(WMGetTextFieldText(b_maxvol));
103 cue_time = atoi(WMGetTextFieldText(b_cuetime));
104 fade_step = atoi(WMGetTextFieldText(b_fadestep));
105 cd_device = WMGetTextFieldText(b_device);
106 save_rc_file();
109 void track_select(WMWidget *self, void *data) {
110 show_db_pos = 0;
111 direct_track = WMGetPopUpButtonSelectedItem(self) + 1;
112 cd_control(DIRECTTRACK);
113 old_track = 0;
114 if (cur_cdmode == WM_CDM_STOPPED) cd_control(PLAY);
117 void theme_pick(WMWidget *self, void *data) {
118 strcpy(theme, WMGetPopUpButtonItem(self, WMGetPopUpButtonSelectedItem(self)));
119 fak_load_theme(theme, TRUE);
120 fak_maskset();
123 void help_cb(WMWidget *self, void *data) {
124 quick_reference(0);
127 void mode1_cb(WMWidget *self, void *data) {
128 if (WMGetButtonSelected(b_mode1)) {
129 WMSetButtonSelected((b_mode2), FALSE);
130 } else {
131 WMSetButtonSelected((b_mode2), TRUE);
134 if (WMGetButtonSelected(b_mode1)) {
135 if (WMGetButtonSelected(b_mode3)) time_mode = 0;
136 else time_mode = 1;
137 } else {
138 if (WMGetButtonSelected(b_mode3)) time_mode = 2;
139 else time_mode = 3;
143 void mode2_cb(WMWidget *self, void *data) {
144 if (WMGetButtonSelected(b_mode2)) {
145 WMSetButtonSelected((b_mode1), FALSE);
146 } else {
147 WMSetButtonSelected((b_mode1), TRUE);
150 if (WMGetButtonSelected(b_mode1)) {
151 if (WMGetButtonSelected(b_mode3)) time_mode = 0;
152 else time_mode = 1;
153 } else {
154 if (WMGetButtonSelected(b_mode3)) time_mode = 2;
155 else time_mode = 3;
159 void mode3_cb(WMWidget *self, void *data) {
160 if (WMGetButtonSelected(b_mode3)) {
161 WMSetButtonSelected((b_mode4), FALSE);
162 } else {
163 WMSetButtonSelected((b_mode4), TRUE);
166 if (WMGetButtonSelected(b_mode1)) {
167 if (WMGetButtonSelected(b_mode3)) time_mode = 0;
168 else time_mode = 1;
169 } else {
170 if (WMGetButtonSelected(b_mode3)) time_mode = 2;
171 else time_mode = 3;
175 void mode4_cb(WMWidget *self, void *data) {
176 if (WMGetButtonSelected(b_mode4)) {
177 WMSetButtonSelected((b_mode3), FALSE);
178 } else {
179 WMSetButtonSelected((b_mode3), TRUE);
182 if (WMGetButtonSelected(b_mode1)) {
183 if (WMGetButtonSelected(b_mode3)) time_mode = 0;
184 else time_mode = 1;
185 } else {
186 if (WMGetButtonSelected(b_mode3)) time_mode = 2;
187 else time_mode = 3;
191 void autoplay_cb(WMWidget *self, void *data) {
192 if (autoplay) autoplay = 0;
193 else autoplay = 1;
195 if (WMGetButtonSelected(b_mode1)) {
196 if (WMGetButtonSelected(b_mode3)) time_mode = 0;
197 else time_mode = 1;
198 } else {
199 if (WMGetButtonSelected(b_mode3)) time_mode = 2;
200 else time_mode = 3;
204 void autorepeat_cb(WMWidget *self, void *data) {
205 if (autorepeat) autorepeat = 0;
206 else autorepeat = 1;
209 void ignoreavoid_cb(WMWidget *self, void *data) {
210 if (ignore_avoid) ignore_avoid = 0;
211 else ignore_avoid = 1;
214 void upper_cb(WMWidget *self, void *data) {
215 if (force_upper) force_upper = 0;
216 else force_upper = 1;
219 void scroll_cb(WMWidget *self, void *data) {
220 if (show_db) show_db = 0;
221 else show_db = 1;
224 void artist_cb(WMWidget *self, void *data) {
225 if (show_artist) show_artist = 0;
226 else show_artist = 1;
229 void volume_cb(WMWidget *self, void *data) {
230 if (cur_cdmode != WM_CDM_EJECTED) {
231 volume = WMGetSliderValue(self);
232 cd_volume(volume, 10, max_volume);
233 redraw = TRUE;
237 /* --------------------------------------------------- */
239 void create_about_window(WMScreen *scr) {
240 char txt[256];
241 WMWidget *lb1, *lb2, *lb3, *lb4, *lb5, *lb6;
242 WMFont *font;
244 aboutwin = WMCreateWindow(scr, "AScd-about");
245 WMSetWindowCloseAction(aboutwin, close_aboutwin, NULL);
246 WMSetWindowTitle(aboutwin, "AScd Info");
247 WMResizeWidget(aboutwin, 350, 170);
249 lb1 = WMCreateLabel(aboutwin);
250 WMResizeWidget(lb1, 35, 20);
251 WMMoveWidget(lb1, 10, 10);
252 font = WMBoldSystemFontOfSize(scr, 12);
253 if (font) {
254 WMSetLabelFont(lb1, font);
255 WMReleaseFont(font);
257 WMSetLabelText(lb1, "AScd");
259 lb2 = WMCreateLabel(aboutwin);
260 WMResizeWidget(lb2, 200, 20);
261 WMMoveWidget(lb2, 50, 10);
262 sprintf(txt, "release %s", VERSION);
263 WMSetLabelText(lb2, txt);
265 lb3 = WMCreateLabel(aboutwin);
266 WMResizeWidget(lb3, 280, 40);
267 WMMoveWidget(lb3, 50, 30);
268 font = WMSystemFontOfSize(scr, 10);
269 if (font) {
270 WMSetLabelFont(lb3, font);
271 WMReleaseFont(font);
273 sprintf(txt, "(c) 1996-1999 Denis Bourez and Rob Malda\nContact: denis@rsn.fdn.fr\nhttp://worldserver.oleane.com/rsn/ascd-en.html");
274 WMSetLabelText(lb3, txt);
276 lb5 = WMCreateLabel(aboutwin);
277 WMResizeWidget(lb5, 60, 20);
278 WMMoveWidget(lb5, 10, 70);
279 font = WMBoldSystemFontOfSize(scr, 10);
280 if (font) {
281 WMSetLabelFont(lb5, font);
282 WMReleaseFont(font);
284 WMSetLabelText(lb5, "Ctrl:");
286 lb4 = WMCreateLabel(aboutwin);
287 WMResizeWidget(lb4, 260, 20);
288 WMMoveWidget(lb4, 50, 70);
289 font = WMSystemFontOfSize(scr, 10);
290 if (font) {
291 WMSetLabelFont(lb4, font);
292 WMReleaseFont(font);
294 sprintf(txt, "CD Control %s + %s", cd_control_version(), wm_libver_string());
295 WMSetLabelText(lb4, txt);
297 lb6 = WMCreateLabel(aboutwin);
298 WMResizeWidget(lb6, 60, 20);
299 WMMoveWidget(lb6, 10, 85);
300 font = WMBoldSystemFontOfSize(scr, 10);
301 if (font) {
302 WMSetLabelFont(lb6, font);
303 WMReleaseFont(font);
305 WMSetLabelText(lb6, "Theme:");
307 about_th1 = WMCreateLabel(aboutwin);
308 WMResizeWidget(about_th1, 280, 12);
309 WMMoveWidget(about_th1, 50, 89);
310 font = WMSystemFontOfSize(scr, 10);
311 if (font) {
312 WMSetLabelFont(about_th1, font);
313 WMReleaseFont(font);
315 WMSetLabelText(about_th1, "A");
317 about_th2 = WMCreateLabel(aboutwin);
318 WMResizeWidget(about_th2, 280, 12);
319 WMMoveWidget(about_th2, 50, 101);
320 font = WMSystemFontOfSize(scr, 10);
321 if (font) {
322 WMSetLabelFont(about_th2, font);
323 WMReleaseFont(font);
325 WMSetLabelText(about_th2, "B");
327 about_th3 = WMCreateLabel(aboutwin);
328 WMResizeWidget(about_th3, 280, 12);
329 WMMoveWidget(about_th3, 50, 113);
330 font = WMSystemFontOfSize(scr, 10);
331 if (font) {
332 WMSetLabelFont(about_th3, font);
333 WMReleaseFont(font);
335 WMSetLabelText(about_th3, "C");
337 about_th4 = WMCreateLabel(aboutwin);
338 WMResizeWidget(about_th4, 280, 12);
339 WMMoveWidget(about_th4, 50, 125);
340 font = WMSystemFontOfSize(scr, 10);
341 if (font) {
342 WMSetLabelFont(about_th4, font);
343 WMReleaseFont(font);
345 WMSetLabelText(about_th4, "D");
347 about_th5 = WMCreateLabel(aboutwin);
348 WMResizeWidget(about_th5, 280, 12);
349 WMMoveWidget(about_th5, 50, 137);
350 font = WMSystemFontOfSize(scr, 10);
351 if (font) {
352 WMSetLabelFont(about_th5, font);
353 WMReleaseFont(font);
355 WMSetLabelText(about_th5, "E");
357 about_th6 = WMCreateLabel(aboutwin);
358 WMResizeWidget(about_th6, 280, 12);
359 WMMoveWidget(about_th6, 50, 149);
360 font = WMSystemFontOfSize(scr, 10);
361 if (font) {
362 WMSetLabelFont(about_th6, font);
363 WMReleaseFont(font);
365 WMSetLabelText(about_th6, "F");
369 WMRealizeWidget(aboutwin);
372 void about_window(WMScreen *scr) {
373 char txt[256];
375 if (! about_en_vue) {
376 sprintf(txt, "%s %s", th_name, th_release);
377 WMSetLabelText(about_th1, txt);
378 WMSetLabelText(about_th2, th_author);
379 WMSetLabelText(about_th3, th_email);
380 WMSetLabelText(about_th4, th_url);
381 WMSetLabelText(about_th5, th_comment);
382 sprintf(txt, "Faktory: %dx%d (panels: %d Buttons: %d)", backXPM.attributes.width, backXPM.attributes.height, panels, but_max);
383 WMSetLabelText(about_th6, txt);
385 WMRealizeWidget(aboutwin);
386 WMMapSubwidgets(aboutwin);
387 WMMapWidget(aboutwin);
388 about_en_vue = TRUE;
389 } else {
390 WMCloseWindow(aboutwin);
391 about_en_vue = FALSE;
395 /* --------------------------------------------------- */
397 void db_prev_cb(WMWidget *self, void *data) {
398 char txt[256];
400 if (cur_cdmode == WM_CDM_EJECTED) return;
402 strcpy(cd->artist, WMGetTextFieldText(db_artist));
403 strcpy(cd->cdname, WMGetTextFieldText(db_title));
404 if (strlen(WMGetTextFieldText(db_track)) > 0) {
405 cd->trk[db_curtrack - 1].songname = malloc(strlen(WMGetTextFieldText(db_track)) + 1);
406 strcpy(cd->trk[db_curtrack - 1].songname, WMGetTextFieldText(db_track));
408 save();
409 load();
411 if (db_curtrack == 1) db_curtrack = cur_ntracks;
412 else db_curtrack--;
413 sprintf(txt, "Tk %d:", db_curtrack);
414 WMSetLabelText(db_tlabel, txt);
416 if (cd->trk[db_curtrack - 1].songname != NULL) {
417 sprintf(txt, cd->trk[db_curtrack - 1].songname);
418 } else {
419 strcpy(txt, "");
421 WMSetTextFieldText(db_track, txt);
423 if (cd->trk[db_curtrack - 1].avoid) {
424 WMSetButtonSelected(db_avoid, TRUE);
425 } else {
426 WMSetButtonSelected(db_avoid, FALSE);
429 WMRealizeWidget(dbwin);
432 void db_next_cb(WMWidget *self, void *data) {
433 char txt[256];
435 if (cur_cdmode == WM_CDM_EJECTED) return;
437 strcpy(cd->artist, WMGetTextFieldText(db_artist));
438 strcpy(cd->cdname, WMGetTextFieldText(db_title));
439 if (strlen(WMGetTextFieldText(db_track)) > 0) {
440 cd->trk[db_curtrack - 1].songname = malloc(strlen(WMGetTextFieldText(db_track)) + 1);
441 strcpy(cd->trk[db_curtrack - 1].songname, WMGetTextFieldText(db_track));
443 save();
444 load();
446 if (db_curtrack == cur_ntracks) db_curtrack = 1;
447 else db_curtrack++;
448 sprintf(txt, "Tk %d:", db_curtrack);
449 WMSetLabelText(db_tlabel, txt);
451 if (cd->trk[db_curtrack - 1].songname != NULL) {
452 sprintf(txt, cd->trk[db_curtrack - 1].songname);
453 } else {
454 strcpy(txt, "");
456 WMSetTextFieldText(db_track, txt);
458 if (cd->trk[db_curtrack - 1].avoid) {
459 WMSetButtonSelected(db_avoid, TRUE);
460 } else {
461 WMSetButtonSelected(db_avoid, FALSE);
464 WMRealizeWidget(dbwin);
467 void db_avoid_cb(WMWidget *self, void *data) {
468 if (cur_cdmode == WM_CDM_EJECTED) return;
469 if (cd->trk[db_curtrack - 1].avoid) {
470 cd->trk[db_curtrack - 1].avoid = 0;
471 } else {
472 cd->trk[db_curtrack - 1].avoid = 1;
474 save();
475 load();
478 void db_playauto_cb(WMWidget *self, void *data) {
479 if (cur_cdmode == WM_CDM_EJECTED) return;
480 if (cd->autoplay) {
481 cd->autoplay = 0;
482 } else {
483 cd->autoplay = 1;
485 save();
486 load();
489 void db_volume_cb(WMWidget *self, void *data) {
490 if (cur_cdmode != WM_CDM_EJECTED) {
491 cd->volume = WMGetSliderValue(self);
492 save();
493 load();
494 volume = cd->volume;
495 cd_volume(volume, 10, max_volume);
496 redraw = TRUE;
497 WMSetSliderMinValue(b_volume, min_volume);
498 WMSetSliderMaxValue(b_volume, max_volume);
499 WMSetSliderValue(b_volume, volume);
503 void create_db_window(WMScreen *scr) {
504 char txt[256];
505 WMWidget *fr, *fr2;
506 WMWidget *lb1, *lb2, *lb3;
508 dbwin = WMCreateWindow(scr, "AScd-db");
509 WMSetWindowCloseAction(dbwin, close_dbwin, NULL);
510 WMSetWindowTitle(dbwin, "AScd database edition");
511 WMResizeWidget(dbwin, 350, 220);
514 fr = WMCreateFrame(dbwin);
515 WMMoveWidget(fr, 10, 05);
516 WMResizeWidget(fr, 330, 105);
517 WMSetFrameTitle(fr, "CD info:");
519 lb1 = WMCreateLabel(dbwin);
520 WMResizeWidget(lb1, 40, 20);
521 WMMoveWidget(lb1, 16, 20);
522 WMSetLabelText(lb1, "Artist:");
524 db_artist = WMCreateTextField(dbwin);
525 WMMoveWidget(db_artist, 70, 20);
526 WMResizeWidget(db_artist, 255, 20);
528 lb2 = WMCreateLabel(dbwin);
529 WMResizeWidget(lb2, 40, 20);
530 WMMoveWidget(lb2, 16, 40);
531 WMSetLabelText(lb2, "Title:");
533 db_title = WMCreateTextField(dbwin);
534 WMMoveWidget(db_title, 70, 40);
535 WMResizeWidget(db_title, 255, 20);
537 db_playauto = WMCreateButton(dbwin, WBTSwitch);
538 WMMoveWidget(db_playauto, 70, 65);
539 WMResizeWidget(db_playauto, 255, 20);
540 WMSetButtonText(db_playauto, "play this CD automatically (WorkMan)");
541 WMSetButtonAction(db_playauto, db_playauto_cb, NULL);
543 lb3 = WMCreateLabel(dbwin);
544 WMResizeWidget(lb3, 54, 20);
545 WMMoveWidget(lb3, 16, 85);
546 WMSetLabelText(lb3, "Volume:");
548 db_volume = WMCreateSlider(dbwin);
549 WMResizeWidget(db_volume, 255, 15);
550 WMMoveWidget(db_volume, 70, 88);
551 WMSetSliderKnobThickness(db_volume, 22);
552 WMSetSliderAction(db_volume, db_volume_cb, NULL);
554 /* --- */
556 fr2 = WMCreateFrame(dbwin);
557 WMMoveWidget(fr2, 10, 115);
558 WMResizeWidget(fr2, 330, 65);
559 WMSetFrameTitle(fr2, "Track info:");
561 db_tlabel = WMCreateLabel(dbwin);
562 WMResizeWidget(db_tlabel, 54, 20);
563 WMMoveWidget(db_tlabel, 16, 130);
564 sprintf(txt, "Track %d:", db_curtrack);
565 WMSetLabelText(db_tlabel, txt);
567 db_track = WMCreateTextField(dbwin);
568 WMMoveWidget(db_track, 70, 130);
569 WMResizeWidget(db_track, 255, 20);
571 db_avoid = WMCreateButton(dbwin, WBTSwitch);
572 WMMoveWidget(db_avoid, 70, 152);
573 WMResizeWidget(db_avoid, 235, 20);
574 WMSetButtonText(db_avoid, "don't play this track");
575 WMSetButtonAction(db_avoid, db_avoid_cb, NULL);
577 /* --- */
579 db_prev = WMCreateButton(dbwin, 0);
580 WMResizeWidget(db_prev, 110, 25);
581 WMMoveWidget(db_prev, 10, 190);
582 WMSetButtonText(db_prev, "Previous Track");
583 WMSetButtonAction(db_prev, db_prev_cb, NULL);
585 db_next = WMCreateButton(dbwin, 0);
586 WMResizeWidget(db_next, 110, 25);
587 WMMoveWidget(db_next, 125, 190);
588 WMSetButtonText(db_next, "Next Track");
589 WMSetButtonAction(db_next, db_next_cb, NULL);
591 db_close = WMCreateButton(dbwin, 0);
592 WMResizeWidget(db_close, 55, 25);
593 WMMoveWidget(db_close, 285, 190);
594 WMSetButtonText(db_close, "Close");
595 WMSetButtonAction(db_close, close_dbwin, NULL);
597 WMRealizeWidget(dbwin);
600 void db_window(WMScreen *scr) {
601 char txt[256];
603 if (! db_en_vue) {
604 if (cur_cdmode == WM_CDM_EJECTED) return;
606 /* 0.13 fix */
607 if (db_curtrack < 1) db_curtrack = 1;
609 load();
610 if (cd->artist != NULL) strcpy(txt, cd->artist);
611 else strcpy(txt, "");
612 WMSetTextFieldText(db_artist, txt);
614 if (cd->cdname != NULL) strcpy(txt, cd->cdname);
615 else strcpy(txt, "");
616 WMSetTextFieldText(db_title, txt);
618 if (cd->autoplay) {
619 WMSetButtonSelected(db_playauto, TRUE);
620 } else {
621 WMSetButtonSelected(db_playauto, TRUE);
624 if (cd->trk[db_curtrack - 1].songname != NULL) {
625 sprintf(txt, cd->trk[db_curtrack - 1].songname);
626 } else {
627 strcpy(txt, "");
629 WMSetTextFieldText(db_track, txt);
631 if (cd->trk[db_curtrack - 1].avoid) {
632 WMSetButtonSelected(db_avoid, TRUE);
633 } else {
634 WMSetButtonSelected(db_avoid, FALSE);
637 WMSetSliderMinValue(db_volume, min_volume);
638 WMSetSliderMaxValue(db_volume, max_volume);
639 if (cd->volume > 0) WMSetSliderValue(db_volume, cd->volume);
640 else WMSetSliderValue(db_volume, max_volume);
642 WMRealizeWidget(dbwin);
643 WMMapSubwidgets(dbwin);
644 WMMapWidget(dbwin);
645 db_en_vue = TRUE;
646 } else {
647 WMCloseWindow(dbwin);
648 db_en_vue = FALSE;
652 void db_cb(WMWidget *self, void *data) {
653 char txt[127];
654 sprintf(txt, "Tk %d:", db_curtrack);
655 WMSetLabelText(db_tlabel, txt);
656 /*WMRealizeWidget(dbwin);*/
657 db_window(scr);
660 void about_cb(WMWidget *self, void *data) {
661 about_window(scr);
664 void create_big_window(WMScreen *scr) {
665 WMWidget *fr, *fr3, *fr4, *fr5;
666 WMWidget *lb1, *lb2, *lb3, *lb4, *lb6;
668 win = WMCreateWindow(scr, "AScd");
669 WMSetWindowCloseAction(win, close_win, NULL);
670 WMSetWindowTitle(win, "AScd");
671 WMResizeWidget(win, 320, 370);
673 b_title = WMCreateButton(win, 0);
674 WMResizeWidget(b_title, 300, 40);
675 WMMoveWidget(b_title, 10, 5);
676 WMSetButtonText(b_title, "1\n2");
677 WMSetButtonAction(b_title, db_cb, NULL);
679 pop = WMCreatePopUpButton(win);
680 WMResizeWidget(pop, 300, 20);
681 WMMoveWidget(pop, 10, 50);
682 WMSetPopUpButtonPullsDown(pop, True);
683 WMSetPopUpButtonText(pop, "Tracks");
684 WMAddPopUpButtonItem(pop, "1");
685 WMSetPopUpButtonAction(pop, track_select, NULL);
687 fr = WMCreateFrame(win);
688 WMMoveWidget(fr, 10, 75);
689 WMResizeWidget(fr, 110, 140);
690 WMSetFrameTitle(fr, "Playback:");
692 b_autoplay = WMCreateButton(win, WBTSwitch);
693 WMMoveWidget(b_autoplay, 20, 95);
694 WMResizeWidget(b_autoplay, 90, 20);
695 WMSetButtonText(b_autoplay, "autoplay");
696 WMSetButtonAction(b_autoplay, autoplay_cb, NULL);
698 b_autorepeat = WMCreateButton(win, WBTSwitch);
699 WMMoveWidget(b_autorepeat, 20, 115);
700 WMResizeWidget(b_autorepeat, 90, 20);
701 WMSetButtonText(b_autorepeat, "autorepeat");
702 WMSetButtonAction(b_autorepeat, autorepeat_cb, NULL);
704 b_ignoreavoid = WMCreateButton(win, WBTSwitch);
705 WMMoveWidget(b_ignoreavoid, 20, 135);
706 WMResizeWidget(b_ignoreavoid, 90, 20);
707 WMSetButtonText(b_ignoreavoid, "apply skips");
708 WMSetButtonAction(b_ignoreavoid, ignoreavoid_cb, NULL);
710 lb6 = WMCreateLabel(win);
711 WMResizeWidget(lb6, 80, 20);
712 WMMoveWidget(lb6, 15, 165);
713 WMSetLabelText(lb6, "CD Device:");
715 b_device = WMCreateTextField(win);
716 WMResizeWidget(b_device, 85, 20);
717 WMMoveWidget(b_device, 20, 185);
720 fr3 = WMCreateFrame(win);
721 WMMoveWidget(fr3, 130, 75);
722 WMResizeWidget(fr3, 180, 140);
723 WMSetFrameTitle(fr3, "Display:");
725 b_scroll = WMCreateButton(win, WBTSwitch);
726 WMMoveWidget(b_scroll, 140, 95);
727 WMResizeWidget(b_scroll, 130, 20);
728 WMSetButtonText(b_scroll, "scroll song names");
729 WMSetButtonAction(b_scroll, scroll_cb, NULL);
731 b_artist = WMCreateButton(win, WBTSwitch);
732 WMMoveWidget(b_artist, 140, 115);
733 WMResizeWidget(b_artist, 130, 20);
734 WMSetButtonText(b_artist, "add artist name");
735 WMSetButtonAction(b_artist, artist_cb, NULL);
737 b_upper = WMCreateButton(win, WBTSwitch);
738 WMMoveWidget(b_upper, 140, 135);
739 WMResizeWidget(b_upper, 130, 20);
740 WMSetButtonText(b_upper, "force uppercase");
741 WMSetButtonAction(b_upper, upper_cb, NULL);
743 lb4 = WMCreateLabel(win);
744 WMResizeWidget(lb4, 80, 20);
745 WMMoveWidget(lb4, 135, 165);
746 WMSetLabelText(lb4, "Theme:");
748 pop2 = WMCreatePopUpButton(win);
749 WMResizeWidget(pop2, 160, 20);
750 WMMoveWidget(pop2, 140, 185);
751 WMSetPopUpButtonText(pop2, theme);
752 WMAddPopUpButtonItem(pop2, "1");
753 WMSetPopUpButtonAction(pop2, theme_pick, NULL);
755 b_help = WMCreateButton(win, 0);
756 WMResizeWidget(b_help, 80, 18);
757 WMMoveWidget(b_help, 220, 165);
758 WMSetButtonText(b_help, "Quick Ref.");
759 WMSetButtonAction(b_help, help_cb, NULL);
761 /* the volume */
763 fr4 = WMCreateFrame(win);
764 WMMoveWidget(fr4, 10, 220);
765 WMResizeWidget(fr4, 300, 80);
766 WMSetFrameTitle(fr4, "Volume & Misc:");
768 b_minvol = WMCreateTextField(win);
769 WMResizeWidget(b_minvol, 30, 20);
770 WMMoveWidget(b_minvol, 20, 240);
772 b_volume = WMCreateSlider(win);
773 WMResizeWidget(b_volume, 220, 20);
774 WMMoveWidget(b_volume, 50, 240);
775 WMSetSliderKnobThickness(b_volume, 22);
776 WMSetSliderAction(b_volume, volume_cb, NULL);
778 b_maxvol = WMCreateTextField(win);
779 WMResizeWidget(b_maxvol, 30, 20);
780 WMMoveWidget(b_maxvol, 270, 240);
782 lb1 = WMCreateLabel(win);
783 WMResizeWidget(lb1, 40, 20);
784 WMMoveWidget(lb1, 15, 270);
785 WMSetLabelText(lb1, "Muted");
787 b_mutedvol = WMCreateTextField(win);
788 WMResizeWidget(b_mutedvol, 30, 20);
789 WMMoveWidget(b_mutedvol, 65, 270);
791 lb2 = WMCreateLabel(win);
792 WMResizeWidget(lb2, 70, 20);
793 WMMoveWidget(lb2, 105, 270);
794 WMSetLabelText(lb2, "Cue Time");
796 b_cuetime = WMCreateTextField(win);
797 WMResizeWidget(b_cuetime, 25, 20);
798 WMMoveWidget(b_cuetime, 180, 270);
800 lb3 = WMCreateLabel(win);
801 WMResizeWidget(lb3, 33, 20);
802 WMMoveWidget(lb3, 225, 270);
803 WMSetLabelText(lb3, "Fade");
805 b_fadestep = WMCreateTextField(win);
806 WMResizeWidget(b_fadestep, 25, 20);
807 WMMoveWidget(b_fadestep, 275, 270);
809 /* the counter modes */
811 fr5 = WMCreateFrame(win);
812 WMMoveWidget(fr5, 10, 305);
813 WMResizeWidget(fr5, 190, 60);
814 WMSetFrameTitle(fr5, "Counter Mode:");
816 b_mode1 = WMCreateButton(win, WBTRadio);
817 WMMoveWidget(b_mode1, 20, 320);
818 WMResizeWidget(b_mode1, 55, 20);
819 WMSetButtonText(b_mode1, "Track");
820 WMSetButtonAction(b_mode1, mode1_cb, NULL);
822 b_mode2 = WMCreateButton(win, WBTRadio);
823 WMMoveWidget(b_mode2, 20, 340);
824 WMResizeWidget(b_mode2, 55, 20);
825 WMSetButtonText(b_mode2, "CD");
826 WMSetButtonAction(b_mode2, mode2_cb, NULL);
828 b_mode3 = WMCreateButton(win, WBTRadio);
829 WMMoveWidget(b_mode3, 90, 320);
830 WMResizeWidget(b_mode3, 85, 20);
831 WMSetButtonText(b_mode3, "Elapsed");
832 WMSetButtonAction(b_mode3, mode3_cb, NULL);
834 b_mode4 = WMCreateButton(win, WBTRadio);
835 WMMoveWidget(b_mode4, 90, 340);
836 WMResizeWidget(b_mode4, 85, 20);
837 WMSetButtonText(b_mode4, "Remaining");
838 WMSetButtonAction(b_mode4, mode4_cb, NULL);
840 /* the global buttons */
842 b_save = WMCreateButton(win, 0);
843 WMResizeWidget(b_save, 50, 25);
844 WMMoveWidget(b_save, 205, 340);
845 WMSetButtonText(b_save, "Save");
846 WMSetButtonAction(b_save, save_cb, NULL);
848 b_about = WMCreateButton(win, 0);
849 WMResizeWidget(b_about, 50, 25);
850 WMMoveWidget(b_about, 205, 310);
851 WMSetButtonText(b_about, "Info");
852 WMSetButtonAction(b_about, about_cb, NULL);
854 b_save = WMCreateButton(win, 0);
855 WMResizeWidget(b_save, 50, 25);
856 WMMoveWidget(b_save, 260, 310);
857 WMSetButtonText(b_save, "Quit");
858 WMSetButtonAction(b_save, quit_ascd, NULL);
860 b_close = WMCreateButton(win, 0);
861 WMResizeWidget(b_close, 50, 25);
862 WMMoveWidget(b_close, 260, 340);
863 WMSetButtonText(b_close, "Close");
864 WMSetButtonAction(b_close, close_win, NULL);
866 /* finished, draw everything */
868 WMRealizeWidget(win);
871 WMMapSubwidgets(win);
872 WMMapWidget(win);
876 void update_track() {
877 int i;
878 char txt[127];
879 char txt2[127];
881 if (en_vue) {
882 if (cur_cdmode != WM_CDM_EJECTED) {
884 if (cd->artist != NULL) {
885 strcpy(txt, cd->artist);
886 if (strcmp(txt, "") == 0) strcpy(txt, "unknown artist");
887 } else {
888 strcpy(txt, "unknown artist");
891 strcat(txt, "\n");
893 if (cd->cdname != NULL) {
894 strcpy(txt2, cd->cdname);
895 if (strcmp(txt2, "") == 0) strcpy(txt2, "unknown album");
896 } else {
897 strcpy(txt2, "unknown album");
900 strcat(txt, txt2);
901 WMSetButtonText(b_title, txt);
903 for (i = WMGetPopUpButtonNumberOfItems(pop); i >= 0; i --) {
904 WMRemovePopUpButtonItem(pop, i);
907 for (i = 0; i < cur_ntracks; i++) {
908 sprintf(txt, "%2d ", i + 1);
909 if (cd->trk[i].songname != NULL) strcat(txt, cd->trk[i].songname);
910 WMAddPopUpButtonItem(pop, txt);
913 pistes = cur_ntracks;
915 if (cur_track >= 1) {
916 if (cd->trk[cur_track - 1].songname != NULL) {
917 sprintf(txt, "%s", cd->trk[cur_track - 1].songname);
918 if (strcmp(txt, "") == 0) sprintf(txt, "Track %d", cur_track);
919 WMSetPopUpButtonText(pop, txt);
920 } else {
921 sprintf(txt, "Track %d", cur_track);
922 WMSetPopUpButtonText(pop, txt);
924 } else {
925 WMSetPopUpButtonText(pop, "Track 1");
928 } else {
929 WMSetButtonText(b_title, "No CD in drive\nor the tray is not loaded");
934 void big_window(WMScreen *scr) {
935 int i;
936 char txt[256];
937 DIR *dir_fd;
938 struct dirent *dir_pt;
940 if (! en_vue) {
942 /*if (cur_cdmode == WM_CDM_EJECTED) return;*/
944 en_vue = TRUE;
946 sprintf(txt, "%d", cue_time);
947 WMSetTextFieldText(b_cuetime, txt);
948 sprintf(txt, "%d", fade_step);
949 WMSetTextFieldText(b_fadestep, txt);
950 sprintf(txt, "%d", min_volume);
951 WMSetTextFieldText(b_minvol, txt);
952 sprintf(txt, "%d", max_volume);
953 WMSetTextFieldText(b_maxvol, txt);
954 sprintf(txt, "%d", muted_volume);
955 WMSetTextFieldText(b_mutedvol, txt);
957 WMSetTextFieldText(b_device, cd_device);
959 WMSetSliderMinValue(b_volume, min_volume);
960 WMSetSliderMaxValue(b_volume, max_volume);
961 WMSetSliderValue(b_volume, volume);
963 /* remove everything in the two popups */
965 for (i = WMGetPopUpButtonNumberOfItems(pop); i >= 0; i --) {
966 WMRemovePopUpButtonItem(pop, i);
969 for (i = WMGetPopUpButtonNumberOfItems(pop2); i >= 0; i --) {
970 WMRemovePopUpButtonItem(pop2, i);
973 /* update the database stuff. AScd 0.13: I deleted all this
974 stuff from this function as update_track() do the same! */
976 update_track();
978 /* make the theme select menu */
980 sprintf(txt, "%s/Themes", THDIR);
981 if ((dir_fd = opendir(txt)) != NULL) {
982 while((dir_pt = readdir(dir_fd)) != NULL) {
983 if (dir_pt->d_name[0] != '.') {
984 WMAddPopUpButtonItem(pop2, dir_pt->d_name);
987 closedir(dir_fd);
989 WMSetPopUpButtonText(pop2, theme);
991 /* several options toggles */
993 if (autoplay) {
994 WMSetButtonSelected(b_autoplay, TRUE);
995 } else {
996 WMSetButtonSelected(b_autoplay, FALSE);
999 if (autorepeat) {
1000 WMSetButtonSelected(b_autorepeat, TRUE);
1001 } else {
1002 WMSetButtonSelected(b_autorepeat, FALSE);
1005 if (show_db) {
1006 WMSetButtonSelected(b_scroll, TRUE);
1007 } else {
1008 WMSetButtonSelected(b_scroll, FALSE);
1011 if (show_artist) {
1012 WMSetButtonSelected(b_artist, TRUE);
1013 } else {
1014 WMSetButtonSelected(b_artist, FALSE);
1017 if (ignore_avoid) {
1018 WMSetButtonSelected(b_ignoreavoid, FALSE);
1019 } else {
1020 WMSetButtonSelected(b_ignoreavoid, TRUE);
1023 if (force_upper) {
1024 WMSetButtonSelected(b_upper, TRUE);
1025 } else {
1026 WMSetButtonSelected(b_upper, FALSE);
1029 /* finally, the counter mode radio buttons */
1031 switch(time_mode) {
1032 case 0:
1033 WMSetButtonSelected((b_mode1), TRUE);
1034 WMSetButtonSelected((b_mode2), FALSE);
1035 WMSetButtonSelected((b_mode3), TRUE);
1036 WMSetButtonSelected((b_mode4), FALSE);
1037 break;
1038 case 1:
1039 WMSetButtonSelected((b_mode1), TRUE);
1040 WMSetButtonSelected((b_mode2), FALSE);
1041 WMSetButtonSelected((b_mode4), TRUE);
1042 WMSetButtonSelected((b_mode3), FALSE);
1043 break;
1044 case 2:
1045 WMSetButtonSelected((b_mode2), TRUE);
1046 WMSetButtonSelected((b_mode1), FALSE);
1047 WMSetButtonSelected((b_mode3), TRUE);
1048 WMSetButtonSelected((b_mode4), FALSE);
1049 break;
1050 default:
1051 WMSetButtonSelected((b_mode2), TRUE);
1052 WMSetButtonSelected((b_mode1), FALSE);
1053 WMSetButtonSelected((b_mode4), TRUE);
1054 WMSetButtonSelected((b_mode3), FALSE);
1055 break;
1058 WMRealizeWidget(win);
1059 WMMapSubwidgets(win);
1060 WMMapWidget(win);
1061 } else {
1062 WMCloseWindow(win);
1063 muted_volume = atoi(WMGetTextFieldText(b_mutedvol));
1064 min_volume = atoi(WMGetTextFieldText(b_minvol));
1065 max_volume = atoi(WMGetTextFieldText(b_maxvol));
1066 cue_time = atoi(WMGetTextFieldText(b_cuetime));
1067 fade_step = atoi(WMGetTextFieldText(b_fadestep));
1068 en_vue = FALSE;