/* ============================================================
 * File  : project.cpp
 * Author: Stephane Gibault
 * Date  : Sun Feb 4 2007
 * Description :
 *
 * 
 *  (C) 2007 by Stephane Gibault
 *
 * 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, 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.
 *
 * ============================================================ */

#include <QtGui>
#include "mainfrm.h"

// ********************************
// *** ENREGISTREMENT DU PROJET ***
// ********************************

void mainfrm::f_save_1()
{
	// *** SAVE AS ***
	this->setDisabled(true);
	if ( hdl_current_menu != 0 )
	{
		hdl_current_menu->is_select = 0;
		hdl_current_menu = 0;
	}

	QString wmypro = QFileDialog::getSaveFileName(this, tr("Sauvegarder votre projet"), path_save, tr("Projet (*.mdvd)"));
       	if ( wmypro.isNull() )
       	{
		this->setEnabled(true);
		return;
       	}
	else
	{
		if ( wmypro.right(5) != ".mdvd" )
		{
			wmypro = wmypro + ".mdvd";
		}
		QString wl_str_001;
		path_always_save = wmypro;
   		wg_int_001 = wmypro.lastIndexOf( '/' );
    		if ( wg_int_001 != -1 )
    		{
        		path_save = wmypro.mid(0,wg_int_001);
    		}

		f_save_widgetonmenu();

		// *** SAUVEGARDE DES MEDIAS ***
	     	QFile wmyfic(path_project + "/DVD/SVP/prj_med.x");

		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING PROJECT MEDIA IN : " + path_project;
			return;
		}
		else
		{
			QTextStream out(&wmyfic);

			wg_int_001 = 0;
			out << QString::number(combo_format_dvd->currentIndex()) << endl;
			out << QString::number(dvdzone) << endl;

			while ( wg_int_001 < nbre_medias )
			{
				hdl_current_media = table_hdl_medias[wg_int_001];

				hdl_current_media->image.save(path_project + "/DVD/SVP/MDI" + QString::number(wg_int_001) + ".png","PNG");
				hdl_current_media->miniature.save(path_project + "/DVD/SVP/MDM" + QString::number(wg_int_001) + ".png","PNG");
				out << hdl_current_media->pathname_media.simplified() << endl;
				out << hdl_current_media->wl_width.simplified() << endl;
				out << hdl_current_media->wl_height.simplified() << endl;
				out << hdl_current_media->wl_fps.simplified() << endl;
				out << hdl_current_media->wl_duree.simplified() << endl;
				out << hdl_current_media->wl_format.simplified() << endl;
				out << hdl_current_media->wl_audio_channel.simplified() << endl;
				out << QString::number(hdl_current_media->isdvd) << endl;
				out << QString::number(hdl_current_media->dvdsize) << endl;
				out << QString::number(hdl_current_media->is_lock) << endl;
				out << QString::number(hdl_current_media->position.x()) << endl;
				out << QString::number(hdl_current_media->position.y()) << endl;
				out << QString::number(hdl_current_media->nbre_chapitres) << endl;
				out << hdl_current_media->wl_vbitrate << endl;
				out << hdl_current_media->wl_vbitrate_encode << endl;
				out << hdl_current_media->wl_sub_path << endl;
				out << QString::number(hdl_current_media->oldisdvd) << endl;
				out << hdl_current_media->wl_video_sync << endl;
				out << hdl_current_media->hue << endl;
				out << hdl_current_media->saturation << endl;
				out << hdl_current_media->contraste << endl;
				out << hdl_current_media->lumiere << "$E" << hdl_current_media->isdvdintro << endl;
				if ( checkBox_save_encode->isChecked() == true )
				{
					out << hdl_current_media->already_encode << endl;
				}
				else
				{
					out << "0" << endl;
				}

				wg_int_002 = 0;
				wg_string_001 = "";
				while ( wg_int_002 <= hdl_current_media->nbre_chapitres )
				{
					wg_string_001 = wg_string_001 + hdl_current_media->chapitres[wg_int_002] + ";";
					wg_pix_001 = hdl_current_media->icones_chapitres[wg_int_002].pixmap(hdl_current_media->miniature.width(),hdl_current_media->miniature.height(),QIcon::Normal,QIcon::On);
					wg_pix_001.save(path_project + "/DVD/SVP/C" + QString::number(wg_int_001) + "X" + QString::number(wg_int_002) + ".png","PNG");
					wg_int_002++;
				}
				out << wg_string_001.simplified() << endl;

				wg_int_002 = 0;
				wg_string_001 = "";
				while ( hdl_current_media->table_soundtrack[wg_int_002] != "" )
				{
					wg_string_001 = wg_string_001 + hdl_current_media->table_soundtrack[wg_int_002] + ";";
					wg_int_002++;
				}
				out << wg_string_001.simplified() << endl;

				out << "------" << endl;
				wg_int_001++;
			}
			wmyfic.close();
		}

		// *** SAUVEGARDE DES POSITIONS DE MENUS DE L'ARBRE ***
	     	wmyfic.setFileName(path_project + "/DVD/SVP/prj_arb.x");

		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING PROJECT TREE IN : " + path_project;
			return;
		}
		else
		{
			int wl_int_001 = 0;
			QTextStream out(&wmyfic);

			while ( wl_int_001 <= nbre_menuth )
			{
				out << frame_syno->tab_pnt_item[wl_int_001]->geometry().x() << endl;
				out << frame_syno->tab_pnt_item[wl_int_001]->geometry().y() << endl;
				wl_int_001++;
			}
			wmyfic.close();
		}

		// *** SAUVEGARDE DES POSITIONS DE MEDIAS DE L'ARBRE ***
	     	wmyfic.setFileName(path_project + "/DVD/SVP/med_arb.x");

		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING PROJECT MEDIA TREE IN : " + path_project;
			return;
		}
		else
		{
			int wl_int_001 = 0;
			QTextStream out(&wmyfic);

			while ( wl_int_001 < nbre_medias )
			{
				out << frame_syno->tab_pnt_media[wl_int_001]->geometry().x() << endl;
				out << frame_syno->tab_pnt_media[wl_int_001]->geometry().y() << endl;
				wl_int_001++;
			}
			wmyfic.close();
		}

		// *** SAUVEGARDE DES MENUS BOUTONS ***
	     	wmyfic.setFileName(path_project + "/DVD/SVP/prj_bou.x");

		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING PROJECT BUTTONS IN : " + path_project;
			return;
		}
		else
		{
			wg_int_001=0;
			QTextStream out(&wmyfic);
			while ( wg_int_001 <= nbre_menuth )
			{
				out << table_menus_property[wg_int_001][0] << endl;
				out << table_menus_property[wg_int_001][1] << endl;
				out << table_menus_property[wg_int_001][2] << endl;
				out << table_menus_property[wg_int_001][3] << endl;
				out << table_menus_property[wg_int_001][4] << endl;
				out << table_menus_property[wg_int_001][5] << endl;
				out << table_menus_property[wg_int_001][6] << endl;
				out << table_menus_property[wg_int_001][7] << endl;
				out << table_menus_property[wg_int_001][8] << endl;

				if ( table_menus_property[wg_int_001][0].right(4) == ".MPG" || table_menus_property[wg_int_001][0].right(4) == ".mpg" || table_menus_property[wg_int_001][0].right(4) == ".AVI" || table_menus_property[wg_int_001][0].right(4) == ".avi" )
				{
			   		wg_int_002 = table_menus_property[wg_int_001][0].lastIndexOf( '/' );
			    		if ( wg_int_002 != -1 )
			    		{
						QFile::copy ( path_project+"/DVD/TEMP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1))+".jpg", path_project+"/DVD/SVP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1)) + ".jpg" );
					}
				}

				wg_int_002 = 0;
				while ( table_menus[wg_int_001][wg_int_002][0] != "$$$" )
				{
					hdl_current_menu = table_hdl_menus[wg_int_002];
					wg_string_001 = "";
					wg_int_003 = 0;
					while ( wg_int_003 < 25 )
					{
						if ( wg_int_003 != 4 )
						{
							wg_string_001 = wg_string_001 + table_menus[wg_int_001][wg_int_002][wg_int_003].simplified() + ";";
						}
						else
						{
							wg_string_001 = wg_string_001 + "*;";
						}
						wg_int_003++;
					}
					out << wg_string_001 << endl;

					wl_str_001 = table_menus[wg_int_001][wg_int_002][4];
					wl_str_001.replace(QString("\n"), QString("$-E#"));
					out << wl_str_001 << endl;
					wg_int_002++;
				}
				out << "------" << endl;
				table_hdl_menuth[wg_int_001]->draw_image.save(path_project + "/DVD/SVP/MTH" + QString::number(wg_int_001) + ".png","PNG");
				wg_int_001++;
			}
			wmyfic.close();
		}

		// *** SAUVEGARDE DU PROJET ***
	     	wmyfic.setFileName(path_project + "/DVD/prjsave.sh");

		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING BASH SAVING PROJECT IN : " + path_project;
			return;
		}
		else
		{
			QTextStream out(&wmyfic);
			out << "cd " + path_project + "/DVD/" << endl;
			out << "rm -f " + path_project + "/DVD/SVP/MEDIAS" << endl;
			if ( checkBox_save_encode->isChecked() == true )
			{
				out << "cp -rf " + path_project + "/DVD/MEDIAS " + path_project + "/DVD/SVP/" << endl;
			}
			out << "tar cf " + wmypro + " SVP" << endl;
			out << "rm -f prjsave.sh" << endl;
			wmyfic.close();

			wg_int_005 = 0;

			QString program = "bash";
			QStringList arguments;
	       		arguments << path_project + "/DVD/prjsave.sh";
		      	projectProcess.setProcessChannelMode(QProcess::MergedChannels);
		      	projectProcess.start(program,arguments);
		}
	}
}

void mainfrm::f_save_2()
{
	// *** SAVE ***
	this->setDisabled(true);
	if ( hdl_current_menu != 0 )
	{
		hdl_current_menu->is_select = 0;
		hdl_current_menu = 0;
	}

	actionCopier_le_bouton->setDisabled(true);
	actionColler_le_bouton->setDisabled(true);
	bt_bt_img->setDisabled(true);
	dial_alpha_menu->setDisabled(true);
	combo_quoilire_media->setDisabled(true);
	combo_quoilire_media_chapitre->setDisabled(true);
	combo_quoilire_menu->setDisabled(true);
	bttxt->setDisabled(true);
	frame_th_msk_idea->setDisabled(true);
	bt_tool_1->setDisabled(true);
	bt_tool_2->setDisabled(true);
	bt_tool_3->setDisabled(true);
	bt_tool_4->setDisabled(true);

	wg_int_001 = path_always_save.lastIndexOf( '/' );
	if ( wg_int_001 != -1 )
	{
		path_save = path_always_save.mid(0,wg_int_001);
	}

	f_save_widgetonmenu();
	QString wl_str_001;
	// *** SAUVEGARDE DES MEDIAS ***
     	QFile wmyfic(path_project + "/DVD/SVP/prj_med.x");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING PROJECT MEDIA IN : " + path_project;
		return;
	}
	else
	{
		QTextStream out(&wmyfic);

		wg_int_001 = 0;
		out << QString::number(combo_format_dvd->currentIndex()) << endl;
		out << QString::number(dvdzone) << endl;

		while ( wg_int_001 < nbre_medias )
		{
			hdl_current_media = table_hdl_medias[wg_int_001];

			hdl_current_media->image.save(path_project + "/DVD/SVP/MDI" + QString::number(wg_int_001) + ".png","PNG");
			hdl_current_media->miniature.save(path_project + "/DVD/SVP/MDM" + QString::number(wg_int_001) + ".png","PNG");
			out << hdl_current_media->pathname_media.simplified() << endl;
			out << hdl_current_media->wl_width.simplified() << endl;
			out << hdl_current_media->wl_height.simplified() << endl;
			out << hdl_current_media->wl_fps.simplified() << endl;
			out << hdl_current_media->wl_duree.simplified() << endl;
			out << hdl_current_media->wl_format.simplified() << endl;
			out << hdl_current_media->wl_audio_channel.simplified() << endl;
			out << QString::number(hdl_current_media->isdvd) << endl;
			out << QString::number(hdl_current_media->dvdsize) << endl;
			out << QString::number(hdl_current_media->is_lock) << endl;
			out << QString::number(hdl_current_media->position.x()) << endl;
			out << QString::number(hdl_current_media->position.y()) << endl;
			out << QString::number(hdl_current_media->nbre_chapitres) << endl;
			out << hdl_current_media->wl_vbitrate << endl;
			out << hdl_current_media->wl_vbitrate_encode << endl;
			out << hdl_current_media->wl_sub_path << endl;
			out << QString::number(hdl_current_media->oldisdvd) << endl;
			out << hdl_current_media->wl_video_sync << endl;
			out << hdl_current_media->hue << endl;
			out << hdl_current_media->saturation << endl;
			out << hdl_current_media->contraste << endl;
			out << hdl_current_media->lumiere << "$E" << hdl_current_media->isdvdintro << endl;
			if ( checkBox_save_encode->isChecked() == true )
			{
				out << hdl_current_media->already_encode << endl;
			}
			else
			{
				out << "0" << endl;
			}

			wg_int_002 = 0;
			wg_string_001 = "";
			while ( wg_int_002 <= hdl_current_media->nbre_chapitres )
			{
				wg_string_001 = wg_string_001 + hdl_current_media->chapitres[wg_int_002] + ";";
				wg_pix_001 = hdl_current_media->icones_chapitres[wg_int_002].pixmap(hdl_current_media->miniature.width(),hdl_current_media->miniature.height(),QIcon::Normal,QIcon::On);
				wg_pix_001.save(path_project + "/DVD/SVP/C" + QString::number(wg_int_001) + "X" + QString::number(wg_int_002) + ".png","PNG");
				wg_int_002++;
			}
			out << wg_string_001.simplified() << endl;

			wg_int_002 = 0;
			wg_string_001 = "";
			while ( hdl_current_media->table_soundtrack[wg_int_002] != "" )
			{
				wg_string_001 = wg_string_001 + hdl_current_media->table_soundtrack[wg_int_002] + ";";
				wg_int_002++;
			}
			out << wg_string_001.simplified() << endl;

			out << "------" << endl;
			wg_int_001++;
		}
		wmyfic.close();
	}

	// *** SAUVEGARDE DES POSITIONS DE MENUS DE L'ARBRE ***
     	wmyfic.setFileName(path_project + "/DVD/SVP/prj_arb.x");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING PROJECT TREE IN : " + path_project;
		return;
	}
	else
	{
		int wl_int_001 = 0;
		QTextStream out(&wmyfic);

		while ( wl_int_001 <= nbre_menuth )
		{
			out << frame_syno->tab_pnt_item[wl_int_001]->geometry().x() << endl;
			out << frame_syno->tab_pnt_item[wl_int_001]->geometry().y() << endl;
			wl_int_001++;
		}
		wmyfic.close();
	}

	// *** SAUVEGARDE DES POSITIONS DE MEDIAS DE L'ARBRE ***
     	wmyfic.setFileName(path_project + "/DVD/SVP/med_arb.x");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING PROJECT MEDIA TREE IN : " + path_project;
		return;
	}
	else
	{
		int wl_int_001 = 0;
		QTextStream out(&wmyfic);

		while ( wl_int_001 < nbre_medias )
		{
			out << frame_syno->tab_pnt_media[wl_int_001]->geometry().x() << endl;
			out << frame_syno->tab_pnt_media[wl_int_001]->geometry().y() << endl;
			wl_int_001++;
		}
		wmyfic.close();
	}

	// *** SAUVEGARDE DES MENUS BOUTONS ***
     	wmyfic.setFileName(path_project + "/DVD/SVP/prj_bou.x");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING PROJECT BUTTONS IN : " + path_project;
		return;
	}
	else
	{
		wg_int_001=0;
		QTextStream out(&wmyfic);
		while ( wg_int_001 <= nbre_menuth )
		{
			out << table_menus_property[wg_int_001][0] << endl;
			out << table_menus_property[wg_int_001][1] << endl;
			out << table_menus_property[wg_int_001][2] << endl;
			out << table_menus_property[wg_int_001][3] << endl;
			out << table_menus_property[wg_int_001][4] << endl;
			out << table_menus_property[wg_int_001][5] << endl;
			out << table_menus_property[wg_int_001][6] << endl;
			out << table_menus_property[wg_int_001][7] << endl;
			out << table_menus_property[wg_int_001][8] << endl;

			if ( table_menus_property[wg_int_001][0].right(4) == ".MPG" || table_menus_property[wg_int_001][0].right(4) == ".mpg" || table_menus_property[wg_int_001][0].right(4) == ".AVI" || table_menus_property[wg_int_001][0].right(4) == ".avi" )
			{
		   		wg_int_002 = table_menus_property[wg_int_001][0].lastIndexOf( '/' );
		    		if ( wg_int_002 != -1 )
		    		{
					QFile::copy ( path_project+"/DVD/TEMP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1))+".jpg", path_project+"/DVD/SVP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1)) + ".jpg" );
				}
			}

			wg_int_002 = 0;
			while ( table_menus[wg_int_001][wg_int_002][0] != "$$$" )
			{
				hdl_current_menu = table_hdl_menus[wg_int_002];
				wg_string_001 = "";
				wg_int_003 = 0;
				while ( wg_int_003 < 25 )
				{
					if ( wg_int_003 != 4 )
					{
						wg_string_001 = wg_string_001 + table_menus[wg_int_001][wg_int_002][wg_int_003].simplified() + ";";
					}
					else
					{
						wg_string_001 = wg_string_001 + "*;";
					}
					wg_int_003++;
				}
				out << wg_string_001 << endl;

				wl_str_001 = table_menus[wg_int_001][wg_int_002][4];
				wl_str_001.replace(QString("\n"), QString("$-E#"));
				out << wl_str_001 << endl;

				wg_int_002++;
			}
			out << "------" << endl;
			table_hdl_menuth[wg_int_001]->draw_image.save(path_project + "/DVD/SVP/MTH" + QString::number(wg_int_001) + ".png","PNG");
			wg_int_001++;
		}
		wmyfic.close();
	}

	// *** SAUVEGARDE DU PROJET ***
     	wmyfic.setFileName(path_project + "/DVD/prjsave.sh");

	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING BASH SAVING PROJECT IN : " + path_project;
		return;
	}
	else
	{
		QTextStream out(&wmyfic);
		out << "cd " + path_project + "/DVD/" << endl;
		out << "rm -f " + path_project + "/DVD/SVP/MEDIAS" << endl;
		if ( checkBox_save_encode->isChecked() == true )
		{
			out << "cp -rf " + path_project + "/DVD/MEDIAS " + path_project + "/DVD/SVP/" << endl;
		}
		out << "tar cf " + path_always_save + " SVP" << endl;
		out << "rm -f prjsave.sh" << endl;
		wmyfic.close();

		wg_int_005 = 0;

		QString program = "bash";
		QStringList arguments;
       		arguments << path_project + "/DVD/prjsave.sh";
	      	projectProcess.setProcessChannelMode(QProcess::MergedChannels);
	      	projectProcess.start(program,arguments);
	}
}

// ************************************************
// *** POINT DE SORTIE POUR GESTION DES PROJETS ***
// ************************************************

void mainfrm::projectend(int, QProcess::ExitStatus)
{
	if ( wg_int_005 == 0 )
	{
		
		QMessageBox::information(this, name_application, tr("Sauvegarde du projet terminee"));
		this->setEnabled(true);
		actionEnregistrer_2->setEnabled(true);
		top_window->setEnabled(true);
		this->setWindowTitle(tr("2ManDVD - Creation de DVD Videos : ") + path_always_save);
		return;
	}

	if ( wg_int_005 == 1 )
	{
		f_open_2();
		this->setWindowTitle(tr("2ManDVD - Creation de DVD Videos : ") + path_always_save);
		return;
	}

}

// ***************************
// *** OUVERTURE DU PROJET ***
// ***************************

void mainfrm::f_open_from_start()
{
	QString wmypro = QFileDialog::getOpenFileName(
        	this,
        	tr("Ouvrir un projet"),
        	path_save,
        	"(*.mdvd)");
	if ( wmypro.isNull() )
	{
	}
	else
	{
		if ( line_path_projet->text() != "" )
		{
	   		int wl_int_001 = wmypro.lastIndexOf( '/' );
	    		if ( wl_int_001 != -1 )
	    		{
				path_save = wmypro.mid(0,wl_int_001);
	    		}
			path_project = line_path_projet->text();

			QFile wmyficext;
			QTextStream outext(&wmyficext);

			wmyficext.setFileName(path_project + "/.delall.sh");
			wmyficext.open( QIODevice::WriteOnly );
			outext << "rm -rf " + path_project + "/DVD" << endl;
			outext << "rm -f " + path_project + "/.delall.sh" << endl;
			outext << "exit" << endl;
			wmyficext.close();
			QString programf = "bash";
			QStringList argumentsf;
			argumentsf << path_project + "/.delall.sh";

		      	proc_ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
			proc_ffmpeg.start(programf,argumentsf);

			proc_ffmpeg.waitForFinished(-1);

			if ( f_create_env() == true )
			{
				path_always_save = wmypro;
				frame_editor->lower();
				frame_editor->show();
				thread_ani->hdlmsk = mask_interface;
				thread_ani->progress = 220;
				thread_ani->sens = 0;
				frame_new_proj->hide();

				smenuBar->setEnabled(true);

		                // *** SAUVEGARDE LES INFOS DE LA DERNIERE SESSION ***
		                QDir currentDir = QDir::homePath();
		                QFile configfile( currentDir.path() + "/.2mandvd.cnf" );
		                if (configfile.open(QIODevice::WriteOnly))
		                {
		                        QTextStream out(&configfile);
		                        out << line_path_projet->text() << endl;
					if ( checkBox_save_encode->isChecked() == true )
					{
			                        out << "1" << endl;
					}
					else
					{
			                        out << "0" << endl;
					}
					if ( combo_format_vmax->currentIndex() == 0 )
					{
						out << "2600" << endl;
						wl_vmax = 2600;
					}
					else
					{
						if ( combo_format_vmax->currentIndex() == 1 )
						{
							out << "5000" << endl;
							wl_vmax = 5000;
						}
						else
						{
							out << "9800" << endl;
							wl_vmax = 9800;
						}
					}
					out << combo_format_audio->currentIndex() << endl;
		                        configfile.close();
		                }

				QTimer::singleShot(10, this, SLOT(f_run_ani()));

		   		wg_int_001 = wmypro.lastIndexOf( '/' );
		    		if ( wg_int_001 != -1 )
		    		{
					path_save = wmypro.mid(0,wg_int_001);
		    		}

				QFile wmyfic(path_project + "/DVD/prjopen.sh");
				if ( !wmyfic.open( QIODevice::WriteOnly ))
				{
					qDebug() << "ERROR CREATING BASH SAVING PROJECT IN : " + path_project;
					return;
				}
				else
				{
					this->setDisabled(true);
					QTextStream out(&wmyfic);
					out << "cd " + path_project + "/DVD/" << endl;
					out << "tar xf " + wmypro << endl;
					out << "cp -rf " + path_project + "/DVD/SVP/MEDIAS " + path_project + "/DVD/"<< endl;
					out << "rm -f prjopen.sh" << endl;
					out << "exit" << endl;
					wmyfic.close();

					wg_int_005 = 1;

					QString program = "bash";
					QStringList arguments;
			       		arguments << path_project + "/DVD/prjopen.sh";
				      	projectProcess.setProcessChannelMode(QProcess::MergedChannels);
				      	projectProcess.start(program,arguments);
				}
			}
			else
			{
				qDebug() << "ERROR CREATING ENVIRONEMENT ************************************";
				QMessageBox::information(this, name_application, tr("Impossible de créer les dossiers de travail"));
				this->setEnabled(true);
			}
		}
		else
		{
			QMessageBox::information(this, name_application, tr("Vous devez choisir un dossier pour les fichiers de travail"));
		}
	}
}

void mainfrm::f_open_1()
{
	top_window->setDisabled(true);
	QString wmypro = QFileDialog::getOpenFileName(
        	this,
        	tr("Ouvrir un projet"),
        	path_save,
        	"(*.mdvd)");
	if ( wmypro.isNull() )
	{
		top_window->setEnabled(true);
		return;
	}
	else
	{
   		int wl_int_001 = wmypro.lastIndexOf( '/' );
    		if ( wl_int_001 != -1 )
    		{
        		path_save = wmypro.mid(0,wl_int_001);
    		}

		path_always_save = wmypro;

		QFile wmyfic(path_project + "/DVD/prjopen.sh");
		if ( !wmyfic.open( QIODevice::WriteOnly ))
		{
			qDebug() << "ERROR CREATING BASH SAVING PROJECT IN : " + path_project;
			return;
		}
		else
		{
			this->setDisabled(true);
			QTextStream out(&wmyfic);
			out << "cd " + path_project + "/DVD/" << endl;
			out << "tar xf " + wmypro << endl;
			out << "cp -rf " + path_project + "/DVD/SVP/MEDIAS " + path_project + "/DVD/"<< endl;
			out << "rm -f prjopen.sh" << endl;
			wmyfic.close();

			wg_int_005 = 1;

			QString program = "bash";
			QStringList arguments;
	       		arguments << path_project + "/DVD/prjopen.sh";
		      	projectProcess.setProcessChannelMode(QProcess::MergedChannels);
		      	projectProcess.start(program,arguments);
		}
	}
}

void mainfrm::f_open_ext(QString wmypro)
{
	top_window->setDisabled(true);

	f_create_env();

	wg_int_001 = wmypro.lastIndexOf( '/' );
	if ( wg_int_001 != -1 )
	{
		path_save = wmypro.mid(0,wg_int_001);
	}

	path_always_save = wmypro;

	QFile wmyfic(path_project + "/DVD/prjopen.sh");
	if ( !wmyfic.open( QIODevice::WriteOnly ))
	{
		qDebug() << "ERROR CREATING BASH SAVING PROJECT IN : " + path_project;
		return;
	}
	else
	{
		this->setDisabled(true);
		QTextStream out(&wmyfic);
		out << "cd " + path_project + "/DVD/" << endl;
		out << "tar xf " + wmypro << endl;
		out << "cp -rf " + path_project + "/DVD/SVP/MEDIAS " + path_project + "/DVD/"<< endl;
		out << "rm -f prjopen.sh" << endl;
		wmyfic.close();

		wg_int_005 = 1;

		QString program = "bash";
		QStringList arguments;
       		arguments << path_project + "/DVD/prjopen.sh";
	      	projectProcess.setProcessChannelMode(QProcess::MergedChannels);
	      	projectProcess.start(program,arguments);
	}
}

void mainfrm::f_open_2()
{
	must_update = 0;
	f_init_proj();
	dvd_actual_size = 0;
	// *** CHARGEMENT DES MEDIAS ***

	QByteArray newData;
	QStringList wl_explode;
     	QFile wmyfic(path_project + "/DVD/SVP/prj_med.x");

	if ( !wmyfic.open( QIODevice::ReadOnly ))
	{
		qDebug() << "ERROR OPENING MEDIA IN : " + path_project;
		return;
	}
	else
	{
		newData = wmyfic.readLine(0);
		wg_string_001 = QString::fromLocal8Bit(newData);
		wg_string_001 = wg_string_001.simplified();
		wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
		combo_format_dvd->setCurrentIndex(wg_string_001.toInt());

		if ( combo_format_dvd->currentIndex() == 0 )
		{
			dvdxsize = 720;
			dvdysize = 576;
			dvd_standard = "pal";
			dvd_format = "4/3";
		}
		else
		{
			if ( combo_format_dvd->currentIndex() == 1 )
			{
				dvdxsize = 1024;
				dvdysize = 576;
				dvd_standard = "pal";
				dvd_format = "16/9";
			}
			else
			{
				dvdxsize = 720;
				dvdysize = 480;
				dvd_standard = "ntsc";
				dvd_format = "4/3";
			}
		}

		newData = wmyfic.readLine(0);
		wg_string_001 = QString::fromLocal8Bit(newData);
		wg_string_001 = wg_string_001.simplified();
		wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
		dvdzone = wg_string_001.toInt();

		frame_support_editor->setGeometry(frame_support_editor->geometry().x(),frame_support_editor->geometry().y(),dvdxsize,dvdysize);
		screen_designer->setGeometry(0,0,dvdxsize,dvdysize);
		background_menu->setGeometry(0,0,dvdxsize,dvdysize);
		safety_zone->setGeometry(0,0,dvdxsize,dvdysize);

		newData = wmyfic.readLine(0);
		wg_int_001 = 0;
		while ( wmyfic.atEnd() == false )
		{
			media *newmedia = new media(frame_mediatheque,frame_mediatheque);
			hdl_current_media = newmedia;
			table_hdl_medias[nbre_medias] = newmedia;

			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->pathname_media = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_width = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_height = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_fps = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_duree = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_format = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_audio_channel = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->isdvd = wg_string_001.toInt();

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->dvdsize = wg_string_001.toInt();

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->is_lock = wg_string_001.toInt();

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->position.setX(wg_string_001.toInt());

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->position.setY(wg_string_001.toInt());

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->nbre_chapitres = wg_string_001.toInt();

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_vbitrate = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_vbitrate_encode = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_sub_path = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->oldisdvd = wg_string_001.toInt();

			// *** SYNC AUDIO/VIDEO ***

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->wl_video_sync = wg_string_001;

			// *** EFFECTS ***

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->hue = wg_string_001.toInt();

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->saturation = wg_string_001.toInt();

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->contraste = wg_string_001.toInt();

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);

			int wl_search_intro = wg_string_001.lastIndexOf( "$E" );
			if ( wl_search_intro != -1 )
			{
				hdl_current_media->lumiere = wg_string_001.mid(0,wl_search_intro).toInt();
				hdl_current_media->isdvdintro = wg_string_001.mid(wg_string_001.length()-1,1).toInt();
			}
			else
			{
				hdl_current_media->lumiere = wg_string_001.toInt();
				hdl_current_media->isdvdintro = 0;
			}

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			hdl_current_media->already_encode = wg_string_001.toInt();

			//

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			wl_explode = wg_string_001.split(";",QString::KeepEmptyParts);

			wg_int_002 = 0;
			while ( wg_int_002 <= hdl_current_media->nbre_chapitres )
			{
				hdl_current_media->chapitres[wg_int_002] = wl_explode.at(wg_int_002);
				hdl_current_media->icones_chapitres[wg_int_002].addPixmap(path_project + "/DVD/SVP/C" + QString::number(wg_int_001) + "X" + QString::number(wg_int_002) + ".png",QIcon::Normal,QIcon::On);
				wg_int_002++;
			}

			// *** CHARGEMENT DES LANGUES DU MEDIA ***
			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			wl_explode = wg_string_001.split(";",QString::KeepEmptyParts);
			wg_int_002 = 0;

			while ( wg_int_002 < wl_explode.count() )
			{
				hdl_current_media->table_soundtrack[wg_int_002] = wl_explode.at(wg_int_002);
				wg_int_002++;
			}

			if ( newmedia->image.load(path_project + "/DVD/SVP/MDI" + QString::number(wg_int_001) + ".png") == false )
			{
				qDebug() << "ERROR LOADING IMAGE BUTTON " + path_project + "/DVD/SVP/MDI" + QString::number(wg_int_001) + ".png";
			}

			if ( newmedia->miniature.load(path_project + "/DVD/SVP/MDM" + QString::number(wg_int_001) + ".png") == false )
			{
				qDebug() << "ERROR LOADING IMAGE MINIATURE " + path_project + "/DVD/SVP/MDM" + QString::number(wg_int_001) + ".png";
			}

			combo_quoilire_media->insertItem(wg_int_001+1, hdl_current_media->pathname_media);
			combo_quoilire_media->setItemIcon(wg_int_001+1, QIcon(hdl_current_media->miniature));

			newmedia->setGeometry(hdl_current_media->position.x(), hdl_current_media->position.y(), 142, 120);
			newmedia->show();
			//newmedia->hdlpar = frame_mediatheque;
			newmedia->repaint();

			// *** CONNECTION DES EVENTS ***

			connect(newmedia, SIGNAL(delete_media(media*) ),this, SLOT(f_delete_media(media*)));
			connect(newmedia, SIGNAL(thumbnail_media(media*) ),this, SLOT(f_thumbnail_media(media*)));
			connect(newmedia, SIGNAL(chapitre_media(media*) ),this, SLOT(f_chapitre_media(media*)));
			connect(newmedia, SIGNAL(select_media(media*,int) ),this, SLOT(f_select_media(media*,int)));
			connect(newmedia, SIGNAL(affiche_info(media*) ),this, SLOT(f_affiche_info(media*)));
			connect(newmedia, SIGNAL(cache_info(media*) ),this, SLOT(f_cache_info(media*)));
			connect(newmedia, SIGNAL(encode_media(media*) ),this, SLOT(f_encode_media(media*)));
			connect(newmedia, SIGNAL(soundtrack(media*) ),this, SLOT(f_affiche_language(media*)));
			connect(newmedia, SIGNAL(effets(media*) ),this, SLOT(f_effets_media(media*)));
			connect(newmedia, SIGNAL(introdvd(media*) ),this, SLOT(f_introdvd(media*)));

			// *** CREATION DU MEDIA DANS L'ARBORESCENCE ***
			item_media *newmediaarb = new item_media(frame_syno);
			if ( nbre_medias == 0 && nbre_menuth == 0 )
			{
				newmediaarb->setGeometry( 2, 0, 142, 120 );
			}
			else
			{
				int wl_calcpos = 2+(150*((nbre_medias + nbre_menuth)-1));
				int wl_multi = 1;
				if ( wl_calcpos > 600 )
				{
					wl_multi = ((float)wl_calcpos/(float)600);
					wl_calcpos = wl_calcpos - (wl_multi*600);
					newmediaarb->setGeometry( 2+wl_calcpos, 150*(wl_multi+1), 142, 120 );
				}
				else
				{
					newmediaarb->setGeometry( wl_calcpos, 150*wl_multi, 142, 120 );
				}
			}
			connect(newmediaarb, SIGNAL(item_move(item_media*) ),this, SLOT(f_itemmedia_move(item_media*)));
			connect(newmediaarb, SIGNAL(sg_ren_media(media*) ),this, SLOT(f_itemmedia_ren(media*)));
			newmediaarb->hdlmedia = newmedia;
			newmediaarb->fond = newmedia->image;
			newmediaarb->show();
			frame_syno->tab_pnt_media[nbre_medias] = newmediaarb;


			nbre_medias++;
			wg_int_001++;
			// *** RECALCUL DE LA JAUGE ***
			f_calcul_jauge(hdl_current_media->dvdsize);

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			if ( wg_string_001.mid(0,3) != "---" )
			{
				QMessageBox::information(this, name_application, tr("Sauvegarde du projet corrompue. Le chargement rique d'etre eronne."));
				qDebug() << wg_string_001;
			}
			else
			{
				newData = wmyfic.readLine(0);
			}
		}
		wmyfic.close();
	}

	// *** CHARGEMENT DES MENUS ***
	wmyfic.setFileName(path_project + "/DVD/SVP/prj_bou.x");
	if ( !wmyfic.open( QIODevice::ReadOnly ))
	{
		qDebug() << "ERROR OPENING MENUS IN : " + path_project;
		return;
	}
	else
	{
		newData = wmyfic.readLine(0);
		wg_int_001 = 0;
		while ( wmyfic.atEnd() == false )
		{
			f_create_new_menu();
			table_hdl_menuth[nbre_menuth] = hdl_current_menuth;
			hdl_current_menuth->setGeometry( 2+(nbre_menuth*106), 0, 106, 106);
			hdl_current_menuth->draw_image = QPixmap(path_project + "/DVD/SVP/MTH" + QString::number(wg_int_001) + ".png");
			if ( nbre_menuth == 0 )
			{
				hdl_current_menuth->is_edit = 1;
			}
			else
			{
				hdl_current_menuth->is_edit = 0;
			}
			hdl_current_menuth->is_first = nbre_menuth + 1;
			hdl_current_menuth->show();

			if ( nbre_menuth > 0 )
			{
				combo_quoilire_menu->insertItem(nbre_menuth+1,"Menu " + QString::number(nbre_menuth));
			}

			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][0] = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			if ( table_menus_property[wg_int_001][0] != "" )
			{
				table_menus_property[wg_int_001][1] = wg_string_001;
				if ( table_menus_property[wg_int_001][0].right(4) == ".MPG" || table_menus_property[wg_int_001][0].right(4) == ".mpg" || table_menus_property[wg_int_001][0].right(4) == ".AVI" || table_menus_property[wg_int_001][0].right(4) == ".avi" )
				{
			   		wg_int_002 = table_menus_property[wg_int_001][0].lastIndexOf( '/' );
			    		if ( wg_int_002 != -1 )
			    		{
						if ( QFile::copy ( path_project+"/DVD/SVP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1))+".jpg", path_project+"/DVD/TEMP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1)) + ".jpg" ) )
						{
						}
						else
						{
							qDebug() << "ERROR COPYING THUMBNAIL IMAGE OF ANIMATED BACKGROUND MENU IN OPENING PROJECT";
							qDebug() << path_project+"/DVD/SVP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1))+".jpg" << " " << path_project+"/DVD/TEMP/"+table_menus_property[wg_int_001][0].mid(wg_int_002+1,table_menus_property[wg_int_001][0].length()-(wg_int_002+1)) + ".jpg";
						}
					}
				}

				if (nbre_menuth == 0 )
				{
					if ( table_menus_property[wg_int_001][0].right(4) == ".MPG" || table_menus_property[wg_int_001][0].right(4) == ".mpg" || table_menus_property[wg_int_001][0].right(4) == ".AVI" || table_menus_property[wg_int_001][0].right(4) == ".avi" )
					{
						current_menu_background = table_menus_property[wg_int_001][0];
				   		wg_int_002 = current_menu_background.lastIndexOf( '/' );
				    		if ( wg_int_002 != -1 )
				    		{
							background_menu->setPixmap(path_project+"/DVD/TEMP/"+current_menu_background.mid(wg_int_002+1,current_menu_background.length()-(wg_int_002+1)));
						}
						else
						{
							qDebug() << "ERROR IN BACKGROUND NAME NO / : " << current_menu_background;
							background_menu->setPixmap(QPixmap(path_project+"/DVD/TEMP/nofd.png"));
						}
					}
					else
					{
						current_menu_background = table_menus_property[wg_int_001][0];
						scale_current_menu_background = wg_string_001.toInt();
						f_generation_scale();
					}
				}
			}
			else
			{
				table_menus_property[wg_int_001][1] = "";
				background_menu->setPixmap(QPixmap(path_project+"/DVD/TEMP/nofd.png"));;
			}

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][2] = wg_string_001;

			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][3] = wg_string_001;

			if ( nbre_menuth == 0 )
			{
				QString wl_str_001 = table_menus_property[wg_int_001][2];
				QStringList wl_explode = wl_str_001.split(";",QString::KeepEmptyParts);
				pntwheel1->setColor(wl_explode.at(0).toInt(),wl_explode.at(1).toInt(),wl_explode.at(2).toInt());

				wl_str_001 = table_menus_property[wg_int_001][3];
				wl_explode = wl_str_001.split(";",QString::KeepEmptyParts);
				pntwheel2->setColor(wl_explode.at(0).toInt(),wl_explode.at(1).toInt(),wl_explode.at(2).toInt());
			}

			newData = wmyfic.readLine(0); // *** AUDIO ***
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][4] = wg_string_001;

			newData = wmyfic.readLine(0); // *** VIDEO D'INTRO ***
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][5] = wg_string_001;

			newData = wmyfic.readLine(0); // *** OPACITE DES OVERLAYS ***
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][6] = wg_string_001;

			newData = wmyfic.readLine(0); // *** LOOP DU MENU ***
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][7] = wg_string_001;

			newData = wmyfic.readLine(0); // *** MUSIQUE TRANSITION CALCULEE ***
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.simplified();
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			table_menus_property[wg_int_001][8] = wg_string_001;

			if ( nbre_menuth == 0 )
			{
				current_menu_audio = table_menus_property[wg_int_001][4];

				if ( current_menu_audio != "" )
				{
					screen_designer->has_sound = 1;
				}
				else
				{
					screen_designer->has_sound = 0;
				}

				current_menu_intro = table_menus_property[wg_int_001][5];
				current_loop = table_menus_property[wg_int_001][7].mid(0,1).toInt();
				loop_length = table_menus_property[wg_int_001][7].mid(1,table_menus_property[wg_int_001][7].length()-1).toInt();
				dial_opacity_overlay->setValue(table_menus_property[wg_int_001][6].toInt());

				if ( current_menu_intro == "" )
				{
					is_is_intro->setToolTip("");
					is_is_intro->is_active = 0;
					is_is_intro->repaint();
					screen_designer->has_intro = 0;
				}
				else
				{
					is_is_intro->setToolTip(current_menu_intro);
					is_is_intro->is_active = 1;
					is_is_intro->repaint();
					screen_designer->has_intro = 1;
				}

				if ( current_menu_audio == "" )
				{
					is_is_sound->setToolTip("");
					is_is_sound->is_active = 0;
					is_is_sound->repaint();
				}
				else
				{
					is_is_sound->setToolTip(current_menu_audio);
					is_is_sound->is_active = 1;
					is_is_sound->repaint();
				}
			}

			newData = wmyfic.readLine(0); 
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);

			wg_int_002 = 0;

			while ( wg_string_001.mid(0,3) != "---" )
			{
				wl_explode = wg_string_001.split(";",QString::KeepEmptyParts);
				table_menus[wg_int_001][wg_int_002][0] = wl_explode.at(0);
				table_menus[wg_int_001][wg_int_002][1] = wl_explode.at(1);
				table_menus[wg_int_001][wg_int_002][2] = wl_explode.at(2);
				table_menus[wg_int_001][wg_int_002][3] = wl_explode.at(3);
				//table_menus[wg_int_001][wg_int_002][4] = wl_explode.at(4);
				table_menus[wg_int_001][wg_int_002][5] = wl_explode.at(5);
				table_menus[wg_int_001][wg_int_002][6] = wl_explode.at(6);
				table_menus[wg_int_001][wg_int_002][7] = wl_explode.at(7);
				table_menus[wg_int_001][wg_int_002][8] = wl_explode.at(8);
				table_menus[wg_int_001][wg_int_002][9] = wl_explode.at(9);
				table_menus[wg_int_001][wg_int_002][10] = wl_explode.at(10);
				table_menus[wg_int_001][wg_int_002][11] = wl_explode.at(11);
				table_menus[wg_int_001][wg_int_002][12] = wl_explode.at(12);
				table_menus[wg_int_001][wg_int_002][13] = wl_explode.at(13);
				table_menus[wg_int_001][wg_int_002][14] = wl_explode.at(14);
				table_menus[wg_int_001][wg_int_002][15] = wl_explode.at(15);
				table_menus[wg_int_001][wg_int_002][16] = wl_explode.at(16);
				table_menus[wg_int_001][wg_int_002][17] = wl_explode.at(17);
				table_menus[wg_int_001][wg_int_002][18] = wl_explode.at(18);
				table_menus[wg_int_001][wg_int_002][19] = wl_explode.at(19);
				table_menus[wg_int_001][wg_int_002][20] = wl_explode.at(20);
				table_menus[wg_int_001][wg_int_002][21] = wl_explode.at(21);
				table_menus[wg_int_001][wg_int_002][22] = wl_explode.at(22);
				table_menus[wg_int_001][wg_int_002][23] = wl_explode.at(23);
				table_menus[wg_int_001][wg_int_002][24] = wl_explode.at(24);

				newData = wmyfic.readLine(0);
				wg_string_001 = QString::fromLocal8Bit(newData);
				wg_string_001 = wg_string_001.simplified();
				wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
				
				wg_string_001.replace(QString("$-E#"),QString("\n"));
				//wg_string_001.replace(QString("\n"),QString(""));

				table_menus[wg_int_001][wg_int_002][4] = wg_string_001;

				if (nbre_menuth == 0 )
				{
					f_create_menu_movie();
				}

				wg_int_002++;
				//
				newData = wmyfic.readLine(0);
				wg_string_001 = QString::fromLocal8Bit(newData);
				wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			}

			table_menus[wg_int_001][wg_int_002][0] = "$$$";

			wg_int_001++;
			nbre_menuth++;
			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
		}
		nbre_menuth--;
		hdl_current_menuth = table_hdl_menuth[0];
		wmyfic.close();
	}

	// *** CHARGEMENT DES MENUS DANS L'ARBRE ***
	wmyfic.setFileName(path_project + "/DVD/SVP/prj_arb.x");
	if ( !wmyfic.open( QIODevice::ReadOnly ))
	{
	}
	else
	{
		newData = wmyfic.readLine(0);
		wg_string_001 = QString::fromLocal8Bit(newData);
		wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
		wg_int_001 = 0;
		while ( wmyfic.atEnd() == false )
		{
			frame_syno->tab_pnt_item[wg_int_001]->setGeometry(wg_string_001.toInt(),0,frame_syno->tab_pnt_item[wg_int_001]->width(),frame_syno->tab_pnt_item[wg_int_001]->height());
			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			frame_syno->tab_pnt_item[wg_int_001]->setGeometry(frame_syno->tab_pnt_item[wg_int_001]->geometry().x(),wg_string_001.toInt(),frame_syno->tab_pnt_item[wg_int_001]->width(),frame_syno->tab_pnt_item[wg_int_001]->height());
			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			wg_int_001++;
		}
		wmyfic.close();
	}

	// *** CHARGEMENT DES MEDIAS DANS L'ARBRE ***
	wmyfic.setFileName(path_project + "/DVD/SVP/med_arb.x");
	if ( !wmyfic.open( QIODevice::ReadOnly ))
	{
	}
	else
	{
		newData = wmyfic.readLine(0);
		wg_string_001 = QString::fromLocal8Bit(newData);
		wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
		wg_int_001 = 0;
		while ( wmyfic.atEnd() == false )
		{
			frame_syno->tab_pnt_media[wg_int_001]->setGeometry(wg_string_001.toInt(),0,frame_syno->tab_pnt_media[wg_int_001]->width(),frame_syno->tab_pnt_media[wg_int_001]->height());
			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			frame_syno->tab_pnt_media[wg_int_001]->setGeometry(frame_syno->tab_pnt_media[wg_int_001]->geometry().x(),wg_string_001.toInt(),frame_syno->tab_pnt_media[wg_int_001]->width(),frame_syno->tab_pnt_media[wg_int_001]->height());
			newData = wmyfic.readLine(0);
			wg_string_001 = QString::fromLocal8Bit(newData);
			wg_string_001 = wg_string_001.mid(0, newData.count() - 1);
			wg_int_001++;
		}
		wmyfic.close();
	}

	if ( (nbre_menuth*110) > frame_support_menu_th_contain->width() )
	{
		frame_support_menuthumb->setGeometry(0,0,((nbre_menuth+1)*110),106);
		scroll_timeline->setMaximum(((nbre_menuth+1)*110)-frame_support_menu_th_contain->width());
		scroll_timeline->setEnabled(true);
	}
	else
	{
		frame_support_menuthumb->setGeometry(0,0,frame_support_menu_th_contain->width(),106);
		scroll_timeline->setMaximum(0);
		scroll_timeline->setDisabled(true);
	}

	top_window->setEnabled(true);
	actionEnregistrer_2->setEnabled(true);
	this->setEnabled(true);
	hdl_current_menu = 0;
	must_update = 1;
}

void mainfrm::f_create_new_menu()
{
	menu_th *newmenu = new menu_th(frame_support_menuthumb);
	connect(newmenu, SIGNAL(select_menuth(menu_th*) ),this, SLOT(f_select_menuth(menu_th*)));
	connect(newmenu, SIGNAL(delete_menu(menu_th*) ),this, SLOT(f_delete_menuth(menu_th*)));
	hdl_current_menuth = newmenu;

	item_menu *newmenuarb = new item_menu(frame_syno);
	if ( nbre_menuth == 0 && nbre_medias == 0 )
	{
		newmenuarb->setGeometry( 2, 0, 106, 106 );
	}
	else
	{
		newmenuarb->setGeometry( 2+(110*((nbre_medias + nbre_menuth)-1)), 110, 106, 106 );
	}
	connect(newmenuarb, SIGNAL(item_move(item_menu*) ),this, SLOT(f_item_move(item_menu*)));
	connect(newmenuarb, SIGNAL(item_select(item_menu*) ),this, SLOT(f_item_select(item_menu*)));
	connect(newmenuarb, SIGNAL(affiche_info(item_menu*) ),this, SLOT(f_affiche_info_arbo(item_menu*)));
	connect(newmenuarb, SIGNAL(hide_info(item_menu*) ),this, SLOT(f_hide_info_arbo(item_menu*)));
	connect(newmenuarb, SIGNAL(add_link(item_menu*,int) ),this, SLOT(f_add_link(item_menu*,int)));
	connect(newmenuarb, SIGNAL(add_link_media(item_menu*,QString) ),this, SLOT(f_add_link_media(item_menu*,QString)));
	connect(newmenuarb, SIGNAL(edit_menu_tree(item_menu*) ),this, SLOT(f_edit_menu_tree(item_menu*)));
	newmenuarb->show();
	frame_syno->tab_pnt_item[nbre_menuth] = newmenuarb;
}

// **********************
// *** NOUVEAU PROJET ***
// **********************
void mainfrm::f_new_1()
{
	frame_editor->lower();
	frame_editor->show();
	thread_ani->hdlmsk = mask_interface;
	thread_ani->progress = 0;
	thread_ani->sens = 1;
	thread_ani->isrender = 100;
	QTimer::singleShot(5, this, SLOT(f_run_ani()));

	f_init_proj();
	smenuBar->setDisabled(true);

	// *** MASK DE FOND ***
	mask_interface->show();
	mask_interface->raise();

	// *** AFFICHAGE DE LA FENETRE NOUVEAU PROJET ***
	frame_new_proj->show();
	frame_new_proj->raise();
}

// **********************************
// *** REINITIALISATION DU PROJET ***
// **********************************

void mainfrm::f_init_proj()
{
	f_delete_widgetonmenu();

	// *** DELETE DES MEDIAS ***

	wg_int_001 = 0;
	while ( wg_int_001 < nbre_medias )
	{
		delete table_hdl_medias[wg_int_001];
		wg_int_001++;
	}
	nbre_medias = 0;

	// *** DELETE MENUS ***
	wg_int_001 = 0;
	while ( wg_int_001 <= nbre_menuth )
	{
		delete table_hdl_menuth[wg_int_001];
		delete frame_syno->tab_pnt_item[wg_int_001];
		wg_int_001++;
	}
	nbre_menuth = 0;
	nbre_menus_wo_label = 0;
	current_menu_background = "";
	scale_current_menu_background = 0;
	current_menu_audio = "";
	current_menu_intro = "";
	hdl_current_menu = 0;
	nbre_medias = 0;
	actionOrdre_de_tabulation->setDisabled(true);

	must_update = 0;
	bttxt->setPlainText("");
	combo_quoilire_media->clear();
	combo_quoilire_media_chapitre->clear();
	combo_select_langue->clear();
	combo_quoilire_menu->clear();
	combo_quoilire_media->insertItem(0,wg_str_int_002);
	combo_quoilire_menu->insertItem(0,wg_str_int_002);
	combo_quoilire_menu->insertItem(1,wg_str_int_003);
	check_anim->setChecked(false);

	must_update = 1;

	actionCopier_le_bouton->setDisabled(true);
	actionColler_le_bouton->setDisabled(true);
	check_anim->setDisabled(true);
	bt_bt_img->setDisabled(true);
	dial_alpha_menu->setDisabled(true);
	combo_quoilire_media->setDisabled(true);
	combo_quoilire_media_chapitre->setDisabled(true);
	combo_select_langue->setDisabled(true);
	combo_quoilire_menu->setDisabled(true);
	bttxt->setDisabled(true);
	frame_th_msk_idea->setDisabled(true);
	bt_tool_1->setDisabled(true);
	bt_tool_2->setDisabled(true);
	bt_tool_3->setDisabled(true);
	bt_tool_4->setDisabled(true);
}

