insilmaril@0: #include "exports.h" insilmaril@750: insilmaril@750: #include "branchitem.h" insilmaril@171: #include "file.h" insilmaril@171: #include "linkablemapobj.h" insilmaril@171: #include "misc.h" insilmaril@171: #include "mainwindow.h" insilmaril@311: #include "warningdialog.h" insilmaril@228: #include "xsltproc.h" insilmaril@0: insilmaril@824: insilmaril@171: extern Main *mainWindow; insilmaril@228: extern QDir vymBaseDir; insilmaril@404: extern QString vymName; insilmaril@131: insilmaril@171: ExportBase::ExportBase() insilmaril@0: { insilmaril@819: init(); insilmaril@819: } insilmaril@819: insilmaril@819: ExportBase::ExportBase(VymModel *m) insilmaril@819: { insilmaril@819: init(); insilmaril@819: model=m; insilmaril@819: } insilmaril@819: insilmaril@819: ExportBase::~ExportBase() insilmaril@819: { insilmaril@819: // Cleanup tmpdir insilmaril@819: removeDir (tmpDir); insilmaril@819: } insilmaril@819: insilmaril@819: void ExportBase::init() insilmaril@819: { insilmaril@0: indentPerDepth=" "; insilmaril@377: bool ok; insilmaril@606: tmpDir.setPath (makeTmpDir(ok,"vym-export")); insilmaril@377: if (!tmpDir.exists() || !ok) insilmaril@377: QMessageBox::critical( 0, QObject::tr( "Error" ), insilmaril@377: QObject::tr("Couldn't access temporary directory\n")); insilmaril@512: cancelFlag=false; insilmaril@228: } insilmaril@228: insilmaril@424: void ExportBase::setDir(const QDir &d) insilmaril@0: { insilmaril@424: outDir=d; insilmaril@199: } insilmaril@199: insilmaril@199: void ExportBase::setFile (const QString &p) insilmaril@199: { insilmaril@199: outputFile=p; insilmaril@0: } insilmaril@0: insilmaril@512: QString ExportBase::getFile () insilmaril@512: { insilmaril@512: return outputFile; insilmaril@512: } insilmaril@512: insilmaril@643: void ExportBase::setModel(VymModel *m) insilmaril@0: { insilmaril@643: model=m; insilmaril@0: } insilmaril@0: insilmaril@228: void ExportBase::setCaption (const QString &s) insilmaril@228: { insilmaril@228: caption=s; insilmaril@228: } insilmaril@228: insilmaril@228: void ExportBase::addFilter(const QString &s) insilmaril@228: { insilmaril@228: filter=s; insilmaril@228: } insilmaril@228: insilmaril@228: bool ExportBase::execDialog() insilmaril@228: { insilmaril@228: { insilmaril@643: QFileDialog *fd=new QFileDialog( 0, caption); insilmaril@366: fd->setFilter (filter); insilmaril@228: fd->setCaption(caption); insilmaril@228: fd->setMode( QFileDialog::AnyFile ); insilmaril@424: fd->setDir (outDir); insilmaril@228: fd->show(); insilmaril@228: insilmaril@228: if ( fd->exec() == QDialog::Accepted ) insilmaril@228: { insilmaril@228: if (QFile (fd->selectedFile()).exists() ) insilmaril@228: { insilmaril@404: QMessageBox mb( vymName, insilmaril@228: QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()), insilmaril@228: QMessageBox::Warning, insilmaril@228: QMessageBox::Yes | QMessageBox::Default, insilmaril@228: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@366: Qt::NoButton ); insilmaril@228: mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") ); insilmaril@228: mb.setButtonText( QMessageBox::No, QObject::tr("Cancel")); insilmaril@228: ExportBase ex; insilmaril@228: switch( mb.exec() ) insilmaril@228: { insilmaril@228: case QMessageBox::Yes: insilmaril@228: // save insilmaril@228: break;; insilmaril@228: case QMessageBox::Cancel: insilmaril@512: cancelFlag=true; insilmaril@228: return false; insilmaril@228: break; insilmaril@228: } insilmaril@228: } insilmaril@228: outputFile=fd->selectedFile(); insilmaril@512: cancelFlag=false; insilmaril@228: return true; insilmaril@228: } insilmaril@228: } insilmaril@228: return false; insilmaril@228: } insilmaril@228: insilmaril@512: bool ExportBase::canceled() insilmaril@512: { insilmaril@512: return cancelFlag; insilmaril@512: } insilmaril@512: insilmaril@791: QString ExportBase::getSectionString(TreeItem *start) insilmaril@163: { insilmaril@205: // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3" insilmaril@163: QString r; insilmaril@791: TreeItem *ti=start; insilmaril@749: int depth=ti->depth(); insilmaril@163: while (depth>0) insilmaril@163: { insilmaril@749: r=QString("%1").arg(1+ti->num(),0,10)+"." + r; insilmaril@749: ti=ti->parent(); insilmaril@749: depth=ti->depth(); insilmaril@163: } insilmaril@163: if (r.isEmpty()) insilmaril@163: return r; insilmaril@163: else insilmaril@163: return r + " "; insilmaril@163: } insilmaril@163: insilmaril@239: //////////////////////////////////////////////////////////////////////// insilmaril@807: ExportAO::ExportAO() insilmaril@807: { insilmaril@807: filter="TXT (*.txt)"; insilmaril@807: caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)"); insilmaril@807: } insilmaril@807: insilmaril@807: void ExportAO::doExport() insilmaril@807: { insilmaril@807: QFile file (outputFile); insilmaril@807: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@807: { insilmaril@807: qWarning ("ExportAO::doExport couldn't open "+outputFile); insilmaril@807: return; insilmaril@807: } insilmaril@807: QTextStream ts( &file ); // use LANG decoding here... insilmaril@807: insilmaril@807: // Main loop over all branches insilmaril@807: QString s; insilmaril@807: QString curIndent; insilmaril@807: int i; insilmaril@807: BranchItem *cur=NULL; insilmaril@807: BranchItem *prev=NULL; insilmaril@807: insilmaril@807: QString colString; insilmaril@807: QColor col; insilmaril@807: insilmaril@807: cur=model->nextBranch (cur,prev); insilmaril@807: while (cur) insilmaril@807: { insilmaril@807: if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter) insilmaril@807: { insilmaril@807: // Make indentstring insilmaril@807: curIndent=""; insilmaril@807: for (i=0;idepth()-1;i++) curIndent+= indentPerDepth; insilmaril@807: insilmaril@807: if (!cur->hasHiddenExportParent() ) insilmaril@807: { insilmaril@807: col=cur->getHeadingColor(); insilmaril@807: if (col==QColor (255,0,0)) insilmaril@807: colString="[R]"; insilmaril@807: else if (col==QColor (217,81,0)) insilmaril@807: colString="[O]"; insilmaril@807: else if (col==QColor (0,85,0)) insilmaril@807: colString="[G]"; insilmaril@807: else insilmaril@807: colString="[?]"; insilmaril@807: switch (cur->depth()) insilmaril@807: { insilmaril@807: case 0: insilmaril@807: //ts << underline (cur->getHeading(),QString("=")); insilmaril@807: //ts << "\n"; insilmaril@807: break; insilmaril@807: case 1: insilmaril@807: //ts << "\n"; insilmaril@807: //ts << (underline ( cur->getHeading(), QString("-") ) ); insilmaril@807: //ts << "\n"; insilmaril@807: break; insilmaril@807: case 2: // Main heading insilmaril@807: ts << "\n"; insilmaril@807: ts << underline ( cur->getHeading(), QString("=") ); insilmaril@818: ts << "\n"; insilmaril@807: break; insilmaril@807: case 3: // Achievement, Bonus, Objective ... insilmaril@818: ts << "\n\n"; insilmaril@807: ts << underline ( cur->getHeading(), "-"); insilmaril@807: ts << "\n\n"; insilmaril@807: break; insilmaril@807: case 4: // That's the item we need to know insilmaril@815: //ts << (curIndent + "* " + colString+" "+ cur->getHeading()); insilmaril@815: ts << colString+" "+ cur->getHeading(); insilmaril@807: if (cur->isActiveStandardFlag ("hook-green")) insilmaril@807: ts << " [DONE] "; insilmaril@815: else if (cur->isActiveStandardFlag ("wip")) insilmaril@807: ts << " [WIP] "; insilmaril@807: else if (cur->isActiveStandardFlag ("cross-red")) insilmaril@807: ts << " [NOT STARTED] "; insilmaril@807: ts << "\n"; insilmaril@818: break; insilmaril@807: default: insilmaril@807: ts << (curIndent + "- " + cur->getHeading()); insilmaril@807: ts << "\n"; insilmaril@807: break; insilmaril@807: } insilmaril@807: insilmaril@807: // If necessary, write note insilmaril@807: if (!cur->getNoteObj().isEmpty()) insilmaril@807: { insilmaril@807: curIndent +=" | "; insilmaril@807: s=cur->getNoteASCII( curIndent, 80); insilmaril@807: ts << s; insilmaril@807: } insilmaril@807: } insilmaril@807: } insilmaril@807: cur=model->nextBranch(cur,prev); insilmaril@807: } insilmaril@807: file.close(); insilmaril@807: } insilmaril@807: insilmaril@807: QString ExportAO::underline (const QString &text, const QString &line) insilmaril@807: { insilmaril@807: QString r=text + "\n"; insilmaril@807: for (int j=0;jnextBranch (cur,prev); insilmaril@741: while (cur) insilmaril@0: { insilmaril@741: if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter) insilmaril@740: { insilmaril@740: // Make indentstring insilmaril@740: curIndent=""; insilmaril@819: for (i=1;idepth()-1;i++) curIndent+= indentPerDepth; insilmaril@740: insilmaril@753: if (!cur->hasHiddenExportParent() ) insilmaril@600: { insilmaril@791: //std::cout << "ExportASCII:: "<getHeading().toStdString()<depth()) insilmaril@740: { insilmaril@740: case 0: insilmaril@741: ts << underline (cur->getHeading(),QString("=")); insilmaril@740: ts << "\n"; insilmaril@740: break; insilmaril@740: case 1: insilmaril@740: ts << "\n"; insilmaril@791: ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) ); insilmaril@740: ts << "\n"; insilmaril@740: break; insilmaril@740: case 2: insilmaril@740: ts << "\n"; insilmaril@741: ts << (curIndent + "* " + cur->getHeading()); insilmaril@740: ts << "\n"; insilmaril@740: break; insilmaril@740: case 3: insilmaril@741: ts << (curIndent + "- " + cur->getHeading()); insilmaril@740: ts << "\n"; insilmaril@740: break; insilmaril@740: default: insilmaril@741: ts << (curIndent + "- " + cur->getHeading()); insilmaril@740: ts << "\n"; insilmaril@740: break; insilmaril@740: } insilmaril@613: insilmaril@740: // If necessary, write note insilmaril@746: if (!cur->getNoteObj().isEmpty()) insilmaril@740: { insilmaril@740: curIndent +=" | "; insilmaril@746: s=cur->getNoteASCII( curIndent, 80); insilmaril@740: ts << s; insilmaril@740: } insilmaril@600: } insilmaril@0: } insilmaril@804: cur=model->nextBranch(cur,prev); insilmaril@0: } insilmaril@0: file.close(); insilmaril@0: } insilmaril@0: insilmaril@613: QString ExportASCII::underline (const QString &text, const QString &line) insilmaril@613: { insilmaril@613: QString r=text + "\n"; insilmaril@613: for (int j=0;jnextBranch (cur,prev); insilmaril@741: while (cur) insilmaril@497: { insilmaril@753: if (!cur->hasHiddenExportParent() ) insilmaril@497: { insilmaril@600: // If necessary, write note insilmaril@746: if (!cur->getNoteObj().isEmpty()) insilmaril@600: { insilmaril@746: s =cur->getNoteASCII(); insilmaril@613: s=s.replace ("\n","\n"+curIndent); insilmaril@600: ts << ("\""+s+"\","); insilmaril@600: } else insilmaril@600: ts <<"\"\","; insilmaril@497: insilmaril@600: // Make indentstring insilmaril@741: for (i=0;idepth();i++) curIndent+= "\"\","; insilmaril@497: insilmaril@600: // Write heading insilmaril@741: ts << curIndent << "\"" << cur->getHeading()<<"\""<nextBranch(cur,prev); insilmaril@613: curIndent=""; insilmaril@497: } insilmaril@497: file.close(); insilmaril@497: } insilmaril@497: insilmaril@239: //////////////////////////////////////////////////////////////////////// insilmaril@742: void ExportKDE3Bookmarks::doExport() insilmaril@239: { insilmaril@721: WarningDialog dia; insilmaril@721: dia.showCancelButton (true); insilmaril@721: dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE")); insilmaril@742: dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3")); insilmaril@742: dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks"); insilmaril@742: if (dia.exec()==QDialog::Accepted) insilmaril@742: { insilmaril@742: model->exportXML(tmpDir.path(),false); insilmaril@742: insilmaril@742: XSLTProc p; insilmaril@742: p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml"); insilmaril@742: p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml"); insilmaril@742: p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl"); insilmaril@742: p.process(); insilmaril@742: insilmaril@742: QString ub=vymBaseDir.path()+"/scripts/update-bookmarks"; insilmaril@742: QProcess *proc= new QProcess ; insilmaril@742: proc->start( ub); insilmaril@742: if (!proc->waitForStarted()) insilmaril@742: { insilmaril@742: QMessageBox::warning(0, insilmaril@742: QObject::tr("Warning"), insilmaril@742: QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub)); insilmaril@742: } insilmaril@742: } insilmaril@742: } insilmaril@742: insilmaril@742: //////////////////////////////////////////////////////////////////////// insilmaril@742: void ExportKDE4Bookmarks::doExport() insilmaril@742: { insilmaril@742: WarningDialog dia; insilmaril@742: dia.showCancelButton (true); insilmaril@742: dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4")); insilmaril@721: dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE")); insilmaril@721: dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks"); insilmaril@721: if (dia.exec()==QDialog::Accepted) insilmaril@239: { insilmaril@721: model->exportXML(tmpDir.path(),false); insilmaril@721: insilmaril@721: XSLTProc p; insilmaril@721: p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml"); insilmaril@742: p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml"); insilmaril@721: p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl"); insilmaril@721: p.process(); insilmaril@721: insilmaril@721: QString ub=vymBaseDir.path()+"/scripts/update-bookmarks"; insilmaril@721: QProcess *proc= new QProcess ; insilmaril@721: proc->start( ub); insilmaril@721: if (!proc->waitForStarted()) insilmaril@311: { insilmaril@721: QMessageBox::warning(0, insilmaril@721: QObject::tr("Warning"), insilmaril@721: QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub)); insilmaril@721: } insilmaril@239: } insilmaril@239: } insilmaril@239: insilmaril@239: //////////////////////////////////////////////////////////////////////// insilmaril@311: void ExportFirefoxBookmarks::doExport() insilmaril@311: { insilmaril@721: WarningDialog dia; insilmaril@721: dia.showCancelButton (true); insilmaril@721: dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox")); insilmaril@721: dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox")); insilmaril@721: dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks"); insilmaril@721: if (dia.exec()==QDialog::Accepted) insilmaril@311: { insilmaril@721: model->exportXML(tmpDir.path(),false); insilmaril@311: insilmaril@311: /* insilmaril@721: XSLTProc p; insilmaril@721: p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml"); insilmaril@721: p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml"); insilmaril@721: p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl"); insilmaril@721: p.process(); insilmaril@311: insilmaril@721: QString ub=vymBaseDir.path()+"/scripts/update-bookmarks"; insilmaril@721: QProcess *proc = new QProcess( ); insilmaril@721: proc->addArgument(ub); insilmaril@311: insilmaril@721: if ( !proc->start() ) insilmaril@721: { insilmaril@721: QMessageBox::warning(0, insilmaril@721: QObject::tr("Warning"), insilmaril@721: QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub)); insilmaril@721: } insilmaril@311: insilmaril@311: */ insilmaril@311: } insilmaril@311: } insilmaril@311: insilmaril@311: //////////////////////////////////////////////////////////////////////// insilmaril@819: ExportHTML::ExportHTML():ExportBase() insilmaril@819: { insilmaril@819: init(); insilmaril@819: } insilmaril@819: insilmaril@819: ExportHTML::ExportHTML(VymModel *m):ExportBase(m) insilmaril@819: { insilmaril@819: init(); insilmaril@819: } insilmaril@819: insilmaril@819: void ExportHTML::init() insilmaril@819: { insilmaril@819: singularDelimiter=": "; insilmaril@819: noSingulars=true; insilmaril@819: frameURLs=true; insilmaril@824: cssFileName="vym.css"; insilmaril@824: cssOriginalPath=""; // Is set in VymModel, based on default setting in ExportHTMLDialog insilmaril@819: insilmaril@819: if (model &&model->getMapEditor()) insilmaril@819: offset=model->getMapEditor()->getTotalBBox().topLeft(); insilmaril@819: } insilmaril@819: insilmaril@819: QString ExportHTML::getBranchText(BranchItem *current) insilmaril@819: { insilmaril@819: if (current) insilmaril@819: { insilmaril@819: bool vis=false; insilmaril@819: QRectF hr; insilmaril@819: LinkableMapObj *lmo=current->getLMO(); insilmaril@819: if (lmo) insilmaril@819: { insilmaril@819: hr=((BranchObj*)lmo)->getBBoxHeading(); insilmaril@819: if (lmo->isVisibleObj()) vis=true; insilmaril@819: } insilmaril@819: QString col; insilmaril@819: QString id=model->getSelectString(current); insilmaril@825: if (dia.useTextColor) insilmaril@819: col=QString("style='color:%1'").arg(current->getHeadingColor().name()); insilmaril@819: QString s=QString("") insilmaril@819: .arg(current->depth()) insilmaril@819: .arg(col) insilmaril@819: .arg(id); insilmaril@819: QString url=current->getURL(); insilmaril@819: if (!url.isEmpty()) insilmaril@819: { insilmaril@819: s+=QString ("").arg(url); insilmaril@819: s+=QString ("%1").arg(quotemeta(current->getHeading())); insilmaril@819: s+=""; insilmaril@819: insilmaril@823: QRectF fbox=current->getBBoxURLFlag (); insilmaril@819: if (vis) insilmaril@819: imageMap+=QString(" \n") insilmaril@819: .arg(fbox.left()-offset.x()) insilmaril@819: .arg(fbox.top()-offset.y()) insilmaril@819: .arg(fbox.right()-offset.x()) insilmaril@819: .arg(fbox.bottom()-offset.y()) insilmaril@819: .arg(url); insilmaril@819: } else insilmaril@819: s+=quotemeta(current->getHeading()); insilmaril@819: s+=""; insilmaril@819: insilmaril@825: if (vis && dia.useImage) insilmaril@819: imageMap+=QString(" \n") insilmaril@819: .arg(hr.left()-offset.x()) insilmaril@819: .arg(hr.top()-offset.y()) insilmaril@819: .arg(hr.right()-offset.x()) insilmaril@819: .arg(hr.bottom()-offset.y()) insilmaril@819: .arg(id); insilmaril@819: insilmaril@819: // Include note insilmaril@819: if (!current->getNoteObj().isEmpty()) insilmaril@819: s+="
"+current->getNote()+"
"; insilmaril@819: insilmaril@819: return s; insilmaril@819: } insilmaril@819: return QString(); insilmaril@819: } insilmaril@819: insilmaril@819: QString ExportHTML::buildList (BranchItem *current) insilmaril@819: { insilmaril@819: QString r; insilmaril@819: insilmaril@819: uint i=0; insilmaril@819: BranchItem *bi=current->getFirstBranch(); insilmaril@819: insilmaril@819: // Only add itemized list, if we have more than one subitem. insilmaril@819: // For only one subitem, just add a separator to keep page more compact insilmaril@819: bool noSingularsHere=false; insilmaril@819: if (current->branchCount()<2 && noSingulars) noSingularsHere=true; insilmaril@819: insilmaril@819: if (bi) insilmaril@819: { insilmaril@819: if (!noSingularsHere) insilmaril@819: r+="
    \n"; insilmaril@819: else insilmaril@819: r+=singularDelimiter; insilmaril@819: insilmaril@819: while (bi) insilmaril@819: { insilmaril@819: if (!bi->hasHiddenExportParent() ) insilmaril@819: { insilmaril@819: if (!noSingularsHere) r+="
  • "; insilmaril@819: r+=getBranchText (bi); insilmaril@819: if (!bi->getURL().isEmpty() && frameURLs && noSingularsHere) insilmaril@819: // Add frame, if we have subitems to an URL insilmaril@819: r+="
    "+buildList (bi)+"
    "; // recursivly add deeper branches insilmaril@819: else insilmaril@819: r+=buildList (bi); // recursivly add deeper branches insilmaril@819: if (!noSingularsHere) r+="
  • "; insilmaril@819: r+="\n"; insilmaril@819: } insilmaril@819: i++; insilmaril@819: bi=current->getBranchNum(i); insilmaril@819: } insilmaril@819: insilmaril@819: if (!noSingularsHere) r+="
\n"; insilmaril@819: } insilmaril@819: return r; insilmaril@819: } insilmaril@819: insilmaril@824: void ExportHTML::setCSSPath(const QString &p) insilmaril@824: { insilmaril@824: cssOriginalPath=p; insilmaril@824: } insilmaril@824: insilmaril@825: void ExportHTML::doExport(bool useDialog) insilmaril@819: { insilmaril@825: // Execute dialog insilmaril@825: dia.setFilePath (model->getFilePath()); insilmaril@825: dia.setMapName (model->getMapName()); insilmaril@825: dia.readSettings(); insilmaril@825: if (useDialog && dia.exec()!=QDialog::Accepted) return; insilmaril@825: insilmaril@825: // Check if destination is not empty insilmaril@825: QDir d=dia.getDir(); insilmaril@825: // Check, if warnings should be used before overwriting insilmaril@825: // the output directory insilmaril@825: if (d.exists() && d.count()>0) insilmaril@825: { insilmaril@825: WarningDialog warn; insilmaril@825: warn.showCancelButton (true); insilmaril@825: warn.setText(QString( insilmaril@825: "The directory %1 is not empty.\n" insilmaril@825: "Do you risk to overwrite some of its contents?").arg(d.path() )); insilmaril@825: warn.setCaption("Warning: Directory not empty"); insilmaril@825: warn.setShowAgainName("mainwindow/export-XML-overwrite-dir"); insilmaril@825: insilmaril@825: if (warn.exec()!=QDialog::Accepted) insilmaril@825: { insilmaril@825: mainWindow->statusMessage(QString(QObject::tr("Export aborted."))); insilmaril@825: return; insilmaril@825: } insilmaril@825: } insilmaril@825: insilmaril@825: setFile (d.path()+"/"+model->getMapName()+".html"); insilmaril@825: setCSSPath( dia.getCSSPath() ); insilmaril@825: insilmaril@825: // Copy CSS file insilmaril@824: QFile css_src (cssOriginalPath); insilmaril@824: QFile css_dst (outDir.path()+"/"+cssFileName); insilmaril@824: if (!css_src.open ( QIODevice::ReadOnly)) insilmaril@824: QMessageBox::warning( 0, QObject::tr( "Warning","ExportHTML" ),QObject::tr("Could not open %1","ExportHTML").arg(cssOriginalPath)); insilmaril@824: else insilmaril@824: { insilmaril@824: if (!css_dst.open( QIODevice::WriteOnly)) insilmaril@824: QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr("Could not open %1").arg(css_dst.fileName())); insilmaril@824: else insilmaril@824: { insilmaril@824: insilmaril@824: QTextStream tsout( &css_dst); insilmaril@824: QTextStream tsin ( &css_src); insilmaril@824: QString s= tsin.read(); insilmaril@824: tsout << s; insilmaril@824: css_dst.close(); insilmaril@824: } insilmaril@824: css_src.close(); insilmaril@824: } insilmaril@824: insilmaril@824: insilmaril@824: insilmaril@824: // Open file for writing insilmaril@819: QFile file (outputFile); insilmaril@819: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@819: { insilmaril@819: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile)); insilmaril@819: mainWindow->statusMessage(QString(QObject::tr("Export failed."))); insilmaril@819: return; insilmaril@819: } insilmaril@819: QTextStream ts( &file ); // use LANG decoding here... insilmaril@819: ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8 insilmaril@819: insilmaril@825: // Hide stuff during export insilmaril@825: model->setExportMode (true); insilmaril@825: insilmaril@819: // Write header insilmaril@819: ts<<""+model->getMapName()<<""; insilmaril@824: ts<<" \n"; insilmaril@819: insilmaril@819: // Include image insilmaril@825: if (dia.useImage) insilmaril@825: { insilmaril@825: ts<<"
getMapName()<<".png\" usemap='#imagemap'>
\n"; insilmaril@825: model->exportImage (d.path()+"/"+model->getMapName()+".png",false,"PNG"); insilmaril@825: } insilmaril@819: insilmaril@819: // Main loop over all mapcenters insilmaril@819: QString s; insilmaril@819: TreeItem *rootItem=model->getRootItem(); insilmaril@819: BranchItem *bi; insilmaril@819: for (int i=0; ibranchCount(); i++) insilmaril@819: { insilmaril@819: bi=rootItem->getBranchNum(i); insilmaril@819: if (!bi->hasHiddenExportParent()) insilmaril@819: { insilmaril@819: ts<\n"+imageMap+"\n"; insilmaril@819: insilmaril@819: // Write footer insilmaril@819: ts<<"
\n"; insilmaril@819: ts<<" \n\ insilmaril@819: \n\ insilmaril@819: \n\ insilmaril@819: \n\ insilmaril@819: \n\ insilmaril@819: \n \ insilmaril@819:
"+model->getFileName()+""+model->getDate()+" vym "+model->getVersion()+"
\n"; insilmaril@819: ts<<""; insilmaril@819: file.close(); insilmaril@825: insilmaril@825: if (!dia.postscript.isEmpty()) insilmaril@825: { insilmaril@825: Process p; insilmaril@825: p.runScript (dia.postscript,d.path()+"/"+model->getMapName()+".html"); insilmaril@825: } insilmaril@825: insilmaril@825: insilmaril@825: dia.saveSettings(); insilmaril@825: model->setExportMode (true); insilmaril@819: } insilmaril@819: insilmaril@819: //////////////////////////////////////////////////////////////////////// insilmaril@228: void ExportTaskjuggler::doExport() insilmaril@228: { insilmaril@721: model->exportXML(tmpDir.path(),false); insilmaril@228: insilmaril@721: XSLTProc p; insilmaril@721: p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml"); insilmaril@721: p.setOutputFile (outputFile); insilmaril@721: p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl"); insilmaril@721: p.process(); insilmaril@228: } insilmaril@228: insilmaril@239: //////////////////////////////////////////////////////////////////////// insilmaril@228: void ExportLaTeX::doExport() insilmaril@0: { insilmaril@183: // Exports a map to a LaTex file. insilmaril@183: // This file needs to be included insilmaril@183: // or inported into a LaTex document insilmaril@183: // it will not add a preamble, or anything insilmaril@183: // that makes a full LaTex document. insilmaril@199: QFile file (outputFile); insilmaril@366: if ( !file.open( QIODevice::WriteOnly ) ) { insilmaril@205: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile)); insilmaril@205: mainWindow->statusMessage(QString(QObject::tr("Export failed."))); insilmaril@163: return; insilmaril@163: } insilmaril@163: QTextStream ts( &file ); // use LANG decoding here... insilmaril@163: ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8 insilmaril@163: insilmaril@163: // Main loop over all branches insilmaril@163: QString s; insilmaril@613: // QString curIndent(""); insilmaril@163: // int i; insilmaril@163: BranchObj *bo; insilmaril@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@804: model->nextBranch(cur,prev); insilmaril@741: while (cur) insilmaril@740: { insilmaril@741: bo=(BranchObj*)(cur->getLMO()); insilmaril@740: insilmaril@753: if (!cur->hasHiddenExportParent() ) insilmaril@600: { insilmaril@741: switch (cur->depth() ) insilmaril@740: { insilmaril@740: case 0: break; insilmaril@740: case 1: insilmaril@753: ts << ("\\chapter{" + cur->getHeading()+ "}\n"); insilmaril@740: break; insilmaril@740: case 2: insilmaril@753: ts << ("\\section{" + cur->getHeading()+ "}\n"); insilmaril@740: break; insilmaril@740: case 3: insilmaril@753: ts << ("\\subsection{" + cur->getHeading()+ "}\n"); insilmaril@740: break; insilmaril@740: case 4: insilmaril@753: ts << ("\\subsubsection{" + cur->getHeading()+ "}\n"); insilmaril@740: break; insilmaril@740: default: insilmaril@753: ts << ("\\paragraph*{" + cur->getHeading()+ "}\n"); insilmaril@740: insilmaril@600: } insilmaril@600: // If necessary, write note insilmaril@746: if (!cur->getNoteObj().isEmpty()) { insilmaril@746: ts << (cur->getNoteASCII()); insilmaril@600: ts << ("\n"); insilmaril@600: } insilmaril@254: } insilmaril@804: cur=model->nextBranch(cur,prev); insilmaril@163: } insilmaril@163: file.close(); insilmaril@0: } insilmaril@0: insilmaril@239: //////////////////////////////////////////////////////////////////////// insilmaril@171: ExportOO::ExportOO() insilmaril@171: { insilmaril@199: useSections=false; insilmaril@171: } insilmaril@163: insilmaril@171: ExportOO::~ExportOO() insilmaril@171: { insilmaril@171: } insilmaril@163: insilmaril@750: QString ExportOO::buildList (TreeItem *current) insilmaril@171: { insilmaril@171: QString r; insilmaril@183: insilmaril@183: uint i=0; insilmaril@750: BranchItem *bi=current->getFirstBranch(); insilmaril@750: if (bi) insilmaril@171: { insilmaril@819: // Start list insilmaril@819: r+="\n"; insilmaril@819: while (bi) insilmaril@600: { insilmaril@819: if (!bi->hasHiddenExportParent() ) insilmaril@600: { insilmaril@600: r+=""; insilmaril@750: r+=quotemeta(bi->getHeading()); insilmaril@600: // If necessary, write note insilmaril@750: if (!bi->getNoteObj().isEmpty()) insilmaril@750: r+=bi->getNoteOpenDoc(); insilmaril@600: r+=""; insilmaril@750: r+=buildList (bi); // recursivly add deeper branches insilmaril@600: r+="\n"; insilmaril@600: } insilmaril@819: i++; insilmaril@819: bi=current->getBranchNum(i); insilmaril@600: } insilmaril@819: r+="\n"; insilmaril@171: } insilmaril@171: return r; insilmaril@171: } insilmaril@163: insilmaril@171: insilmaril@171: void ExportOO::exportPresentation() insilmaril@171: { insilmaril@183: QString allPages; insilmaril@171: insilmaril@804: BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch()); insilmaril@804: if (!firstMCO) insilmaril@804: { insilmaril@804: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!")); insilmaril@804: return; insilmaril@804: } insilmaril@804: insilmaril@163: // Insert new content insilmaril@804: // FIXME add extra title in mapinfo for vym 1.13.x insilmaril@804: content.replace ("",quotemeta(firstMCO->getHeading())); insilmaril@804: content.replace ("",quotemeta(model->getAuthor())); insilmaril@183: insilmaril@183: QString onePage; insilmaril@183: QString list; insilmaril@183: insilmaril@804: BranchItem *sectionBI; insilmaril@183: int i=0; insilmaril@804: BranchItem *pagesBI; insilmaril@183: int j=0; insilmaril@183: insilmaril@804: int mapcenters=model->getRootItem()->branchCount(); insilmaril@804: insilmaril@804: // useSections already has been set in setConfigFile insilmaril@804: if (mapcenters>1) insilmaril@804: sectionBI=firstMCO; insilmaril@804: else insilmaril@804: sectionBI=firstMCO->getFirstBranch(); insilmaril@804: insilmaril@194: // Walk sections insilmaril@804: while (sectionBI && !sectionBI->hasHiddenExportParent() ) insilmaril@183: { insilmaril@194: if (useSections) insilmaril@183: { insilmaril@194: // Add page with section title insilmaril@194: onePage=sectionTemplate; insilmaril@804: onePage.replace ("", quotemeta(sectionBI->getHeading() ) ); insilmaril@183: allPages+=onePage; insilmaril@804: pagesBI=sectionBI->getFirstBranch(); insilmaril@183: } else insilmaril@183: { insilmaril@804: //i=-2; // only use inner loop to insilmaril@183: // turn mainbranches into pages insilmaril@804: //sectionBI=firstMCO; insilmaril@804: pagesBI=sectionBI; insilmaril@183: } insilmaril@183: insilmaril@183: j=0; insilmaril@804: while (pagesBI && !pagesBI->hasHiddenExportParent() ) insilmaril@183: { insilmaril@183: // Add page with list of items insilmaril@254: onePage=pageTemplate; insilmaril@804: onePage.replace ("", quotemeta (pagesBI->getHeading() ) ); insilmaril@804: list=buildList (pagesBI); insilmaril@254: onePage.replace ("", list); insilmaril@254: allPages+=onePage; insilmaril@804: if (pagesBI!=sectionBI) insilmaril@804: { insilmaril@804: j++; insilmaril@804: pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j); insilmaril@804: } else insilmaril@804: pagesBI=NULL; // We are already iterating over the sectionBIs insilmaril@183: } insilmaril@183: i++; insilmaril@804: if (mapcenters>1 ) insilmaril@804: sectionBI=model->getRootItem()->getBranchNum (i); insilmaril@804: else insilmaril@804: sectionBI=firstMCO->getBranchNum (i); insilmaril@183: } insilmaril@183: insilmaril@171: content.replace ("",allPages); insilmaril@171: insilmaril@171: // Write modified content insilmaril@171: QFile f (contentFile); insilmaril@366: if ( !f.open( QIODevice::WriteOnly ) ) insilmaril@171: { insilmaril@205: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile)); insilmaril@205: mainWindow->statusMessage(QString(QObject::tr("Export failed."))); insilmaril@171: return; insilmaril@171: } insilmaril@171: insilmaril@171: QTextStream t( &f ); insilmaril@171: t << content; insilmaril@171: f.close(); insilmaril@171: insilmaril@163: // zip tmpdir to destination insilmaril@171: zipDir (tmpDir,outputFile); insilmaril@163: } insilmaril@163: insilmaril@194: bool ExportOO::setConfigFile (const QString &cf) insilmaril@183: { insilmaril@183: configFile=cf; insilmaril@183: int i=cf.findRev ("/"); insilmaril@183: if (i>=0) configDir=cf.left(i); insilmaril@183: SimpleSettings set; insilmaril@183: set.readSettings(configFile); insilmaril@183: insilmaril@183: // set paths insilmaril@183: templateDir=configDir+"/"+set.readEntry ("Template"); insilmaril@183: insilmaril@194: QDir d (templateDir); insilmaril@194: if (!d.exists()) insilmaril@194: { insilmaril@194: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile)); insilmaril@194: return false; insilmaril@194: insilmaril@194: } insilmaril@183: insilmaril@183: contentTemplateFile=templateDir+"content-template.xml"; insilmaril@183: contentFile=tmpDir.path()+"/content.xml"; insilmaril@183: pageTemplateFile=templateDir+"page-template.xml"; insilmaril@194: sectionTemplateFile=templateDir+"section-template.xml"; insilmaril@183: insilmaril@199: if (set.readEntry("useSections").contains("yes")) insilmaril@199: useSections=true; insilmaril@199: insilmaril@183: // Copy template to tmpdir insilmaril@183: system ("cp -r "+templateDir+"* "+tmpDir.path()); insilmaril@183: insilmaril@183: // Read content-template insilmaril@183: if (!loadStringFromDisk (contentTemplateFile,content)) insilmaril@183: { insilmaril@194: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile)); insilmaril@194: return false; insilmaril@183: } insilmaril@183: insilmaril@183: // Read page-template insilmaril@183: if (!loadStringFromDisk (pageTemplateFile,pageTemplate)) insilmaril@183: { insilmaril@194: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile)); insilmaril@194: return false; insilmaril@183: } insilmaril@183: insilmaril@194: // Read section-template insilmaril@201: if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate)) insilmaril@183: { insilmaril@194: QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile)); insilmaril@194: return false; insilmaril@183: } insilmaril@194: return true; insilmaril@183: } insilmaril@183: