imports.cpp
author insilmaril
Mon, 18 May 2009 09:41:31 +0000
changeset 770 57ce1ba6d1cb
parent 742 54d44ecd6097
child 775 6e4b586aa88a
permissions -rw-r--r--
Fixed Standard Flags finally
     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 ImportKDE3Bookmarks::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 bool ImportKDE4Bookmarks::transform()
    68 {
    69 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    70 
    71 	XSLTProc p;
    72 	p.setInputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
    73 	p.setOutputFile (transformedFile);
    74 	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    75 	p.process();
    76 
    77 	return true;
    78 }
    79 
    80 
    81 
    82 /////////////////////////////////////////////////
    83 bool ImportFirefoxBookmarks::transform()
    84 {
    85 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    86 
    87 	QStringList lines;
    88 	QFile file( inputFile );
    89 	if ( file.open( QIODevice::ReadOnly ) ) 
    90 	{
    91 		QTextStream stream( &file );
    92 		while ( !stream.atEnd() ) 
    93 			lines += stream.readLine(); // line of text excluding '\n'
    94 		file.close();
    95 	}
    96 	// TODO Generate vym from broken bookmarks above...
    97 
    98 	return true;
    99 }
   100 
   101 /////////////////////////////////////////////////
   102 bool ImportMM::transform()
   103 {
   104 	// try to unzip 
   105 	if (success==unzipDir (tmpDir, inputFile))
   106 	{
   107 		
   108 		// Set short name, too. Search from behind:
   109 		transformedFile=inputFile;
   110 		int i=transformedFile.findRev("/");
   111 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
   112 		transformedFile.replace(".mmap",".xml");
   113 		transformedFile=tmpDir.path()+"/"+transformedFile;
   114 
   115 		XSLTProc p;
   116 		p.setInputFile (tmpDir.path()+"/Document.xml");
   117 		p.setOutputFile (transformedFile);
   118 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
   119 		p.process();
   120 
   121 		return true;
   122 	} else
   123 		return false;
   124 	
   125 }