1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imports.cpp Mon Nov 16 09:07:17 2009 +0000
1.3 @@ -0,0 +1,125 @@
1.4 +#include "file.h"
1.5 +#include "imports.h"
1.6 +#include "linkablemapobj.h"
1.7 +#include "misc.h"
1.8 +#include "mainwindow.h"
1.9 +#include "xsltproc.h"
1.10 +
1.11 +extern Main *mainWindow;
1.12 +extern QDir vymBaseDir;
1.13 +
1.14 +ImportBase::ImportBase()
1.15 +{
1.16 + bool ok;
1.17 + tmpDir.setPath (makeTmpDir(ok,"vym-import"));
1.18 + if (!tmpDir.exists() || !ok)
1.19 + QMessageBox::critical( 0, QObject::tr( "Error" ),
1.20 + QObject::tr("Couldn't access temporary directory\n"));
1.21 +}
1.22 +
1.23 +
1.24 +ImportBase::~ImportBase()
1.25 +{
1.26 + // Remove tmpdir
1.27 + removeDir (tmpDir);
1.28 +}
1.29 +
1.30 +void ImportBase::setDir(const QString &p)
1.31 +{
1.32 + inputDir=p;
1.33 +}
1.34 +
1.35 +void ImportBase::setFile (const QString &p)
1.36 +{
1.37 + inputFile=p;
1.38 +}
1.39 +
1.40 +void ImportBase::setMapCenter(MapCenterObj *mc)
1.41 +{
1.42 + mapCenter=mc;
1.43 +}
1.44 +
1.45 +bool ImportBase::transform()
1.46 +{
1.47 + return true;
1.48 +}
1.49 +
1.50 +QString ImportBase::getTransformedFile()
1.51 +{
1.52 + return transformedFile;
1.53 +}
1.54 +
1.55 +/////////////////////////////////////////////////
1.56 +bool ImportKDE3Bookmarks::transform()
1.57 +{
1.58 + transformedFile=tmpDir.path()+"/bookmarks.xml";
1.59 +
1.60 + XSLTProc p;
1.61 + p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
1.62 + p.setOutputFile (transformedFile);
1.63 + p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
1.64 + p.process();
1.65 +
1.66 + return true;
1.67 +}
1.68 +
1.69 +/////////////////////////////////////////////////
1.70 +bool ImportKDE4Bookmarks::transform()
1.71 +{
1.72 + transformedFile=tmpDir.path()+"/bookmarks.xml";
1.73 +
1.74 + XSLTProc p;
1.75 + p.setInputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
1.76 + p.setOutputFile (transformedFile);
1.77 + p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
1.78 + p.process();
1.79 +
1.80 + return true;
1.81 +}
1.82 +
1.83 +
1.84 +
1.85 +/////////////////////////////////////////////////
1.86 +bool ImportFirefoxBookmarks::transform()
1.87 +{
1.88 + transformedFile=tmpDir.path()+"/bookmarks.xml";
1.89 +
1.90 + QStringList lines;
1.91 + QFile file( inputFile );
1.92 + if ( file.open( QIODevice::ReadOnly ) )
1.93 + {
1.94 + QTextStream stream( &file );
1.95 + while ( !stream.atEnd() )
1.96 + lines += stream.readLine(); // line of text excluding '\n'
1.97 + file.close();
1.98 + }
1.99 + // TODO Generate vym from broken bookmarks above...
1.100 +
1.101 + return true;
1.102 +}
1.103 +
1.104 +/////////////////////////////////////////////////
1.105 +bool ImportMM::transform()
1.106 +{
1.107 + // try to unzip
1.108 + if (success==unzipDir (tmpDir, inputFile))
1.109 + {
1.110 +
1.111 + // Set short name, too. Search from behind:
1.112 + transformedFile=inputFile;
1.113 + int i=transformedFile.findRev("/");
1.114 + if (i>=0) transformedFile=transformedFile.remove (0,i+1);
1.115 + transformedFile.replace(".mmap",".xml");
1.116 + transformedFile=tmpDir.path()+"/"+transformedFile;
1.117 +
1.118 + XSLTProc p;
1.119 + p.setInputFile (tmpDir.path()+"/Document.xml");
1.120 + p.setOutputFile (transformedFile);
1.121 + p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
1.122 + p.process();
1.123 +
1.124 + return true;
1.125 + } else
1.126 + return false;
1.127 +
1.128 +}