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