comparison src/sid/xs_fileinfo.c @ 1574:e566e18e9e3d

Huge cleanup and some bugfixes. Temporarily breaks / removes sub-tune changing.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Sep 2007 06:28:17 +0300
parents 88878ed02ca0
children 8581eb9d574a
comparison
equal deleted inserted replaced
1573:82548d92c922 1574:e566e18e9e3d
24 #include <gtk/gtk.h> 24 #include <gtk/gtk.h>
25 25
26 #include "xs_fileinfo.h" 26 #include "xs_fileinfo.h"
27 #include "xs_player.h" 27 #include "xs_player.h"
28 #include "xs_support.h" 28 #include "xs_support.h"
29 #include "xs_stil.h"
30 #include "xs_config.h" 29 #include "xs_config.h"
31 #include "xs_interface.h" 30 #include "xs_interface.h"
32 #include "xs_glade.h" 31 #include "xs_glade.h"
33 32 #include "xs_slsup.h"
34 33
35 static t_xs_stildb *xs_stildb_db = NULL;
36 XS_MUTEX(xs_stildb_db);
37 34
38 static GtkWidget *xs_fileinfowin = NULL; 35 static GtkWidget *xs_fileinfowin = NULL;
39 static t_xs_stil_node *xs_fileinfostil = NULL; 36 static t_xs_stil_node *xs_fileinfostil = NULL;
40 XS_MUTEX(xs_fileinfowin); 37 XS_MUTEX(xs_fileinfowin);
41 38
42 #define LUW(x) lookup_widget(xs_fileinfowin, x) 39 #define LUW(x) lookup_widget(xs_fileinfowin, x)
43 40
44 41
45 /* STIL-database handling 42 #ifndef AUDACIOUS_PLUGIN
46 */
47 gint xs_stil_init(void)
48 {
49 XS_MUTEX_LOCK(xs_cfg);
50
51 if (!xs_cfg.stilDBPath) {
52 XS_MUTEX_UNLOCK(xs_cfg);
53 return -1;
54 }
55
56 XS_MUTEX_LOCK(xs_stildb_db);
57
58 /* Check if already initialized */
59 if (xs_stildb_db)
60 xs_stildb_free(xs_stildb_db);
61
62 /* Allocate database */
63 xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb));
64 if (!xs_stildb_db) {
65 XS_MUTEX_UNLOCK(xs_cfg);
66 XS_MUTEX_UNLOCK(xs_stildb_db);
67 return -2;
68 }
69
70 /* Read the database */
71 if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) {
72 xs_stildb_free(xs_stildb_db);
73 xs_stildb_db = NULL;
74 XS_MUTEX_UNLOCK(xs_cfg);
75 XS_MUTEX_UNLOCK(xs_stildb_db);
76 return -3;
77 }
78
79 /* Create index */
80 if (xs_stildb_index(xs_stildb_db) != 0) {
81 xs_stildb_free(xs_stildb_db);
82 xs_stildb_db = NULL;
83 XS_MUTEX_UNLOCK(xs_cfg);
84 XS_MUTEX_UNLOCK(xs_stildb_db);
85 return -4;
86 }
87
88 XS_MUTEX_UNLOCK(xs_cfg);
89 XS_MUTEX_UNLOCK(xs_stildb_db);
90 return 0;
91 }
92
93
94 void xs_stil_close(void)
95 {
96 XS_MUTEX_LOCK(xs_stildb_db);
97 xs_stildb_free(xs_stildb_db);
98 xs_stildb_db = NULL;
99 XS_MUTEX_UNLOCK(xs_stildb_db);
100 }
101
102
103 t_xs_stil_node *xs_stil_get(gchar *pcFilename)
104 {
105 t_xs_stil_node *pResult;
106 gchar *tmpFilename;
107
108 XS_MUTEX_LOCK(xs_stildb_db);
109 XS_MUTEX_LOCK(xs_cfg);
110
111 if (xs_cfg.stilDBEnable && xs_stildb_db) {
112 if (xs_cfg.hvscPath) {
113 /* Remove postfixed directory separator from HVSC-path */
114 tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/');
115 if (tmpFilename && (tmpFilename[1] == 0))
116 tmpFilename[0] = 0;
117
118 /* Remove HVSC location-prefix from filename */
119 tmpFilename = strstr(pcFilename, xs_cfg.hvscPath);
120 if (tmpFilename)
121 tmpFilename += strlen(xs_cfg.hvscPath);
122 else
123 tmpFilename = pcFilename;
124 } else
125 tmpFilename = pcFilename;
126
127 XSDEBUG("xs_stil_get('%s') = '%s'\n", pcFilename, tmpFilename);
128
129 pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename);
130 } else
131 pResult = NULL;
132
133 XS_MUTEX_UNLOCK(xs_stildb_db);
134 XS_MUTEX_UNLOCK(xs_cfg);
135
136 return pResult;
137 }
138
139
140 void xs_fileinfo_update(void) 43 void xs_fileinfo_update(void)
141 { 44 {
142 XS_MUTEX_LOCK(xs_status); 45 XS_MUTEX_LOCK(xs_status);
143 XS_MUTEX_LOCK(xs_fileinfowin); 46 XS_MUTEX_LOCK(xs_fileinfowin);
144 47
187 } 90 }
188 91
189 XS_MUTEX_UNLOCK(xs_fileinfowin); 92 XS_MUTEX_UNLOCK(xs_fileinfowin);
190 XS_MUTEX_UNLOCK(xs_status); 93 XS_MUTEX_UNLOCK(xs_status);
191 } 94 }
95 #endif /* AUDACIOUS_PLUGIN */
192 96
193 97
194 void xs_fileinfo_ok(void) 98 void xs_fileinfo_ok(void)
195 { 99 {
196 XS_MUTEX_LOCK(xs_fileinfowin); 100 XS_MUTEX_LOCK(xs_fileinfowin);
224 (void) widget; 128 (void) widget;
225 (void) data; 129 (void) data;
226 130
227 /* Freeze text-widget and delete the old text */ 131 /* Freeze text-widget and delete the old text */
228 tmpText = LUW("fileinfo_sub_info"); 132 tmpText = LUW("fileinfo_sub_info");
133 #ifndef AUDACIOUS_PLUGIN
134 gtk_text_freeze(GTK_TEXT(tmpText));
135 gtk_text_set_point(GTK_TEXT(tmpText), 0);
136 gtk_text_forward_delete(GTK_TEXT(tmpText), gtk_text_get_length(GTK_TEXT(tmpText)));
137 #endif
229 138
230 /* Get subtune information */ 139 /* Get subtune information */
231 tmpIndex = g_list_index(GTK_MENU_SHELL(data)->children, gtk_menu_get_active(GTK_MENU(data))); 140 tmpIndex = g_list_index(GTK_MENU_SHELL(data)->children, gtk_menu_get_active(GTK_MENU(data)));
232 141
233 if (xs_fileinfostil && tmpIndex <= xs_fileinfostil->nsubTunes) 142 if (xs_fileinfostil && tmpIndex <= xs_fileinfostil->nsubTunes)
246 } 155 }
247 156
248 /* Get and set subtune information */ 157 /* Get and set subtune information */
249 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_name")), subName ? subName : ""); 158 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_name")), subName ? subName : "");
250 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_author")), subAuthor ? subAuthor : ""); 159 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_author")), subAuthor ? subAuthor : "");
160
161 #ifdef AUDACIOUS_PLUGIN
251 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(tmpText))), 162 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(tmpText))),
252 subInfo ? subInfo : "", -1); 163 subInfo ? subInfo : "", -1);
164 #else
165 gtk_text_insert(GTK_TEXT(tmpText), NULL, NULL, NULL,
166 subInfo ? subInfo : "", -1);
167
168 /* Un-freeze the widget */
169 gtk_text_thaw(GTK_TEXT(tmpText));
170 #endif
253 } 171 }
254 172
255 173
256 void xs_fileinfo(gchar * pcFilename) 174 void xs_fileinfo(gchar * pcFilename)
257 { 175 {
258 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu; 176 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
259 t_xs_tuneinfo *tmpInfo; 177 t_xs_tuneinfo *tmpInfo;
260 gchar tmpStr[256], *tmpStr2; 178 gchar tmpStr[256], *tmpFilename;
261 gint n; 179 gint n;
262 180
263 /* Current implementation leaves old fileinfo window untouched if 181 /* Current implementation leaves old fileinfo window untouched if
264 * no information can be found for the new file. Hmm... 182 * no information can be found for the new file. Hmm...
265 */ 183 */
279 /* Check if there already is an open fileinfo window */ 197 /* Check if there already is an open fileinfo window */
280 if (xs_fileinfowin) 198 if (xs_fileinfowin)
281 gdk_window_raise(xs_fileinfowin->window); 199 gdk_window_raise(xs_fileinfowin->window);
282 else { 200 else {
283 xs_fileinfowin = create_xs_fileinfowin(); 201 xs_fileinfowin = create_xs_fileinfowin();
284 g_signal_connect(G_OBJECT( 202 #ifndef AUDACIOUS_PLUGIN
285 gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")))), "value_changed", 203 XS_SIGNAL_CONNECT(gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj"))),
286 G_CALLBACK(xs_fileinfo_setsong), NULL); 204 "value_changed", xs_fileinfo_setsong, NULL);
205 #endif
287 } 206 }
288 207
289 /* Delete current items */ 208 /* Delete current items */
290 tmpOptionMenu = LUW("fileinfo_sub_tune"); 209 tmpOptionMenu = LUW("fileinfo_sub_tune");
291 tmpMenu = gtk_option_menu_get_menu(GTK_OPTION_MENU(tmpOptionMenu)); 210 tmpMenu = gtk_option_menu_get_menu(GTK_OPTION_MENU(tmpOptionMenu));
293 gtk_option_menu_remove_menu(GTK_OPTION_MENU(tmpOptionMenu)); 212 gtk_option_menu_remove_menu(GTK_OPTION_MENU(tmpOptionMenu));
294 tmpMenu = gtk_menu_new(); 213 tmpMenu = gtk_menu_new();
295 214
296 215
297 /* Set the generic song information */ 216 /* Set the generic song information */
298 tmpStr2 = g_filename_to_utf8(pcFilename, -1, NULL, NULL, NULL); 217 tmpFilename = XS_CS_FILENAME(pcFilename);
299 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), tmpStr2); 218 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), tmpFilename);
300 g_free(tmpStr2); 219 g_free(tmpFilename);
301
302 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), tmpInfo->sidName); 220 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), tmpInfo->sidName);
303 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), tmpInfo->sidComposer); 221 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), tmpInfo->sidComposer);
304 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), tmpInfo->sidCopyright); 222 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), tmpInfo->sidCopyright);
305 223
306 224
307 /* Main tune - the pseudo tune */ 225 /* Main tune - the pseudo tune */
308 tmpMenuItem = gtk_menu_item_new_with_label(_("General info")); 226 tmpMenuItem = gtk_menu_item_new_with_label(_("General info"));
309 gtk_widget_show(tmpMenuItem); 227 gtk_widget_show(tmpMenuItem);
310 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem); 228 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem);
311 g_signal_connect(G_OBJECT(tmpMenuItem), "activate", 229 XS_SIGNAL_CONNECT(tmpMenuItem, "activate", xs_fileinfo_subtune, tmpMenu);
312 G_CALLBACK(xs_fileinfo_subtune), tmpMenu);
313 230
314 /* Other menu items */ 231 /* Other menu items */
315 for (n = 1; n <= tmpInfo->nsubTunes; n++) { 232 for (n = 1; n <= tmpInfo->nsubTunes; n++) {
316 if (xs_fileinfostil && n <= xs_fileinfostil->nsubTunes && xs_fileinfostil->subTunes[n]) { 233 if (xs_fileinfostil && n <= xs_fileinfostil->nsubTunes && xs_fileinfostil->subTunes[n]) {
317 t_xs_stil_subnode *tmpNode = xs_fileinfostil->subTunes[n]; 234 t_xs_stil_subnode *tmpNode = xs_fileinfostil->subTunes[n];
331 } 248 }
332 249
333 tmpMenuItem = gtk_menu_item_new_with_label(tmpStr); 250 tmpMenuItem = gtk_menu_item_new_with_label(tmpStr);
334 gtk_widget_show(tmpMenuItem); 251 gtk_widget_show(tmpMenuItem);
335 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem); 252 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem);
336 g_signal_connect(G_OBJECT(tmpMenuItem), "activate", 253 XS_SIGNAL_CONNECT(tmpMenuItem, "activate", xs_fileinfo_subtune, tmpMenu);
337 G_CALLBACK(xs_fileinfo_subtune), tmpMenu);
338 } 254 }
339 255
340 gtk_option_menu_set_menu(GTK_OPTION_MENU(tmpOptionMenu), tmpMenu); 256 gtk_option_menu_set_menu(GTK_OPTION_MENU(tmpOptionMenu), tmpMenu);
341 gtk_widget_show(tmpOptionMenu); 257 gtk_widget_show(tmpOptionMenu);
342 258
349 /* Show the window */ 265 /* Show the window */
350 gtk_widget_show(xs_fileinfowin); 266 gtk_widget_show(xs_fileinfowin);
351 267
352 XS_MUTEX_UNLOCK(xs_fileinfowin); 268 XS_MUTEX_UNLOCK(xs_fileinfowin);
353 269
270 #ifndef AUDACIOUS_PLUGIN
354 xs_fileinfo_update(); 271 xs_fileinfo_update();
355 } 272 #endif
273 }