// This was an experimantal new aproach for dvdauth.xml generation that faild in spmuxing
// The idea was to have a title for every movie so subtitles could be renderd okey. 

	    tmp_001 = "<?xml version='1.0' encoding='iso-8859-15'?>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    tmp_001 = "<dvdauthor dest=\"" + path_out->text() + "DVD\">\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    myfic_2.writeBlock("\t<vmgm>\n", 8);

  	    myfic_2.writeBlock("\t\t<fpc>\n", 8);
	    myfic_2.writeBlock("\t\tg0=100;\n", 10);
 	    myfic_2.writeBlock("\t\tg1=0;\n", 8);
 	    myfic_2.writeBlock("\t\tg2=1024;\n", 11);
 	    myfic_2.writeBlock("\t\tjump menu 1;\n", 15);
 	    myfic_2.writeBlock("\t\t</fpc>\n", 9);

	    myfic_2.writeBlock("\t\t<menus>\n", 10);

	    if (projfps == 29) {
		tmp_001 =
		    "\t\t\t<video format=\"NTSC\" aspect=\"" + aspectdvdauth + "\"></video>\n";
	    } else {
		tmp_001 =
 		    "\t\t\t<video format=\"PAL\" aspect=\"" + aspectdvdauth + "\"></video>\n";
	    }

	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    
	    tmp_001 = "\t\t\t<pgc>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	
	    // <pre> 
	    tmp_001 = "\t\t\t<pre>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    int y = 1;
	    while (y <= max_boutons ){
		tmp_001 = "\t\t\tif (g0 eq " + QString::number(y) + 
		") { \n\t\t\t\t\tjump titleset " + QString::number(y+1) + " menu;\n\t\t\t}\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    y++;
	    }
	    tmp_001 = "\t\t\tif (g0 eq 100 ) { \n\t\t\t\tg2=1024;\n\t\t\t\tjump titleset 1 menu;\n\t\t\t}\n\t\t\t</pre>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

	    // </pre> 

	    // VOB file for menu 
	    if (loopsound->currentText() == table_message[60]) {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"0\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    } else {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"inf\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    }	    


/*
	    // Intromovie if present
	    if (pathintro != "") {
		tmp_001 = "\t\t\t<vob file=\"" + path_out->text() + "/gibintromenu.mpg\" pause=\"0\" />\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    }
	    else{
	    	tmp_001 = "\t\t\t<vob file=\"" + path_out->text() + "/gibintromenu.mpg\" />\n";
	    	myfic_2.writeBlock(tmp_001, tmp_001.length());
	    }
*/

/*
	    if (startfilm->currentText() == "DVD_Menu") {
		tmp_001 = "<post>jump titleset 1 menu;</post>\n";
	    } else {
		tmp_001 = "<post>jump title 1;</post>\n";
	    }
*/
	    tmp_001 = "\t\t\t</pgc>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    tmp_001 = "\t\t</menus>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    tmp_001 = "\t</vmgm>\n\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    // End <vmgm>

	   // Titleset starts
	    myfic_2.writeBlock("\t<titleset>\n", 12);
	    tmp_001 = "\t\t<menus>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

	    tmp_001 =
		"\t\t\t<video format=\"" + videostandard->currentText() +
		"\" aspect=\"" + aspectdvdauth + "\" resolution=\"" +
		QString::number(projwid) + "x" + QString::number(projhau) +
		"\"></video>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	
    	    tmp_001 = "\t\t\t<pgc>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

	    tmp_001 = "\t\t\t<pre>\n\t\t\t\ts8=g2;\n\t\t\t\tif (g1 eq 100) {\n\t\t\t\tjump title 1;\n\t\t\t\t}\n\t\t\t</pre>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

	    // VOB file for menu 
	    if (loopsound->currentText() == table_message[60]) {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"0\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    } else {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"inf\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	      }

	    // Buttons
	    y = 1;
	    while (y <= max_boutons ){
		tmp_001 = "\t\t\t<button name=\"" + QString::number(y-1) + "\"> g0=" + QString::number(y) + "; jump vmgm menu;</button>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    y++;
	    }

            tmp_001 = "\t\t\t<post>\n\t\t\t\tg2=s8;\n\t\t\t\tg1=0;\n\t\t\t\tjump menu 1;\n\t\t\t</post>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
    	    tmp_001 = "\t\t\t</pgc>\n\t\t</menus>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

	    // Titles
    	    myfic_2.writeBlock("\t\t<titles>\n", 11);

	    if (projfps == 29) {
		tmp_001 =
		    "\t\t\t<video format=\"NTSC\" aspect=\"" + aspectdvdauth + "\"></video>\n";
	    } else {
		tmp_001 =
 		    "\t\t\t<video format=\"PAL\" aspect=\"" + aspectdvdauth + "\"></video>\n";
	    }
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

	    tmp_001 = "\t\t\t<pgc>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

	    // VOB file for menu 
	    if (loopsound->currentText() == table_message[60]) {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"0\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    } else {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"inf\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    }	

 	    tmp_001 = "\t\t\t<post>\n\t\t\t\tg0=1;\n\t\t\t\tg1=0;\n\t\t\t\tg2=1024;\n\t\t\t\tcall vmgm menu entry title;\n\t\t\t</post>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

    	    tmp_001 = "\t\t\t</pgc>\n\t\t</titles>\n\t</titleset>\n\n\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    // End this titleset for menu


	    // Start generating for every movie on the DVD
	    int wl_cpt1 = 0;
	    compteur = 0;

	    while (compteur < max_boutons) {
		// Titleset starts
		myfic_2.writeBlock("\t<titleset>\n", 12);
		tmp_001 = "\t\t<menus>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());

		tmp_001 =
			"\t\t\t<video format=\"" + videostandard->currentText() +
			"\" aspect=\"" + aspectdvdauth + "\" resolution=\"" +
			QString::number(projwid) + "x" + QString::number(projhau) +
			"\"></video>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
		
		tmp_001 = "\t\t\t<pgc>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	
		tmp_001 = "\t\t\t<pre>\n\t\t\t\tif (g0 eq 100) {\n\t\t\t\t\tjump vmgm menu entry title;\n\t\t\t\t}\n\t\t\t\tg0=100;\n\t\t\t\tg1=0;\n\t\t\t\tjump title 1;\n\t\t\t</pre>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());

	    // VOB file for menu 
	    if (loopsound->currentText() == table_message[60]) {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"0\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    } else {
		tmp_001 =
		    "\t\t\t<vob file=\"" + path_out->text() +
		    "/genmenu.mpg\" pause=\"inf\"></vob>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
	    }

		tmp_001 = "\t\t\t</pgc>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());
		tmp_001 = "\t\t</menus>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());

	        // Titles start for this movie
		tmp_001 = "\t\t<titles>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());

		// Videoformat code again -Should be function
		tmp_001 =
			"\t\t\t<video format=\"" + videostandard->currentText() +
			"\" aspect=\"" + aspectdvdauth + "\" resolution=\"" +
			QString::number(projwid) + "x" + QString::number(projhau) +
			"\" widescreen=\"nopanscan\"></video>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());

		/* Code for subtitles in dvdauth */
		QListViewItem *lsub = listViewSubTitle_2->firstChild();
		tmp_001 = "";
		while (lsub) {
		    // Match path to video encoded and path for subtitle 
		    if (table_boutons_lien[compteur][1] == lsub->text(2)) {
			QString sublang = lsub->text(0);
			sublang = sublang.lower();
			sublang = sublang.left(2);
			tmp_001 =
			    tmp_001 + "\t\t\t<subpicture lang=\"" + sublang +
			    "\" />\n";
		    }
		    lsub = lsub->nextSibling();
		}
		myfic_2.writeBlock(tmp_001, tmp_001.length());

		tmp_001 = "\t\t\t<pgc>\n";
		myfic_2.writeBlock(tmp_001, tmp_001.length());


		// *** Recherche de la position du titre ***
		if (table_boutons_lien[compteur][3] == "$$CHAP$$") {
		    cpt_006 = 0;
		    tmp_010 = table_boutons_lien[compteur][1];
		    rc_001 = tmp_010.find("|||", 0);

		    if (rc_001 != -1) {
			tmp_011 = tmp_010.mid(0, rc_001);
			cpt_005 = 1;

			// Generate buttons for chapters
			while (tmp_011 != table_boutons_lien[cpt_006][0]
			       && cpt_006 < max_boutons) {
			    if (table_boutons_lien[cpt_006][3] !=
				"$$CHAP$$") {
				cpt_005 = cpt_005 + 1;
			    }
			    cpt_006 = cpt_006 + 1;
			}
/*
			if (tmp_011 == table_boutons_lien[cpt_006][0]) {
			    tmp_001 =
				"\t\t\t<button name=\"" +
				QString::number(compteur) +
				"\"> jump title " +
				QString::number(cpt_005) + " chapter " +
				tmp_010.mid(rc_001 + 3,
					    tmp_010.length() - (rc_001 +
								3)) +
				"; </button>\n";
			    myfic_2.writeBlock(tmp_001, tmp_001.length());
			} else {
			    printf
				("Error generating XML file ! Contact me");
			}
*/
		    } else {
			printf("Error generating XML file ! Contact me");
		    } 
		} else {
		    cpt_006 = 0;
		    tmp_010 = table_boutons_lien[compteur][0];
		    cpt_005 = 1;

		    while (tmp_010 != table_boutons_lien[cpt_006][0]
			   && cpt_006 < max_boutons) {
			if (table_boutons_lien[cpt_006][3] != "$$CHAP$$") {
			    cpt_005 = cpt_005 + 1;
			}
			cpt_006 = cpt_006 + 1;
		    }
		    if (tmp_010 == table_boutons_lien[cpt_006][0]) {
			tmp_001 =
			    "<button name=\"" + QString::number(compteur) +
			    "\"> jump title " + QString::number(cpt_005) +
			    "; </button>\n";
		    } else {
			printf("Error generating XML file ! Contact me");
		    }
		    myfic_2.writeBlock(tmp_001, tmp_001.length());
		}
		
		// NO chapers in this movie 
		if (table_boutons_lien[compteur][3] != "$$CHAP$$") {
		    //myfic_2.writeBlock("<pgc>\n", 6);

		    if (table_boutons_lien[compteur][3] == "") {	// No chapters
			tmp_001 =
			    "\t\t\t<vob file=\"" + path_out->text() +
			    "gibvideo" + QString::number(cpt_005) +
			    ".mpg\"></vob>\n";
		    } else {
			tmp_002 = table_boutons_lien[compteur][3];	// Chapters valid
			tmp_001 =
			    "\t\t\t<vob file=\"" + path_out->text() +
			    "gibvideo" + QString::number(cpt_005) +
			    ".mpg\" chapters=\"" + tmp_002.mid(0,
							       tmp_002.length
							       () - 9) +
			    "\"></vob>\n";
		    }
		    myfic_2.writeBlock(tmp_001, tmp_001.length());
		}

 	    tmp_001 = "\t\t\t<post>\n\t\t\t\tg1=0;\n\t\t\t\tg0=100;\n\t\t\t\tcall vmgm menu entry title;\n\t\t\t</post>\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());

    	    tmp_001 = "\t\t\t</pgc>\n\t\t</titles>\n\t</titleset>\n\n";
	    myfic_2.writeBlock(tmp_001, tmp_001.length());
	    // End this titleset for menu

		compteur = compteur + 1;
	    }
	    myfic_2.writeBlock("</dvdauthor>\n", 13);
 	    myfic_2.close();