File: cfg_types.c

package info (click to toggle)
gentoo 0.11.46-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,648 kB
  • ctags: 4,313
  • sloc: ansic: 33,912; sh: 3,903; makefile: 649; yacc: 316; sed: 16
file content (922 lines) | stat: -rw-r--r-- 31,236 bytes parent folder | download | duplicates (3)
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
/*
** 1998-08-12 -	The file typing systems seems to work OK; better give it a GUI too.
** 1999-05-27 -	Changed linkage between this module and cfg_styles. Somewhat cleaner now.
*/

#include "gentoo.h"

#include "types.h"
#include "styles.h"
#include "style_dialog.h"
#include "strutil.h"
#include "guiutil.h"
#include "xmlutil.h"
#include "dirpane.h"
#include "iconutil.h"

#include "configure.h"
#include "cfg_module.h"
#include "cfg_styles.h"

#include "cfg_types.h"

#define	NODE	"FileTypes"

/* ----------------------------------------------------------------------------------------- */

typedef struct {		/* Just a little helper structure for the identification. */
	GtkWidget	*check;
	GtkWidget	*entry;
	GtkWidget	*glob;		/* For the name and file RE, this gives glob->RE translation. */
	GtkWidget	*nocase;	/* Do case-insensitive RE matching? */
} CEntry;

typedef struct {
	GtkWidget	*vbox;		/* The usual mandatory root vbox. */
	GtkWidget	*scwin;		/* Scrolled window wrapping main clist. */
	GtkWidget	*clist;		/* Clist showing existing types. */

	GtkWidget	*ntable;	/* Table holding the type name widgetry. */
	GtkWidget	*name;		/* Entry widget for type name. */
	gint		sig_name;	/* Signal handler number for name changes. */

	GtkWidget	*iframe;	/* Identification frame. */
	GtkWidget	*itable;	/* This holds all the identification widgets. */
	GtkWidget	*ithbox;	/* Hbox for the 'type' id row. */
	GtkWidget	*itype[7];	/* Radio buttons for the type selection. Boring. */
	GSList		*itlist;	/* Radio button grouping list. */
	mode_t		*itmode;	/* The actual mode values (e.g. S_IFREG etc) for types. */
	GtkWidget	*irperm;	/* Require permissions match? */
	GtkWidget	*iphbox;	/* Hbox for all the toggle buttons. */
	GtkWidget	*iperm[6];	/* Toggle buttons for permissions (set uid, gid, sticky, read, write, execute). */
	CEntry		ident[3];	/* The suffix, name and 'file' id widgets. */

	GtkWidget	*sframe;	/* Style frame. */
	GtkWidget	*shbox;		/* Just something to hold the style stuff. */
	GtkWidget	*sbtn;		/* Button to change style (also displays current). */
	GtkWidget	*sbhbox;	/* Hbox containing _button_ contents. */
	GtkWidget	*sicon;		/* A pixmap displayed inside the "sbtn" button. */
	GtkWidget	*slabel;	/* A "loose" label displayed inside the "sbtn" button. */

	GtkWidget	*bhbox;		/* A box for the "Add", "Up", "Down" & "Delete" buttons. */
	GtkWidget	*add, *up,	/* And here are the buttons themselves. */
			*down, *del;

	MainInfo	*min;
	GList		*type;		/* List of editing types. */
	FType		*curr_type;	/* Currently selected type. */
	gint		row;		/* Clist row index of currently selected type. */
	gboolean	modified;	/* Did user change anything? */
} P_Types;

/* ----------------------------------------------------------------------------------------- */

static P_Types	the_page;

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-13 -	Set the widgets so they reflect the settings for the given file type. */
static void set_widgets(P_Types *page, FType *tpe)
{
	gchar	*itext[3];
	gint	iflags[] = { FTFL_REQSUFFIX, FTFL_NAMEMATCH, FTFL_FILEMATCH },
		pflags[] = { FTPM_SETUID, FTPM_SETGID, FTPM_STICKY, FTPM_READ, FTPM_WRITE, FTPM_EXECUTE },
		igflags[] = { 0, FTFL_NAMEGLOB, FTFL_FILEGLOB },
		incflags[] = { 0, FTFL_NAMENOCASE, FTFL_FILENOCASE }, i;

	itext[0] = tpe->suffix;
	itext[1] = tpe->name_re_src;
	itext[2] = tpe->file_re_src;

	if(tpe != NULL)
	{
		gtk_signal_handler_block(GTK_OBJECT(page->name), page->sig_name);
		gtk_entry_set_text(GTK_ENTRY(page->name), tpe->name);
		gtk_signal_handler_unblock(GTK_OBJECT(page->name), page->sig_name);
		gtk_widget_set_sensitive(page->ntable, TRUE);

		for(i = 0; i < 7; i++)
		{
			if(page->itmode[GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(page->itype[i])))] == tpe->mode)
			{
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->itype[i]), TRUE);
				break;
			}
		}

		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->irperm), tpe->flags & FTFL_REQPERM);
		for(i = 0; i < 6; i++)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->iperm[i]), tpe->perm & pflags[i]);
		gtk_widget_set_sensitive(page->iphbox, tpe->flags & FTFL_REQPERM);

		for(i = 0; i < 3; i++)
		{
			gtk_entry_set_text(GTK_ENTRY(page->ident[i].entry), itext[i]);
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->ident[i].check), tpe->flags & iflags[i]);
			gtk_widget_set_sensitive(page->ident[i].entry, tpe->flags & iflags[i]);
			if(i >= 1)
			{
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->ident[i].glob), tpe->flags & igflags[i]);
				gtk_widget_set_sensitive(page->ident[i].glob, tpe->flags & iflags[i]);
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->ident[i].nocase), tpe->flags & incflags[i]);
				gtk_widget_set_sensitive(page->ident[i].nocase, tpe->flags & iflags[i]);
			}
		}
		gtk_widget_set_sensitive(page->iframe, tpe->mode != 0);

		if(tpe->style != NULL)
		{
			GdkPixmap	*ipix;
			GdkBitmap	*imsk = NULL;
			gchar		buf[128];
			const gchar	*iname;

			if((iname = stl_style_property_get_icon(tpe->style, SPN_ICON_UNSEL)) != NULL)
			{
				if((ipix = ico_icon_get(page->min, iname, &imsk)) != NULL)
				{
					if(page->sicon == NULL)
					{
						page->sicon = gtk_pixmap_new(ipix, imsk);
						gtk_box_pack_start(GTK_BOX(page->sbhbox), page->sicon, FALSE, FALSE, 10);
						gtk_box_reorder_child(GTK_BOX(page->sbhbox), page->sicon, 0);
						gtk_widget_show(page->sicon);
					}
					else
						gtk_pixmap_set(GTK_PIXMAP(page->sicon), ipix, imsk);
				}
			}
			g_snprintf(buf, sizeof buf, _("%s - Click to Change..."), stl_style_get_name(tpe->style));
			gtk_label_set_text(GTK_LABEL(page->slabel), buf);
		}
		gtk_widget_set_sensitive(page->sframe, TRUE);
		gtk_widget_set_sensitive(page->up, page->row != 0 && !TYP_IS_UNKNOWN(tpe));
		gtk_widget_set_sensitive(page->down, !TYP_IS_UNKNOWN(tpe) && ((guint) page->row < g_list_length(page->type) - 2));
		gtk_widget_set_sensitive(page->del, tpe->mode != 0);
	}
}

/* 1998-08-13 -	Reset the state of all the type-editing widgets. */
static void reset_widgets(P_Types *page)
{
	gint	i;

	page->curr_type = NULL;
	page->row	= -1;
	gtk_entry_set_text(GTK_ENTRY(page->name), "");
	gtk_widget_set_sensitive(page->ntable, FALSE);

	gtk_widget_set_sensitive(page->iphbox, FALSE);
	for(i = 0; i < 6; i++)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->iperm[i]), FALSE);

	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->itype[0]), TRUE);
	for(i = 0; i < 3; i++)
	{
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->ident[i].check), FALSE);
		gtk_entry_set_text(GTK_ENTRY(page->ident[i].entry), "");
		if(i >= 1)
		{
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->ident[i].glob), FALSE);
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->ident[i].nocase), FALSE);
		}
	}
	gtk_widget_set_sensitive(page->iframe, FALSE);

	if(page->sicon != NULL)
	{
		gtk_widget_destroy(page->sicon);
		page->sicon = NULL;
	}
	gtk_label_set_text(GTK_LABEL(page->slabel), _("(None)"));
	gtk_widget_set_sensitive(page->sframe, FALSE);

	gtk_widget_set_sensitive(page->up, FALSE);
	gtk_widget_set_sensitive(page->down, FALSE);
	gtk_widget_set_sensitive(page->del, FALSE);
}

/* 1998-12-13 -	Broke out the actual list updating code, since it's now needed more. */
static void update_clist(P_Types *page)
{
	gchar	*text[] = { NULL };
	gint	row;
	GList	*iter;

	gtk_clist_freeze(GTK_CLIST(page->clist));
	gtk_clist_clear(GTK_CLIST(page->clist));
	for(iter = page->type; iter != NULL; iter = g_list_next(iter))
	{
		text[0] = ((FType *) iter->data)->name;
		row = gtk_clist_append(GTK_CLIST(page->clist), text);
		gtk_clist_set_row_data(GTK_CLIST(page->clist), row, iter->data);
	}
	gtk_clist_thaw(GTK_CLIST(page->clist));
}

/* 1998-08-13 -	Copy the given type (at <data>) and add it to the editing-copy list. Also
**		append a row with the type's name to the clist. 
*/
static void copy_type(gpointer data, gpointer user)
{
	P_Types	*page = user;
	FType	*tpe = data, *nt;

	if(tpe == NULL)
		return;

	if((nt = typ_type_copy(tpe)) != NULL)
		page->type = typ_type_insert(page->type, NULL, nt);
}

/* 1998-08-13 -	Copy the current type definitions and display the copies in the main clist. */
static void populate_clist(MainInfo *min, P_Types *page)
{
	gtk_clist_clear(GTK_CLIST(page->clist));
	reset_widgets(page);

	g_list_foreach(min->cfg.type, copy_type, page);
	update_clist(page);
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-13 -	Something was selected in the main clist. Update editing widgets. */
static gint evt_clist_select(GtkWidget *wid, gint row, gint column, GdkEventButton *evt, gpointer user)
{
	P_Types	*page = user;
	FType	*tpe;

	if((tpe = gtk_clist_get_row_data(GTK_CLIST(wid), row)) != NULL)
	{
		page->curr_type = tpe;
		page->row	= row;
		set_widgets(page, tpe);
	}
	return TRUE;
}

/* 1998-08-13 -	This gets called when there is no longer a selection in the clist. */
static gint evt_clist_unselect(GtkWidget *wid, gint row, gint column, GdkEventButton *evt, gpointer user)
{
	P_Types	*page = user;

	page->curr_type = NULL;		/* Must be done _before_ reset_widgets()! Tricky! */
	page->row = -1;
	reset_widgets(page);	

	return TRUE;
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-13 -	User is editing the name. Copy it as soon as it changes. Note that there is
**		no unique-ness requirement for type names. That simplifies things.
*/
static gint evt_name_changed(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gchar	*text;

	if(page->curr_type != NULL)
	{
		page->modified = TRUE;
		text = gtk_entry_get_text(GTK_ENTRY(wid));
		page->type = typ_type_set_name(page->type, page->curr_type, text);
		gtk_clist_set_text(GTK_CLIST(page->clist), page->row, 0, text);
	}
	return TRUE;
}

/* 1998-08-13 -	This is the callback for (all seven) mode check buttons. */
static gint evt_mode_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gint	index = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(wid)));

	if(page->curr_type == NULL)
		return TRUE;

	page->modified = TRUE;

	page->curr_type->mode = page->itmode[index];

	return TRUE;
}

/* 1998-09-07 -	User hit the "require permissions" check button. */
static gint evt_id_reqperm_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gint	state;

	if(page->curr_type == NULL)
		return TRUE;

	page->modified = TRUE;
	state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid));

	gtk_widget_set_sensitive(page->iphbox, state);
	if(state)
		page->curr_type->flags |= FTFL_REQPERM;
	else
		page->curr_type->flags &= ~FTFL_REQPERM;
	
	return TRUE;
}

/* 1998-09-07 -	User clicked one of the permission toggle buttons. Remember. */
static gint evt_id_perm_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gint	flag;

	if(page->curr_type == NULL)
		return TRUE;

	page->modified = TRUE;
	flag = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(wid)));
	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid)))
		page->curr_type->perm |= flag;
	else
		page->curr_type->perm &= ~flag;

	return TRUE;
}

/* 1998-08-13 -	User clicked on of the check buttons for identification (suffix, name RE, 'file' RE). Act. */
static gint evt_id_check_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gint	index = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(wid)));
	gint	iflags[] = { FTFL_REQSUFFIX, FTFL_NAMEMATCH, FTFL_FILEMATCH };
	gint	state;

	if(page->curr_type == NULL)
		return TRUE;

	page->modified = TRUE;

	state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid));

	gtk_widget_set_sensitive(page->ident[index].entry, state);
	if(state)
	{
		page->curr_type->flags |= iflags[index];
		gtk_widget_grab_focus(page->ident[index].entry);
	}
	else
		page->curr_type->flags &= ~iflags[index];
	if(index >= 1)
	{
		gtk_widget_set_sensitive(page->ident[index].glob, state);
		gtk_widget_set_sensitive(page->ident[index].nocase, state);
	}
	return TRUE;
}

static gint evt_id_entry_changed(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gchar	*text;
	gint	index = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(wid)));

	if(page->curr_type == NULL)
		return TRUE;

	page->modified = TRUE;

	text = gtk_entry_get_text(GTK_ENTRY(wid));

	/* This is soo crude... I guess the FStyle organization really sucks. :( */
	switch(index)
	{
		case 0:
			stu_strncpy(page->curr_type->suffix, text, sizeof page->curr_type->suffix);
			break;
		case 1:
			stu_strncpy(page->curr_type->name_re_src, text, sizeof page->curr_type->name_re_src);
			break;
		case 2:
			stu_strncpy(page->curr_type->file_re_src, text, sizeof page->curr_type->file_re_src);
			break;
	}
	return TRUE;
}

/* 1998-08-30 -	User just clicked the glob translation check button. Do the things. */
static gint evt_id_glob_changed(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gint	index = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(wid)));
	gint	flag[] = { 0, FTFL_NAMEGLOB, FTFL_FILEGLOB };

	if(page->curr_type == NULL)
		return TRUE;

	page->modified = TRUE;
	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid)))
		page->curr_type->flags |= flag[index];
	else
		page->curr_type->flags &= ~flag[index];

	return TRUE;
}

/* 1998-09-15 -	User just clicked the nocase toggle button. React! */
static gint evt_id_nocase_changed(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gint	index = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(wid)));
	gint	flag[] = { 0, FTFL_NAMENOCASE, FTFL_FILENOCASE };

	if(page->curr_type == NULL)
		return TRUE;

	page->modified = TRUE;
	if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wid)))
		page->curr_type->flags |= flag[index];
	else
		page->curr_type->flags &= ~flag[index];

	return TRUE;
}

/* ----------------------------------------------------------------------------------------- */

/* 1999-05-27 -	Select style for current type. Rewritten, to work with new style config module. */
static gint evt_style_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;

	if((page != NULL) && (page->curr_type != NULL))
	{
		Style	*stl;

		if((stl = sdl_dialog_sync_new_wait(cst_get_styleinfo(), NULL)) != NULL)
		{
			page->curr_type->style = stl;
			set_widgets(page, page->curr_type);
		}
	}
	return TRUE;
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-14 -	User just clicked the 'Add' button. Let's add a new type to play with!
** 1998-12-14 -	Rewritten to work better with the new priority-less type editing system.
*/
static gint evt_add_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	CfgInfo	*cfg  = gtk_object_get_user_data(GTK_OBJECT(wid));
	FType	*tpe;
	gint	row;

	if((tpe = typ_type_new(cfg, _("(New Type)"), S_IFREG, 0, NULL, NULL, NULL)) != NULL)
	{
		page->type = typ_type_insert(page->type, page->curr_type, tpe);
		page->type = typ_type_set_style(page->type, tpe, cst_get_styleinfo(), NULL);
		row = g_list_index(page->type, tpe);
		update_clist(page);
		gtk_clist_select_row(GTK_CLIST(page->clist), row, 0);
		gtk_clist_moveto(GTK_CLIST(page->clist), row, -1, 0.5f, 0.0f);
		gtk_entry_select_region(GTK_ENTRY(page->name), 0, -1);
		gtk_widget_grab_focus(page->name);
		page->modified = TRUE;
	}
	return TRUE;
}

/* 1998-08-14 -	Delete button was hit, so kill the currently selected type. Tragic.
** 1998-12-14 -	Rewritten. Didn't use the types-module, and lost selection.
*/
static gint evt_del_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;
	gint	row, len;

	if(page->curr_type != NULL)
	{
		page->type = typ_type_remove(page->type, page->curr_type);
		len = g_list_length(page->type);
		row = (page->row > len) ? len - 1 : page->row;
		update_clist(page);
		gtk_clist_select_row(GTK_CLIST(page->clist), row, 0);
		gtk_clist_moveto(GTK_CLIST(page->clist), row, -1, 0.5f, 0.0f);
		page->modified = TRUE;
	}
	return TRUE;
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-12-13 -	Move selected type up one position (increases its priority). */
static gint evt_up_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;

	if(page->curr_type != NULL)
	{
		page->type = typ_type_move(page->type, page->curr_type, -1);
		update_clist(page);
		gtk_clist_select_row(GTK_CLIST(page->clist), page->row - 1, 0);
		gtk_clist_moveto(GTK_CLIST(page->clist), page->row - 1, -1, 0.0f, 0.0f);
		page->modified = TRUE;
	}
	return TRUE;
}

/* 1998-12-13 -	Move selected type down, decreasing its priority. */
static gint evt_down_clicked(GtkWidget *wid, gpointer user)
{
	P_Types	*page = user;

	if(page->curr_type != NULL)
	{
		page->type = typ_type_move(page->type, page->curr_type, 1);
		update_clist(page);
		gtk_clist_select_row(GTK_CLIST(page->clist), page->row + 1, 0);
		gtk_clist_moveto(GTK_CLIST(page->clist), page->row + 1, -1, 1.0f, 0.0f);
		page->modified = TRUE;
	}
	return TRUE;
}

/* ----------------------------------------------------------------------------------------- */

static GtkWidget * ctp_init(MainInfo *min, gchar **name)
{
	P_Types		*page = &the_page;
	GtkWidget	*label, *vbox, *sep;
	const gchar	*tlab[] = { N_("File"), N_("Dir"), N_("Link"), N_("B-Dev"), N_("C-Dev"), N_("FIFO"), N_("Socket") },
			*iplab[] = { N_("SetUID"), N_("SetGID"), N_("Sticky"),  N_("Readable"),
					N_("Writable"), N_("Executable") },
			*idlab[] = { N_("Require Suffix"), N_("Match Name (RE)"), N_("Match 'file' (RE)") };
	gint		idmax[] = { FT_SUFFIX_SIZE, FT_NAMERE_SIZE, FT_FILERE_SIZE },
			ifperm[] = { FTPM_SETUID, FTPM_SETGID, FTPM_STICKY, FTPM_READ, FTPM_WRITE, FTPM_EXECUTE }, i, y;
	static mode_t	type[] = { S_IFREG, S_IFDIR, S_IFLNK, S_IFBLK, S_IFCHR, S_IFIFO, S_IFSOCK };

	page->min = min;

	page->type = NULL;
	page->curr_type = NULL;
	page->row       = -1;
	page->modified  = FALSE;

	page->vbox = gtk_vbox_new(FALSE, 0);

	page->scwin = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(page->scwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	page->clist = gtk_clist_new(1);
	gtk_signal_connect(GTK_OBJECT(page->clist), "select_row", GTK_SIGNAL_FUNC(evt_clist_select), page);
	gtk_signal_connect(GTK_OBJECT(page->clist), "unselect_row", GTK_SIGNAL_FUNC(evt_clist_unselect), page);
	gtk_container_add(GTK_CONTAINER(page->scwin), page->clist);
	gtk_box_pack_start(GTK_BOX(page->vbox), page->scwin, TRUE, TRUE, 0);

	page->ntable = gtk_table_new(2, 2, FALSE);
	label = gtk_label_new(_("Name"));
	gtk_table_attach(GTK_TABLE(page->ntable), label, 0, 1, 0, 1,  GTK_FILL,0,5,0);
	page->name = gtk_entry_new_with_max_length(STL_STYLE_NAME_SIZE - 1);
	page->sig_name = gtk_signal_connect(GTK_OBJECT(page->name), "changed", GTK_SIGNAL_FUNC(evt_name_changed), page);
	gtk_table_attach_defaults(GTK_TABLE(page->ntable), page->name, 1, 2, 0, 1);

	gtk_box_pack_start(GTK_BOX(page->vbox), page->ntable, FALSE, FALSE, 0);

	page->iframe = gtk_frame_new(_("Identification"));
	page->itable = gtk_table_new(7, 3, FALSE);
	label = gtk_label_new(_("Require Type"));
	gtk_table_attach(GTK_TABLE(page->itable), label, 0, 1, 0, 1,  GTK_FILL,0,0,0);
	page->ithbox = gtk_hbox_new(FALSE, 0);

	page->itlist = gui_radio_group_new(7, tlab, page->itype);
	page->itmode = type;
	for(i = 0; i < 7; i++)
	{
		gtk_signal_connect(GTK_OBJECT(page->itype[i]), "clicked", GTK_SIGNAL_FUNC(evt_mode_clicked), page);
		gtk_object_set_user_data(GTK_OBJECT(page->itype[i]), GINT_TO_POINTER(i));
		gtk_box_pack_start(GTK_BOX(page->ithbox), page->itype[i], TRUE, TRUE, 0);
	}
	gtk_table_attach(GTK_TABLE(page->itable), page->ithbox, 1, 3, 0, 1, GTK_EXPAND|GTK_FILL,0,0,0);

	page->irperm = gtk_check_button_new_with_label(_("Require Protection"));
	gtk_signal_connect(GTK_OBJECT(page->irperm), "clicked", GTK_SIGNAL_FUNC(evt_id_reqperm_clicked), page);
	gtk_table_attach(GTK_TABLE(page->itable), page->irperm, 0, 1, 1, 2,  GTK_FILL,0,0,0);
	page->iphbox = gtk_hbox_new(FALSE, 0);
	for(i = 0; i < 6; i++)
	{
		page->iperm[i] = gtk_toggle_button_new_with_label(_(iplab[i]));
		gtk_object_set_user_data(GTK_OBJECT(page->iperm[i]), GINT_TO_POINTER(ifperm[i]));
		gtk_signal_connect(GTK_OBJECT(page->iperm[i]), "clicked", GTK_SIGNAL_FUNC(evt_id_perm_clicked), page);
		gtk_box_pack_start(GTK_BOX(page->iphbox), page->iperm[i], TRUE, TRUE, 0);
	}
	gtk_table_attach(GTK_TABLE(page->itable), page->iphbox, 1, 3, 1, 2,  GTK_EXPAND | GTK_FILL,0,0,0);

	sep = gtk_hseparator_new();
	gtk_table_attach(GTK_TABLE(page->itable), sep, 0, 3, 4, 5, GTK_EXPAND | GTK_FILL,0,0,5);

	for(i = 0; i < 3; i++)
	{
		y = (i == 2) ? i + 3 : i + 2;

		page->ident[i].check = gtk_check_button_new_with_label(_(idlab[i]));
		gtk_object_set_user_data(GTK_OBJECT(page->ident[i].check), GINT_TO_POINTER(i));
		gtk_signal_connect(GTK_OBJECT(page->ident[i].check), "clicked", GTK_SIGNAL_FUNC(evt_id_check_clicked), page);
		gtk_table_attach(GTK_TABLE(page->itable), page->ident[i].check, 0, 1, y, y+1,  GTK_FILL,0,0,0);

		page->ident[i].entry = gtk_entry_new_with_max_length(idmax[i] - 1);
		gtk_object_set_user_data(GTK_OBJECT(page->ident[i].entry), GINT_TO_POINTER(i));
		gtk_signal_connect(GTK_OBJECT(page->ident[i].entry), "changed", GTK_SIGNAL_FUNC(evt_id_entry_changed), page);
		gtk_table_attach(GTK_TABLE(page->itable), page->ident[i].entry, 1, (i == 0) ? 3 : 2, y, y+1,  GTK_EXPAND | GTK_FILL,0,0,0);

		if(i >= 1)
		{
			GtkWidget	*hbox;

			hbox = gtk_hbox_new(FALSE, 0);
			page->ident[i].glob = gtk_check_button_new_with_label(_("Glob?"));
			gtk_object_set_user_data(GTK_OBJECT(page->ident[i].glob), GINT_TO_POINTER(i));
			gtk_signal_connect(GTK_OBJECT(page->ident[i].glob), "clicked", GTK_SIGNAL_FUNC(evt_id_glob_changed), page);
			gtk_box_pack_start(GTK_BOX(hbox), page->ident[i].glob, FALSE, FALSE, 0);

			page->ident[i].nocase = gtk_check_button_new_with_label(_("Ignore Case?"));
			gtk_object_set_user_data(GTK_OBJECT(page->ident[i].nocase), GINT_TO_POINTER(i));
			gtk_signal_connect(GTK_OBJECT(page->ident[i].nocase), "clicked", GTK_SIGNAL_FUNC(evt_id_nocase_changed), page);
			gtk_box_pack_start(GTK_BOX(hbox), page->ident[i].nocase, FALSE, FALSE, 0);

			gtk_table_attach(GTK_TABLE(page->itable), hbox, 2, 3, y, y + 1, GTK_SHRINK,0,0,0);
		}
	}
	gtk_container_add(GTK_CONTAINER(page->iframe), page->itable);
	gtk_box_pack_start(GTK_BOX(page->vbox), page->iframe, FALSE, FALSE, 5);

	page->sframe = gtk_frame_new(_("Type's Style"));
	page->shbox = gtk_hbox_new(FALSE, 0);
	label = gtk_label_new(_("Style"));
	gtk_box_pack_start(GTK_BOX(page->shbox), label, FALSE, FALSE, 5);
	page->sbtn = gtk_button_new();
	gtk_signal_connect(GTK_OBJECT(page->sbtn), "clicked", GTK_SIGNAL_FUNC(evt_style_clicked), page);

	page->sbhbox = gtk_hbox_new(FALSE, 0);
	page->sicon  = NULL;
	page->slabel = gtk_label_new("");
	gtk_box_pack_start(GTK_BOX(page->sbhbox), page->slabel, TRUE, TRUE, 0);
	gtk_container_add(GTK_CONTAINER(page->sbtn), page->sbhbox);

	gtk_box_pack_start(GTK_BOX(page->shbox), page->sbtn, TRUE, TRUE, 5);
	vbox = gtk_vbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), page->shbox, FALSE, FALSE, 5);
	gtk_container_add(GTK_CONTAINER(page->sframe), vbox);

	gtk_box_pack_start(GTK_BOX(page->vbox), page->sframe, FALSE, FALSE, 5);

	page->bhbox = gtk_hbox_new(FALSE, 0);
	page->add = gtk_button_new_with_label(_("Add"));
	gtk_object_set_user_data(GTK_OBJECT(page->add), &min->cfg);
	gtk_signal_connect(GTK_OBJECT(page->add), "clicked", GTK_SIGNAL_FUNC(evt_add_clicked), page);
	gtk_box_pack_start(GTK_BOX(page->bhbox), page->add, TRUE, TRUE, 5);

	page->up = gui_arrow_button_new(GTK_ARROW_UP);
	gtk_signal_connect(GTK_OBJECT(page->up), "clicked", GTK_SIGNAL_FUNC(evt_up_clicked), page);
	gtk_box_pack_start(GTK_BOX(page->bhbox), page->up, FALSE, FALSE, 0);

	page->down = gui_arrow_button_new(GTK_ARROW_DOWN);
	gtk_signal_connect(GTK_OBJECT(page->down), "clicked", GTK_SIGNAL_FUNC(evt_down_clicked), page);
	gtk_box_pack_start(GTK_BOX(page->bhbox), page->down, FALSE, FALSE, 0);

	page->del = gtk_button_new_with_label(_("Delete"));
	gtk_signal_connect(GTK_OBJECT(page->del), "clicked", GTK_SIGNAL_FUNC(evt_del_clicked), page);
	gtk_box_pack_start(GTK_BOX(page->bhbox), page->del, TRUE, TRUE, 5);

	gtk_box_pack_start(GTK_BOX(page->vbox), page->bhbox, FALSE, FALSE, 5);

	gtk_widget_show_all(page->vbox);		

	cfg_tree_level_append(_("Types"), page->vbox);
	cfg_tree_level_end();

	return NULL;
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-14 -	Redisplay imminent, update looks. Simplistic. */
static void ctp_update(MainInfo *min)
{
	populate_clist(min, &the_page);
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-14 -	Accept the changes. Replace the cfg->type list with our the_page.list, and
**		also free the one being replaced.
*/
static void ctp_accept(MainInfo *min)
{
	P_Types	*page = &the_page;
	GList	*iter;

	if(page->modified)
	{
		for(iter = min->cfg.type; iter != NULL; iter = g_list_next(iter))
			typ_type_destroy(iter->data);
		g_list_free(min->cfg.type);
		min->cfg.type = page->type;
		page->type	= NULL;		/* Make sure list gets rebuilt next time. */
		page->modified	= FALSE;
		cfg_set_flags(CFLG_RESCAN_LEFT | CFLG_RESCAN_RIGHT);
	}
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-14 -	Save out a single file type. */
static void save_type(gpointer data, gpointer user)
{
	FType	*tpe = data;
	FILE	*out = user;

	if(tpe == NULL)
		return;

	xml_put_node_open(out, "FileType");
	xml_put_text(out, "name", tpe->name);
	xml_put_integer(out, "mode", tpe->mode);

	if(tpe->flags & FTFL_REQPERM)
		xml_put_integer(out, "perm", tpe->perm);
	if(tpe->flags & FTFL_REQSUFFIX)
		xml_put_text(out, "suffix", tpe->suffix);
	if(tpe->flags & FTFL_NAMEMATCH)
	{
		xml_put_text(out, "name_re", tpe->name_re_src);
		xml_put_boolean(out, "name_glob", tpe->flags & FTFL_NAMEGLOB);
		xml_put_boolean(out, "name_nocase", tpe->flags & FTFL_NAMENOCASE);
	}
	if(tpe->flags & FTFL_FILEMATCH)
	{
		xml_put_text(out, "file_re", tpe->file_re_src);
		xml_put_boolean(out, "file_glob", tpe->flags & FTFL_FILEGLOB);
		xml_put_boolean(out, "file_nocase", tpe->flags & FTFL_FILENOCASE);
	}
	if(tpe->style != NULL)
		xml_put_text(out, "style", stl_style_get_name(tpe->style));
	else
		fprintf(stderr, "**CFGTYPES: Type '%s' has NULL style!\n", tpe->name);
	xml_put_node_close(out, "FileType");
}

/* 1998-08-14 -	Save out all the filetype information. */
static gint ctp_save(MainInfo *min, FILE *out)
{
	xml_put_node_open(out, NODE);
	g_list_foreach(min->cfg.type, save_type, out);
	xml_put_node_close(out, NODE);

	return 1;
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-14 -	Load a single type and put it into the list.
** 1999-03-07 -	Fixed huge bug, where a pointer to mode_t was cast to int *.
**		Not good, since mode_t is just 16 bit...
*/
static void load_type(const XmlNode *node, gpointer user)
{
	CfgInfo		*cfg = user;
	const gchar	*name = NULL, *suffix = NULL, *name_re = NULL, *file_re = NULL, *style = NULL;
	gint		perm = 0, tmp, mode;
	FType		*tpe;

	xml_get_text(node, "name", &name);
	xml_get_integer(node, "mode", &mode);
	xml_get_integer(node, "perm", &perm);
	xml_get_text(node, "suffix", &suffix);
	xml_get_text(node, "name_re", &name_re);
	xml_get_text(node, "file_re", &file_re);
	xml_get_text(node, "style", &style);

	if((tpe = typ_type_new(cfg, name, mode, perm, suffix, name_re, file_re)) != NULL)
	{
		if(xml_get_boolean(node, "name_glob", &tmp) && tmp)
			tpe->flags |= FTFL_NAMEGLOB;
		if(xml_get_boolean(node, "name_nocase", &tmp) && tmp)
			tpe->flags |= FTFL_NAMENOCASE;
		if(xml_get_boolean(node, "file_glob", &tmp) && tmp)
			tpe->flags |= FTFL_FILEGLOB;
		if(xml_get_boolean(node, "file_nocase", &tmp) && tmp)
			tpe->flags |= FTFL_FILENOCASE;
		cfg->type = typ_type_insert(cfg->type, NULL, tpe);
		cfg->type = typ_type_set_style(cfg->type, tpe, cfg->style, style);
	}
}

/* 1998-08-14 -	Load in the filetypes hanging off of <node>. */
static void ctp_load(MainInfo *min, const XmlNode *node)
{
	GList	*old, *next;

	/* First destroy any previously defined types (e.g. the built-in ones). */
	for(old = min->cfg.type; old != NULL; old = next)
	{
		next = g_list_next(old);
		if(old->data == NULL)
			continue;
		typ_type_destroy(old->data);
		min->cfg.type = g_list_remove(min->cfg.type, old->data);
	}
	xml_node_visit_children(node, load_type, &min->cfg);
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-14 -	When the GUI hides (i.e. is removed from screen by a reason different than
**		the user hitting the "OK" button), we free our editing copies.
*/
static void ctp_hide(MainInfo *min)
{
	P_Types	*page = &the_page;
	GList	*old, *next;

	for(old = page->type; old != NULL; old = next)
	{
		next = g_list_next(old);
		if(old->data == NULL)
			continue;
		typ_type_destroy(old->data);
		page->type = g_list_remove(page->type, old->data);
	}
	g_list_free(page->type);
	page->type = NULL;
}

/* ----------------------------------------------------------------------------------------- */

const CfgModule * ctp_describe(MainInfo *min)
{
	static const CfgModule	desc = { NODE, ctp_init, ctp_update, ctp_accept, ctp_save, ctp_load, ctp_hide };

	return &desc;
}

/* ----------------------------------------------------------------------------------------- */

/* 1998-08-25 -	Returns the list of current editing types. Handy when styles have changed.
**		This function is part of the rather nasty relationship between styles and
**		types; if you change enough on the styles page, the types will also think
**		they've been modified (thanks to the flag setting below). This is all due
**		to the fact that types link to their styles using direct pointer links.
*/
GList * ctp_get_types(void)
{
	the_page.modified = TRUE;

	return the_page.type;
}

/* ----------------------------------------------------------------------------------------- */

/* 1999-05-27 -	Go through current types, and if any type contains a link to a style named <from>,
**		replace that with a link to the given style. Called by the styles config module,
**		when a style is renamed or deleted (in the latter case, <to> will be "Root").
*/
void ctp_replace_style(const gchar *from, Style *to)
{
	GList	*iter;
	FType	*type;

	for(iter = the_page.type; iter != NULL; iter = g_list_next(iter))
	{
		type = iter->data;

		if(strcmp(stl_style_get_name(type->style), from) == 0)
		{
			type->style = to;
			the_page.modified = TRUE;
		}
	}
}

/* 1999-05-27 -	Change all type's style pointers to point at styles in <to>, rather than <from>.
**		This gets called by the cfg_styles module, just before it destroys the <from>
**		styles.
*/
void ctp_relink_styles(StyleInfo *from, StyleInfo *to)
{
	GList	*iter;
	FType	*type;
	Style	*ns;

	for(iter = the_page.type; iter != NULL; iter = g_list_next(iter))
	{
		type = iter->data;
		ns   = stl_styleinfo_style_find(to, stl_style_get_name(type->style));
		if(type->style != ns)
		{
			type->style = ns;
			the_page.modified = TRUE;
		}
	}
}