Switch to unified view

a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.36 2008-09-08 16:49:10 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.37 2008-10-03 08:09:35 dockes Exp $ (C) 2005 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
670
        *statusp = -1;
670
        *statusp = -1;
671
        return;
671
        return;
672
    }
672
    }
673
    
673
    
674
    FileInterner interner(filename, &st, rclconfig, tmpdir, mtype);
674
    FileInterner interner(filename, &st, rclconfig, tmpdir, mtype);
675
  // We don't set the interner's target mtype to html because we
676
  // do want the html filter to do its work: we won't use the
677
  // text, but we need the conversion to utf-8
678
  // interner.setTargetMType("text/html");
675
    try {
679
    try {
676
        FileInterner::Status ret = interner.internfile(*out, ipath);
680
        FileInterner::Status ret = interner.internfile(*out, ipath);
677
        if (ret == FileInterner::FIDone || ret == FileInterner::FIAgain) {
681
        if (ret == FileInterner::FIDone || ret == FileInterner::FIAgain) {
678
        // FIAgain is actually not nice here. It means that the record
682
        // FIAgain is actually not nice here. It means that the record
679
        // for the *file* of a multidoc was selected. Actually this
683
        // for the *file* of a multidoc was selected. Actually this
680
        // shouldn't have had a preview link at all, but we don't know
684
        // shouldn't have had a preview link at all, but we don't know
681
        // how to handle it now. Better to show the first doc than
685
        // how to handle it now. Better to show the first doc than
682
        // a mysterious error. Happens when the file name matches a
686
        // a mysterious error. Happens when the file name matches a
683
        // a search term of course.
687
        // a search term of course.
684
        *statusp = 0;
688
        *statusp = 0;
689
      if (prefs.previewHtml && !interner.get_html().empty()) {
690
          out->text = interner.get_html();
691
          out->mimetype = "text/html";
692
      }
685
        } else {
693
        } else {
686
        out->mimetype = interner.getMimetype();
694
        out->mimetype = interner.getMimetype();
687
        interner.getMissingExternal(missing);
695
        interner.getMissingExternal(missing);
688
        *statusp = -1;
696
        *statusp = -1;
689
        }
697
        }
...
...
818
    // We don't do the highlighting for very big texts: too long. We
826
    // We don't do the highlighting for very big texts: too long. We
819
    // should at least do special char escaping, in case a '&' or '<'
827
    // should at least do special char escaping, in case a '&' or '<'
820
    // somehow slipped through previous processing.
828
    // somehow slipped through previous processing.
821
    bool highlightTerms = fdoc.text.length() < 
829
    bool highlightTerms = fdoc.text.length() < 
822
    (unsigned long)prefs.maxhltextmbs * 1024 * 1024;
830
    (unsigned long)prefs.maxhltextmbs * 1024 * 1024;
831
823
    // Final text is produced in chunks so that we can display the top
832
    // Final text is produced in chunks so that we can display the top
824
    // while still inserting at bottom
833
    // while still inserting at bottom
825
    list<QString> qrichlst;
834
    list<QString> qrichlst;
826
835
    bool inputishtml = !fdoc.mimetype.compare("text/html");
827
    if (highlightTerms) {
836
    if (highlightTerms) {
828
    progress.setLabelText(tr("Creating preview text"));
837
    progress.setLabelText(tr("Creating preview text"));
829
    qApp->processEvents();
838
    qApp->processEvents();
839
  if (inputishtml) {
840
      LOGDEB(("Preview: got html %s\n", fdoc.text.c_str()));
841
      m_plaintorich.set_inputhtml(true);
842
  } else {
843
      m_plaintorich.set_inputhtml(false);
844
  }
830
    list<string> richlst;
845
    list<string> richlst;
831
    ToRichThread rthr(fdoc.text, m_hData, richlst, m_plaintorich);
846
    ToRichThread rthr(fdoc.text, m_hData, richlst, m_plaintorich);
832
    rthr.start();
847
    rthr.start();
833
848
834
    for (;;prog++) {
849
    for (;;prog++) {
...
...
853
        return false;
868
        return false;
854
        } else {
869
        } else {
855
        richlst.back() += "<b>Cancelled !</b>";
870
        richlst.back() += "<b>Cancelled !</b>";
856
        }
871
        }
857
    }
872
    }
858
    // Convert to QString list
873
    // Convert C++ string list to QString list
859
    for (list<string>::iterator it = richlst.begin(); 
874
    for (list<string>::iterator it = richlst.begin(); 
860
         it != richlst.end(); it++) {
875
         it != richlst.end(); it++) {
861
        qrichlst.push_back(QString::fromUtf8(it->c_str(), it->length()));
876
        qrichlst.push_back(QString::fromUtf8(it->c_str(), it->length()));
862
    }
877
    }
863
    } else {
878
    } else {
864
  // No plaintorich() call.
879
  LOGDEB(("Preview: no hilighting\n"));
865
  // In this case, the text will no be identified as
880
  // No plaintorich() call.  In this case, either the text is
866
  // richtxt/html (no <html> or <qt> etc. at the beginning), and
881
  // html and the html quoting is hopefully correct, or it's
867
  // there is no need to escape special characters.
882
  // plain-text and there is no need to escape special
868
  // Also we need to split in chunks (so that the top is displayed faster),
883
  // characters. We'd still want to split in chunks (so that the
884
  // top is displayed faster), but we must not cut tags, and
885
  // it's too difficult on html. For text we do the splitting on
869
    // and we must do it on a QString (to avoid utf8 issues).
886
    // a QString to avoid utf8 issues.
870
    QString qr = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
887
    QString qr = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
871
    int l = 0;
888
    int l = 0;
889
  if (inputishtml) {
890
      qrichlst.push_back(qr);
891
  } else {
872
    for (int pos = 0; pos < (int)qr.length(); pos += l) {
892
        for (int pos = 0; pos < (int)qr.length(); pos += l) {
873
        l = MIN(CHUNKL, qr.length() - pos);
893
      l = MIN(CHUNKL, qr.length() - pos);
874
        qrichlst.push_back(qr.mid(pos, l));
894
      qrichlst.push_back(qr.mid(pos, l));
895
      }
875
    }
896
    }
876
    }
897
    }
877
        
898
        
878
    // Load into editor
899
    // Load into editor
879
    QTextEditFixed *editor = getCurrentEditor();
900
    QTextEditFixed *editor = getCurrentEditor();
...
...
893
     it != qrichlst.end(); it++, prog++, instep++) {
914
     it != qrichlst.end(); it++, prog++, instep++) {
894
    progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
915
    progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
895
    qApp->processEvents();
916
    qApp->processEvents();
896
917
897
    editor->append(*it);
918
    editor->append(*it);
898
919
  LOGDEB(("Preview:: loaded: [%s]\n", 
920
      string((const char *)(*it).utf8()).c_str()));
899
    // Stay at top
921
    // Stay at top
900
    if (instep < 5) {
922
    if (instep < 5) {
901
        editor->setCursorPosition(0,0);
923
        editor->setCursorPosition(0,0);
902
        editor->ensureCursorVisible();
924
        editor->ensureCursorVisible();
903
    }
925
    }