Chris@392: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@392: Chris@392: /* Chris@392: Sonic Visualiser Chris@392: An audio file viewer and annotation editor. Chris@392: Centre for Digital Music, Queen Mary, University of London. Chris@392: This file copyright 2007 QMUL. Chris@392: Chris@392: This program is free software; you can redistribute it and/or Chris@392: modify it under the terms of the GNU General Public License as Chris@392: published by the Free Software Foundation; either version 2 of the Chris@392: License, or (at your option) any later version. See the file Chris@392: COPYING included with this distribution for more information. Chris@392: */ Chris@392: Chris@392: #include "ProgressPrinter.h" Chris@392: Chris@392: #include Chris@392: Chris@392: ProgressPrinter::ProgressPrinter(QString message, QObject *parent) : Chris@392: ProgressReporter(parent), Chris@392: m_prefix(message), Chris@439: m_lastProgress(0), Chris@439: m_definite(true) Chris@392: { Chris@392: } Chris@392: Chris@392: ProgressPrinter::~ProgressPrinter() Chris@392: { Chris@392: if (m_lastProgress > 0 && m_lastProgress != 100) { Chris@392: std::cerr << "\r\n"; Chris@392: } Chris@392: // std::cerr << "(progress printer dtor)" << std::endl; Chris@392: } Chris@392: Chris@439: bool Chris@439: ProgressPrinter::isDefinite() const Chris@439: { Chris@439: return m_definite; Chris@439: } Chris@439: Chris@439: void Chris@439: ProgressPrinter::setDefinite(bool definite) Chris@439: { Chris@439: m_definite = definite; Chris@439: } Chris@439: Chris@392: void Chris@393: ProgressPrinter::setMessage(QString message) Chris@393: { Chris@393: m_prefix = message; Chris@393: } Chris@393: Chris@393: void Chris@515: ProgressPrinter::done() Chris@515: { Chris@517: std::cerr << "\r" Chris@517: << m_prefix.toStdString() Chris@517: << (m_prefix == "" ? "" : " ") Chris@517: << "Done" << std::endl; Chris@515: } Chris@515: Chris@515: void Chris@392: ProgressPrinter::setProgress(int progress) Chris@392: { Chris@392: if (progress == m_lastProgress) return; Chris@517: std::cerr << "\r" Chris@517: << m_prefix.toStdString() Chris@517: << (m_prefix == "" ? "" : " "); Chris@517: if (m_definite) { Chris@517: std::cerr << progress << "%"; Chris@517: } else { Chris@517: std::cerr << "|/-\\"[progress % 4]; Chris@392: } Chris@392: m_lastProgress = progress; Chris@392: } Chris@392: