exports.cpp
changeset 228 654ad4b03c5a
parent 205 30c4a6c7ff10
child 234 5115a9d93e86
     1.1 --- a/exports.cpp	Wed Mar 01 14:39:05 2006 +0000
     1.2 +++ b/exports.cpp	Tue Mar 07 11:32:00 2006 +0000
     1.3 @@ -1,3 +1,4 @@
     1.4 +#include <qfiledialog.h>
     1.5  #include <qmessagebox.h>
     1.6  
     1.7  #include "exports.h"
     1.8 @@ -5,12 +6,23 @@
     1.9  #include "linkablemapobj.h"
    1.10  #include "misc.h"
    1.11  #include "mainwindow.h"
    1.12 +#include "xsltproc.h"
    1.13  
    1.14  extern Main *mainWindow;
    1.15 +extern QDir vymBaseDir;
    1.16 +
    1.17  
    1.18  ExportBase::ExportBase()
    1.19  {
    1.20  	indentPerDepth="  ";
    1.21 +	// Create tmpdir
    1.22 +	tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
    1.23 +}
    1.24 +
    1.25 +ExportBase::~ExportBase()
    1.26 +{
    1.27 +	// Remove tmpdir
    1.28 +	removeDir (tmpDir);
    1.29  }
    1.30  
    1.31  void ExportBase::setDir(const QString &p)
    1.32 @@ -28,6 +40,57 @@
    1.33  	mapCenter=mc;
    1.34  }
    1.35  
    1.36 +void ExportBase::setCaption (const QString &s)
    1.37 +{
    1.38 +	caption=s;
    1.39 +}
    1.40 +
    1.41 +void ExportBase::addFilter(const QString &s)
    1.42 +{
    1.43 +	filter=s;
    1.44 +}
    1.45 +
    1.46 +bool ExportBase::execDialog()
    1.47 +{
    1.48 +	if (mapCenter && mapCenter->getMapEditor())
    1.49 +	{
    1.50 +		QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
    1.51 +		fd->addFilter (filter);
    1.52 +		fd->setCaption(caption);
    1.53 +		fd->setMode( QFileDialog::AnyFile );
    1.54 +		fd->show();
    1.55 +
    1.56 +		if ( fd->exec() == QDialog::Accepted )
    1.57 +		{
    1.58 +			if (QFile (fd->selectedFile()).exists() )
    1.59 +			{
    1.60 +				QMessageBox mb( __VYM,
    1.61 +					QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()), 
    1.62 +				QMessageBox::Warning,
    1.63 +				QMessageBox::Yes | QMessageBox::Default,
    1.64 +				QMessageBox::Cancel | QMessageBox::Escape,
    1.65 +				QMessageBox::NoButton );
    1.66 +				mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
    1.67 +				mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
    1.68 +				ExportBase ex;
    1.69 +				switch( mb.exec() ) 
    1.70 +				{
    1.71 +					case QMessageBox::Yes:
    1.72 +						// save 
    1.73 +						break;;
    1.74 +					case QMessageBox::Cancel:
    1.75 +						// return, do nothing
    1.76 +						return false;
    1.77 +						break;
    1.78 +				}
    1.79 +			}
    1.80 +			outputFile=fd->selectedFile();
    1.81 +			return true;
    1.82 +		}
    1.83 +	}
    1.84 +	return false;
    1.85 +}
    1.86 +
    1.87  QString ExportBase::getSectionString(BranchObj *bostart)
    1.88  {
    1.89  	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
    1.90 @@ -46,13 +109,13 @@
    1.91  		return r + " ";
    1.92  }
    1.93  
    1.94 -void ExportBase::exportXML()
    1.95 +void ExportASCII::doExport()
    1.96  {
    1.97  	QFile file (outputFile);
    1.98  	if ( !file.open( IO_WriteOnly ) )
    1.99  	{
   1.100  		// FIXME experimental, testing
   1.101 -		cout << "ExportBase::exportXML  couldn't open "<<outputFile<<endl;
   1.102 +		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
   1.103  		return;
   1.104  	}
   1.105  	QTextStream ts( &file );	// use LANG decoding here...
   1.106 @@ -95,7 +158,26 @@
   1.107  	file.close();
   1.108  }
   1.109  
   1.110 -void ExportLaTeX::exportLaTeX() 
   1.111 +void ExportTaskjuggler::doExport() 
   1.112 +{
   1.113 +	MapEditor *me=NULL;
   1.114 +	if (mapCenter) me=mapCenter->getMapEditor();
   1.115 +	if (me)
   1.116 +	{
   1.117 +		me->exportXML(tmpDir.path());
   1.118 +		//FIXME testing
   1.119 +		cout << "tmpDir="<<tmpDir.path()<<endl;
   1.120 +
   1.121 +		XSLTProc p;
   1.122 +		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
   1.123 +		p.setOutputFile (outputFile);
   1.124 +		p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
   1.125 +		p.process();
   1.126 +	}
   1.127 +
   1.128 +}
   1.129 +
   1.130 +void ExportLaTeX::doExport() 
   1.131  {
   1.132  	// Exports a map to a LaTex file.  
   1.133  	// This file needs to be included 
   1.134 @@ -149,14 +231,10 @@
   1.135  ExportOO::ExportOO()
   1.136  {
   1.137  	useSections=false;
   1.138 -	// Create tmpdir
   1.139 -	tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
   1.140  }
   1.141  
   1.142  ExportOO::~ExportOO()
   1.143  {
   1.144 -	// Remove tmpdir
   1.145 -	removeDir (tmpDir);
   1.146  }	
   1.147  
   1.148  QString ExportOO::buildList (BranchObj *current)