author | insilmaril |
Tue, 04 Sep 2007 13:53:33 +0000 | |
changeset 595 | 0bd62e09d061 |
parent 570 | ab83f030285e |
child 607 | 53c66cb9f5bd |
permissions | -rw-r--r-- |
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@393 | 14 |
tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-import-XXXXXX")); |
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@215 | 53 |
bool ImportKDEBookmarks::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@215 | 66 |
|
insilmaril@215 | 67 |
///////////////////////////////////////////////// |
insilmaril@312 | 68 |
bool ImportFirefoxBookmarks::transform() |
insilmaril@312 | 69 |
{ |
insilmaril@312 | 70 |
transformedFile=tmpDir.path()+"/bookmarks.xml"; |
insilmaril@312 | 71 |
|
insilmaril@326 | 72 |
QStringList lines; |
insilmaril@326 | 73 |
QFile file( inputFile ); |
insilmaril@366 | 74 |
if ( file.open( QIODevice::ReadOnly ) ) |
insilmaril@326 | 75 |
{ |
insilmaril@326 | 76 |
QTextStream stream( &file ); |
insilmaril@326 | 77 |
while ( !stream.atEnd() ) |
insilmaril@326 | 78 |
lines += stream.readLine(); // line of text excluding '\n' |
insilmaril@326 | 79 |
file.close(); |
insilmaril@326 | 80 |
} |
insilmaril@393 | 81 |
// TODO Generate vym from broken bookmarks above... |
insilmaril@312 | 82 |
|
insilmaril@312 | 83 |
return true; |
insilmaril@312 | 84 |
} |
insilmaril@312 | 85 |
|
insilmaril@312 | 86 |
///////////////////////////////////////////////// |
insilmaril@215 | 87 |
bool ImportMM::transform() |
insilmaril@205 | 88 |
{ |
insilmaril@215 | 89 |
// try to unzip |
insilmaril@215 | 90 |
if (success==unzipDir (tmpDir, inputFile)) |
insilmaril@215 | 91 |
{ |
insilmaril@215 | 92 |
|
insilmaril@215 | 93 |
// Set short name, too. Search from behind: |
insilmaril@215 | 94 |
transformedFile=inputFile; |
insilmaril@215 | 95 |
int i=transformedFile.findRev("/"); |
insilmaril@215 | 96 |
if (i>=0) transformedFile=transformedFile.remove (0,i+1); |
insilmaril@215 | 97 |
transformedFile.replace(".mmap",".xml"); |
insilmaril@215 | 98 |
transformedFile=tmpDir.path()+"/"+transformedFile; |
insilmaril@215 | 99 |
|
insilmaril@215 | 100 |
XSLTProc p; |
insilmaril@215 | 101 |
p.setInputFile (tmpDir.path()+"/Document.xml"); |
insilmaril@215 | 102 |
p.setOutputFile (transformedFile); |
insilmaril@215 | 103 |
p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl"); |
insilmaril@215 | 104 |
p.process(); |
insilmaril@215 | 105 |
|
insilmaril@215 | 106 |
return true; |
insilmaril@215 | 107 |
} else |
insilmaril@215 | 108 |
return false; |
insilmaril@215 | 109 |
|
insilmaril@205 | 110 |
} |