/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018 - 2026 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
#+
#+	astyle --style=banner --indent=tab load-program.c.in
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	June 30, 2026

#include "includes.h"
#include "defines.h"
#include "common-externs.h"
#include "common-fcn-headers.h"

#include "global-extern-variables.h"

#include <vlc/libvlc.h>
#include <vlc/libvlc_renderer_discoverer.h>
#include <vlc/libvlc_media.h>
#include <vlc/libvlc_media_player.h>

#define SLASH '/'

// UPDATE_TILES 1
// SCAN_TILES NULL


void	on_scan_video_dir1_clicked(GtkWidget *w) {
	on_scan_video_dir_clicked(SCAN_TILES); // full rescan
	}

void	on_scan_video_dir_clicked(GtkWidget *w) {

	char tmp[8192];

	printf("Scan video directory\n");

	gtk_label_set_text(GTK_LABEL(current_dir), Music_Home_Directory);

	if (w == NULL) { // full re-scan
		sprintf(tmp, "rm -f \"%s/thumbnails/\"*.jpg", Code_Home);
		printf("%s\n", tmp);
		system(tmp);
		}

	SP->scount = 0;

	buttonColor(-1, NULL); // clear current image array

	DisplayProgramButtons();
	while (gtk_events_pending()) gtk_main_iteration();

	int i = empty_dir(Music_Home_Directory);

//-------------------------------------------------------
//	populate program.lst
//	full addresses of files
//	system("readlink -f videos/* > program.lst");
//-------------------------------------------------------

	if (i == 0)
		sprintf(tmp, "cat /dev/null > \"%s\"", Program_List);
	else
		sprintf(tmp, "readlink -f \"%s/\"* > %s",
		        Music_Home_Directory, Program_List);

	printf("Directory Scan: %s\n", tmp);

	int err_stat = system(tmp);

	if (err_stat != 0) {
		error_message("An error or interrupt occurred while processing", tmp);
		return;
		}

	LoadProgram();
	on_date_sort_clicked(NULL);

	DisplayProgramButtons( );
	on_update_times_clicked(NULL);

	}
