void Krecipes::import()
{
	QPointer<KFileDialog> file_dialog = new KFileDialog( KUrl(), QString(
		"*.kre *.kreml|Krecipes (*.kre, *.kreml)\n"
		"*.mx2|MasterCook (*.mx2)\n"
		"*.mxp *.txt|%1 (*.mxp, *.txt)\n"
		"*.mmf *.txt|Meal-Master (*.mmf, *.txt)\n"
		"*.txt|%2 (*.txt)\n"
		"*.xml *.recipeml|RecipeML (*.xml, *.recipeml)\n"
		"*.rk *.txt|Rezkonv (*.rk, *.txt)"
		).arg( i18n("MasterCook Export format") )
		.arg( i18n("\"Now You're Cooking\" Generic Export format") ),
		this,
		0
	);
	file_dialog->setObjectName( "file_dialog" );
	file_dialog->setCaption( i18n( "Import from file" ) );
	file_dialog->setMode( KFile::Files );

	if ( file_dialog->exec() == KFileDialog::Accepted ) {
		QStringList warnings_list;

		QString selected_filter = file_dialog->currentFilter();

		BaseImporter *importer;
		if ( selected_filter == "*.mxp *.txt" )
			importer = new MXPImporter();
		else if ( selected_filter == "*.mmf *.txt" )
			importer = new MMFImporter();
		else if ( selected_filter == "*.txt" )
			importer = new NYCGenericImporter();
		else if ( selected_filter == "*.mx2" )
			importer = new MX2Importer();
		else if ( selected_filter == "*.kre *.kreml" )
			importer = new KreImporter();
		else if ( selected_filter == "*.xml *.recipeml" )
			importer = new RecipeMLImporter();
		else if ( selected_filter == "*.rk *.txt" )
			importer = new RezkonvImporter();
		else {
			KMessageBox::sorry( this,
				i18n( "Filter \"%1\" not recognized.\n"
				"Please select one of the provided filters."  , selected_filter ),
				i18n( "Unrecognized Filter" )
			);
			import(); //let's try again :)
			return ;
		}

		parsing_file_dlg->show();
		KApplication::setOverrideCursor( Qt::WaitCursor );
		importer->parseFiles( file_dialog->selectedFiles() );
		parsing_file_dlg->hide();
		KApplication::restoreOverrideCursor();

		KConfigGroup grp(KGlobal::config(),"Import");
		bool direct = grp.readEntry( "DirectImport", false );
		if ( !direct ) {
			QPointer<RecipeImportDialog> import_dialog = new RecipeImportDialog( importer->recipeList() );

			if ( import_dialog->exec() != QDialog::Accepted ) {
				delete importer;
				return;
			}
			else
				importer->setRecipeList( import_dialog->getSelectedRecipes() );

			delete import_dialog;
		}

		importer->import(m_view->database);
		//m_view->database->import( importer ); //TODO TESTS: Do it this way

		if ( !importer->getMessages().isEmpty() ) {
			KTextEdit * warningEdit = new KTextEdit( this );
			warningEdit->setText( i18n("<p>NOTE: We recommend that all recipes generating warnings be checked to ensure that they were properly imported, and no loss of recipe data has occurred.</p>" ) + importer->getMessages() );
			warningEdit->setReadOnly( true );

			//FIXME: This dialog should allow cancel the import.
			QPointer<KDialog> showWarningsDlg = new KDialog( this );
			showWarningsDlg->setCaption( i18n("Import Warnings") );
			showWarningsDlg->setButtons( KDialog::Ok );

			showWarningsDlg->setMainWidget( warningEdit ); //KDialog will delete warningEdit for us
			showWarningsDlg->resize( QSize( 550, 250 ) );
			showWarningsDlg->exec();
			delete showWarningsDlg;
		}

		delete importer;
	}

	delete file_dialog;
}
void Krecipes::import()
{
	QPointer<KFileDialog> file_dialog = new KFileDialog( KUrl(), QString(
		"*.kre *.kreml|Krecipes (*.kre, *.kreml)\n"
		"*.mx2|MasterCook (*.mx2)\n"
		"*.mxp *.txt|%1 (*.mxp, *.txt)\n"
		"*.mmf *.txt|Meal-Master (*.mmf, *.txt)\n"
		"*.txt|%2 (*.txt)\n"
		"*.xml *.recipeml|RecipeML (*.xml, *.recipeml)\n"
		"*.rk *.txt|Rezkonv (*.rk, *.txt)"
		).arg( i18n("MasterCook Export format") )
		.arg( i18n("\"Now You're Cooking\" Generic Export format") ),
		this,
		0
	);
	file_dialog->setObjectName( "file_dialog" );
	file_dialog->setCaption( i18n( "Import from file" ) );
	file_dialog->setMode( KFile::Files );

	if ( file_dialog->exec() == KFileDialog::Accepted ) {
		QStringList warnings_list;

		QString selected_filter = file_dialog->currentFilter();

		BaseImporter *importer;
		if ( selected_filter == "*.mxp *.txt" )
			importer = new MXPImporter();
		else if ( selected_filter == "*.mmf *.txt" )
			importer = new MMFImporter();
		else if ( selected_filter == "*.txt" )
			importer = new NYCGenericImporter();
		else if ( selected_filter == "*.mx2" )
			importer = new MX2Importer();
		else if ( selected_filter == "*.kre *.kreml" )
			importer = new KreImporter();
		else if ( selected_filter == "*.xml *.recipeml" )
			importer = new RecipeMLImporter();
		else if ( selected_filter == "*.rk *.txt" )
			importer = new RezkonvImporter();
		else {
			KMessageBox::sorry( this,
				i18n( "Filter \"%1\" not recognized.\n"
				"Please select one of the provided filters."  , selected_filter ),
				i18n( "Unrecognized Filter" )
			);
			import();  
			return ;
		}

		parsing_file_dlg->show();
		KApplication::setOverrideCursor( Qt::WaitCursor );
		importer->parseFiles( file_dialog->selectedFiles() );
		parsing_file_dlg->hide();
		KApplication::restoreOverrideCursor();

		KConfigGroup grp(KGlobal::config(),"Import");
		bool direct = grp.readEntry( "DirectImport", false );
		if ( !direct ) {
			QPointer<RecipeImportDialog> import_dialog = new RecipeImportDialog( importer->recipeList() );

			if ( import_dialog->exec() != QDialog::Accepted ) {
				delete importer;
				return;
			}
			else
				importer->setRecipeList( import_dialog->getSelectedRecipes() );

			delete import_dialog;
		}

		importer->import(m_view->database);
		 

		if ( !importer->getMessages().isEmpty() ) {
			KTextEdit * warningEdit = new KTextEdit( this );
			warningEdit->setText( i18n("<p>NOTE: We recommend that all recipes generating warnings be checked to ensure that they were properly imported, and no loss of recipe data has occurred.</p>" ) + importer->getMessages() );
			warningEdit->setReadOnly( true );

			 
			QPointer<KDialog> showWarningsDlg = new KDialog( this );
			showWarningsDlg->setCaption( i18n("Import Warnings") );
			showWarningsDlg->setButtons( KDialog::Ok );

			showWarningsDlg->setMainWidget( warningEdit );  
			showWarningsDlg->resize( QSize( 550, 250 ) );
			showWarningsDlg->exec();
			delete showWarningsDlg;
		}

		delete importer;
	}

	delete file_dialog;
}