imports.cpp
author insilmaril
Fri Mar 05 19:15:08 2010 +0000 (2010-03-05)
branchrelease-1-12-maintained
changeset 79 32f499cbe874
permissions -rw-r--r--
Fixed changelog
insilmaril@62
     1
#include "file.h"
insilmaril@62
     2
#include "imports.h"
insilmaril@62
     3
#include "linkablemapobj.h"
insilmaril@62
     4
#include "misc.h"
insilmaril@62
     5
#include "mainwindow.h"
insilmaril@62
     6
#include "xsltproc.h"
insilmaril@62
     7
insilmaril@62
     8
extern Main *mainWindow;
insilmaril@62
     9
extern QDir vymBaseDir;
insilmaril@62
    10
insilmaril@62
    11
ImportBase::ImportBase()
insilmaril@62
    12
{
insilmaril@62
    13
	bool ok;
insilmaril@62
    14
    tmpDir.setPath (makeTmpDir(ok,"vym-import"));
insilmaril@62
    15
	if (!tmpDir.exists() || !ok)
insilmaril@62
    16
		QMessageBox::critical( 0, QObject::tr( "Error" ),
insilmaril@62
    17
					   QObject::tr("Couldn't access temporary directory\n"));
insilmaril@62
    18
}
insilmaril@62
    19
insilmaril@62
    20
insilmaril@62
    21
ImportBase::~ImportBase()
insilmaril@62
    22
{
insilmaril@62
    23
	// Remove tmpdir
insilmaril@62
    24
	removeDir (tmpDir);
insilmaril@62
    25
}
insilmaril@62
    26
insilmaril@62
    27
void ImportBase::setDir(const QString &p)
insilmaril@62
    28
{
insilmaril@62
    29
	inputDir=p;
insilmaril@62
    30
}
insilmaril@62
    31
insilmaril@62
    32
void ImportBase::setFile (const QString &p)
insilmaril@62
    33
{
insilmaril@62
    34
	inputFile=p;
insilmaril@62
    35
}
insilmaril@62
    36
insilmaril@62
    37
void ImportBase::setMapCenter(MapCenterObj *mc)
insilmaril@62
    38
{
insilmaril@62
    39
	mapCenter=mc;
insilmaril@62
    40
}
insilmaril@62
    41
insilmaril@62
    42
bool ImportBase::transform()
insilmaril@62
    43
{
insilmaril@62
    44
	return true;
insilmaril@62
    45
}
insilmaril@62
    46
insilmaril@62
    47
QString ImportBase::getTransformedFile()
insilmaril@62
    48
{
insilmaril@62
    49
	return transformedFile;
insilmaril@62
    50
}
insilmaril@62
    51
insilmaril@62
    52
/////////////////////////////////////////////////
insilmaril@62
    53
bool ImportKDE3Bookmarks::transform()
insilmaril@62
    54
{
insilmaril@62
    55
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@62
    56
insilmaril@62
    57
	XSLTProc p;
insilmaril@62
    58
	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@62
    59
	p.setOutputFile (transformedFile);
insilmaril@62
    60
	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
insilmaril@62
    61
	p.process();
insilmaril@62
    62
insilmaril@62
    63
	return true;
insilmaril@62
    64
}
insilmaril@62
    65
insilmaril@62
    66
/////////////////////////////////////////////////
insilmaril@62
    67
bool ImportKDE4Bookmarks::transform()
insilmaril@62
    68
{
insilmaril@62
    69
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@62
    70
insilmaril@62
    71
	XSLTProc p;
insilmaril@62
    72
	p.setInputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
insilmaril@62
    73
	p.setOutputFile (transformedFile);
insilmaril@62
    74
	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
insilmaril@62
    75
	p.process();
insilmaril@62
    76
insilmaril@62
    77
	return true;
insilmaril@62
    78
}
insilmaril@62
    79
insilmaril@62
    80
insilmaril@62
    81
insilmaril@62
    82
/////////////////////////////////////////////////
insilmaril@62
    83
bool ImportFirefoxBookmarks::transform()
insilmaril@62
    84
{
insilmaril@62
    85
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@62
    86
insilmaril@62
    87
	QStringList lines;
insilmaril@62
    88
	QFile file( inputFile );
insilmaril@62
    89
	if ( file.open( QIODevice::ReadOnly ) ) 
insilmaril@62
    90
	{
insilmaril@62
    91
		QTextStream stream( &file );
insilmaril@62
    92
		while ( !stream.atEnd() ) 
insilmaril@62
    93
			lines += stream.readLine(); // line of text excluding '\n'
insilmaril@62
    94
		file.close();
insilmaril@62
    95
	}
insilmaril@62
    96
	// TODO Generate vym from broken bookmarks above...
insilmaril@62
    97
insilmaril@62
    98
	return true;
insilmaril@62
    99
}
insilmaril@62
   100
insilmaril@62
   101
/////////////////////////////////////////////////
insilmaril@62
   102
bool ImportMM::transform()
insilmaril@62
   103
{
insilmaril@62
   104
	// try to unzip 
insilmaril@62
   105
	if (success==unzipDir (tmpDir, inputFile))
insilmaril@62
   106
	{
insilmaril@62
   107
		
insilmaril@62
   108
		// Set short name, too. Search from behind:
insilmaril@62
   109
		transformedFile=inputFile;
insilmaril@62
   110
		int i=transformedFile.findRev("/");
insilmaril@62
   111
		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
insilmaril@62
   112
		transformedFile.replace(".mmap",".xml");
insilmaril@62
   113
		transformedFile=tmpDir.path()+"/"+transformedFile;
insilmaril@62
   114
insilmaril@62
   115
		XSLTProc p;
insilmaril@62
   116
		p.setInputFile (tmpDir.path()+"/Document.xml");
insilmaril@62
   117
		p.setOutputFile (transformedFile);
insilmaril@62
   118
		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
insilmaril@62
   119
		p.process();
insilmaril@62
   120
insilmaril@62
   121
		return true;
insilmaril@62
   122
	} else
insilmaril@62
   123
		return false;
insilmaril@62
   124
	
insilmaril@62
   125
}