imports.cpp
author insilmaril
Tue, 13 Jun 2006 13:54:53 +0000
branchqt4-port
changeset 4 ec3d2962893d
parent 2 608f976aa7bb
child 19 caba269c3757
permissions -rw-r--r--
ported File Menu to QT4
     1 #include <qmessagebox.h>
     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 	tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
    19 }
    20 
    21 
    22 ImportBase::~ImportBase()
    23 {
    24 	// Remove tmpdir
    25 	removeDir (tmpDir);
    26 }
    27 
    28 void ImportBase::setDir(const QString &p)
    29 {
    30 	inputDir=p;
    31 }
    32 
    33 void ImportBase::setFile (const QString &p)
    34 {
    35 	inputFile=p;
    36 }
    37 
    38 void ImportBase::setMapCenter(MapCenterObj *mc)
    39 {
    40 	mapCenter=mc;
    41 }
    42 
    43 bool ImportBase::transform()
    44 {
    45 	return true;
    46 }
    47 
    48 QString ImportBase::getTransformedFile()
    49 {
    50 	return transformedFile;
    51 }
    52 
    53 /////////////////////////////////////////////////
    54 bool ImportKDEBookmarks::transform()
    55 {
    56 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    57 
    58 	XSLTProc p;
    59 	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
    60 	p.setOutputFile (transformedFile);
    61 	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    62 	p.process();
    63 
    64 	return true;
    65 }
    66 
    67 
    68 /////////////////////////////////////////////////
    69 bool ImportFirefoxBookmarks::transform()
    70 {
    71 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    72 
    73 	QStringList lines;
    74 	QFile file( inputFile );
    75 	if ( file.open( QIODevice::ReadOnly ) ) 
    76 	{
    77 		QTextStream stream( &file );
    78 		while ( !stream.atEnd() ) 
    79 			lines += stream.readLine(); // line of text excluding '\n'
    80 		file.close();
    81 	}
    82 	// FIXME
    83 	// Generate vym from broken bookmarks above...
    84 
    85 	return true;
    86 }
    87 
    88 
    89 /////////////////////////////////////////////////
    90 bool ImportMM::transform()
    91 {
    92 	// try to unzip 
    93 	if (success==unzipDir (tmpDir, inputFile))
    94 	{
    95 		
    96 		// Set short name, too. Search from behind:
    97 		transformedFile=inputFile;
    98 		int i=transformedFile.findRev("/");
    99 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
   100 		transformedFile.replace(".mmap",".xml");
   101 		transformedFile=tmpDir.path()+"/"+transformedFile;
   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 }