imports.cpp
author insilmaril
Tue, 23 Jan 2007 11:50:53 +0000
changeset 422 07a2f3f31101
parent 393 053b8645e3e9
child 570 ab83f030285e
permissions -rw-r--r--
1.8.65 Various fixes
     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 (makeUniqueDir(ok,"/tmp/vym-import-XXXXXX"));
    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 void ImportBase::setMapCenter(MapCenterObj *mc)
    38 {
    39 	mapCenter=mc;
    40 }
    41 
    42 bool ImportBase::transform()
    43 {
    44 	return true;
    45 }
    46 
    47 QString ImportBase::getTransformedFile()
    48 {
    49 	return transformedFile;
    50 }
    51 
    52 /////////////////////////////////////////////////
    53 bool ImportKDEBookmarks::transform()
    54 {
    55 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    56 
    57 	XSLTProc p;
    58 	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
    59 	p.setOutputFile (transformedFile);
    60 	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    61 	p.process();
    62 
    63 	return true;
    64 }
    65 
    66 
    67 /////////////////////////////////////////////////
    68 bool ImportFirefoxBookmarks::transform()
    69 {
    70 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    71 
    72 	QStringList lines;
    73 	QFile file( inputFile );
    74 	if ( file.open( QIODevice::ReadOnly ) ) 
    75 	{
    76 		QTextStream stream( &file );
    77 		while ( !stream.atEnd() ) 
    78 			lines += stream.readLine(); // line of text excluding '\n'
    79 		file.close();
    80 	}
    81 	// TODO 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 		
    94 		// Set short name, too. Search from behind:
    95 		transformedFile=inputFile;
    96 		int i=transformedFile.findRev("/");
    97 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
    98 		transformedFile.replace(".mmap",".xml");
    99 		transformedFile=tmpDir.path()+"/"+transformedFile;
   100 
   101 		XSLTProc p;
   102 		p.setInputFile (tmpDir.path()+"/Document.xml");
   103 		p.setOutputFile (transformedFile);
   104 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
   105 		p.process();
   106 
   107 		cout << "  xslt done"<<endl;
   108 
   109 		return true;
   110 	} else
   111 		return false;
   112 	
   113 }