imports.cpp
author insilmaril
Fri, 09 Apr 2010 14:16:02 +0000
changeset 845 b98c1793bb8b
parent 775 6e4b586aa88a
permissions -rw-r--r--
XHTML export obsoleted by HTML export
     1 #include "file.h"
     2 #include "imports.h"
     3 #include "linkablemapobj.h"
     4 #include "misc.h"
     5 #include "mainwindow.h"
     6 #include "xsltproc.h"
     7 
     8 extern Main *mainWindow;
     9 extern QDir vymBaseDir;
    10 
    11 ImportBase::ImportBase()
    12 {
    13 	bool ok;
    14     tmpDir.setPath (makeTmpDir(ok,"vym-import"));
    15 	if (!tmpDir.exists() || !ok)
    16 		QMessageBox::critical( 0, QObject::tr( "Error" ),
    17 					   QObject::tr("Couldn't access temporary directory\n"));
    18 }
    19 
    20 
    21 ImportBase::~ImportBase()
    22 {
    23 	// Remove tmpdir
    24 	removeDir (tmpDir);
    25 }
    26 
    27 void ImportBase::setDir(const QString &p)
    28 {
    29 	inputDir=p;
    30 }
    31 
    32 void ImportBase::setFile (const QString &p)
    33 {
    34 	inputFile=p;
    35 }
    36 
    37 bool ImportBase::transform()
    38 {
    39 	return true;
    40 }
    41 
    42 QString ImportBase::getTransformedFile()
    43 {
    44 	return transformedFile;
    45 }
    46 
    47 /////////////////////////////////////////////////
    48 bool ImportKDE3Bookmarks::transform()
    49 {
    50 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    51 
    52 	XSLTProc p;
    53 	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
    54 	p.setOutputFile (transformedFile);
    55 	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    56 	p.process();
    57 
    58 	return true;
    59 }
    60 
    61 /////////////////////////////////////////////////
    62 bool ImportKDE4Bookmarks::transform()
    63 {
    64 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    65 
    66 	XSLTProc p;
    67 	p.setInputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
    68 	p.setOutputFile (transformedFile);
    69 	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    70 	p.process();
    71 
    72 	return true;
    73 }
    74 
    75 
    76 
    77 /////////////////////////////////////////////////
    78 bool ImportFirefoxBookmarks::transform()
    79 {
    80 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    81 
    82 	QStringList lines;
    83 	QFile file( inputFile );
    84 	if ( file.open( QIODevice::ReadOnly ) ) 
    85 	{
    86 		QTextStream stream( &file );
    87 		while ( !stream.atEnd() ) 
    88 			lines += stream.readLine(); // line of text excluding '\n'
    89 		file.close();
    90 	}
    91 	// TODO Generate vym from broken bookmarks above...
    92 
    93 	return true;
    94 }
    95 
    96 /////////////////////////////////////////////////
    97 bool ImportMM::transform()
    98 {
    99 	// try to unzip 
   100 	if (success==unzipDir (tmpDir, inputFile))
   101 	{
   102 		
   103 		// Set short name, too. Search from behind:
   104 		transformedFile=inputFile;
   105 		int i=transformedFile.findRev("/");
   106 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
   107 		transformedFile.replace(".mmap",".xml");
   108 		transformedFile=tmpDir.path()+"/"+transformedFile;
   109 
   110 		XSLTProc p;
   111 		p.setInputFile (tmpDir.path()+"/Document.xml");
   112 		p.setOutputFile (transformedFile);
   113 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
   114 		p.process();
   115 
   116 		return true;
   117 	} else
   118 		return false;
   119 	
   120 }