imports.cpp
author insilmaril
Wed Mar 01 14:39:04 2006 +0000 (2006-03-01)
changeset 226 5e684bfe5bb1
parent 215 e211e2fc9d54
child 228 654ad4b03c5a
permissions -rw-r--r--
1.7.10 includeImagesHorizontally implemented
     1 #include <qmessagebox.h>
     2 
     3 #include "file.h"
     4 #include "imports.h"
     5 #include "linkablemapobj.h"
     6 #include "misc.h"
     7 #include "mainwindow.h"
     8 #include "xsltproc.h"
     9 
    10 extern Main *mainWindow;
    11 extern QDir vymBaseDir;
    12 
    13 ImportBase::ImportBase()
    14 {
    15 	// Create tmpdir
    16 	tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
    17 }
    18 
    19 
    20 ImportBase::~ImportBase()
    21 {
    22 	// Remove tmpdir
    23 	// FIXME just testing!
    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 ImportMM::transform()
    69 {
    70 	// try to unzip 
    71 	if (success==unzipDir (tmpDir, inputFile))
    72 	{
    73 		cout << "Unzipped "<<inputFile<<" to "<<tmpDir.path()<<endl;
    74 		
    75 		// Set short name, too. Search from behind:
    76 		transformedFile=inputFile;
    77 		int i=transformedFile.findRev("/");
    78 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
    79 		transformedFile.replace(".mmap",".xml");
    80 		transformedFile=tmpDir.path()+"/"+transformedFile;
    81 		cout << "  transformedFile="<<transformedFile<<endl;
    82 
    83 		XSLTProc p;
    84 		p.setInputFile (tmpDir.path()+"/Document.xml");
    85 		p.setOutputFile (transformedFile);
    86 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
    87 		p.process();
    88 
    89 		cout << "  xslt done"<<endl;
    90 
    91 		return true;
    92 	} else
    93 		return false;
    94 	
    95 }