suppressed a number of gratuitous unistd inclusions + clean up preview progress dialog code

This commit is contained in:
Jean-Francois Dockes 2015-09-24 15:36:02 +02:00
parent 0cc5bb82d5
commit f000aaa792
6 changed files with 471 additions and 489 deletions

View file

@ -14,7 +14,6 @@
* Free Software Foundation, Inc., * Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <unistd.h>
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>

View file

@ -14,11 +14,8 @@
* Free Software Foundation, Inc., * Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "autoconfig.h" #include "autoconfig.h"
#include <unistd.h>
#include <cstdlib> #include <cstdlib>
#include <qapplication.h> #include <qapplication.h>

View file

@ -16,8 +16,6 @@
*/ */
#include "autoconfig.h" #include "autoconfig.h"
#include "safeunistd.h"
#include <list> #include <list>
#include <utility> #include <utility>
@ -45,6 +43,7 @@
#include <qimage.h> #include <qimage.h>
#include <qurl.h> #include <qurl.h>
#include <QShortcut> #include <QShortcut>
#include <QTimer>
#include "debuglog.h" #include "debuglog.h"
#include "pathut.h" #include "pathut.h"
@ -70,8 +69,7 @@ class PlainToRichQtPreview : public PlainToRich {
public: public:
PlainToRichQtPreview() PlainToRichQtPreview()
: m_curanchor(1), m_lastanchor(0) : m_curanchor(1), m_lastanchor(0) {
{
} }
void clear() { void clear() {
m_curanchor = 1; m_curanchor = 1;
@ -80,13 +78,11 @@ public:
m_groupcuranchors.clear(); m_groupcuranchors.clear();
} }
bool haveAnchors() bool haveAnchors() {
{
return m_lastanchor != 0; return m_lastanchor != 0;
} }
virtual string header() virtual string header() {
{
if (!m_inputhtml) { if (!m_inputhtml) {
switch (prefs.previewPlainPre) { switch (prefs.previewPlainPre) {
case PrefsPack::PP_BR: case PrefsPack::PP_BR:
@ -104,8 +100,7 @@ public:
return cstr_null; return cstr_null;
} }
virtual string startMatch(unsigned int grpidx) virtual string startMatch(unsigned int grpidx) {
{
LOGDEB2(("startMatch, grpidx %u\n", grpidx)); LOGDEB2(("startMatch, grpidx %u\n", grpidx));
grpidx = m_hdata->grpsugidx[grpidx]; grpidx = m_hdata->grpsugidx[grpidx];
LOGDEB2(("startMatch, ugrpidx %u\n", grpidx)); LOGDEB2(("startMatch, ugrpidx %u\n", grpidx));
@ -120,26 +115,22 @@ public:
append("\">"); append("\">");
} }
virtual string endMatch() virtual string endMatch() {
{
return string("</a></span>"); return string("</a></span>");
} }
virtual string termAnchorName(int i) const virtual string termAnchorName(int i) const {
{
static const char *termAnchorNameBase = "TRM"; static const char *termAnchorNameBase = "TRM";
char acname[sizeof(termAnchorNameBase) + 20]; char acname[sizeof(termAnchorNameBase) + 20];
sprintf(acname, "%s%d", termAnchorNameBase, i); sprintf(acname, "%s%d", termAnchorNameBase, i);
return string(acname); return string(acname);
} }
virtual string startChunk() virtual string startChunk() {
{
return "<pre>"; return "<pre>";
} }
int nextAnchorNum(int grpidx) int nextAnchorNum(int grpidx) {
{
LOGDEB2(("nextAnchorNum: group %d\n", grpidx)); LOGDEB2(("nextAnchorNum: group %d\n", grpidx));
map<unsigned int, unsigned int>::iterator curit = map<unsigned int, unsigned int>::iterator curit =
m_groupcuranchors.find(grpidx); m_groupcuranchors.find(grpidx);
@ -162,8 +153,7 @@ public:
return m_curanchor; return m_curanchor;
} }
int prevAnchorNum(int grpidx) int prevAnchorNum(int grpidx) {
{
map<unsigned int, unsigned int>::iterator curit = map<unsigned int, unsigned int>::iterator curit =
m_groupcuranchors.find(grpidx); m_groupcuranchors.find(grpidx);
map<unsigned int, vector<int> >::iterator vecit = map<unsigned int, vector<int> >::iterator vecit =
@ -184,8 +174,7 @@ public:
return m_curanchor; return m_curanchor;
} }
QString curAnchorName() const QString curAnchorName() const {
{
return QString::fromUtf8(termAnchorName(m_curanchor).c_str()); return QString::fromUtf8(termAnchorName(m_curanchor).c_str());
} }
@ -729,7 +718,7 @@ class LoadThread : public QThread {
Rcl::Doc& out; Rcl::Doc& out;
const Rcl::Doc& idoc; const Rcl::Doc& idoc;
int loglevel; int loglevel;
public: public:
string missing; string missing;
TempFile imgtmp; TempFile imgtmp;
@ -742,7 +731,6 @@ class LoadThread : public QThread {
} }
virtual void run() { virtual void run() {
DebugLog::getdbl()->setloglevel(loglevel); DebugLog::getdbl()->setloglevel(loglevel);
FileInterner interner(idoc, theconfig, FileInterner::FIF_forPreview); FileInterner interner(idoc, theconfig, FileInterner::FIF_forPreview);
FIMissingStore mst; FIMissingStore mst;
interner.setMissingStore(&mst); interner.setMissingStore(&mst);
@ -792,7 +780,7 @@ class ToRichThread : public QThread {
list<string> &out; list<string> &out;
int loglevel; int loglevel;
PlainToRichQtPreview *ptr; PlainToRichQtPreview *ptr;
public: public:
ToRichThread(string &i, const HighlightData& hd, list<string> &o, ToRichThread(string &i, const HighlightData& hd, list<string> &o,
PlainToRichQtPreview *_ptr) PlainToRichQtPreview *_ptr)
: in(i), hdata(hd), out(o), ptr(_ptr) : in(i), hdata(hd), out(o), ptr(_ptr)
@ -829,10 +817,12 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
.arg(QString::fromLocal8Bit(idoc.url.c_str())) .arg(QString::fromLocal8Bit(idoc.url.c_str()))
.arg(QString::fromUtf8(idoc.fbytes.c_str())); .arg(QString::fromUtf8(idoc.fbytes.c_str()));
// Create progress dialog and aux objects QProgressDialog progress(msg, tr("Cancel"), 0, 0, this);
const int nsteps = 20;
QProgressDialog progress(msg, tr("Cancel"), 0, nsteps, this);
progress.setMinimumDuration(2000); progress.setMinimumDuration(2000);
QEventLoop loop;
QTimer tT;
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &loop, SLOT(quit()));
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Load and convert document // Load and convert document
@ -841,18 +831,19 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
Rcl::Doc fdoc; Rcl::Doc fdoc;
int status = 1; int status = 1;
LoadThread lthr(&status, fdoc, idoc); LoadThread lthr(&status, fdoc, idoc);
connect(&lthr, SIGNAL(finished()), &loop, SLOT(quit()));
lthr.start(); lthr.start();
int prog; for (int i = 0;;i++) {
for (prog = 1;;prog++) { tT.start(1000);
if (lthr.wait(100)) loop.exec();
if (lthr.isFinished())
break; break;
progress.setValue(prog);
qApp->processEvents();
if (progress.wasCanceled()) { if (progress.wasCanceled()) {
CancelCheck::instance().setCancel(); CancelCheck::instance().setCancel();
} }
if (prog >= 5) if (i == 2)
sleep(1); progress.show();
} }
LOGDEB(("loadDocInCurrentTab: after file load: cancel %d status %d" LOGDEB(("loadDocInCurrentTab: after file load: cancel %d status %d"
@ -862,6 +853,7 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
if (CancelCheck::instance().cancelState()) if (CancelCheck::instance().cancelState())
return false; return false;
if (status != 0) { if (status != 0) {
progress.close();
QString explain; QString explain;
if (!lthr.missing.empty()) { if (!lthr.missing.empty()) {
explain = QString::fromUtf8("<br>") + explain = QString::fromUtf8("<br>") +
@ -940,18 +932,17 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
} }
list<string> richlst; list<string> richlst;
ToRichThread rthr(fdoc.text, m_hData, richlst, editor->m_plaintorich); ToRichThread rthr(fdoc.text, m_hData, richlst, editor->m_plaintorich);
connect(&rthr, SIGNAL(finished()), &loop, SLOT(quit()));
rthr.start(); rthr.start();
for (;;prog++) { for (;;) {
if (rthr.wait(100)) tT.start(1000);
loop.exec();
if (rthr.isFinished())
break; break;
progress.setValue(nsteps);
qApp->processEvents();
if (progress.wasCanceled()) { if (progress.wasCanceled()) {
CancelCheck::instance().setCancel(); CancelCheck::instance().setCancel();
} }
if (prog >= 5)
sleep(1);
} }
// Conversion to rich text done // Conversion to rich text done
@ -995,16 +986,12 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
#endif #endif
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Load text into editor window. // Load text into editor window.
prog = 2 * nsteps / 3;
progress.setLabelText(tr("Loading preview text into editor")); progress.setLabelText(tr("Loading preview text into editor"));
qApp->processEvents(); qApp->processEvents();
int instep = 0;
for (list<QString>::iterator it = qrichlst.begin(); for (list<QString>::iterator it = qrichlst.begin();
it != qrichlst.end(); it++, prog++, instep++) { it != qrichlst.end(); it++) {
progress.setValue(prog);
qApp->processEvents(); qApp->processEvents();
editor->append(*it); editor->append(*it);

View file

@ -16,9 +16,6 @@
*/ */
#include "autoconfig.h" #include "autoconfig.h"
#include <fcntl.h>
#include "safeunistd.h"
#include <utility> #include <utility>
#include MEMORY_INCLUDE #include MEMORY_INCLUDE
@ -138,10 +135,14 @@ void RclMain::init()
// idxstatus file. Make sure it exists before trying to watch it // idxstatus file. Make sure it exists before trying to watch it
// (case where we're started on an older index, or if the status // (case where we're started on an older index, or if the status
// file was deleted since indexing // file was deleted since indexing)
::close(::open(theconfig->getIdxStatusFile().c_str(), O_CREAT, 0600)); QString idxfn =
m_watcher.addPath(QString::fromLocal8Bit( QString::fromLocal8Bit(theconfig->getIdxStatusFile().c_str());
theconfig->getIdxStatusFile().c_str())); QFile qf(idxfn);
qf.open(QIODevice::ReadWrite);
qf.setPermissions(QFile::ReadOwner|QFile::WriteOwner);
qf.close();
m_watcher.addPath(idxfn);
// At least some versions of qt4 don't display the status bar if // At least some versions of qt4 don't display the status bar if
// it's not created here. // it's not created here.
(void)statusBar(); (void)statusBar();
@ -728,7 +729,7 @@ void RclMain::initiateQuery()
qApp->processEvents(); qApp->processEvents();
if (progress.wasCanceled()) { if (progress.wasCanceled()) {
// Just get out of there asap. // Just get out of there asap.
_exit(1); exit(1);
} }
qApp->processEvents(); qApp->processEvents();

View file

@ -16,7 +16,6 @@
*/ */
#include "autoconfig.h" #include "autoconfig.h"
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>

View file

@ -17,7 +17,6 @@
#include "autoconfig.h" #include "autoconfig.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <algorithm> #include <algorithm>
#include <list> #include <list>