diff 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
line wrap: on
line diff
--- a/src/xs_fileinfo.c	Tue Dec 21 13:12:04 2004 +0000
+++ b/src/xs_fileinfo.c	Tue Dec 21 13:13:05 2004 +0000
@@ -23,6 +23,7 @@
 #include <gtk/gtk.h>
 
 #include "xmms-sid.h"
+#include "xs_support.h"
 #include "xs_stil.h"
 #include "xs_config.h"
 #include "xs_interface.h"
@@ -30,11 +31,49 @@
 
 static GtkWidget		*xs_fileinfowin = NULL;
 static t_xs_stil_node		*xs_fileinfostil = NULL;
-static t_xs_tuneinfo		*xs_fileinfotune = NULL;
+XS_MUTEX(xs_fileinfowin);
 
 #define LUW(x...)	lookup_widget(xs_fileinfowin, ## x)
 
 
+void xs_fileinfo_update(void)
+{
+ gboolean isEnabled;
+ GtkAdjustment *tmpAdj;
+ 
+ XS_MUTEX_LOCK(xs_status);
+ XS_MUTEX_LOCK(xs_fileinfowin);
+ 
+ /* Check if control window exists, we are currently playing and have a tune */
+ if (xs_fileinfowin)
+	{
+	if (xs_status.tuneInfo && xs_status.isPlaying && (xs_status.tuneInfo->nsubTunes > 1))
+		{
+		tmpAdj = gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")));
+ 	
+ 		tmpAdj->value = xs_status.currSong;
+ 		tmpAdj->lower = 1;
+		tmpAdj->upper = xs_status.tuneInfo->nsubTunes;
+		XS_MUTEX_UNLOCK(xs_status);
+		XS_MUTEX_UNLOCK(xs_fileinfowin);
+ 		gtk_adjustment_value_changed(tmpAdj);
+		XS_MUTEX_LOCK(xs_status);
+		XS_MUTEX_LOCK(xs_fileinfowin); 		
+ 		isEnabled = TRUE;
+ 		} else
+ 		isEnabled = FALSE;
+
+	/* Enable or disable subtune-control in fileinfo window */
+	gtk_widget_set_sensitive(LUW("fileinfo_subctrl_prev"), isEnabled);
+	gtk_widget_set_sensitive(LUW("fileinfo_subctrl_adj"), isEnabled);
+	gtk_widget_set_sensitive(LUW("fileinfo_subctrl_next"), isEnabled); 		
+ 	}
+
+ XS_MUTEX_UNLOCK(xs_status);
+ XS_MUTEX_UNLOCK(xs_fileinfowin);
+}
+
+
 void xs_fileinfo_setsong(void)
 {
 }
@@ -42,8 +81,13 @@
 
 void xs_fileinfo_ok(void)
 {
- gtk_widget_destroy(xs_fileinfowin);
- xs_fileinfowin = NULL;
+ XS_MUTEX_LOCK(xs_fileinfowin);
+ if (xs_fileinfowin)
+ 	{
+ 	gtk_widget_destroy(xs_fileinfowin);
+ 	xs_fileinfowin = NULL;
+ 	}
+ XS_MUTEX_UNLOCK(xs_fileinfowin);
 }
 
 
@@ -96,23 +140,27 @@
 void xs_fileinfo(gchar *pcFilename)
 {
  GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
+ t_xs_tuneinfo *tmpInfo;
  t_xs_stil_subnode *tmpNode;
  gchar tmpStr[32], *tmpS;
  gint n;
 
- /* Free old info, if set */
- if (xs_fileinfotune)
- 	xs_tuneinfo_free(xs_fileinfotune);
- 
+ /* Current implementation leaves old fileinfo window untouched if
+  * no information can be found for the new file. Hmm...
+  */
+
  /* Get new tune information */
- if ((xs_fileinfotune = xs_player->plrGetSIDInfo(pcFilename)) == NULL)
+ XS_MUTEX_LOCK(xs_fileinfowin);
+ XS_MUTEX_LOCK(xs_status);
+ if ((tmpInfo = xs_status.sidPlayer->plrGetSIDInfo(pcFilename)) == NULL)
+ 	{
+ 	XS_MUTEX_UNLOCK(xs_fileinfowin);
+ 	XS_MUTEX_UNLOCK(xs_status);
  	return;
+ 	}
+ XS_MUTEX_UNLOCK(xs_status);
 
- if (xs_cfg.stilDBEnable)
-	xs_fileinfostil = xs_stil_get(pcFilename);
-	else
-	xs_fileinfostil = NULL;
- 
+ xs_fileinfostil = xs_stil_get(pcFilename);
 
  /* Check if there already is an open fileinfo window */
  if (xs_fileinfowin)
@@ -137,9 +185,9 @@
 
  /* Set the generic song information */
  gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), pcFilename);
- gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), xs_fileinfotune->tuneName);
- gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), xs_fileinfotune->tuneComposer);
- gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), xs_fileinfotune->tuneCopyright);
+ gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), tmpInfo->sidName);
+ gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), tmpInfo->sidComposer);
+ gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), tmpInfo->sidCopyright);
 
 
  /* Main tune - the pseudo tune */
@@ -153,7 +201,7 @@
 		GTK_SIGNAL_FUNC (xs_fileinfo_subtune), tmpMenu);
 
  /* Other menu items */
- for (n = 1; n <= xs_fileinfotune->nsubTunes; n++)
+ for (n = 1; n <= tmpInfo->nsubTunes; n++)
 	{
 	if (xs_fileinfostil)
 		{
@@ -181,7 +229,14 @@
  /* Set the subtune information */
  xs_fileinfo_subtune(NULL, tmpMenu);
 
+ /* Free temporary tuneinfo */
+ xs_tuneinfo_free(tmpInfo);
+
  /* Show the window */
  gtk_widget_show(xs_fileinfowin);
+
+ XS_MUTEX_UNLOCK(xs_fileinfowin);
+
+ xs_fileinfo_update();
 }