Elliot Lee 054a422
Elliot Lee 054a422
#include "libxmms/configfile.h"
Elliot Lee 054a422
#include <gtk/gtk.h>
Elliot Lee 054a422
#include "xmms/plugin.h"
Elliot Lee 054a422
#include "xmms/i18n.h"
Elliot Lee 054a422
#include "libxmms/util.h"
Elliot Lee 054a422
Elliot Lee 054a422
static int enabled;
Elliot Lee 054a422
static gpointer foo;
Elliot Lee 054a422
Elliot Lee 054a422
static void init(void)
Elliot Lee 054a422
{
Elliot Lee 054a422
	ConfigFile *cfg;
Elliot Lee 054a422
	
Elliot Lee 054a422
	enabled = 1;
Elliot Lee 054a422
	cfg = xmms_cfg_open_default_file();
Elliot Lee 054a422
        
Elliot Lee 054a422
	xmms_cfg_read_boolean(cfg, "zzmp3", "enabled", &enabled);
Elliot Lee 054a422
	xmms_cfg_free(cfg);
Elliot Lee 054a422
}
Elliot Lee 054a422
Elliot Lee 054a422
static int get_time(void)
Elliot Lee 054a422
{
Elliot Lee 054a422
	return -1;
Elliot Lee 054a422
}
Elliot Lee 054a422
Elliot Lee 054a422
Elliot Lee 054a422
static void clicked_button()
Elliot Lee 054a422
{
Elliot Lee 054a422
	ConfigFile *cfg;
Elliot Lee 054a422
	gchar *filename;
Elliot Lee 054a422
	
Elliot Lee 054a422
	filename = g_strconcat(g_get_home_dir(), "/.xmms/config", NULL);
Elliot Lee 054a422
	cfg = xmms_cfg_open_file(filename);
Elliot Lee 054a422
	if (!cfg)
Elliot Lee 054a422
		cfg = xmms_cfg_new();
Elliot Lee 054a422
	xmms_cfg_write_boolean(cfg, "zzmp3", "enabled", enabled);
Elliot Lee 054a422
	xmms_cfg_write_file(cfg, filename);
Elliot Lee 054a422
	xmms_cfg_free(cfg);
Elliot Lee 054a422
	g_free(filename);
Elliot Lee 054a422
}
Elliot Lee 054a422
Elliot Lee 054a422
static void pref_toggled(void *button)
Elliot Lee 054a422
{
Elliot Lee 054a422
	GtkWidget *check = GTK_WIDGET(button);
Elliot Lee 054a422
	
Elliot Lee 054a422
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check)))
Elliot Lee 054a422
		enabled = 0;
Elliot Lee 054a422
	else
Elliot Lee 054a422
		enabled = 1;
Elliot Lee 054a422
}
Elliot Lee 054a422
Elliot Lee 054a422
static void play_file(char *filename)
Elliot Lee 054a422
{
Elliot Lee 054a422
	GtkWidget *dialog, *vbox, *label, *checkbox, *bbox, *button;
Elliot Lee 054a422
	
Elliot Lee 054a422
	dialog = gtk_dialog_new();
Elliot Lee 054a422
	gtk_window_set_title(GTK_WINDOW(dialog), _("MPEG Layer 1/2/3 Not Supported"));
Elliot Lee 054a422
			     
Elliot Lee 054a422
	vbox = gtk_vbox_new(FALSE, 0);
Elliot Lee 054a422
	gtk_container_set_border_width(GTK_CONTAINER(vbox), 15);
Elliot Lee 054a422
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, TRUE, TRUE, 0);
Elliot Lee 054a422
	
Elliot Lee 054a422
	label = gtk_label_new(_("Due to patent licensing, and conflicts between\n"
Elliot Lee 054a422
				"such patent licenses and the licenses of application\n"
Elliot Lee 054a422
				"source code, MPEG-1/2 audio layer 3 (mp3) support has\n"
Elliot Lee 054a422
				"been removed from this application by Red Hat, Inc.\n\n"
Elliot Lee 054a422
				"We apologize for the inconvenience."));
Elliot Lee 054a422
	gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
Elliot Lee 054a422
	
Elliot Lee 054a422
	checkbox = gtk_check_button_new_with_label (_("Do not show this dialog again"));
Elliot Lee 054a422
	gtk_signal_connect_object(GTK_OBJECT(checkbox), "toggled", GTK_SIGNAL_FUNC(pref_toggled), GTK_OBJECT(checkbox));
Elliot Lee 054a422
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), TRUE);
Elliot Lee 054a422
	gtk_box_pack_start(GTK_BOX(vbox), checkbox, TRUE, TRUE, 0);
Elliot Lee 054a422
	gtk_widget_show(label);
Elliot Lee 054a422
	gtk_widget_show(checkbox);
Elliot Lee 054a422
	gtk_widget_show(vbox);
Elliot Lee 054a422
	
Elliot Lee 054a422
	bbox = gtk_hbutton_box_new();
Elliot Lee 054a422
	gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD);
Elliot Lee 054a422
	gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
Elliot Lee 054a422
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), bbox, FALSE, FALSE, 0);
Elliot Lee 054a422
	
Elliot Lee 054a422
	button = gtk_button_new_with_label(_("Ok"));
Elliot Lee 054a422
	gtk_signal_connect(GTK_OBJECT(button), "clicked", clicked_button, button);
Elliot Lee 054a422
	gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dialog));
Elliot Lee 054a422
	gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
Elliot Lee 054a422
	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
Elliot Lee 054a422
	gtk_widget_grab_default(button);
Elliot Lee 054a422
	gtk_widget_show(button);
Elliot Lee 054a422
	gtk_widget_show(bbox);
Elliot Lee 054a422
	gtk_widget_show(dialog);
Elliot Lee 054a422
	gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
Elliot Lee 054a422
			   GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog);
Elliot Lee 054a422
}
Elliot Lee 054a422
Elliot Lee 054a422
Elliot Lee 054a422
static int is_our_file(char *filename)
Elliot Lee 054a422
{
Elliot Lee 054a422
	char *ext;
Elliot Lee 054a422
	guint16 wavid;
Elliot Lee 054a422
Elliot Lee 054a422
	if (!enabled) return FALSE;
Elliot Lee 054a422
	
Elliot Lee 054a422
	if (!strncasecmp(filename, "http://", 7))
Elliot Lee 054a422
	{			/* We assume all http:// (except those ending in .ogg) are mpeg -- why do we do that? */
Elliot Lee 054a422
		ext = strrchr(filename, '.');
Elliot Lee 054a422
		if (ext) 
Elliot Lee 054a422
		{
Elliot Lee 054a422
			if (!strncasecmp(ext, ".ogg", 4)) 
Elliot Lee 054a422
				return FALSE;
Elliot Lee 054a422
			if (!strncasecmp(ext, ".rm", 3) || 
Elliot Lee 054a422
			    !strncasecmp(ext, ".ra", 3)  ||
Elliot Lee 054a422
			    !strncasecmp(ext, ".rpm", 4)  ||
Elliot Lee 054a422
			    !strncasecmp(ext, ".ram", 4))
Elliot Lee 054a422
				return FALSE;
Elliot Lee 054a422
		}
Elliot Lee 054a422
		return TRUE;
Elliot Lee 054a422
	}
Elliot Lee 054a422
	ext = strrchr(filename, '.');
Elliot Lee 054a422
	if (ext)
Elliot Lee 054a422
	{
Elliot Lee 054a422
		if (!strncasecmp(ext, ".mp2", 4) || !strncasecmp(ext, ".mp3", 4))
Elliot Lee 054a422
		{
Elliot Lee 054a422
			return TRUE;
Elliot Lee 054a422
		}
Elliot Lee 054a422
	}
Elliot Lee 054a422
	return FALSE;
Elliot Lee 054a422
}
Elliot Lee 054a422
Elliot Lee 054a422
static void aboutbox(void) {
Elliot Lee 054a422
	static GtkWidget *aboutbox;
Elliot Lee 054a422
	
Elliot Lee 054a422
	if (aboutbox != NULL)
Elliot Lee 054a422
		return;
Elliot Lee 054a422
	
Elliot Lee 054a422
	aboutbox = xmms_show_message(
Elliot Lee 054a422
				     _("MPEG Layer 1/2/3 Placeholder plugin"),
Elliot Lee 054a422
				     _("Placeholder for MPEG Layer 1/2/3, explaining patent issues\n"
Elliot Lee 054a422
				     "Red Hat, Inc."),
Elliot Lee 054a422
				     _("Ok"), FALSE, NULL, NULL);
Elliot Lee 054a422
	gtk_signal_connect(GTK_OBJECT(aboutbox), "destroy",
Elliot Lee 054a422
			   GTK_SIGNAL_FUNC(gtk_widget_destroyed), &aboutbox);
Elliot Lee 054a422
}
Elliot Lee 054a422
Elliot Lee 054a422
InputPlugin zzmp3_ip =
Elliot Lee 054a422
{
Elliot Lee 054a422
	NULL,
Elliot Lee 054a422
	NULL,
Elliot Lee 054a422
	NULL, /* description */
Elliot Lee 054a422
	init,
Elliot Lee 054a422
	aboutbox,
Elliot Lee 054a422
	NULL, /* configure */
Elliot Lee 054a422
	is_our_file,
Elliot Lee 054a422
	NULL,
Elliot Lee 054a422
        play_file,
Elliot Lee 054a422
        NULL, /* stop */
Elliot Lee 054a422
	NULL, /* pause */
Elliot Lee 054a422
	NULL, /* seek */
Elliot Lee 054a422
	NULL, /* set eq */
Elliot Lee 054a422
        get_time, /* get time */
Elliot Lee 054a422
	NULL, NULL, NULL,
Elliot Lee 054a422
	NULL, NULL, NULL, NULL,
Elliot Lee 054a422
	NULL, /* get_song_info */
Elliot Lee 054a422
	NULL, /* file_info_box */
Elliot Lee 054a422
	NULL
Elliot Lee 054a422
};
Elliot Lee 054a422
Elliot Lee 054a422
InputPlugin *get_iplugin_info(void)
Elliot Lee 054a422
{
Elliot Lee 054a422
	zzmp3_ip.description =
Elliot Lee 054a422
		g_strdup(_("MPEG Layer 1/2/3 Placeholder Plugin"));
Elliot Lee 054a422
	return &zzmp3_ip;
Elliot Lee 054a422
}