comparison src/xmms-sid.c @ 462:1d55247ad0cc

Moved again. :D
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 24 Jan 2007 23:42:05 +0000
parents a1224c1f8670
children 08038c161936
comparison
equal deleted inserted replaced
461:a1224c1f8670 462:1d55247ad0cc
91 91
92 static GtkWidget *xs_subctrl = NULL; 92 static GtkWidget *xs_subctrl = NULL;
93 static GtkObject *xs_subctrl_adj = NULL; 93 static GtkObject *xs_subctrl_adj = NULL;
94 XS_MUTEX(xs_subctrl); 94 XS_MUTEX(xs_subctrl);
95 95
96 static t_xs_stildb *xs_stildb_db = NULL;
97 XS_MUTEX(xs_stildb_db);
98
99 void xs_subctrl_close(void); 96 void xs_subctrl_close(void);
100 void xs_subctrl_update(void); 97 void xs_subctrl_update(void);
101 gint xs_stil_init(void);
102 void xs_stil_close(void);
103 98
104 99
105 /* 100 /*
106 * Error messages 101 * Error messages
107 */ 102 */
1047 g_free(pTune->sidCopyright); 1042 g_free(pTune->sidCopyright);
1048 g_free(pTune->sidFormat); 1043 g_free(pTune->sidFormat);
1049 g_free(pTune); 1044 g_free(pTune);
1050 } 1045 }
1051 1046
1052
1053 /*
1054 * STIL-database handling
1055 */
1056 gint xs_stil_init(void)
1057 {
1058 XS_MUTEX_LOCK(xs_cfg);
1059
1060 if (!xs_cfg.stilDBPath) {
1061 XS_MUTEX_UNLOCK(xs_cfg);
1062 return -1;
1063 }
1064
1065 XS_MUTEX_LOCK(xs_stildb_db);
1066
1067 /* Check if already initialized */
1068 if (xs_stildb_db)
1069 xs_stildb_free(xs_stildb_db);
1070
1071 /* Allocate database */
1072 xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb));
1073 if (!xs_stildb_db) {
1074 XS_MUTEX_UNLOCK(xs_cfg);
1075 XS_MUTEX_UNLOCK(xs_stildb_db);
1076 return -2;
1077 }
1078
1079 /* Read the database */
1080 if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) {
1081 xs_stildb_free(xs_stildb_db);
1082 xs_stildb_db = NULL;
1083 XS_MUTEX_UNLOCK(xs_cfg);
1084 XS_MUTEX_UNLOCK(xs_stildb_db);
1085 return -3;
1086 }
1087
1088 /* Create index */
1089 if (xs_stildb_index(xs_stildb_db) != 0) {
1090 xs_stildb_free(xs_stildb_db);
1091 xs_stildb_db = NULL;
1092 XS_MUTEX_UNLOCK(xs_cfg);
1093 XS_MUTEX_UNLOCK(xs_stildb_db);
1094 return -4;
1095 }
1096
1097 XS_MUTEX_UNLOCK(xs_cfg);
1098 XS_MUTEX_UNLOCK(xs_stildb_db);
1099 return 0;
1100 }
1101
1102
1103 void xs_stil_close(void)
1104 {
1105 XS_MUTEX_LOCK(xs_stildb_db);
1106 xs_stildb_free(xs_stildb_db);
1107 xs_stildb_db = NULL;
1108 XS_MUTEX_UNLOCK(xs_stildb_db);
1109 }
1110
1111
1112 t_xs_stil_node *xs_stil_get(gchar *pcFilename)
1113 {
1114 t_xs_stil_node *pResult;
1115 gchar *tmpFilename;
1116
1117 XS_MUTEX_LOCK(xs_stildb_db);
1118 XS_MUTEX_LOCK(xs_cfg);
1119
1120 if (xs_cfg.stilDBEnable && xs_stildb_db) {
1121 if (xs_cfg.hvscPath) {
1122 /* Remove postfixed directory separator from HVSC-path */
1123 tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/');
1124 if (tmpFilename && (tmpFilename[1] == 0))
1125 tmpFilename[0] = 0;
1126
1127 /* Remove HVSC location-prefix from filename */
1128 tmpFilename = strstr(pcFilename, xs_cfg.hvscPath);
1129 if (tmpFilename)
1130 tmpFilename += strlen(xs_cfg.hvscPath);
1131 else
1132 tmpFilename = pcFilename;
1133 } else
1134 tmpFilename = pcFilename;
1135
1136 XSDEBUG("xs_stil_get('%s') = '%s'\n", pcFilename, tmpFilename);
1137
1138 pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename);
1139 } else
1140 pResult = NULL;
1141
1142 XS_MUTEX_UNLOCK(xs_stildb_db);
1143 XS_MUTEX_UNLOCK(xs_cfg);
1144
1145 return pResult;
1146 }