view src/xs_fileinfo.c @ 230:608f31f6c095

Raw cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Dec 2004 09:25:03 +0000
parents dcf88b73e4c1
children e613873c3379
line wrap: on
line source

/*
   XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)

   File information window

   Written by Matti "ccr" Hamalainen <ccr@tnsp.org>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "xmms-sid.h"
#include "xs_stil.h"
#include "xs_config.h"
#include "xs_interface.h"
#include "xs_glade.h"

static GtkWidget		*xs_fileinfowin = NULL;
static t_xs_stil_node		*xs_fileinfostil = NULL;
static t_xs_tuneinfo		*xs_fileinfotune = NULL;

#define LUW(x...)	lookup_widget(xs_fileinfowin, ## x)


void xs_fileinfo_setsong(void)
{
}


void xs_fileinfo_ok(void)
{
 gtk_widget_destroy(xs_fileinfowin);
 xs_fileinfowin = NULL;
}


void xs_fileinfo_subtune(GtkWidget *widget, void *data)
{
 t_xs_stil_subnode *tmpNode;
 GtkWidget *tmpItem, *tmpText;
 gint tmpIndex;
 gchar *subName, *subAuthor;

 /* Freeze text-widget and delete the old text */
 tmpText = LUW("fileinfo_sub_info");
 gtk_text_freeze(GTK_TEXT(tmpText));
 gtk_text_set_point(GTK_TEXT(tmpText), 0);
 gtk_text_forward_delete(GTK_TEXT(tmpText),
 gtk_text_get_length(GTK_TEXT(tmpText)));

 if (xs_fileinfostil)
 	{
	/* Get subtune number */
	tmpItem  = gtk_menu_get_active(GTK_MENU(data));
	tmpIndex = g_list_index(GTK_MENU_SHELL(data)->children, tmpItem);

	/* Get subtune information */
	tmpNode = &xs_fileinfostil->subTune[tmpIndex];
	subName = tmpNode->pName;
	subAuthor = tmpNode->pAuthor;

	/* Put in the new text, if available */
	if (tmpNode->pInfo)
		{
		gtk_text_insert (GTK_TEXT (tmpText), NULL, NULL, NULL,
		tmpNode->pInfo, strlen(tmpNode->pInfo));
		}
	} else {
	/* We don't have any information */
	subName = NULL;
	subAuthor = NULL;
	}

 /* Get and set subtune information */
 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_name")), subName ? subName : "");
 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_author")), subAuthor ? subAuthor : "");

 /* Un-freeze the widget */
 gtk_text_thaw(GTK_TEXT(tmpText));
}


void xs_fileinfo(gchar *pcFilename)
{
 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
 t_xs_stil_subnode *tmpNode;
 gchar tmpStr[32], *tmpS;
 gint n;

 /* Free old info, if set */
 if (xs_fileinfotune)
 	xs_tuneinfo_free(xs_fileinfotune);
 
 /* Get new tune information */
 if ((xs_fileinfotune = xs_player->plrGetSIDInfo(pcFilename)) == NULL)
 	return;

 if (xs_cfg.stilDBEnable)
	xs_fileinfostil = xs_stil_get(pcFilename);
	else
	xs_fileinfostil = NULL;
 

 /* Check if there already is an open fileinfo window */
 if (xs_fileinfowin)
	{
	/* Raise old window */
	gdk_window_raise(xs_fileinfowin->window);

	/* Delete items */
	tmpOptionMenu = LUW("fileinfo_sub_tune");
	gtk_widget_destroy(GTK_OPTION_MENU(tmpOptionMenu)->menu);
	GTK_OPTION_MENU(tmpOptionMenu)->menu = gtk_menu_new();	
	} else {
	/* If not, create a new one */
	xs_fileinfowin = create_xs_fileinfowin();
	
	/* Connect additional signals */
	gtk_signal_connect(GTK_OBJECT(
		gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")))),
		"value_changed", GTK_SIGNAL_FUNC (xs_fileinfo_setsong), NULL);
	}


 /* 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);


 /* Main tune - the pseudo tune */
 tmpOptionMenu = LUW("fileinfo_sub_tune");
 tmpMenu = GTK_OPTION_MENU(tmpOptionMenu)->menu;

 tmpMenuItem = gtk_menu_item_new_with_label ("General info");
 gtk_widget_show (tmpMenuItem);
 gtk_menu_append (GTK_MENU(tmpMenu), tmpMenuItem);
 gtk_signal_connect (GTK_OBJECT (tmpMenuItem), "activate",
		GTK_SIGNAL_FUNC (xs_fileinfo_subtune), tmpMenu);

 /* Other menu items */
 for (n = 1; n <= xs_fileinfotune->nsubTunes; n++)
	{
	if (xs_fileinfostil)
		{
		tmpNode = &xs_fileinfostil->subTune[n];
		if (tmpNode->pName)
			tmpS = tmpNode->pName;
			else
		if (tmpNode->pInfo)
			tmpS = tmpNode->pInfo;
			else
			tmpS = "---";

		snprintf(tmpStr, sizeof(tmpStr), "Tune #%i: %s", n, tmpS);
		} else
		snprintf(tmpStr, sizeof(tmpStr), "Tune #%i", n);

	tmpMenuItem = gtk_menu_item_new_with_label(tmpStr);
	gtk_widget_show (tmpMenuItem);
	gtk_menu_append (GTK_MENU(tmpMenu), tmpMenuItem);

	gtk_signal_connect (GTK_OBJECT(tmpMenuItem), "activate",
			GTK_SIGNAL_FUNC(xs_fileinfo_subtune), tmpMenu);
	}

 /* Set the subtune information */
 xs_fileinfo_subtune(NULL, tmpMenu);

 /* Show the window */
 gtk_widget_show(xs_fileinfowin);
}