xca/lib/XcaProgress.cpp
Christian Hohnstaedt 82da759a4e XcaProgress: separate Cmdline progress from GUI progress
The generic XcaProgress object is used, which dynamically
creates a Cmdline progress object.
The Mainwindow replaces it by a GUI object, which integrates
into the status bar.
2021-06-01 17:48:37 +02:00

63 lines
976 B
C++

/* vi: set sw=4 ts=4:
*
* Copyright (C) 2018 - 2020 Christian Hohnstaedt.
*
* All rights reserved.
*/
#include <stdio.h>
#include <string.h>
#include "base.h"
#include "XcaProgress.h"
void XcaProgressCmd::stop()
{
puts(" finished.");
}
void XcaProgressCmd::start(const QString &what, int)
{
puts("");
puts(CCHAR(what));
}
void XcaProgressCmd::increment()
{
static const char *spinner = "|/-\\";
printf("\rGenerating %c ...", spinner[i++%4]);
fflush(stdout);
}
XcaProgress_i *XcaProgress::progress;
XcaProgress::XcaProgress(const QString &what, int max)
{
if (!progress)
progress = new XcaProgressCmd();
progress->start(what, max);
}
XcaProgress::~XcaProgress()
{
progress->stop();
}
void XcaProgress::increment()
{
progress->increment();
}
void XcaProgress::inc(int, int, void *p)
{
XcaProgress *prog = static_cast<XcaProgress*>(p);
if (prog)
prog->increment();
}
void XcaProgress::setGui(XcaProgress_i *p)
{
delete progress;
progress = p;
}