imports.cpp
author insilmaril
Mon, 14 Jan 2008 16:26:59 +0000
changeset 642 d35bd2241fd1
parent 607 53c66cb9f5bd
child 742 54d44ecd6097
permissions -rw-r--r--
Added french manual by Claude
     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 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 bool ImportMM::transform()
    88 {
    89 	// try to unzip 
    90 	if (success==unzipDir (tmpDir, inputFile))
    91 	{
    92 		
    93 		// Set short name, too. Search from behind:
    94 		transformedFile=inputFile;
    95 		int i=transformedFile.findRev("/");
    96 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
    97 		transformedFile.replace(".mmap",".xml");
    98 		transformedFile=tmpDir.path()+"/"+transformedFile;
    99 
   100 		XSLTProc p;
   101 		p.setInputFile (tmpDir.path()+"/Document.xml");
   102 		p.setOutputFile (transformedFile);
   103 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
   104 		p.process();
   105 
   106 		return true;
   107 	} else
   108 		return false;
   109 	
   110 }