Browse Source

Added missing files

Jakob Truelsen 16 years ago
parent
commit
3b2bddf5d5
3 changed files with 136 additions and 0 deletions
  1. 3 0
      src/pageconverter.cc
  2. 99 0
      src/progressfeedback.cc
  3. 34 0
      src/progressfeedback.hh

+ 3 - 0
src/pageconverter.cc

@@ -323,6 +323,9 @@ void PageConverterPrivate::printPage(bool ok) {
 
 	currentPhase = 4;
 	emit outer.phaseChanged();
+
+	progressString = "Preparing";
+	emit outer.progressChanged(0);
 	
 	for(int cc_=0; cc_ < cc; ++cc_) {
 		//TODO print front here

+ 99 - 0
src/progressfeedback.cc

@@ -0,0 +1,99 @@
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#include "progressfeedback.hh"
+
+/*!
+  \file progressfeedback.hh
+  \brief Define the ProgressFeedback class
+*/
+
+/*!
+  \class ProgressFeedback
+  \brief Produce progress feedback on the terminal
+*/
+
+#define S(t) ((t).toLocal8Bit().constData())
+	
+/*!
+  \brief Write out a warning message
+  \param message The warning message
+*/
+void ProgressFeedback::warning(const QString &message) {
+	fprintf(stderr, "Warning: %s",S(message));
+	for(int l = 9 + message.size(); l < lw; ++l) 
+		fprintf(stderr, " ");
+	fprintf(stderr, "\n");
+	lw = 0;
+}
+
+/*!
+  \brief Write out an error message
+  \param message The error message
+*/
+void ProgressFeedback::error(const QString &message) {
+	fprintf(stderr, "Error: %s",S(message));
+	for(int l = 7 + message.size(); l < lw; ++l) 
+		fprintf(stderr, " ");
+	fprintf(stderr, "\n");
+	lw = 0;
+}
+
+/*!
+  \brief Write out the name of the next phase
+*/
+void ProgressFeedback::phaseChanged() {
+	QString desc=pageConverter.phaseDescription();
+	fprintf(stderr, "%s", S(desc));
+	
+	int l = desc.size();
+	if(pageConverter.currentPhase() < pageConverter.phaseCount() -1)
+		l += fprintf(stderr," (%d/%d)",pageConverter.currentPhase()+1,pageConverter.phaseCount()-1);
+	for(; l < lw; ++l) 
+		fprintf(stderr, " ");
+	fprintf(stderr, "\n");
+	lw = 0;
+}
+
+/*!
+  \brief Update progress bar
+*/
+void ProgressFeedback::progressChanged(int progress) {
+	fprintf(stderr, "[");
+	int w=60;
+	progress *= w;
+	progress /= 100;
+	for (int i=0; i < w; ++i) {
+		if (i < progress) fprintf(stderr, "=");
+		else if (i == progress) fprintf(stderr, ">");
+		else fprintf(stderr, " ");
+	}
+	fprintf(stderr, "]");
+	fprintf(stderr, " %s", S(pageConverter.progressString()));
+	int l=1+w+2+pageConverter.progressString().size();
+	for(int i=l; i < lw; ++i) fprintf(stderr, " ");
+	lw = l;
+	fprintf(stderr, "\r");
+    //rintf(stderr, "Progress: %d%%\n",progress);
+}
+
+ProgressFeedback::ProgressFeedback(PageConverter & _):
+    pageConverter(_), lw(0) {
+    connect(&pageConverter, SIGNAL(warning(const QString &)), this, SLOT(warning(const QString &)));
+	connect(&pageConverter, SIGNAL(error(const QString &)), this, SLOT(error(const QString &)));
+	connect(&pageConverter, SIGNAL(phaseChanged()), this, SLOT(phaseChanged()));
+	connect(&pageConverter, SIGNAL(progressChanged(int)), this, SLOT(progressChanged(int)));
+}
+

+ 34 - 0
src/progressfeedback.hh

@@ -0,0 +1,34 @@
+//-*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// This file is part of wkhtmltopdf.
+//
+// wkhtmltopdf is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// wkhtmltopdf is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
+#ifndef __PROGRESSFEEDBACK_HH__
+#define __PROGRESSFEEDBACK_HH__
+#include "pageconverter.hh"
+
+class ProgressFeedback: public QObject {
+	Q_OBJECT
+public:
+	PageConverter & pageConverter;
+	int lw;
+public slots:
+	void warning(const QString &message);
+	void error(const QString &message);
+	void phaseChanged();
+	void progressChanged(int progress);
+public:
+	ProgressFeedback(PageConverter & _);
+};
+
+#endif //__PROGRESSFEEDBACK_HH__