imports.cpp
author insilmaril
Wed, 01 Mar 2006 14:39:04 +0000
changeset 224 bbb4eeefcc94
parent 218 160459d924a1
child 228 654ad4b03c5a
permissions -rw-r--r--
1.7.10 includeImagesHorizontally implemented
insilmaril@205
     1
#include <qmessagebox.h>
insilmaril@205
     2
insilmaril@215
     3
#include "file.h"
insilmaril@205
     4
#include "imports.h"
insilmaril@205
     5
#include "linkablemapobj.h"
insilmaril@205
     6
#include "misc.h"
insilmaril@205
     7
#include "mainwindow.h"
insilmaril@205
     8
#include "xsltproc.h"
insilmaril@205
     9
insilmaril@205
    10
extern Main *mainWindow;
insilmaril@215
    11
extern QDir vymBaseDir;
insilmaril@205
    12
insilmaril@205
    13
ImportBase::ImportBase()
insilmaril@205
    14
{
insilmaril@205
    15
	// Create tmpdir
insilmaril@205
    16
	tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
insilmaril@205
    17
}
insilmaril@205
    18
insilmaril@205
    19
insilmaril@205
    20
ImportBase::~ImportBase()
insilmaril@205
    21
{
insilmaril@205
    22
	// Remove tmpdir
insilmaril@218
    23
	// FIXME just testing!
insilmaril@215
    24
	//removeDir (tmpDir);
insilmaril@205
    25
}
insilmaril@205
    26
insilmaril@205
    27
void ImportBase::setDir(const QString &p)
insilmaril@205
    28
{
insilmaril@205
    29
	inputDir=p;
insilmaril@205
    30
}
insilmaril@205
    31
insilmaril@205
    32
void ImportBase::setFile (const QString &p)
insilmaril@205
    33
{
insilmaril@205
    34
	inputFile=p;
insilmaril@205
    35
}
insilmaril@205
    36
insilmaril@205
    37
void ImportBase::setMapCenter(MapCenterObj *mc)
insilmaril@205
    38
{
insilmaril@205
    39
	mapCenter=mc;
insilmaril@205
    40
}
insilmaril@205
    41
insilmaril@215
    42
bool ImportBase::transform()
insilmaril@215
    43
{
insilmaril@215
    44
	return true;
insilmaril@215
    45
}
insilmaril@215
    46
insilmaril@215
    47
QString ImportBase::getTransformedFile()
insilmaril@215
    48
{
insilmaril@215
    49
	return transformedFile;
insilmaril@215
    50
}
insilmaril@215
    51
insilmaril@205
    52
/////////////////////////////////////////////////
insilmaril@215
    53
bool ImportKDEBookmarks::transform()
insilmaril@205
    54
{
insilmaril@205
    55
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@205
    56
insilmaril@205
    57
	XSLTProc p;
insilmaril@205
    58
	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@205
    59
	p.setOutputFile (transformedFile);
insilmaril@215
    60
	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
insilmaril@205
    61
	p.process();
insilmaril@215
    62
insilmaril@215
    63
	return true;
insilmaril@205
    64
}
insilmaril@205
    65
insilmaril@215
    66
insilmaril@215
    67
/////////////////////////////////////////////////
insilmaril@215
    68
bool ImportMM::transform()
insilmaril@205
    69
{
insilmaril@215
    70
	// try to unzip 
insilmaril@215
    71
	if (success==unzipDir (tmpDir, inputFile))
insilmaril@215
    72
	{
insilmaril@215
    73
		cout << "Unzipped "<<inputFile<<" to "<<tmpDir.path()<<endl;
insilmaril@215
    74
		
insilmaril@215
    75
		// Set short name, too. Search from behind:
insilmaril@215
    76
		transformedFile=inputFile;
insilmaril@215
    77
		int i=transformedFile.findRev("/");
insilmaril@215
    78
		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
insilmaril@215
    79
		transformedFile.replace(".mmap",".xml");
insilmaril@215
    80
		transformedFile=tmpDir.path()+"/"+transformedFile;
insilmaril@215
    81
		cout << "  transformedFile="<<transformedFile<<endl;
insilmaril@215
    82
insilmaril@215
    83
		XSLTProc p;
insilmaril@215
    84
		p.setInputFile (tmpDir.path()+"/Document.xml");
insilmaril@215
    85
		p.setOutputFile (transformedFile);
insilmaril@215
    86
		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
insilmaril@215
    87
		p.process();
insilmaril@215
    88
insilmaril@215
    89
		cout << "  xslt done"<<endl;
insilmaril@215
    90
insilmaril@215
    91
		return true;
insilmaril@215
    92
	} else
insilmaril@215
    93
		return false;
insilmaril@215
    94
	
insilmaril@205
    95
}