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@439
|
23 m_lastProgress(0),
|
Chris@439
|
24 m_definite(true)
|
Chris@392
|
25 {
|
Chris@392
|
26 }
|
Chris@392
|
27
|
Chris@392
|
28 ProgressPrinter::~ProgressPrinter()
|
Chris@392
|
29 {
|
Chris@392
|
30 if (m_lastProgress > 0 && m_lastProgress != 100) {
|
Chris@392
|
31 std::cerr << "\r\n";
|
Chris@392
|
32 }
|
Chris@392
|
33 // std::cerr << "(progress printer dtor)" << std::endl;
|
Chris@392
|
34 }
|
Chris@392
|
35
|
Chris@439
|
36 bool
|
Chris@439
|
37 ProgressPrinter::isDefinite() const
|
Chris@439
|
38 {
|
Chris@439
|
39 return m_definite;
|
Chris@439
|
40 }
|
Chris@439
|
41
|
Chris@439
|
42 void
|
Chris@439
|
43 ProgressPrinter::setDefinite(bool definite)
|
Chris@439
|
44 {
|
Chris@439
|
45 m_definite = definite;
|
Chris@439
|
46 }
|
Chris@439
|
47
|
Chris@392
|
48 void
|
Chris@393
|
49 ProgressPrinter::setMessage(QString message)
|
Chris@393
|
50 {
|
Chris@393
|
51 m_prefix = message;
|
Chris@393
|
52 }
|
Chris@393
|
53
|
Chris@393
|
54 void
|
Chris@515
|
55 ProgressPrinter::done()
|
Chris@515
|
56 {
|
Chris@515
|
57 setProgress(100);
|
Chris@515
|
58 }
|
Chris@515
|
59
|
Chris@515
|
60 void
|
Chris@392
|
61 ProgressPrinter::setProgress(int progress)
|
Chris@392
|
62 {
|
Chris@392
|
63 if (progress == m_lastProgress) return;
|
Chris@392
|
64 if (progress == 100) std::cerr << "\r\n";
|
Chris@392
|
65 else {
|
Chris@392
|
66 std::cerr << "\r"
|
Chris@392
|
67 << m_prefix.toStdString()
|
Chris@439
|
68 << (m_prefix == "" ? "" : " ");
|
Chris@439
|
69 if (m_definite) {
|
Chris@439
|
70 std::cerr << progress << "%";
|
Chris@439
|
71 } else {
|
Chris@439
|
72 std::cerr << "|/-\\"[progress % 4];
|
Chris@439
|
73 }
|
Chris@392
|
74 }
|
Chris@392
|
75 m_lastProgress = progress;
|
Chris@392
|
76 }
|
Chris@392
|
77
|