File: ui_cdinfo.c

package info (click to toggle)
workman 1.3a-8
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 944 kB
  • ctags: 745
  • sloc: ansic: 9,810; makefile: 137; sh: 27
file content (459 lines) | stat: -rw-r--r-- 10,530 bytes parent folder | download
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*
 * @(#)ui_cdinfo.c	1.8	16 Jun 1995
 *
 * ui_cdinfo.c - handle the user interface elements in the CD Info popup.
 */
static char *ident = "@(#)ui_cdinfo.c	1.8 16 Jun 1995";

#include <stdio.h>
#include <sys/param.h>
#include <sys/types.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include "workman_ui.h"
#include "struct.h"

void	continued();
void	setup_itimer();
void	init_stats();
void	avoid_track();
void	keep_settings();
void	cd_volume();
void	set_default_volume();
char *	listentry();
char *	trackname();
int *	get_playlist();
void	kill_stats();
void	insert_into_playlist();
void	scoot_stuff();
int	switch_playlists();

extern Panel_item quitbutton;
extern Rect	*track_rect;
extern int	add_height, small_height, basic_spacing;

/*
 * Global object definitions.
 */
extern window1_objects	*Workman_window1;
extern popup1_objects	*Workman_popup1;
extern about_objects	*Workman_about;
extern goodies_objects	*Workman_goodies;
extern plpopup_objects	*Workman_plpopup;

extern int num_names, num_nalloc, my_cdname, my_artist;
extern int cur_track, cur_pos_abs, cur_pos_rel, cur_tracklen, cur_cdlen,
	cur_ntracks, cur_nsections, cur_lasttrack;
extern enum cd_modes cur_cdmode;
extern int cur_frame;
extern char *cur_cdname, *cur_artist;
extern int displayed_track, pop_track, *pop_list, pop_listsize, pl_item,
	pl_listnum;
extern char *empty;
extern int dont_retry, dismiss_button, info_modified;
extern void (*text_event_handler)();
extern unsigned char *speaker_bits[];

/*
 * Stash the current settings away in memory (in preparation for changing
 * tracks, for instance, or before a save.)
 */
void
keep_settings(ip)
	window1_objects	*ip;
{
	popup1_objects	*pu = Workman_popup1;

	stash_cdinfo(xv_get(pu->artist, PANEL_VALUE),
		xv_get(pu->cdname, PANEL_VALUE),
		xv_get(pu->autoplay, PANEL_VALUE),
		xv_get(pu->playmode, PANEL_VALUE), NULL);
	if (pop_track > 0)
		stash_trkinfo(pop_track, xv_get(pu->trackname, PANEL_VALUE),
			xv_get(pu->trackoptions, PANEL_VALUE) & 1,
			xv_get(pu->trackoptions, PANEL_VALUE) & 2);
}

/*
 * Callback function for Apply button.
 */
void
save_config(item, event)
	Panel_item	item;
	Event		*event;
{
	keep_settings(Workman_window1);
	save();
	info_modified = 0;
}

/*
 * Notify callback function for `delete'.
 */
void
delete_from_playlist(item, event)
	Panel_item	item;
	Event		*event;
{
	plpopup_objects *ip = Workman_plpopup;
	int i;
	
	info_modified = 1;

	if (pl_item >= 0)
	{
		xv_set(ip->playlist, PANEL_LIST_SELECT, pl_item, FALSE,
			PANEL_LIST_DELETE, pl_item, NULL);
		for (i = pl_item; i < pop_listsize; i++)
			pop_list[i] = pop_list[i + 1];
		if (--pop_listsize)
		{
			if (pl_item == pop_listsize)
				pl_item--;
			xv_set(ip->playlist, PANEL_LIST_SELECT, pl_item,
				TRUE, NULL);
			cd->lists[pl_listnum].list = pop_list;
		}
		else
		{
			pl_item = -1;
			xv_set(ip->delete, PANEL_INACTIVE, TRUE, NULL);
			free(pop_list);
			pop_list = NULL;
			cd->lists[pl_listnum].list = pop_list;
		}
	}
}

/*
 * Notify callback function for `artist'.
 */
Panel_setting
update_title(item, event)
	Panel_item	item;
	Event		*event;
{
	new_trackname_display(cur_track > 0 ? trackname(cur_track - 1)[0] ?
		trackname(cur_track - 1) : NULL : "",
		cur_track);

	if (event == NULL)
		return ((Panel_setting)NULL);
	return panel_text_notify(item, event);
}

/*
 * Notify callback function for `tracklist'.
 */
int
update_trackname(item, string, client_data, op, event, row)
	Panel_item	item;
	char		*string;
	Xv_opaque	client_data;
	Panel_list_op	op;
	Event		*event;
	int		row;
{
	popup1_objects *ip = Workman_popup1;
	int	options;
	char	*name;

	switch(op) {
	case PANEL_LIST_OP_DESELECT:
	case PANEL_LIST_OP_VALIDATE:
		if (! pop_track)	/* workaround for bug 1090204 */
			break;
		options = xv_get(ip->trackoptions, PANEL_VALUE);
		name = (char *) xv_get(ip->trackname, PANEL_VALUE);
		stash_trkinfo(row + 1, name, options & 1, (options & 2) >> 1);
		xv_set(ip->tracklist, PANEL_LIST_STRING, row, listentry(row),
			NULL);
		if (cur_track - 1 == row)
			new_trackname_display(name, cur_track);
		if (op == PANEL_LIST_OP_DESELECT)
		{
			xv_set(ip->trackname, PANEL_VALUE, empty, NULL);
			pop_track = 0;
		}
		break;

	case PANEL_LIST_OP_SELECT:
		xv_set(ip->trackname, PANEL_VALUE, trackname(row), NULL);
		xv_set(ip->trackoptions, PANEL_VALUE, (get_avoid(row) ? 2 : 0) |
			(get_contd(row) ? 1 : 0), NULL);
		pop_track = row + 1;
		if (xv_get(ip->whichvolume, PANEL_VALUE))
		{
			xv_set(ip->defaultvolume, PANEL_VALUE,
				get_default_volume(row + 1), NULL);
			set_default_volume(ip->defaultvolume,
				get_default_volume(row + 1), NULL);
		}
		break;

	case PANEL_LIST_OP_DELETE:
		break;
	}

	return XV_OK;
}

/*
 * Notify callback function for `trackname'.
 */
Panel_setting
name_entered(item, event)
	Panel_item	item;
	Event		*event;
{
	popup1_objects *ip = Workman_popup1;
	int	next_track = 0;
	Panel_setting	retval;
	
	switch (event_action(event))
	{
		case '\n':
		case '\r':
		case '\033':
			retval = PANEL_NONE;
			next_track = 1;
			break;
		case '\t':
			retval = PANEL_NEXT;
			break;
		default:
			retval = panel_text_notify(item, event);
	}

/* If a track was selected, save the current settings and go to the next. */
	if (pop_track)
	{
		if (next_track)
		{
			next_track = pop_track;
			if (next_track == cur_ntracks)
				next_track = 0;
			xv_set(ip->tracklist, PANEL_LIST_SELECT, pop_track - 1,
				FALSE, NULL);
			update_trackname(ip->tracklist, listentry(pop_track -
				1), NULL, PANEL_LIST_OP_DESELECT, event,
				pop_track - 1);
			xv_set(ip->tracklist, PANEL_LIST_SELECT, next_track,
				TRUE, NULL);
			update_trackname(ip->tracklist, listentry(next_track),
				NULL, PANEL_LIST_OP_SELECT, event, next_track);
		}
		else
			update_trackname(ip->tracklist, listentry(pop_track -
				1), NULL, PANEL_LIST_OP_VALIDATE, event,
				pop_track - 1);
	}

	return (retval);
}

/*
 * Notify callback function for `defaultvolume'.
 */
void
set_default_volume(item, value, event)
	Panel_item	item;
	int		value;
	Event		*event;
{
	popup1_objects *ip = Workman_popup1;
	static int	old_image = -1;
	Xv_opaque	old_serverimage;
	int		max = xv_get(item, PANEL_MAX_VALUE);
	int		new_image;
	static int	old_volume = -1;

	/*
	 * Make the real volume track the default volume while the user is
	 * sliding the default slider.
	 */
	if (event != NULL)
	{
		info_modified = 1;

		if (event_is_up(event))
		{
			if (old_volume != -1)
				xv_set(Workman_window1->volume, PANEL_VALUE,
					old_volume, NULL);
			old_volume = -1;
		}
		else
		{
			if (old_volume == -1)
				old_volume = xv_get(Workman_window1->volume,
					PANEL_VALUE);
			if (value)
				xv_set(Workman_window1->volume, PANEL_VALUE,
					value - 1, NULL);
		}
		figure_volume(Workman_window1);
	}

	/* we want this to look sort of logarithmic */
	if (value)
	{
		default_volume(xv_get(ip->whichvolume, PANEL_VALUE) * pop_track,
			value);
		new_image = value / (max / 8);
		value = (max * max) - ((max - value) * (max - value));
	}
	else
	{
		new_image = -1;
		default_volume(xv_get(ip->whichvolume, PANEL_VALUE) * pop_track,
			0);
	}

	/* maybe show a new icon... */
	if (new_image > 7)
		new_image = 7;
	if (old_image > -1)
		old_serverimage = xv_get(ip->defaultspeaker, PANEL_LABEL_IMAGE);
	if (new_image != old_image && new_image > -1)
	{
		xv_set(ip->defaultspeaker, PANEL_LABEL_IMAGE,
			xv_create(XV_NULL, SERVER_IMAGE, SERVER_IMAGE_DEPTH, 1,
			XV_WIDTH, 16, XV_HEIGHT, 15, SERVER_IMAGE_X_BITS,
			speaker_bits[new_image], NULL), NULL);
		if (old_image > -1)
			xv_destroy(old_serverimage);
		else
		{
			xv_set(ip->nonemsg, XV_SHOW, FALSE, NULL);
			xv_set(ip->defaultspeaker, XV_SHOW, TRUE, NULL);
		}
		old_image = new_image;
	}
	if (new_image != old_image && new_image == -1)
	{
		xv_destroy(old_serverimage);
		xv_set(ip->defaultspeaker, XV_SHOW, FALSE, NULL);
		xv_set(ip->nonemsg, XV_SHOW, TRUE, NULL);
		old_image = -1;
	}
}

/*
 * Notify callback function for `whichvolume'.
 */
void
set_which_volume(item, value, event)
	Panel_item	item;
	int		value;
	Event		*event;
{
	popup1_objects *ip = Workman_popup1;
	int	vol;

	if (value == 1 && ! pop_track)
	{
		xv_set(item, PANEL_VALUE, 0, NULL);
		value = 0;
	}

	xv_set(item, PANEL_DEFAULT_VALUE, (value + 1) % 2, NULL);
	xv_set(ip->defaultvolume, PANEL_VALUE, vol = get_default_volume(value ?
		pop_track : 0), NULL);
	set_default_volume(ip->defaultvolume, vol, NULL);
}

/*
 * Event notify procedure for text fields, so the PANEL_NOTIFY_PROC gets
 * called when the user clicks on another field.
 */
void
text_event_p(item, event)
	Panel_item	item;
	Event		*event;
{
	Panel_setting   (*fp)();
	int               e;
	char             *pns;
	Panel_setting     level;
	static Panel_item last_item = (Panel_item)NULL;

	e = event_id(event);

/* call last_item's PANEL_NOTIFY_PROC if user mouse clicks off it
   but don't do this if PANEL_NOTIFY_PROC already gets triggered via kbd */
	if ( (item != last_item) && (event_action(event) == ACTION_SELECT) &&
		(last_item != (Panel_item)NULL) )
	{
		level = (Panel_setting) xv_get(last_item, PANEL_NOTIFY_LEVEL);
		switch (level)
		{
		case PANEL_NONE:
			break;
		case PANEL_NON_PRINTABLE:
			break;
		case PANEL_SPECIFIED:
			pns = (char *)xv_get(last_item, PANEL_NOTIFY_STRING);
			if ( strchr( pns, (char)e ) != NULL)
				break;
		case PANEL_ALL:
		default:
			fp = (Panel_setting (*)())
				xv_get(last_item, PANEL_NOTIFY_PROC);
			(*fp)(last_item, event);
			break;
		}
	}

	/* save last item in static var */
	last_item = item;

	(text_event_handler)(item, event);
}

/*
 * Notify callback function for `buttonpl'.
 */
void
popup1_buttonpl_notify_callback(item, event)
	Panel_item	item;
	Event		*event;
{
	popup1_objects *ip = Workman_popup1;
	
	if (dismiss_button && item == ip->buttonpl ||
		xv_get(Workman_plpopup->plpopup, FRAME_CMD_PUSHPIN_IN) == FALSE)
	{
		xv_set(Workman_plpopup->plpopup, FRAME_CMD_PUSHPIN_IN, TRUE,
			NULL);
		xv_set(Workman_plpopup->plpopup, XV_SHOW, TRUE, NULL);
	}
	else
		xv_set(Workman_plpopup->plpopup, FRAME_CMD_PUSHPIN_IN, FALSE,
			XV_SHOW, FALSE, NULL);
	xv_set(Workman_plpopup->plpopup, XV_KEY_DATA, FRAME_CMD_PUSHPIN_IN,
		FALSE, NULL);
}

/*
 * Notify callback function for `button8'.
 */
void
cdinfo_reset(item, event)
	Panel_item	item;
	Event		*event;
{
	enum cd_modes	old_cdmode = cur_cdmode;
	
	kill_stats(Workman_window1);
	wipe_cdinfo();
	load();
	init_stats(Workman_window1);
	show_stats(Workman_window1);
	if (old_cdmode == PAUSED)
	{
		cur_cdmode = PAUSED;
		xv_set(Workman_window1->mode, PANEL_VALUE, PAUSED, NULL);
	}
	info_modified = 0;
}