imports.cpp
author insilmaril
Thu, 01 Jun 2006 11:19:57 +0000
changeset 343 f5c1cdf79e6e
parent 326 7758f3ceb98a
child 366 e95081c21da2
permissions -rw-r--r--
added warningdialog.ui
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@326
    71
	QStringList lines;
insilmaril@326
    72
	QFile file( inputFile );
insilmaril@326
    73
	if ( file.open( IO_ReadOnly ) ) 
insilmaril@326
    74
	{
insilmaril@326
    75
		QTextStream stream( &file );
insilmaril@326
    76
		while ( !stream.atEnd() ) 
insilmaril@326
    77
			lines += stream.readLine(); // line of text excluding '\n'
insilmaril@326
    78
		file.close();
insilmaril@326
    79
	}
insilmaril@326
    80
	// FIXME
insilmaril@326
    81
	// Generate vym from broken bookmarks above...
insilmaril@312
    82
insilmaril@312
    83
	return true;
insilmaril@312
    84
}
insilmaril@312
    85
insilmaril@312
    86
insilmaril@312
    87
/////////////////////////////////////////////////
insilmaril@215
    88
bool ImportMM::transform()
insilmaril@205
    89
{
insilmaril@215
    90
	// try to unzip 
insilmaril@215
    91
	if (success==unzipDir (tmpDir, inputFile))
insilmaril@215
    92
	{
insilmaril@215
    93
		cout << "Unzipped "<<inputFile<<" to "<<tmpDir.path()<<endl;
insilmaril@215
    94
		
insilmaril@215
    95
		// Set short name, too. Search from behind:
insilmaril@215
    96
		transformedFile=inputFile;
insilmaril@215
    97
		int i=transformedFile.findRev("/");
insilmaril@215
    98
		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
insilmaril@215
    99
		transformedFile.replace(".mmap",".xml");
insilmaril@215
   100
		transformedFile=tmpDir.path()+"/"+transformedFile;
insilmaril@215
   101
		cout << "  transformedFile="<<transformedFile<<endl;
insilmaril@215
   102
insilmaril@215
   103
		XSLTProc p;
insilmaril@215
   104
		p.setInputFile (tmpDir.path()+"/Document.xml");
insilmaril@215
   105
		p.setOutputFile (transformedFile);
insilmaril@215
   106
		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
insilmaril@215
   107
		p.process();
insilmaril@215
   108
insilmaril@215
   109
		cout << "  xslt done"<<endl;
insilmaril@215
   110
insilmaril@215
   111
		return true;
insilmaril@215
   112
	} else
insilmaril@215
   113
		return false;
insilmaril@215
   114
	
insilmaril@205
   115
}