imports.cpp
author insilmaril
Mon, 10 Apr 2006 11:00:46 +0000
changeset 270 e7adc7586136
parent 228 654ad4b03c5a
child 312 d1d464798f08
permissions -rw-r--r--
switching to KDE icons
     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 	removeDir (tmpDir);
    24 }
    25 
    26 void ImportBase::setDir(const QString &p)
    27 {
    28 	inputDir=p;
    29 }
    30 
    31 void ImportBase::setFile (const QString &p)
    32 {
    33 	inputFile=p;
    34 }
    35 
    36 void ImportBase::setMapCenter(MapCenterObj *mc)
    37 {
    38 	mapCenter=mc;
    39 }
    40 
    41 bool ImportBase::transform()
    42 {
    43 	return true;
    44 }
    45 
    46 QString ImportBase::getTransformedFile()
    47 {
    48 	return transformedFile;
    49 }
    50 
    51 /////////////////////////////////////////////////
    52 bool ImportKDEBookmarks::transform()
    53 {
    54 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    55 
    56 	XSLTProc p;
    57 	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
    58 	p.setOutputFile (transformedFile);
    59 	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
    60 	p.process();
    61 
    62 	return true;
    63 }
    64 
    65 
    66 /////////////////////////////////////////////////
    67 bool ImportMM::transform()
    68 {
    69 	// try to unzip 
    70 	if (success==unzipDir (tmpDir, inputFile))
    71 	{
    72 		cout << "Unzipped "<<inputFile<<" to "<<tmpDir.path()<<endl;
    73 		
    74 		// Set short name, too. Search from behind:
    75 		transformedFile=inputFile;
    76 		int i=transformedFile.findRev("/");
    77 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
    78 		transformedFile.replace(".mmap",".xml");
    79 		transformedFile=tmpDir.path()+"/"+transformedFile;
    80 		cout << "  transformedFile="<<transformedFile<<endl;
    81 
    82 		XSLTProc p;
    83 		p.setInputFile (tmpDir.path()+"/Document.xml");
    84 		p.setOutputFile (transformedFile);
    85 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
    86 		p.process();
    87 
    88 		cout << "  xslt done"<<endl;
    89 
    90 		return true;
    91 	} else
    92 		return false;
    93 	
    94 }