insilmaril@62: #include "file.h" insilmaril@62: #include "imports.h" insilmaril@62: #include "linkablemapobj.h" insilmaril@62: #include "misc.h" insilmaril@62: #include "mainwindow.h" insilmaril@62: #include "xsltproc.h" insilmaril@62: insilmaril@62: extern Main *mainWindow; insilmaril@62: extern QDir vymBaseDir; insilmaril@62: insilmaril@62: ImportBase::ImportBase() insilmaril@62: { insilmaril@62: bool ok; insilmaril@62: tmpDir.setPath (makeTmpDir(ok,"vym-import")); insilmaril@62: if (!tmpDir.exists() || !ok) insilmaril@62: QMessageBox::critical( 0, QObject::tr( "Error" ), insilmaril@62: QObject::tr("Couldn't access temporary directory\n")); insilmaril@62: } insilmaril@62: insilmaril@62: insilmaril@62: ImportBase::~ImportBase() insilmaril@62: { insilmaril@62: // Remove tmpdir insilmaril@62: removeDir (tmpDir); insilmaril@62: } insilmaril@62: insilmaril@62: void ImportBase::setDir(const QString &p) insilmaril@62: { insilmaril@62: inputDir=p; insilmaril@62: } insilmaril@62: insilmaril@62: void ImportBase::setFile (const QString &p) insilmaril@62: { insilmaril@62: inputFile=p; insilmaril@62: } insilmaril@62: insilmaril@62: void ImportBase::setMapCenter(MapCenterObj *mc) insilmaril@62: { insilmaril@62: mapCenter=mc; insilmaril@62: } insilmaril@62: insilmaril@62: bool ImportBase::transform() insilmaril@62: { insilmaril@62: return true; insilmaril@62: } insilmaril@62: insilmaril@62: QString ImportBase::getTransformedFile() insilmaril@62: { insilmaril@62: return transformedFile; insilmaril@62: } insilmaril@62: insilmaril@62: ///////////////////////////////////////////////// insilmaril@62: bool ImportKDE3Bookmarks::transform() insilmaril@62: { insilmaril@62: transformedFile=tmpDir.path()+"/bookmarks.xml"; insilmaril@62: insilmaril@62: XSLTProc p; insilmaril@62: p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml"); insilmaril@62: p.setOutputFile (transformedFile); insilmaril@62: p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl"); insilmaril@62: p.process(); insilmaril@62: insilmaril@62: return true; insilmaril@62: } insilmaril@62: insilmaril@62: ///////////////////////////////////////////////// insilmaril@62: bool ImportKDE4Bookmarks::transform() insilmaril@62: { insilmaril@62: transformedFile=tmpDir.path()+"/bookmarks.xml"; insilmaril@62: insilmaril@62: XSLTProc p; insilmaril@62: p.setInputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml"); insilmaril@62: p.setOutputFile (transformedFile); insilmaril@62: p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl"); insilmaril@62: p.process(); insilmaril@62: insilmaril@62: return true; insilmaril@62: } insilmaril@62: insilmaril@62: insilmaril@62: insilmaril@62: ///////////////////////////////////////////////// insilmaril@62: bool ImportFirefoxBookmarks::transform() insilmaril@62: { insilmaril@62: transformedFile=tmpDir.path()+"/bookmarks.xml"; insilmaril@62: insilmaril@62: QStringList lines; insilmaril@62: QFile file( inputFile ); insilmaril@62: if ( file.open( QIODevice::ReadOnly ) ) insilmaril@62: { insilmaril@62: QTextStream stream( &file ); insilmaril@62: while ( !stream.atEnd() ) insilmaril@62: lines += stream.readLine(); // line of text excluding '\n' insilmaril@62: file.close(); insilmaril@62: } insilmaril@62: // TODO Generate vym from broken bookmarks above... insilmaril@62: insilmaril@62: return true; insilmaril@62: } insilmaril@62: insilmaril@62: ///////////////////////////////////////////////// insilmaril@62: bool ImportMM::transform() insilmaril@62: { insilmaril@62: // try to unzip insilmaril@62: if (success==unzipDir (tmpDir, inputFile)) insilmaril@62: { insilmaril@62: insilmaril@62: // Set short name, too. Search from behind: insilmaril@62: transformedFile=inputFile; insilmaril@62: int i=transformedFile.findRev("/"); insilmaril@62: if (i>=0) transformedFile=transformedFile.remove (0,i+1); insilmaril@62: transformedFile.replace(".mmap",".xml"); insilmaril@62: transformedFile=tmpDir.path()+"/"+transformedFile; insilmaril@62: insilmaril@62: XSLTProc p; insilmaril@62: p.setInputFile (tmpDir.path()+"/Document.xml"); insilmaril@62: p.setOutputFile (transformedFile); insilmaril@62: p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl"); insilmaril@62: p.process(); insilmaril@62: insilmaril@62: return true; insilmaril@62: } else insilmaril@62: return false; insilmaril@62: insilmaril@62: }