forked from Ivasoft/DSView
Add save data reminder when hardware detach
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "storeprogress.h"
|
||||
#include "dsmessagebox.h"
|
||||
#include "pv/sigsession.h"
|
||||
|
||||
#include "QVBoxLayout"
|
||||
|
||||
@@ -59,15 +60,19 @@ void StoreProgress::reject()
|
||||
{
|
||||
using namespace Qt;
|
||||
_store_session.cancel();
|
||||
save_done();
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void StoreProgress::timeout()
|
||||
{
|
||||
if (_done)
|
||||
if (_done) {
|
||||
_store_session.session().set_saving(false);
|
||||
save_done();
|
||||
close();
|
||||
else
|
||||
} else {
|
||||
QTimer::singleShot(100, this, SLOT(timeout()));
|
||||
}
|
||||
}
|
||||
|
||||
void StoreProgress::save_run(QString session_file)
|
||||
@@ -76,7 +81,7 @@ void StoreProgress::save_run(QString session_file)
|
||||
if (_store_session.save_start(session_file))
|
||||
show();
|
||||
else
|
||||
show_error();
|
||||
show_error();
|
||||
|
||||
QTimer::singleShot(100, this, SLOT(timeout()));
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ private:
|
||||
void show_error();
|
||||
void closeEvent(QCloseEvent* e);
|
||||
|
||||
signals:
|
||||
void save_done();
|
||||
|
||||
public slots:
|
||||
void save_run(QString session_file);
|
||||
void export_run();
|
||||
|
||||
@@ -54,6 +54,10 @@
|
||||
#include "device/device.h"
|
||||
#include "device/file.h"
|
||||
|
||||
#include "data/logicsnapshot.h"
|
||||
#include "data/dsosnapshot.h"
|
||||
#include "data/analogsnapshot.h"
|
||||
|
||||
#include "dialogs/about.h"
|
||||
#include "dialogs/deviceoptions.h"
|
||||
#include "dialogs/storeprogress.h"
|
||||
@@ -100,6 +104,7 @@ MainWindow::MainWindow(DeviceManager &device_manager,
|
||||
QMainWindow(parent),
|
||||
_device_manager(device_manager),
|
||||
_session(device_manager),
|
||||
_hot_detach(false),
|
||||
_msg(NULL)
|
||||
{
|
||||
setup_ui();
|
||||
@@ -460,9 +465,9 @@ void MainWindow::update_device_list()
|
||||
"Please replug it into a USB 3.0 port."));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::reload()
|
||||
{
|
||||
_trigger_widget->device_updated();
|
||||
@@ -534,7 +539,38 @@ void MainWindow::device_detach()
|
||||
|
||||
session_save();
|
||||
_view->hide_calibration();
|
||||
if (_session.get_device()->dev_inst()->mode != DSO &&
|
||||
strncmp(_session.get_device()->name().toLocal8Bit(), "virtual", 7)) {
|
||||
const boost::shared_ptr<data::Snapshot> logic_snapshot(_session.get_snapshot(SR_CHANNEL_LOGIC));
|
||||
assert(logic_snapshot);
|
||||
const boost::shared_ptr<data::Snapshot> analog_snapshot(_session.get_snapshot(SR_CHANNEL_ANALOG));
|
||||
assert(analog_snapshot);
|
||||
|
||||
if (!logic_snapshot->empty() || !analog_snapshot->empty()) {
|
||||
dialogs::DSMessageBox msg(this);
|
||||
_msg = &msg;
|
||||
msg.mBox()->setText(tr("Hardware Detached"));
|
||||
msg.mBox()->setInformativeText(tr("Save captured data?"));
|
||||
msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole);
|
||||
msg.mBox()->addButton(tr("Cancel"), QMessageBox::RejectRole);
|
||||
msg.mBox()->setIcon(QMessageBox::Warning);
|
||||
if (msg.exec())
|
||||
on_save();
|
||||
_msg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_hot_detach = true;
|
||||
if (!_session.get_saving())
|
||||
device_detach_post();
|
||||
}
|
||||
|
||||
void MainWindow::device_detach_post()
|
||||
{
|
||||
if (!_hot_detach)
|
||||
return;
|
||||
|
||||
_hot_detach = false;
|
||||
struct sr_dev_driver **const drivers = sr_driver_list();
|
||||
struct sr_dev_driver **driver;
|
||||
for (driver = drivers; *driver; driver++)
|
||||
@@ -839,6 +875,7 @@ void MainWindow::on_save()
|
||||
// dialogs::RegionOptions *regionDlg = new dialogs::RegionOptions(_view, _session, this);
|
||||
// regionDlg->exec();
|
||||
|
||||
_session.set_saving(true);
|
||||
QString session_file;
|
||||
QDir dir;
|
||||
#if QT_VERSION >= 0x050400
|
||||
@@ -854,6 +891,7 @@ void MainWindow::on_save()
|
||||
}
|
||||
|
||||
StoreProgress *dlg = new StoreProgress(_session, this);
|
||||
connect(dlg, SIGNAL(save_done()), this, SLOT(device_detach_post()));
|
||||
dlg->save_run(session_file);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,7 @@ private slots:
|
||||
*/
|
||||
void device_attach();
|
||||
void device_detach();
|
||||
void device_detach_post();
|
||||
void device_changed(bool close);
|
||||
|
||||
/*
|
||||
@@ -160,6 +161,7 @@ private:
|
||||
DeviceManager &_device_manager;
|
||||
|
||||
SigSession _session;
|
||||
bool _hot_detach;
|
||||
|
||||
pv::view::View *_view;
|
||||
dialogs::DSMessageBox *_msg;
|
||||
|
||||
@@ -114,6 +114,7 @@ SigSession::SigSession(DeviceManager &device_manager) :
|
||||
#endif
|
||||
_lissajous_trace = NULL;
|
||||
_math_trace = NULL;
|
||||
_saving = false;
|
||||
_dso_feed = false;
|
||||
|
||||
// Create snapshots & data containers
|
||||
@@ -1749,4 +1750,14 @@ uint64_t SigSession::get_save_end() const
|
||||
return _save_end;
|
||||
}
|
||||
|
||||
bool SigSession::get_saving() const
|
||||
{
|
||||
return _saving;
|
||||
}
|
||||
|
||||
void SigSession::set_saving(bool saving)
|
||||
{
|
||||
_saving = saving;
|
||||
}
|
||||
|
||||
} // namespace pv
|
||||
|
||||
@@ -253,6 +253,8 @@ public:
|
||||
void set_save_end(uint64_t end);
|
||||
uint64_t get_save_start() const;
|
||||
uint64_t get_save_end() const;
|
||||
bool get_saving() const;
|
||||
void set_saving(bool saving);
|
||||
|
||||
private:
|
||||
void set_capture_state(capture_state state);
|
||||
@@ -360,6 +362,7 @@ private:
|
||||
|
||||
uint64_t _save_start;
|
||||
uint64_t _save_end;
|
||||
bool _saving;
|
||||
|
||||
bool _dso_feed;
|
||||
|
||||
|
||||
@@ -65,7 +65,8 @@ StoreSession::StoreSession(SigSession &session) :
|
||||
_outModule(NULL),
|
||||
_units_stored(0),
|
||||
_unit_count(0),
|
||||
_has_error(false)
|
||||
_has_error(false),
|
||||
_canceled(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -74,6 +75,11 @@ StoreSession::~StoreSession()
|
||||
wait();
|
||||
}
|
||||
|
||||
SigSession& StoreSession::session()
|
||||
{
|
||||
return _session;
|
||||
}
|
||||
|
||||
pair<uint64_t, uint64_t> StoreSession::progress() const
|
||||
{
|
||||
//lock_guard<mutex> lock(_mutex);
|
||||
@@ -94,6 +100,7 @@ void StoreSession::wait()
|
||||
|
||||
void StoreSession::cancel()
|
||||
{
|
||||
_canceled = true;
|
||||
_thread.interrupt();
|
||||
}
|
||||
|
||||
@@ -174,7 +181,6 @@ bool StoreSession::save_start(QString session_file)
|
||||
#endif
|
||||
if (meta_file == NULL) {
|
||||
_error = tr("Generate temp file failed.");
|
||||
return false;
|
||||
} else {
|
||||
int ret = sr_session_save_init(_file_name.toLocal8Bit().data(),
|
||||
meta_file.toLocal8Bit().data(),
|
||||
@@ -182,7 +188,6 @@ bool StoreSession::save_start(QString session_file)
|
||||
session_file.toLocal8Bit().data());
|
||||
if (ret != SR_OK) {
|
||||
_error = tr("Failed to create zip file. Please check write permission of this path.");
|
||||
return false;
|
||||
} else {
|
||||
_thread = boost::thread(&StoreSession::save_proc, this, snapshot);
|
||||
return !_has_error;
|
||||
@@ -190,6 +195,7 @@ bool StoreSession::save_start(QString session_file)
|
||||
}
|
||||
}
|
||||
|
||||
QFile::remove(_file_name);
|
||||
_error.clear();
|
||||
return false;
|
||||
}
|
||||
@@ -199,6 +205,7 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
||||
assert(snapshot);
|
||||
|
||||
int ret = SR_ERR;
|
||||
int num = 0;
|
||||
shared_ptr<data::LogicSnapshot> logic_snapshot;
|
||||
shared_ptr<data::AnalogSnapshot> analog_snapshot;
|
||||
shared_ptr<data::DsoSnapshot> dso_snapshot;
|
||||
@@ -210,7 +217,7 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
||||
to_save_probes++;
|
||||
}
|
||||
_unit_count = logic_snapshot->get_sample_count() / 8 * to_save_probes;
|
||||
int num = logic_snapshot->get_block_num();
|
||||
num = logic_snapshot->get_block_num();
|
||||
bool sample;
|
||||
|
||||
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
|
||||
@@ -240,6 +247,8 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
||||
_error = tr("Failed to create zip file. Please check write permission of this path.");
|
||||
}
|
||||
progress_updated();
|
||||
if (_has_error)
|
||||
QFile::remove(_file_name);
|
||||
return;
|
||||
}
|
||||
_units_stored += size;
|
||||
@@ -256,7 +265,7 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
||||
break;
|
||||
}
|
||||
if (ch_type != -1) {
|
||||
const int num = snapshot->get_block_num();
|
||||
num = snapshot->get_block_num();
|
||||
_unit_count = snapshot->get_sample_count() *
|
||||
snapshot->get_unit_bytes() *
|
||||
snapshot->get_channel_num();
|
||||
@@ -292,6 +301,8 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
||||
_error = tr("Failed to create zip file. Please check write permission of this path.");
|
||||
}
|
||||
progress_updated();
|
||||
if (_has_error)
|
||||
QFile::remove(_file_name);
|
||||
return;
|
||||
}
|
||||
_units_stored += size;
|
||||
@@ -300,6 +311,9 @@ void StoreSession::save_proc(shared_ptr<data::Snapshot> snapshot)
|
||||
}
|
||||
}
|
||||
progress_updated();
|
||||
|
||||
if (_canceled || num == 0)
|
||||
QFile::remove(_file_name);
|
||||
}
|
||||
|
||||
QString StoreSession::meta_gen(boost::shared_ptr<data::Snapshot> snapshot)
|
||||
|
||||
@@ -56,6 +56,8 @@ public:
|
||||
|
||||
~StoreSession();
|
||||
|
||||
SigSession& session();
|
||||
|
||||
std::pair<uint64_t, uint64_t> progress() const;
|
||||
|
||||
const QString& error() const;
|
||||
@@ -103,6 +105,7 @@ private:
|
||||
uint64_t _unit_count;
|
||||
bool _has_error;
|
||||
QString _error;
|
||||
bool _canceled;
|
||||
};
|
||||
|
||||
} // pv
|
||||
|
||||
Reference in New Issue
Block a user