comparison src/xs_config.c @ 592:7ae251af5f83

Some macro magic for simplifying the repetitive code.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 22 Mar 2007 17:26:04 +0000
parents 7d94e9e5dfb7
children 91ca76e6c23f
comparison
equal deleted inserted replaced
591:acda6c2f10c8 592:7ae251af5f83
70 *xs_filt_importselector = NULL, 70 *xs_filt_importselector = NULL,
71 *xs_filt_exportselector = NULL; 71 *xs_filt_exportselector = NULL;
72 72
73 #define LUW(x) lookup_widget(xs_configwin, x) 73 #define LUW(x) lookup_widget(xs_configwin, x)
74 74
75 #define XS_DEF_WINDOW_DELETE(ME, MV) \ 75 #define XS_DEF_WINDOW_DELETE(ME, MV) \
76 gboolean xs_ ## ME ## _delete(GtkWidget * w, GdkEvent * e, gpointer d) { \ 76 gboolean xs_ ## ME ## _delete(GtkWidget * w, GdkEvent * e, gpointer d) { \
77 (void) w; (void) e; (void) d; \ 77 (void) w; (void) e; (void) d; \
78 if (xs_ ## MV ) { gtk_widget_destroy(xs_ ## MV ); xs_ ## MV = NULL; } \ 78 if (xs_ ## MV ) { gtk_widget_destroy(xs_ ## MV ); xs_ ## MV = NULL; } \
79 return FALSE; \ 79 return FALSE; \
80 } 80 }
81 81
82 #define XS_DEF_WINDOW_CANCEL(ME, MV) \
83 void xs_ ## ME ## _cancel(GtkButton *b, gpointer d) { \
84 (void) b; (void) d; \
85 gtk_widget_destroy(xs_ ## MV ); \
86 xs_ ## MV = NULL; \
87 }
82 88
83 89
84 /* 90 /*
85 * Configuration specific stuff 91 * Configuration specific stuff
86 */ 92 */
318 g_snprintf(tmpKey, sizeof(tmpKey), "filter%dPoints", nFilter); 324 g_snprintf(tmpKey, sizeof(tmpKey), "filter%dPoints", nFilter);
319 if (!XS_CFG_GET_STRING(cfg, XS_CONFIG_IDENT, tmpKey, &tmpStr)) 325 if (!XS_CFG_GET_STRING(cfg, XS_CONFIG_IDENT, tmpKey, &tmpStr))
320 return FALSE; 326 return FALSE;
321 327
322 for (i = 0, j = 0; i < pResult->npoints; i++, j += XS_FITEM) { 328 for (i = 0, j = 0; i < pResult->npoints; i++, j += XS_FITEM) {
323 sscanf(&tmpStr[j], "%4x%4x", 329 if (sscanf(&tmpStr[j], "%4x%4x",
324 &(pResult->points[i].x), 330 &(pResult->points[i].x),
325 &(pResult->points[i].y)); 331 &(pResult->points[i].y)) != 2)
332 return FALSE;
326 } 333 }
327 334
328 return TRUE; 335 return TRUE;
329 } 336 }
330 337
384 { 391 {
385 FILE *inFile; 392 FILE *inFile;
386 gchar inLine[XS_BUF_SIZE]; 393 gchar inLine[XS_BUF_SIZE];
387 size_t lineNum; 394 size_t lineNum;
388 t_xs_sid2_filter *f; 395 t_xs_sid2_filter *f;
389 396 fprintf(stderr, "xs_filters_import(%s)\n", pcFilename);
390 if ((inFile = fopen(pcFilename, "ra")) == NULL) 397 if ((inFile = fopen(pcFilename, "ra")) == NULL)
391 return FALSE; 398 return FALSE;
399 fprintf(stderr, "importing...\n");
392 400
393 lineNum = 0; 401 lineNum = 0;
394 while (fgets(inLine, XS_BUF_SIZE, inFile) != NULL) { 402 while (fgets(inLine, XS_BUF_SIZE, inFile) != NULL) {
395 size_t linePos = 0; 403 size_t linePos = 0;
396 lineNum++; 404 lineNum++;
569 } 577 }
570 578
571 579
572 /* Configuration panel was canceled 580 /* Configuration panel was canceled
573 */ 581 */
574 void xs_cfg_cancel(void) 582 XS_DEF_WINDOW_CANCEL(cfg, configwin)
575 {
576 gtk_widget_destroy(xs_configwin);
577 xs_configwin = NULL;
578 }
579 583
580 584
581 /* Configuration was accepted, save the settings 585 /* Configuration was accepted, save the settings
582 */ 586 */
583 void xs_cfg_ok(void) 587 void xs_cfg_ok(void)
701 /* Close file selector window */ 705 /* Close file selector window */
702 gtk_widget_destroy(xs_sldb_fileselector); 706 gtk_widget_destroy(xs_sldb_fileselector);
703 xs_sldb_fileselector = NULL; 707 xs_sldb_fileselector = NULL;
704 } 708 }
705 709
706 710 XS_DEF_WINDOW_CANCEL(sldb_fs, sldb_fileselector)
707 void xs_sldb_fs_cancel(GtkButton *button, gpointer user_data)
708 {
709 (void) button;
710 (void) user_data;
711
712 /* Close file selector window */
713 gtk_widget_destroy(xs_sldb_fileselector);
714 xs_sldb_fileselector = NULL;
715 }
716
717
718 XS_DEF_WINDOW_DELETE(sldb_fs, sldb_fileselector) 711 XS_DEF_WINDOW_DELETE(sldb_fs, sldb_fileselector)
719 712
720 713
721 /* STIL-database file selector response-functions 714 /* STIL-database file selector response-functions
722 */ 715 */
751 gtk_widget_destroy(xs_stil_fileselector); 744 gtk_widget_destroy(xs_stil_fileselector);
752 xs_stil_fileselector = NULL; 745 xs_stil_fileselector = NULL;
753 } 746 }
754 747
755 748
756 void xs_stil_fs_cancel(GtkButton *button, gpointer user_data) 749 XS_DEF_WINDOW_CANCEL(stil_fs, stil_fileselector)
757 {
758 (void) button;
759 (void) user_data;
760
761 /* Close file selector window */
762 gtk_widget_destroy(xs_stil_fileselector);
763 xs_stil_fileselector = NULL;
764 }
765
766
767 XS_DEF_WINDOW_DELETE(stil_fs, stil_fileselector) 750 XS_DEF_WINDOW_DELETE(stil_fs, stil_fileselector)
768 751
769 752
770 /* HVSC location selector response-functions 753 /* HVSC location selector response-functions
771 */ 754 */
800 gtk_widget_destroy(xs_hvsc_selector); 783 gtk_widget_destroy(xs_hvsc_selector);
801 xs_hvsc_selector = NULL; 784 xs_hvsc_selector = NULL;
802 } 785 }
803 786
804 787
805 void xs_hvsc_fs_cancel(GtkButton *button, gpointer user_data) 788 XS_DEF_WINDOW_CANCEL(hvsc_fs, hvsc_selector)
806 {
807 (void) button;
808 (void) user_data;
809
810 /* Close file selector window */
811 gtk_widget_destroy(xs_hvsc_selector);
812 xs_hvsc_selector = NULL;
813 }
814
815
816 XS_DEF_WINDOW_DELETE(hvsc_fs, hvsc_selector) 789 XS_DEF_WINDOW_DELETE(hvsc_fs, hvsc_selector)
817 790
818 791
819 /* Filter handling 792 /* Filter handling
820 */ 793 */
838 xs_curve_set_range(curve, 0,0, XS_SIDPLAY2_NFPOINTS, XS_SIDPLAY2_FMAX); 811 xs_curve_set_range(curve, 0,0, XS_SIDPLAY2_NFPOINTS, XS_SIDPLAY2_FMAX);
839 xs_curve_set_points(curve, f->points, f->npoints); 812 xs_curve_set_points(curve, f->points, f->npoints);
840 } 813 }
841 814
842 815
843 void xs_cfg_sp2_presets_update() 816 void xs_cfg_sp2_presets_update(void)
844 { 817 {
818 /*
819 update the drowdown list of preset names from current filter presets list
820 */
845 } 821 }
846 822
847 823
848 void xs_cfg_sp2_filter_load(GtkButton *button, gpointer user_data) 824 void xs_cfg_sp2_filter_load(GtkButton *button, gpointer user_data)
849 { 825 {
940 } 916 }
941 917
942 918
943 void xs_filter_import_fs_ok(GtkButton *button, gpointer user_data) 919 void xs_filter_import_fs_ok(GtkButton *button, gpointer user_data)
944 { 920 {
945 (void) button; 921 gchar *tmpStr;
946 (void) user_data; 922 (void) button;
923 (void) user_data;
924
925 XS_MUTEX_LOCK(xs_cfg);
926
927 /* Selection was accepted! */
928 tmpStr = gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_filt_importselector));
929 fprintf(stderr, "paf: %s\n", tmpStr);
930 xs_filters_import(tmpStr, xs_cfg.sid2FilterPresets, &xs_cfg.sid2NFilterPresets);
947 931
948 xs_cfg_sp2_presets_update(); 932 xs_cfg_sp2_presets_update();
949 933
950 /* Close file selector window */ 934 /* Close file selector window */
951 gtk_widget_destroy(xs_filt_importselector); 935 gtk_widget_destroy(xs_filt_importselector);
952 xs_filt_importselector = NULL; 936 xs_filt_importselector = NULL;
953 } 937 XS_MUTEX_UNLOCK(xs_cfg);
954 938 }
955 939
956 void xs_filter_import_fs_cancel(GtkButton *button, gpointer user_data) 940
957 { 941 XS_DEF_WINDOW_CANCEL(filter_import_fs, filt_importselector)
958 (void) button;
959 (void) user_data;
960
961 /* Close file selector window */
962 gtk_widget_destroy(xs_filt_importselector);
963 xs_filt_importselector = NULL;
964 }
965
966
967 XS_DEF_WINDOW_DELETE(filter_import_fs, filt_importselector) 942 XS_DEF_WINDOW_DELETE(filter_import_fs, filt_importselector)
968 943
969 944
970 void xs_cfg_sp2_filter_export(GtkButton *button, gpointer user_data) 945 void xs_cfg_sp2_filter_export(GtkButton *button, gpointer user_data)
971 { 946 {
982 } 957 }
983 958
984 959
985 void xs_filter_export_fs_ok(GtkButton *button, gpointer user_data) 960 void xs_filter_export_fs_ok(GtkButton *button, gpointer user_data)
986 { 961 {
987 (void) button; 962 gchar *tmpStr;
988 (void) user_data; 963 (void) button;
964 (void) user_data;
965
966 XS_MUTEX_LOCK(xs_cfg);
967
968 /* Selection was accepted! */
969 tmpStr = gtk_file_selection_get_filename(GTK_FILE_SELECTION(xs_filt_exportselector));
970 fprintf(stderr, "paf: %s\n", tmpStr);
971 // xs_filters_export(tmpStr, xs_cfg.sid2FilterPresets, &xs_cfg.sid2NFilterPresets);
989 972
990 /* Close file selector window */ 973 /* Close file selector window */
991 gtk_widget_destroy(xs_filt_exportselector); 974 gtk_widget_destroy(xs_filt_exportselector);
992 xs_filt_exportselector = NULL; 975 xs_filt_exportselector = NULL;
993 } 976 XS_MUTEX_UNLOCK(xs_cfg);
994 977 }
995 978
996 void xs_filter_export_fs_cancel(GtkButton *button, gpointer user_data) 979
997 { 980 XS_DEF_WINDOW_CANCEL(filter_export_fs, filt_exportselector)
998 (void) button;
999 (void) user_data;
1000
1001 /* Close file selector window */
1002 gtk_widget_destroy(xs_filt_exportselector);
1003 xs_filt_exportselector = NULL;
1004 }
1005
1006
1007 XS_DEF_WINDOW_DELETE(filter_export_fs, filt_exportselector) 981 XS_DEF_WINDOW_DELETE(filter_export_fs, filt_exportselector)
1008 982
1009 983
1010 /* Selection toggle handlers 984 /* Selection toggle handlers
1011 */ 985 */