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@843: #include "Debug.h" Chris@843: 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@521: if (m_prefix.length() > 70) { Chris@521: m_prefix = m_prefix.left(70) + "..."; Chris@521: } Chris@392: } Chris@392: Chris@392: ProgressPrinter::~ProgressPrinter() Chris@392: { Chris@392: if (m_lastProgress > 0 && m_lastProgress != 100) { Chris@843: cerr << "\r\n"; Chris@392: } Chris@843: // cerr << "(progress printer dtor)" << 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@624: if (m_prefix.length() > 70) { Chris@624: m_prefix = m_prefix.left(70) + "..."; Chris@624: } Chris@393: } Chris@393: Chris@393: void Chris@515: ProgressPrinter::done() Chris@515: { Chris@843: cerr << "\r" Chris@844: << m_prefix Chris@517: << (m_prefix == "" ? "" : " ") Chris@843: << "Done" << endl; Chris@515: } Chris@515: Chris@515: void Chris@392: ProgressPrinter::setProgress(int progress) Chris@392: { Chris@392: if (progress == m_lastProgress) return; Chris@843: cerr << "\r" Chris@844: << m_prefix Chris@517: << (m_prefix == "" ? "" : " "); Chris@517: if (m_definite) { Chris@843: cerr << progress << "%"; Chris@517: } else { Chris@843: cerr << "|/-\\"[progress % 4]; Chris@392: } Chris@392: m_lastProgress = progress; Chris@392: } Chris@392: