imports.cpp
author insilmaril
Thu, 03 Sep 2009 08:52:00 +0000
changeset 790 133e2ed6b9c5
parent 775 6e4b586aa88a
permissions -rw-r--r--
More work on xLinks
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@215
    37
bool ImportBase::transform()
insilmaril@215
    38
{
insilmaril@215
    39
	return true;
insilmaril@215
    40
}
insilmaril@215
    41
insilmaril@215
    42
QString ImportBase::getTransformedFile()
insilmaril@215
    43
{
insilmaril@215
    44
	return transformedFile;
insilmaril@215
    45
}
insilmaril@215
    46
insilmaril@205
    47
/////////////////////////////////////////////////
insilmaril@742
    48
bool ImportKDE3Bookmarks::transform()
insilmaril@205
    49
{
insilmaril@205
    50
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@205
    51
insilmaril@205
    52
	XSLTProc p;
insilmaril@205
    53
	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@205
    54
	p.setOutputFile (transformedFile);
insilmaril@215
    55
	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
insilmaril@205
    56
	p.process();
insilmaril@215
    57
insilmaril@215
    58
	return true;
insilmaril@205
    59
}
insilmaril@205
    60
insilmaril@742
    61
/////////////////////////////////////////////////
insilmaril@742
    62
bool ImportKDE4Bookmarks::transform()
insilmaril@742
    63
{
insilmaril@742
    64
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@742
    65
insilmaril@742
    66
	XSLTProc p;
insilmaril@742
    67
	p.setInputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
insilmaril@742
    68
	p.setOutputFile (transformedFile);
insilmaril@742
    69
	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
insilmaril@742
    70
	p.process();
insilmaril@742
    71
insilmaril@742
    72
	return true;
insilmaril@742
    73
}
insilmaril@742
    74
insilmaril@742
    75
insilmaril@215
    76
insilmaril@215
    77
/////////////////////////////////////////////////
insilmaril@312
    78
bool ImportFirefoxBookmarks::transform()
insilmaril@312
    79
{
insilmaril@312
    80
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@312
    81
insilmaril@326
    82
	QStringList lines;
insilmaril@326
    83
	QFile file( inputFile );
insilmaril@366
    84
	if ( file.open( QIODevice::ReadOnly ) ) 
insilmaril@326
    85
	{
insilmaril@326
    86
		QTextStream stream( &file );
insilmaril@326
    87
		while ( !stream.atEnd() ) 
insilmaril@326
    88
			lines += stream.readLine(); // line of text excluding '\n'
insilmaril@326
    89
		file.close();
insilmaril@326
    90
	}
insilmaril@393
    91
	// TODO Generate vym from broken bookmarks above...
insilmaril@312
    92
insilmaril@312
    93
	return true;
insilmaril@312
    94
}
insilmaril@312
    95
insilmaril@312
    96
/////////////////////////////////////////////////
insilmaril@215
    97
bool ImportMM::transform()
insilmaril@205
    98
{
insilmaril@215
    99
	// try to unzip 
insilmaril@215
   100
	if (success==unzipDir (tmpDir, inputFile))
insilmaril@215
   101
	{
insilmaril@215
   102
		
insilmaril@215
   103
		// Set short name, too. Search from behind:
insilmaril@215
   104
		transformedFile=inputFile;
insilmaril@215
   105
		int i=transformedFile.findRev("/");
insilmaril@215
   106
		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
insilmaril@215
   107
		transformedFile.replace(".mmap",".xml");
insilmaril@215
   108
		transformedFile=tmpDir.path()+"/"+transformedFile;
insilmaril@215
   109
insilmaril@215
   110
		XSLTProc p;
insilmaril@215
   111
		p.setInputFile (tmpDir.path()+"/Document.xml");
insilmaril@215
   112
		p.setOutputFile (transformedFile);
insilmaril@215
   113
		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
insilmaril@215
   114
		p.process();
insilmaril@215
   115
insilmaril@215
   116
		return true;
insilmaril@215
   117
	} else
insilmaril@215
   118
		return false;
insilmaril@215
   119
	
insilmaril@205
   120
}