imports.cpp
author insilmaril
Mon, 08 May 2006 13:25:46 +0000
changeset 315 866f79dfa6d7
parent 312 d1d464798f08
child 326 7758f3ceb98a
permissions -rw-r--r--
1.7.16 Small bugfixes
     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 ImportFirefoxBookmarks::transform()
    68 {
    69 	transformedFile=tmpDir.path()+"/bookmarks.xml";
    70 
    71 	XSLTProc p;
    72 	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
    73 	p.setOutputFile (transformedFile);
    74 	p.setXSLFile (vymBaseDir.path()+"/styles/firefoxbookmarks2vym.xsl");
    75 	p.process();
    76 
    77 	return true;
    78 }
    79 
    80 
    81 /////////////////////////////////////////////////
    82 bool ImportMM::transform()
    83 {
    84 	// try to unzip 
    85 	if (success==unzipDir (tmpDir, inputFile))
    86 	{
    87 		cout << "Unzipped "<<inputFile<<" to "<<tmpDir.path()<<endl;
    88 		
    89 		// Set short name, too. Search from behind:
    90 		transformedFile=inputFile;
    91 		int i=transformedFile.findRev("/");
    92 		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
    93 		transformedFile.replace(".mmap",".xml");
    94 		transformedFile=tmpDir.path()+"/"+transformedFile;
    95 		cout << "  transformedFile="<<transformedFile<<endl;
    96 
    97 		XSLTProc p;
    98 		p.setInputFile (tmpDir.path()+"/Document.xml");
    99 		p.setOutputFile (transformedFile);
   100 		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
   101 		p.process();
   102 
   103 		cout << "  xslt done"<<endl;
   104 
   105 		return true;
   106 	} else
   107 		return false;
   108 	
   109 }