imports.cpp
branchqt4-port
changeset 10 e2a80d9b5858
child 19 caba269c3757
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/imports.cpp	Thu Jul 06 15:39:54 2006 +0000
     1.3 @@ -0,0 +1,115 @@
     1.4 +#include <qmessagebox.h>
     1.5 +//Added by qt3to4:
     1.6 +#include <QTextStream>
     1.7 +
     1.8 +#include "file.h"
     1.9 +#include "imports.h"
    1.10 +#include "linkablemapobj.h"
    1.11 +#include "misc.h"
    1.12 +#include "mainwindow.h"
    1.13 +#include "xsltproc.h"
    1.14 +
    1.15 +extern Main *mainWindow;
    1.16 +extern QDir vymBaseDir;
    1.17 +
    1.18 +ImportBase::ImportBase()
    1.19 +{
    1.20 +	// Create tmpdir
    1.21 +	tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
    1.22 +}
    1.23 +
    1.24 +
    1.25 +ImportBase::~ImportBase()
    1.26 +{
    1.27 +	// Remove tmpdir
    1.28 +	removeDir (tmpDir);
    1.29 +}
    1.30 +
    1.31 +void ImportBase::setDir(const QString &p)
    1.32 +{
    1.33 +	inputDir=p;
    1.34 +}
    1.35 +
    1.36 +void ImportBase::setFile (const QString &p)
    1.37 +{
    1.38 +	inputFile=p;
    1.39 +}
    1.40 +
    1.41 +void ImportBase::setMapCenter(MapCenterObj *mc)
    1.42 +{
    1.43 +	mapCenter=mc;
    1.44 +}
    1.45 +
    1.46 +bool ImportBase::transform()
    1.47 +{
    1.48 +	return true;
    1.49 +}
    1.50 +
    1.51 +QString ImportBase::getTransformedFile()
    1.52 +{
    1.53 +	return transformedFile;
    1.54 +}
    1.55 +
    1.56 +/////////////////////////////////////////////////
    1.57 +bool ImportKDEBookmarks::transform()
    1.58 +{
    1.59 +	transformedFile=tmpDir.path()+"/bookmarks.xml";
    1.60 +
    1.61 +	XSLTProc p;
    1.62 +	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
    1.63 +	p.setOutputFile (transformedFile);
    1.64 +	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    1.65 +	p.process();
    1.66 +
    1.67 +	return true;
    1.68 +}
    1.69 +
    1.70 +
    1.71 +/////////////////////////////////////////////////
    1.72 +bool ImportFirefoxBookmarks::transform()
    1.73 +{
    1.74 +	transformedFile=tmpDir.path()+"/bookmarks.xml";
    1.75 +
    1.76 +	QStringList lines;
    1.77 +	QFile file( inputFile );
    1.78 +	if ( file.open( QIODevice::ReadOnly ) ) 
    1.79 +	{
    1.80 +		QTextStream stream( &file );
    1.81 +		while ( !stream.atEnd() ) 
    1.82 +			lines += stream.readLine(); // line of text excluding '\n'
    1.83 +		file.close();
    1.84 +	}
    1.85 +	// FIXME
    1.86 +	// Generate vym from broken bookmarks above...
    1.87 +
    1.88 +	return true;
    1.89 +}
    1.90 +
    1.91 +
    1.92 +/////////////////////////////////////////////////
    1.93 +bool ImportMM::transform()
    1.94 +{
    1.95 +	// try to unzip 
    1.96 +	if (success==unzipDir (tmpDir, inputFile))
    1.97 +	{
    1.98 +		
    1.99 +		// Set short name, too. Search from behind:
   1.100 +		transformedFile=inputFile;
   1.101 +		int i=transformedFile.findRev("/");
   1.102 +		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
   1.103 +		transformedFile.replace(".mmap",".xml");
   1.104 +		transformedFile=tmpDir.path()+"/"+transformedFile;
   1.105 +
   1.106 +		XSLTProc p;
   1.107 +		p.setInputFile (tmpDir.path()+"/Document.xml");
   1.108 +		p.setOutputFile (transformedFile);
   1.109 +		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
   1.110 +		p.process();
   1.111 +
   1.112 +		cout << "  xslt done"<<endl;
   1.113 +
   1.114 +		return true;
   1.115 +	} else
   1.116 +		return false;
   1.117 +	
   1.118 +}