imports.cpp
author insilmaril
Thu, 26 Mar 2009 07:50:32 +0000
changeset 747 008e72977ab8
parent 742 54d44ecd6097
child 775 6e4b586aa88a
permissions -rw-r--r--
Notes work again (to some degree)
insilmaril@215
     1
#include "file.h"
insilmaril@205
     2
#include "imports.h"
insilmaril@205
     3
#include "linkablemapobj.h"
insilmaril@205
     4
#include "misc.h"
insilmaril@205
     5
#include "mainwindow.h"
insilmaril@205
     6
#include "xsltproc.h"
insilmaril@205
     7
insilmaril@205
     8
extern Main *mainWindow;
insilmaril@215
     9
extern QDir vymBaseDir;
insilmaril@205
    10
insilmaril@205
    11
ImportBase::ImportBase()
insilmaril@205
    12
{
insilmaril@377
    13
	bool ok;
insilmaril@607
    14
    tmpDir.setPath (makeTmpDir(ok,"vym-import"));
insilmaril@377
    15
	if (!tmpDir.exists() || !ok)
insilmaril@377
    16
		QMessageBox::critical( 0, QObject::tr( "Error" ),
insilmaril@377
    17
					   QObject::tr("Couldn't access temporary directory\n"));
insilmaril@205
    18
}
insilmaril@205
    19
insilmaril@205
    20
insilmaril@205
    21
ImportBase::~ImportBase()
insilmaril@205
    22
{
insilmaril@205
    23
	// Remove tmpdir
insilmaril@228
    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@742
    53
bool ImportKDE3Bookmarks::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@742
    66
/////////////////////////////////////////////////
insilmaril@742
    67
bool ImportKDE4Bookmarks::transform()
insilmaril@742
    68
{
insilmaril@742
    69
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@742
    70
insilmaril@742
    71
	XSLTProc p;
insilmaril@742
    72
	p.setInputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
insilmaril@742
    73
	p.setOutputFile (transformedFile);
insilmaril@742
    74
	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
insilmaril@742
    75
	p.process();
insilmaril@742
    76
insilmaril@742
    77
	return true;
insilmaril@742
    78
}
insilmaril@742
    79
insilmaril@742
    80
insilmaril@215
    81
insilmaril@215
    82
/////////////////////////////////////////////////
insilmaril@312
    83
bool ImportFirefoxBookmarks::transform()
insilmaril@312
    84
{
insilmaril@312
    85
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@312
    86
insilmaril@326
    87
	QStringList lines;
insilmaril@326
    88
	QFile file( inputFile );
insilmaril@366
    89
	if ( file.open( QIODevice::ReadOnly ) ) 
insilmaril@326
    90
	{
insilmaril@326
    91
		QTextStream stream( &file );
insilmaril@326
    92
		while ( !stream.atEnd() ) 
insilmaril@326
    93
			lines += stream.readLine(); // line of text excluding '\n'
insilmaril@326
    94
		file.close();
insilmaril@326
    95
	}
insilmaril@393
    96
	// TODO Generate vym from broken bookmarks above...
insilmaril@312
    97
insilmaril@312
    98
	return true;
insilmaril@312
    99
}
insilmaril@312
   100
insilmaril@312
   101
/////////////////////////////////////////////////
insilmaril@215
   102
bool ImportMM::transform()
insilmaril@205
   103
{
insilmaril@215
   104
	// try to unzip 
insilmaril@215
   105
	if (success==unzipDir (tmpDir, inputFile))
insilmaril@215
   106
	{
insilmaril@215
   107
		
insilmaril@215
   108
		// Set short name, too. Search from behind:
insilmaril@215
   109
		transformedFile=inputFile;
insilmaril@215
   110
		int i=transformedFile.findRev("/");
insilmaril@215
   111
		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
insilmaril@215
   112
		transformedFile.replace(".mmap",".xml");
insilmaril@215
   113
		transformedFile=tmpDir.path()+"/"+transformedFile;
insilmaril@215
   114
insilmaril@215
   115
		XSLTProc p;
insilmaril@215
   116
		p.setInputFile (tmpDir.path()+"/Document.xml");
insilmaril@215
   117
		p.setOutputFile (transformedFile);
insilmaril@215
   118
		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
insilmaril@215
   119
		p.process();
insilmaril@215
   120
insilmaril@215
   121
		return true;
insilmaril@215
   122
	} else
insilmaril@215
   123
		return false;
insilmaril@215
   124
	
insilmaril@205
   125
}