annotate base/ProgressPrinter.cpp @ 399:0f0f08c22552

...
author Chris Cannam
date Fri, 28 Mar 2008 17:51:13 +0000
parents cfd11e44ad87
children beb2948baa77
rev   line source
Chris@392 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@392 2
Chris@392 3 /*
Chris@392 4 Sonic Visualiser
Chris@392 5 An audio file viewer and annotation editor.
Chris@392 6 Centre for Digital Music, Queen Mary, University of London.
Chris@392 7 This file copyright 2007 QMUL.
Chris@392 8
Chris@392 9 This program is free software; you can redistribute it and/or
Chris@392 10 modify it under the terms of the GNU General Public License as
Chris@392 11 published by the Free Software Foundation; either version 2 of the
Chris@392 12 License, or (at your option) any later version. See the file
Chris@392 13 COPYING included with this distribution for more information.
Chris@392 14 */
Chris@392 15
Chris@392 16 #include "ProgressPrinter.h"
Chris@392 17
Chris@392 18 #include <iostream>
Chris@392 19
Chris@392 20 ProgressPrinter::ProgressPrinter(QString message, QObject *parent) :
Chris@392 21 ProgressReporter(parent),
Chris@392 22 m_prefix(message),
Chris@392 23 m_lastProgress(0)
Chris@392 24 {
Chris@392 25 }
Chris@392 26
Chris@392 27 ProgressPrinter::~ProgressPrinter()
Chris@392 28 {
Chris@392 29 if (m_lastProgress > 0 && m_lastProgress != 100) {
Chris@392 30 std::cerr << "\r\n";
Chris@392 31 }
Chris@392 32 // std::cerr << "(progress printer dtor)" << std::endl;
Chris@392 33 }
Chris@392 34
Chris@392 35 void
Chris@393 36 ProgressPrinter::setMessage(QString message)
Chris@393 37 {
Chris@393 38 m_prefix = message;
Chris@393 39 }
Chris@393 40
Chris@393 41 void
Chris@392 42 ProgressPrinter::setProgress(int progress)
Chris@392 43 {
Chris@392 44 if (progress == m_lastProgress) return;
Chris@392 45 if (progress == 100) std::cerr << "\r\n";
Chris@392 46 else {
Chris@392 47 std::cerr << "\r"
Chris@392 48 << m_prefix.toStdString()
Chris@392 49 << (m_prefix == "" ? "" : " ")
Chris@392 50 << progress << "%";
Chris@392 51 }
Chris@392 52 m_lastProgress = progress;
Chris@392 53 }
Chris@392 54