imports.cpp
author insilmaril
Thu, 14 Sep 2006 11:38:18 +0000
changeset 388 3a58c9ef4a18
parent 377 5391ab620c95
child 393 053b8645e3e9
permissions -rw-r--r--
1.8.57 - more changes in history window, Note Editor is QT4 now
insilmaril@366
     1
#include <QMessageBox>
insilmaril@366
     2
//Added by qt3to4:
insilmaril@366
     3
#include <QTextStream>
insilmaril@205
     4
insilmaril@215
     5
#include "file.h"
insilmaril@205
     6
#include "imports.h"
insilmaril@205
     7
#include "linkablemapobj.h"
insilmaril@205
     8
#include "misc.h"
insilmaril@205
     9
#include "mainwindow.h"
insilmaril@205
    10
#include "xsltproc.h"
insilmaril@205
    11
insilmaril@205
    12
extern Main *mainWindow;
insilmaril@215
    13
extern QDir vymBaseDir;
insilmaril@205
    14
insilmaril@205
    15
ImportBase::ImportBase()
insilmaril@205
    16
{
insilmaril@377
    17
	bool ok;
insilmaril@377
    18
    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-XXXXXX"));
insilmaril@377
    19
	if (!tmpDir.exists() || !ok)
insilmaril@377
    20
		QMessageBox::critical( 0, QObject::tr( "Error" ),
insilmaril@377
    21
					   QObject::tr("Couldn't access temporary directory\n"));
insilmaril@205
    22
}
insilmaril@205
    23
insilmaril@205
    24
insilmaril@205
    25
ImportBase::~ImportBase()
insilmaril@205
    26
{
insilmaril@205
    27
	// Remove tmpdir
insilmaril@228
    28
	removeDir (tmpDir);
insilmaril@205
    29
}
insilmaril@205
    30
insilmaril@205
    31
void ImportBase::setDir(const QString &p)
insilmaril@205
    32
{
insilmaril@205
    33
	inputDir=p;
insilmaril@205
    34
}
insilmaril@205
    35
insilmaril@205
    36
void ImportBase::setFile (const QString &p)
insilmaril@205
    37
{
insilmaril@205
    38
	inputFile=p;
insilmaril@205
    39
}
insilmaril@205
    40
insilmaril@205
    41
void ImportBase::setMapCenter(MapCenterObj *mc)
insilmaril@205
    42
{
insilmaril@205
    43
	mapCenter=mc;
insilmaril@205
    44
}
insilmaril@205
    45
insilmaril@215
    46
bool ImportBase::transform()
insilmaril@215
    47
{
insilmaril@215
    48
	return true;
insilmaril@215
    49
}
insilmaril@215
    50
insilmaril@215
    51
QString ImportBase::getTransformedFile()
insilmaril@215
    52
{
insilmaril@215
    53
	return transformedFile;
insilmaril@215
    54
}
insilmaril@215
    55
insilmaril@205
    56
/////////////////////////////////////////////////
insilmaril@215
    57
bool ImportKDEBookmarks::transform()
insilmaril@205
    58
{
insilmaril@205
    59
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@205
    60
insilmaril@205
    61
	XSLTProc p;
insilmaril@205
    62
	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@205
    63
	p.setOutputFile (transformedFile);
insilmaril@215
    64
	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
insilmaril@205
    65
	p.process();
insilmaril@215
    66
insilmaril@215
    67
	return true;
insilmaril@205
    68
}
insilmaril@205
    69
insilmaril@215
    70
insilmaril@215
    71
/////////////////////////////////////////////////
insilmaril@312
    72
bool ImportFirefoxBookmarks::transform()
insilmaril@312
    73
{
insilmaril@312
    74
	transformedFile=tmpDir.path()+"/bookmarks.xml";
insilmaril@312
    75
insilmaril@326
    76
	QStringList lines;
insilmaril@326
    77
	QFile file( inputFile );
insilmaril@366
    78
	if ( file.open( QIODevice::ReadOnly ) ) 
insilmaril@326
    79
	{
insilmaril@326
    80
		QTextStream stream( &file );
insilmaril@326
    81
		while ( !stream.atEnd() ) 
insilmaril@326
    82
			lines += stream.readLine(); // line of text excluding '\n'
insilmaril@326
    83
		file.close();
insilmaril@326
    84
	}
insilmaril@326
    85
	// FIXME
insilmaril@326
    86
	// Generate vym from broken bookmarks above...
insilmaril@312
    87
insilmaril@312
    88
	return true;
insilmaril@312
    89
}
insilmaril@312
    90
insilmaril@312
    91
insilmaril@312
    92
/////////////////////////////////////////////////
insilmaril@215
    93
bool ImportMM::transform()
insilmaril@205
    94
{
insilmaril@215
    95
	// try to unzip 
insilmaril@215
    96
	if (success==unzipDir (tmpDir, inputFile))
insilmaril@215
    97
	{
insilmaril@215
    98
		
insilmaril@215
    99
		// Set short name, too. Search from behind:
insilmaril@215
   100
		transformedFile=inputFile;
insilmaril@215
   101
		int i=transformedFile.findRev("/");
insilmaril@215
   102
		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
insilmaril@215
   103
		transformedFile.replace(".mmap",".xml");
insilmaril@215
   104
		transformedFile=tmpDir.path()+"/"+transformedFile;
insilmaril@215
   105
insilmaril@215
   106
		XSLTProc p;
insilmaril@215
   107
		p.setInputFile (tmpDir.path()+"/Document.xml");
insilmaril@215
   108
		p.setOutputFile (transformedFile);
insilmaril@215
   109
		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
insilmaril@215
   110
		p.process();
insilmaril@215
   111
insilmaril@215
   112
		cout << "  xslt done"<<endl;
insilmaril@215
   113
insilmaril@215
   114
		return true;
insilmaril@215
   115
	} else
insilmaril@215
   116
		return false;
insilmaril@215
   117
	
insilmaril@205
   118
}