]> sigrok.org Git - pulseview.git/blame_incremental - pv/dialogs/storeprogress.cpp
TraceView: Center traces more than once
[pulseview.git] / pv / dialogs / storeprogress.cpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <cassert>
21
22#include <QMessageBox>
23
24#include "storeprogress.hpp"
25
26using std::map;
27using std::string;
28
29using Glib::VariantBase;
30
31namespace pv {
32namespace dialogs {
33
34StoreProgress::StoreProgress(const QString &file_name,
35 const std::shared_ptr<sigrok::OutputFormat> output_format,
36 const map<string, VariantBase> &options,
37 const std::pair<uint64_t, uint64_t> sample_range,
38 const Session &session, QWidget *parent) :
39 QProgressDialog(tr("Saving..."), tr("Cancel"), 0, 0, parent),
40 session_(file_name.toStdString(), output_format, options, sample_range,
41 session)
42{
43 connect(&session_, SIGNAL(progress_updated()),
44 this, SLOT(on_progress_updated()));
45}
46
47StoreProgress::~StoreProgress()
48{
49 session_.wait();
50}
51
52void StoreProgress::run()
53{
54 if (session_.start())
55 show();
56 else
57 show_error();
58}
59
60void StoreProgress::show_error()
61{
62 QMessageBox msg(parentWidget());
63 msg.setText(tr("Failed to save session."));
64 msg.setInformativeText(session_.error());
65 msg.setStandardButtons(QMessageBox::Ok);
66 msg.setIcon(QMessageBox::Warning);
67 msg.exec();
68}
69
70void StoreProgress::closeEvent(QCloseEvent*)
71{
72 session_.cancel();
73}
74
75void StoreProgress::on_progress_updated()
76{
77 const std::pair<int, int> p = session_.progress();
78 assert(p.first <= p.second);
79
80 if (p.second) {
81 setValue(p.first);
82 setMaximum(p.second);
83 } else {
84 const QString err = session_.error();
85 if (!err.isEmpty())
86 show_error();
87 close();
88 }
89}
90
91} // dialogs
92} // pv