/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018, 2019, 2020, 2021 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     https://threadsafebooks.com/
#+
#+ 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
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	April 18, 2021

#include "includes.h"
#include "common-externs.h"

#define SLASH '/'

//-------------------------------------------
//      Play file common code interface
//-------------------------------------------

void    PlayClip (GtkButton *button, GtkEntry *user_data, int Row) {

	gchar * text1 ;
	char mesg[512];
	char cmd[1024];
	char lcl[1024];
	char tmp[1024];
	int dirFlg = 0, i, j, k = -1;

	if (SP->Pause) {
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pauseAtEnd), FALSE);
		SP->Pause = 0;
		SP->PauseKill = -1;
		}

	// Row is -1 if call is from a program

	if (Row >= 0 ) {

//----------------------------------------
//		move to correct directory
//----------------------------------------

		if (chdir(directories[Row]))
			printf("*** Directory error Row %d\n",Row);
		text1 = (gchar *) gtk_entry_get_text (user_data);
		DisplayProgramButtons();
		}

	if (Row == -10) { // top row
		text1 = lcl; // make pointer point at real data
		strcpy(text1, top1);
		}
	else if (Row == -20) { // top row
		text1 = lcl; // make pointer point at real data
		strcpy(text1, top2);
		}
	else if (Row == -30) { // top row
		text1 = lcl; // make pointer point at real data
		strcpy(text1, top3);
		}
	else if (Row == -1) {
		k = SP->NowPlaying;
		text1 = (gchar *) user_data;
		}

	else text1 = (gchar *) gtk_entry_get_text (user_data); // was for program buttons

	if (strlen((char *) text1) == 0) {
		Message("No file specified.");    // update label
		return;
		}

	ClearPlayers();

	strcpy(SP->playThis, text1);

	strcpy(mesg, "\"");
	strcat(mesg, text1);
	strcat(mesg, "\"");

	if (Row != -1) chdir(directories[Row]); // move to correct directory

	SP->playClip = 1;

	strcpy(SP->next_random,"Next Program Selection");
	return;
	}

