Changeset f48433245d in tspsg for src


Ignore:
Timestamp:
Sep 10, 2012, 5:50:48 PM (12 years ago)
Author:
Oleksii Serdiuk
Branches:
appveyor, imgbot, master, readme
Children:
89e5214692
Parents:
b26dc16dcf
Message:

Added support for saving solution in MHTML format.

MIME HTML, also known as Web Archive.

Closes #10: Add support for MHTML format

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    rb26dc16dcf rf48433245d  
    263263#endif
    264264    filters.append(tr("HTML Files") + " (*.html *.htm)");
     265    filters.append(tr("Web Archive Files") + " (*.mht *.mhtml)");
    265266    filters.append(tr("OpenDocument Files") + " (*.odt)");
    266267    filters.append(tr("All Files") + " (*)");
     
    284285#endif
    285286    QByteArray imgdata;
    286     bool embed = settings->value("Output/EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool();
    287     if (selectedFile.endsWith(".htm", Qt::CaseInsensitive) || selectedFile.endsWith(".html", Qt::CaseInsensitive)) {
     287    bool mhtml = selectedFile.contains(QRegExp("\\.mht(ml)?$", Qt::CaseInsensitive));
     288    bool embed = !mhtml && settings->value("Output/EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool();
     289    if (selectedFile.contains(QRegExp("\\.(html?|mht(ml)?)$", Qt::CaseInsensitive))) {
    288290        QFile file(selectedFile);
    289291        if (!file.open(QFile::WriteOnly | QFile::Text)) {
     
    335337QTextStream ts(&file);
    336338        ts.setCodec(QTextCodec::codecForName("UTF-8"));
     339        QString boundary = QString("------=multipart_boundary.%1").arg(qHash(selectedFile));
     340        if (mhtml) {
     341            ts << "Content-Type: multipart/related; start=<[email protected]>; boundary=\""
     342               << boundary << "\"; type=\"text/html\"" << endl;
     343            boundary.prepend("--");
     344            ts << "MIME-Version: 1.0" << endl;
     345            ts << endl;
     346            ts << boundary << endl;
     347            ts << "Content-Disposition: inline; filename=" << fi.completeBaseName() << ".html" << endl;
     348            ts << "Content-Type: text/html; name=" << fi.completeBaseName() << ".html" << endl;
     349            ts << "Content-ID: <[email protected]>" << endl;
     350            ts << "Content-Location: " << fi.completeBaseName() << ".html" << endl;
     351            ts << "Content-Transfer-Encoding: 8bit" << endl;
     352            ts << endl;
     353        }
    337354        ts << html << endl;
     355        if (mhtml) {
     356            ts << endl << boundary << endl;
     357            ts << "Content-Disposition: inline; filename=" << fi.completeBaseName() << "." << format << endl;
     358            ts << "Content-Type: image/" << format;
     359            if (format == "svg")
     360                ts << "+xml";
     361            ts << "; name=" << fi.completeBaseName() << "." << format  << endl;
     362            ts << "Content-Location: " << fi.completeBaseName() << "." << format << endl;
     363            ts << "Content-Transfer-Encoding: Base64" << endl;
     364            ts << endl;
     365            ts << toWrappedBase64(imgdata) << endl;
     366            ts << endl << boundary << "--" << endl;
     367        }
    338368        file.close();
    339         if (!embed) {
     369        if (!embed && !mhtml) {
    340370            QFile img(fi.path() + "/" + fi.completeBaseName() + "." + format);
    341371            if (!img.open(QFile::WriteOnly)) {
Note: See TracChangeset for help on using the changeset viewer.