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