comparison src/xs_fileinfo.c @ 232:e613873c3379

Thread locking now final. All parts, including GTK GUI, should be(?) properly locked and no race conditions should be present.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Dec 2004 13:13:05 +0000
parents 608f31f6c095
children 6f9764fbd693
comparison
equal deleted inserted replaced
231:9d7274a11fb1 232:e613873c3379
21 */ 21 */
22 #include <gdk/gdkkeysyms.h> 22 #include <gdk/gdkkeysyms.h>
23 #include <gtk/gtk.h> 23 #include <gtk/gtk.h>
24 24
25 #include "xmms-sid.h" 25 #include "xmms-sid.h"
26 #include "xs_support.h"
26 #include "xs_stil.h" 27 #include "xs_stil.h"
27 #include "xs_config.h" 28 #include "xs_config.h"
28 #include "xs_interface.h" 29 #include "xs_interface.h"
29 #include "xs_glade.h" 30 #include "xs_glade.h"
30 31
31 static GtkWidget *xs_fileinfowin = NULL; 32 static GtkWidget *xs_fileinfowin = NULL;
32 static t_xs_stil_node *xs_fileinfostil = NULL; 33 static t_xs_stil_node *xs_fileinfostil = NULL;
33 static t_xs_tuneinfo *xs_fileinfotune = NULL; 34 XS_MUTEX(xs_fileinfowin);
34 35
35 #define LUW(x...) lookup_widget(xs_fileinfowin, ## x) 36 #define LUW(x...) lookup_widget(xs_fileinfowin, ## x)
36 37
37 38
39 void xs_fileinfo_update(void)
40 {
41 gboolean isEnabled;
42 GtkAdjustment *tmpAdj;
43
44 XS_MUTEX_LOCK(xs_status);
45 XS_MUTEX_LOCK(xs_fileinfowin);
46
47 /* Check if control window exists, we are currently playing and have a tune */
48 if (xs_fileinfowin)
49 {
50 if (xs_status.tuneInfo && xs_status.isPlaying && (xs_status.tuneInfo->nsubTunes > 1))
51 {
52 tmpAdj = gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")));
53
54 tmpAdj->value = xs_status.currSong;
55 tmpAdj->lower = 1;
56 tmpAdj->upper = xs_status.tuneInfo->nsubTunes;
57 XS_MUTEX_UNLOCK(xs_status);
58 XS_MUTEX_UNLOCK(xs_fileinfowin);
59 gtk_adjustment_value_changed(tmpAdj);
60 XS_MUTEX_LOCK(xs_status);
61 XS_MUTEX_LOCK(xs_fileinfowin);
62 isEnabled = TRUE;
63 } else
64 isEnabled = FALSE;
65
66 /* Enable or disable subtune-control in fileinfo window */
67 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_prev"), isEnabled);
68 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_adj"), isEnabled);
69 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_next"), isEnabled);
70 }
71
72 XS_MUTEX_UNLOCK(xs_status);
73 XS_MUTEX_UNLOCK(xs_fileinfowin);
74 }
75
76
38 void xs_fileinfo_setsong(void) 77 void xs_fileinfo_setsong(void)
39 { 78 {
40 } 79 }
41 80
42 81
43 void xs_fileinfo_ok(void) 82 void xs_fileinfo_ok(void)
44 { 83 {
45 gtk_widget_destroy(xs_fileinfowin); 84 XS_MUTEX_LOCK(xs_fileinfowin);
46 xs_fileinfowin = NULL; 85 if (xs_fileinfowin)
86 {
87 gtk_widget_destroy(xs_fileinfowin);
88 xs_fileinfowin = NULL;
89 }
90 XS_MUTEX_UNLOCK(xs_fileinfowin);
47 } 91 }
48 92
49 93
50 void xs_fileinfo_subtune(GtkWidget *widget, void *data) 94 void xs_fileinfo_subtune(GtkWidget *widget, void *data)
51 { 95 {
94 138
95 139
96 void xs_fileinfo(gchar *pcFilename) 140 void xs_fileinfo(gchar *pcFilename)
97 { 141 {
98 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu; 142 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
143 t_xs_tuneinfo *tmpInfo;
99 t_xs_stil_subnode *tmpNode; 144 t_xs_stil_subnode *tmpNode;
100 gchar tmpStr[32], *tmpS; 145 gchar tmpStr[32], *tmpS;
101 gint n; 146 gint n;
102 147
103 /* Free old info, if set */ 148 /* Current implementation leaves old fileinfo window untouched if
104 if (xs_fileinfotune) 149 * no information can be found for the new file. Hmm...
105 xs_tuneinfo_free(xs_fileinfotune); 150 */
106 151
107 /* Get new tune information */ 152 /* Get new tune information */
108 if ((xs_fileinfotune = xs_player->plrGetSIDInfo(pcFilename)) == NULL) 153 XS_MUTEX_LOCK(xs_fileinfowin);
154 XS_MUTEX_LOCK(xs_status);
155 if ((tmpInfo = xs_status.sidPlayer->plrGetSIDInfo(pcFilename)) == NULL)
156 {
157 XS_MUTEX_UNLOCK(xs_fileinfowin);
158 XS_MUTEX_UNLOCK(xs_status);
109 return; 159 return;
110 160 }
111 if (xs_cfg.stilDBEnable) 161 XS_MUTEX_UNLOCK(xs_status);
112 xs_fileinfostil = xs_stil_get(pcFilename); 162
113 else 163 xs_fileinfostil = xs_stil_get(pcFilename);
114 xs_fileinfostil = NULL;
115
116 164
117 /* Check if there already is an open fileinfo window */ 165 /* Check if there already is an open fileinfo window */
118 if (xs_fileinfowin) 166 if (xs_fileinfowin)
119 { 167 {
120 /* Raise old window */ 168 /* Raise old window */
135 } 183 }
136 184
137 185
138 /* Set the generic song information */ 186 /* Set the generic song information */
139 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), pcFilename); 187 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), pcFilename);
140 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), xs_fileinfotune->tuneName); 188 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), tmpInfo->sidName);
141 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), xs_fileinfotune->tuneComposer); 189 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), tmpInfo->sidComposer);
142 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), xs_fileinfotune->tuneCopyright); 190 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), tmpInfo->sidCopyright);
143 191
144 192
145 /* Main tune - the pseudo tune */ 193 /* Main tune - the pseudo tune */
146 tmpOptionMenu = LUW("fileinfo_sub_tune"); 194 tmpOptionMenu = LUW("fileinfo_sub_tune");
147 tmpMenu = GTK_OPTION_MENU(tmpOptionMenu)->menu; 195 tmpMenu = GTK_OPTION_MENU(tmpOptionMenu)->menu;
151 gtk_menu_append (GTK_MENU(tmpMenu), tmpMenuItem); 199 gtk_menu_append (GTK_MENU(tmpMenu), tmpMenuItem);
152 gtk_signal_connect (GTK_OBJECT (tmpMenuItem), "activate", 200 gtk_signal_connect (GTK_OBJECT (tmpMenuItem), "activate",
153 GTK_SIGNAL_FUNC (xs_fileinfo_subtune), tmpMenu); 201 GTK_SIGNAL_FUNC (xs_fileinfo_subtune), tmpMenu);
154 202
155 /* Other menu items */ 203 /* Other menu items */
156 for (n = 1; n <= xs_fileinfotune->nsubTunes; n++) 204 for (n = 1; n <= tmpInfo->nsubTunes; n++)
157 { 205 {
158 if (xs_fileinfostil) 206 if (xs_fileinfostil)
159 { 207 {
160 tmpNode = &xs_fileinfostil->subTune[n]; 208 tmpNode = &xs_fileinfostil->subTune[n];
161 if (tmpNode->pName) 209 if (tmpNode->pName)
179 } 227 }
180 228
181 /* Set the subtune information */ 229 /* Set the subtune information */
182 xs_fileinfo_subtune(NULL, tmpMenu); 230 xs_fileinfo_subtune(NULL, tmpMenu);
183 231
232 /* Free temporary tuneinfo */
233 xs_tuneinfo_free(tmpInfo);
234
184 /* Show the window */ 235 /* Show the window */
185 gtk_widget_show(xs_fileinfowin); 236 gtk_widget_show(xs_fileinfowin);
186 } 237
187 238 XS_MUTEX_UNLOCK(xs_fileinfowin);
239
240 xs_fileinfo_update();
241 }
242