File: sort_window.c

package info (click to toggle)
gtkpod 0.99.14-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,716 kB
  • ctags: 3,266
  • sloc: ansic: 43,120; sh: 4,837; xml: 1,316; lex: 637; perl: 264; makefile: 236; awk: 73; python: 35
file content (746 lines) | stat: -rw-r--r-- 19,039 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
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
/*
|  Copyright (C) 2002 Corey Donohoe <atmos at atmos.org>
|  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
|  Part of the gtkpod project.
|
|  URL: http://www.gtkpod.org/
|  URL: http://gtkpod.sourceforge.net/
|
|  This program is free software; you can redistribute it and/or modify
|  it under the terms of the GNU General Public License as published by
|  the Free Software Foundation; either version 2 of the License, or
|  (at your option) any later version.
|
|  This program is distributed in the hope that it will be useful,
|  but WITHOUT ANY WARRANTY; without even the implied warranty of
|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
|  GNU General Public License for more details.
|
|  You should have received a copy of the GNU General Public License
|  along with this program; if not, write to the Free Software
|  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|  iTunes and iPod are trademarks of Apple
|
|  This product is not supported/written/published by Apple!
|
|  $Id: sort_window.c 2087 2008-08-04 13:12:23Z jcsjcs $
*/

#include <stdio.h>
#include <string.h>
#include "charset.h"
#include "display_itdb.h"
#include "info.h"
#include "fileselection.h"
#include "sha1.h"
/*#include "md5.h"*/
#include "misc.h"
#include "misc_track.h"
#include "prefs.h"
#include "sort_window.h"
#include "repository.h"
#include "display_coverart.h"

GladeXML *prefs_window_xml;
GladeXML *sort_window_xml;

static GtkWidget *sort_window = NULL;

/* New prefs temp handling */
static TempPrefs *sort_temp_prefs;
static TempLists *sort_temp_lists;

static const GtkFileChooserAction path_type[] =
{
    GTK_FILE_CHOOSER_ACTION_OPEN,  /* select file */
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, /* select folder */
    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_FILE_CHOOSER_ACTION_OPEN,
    -1
};

enum {
    TRACK_COLUMNS_TEXT,
    TRACK_COLUMNS_INT,
    TRACK_N_COLUMNS
};

typedef enum {
    HIDE,
    SHOW
} TrackColumnsType;

/* ------------------------------------------------------------ *\
 *                                                              *
 * Sort-Prefs Window                                            *
 *                                                              *
\* ------------------------------------------------------------ */

/* the following checkboxes exist */
static const gint sort_ign_fields[] = {
    T_TITLE, T_ARTIST,
    T_ALBUM, T_COMPOSER,
    -1
};

/* Copy the current ignore fields and ignore strings into scfg */
static void sort_window_read_sort_ign ()
{
    gint i;
    GtkTextView *tv;
    GtkTextBuffer *tb;
    GList *sort_ign_strings;
    GList *current;
    gchar *buf;


    /* read sort field states */
    for (i=0; sort_ign_fields[i] != -1; ++i)
    {
	buf = g_strdup_printf ("sort_ign_field_%d",
				      sort_ign_fields[i]);
	GtkWidget *w = gtkpod_xml_get_widget (sort_window_xml, buf);
	g_return_if_fail (w);
	prefs_set_int( buf,
	     gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (w)));
	g_free (buf);
    }
    
    /* Read sort ignore strings */
    tv = GTK_TEXT_VIEW (gtkpod_xml_get_widget (sort_window_xml,
					      "sort_ign_strings"));
    g_return_if_fail (tv);
    tb = gtk_text_view_get_buffer (tv);
    g_return_if_fail (tb);

    sort_ign_strings = get_list_from_buffer(tb);
    current = sort_ign_strings;
    
    /* Add a trailing whitespace to strings */
    while (current)
    {
	g_strstrip(current->data);
	
        if (strlen(current->data) != 0)
	{
	    buf = g_strdup_printf("%s ",(gchar *) current->data);
	    g_free(current->data);
	    current->data = buf;
	}

	current = g_list_next(current);
    }
	
    temp_list_add(sort_temp_lists, "sort_ign_string_", sort_ign_strings);
}

/**
 * sort_window_create
 * Create, Initialize, and Show the sorting preferences window
 * allocate a static sort struct for temporary variables
 */
void sort_window_create (void)
{
    if (sort_window)
    {
		/* sort options already open --> simply raise to the top */
		gdk_window_raise(sort_window->window);
    }
    else
    {
		GList *sort_ign_strings;
		GList *current;  /* current sort ignore item */
		GtkWidget *w;
		GtkTextView *tv;
		GtkTextBuffer *tb;
		gint i;
		GtkTextIter ti;
		gchar *str;
		GtkTooltips *tooltips;
		gint *tm_listed_order, tm_list_pos;

		sort_temp_prefs = temp_prefs_create();
		sort_temp_lists = temp_lists_create();

		sort_window_xml = gtkpod_xml_new (xml_file, "sort_window");
		glade_xml_signal_autoconnect (sort_window_xml);

		sort_window = gtkpod_xml_get_widget (sort_window_xml, "sort_window");

		/* label the ignore-field checkbox-labels */
		for (i=0; sort_ign_fields[i] != -1; ++i)
		{
			gchar *buf = g_strdup_printf ("sort_ign_field_%d",
						  sort_ign_fields[i]);
			GtkWidget *w = gtkpod_xml_get_widget (sort_window_xml, buf);
			g_return_if_fail (w);
			gtk_button_set_label (
			GTK_BUTTON (w),
			gettext (get_t_string (sort_ign_fields[i])));
			gtk_toggle_button_set_active (
			GTK_TOGGLE_BUTTON (w),
			prefs_get_int (buf));
			g_free (buf);
		}
		/* set the ignore strings */
		tv = GTK_TEXT_VIEW (gtkpod_xml_get_widget (sort_window_xml,
							  "sort_ign_strings"));
		tb = gtk_text_view_get_buffer (tv);
		if (!tb)
		{   /* text buffer doesn't exist yet */
			tb = gtk_text_buffer_new (NULL);
			gtk_text_view_set_buffer(tv, tb);
			gtk_text_view_set_editable(tv, FALSE);
			gtk_text_view_set_cursor_visible(tv, FALSE);
		}
		
		sort_ign_strings = prefs_get_list("sort_ign_string_");
		current = sort_ign_strings;
		while (current)
		{
			str = (gchar *)current->data;
			current = g_list_next(current);

			/* append new text to the end */
			gtk_text_buffer_get_end_iter (tb, &ti);
			gtk_text_buffer_insert (tb, &ti, str, -1);
			/* append newline */
			gtk_text_buffer_get_end_iter (tb, &ti);
			gtk_text_buffer_insert (tb, &ti, "\n", -1);
		}
		
		prefs_free_list(sort_ign_strings);

		sort_window_read_sort_ign ();

		/* Set Sort-Column-Combo */
		/* create the list in the order of the columns displayed */
		tm_store_col_order ();

		/* Here we store the order of TM_Items in the
		 * GtkComboBox */
		tm_listed_order = g_new (gint, TM_NUM_COLUMNS);
		tm_list_pos = 1;

		w = gtkpod_xml_get_widget (sort_window_xml, "sort_combo");
		gtk_combo_box_remove_text (GTK_COMBO_BOX (w), 0);

		gtk_combo_box_append_text (GTK_COMBO_BOX (w), _("No sorting"));

		for (i = 0; i < TM_NUM_COLUMNS; ++i)
		{   /* first the visible columns */
			TM_item col = prefs_get_int_index("col_order", i);
			if (col != -1)
			{
				if (prefs_get_int_index("col_visible", col))
				{
					gtk_combo_box_append_text (GTK_COMBO_BOX (w), gettext (get_tm_string (col)));
					tm_listed_order[col] = tm_list_pos;
					++tm_list_pos;
				}
			}
		}

		for (i=0; i<TM_NUM_COLUMNS; ++i)
		{   /* now the hidden colums */
			TM_item col = prefs_get_int_index("col_order", i);
			if (col != -1)
			{
				if (!prefs_get_int_index("col_visible", col))
				{
					gtk_combo_box_append_text (GTK_COMBO_BOX (w), gettext (get_tm_string (col)));
					tm_listed_order[col] = tm_list_pos;
					++tm_list_pos;
				}
			}
		}

		/* associate tm_listed_order with sort_window */
		g_object_set_data (G_OBJECT (sort_window), "tm_listed_order", tm_listed_order);
			
		tooltips = gtk_tooltips_new ();
		gtk_tooltips_set_tip (tooltips, w, _("You can also use the table headers, but this allows you to sort according to a column that is not displayed."), NULL);

		sort_window_update ();

		sort_window_show_hide_tooltips ();
		gtk_widget_show (sort_window);
    }
}



/* Update sort_window's settings (except for ignore list and ignore
 * fields) */
void sort_window_update (void)
{
    if (sort_window)
    {
	/*	gchar *str; */
		GtkWidget *w = NULL;
		gint *tm_listed_order;
		gint sortorder;
		TM_item sortcol;

		switch (prefs_get_int("pm_sort"))
		{
		case SORT_ASCENDING:
			w = gtkpod_xml_get_widget (sort_window_xml, "pm_ascend");
			break;
		case SORT_DESCENDING:
			w = gtkpod_xml_get_widget (sort_window_xml, "pm_descend");
			break;
		case SORT_NONE:
			w = gtkpod_xml_get_widget (sort_window_xml, "pm_none");
			break;
		}
		if (w)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE);

		w = NULL;
		switch (prefs_get_int("st_sort"))
		{
		case SORT_ASCENDING:
			w = gtkpod_xml_get_widget (sort_window_xml, "st_ascend");
			break;
		case SORT_DESCENDING:
			w = gtkpod_xml_get_widget (sort_window_xml, "st_descend");
			break;
		case SORT_NONE:
			w = gtkpod_xml_get_widget (sort_window_xml, "st_none");
			break;
		}
		if (w)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE);

		switch (prefs_get_int("tm_sort"))
		{
		case SORT_ASCENDING:
			w = gtkpod_xml_get_widget (sort_window_xml, "tm_ascend");
			break;
		case SORT_DESCENDING:
			w = gtkpod_xml_get_widget (sort_window_xml, "tm_descend");
			break;
		case SORT_NONE:
			w = gtkpod_xml_get_widget (sort_window_xml, "tm_none");
			break;
		}
		if (w)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE);

		w = gtkpod_xml_get_widget (sort_window_xml, "tm_autostore");
		if (w)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
						 prefs_get_int("tm_autostore"));

		if((w = gtkpod_xml_get_widget (sort_window_xml, "cfg_case_sensitive")))
		{
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
						 prefs_get_int("case_sensitive"));
		}
		/* set standard entry in combo */
	/*	str = gettext (get_tm_string (prefs_get_int("tm_sortcol")));
		w = gtkpod_xml_get_widget (sort_window_xml, "sort_combo");
		gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (w)->entry), str); */
		w = gtkpod_xml_get_widget (sort_window_xml, "sort_combo");
		tm_listed_order = g_object_get_data (G_OBJECT (sort_window), "tm_listed_order");
		g_return_if_fail (tm_listed_order);
		sortcol = prefs_get_int ("tm_sortcol");
		sortorder = prefs_get_int ("tm_sort");
		if ((sortcol >= 0) && (sortcol < TM_NUM_COLUMNS) && (sortorder != SORT_NONE))
		{
		    gtk_combo_box_set_active (GTK_COMBO_BOX(w), tm_listed_order[sortcol]);
		}
		else
		{
		    gtk_combo_box_set_active (GTK_COMBO_BOX(w), 0);
		}
    }
}


/* turn the sort window insensitive (if it's open) */
void sort_window_block (void)
{
    if (sort_window)
	gtk_widget_set_sensitive (sort_window, FALSE);
}

/* turn the sort window sensitive (if it's open) */
void sort_window_release (void)
{
    if (sort_window)
	gtk_widget_set_sensitive (sort_window, TRUE);
}


/* make the tooltips visible or hide it depending on the value set in
 * the prefs (tooltips_prefs) */
void sort_window_show_hide_tooltips (void)
{
    if (sort_window)
    {
		GtkTooltips *tt;
		GtkTooltipsData *tooltips_data;
		
		tooltips_data = gtk_tooltips_data_get (gtkpod_xml_get_widget (sort_window_xml, "sort_combo"));
		tt = tooltips_data->tooltips;

		if (tt)
		{
			if (prefs_get_int("display_tooltips_prefs")) 
			gtk_tooltips_enable (tt);
			else                                     
			gtk_tooltips_disable (tt);
		}
		else
		{
			g_warning ("***tt is NULL***");
		}
    }
}


/* get the sort_column selected in the combo */
static TM_item sort_window_get_sort_col (void)
{
    GtkWidget *w;
    TM_item sortcol;
    gint item;
    gint *tm_listed_order;

    g_return_val_if_fail (sort_window, -1);
    tm_listed_order = g_object_get_data (G_OBJECT (sort_window), "tm_listed_order");

    w = gtkpod_xml_get_widget (sort_window_xml, "sort_combo");
    item = gtk_combo_box_get_active (GTK_COMBO_BOX (w));

    if ((item<=0) || (item >TM_NUM_COLUMNS))
    {   /* either an error or no entry is active or "No sorting" is
	   selected (0). In all these cases we return -1 ("No
	   sorting") */
	sortcol = -1;
    }
    else
    {
	gint i;
	sortcol = -1;
	for (i=0; i<TM_NUM_COLUMNS; ++i)
	{
	    if (tm_listed_order[i] == item)
	    {
		sortcol = i;
		break;
	    }
	}
    }

    return sortcol;
}


/* Prepare keys to be copied to prefs table */
static void sort_window_set ()
{
    gint val; /* A value from temp prefs */
    TM_item sortcol_new;
    TM_item sortcol_old;

    sortcol_old = prefs_get_int("tm_sortcol");
    sortcol_new = sort_window_get_sort_col();
    if (sortcol_new != -1)
    {
	prefs_set_int ("tm_sortcol", sortcol_new);
	if (prefs_get_int ("tm_sort") == SORT_NONE)
	{
	    if (temp_prefs_get_int_value (sort_temp_prefs, "tm_sort", &val))
	    {
		prefs_set_int ("tm_sort", val);
	    }
	    else
	    {
		prefs_set_int ("tm_sort", GTK_SORT_ASCENDING);
	    }
	}
    }
    else
    {
	if (prefs_get_int ("tm_sort") == SORT_NONE)
	{  /* no change */
	    sortcol_new = sortcol_old;
	}
	else
	{
	    prefs_set_int ("tm_sort", SORT_NONE);
	}
    }

    /* update compare string keys */
    compare_string_fuzzy_generate_keys ();

    /* if sort type has changed, initialize display */
    if (temp_prefs_get_int_value(sort_temp_prefs, "pm_sort", &val))
    {
	pm_sort (val);
	temp_prefs_remove_key (sort_temp_prefs, "pm_sort");
    }
    if (temp_prefs_get_int_value(sort_temp_prefs, "st_sort", &val))
    {
	st_sort (val);
	temp_prefs_remove_key (sort_temp_prefs, "st_sort");
    }
    if (temp_prefs_get_int_value(sort_temp_prefs, "tm_sort", NULL) ||
	(sortcol_old != sortcol_new))
    {
	tm_sort_counter (-1);
	tm_sort (prefs_get_int("tm_sortcol"), prefs_get_int("tm_sort"));
	temp_prefs_remove_key (sort_temp_prefs, "tm_sort");
    }
    /* if auto sort was changed to TRUE, store order */
    if (!temp_prefs_get_int(sort_temp_prefs, "tm_autostore"))
    {
	tm_rows_reordered ();
	temp_prefs_remove_key (sort_temp_prefs, "tm_autostore");
    }

    sort_window_update ();
}


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

   Callbacks

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

G_MODULE_EXPORT void
on_st_ascend_toggled                   (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_st_sort (SORT_ASCENDING);
}


G_MODULE_EXPORT void
on_st_descend_toggled                  (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_st_sort (SORT_DESCENDING);
}


G_MODULE_EXPORT void
on_st_none_toggled                     (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_st_sort (SORT_NONE);
}


G_MODULE_EXPORT void
on_pm_ascend_toggled                   (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_pm_sort (SORT_ASCENDING);
}


G_MODULE_EXPORT void
on_pm_descend_toggled                  (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_pm_sort (SORT_DESCENDING);
}


G_MODULE_EXPORT void
on_pm_none_toggled                     (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_pm_sort (SORT_NONE);
}


G_MODULE_EXPORT void
on_tm_ascend_toggled                   (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_tm_sort (SORT_ASCENDING);
}


G_MODULE_EXPORT void
on_tm_descend_toggled                  (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_tm_sort (SORT_DESCENDING);
}


G_MODULE_EXPORT void
on_tm_none_toggled                     (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    if (gtk_toggle_button_get_active(togglebutton))
	sort_window_set_tm_sort (SORT_NONE);
}

G_MODULE_EXPORT void
on_tm_autostore_toggled                (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    sort_window_set_tm_autostore (gtk_toggle_button_get_active(togglebutton));
}


G_MODULE_EXPORT void
on_sort_case_sensitive_toggled         (GtkToggleButton *togglebutton,
					gpointer         user_data)
{
    sort_window_set_case_sensitive(
	gtk_toggle_button_get_active(togglebutton));
}


G_MODULE_EXPORT void
on_sort_apply_clicked                  (GtkButton       *button,
					gpointer         user_data)
{
    sort_window_apply ();
}


G_MODULE_EXPORT void
on_sort_cancel_clicked                 (GtkButton       *button,
					gpointer         user_data)
{
    sort_window_cancel ();
}


G_MODULE_EXPORT void
on_sort_ok_clicked                     (GtkButton       *button,
					gpointer         user_data)
{
    sort_window_ok ();
}


G_MODULE_EXPORT gboolean
on_sort_window_delete_event            (GtkWidget       *widget,
					GdkEvent        *event,
					gpointer         user_data)
{
    sort_window_delete ();
    return FALSE;
}



/**
 * sort_window_cancel
 * UI has requested sort prefs changes be ignored -- write back the
 * original values
 */
void sort_window_cancel (void)
{
    /* close the window */
    if(sort_window)
	gtk_widget_destroy(sort_window);
    sort_window = NULL;
}

/* when window is deleted, we keep the currently applied prefs */
void sort_window_delete(void)
{
    temp_prefs_destroy(sort_temp_prefs);
    sort_temp_prefs = NULL;
    temp_lists_destroy(sort_temp_lists);
    sort_temp_lists = NULL;

    /* close the window */
    if(sort_window)
    {
	gint *tm_listed_order;
	tm_listed_order = g_object_get_data (G_OBJECT (sort_window), "tm_listed_order");
	g_warn_if_fail (tm_listed_order);
	g_free (tm_listed_order);
	gtk_widget_destroy(sort_window);
    }
    sort_window = NULL;
}

/* apply the current settings and close the window */
void sort_window_ok (void)
{
    /* update the sort ignore strings */
    sort_window_read_sort_ign ();

    temp_prefs_apply(sort_temp_prefs);
    temp_lists_apply(sort_temp_lists);

    /* save current settings */
    sort_window_set ();
  
    /* close the window */
    if(sort_window)
	gtk_widget_destroy(sort_window);
    sort_window = NULL;
}


/* apply the current settings, don't close the window */
void sort_window_apply (void)
{
    /* update the sort ignore strings */
    sort_window_read_sort_ign ();

    temp_prefs_apply(sort_temp_prefs);
    temp_lists_apply(sort_temp_lists);

    /* save current settings */
    sort_window_set ();
}

void sort_window_set_tm_autostore (gboolean val)
{
    temp_prefs_set_int(sort_temp_prefs, "tm_autostore", val);
}

void sort_window_set_pm_sort (gint val)
{
    temp_prefs_set_int(sort_temp_prefs, "pm_sort", val);
}

void sort_window_set_st_sort (gint val)
{
    temp_prefs_set_int(sort_temp_prefs, "st_sort", val);
}

void sort_window_set_tm_sort (gint val)
{
    temp_prefs_set_int(sort_temp_prefs, "tm_sort", val);
}

void sort_window_set_case_sensitive (gboolean val)
{
    temp_prefs_set_int(sort_temp_prefs, "case_sensitive",
		       val);
}