imports.cpp
author insilmaril
Mon, 31 Jul 2006 12:13:53 +0000
changeset 361 a784c102bbed
parent 326 7758f3ceb98a
child 366 e95081c21da2
permissions -rw-r--r--
added vym2kdebookmarks.xsl
     1 #include <qmessagebox.h>
     2 
     3 #include "file.h"
     4 #include "imports.h"
     5 #include "linkablemapobj.h"
     6 #include "misc.h"
     7 #include "mainwindow.h"
     8 #include "xsltproc.h"
     9 
    10 extern Main *mainWindow;
    11 extern QDir vymBaseDir;
    12 
    13 ImportBase::ImportBase()
    14 {
    15 	// Create tmpdir
    16 	tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
    17 }
    18 
    19 
    20 ImportBase::~ImportBase()
    21 {
    22 	// Remove tmpdir
    23 	removeDir (tmpDir);
    24 }
    25 
    26 void ImportBase::setDir(const QString &p)
    27 {
    28 	inputDir=p;
    29 }
    30 
    31 void ImportBase::setFile (const QString &p)
    32 {
    33 	inputFile=p;
    34 }
    35 
    36 void ImportBase::setMapCenter(MapCenterObj *mc)
    37 {
    38 	mapCenter=mc;
    39 }
    40 
    41 bool ImportBase::transform()
    42 {
    43 	return true;
    44 }
    45 
    46 QString ImportBase::getTransformedFile()
    47 {
    48 	return transformedFile;
    49 }
    50 
    51 /////////////////////////////////////////////////
    52 bool ImportKDEBookmarks::transform()
    53 {
    54 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    55 
    56 	XSLTProc p;
    57 	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
    58 	p.setOutputFile (transformedFile);
    59 	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    60 	p.process();
    61 
    62 	return true;
    63 }
    64 
    65 
    66 /////////////////////////////////////////////////
    67 bool ImportFirefoxBookmarks::transform()
    68 {
    69 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    70 
    71 	QStringList lines;
    72 	QFile file( inputFile );
    73 	if ( file.open( IO_ReadOnly ) ) 
    74 	{
    75 		QTextStream stream( &file );
    76 		while ( !stream.atEnd() ) 
    77 			lines += stream.readLine(); // line of text excluding '\n'
    78 		file.close();
    79 	}
    80 	// FIXME
    81 	// Generate vym from broken bookmarks above...
    82 
    83 	return true;
    84 }
    85 
    86 
    87 /////////////////////////////////////////////////
    88 bool ImportMM::transform()
    89 {
    90 	// try to unzip 
    91 	if (success==unzipDir (tmpDir, inputFile))
    92 	{
    93 		cout << "Unzipped "<<inputFile<<" to "<<tmpDir.path()<<endl;
    94 		
    95 		// Set short name, too. Search from behind:
    96 		transformedFile=inputFile;
    97 		int i=transformedFile.findRev("/");
    98 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
    99 		transformedFile.replace(".mmap",".xml");
   100 		transformedFile=tmpDir.path()+"/"+transformedFile;
   101 		cout << "  transformedFile="<<transformedFile<<endl;
   102 
   103 		XSLTProc p;
   104 		p.setInputFile (tmpDir.path()+"/Document.xml");
   105 		p.setOutputFile (transformedFile);
   106 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
   107 		p.process();
   108 
   109 		cout << "  xslt done"<<endl;
   110 
   111 		return true;
   112 	} else
   113 		return false;
   114 	
   115 }