forked from Ivasoft/DSView
able to export original data
This commit is contained in:
@@ -90,7 +90,7 @@ void _loadApp(AppOptions &o, QSettings &st){
|
||||
st.beginGroup("Application");
|
||||
getFiled("quickScroll", st, o.quickScroll, true);
|
||||
getFiled("warnofMultiTrig", st, o.warnofMultiTrig, true);
|
||||
|
||||
getFiled("originalData", st, o.originalData, false);
|
||||
|
||||
QString fmt;
|
||||
getFiled("protocalFormats", st, fmt, "");
|
||||
@@ -105,6 +105,7 @@ void _saveApp(AppOptions &o, QSettings &st){
|
||||
st.beginGroup("Application");
|
||||
setFiled("quickScroll", st, o.quickScroll);
|
||||
setFiled("warnofMultiTrig", st, o.warnofMultiTrig);
|
||||
setFiled("originalData", st, o.originalData);
|
||||
|
||||
|
||||
QString fmt = FormatArrayToString(o.m_protocolFormats);
|
||||
@@ -149,6 +150,7 @@ void _loadHistory(UserHistory &o, QSettings &st){
|
||||
getFiled("sessionDir", st, o.sessionDir, "");
|
||||
getFiled("openDir", st, o.openDir, "");
|
||||
getFiled("protocolExportPath", st, o.protocolExportPath, "");
|
||||
getFiled("exportFormat", st, o.exportFormat, "");
|
||||
st.endGroup();
|
||||
}
|
||||
|
||||
@@ -160,7 +162,8 @@ void _saveHistory(UserHistory &o, QSettings &st){
|
||||
setFiled("screenShotPath", st, o.screenShotPath);
|
||||
setFiled("sessionDir", st, o.sessionDir);
|
||||
setFiled("openDir", st, o.openDir);
|
||||
setFiled("protocolExportPath", st, o.protocolExportPath);
|
||||
setFiled("protocolExportPath", st, o.protocolExportPath);
|
||||
setFiled("exportFormat", st, o.exportFormat);
|
||||
st.endGroup();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,19 +45,17 @@ public:
|
||||
string m_value;
|
||||
};
|
||||
|
||||
class AppOptions
|
||||
{
|
||||
public:
|
||||
struct AppOptions
|
||||
{
|
||||
bool quickScroll;
|
||||
bool warnofMultiTrig;
|
||||
|
||||
bool originalData;
|
||||
|
||||
vector<StringPair> m_protocolFormats;
|
||||
};
|
||||
|
||||
class FrameOptions
|
||||
{
|
||||
public:
|
||||
struct FrameOptions
|
||||
{
|
||||
QString style;
|
||||
int language;
|
||||
QByteArray geometry;
|
||||
@@ -65,9 +63,8 @@ public:
|
||||
QByteArray windowState;
|
||||
};
|
||||
|
||||
class UserHistory
|
||||
{
|
||||
public:
|
||||
struct UserHistory
|
||||
{
|
||||
QString exportDir;
|
||||
QString saveDir;
|
||||
bool showDocuments;
|
||||
@@ -75,6 +72,7 @@ public:
|
||||
QString sessionDir;
|
||||
QString openDir;
|
||||
QString protocolExportPath;
|
||||
QString exportFormat;
|
||||
};
|
||||
|
||||
class AppConfig
|
||||
|
||||
@@ -19,36 +19,70 @@
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "storeprogress.h"
|
||||
#include "dsmessagebox.h"
|
||||
#include "storeprogress.h"
|
||||
#include "pv/sigsession.h"
|
||||
#include <QGridLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QTimer>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
|
||||
#include "QVBoxLayout"
|
||||
#include "../ui/msgbox.h"
|
||||
#include "../config/appconfig.h"
|
||||
|
||||
namespace pv {
|
||||
namespace dialogs {
|
||||
|
||||
StoreProgress::StoreProgress(SigSession &session, QWidget *parent) :
|
||||
DSDialog(parent),
|
||||
_store_session(session),
|
||||
_button_box(QDialogButtonBox::Cancel, Qt::Horizontal, this),
|
||||
_done(false)
|
||||
_store_session(session)
|
||||
{
|
||||
this->setModal(true);
|
||||
_fileLab = NULL;
|
||||
_ckOrigin = NULL;
|
||||
|
||||
_info.setText("...");
|
||||
this->setMinimumSize(550, 220);
|
||||
this->setModal(true);
|
||||
|
||||
_progress.setValue(0);
|
||||
_progress.setMaximum(100);
|
||||
|
||||
QVBoxLayout* add_layout = new QVBoxLayout();
|
||||
add_layout->addWidget(&_info, 0, Qt::AlignCenter);
|
||||
add_layout->addWidget(&_progress);
|
||||
add_layout->addWidget(&_button_box);
|
||||
layout()->addLayout(add_layout);
|
||||
_isExport = false;
|
||||
_done = false;
|
||||
|
||||
QGridLayout *grid = new QGridLayout();
|
||||
_grid = grid;
|
||||
grid->setContentsMargins(10, 20, 10, 10);
|
||||
grid->setVerticalSpacing(25);
|
||||
|
||||
grid->setColumnStretch(0, 2);
|
||||
grid->setColumnStretch(1, 2);
|
||||
grid->setColumnStretch(2, 1);
|
||||
grid->setColumnStretch(3, 1);
|
||||
|
||||
_fileLab = new QLineEdit();
|
||||
_fileLab->setEnabled(false);
|
||||
|
||||
QPushButton *openButton = new QPushButton(this);
|
||||
openButton->setText(tr("change"));
|
||||
|
||||
grid->addWidget(&_progress, 0, 0, 1, 4);
|
||||
grid->addWidget(_fileLab, 1, 0, 1, 3);
|
||||
grid->addWidget(openButton, 1, 3, 1, 1);
|
||||
|
||||
QDialogButtonBox *_button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
||||
Qt::Horizontal, this);
|
||||
grid->addWidget(_button_box, 2, 2, 1, 2, Qt::AlignRight | Qt::AlignBottom);
|
||||
|
||||
layout()->addLayout(grid);
|
||||
|
||||
connect(_button_box, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(_button_box, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
|
||||
connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(&_store_session, SIGNAL(progress_updated()),
|
||||
this, SLOT(on_progress_updated()), Qt::QueuedConnection);
|
||||
|
||||
connect(openButton, SIGNAL(clicked()),this, SLOT(on_change_file()));
|
||||
}
|
||||
|
||||
StoreProgress::~StoreProgress()
|
||||
@@ -56,12 +90,66 @@ StoreProgress::~StoreProgress()
|
||||
_store_session.wait();
|
||||
}
|
||||
|
||||
void StoreProgress::on_change_file()
|
||||
{
|
||||
if (_isExport){
|
||||
QString file = _store_session.MakeExportFile(true);
|
||||
if (file != "")
|
||||
_fileLab->setText(file);
|
||||
}
|
||||
else{
|
||||
QString file = _store_session.MakeSaveFile(true);
|
||||
if (file != "")
|
||||
_fileLab->setText(file);
|
||||
}
|
||||
}
|
||||
|
||||
void StoreProgress::reject()
|
||||
{
|
||||
using namespace Qt;
|
||||
_store_session.cancel();
|
||||
save_done();
|
||||
QDialog::reject();
|
||||
DSDialog::reject();
|
||||
}
|
||||
|
||||
void StoreProgress::accept()
|
||||
{
|
||||
if (_store_session.GetFileName() == ""){
|
||||
MsgBox::Show(NULL, "you need to select a file name.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isExport && _store_session.IsLogicDataType()){
|
||||
bool ck = _ckOrigin->isChecked();
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
if (app._appOptions.originalData != ck){
|
||||
app._appOptions.originalData = ck;
|
||||
app.SaveApp();
|
||||
}
|
||||
}
|
||||
|
||||
//start done
|
||||
if (_isExport){
|
||||
if (_store_session.export_start()){
|
||||
QTimer::singleShot(100, this, SLOT(timeout()));
|
||||
}
|
||||
else{
|
||||
save_done();
|
||||
close();
|
||||
show_error();
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (_store_session.save_start()){
|
||||
QTimer::singleShot(100, this, SLOT(timeout()));
|
||||
}
|
||||
else{
|
||||
save_done();
|
||||
close();
|
||||
show_error();
|
||||
}
|
||||
}
|
||||
//do not to call base class method, otherwise the window will be closed;
|
||||
}
|
||||
|
||||
void StoreProgress::timeout()
|
||||
@@ -77,36 +165,40 @@ void StoreProgress::timeout()
|
||||
|
||||
void StoreProgress::save_run(QString session_file)
|
||||
{
|
||||
_info.setText(tr("Saving..."));
|
||||
if (_store_session.save_start(session_file))
|
||||
show();
|
||||
else
|
||||
show_error();
|
||||
|
||||
QTimer::singleShot(100, this, SLOT(timeout()));
|
||||
_isExport = false;
|
||||
setTitle(tr("Saving..."));
|
||||
QString file = _store_session.MakeSaveFile(false);
|
||||
_fileLab->setText(file);
|
||||
_store_session._sessionFile = session_file;
|
||||
show();
|
||||
}
|
||||
|
||||
void StoreProgress::export_run()
|
||||
{
|
||||
_info.setText(tr("Exporting..."));
|
||||
if (_store_session.export_start())
|
||||
show();
|
||||
else
|
||||
show_error();
|
||||
if (_store_session.IsLogicDataType())
|
||||
{
|
||||
QGridLayout *lay = new QGridLayout();
|
||||
lay->setContentsMargins(15, 0, 0, 0);
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
_ckOrigin = new QCheckBox();
|
||||
_ckOrigin->setChecked(app._appOptions.originalData);
|
||||
_ckOrigin->setText(tr("all original data"));
|
||||
lay->addWidget(_ckOrigin);
|
||||
_grid->addLayout(lay, 2, 0, 1, 2);
|
||||
}
|
||||
|
||||
QTimer::singleShot(100, this, SLOT(timeout()));
|
||||
_isExport = true;
|
||||
setTitle(tr("Exporting..."));
|
||||
QString file = _store_session.MakeExportFile(false);
|
||||
_fileLab->setText(file);
|
||||
show();
|
||||
}
|
||||
|
||||
void StoreProgress::show_error()
|
||||
{
|
||||
_done = true;
|
||||
if (!_store_session.error().isEmpty()) {
|
||||
dialogs::DSMessageBox msg(parentWidget());
|
||||
msg.mBox()->setText(tr("Failed to save data."));
|
||||
msg.mBox()->setInformativeText(_store_session.error());
|
||||
msg.mBox()->setStandardButtons(QMessageBox::Ok);
|
||||
msg.mBox()->setIcon(QMessageBox::Warning);
|
||||
msg.exec();
|
||||
if (!_store_session.error().isEmpty()) {
|
||||
MsgBox::Show(NULL, _store_session.error().toStdString().c_str(), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,18 +22,16 @@
|
||||
#ifndef DSVIEW_PV_DIALOGS_SAVEPROGRESS_H
|
||||
#define DSVIEW_PV_DIALOGS_SAVEPROGRESS_H
|
||||
|
||||
#include <set>
|
||||
//#include <set>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../storesession.h"
|
||||
#include "../dialogs/dsdialog.h"
|
||||
#include "../toolbars/titlebar.h"
|
||||
#include "../dialogs/dsdialog.h"
|
||||
|
||||
class QLineEdit;
|
||||
class QCheckBox;
|
||||
class QGridLayout;
|
||||
|
||||
namespace pv {
|
||||
|
||||
@@ -51,10 +49,10 @@ public:
|
||||
|
||||
virtual ~StoreProgress();
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
void reject();
|
||||
void accept();
|
||||
|
||||
private:
|
||||
void show_error();
|
||||
@@ -70,17 +68,16 @@ public slots:
|
||||
private slots:
|
||||
void on_progress_updated();
|
||||
void timeout();
|
||||
void on_change_file();
|
||||
|
||||
private:
|
||||
pv::StoreSession _store_session;
|
||||
|
||||
QLabel _info;
|
||||
QProgressBar _progress;
|
||||
QDialogButtonBox _button_box;
|
||||
|
||||
toolbars::TitleBar *_titlebar;
|
||||
|
||||
bool _done;
|
||||
pv::StoreSession _store_session;
|
||||
QProgressBar _progress;
|
||||
bool _done;
|
||||
bool _isExport;
|
||||
QLineEdit *_fileLab;
|
||||
QCheckBox *_ckOrigin;
|
||||
QGridLayout *_grid;
|
||||
};
|
||||
|
||||
} // dialogs
|
||||
|
||||
@@ -379,7 +379,9 @@ void MainFrame::readSettings()
|
||||
{
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
|
||||
_mainWindow->switchLanguage(app._frameOptions.language);
|
||||
if (app._frameOptions.language > 0){
|
||||
_mainWindow->switchLanguage(app._frameOptions.language);
|
||||
}
|
||||
|
||||
if (app._frameOptions.geometry.isEmpty()) {
|
||||
QScreen *screen=QGuiApplication::primaryScreen ();
|
||||
|
||||
@@ -887,9 +887,6 @@ void MainWindow::on_export()
|
||||
{
|
||||
using pv::dialogs::StoreProgress;
|
||||
|
||||
// dialogs::RegionOptions *regionDlg = new dialogs::RegionOptions(_view, _session, this);
|
||||
// regionDlg->exec();
|
||||
|
||||
StoreProgress *dlg = new StoreProgress(_session, this);
|
||||
dlg->export_run();
|
||||
}
|
||||
@@ -1356,7 +1353,7 @@ void MainWindow::switchLanguage(int language)
|
||||
dev->set_config(NULL, NULL, SR_CONF_LANGUAGE, g_variant_new_int16(language));
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
|
||||
if (app._frameOptions.language != language)
|
||||
if (app._frameOptions.language != language && language > 0)
|
||||
{
|
||||
app._frameOptions.language = language;
|
||||
app.SaveFrame();
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QDir>
|
||||
|
||||
#include "config/appconfig.h"
|
||||
|
||||
@@ -137,8 +138,14 @@ QList<QString> StoreSession::getSuportedExportFormats(){
|
||||
return list;
|
||||
}
|
||||
|
||||
bool StoreSession::save_start(QString session_file)
|
||||
bool StoreSession::save_start()
|
||||
{
|
||||
if (_sessionFile == "")
|
||||
{
|
||||
_error = tr("No set session file name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::set<int> type_set;
|
||||
BOOST_FOREACH(const boost::shared_ptr<view::Signal> sig, _session.get_signals()) {
|
||||
assert(sig);
|
||||
@@ -149,11 +156,17 @@ bool StoreSession::save_start(QString session_file)
|
||||
_error = tr("DSView does not currently support"
|
||||
"file saving for multiple data types.");
|
||||
return false;
|
||||
|
||||
} else if (type_set.size() == 0) {
|
||||
_error = tr("No data to save.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_file_name == ""){
|
||||
_error = tr("No set file name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
const boost::shared_ptr<data::Snapshot> snapshot(_session.get_snapshot(*type_set.begin()));
|
||||
assert(snapshot);
|
||||
// Check we have data
|
||||
@@ -161,56 +174,12 @@ bool StoreSession::save_start(QString session_file)
|
||||
_error = tr("No data to save.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//root dir
|
||||
QString default_name;
|
||||
QString meta_file = meta_gen(snapshot);
|
||||
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
if (app._userHistory.saveDir != "")
|
||||
{
|
||||
default_name = app._userHistory.saveDir + "/" + _session.get_device()->name() + "-";
|
||||
}
|
||||
else{
|
||||
default_name = _session.get_device()->name() + "-";
|
||||
}
|
||||
QString decoders_file = decoders_gen();
|
||||
|
||||
for (const GSList *l = _session.get_device()->get_dev_mode_list();
|
||||
l; l = l->next) {
|
||||
const sr_dev_mode *mode = (const sr_dev_mode *)l->data;
|
||||
if (_session.get_device()->dev_inst()->mode == mode->mode) {
|
||||
default_name += mode->acronym;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
default_name += _session.get_session_time().toString("-yyMMdd-hhmmss");
|
||||
|
||||
// Show the dialog
|
||||
QString svFilePath = QFileDialog::getSaveFileName(
|
||||
NULL,
|
||||
tr("Save File"),
|
||||
default_name,
|
||||
tr("DSView Data (*.dsl)"));
|
||||
|
||||
if (!svFilePath.isEmpty()) {
|
||||
QFileInfo f(svFilePath);
|
||||
if(f.suffix().compare("dsl"))
|
||||
svFilePath.append(tr(".dsl"));
|
||||
|
||||
_file_name = svFilePath;
|
||||
svFilePath = GetDirectoryName(svFilePath);
|
||||
|
||||
if (svFilePath != app._userHistory.saveDir){
|
||||
app._userHistory.saveDir = svFilePath;
|
||||
app.SaveHistory();
|
||||
}
|
||||
|
||||
QString meta_file = meta_gen(snapshot);
|
||||
|
||||
QString decoders_file = decoders_gen();
|
||||
|
||||
/*
|
||||
/*
|
||||
if (meta_file == NULL) {
|
||||
_error = tr("Generate temp file failed.");
|
||||
} else {
|
||||
@@ -227,20 +196,20 @@ bool StoreSession::save_start(QString session_file)
|
||||
}
|
||||
*/
|
||||
|
||||
//make zip file
|
||||
if (meta_file != NULL && m_zipDoc.CreateNew(_file_name.toUtf8().data(), false))
|
||||
//make zip file
|
||||
if (meta_file != NULL && m_zipDoc.CreateNew(_file_name.toUtf8().data(), false))
|
||||
{
|
||||
if (!m_zipDoc.AddFromFile(meta_file.toUtf8().data(), "header")
|
||||
|| !m_zipDoc.AddFromFile(decoders_file.toUtf8().data(), "decoders")
|
||||
|| !m_zipDoc.AddFromFile(_sessionFile.toUtf8().data(), "session"))
|
||||
{
|
||||
if ( !m_zipDoc.AddFromFile(meta_file.toUtf8().data(), "header")
|
||||
|| !m_zipDoc.AddFromFile(decoders_file.toUtf8().data(), "decoders")
|
||||
|| !m_zipDoc.AddFromFile(session_file.toUtf8().data(), "session"))
|
||||
{
|
||||
_has_error = true;
|
||||
_error = m_zipDoc.GetError();
|
||||
}
|
||||
else{
|
||||
_thread = boost::thread(&StoreSession::save_proc, this, snapshot);
|
||||
return !_has_error;
|
||||
}
|
||||
_has_error = true;
|
||||
_error = m_zipDoc.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_thread = boost::thread(&StoreSession::save_proc, this, snapshot);
|
||||
return !_has_error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,75 +580,37 @@ bool StoreSession::export_start()
|
||||
return false;
|
||||
}
|
||||
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
|
||||
QString default_name;
|
||||
if (app._userHistory.exportDir != "")
|
||||
{
|
||||
default_name = app._userHistory.exportDir + "/" + _session.get_device()->name() + "-";
|
||||
}
|
||||
else{
|
||||
default_name = _session.get_device()->name() + "-";
|
||||
}
|
||||
if (_file_name == ""){
|
||||
_error = tr("No set file name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const GSList *l = _session.get_device()->get_dev_mode_list();
|
||||
l; l = l->next) {
|
||||
const sr_dev_mode *mode = (const sr_dev_mode *)l->data;
|
||||
if (_session.get_device()->dev_inst()->mode == mode->mode) {
|
||||
default_name += mode->acronym;
|
||||
//set export all data flag
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
int flag = app._appOptions.originalData ? 1 : 0;
|
||||
sr_set_export_original_data(flag);
|
||||
|
||||
const struct sr_output_module **supportedModules = sr_output_list();
|
||||
while (*supportedModules)
|
||||
{
|
||||
if (*supportedModules == NULL)
|
||||
break;
|
||||
if (!strcmp((*supportedModules)->id, _suffix.toUtf8().data()))
|
||||
{
|
||||
_outModule = *supportedModules;
|
||||
break;
|
||||
}
|
||||
}
|
||||
default_name += _session.get_session_time().toString("-yyMMdd-hhmmss");
|
||||
|
||||
// Show the dialog
|
||||
QList<QString> supportedFormats = getSuportedExportFormats();
|
||||
QString filter;
|
||||
for(int i = 0; i < supportedFormats.count();i++){
|
||||
filter.append(supportedFormats[i]);
|
||||
if(i < supportedFormats.count() - 1)
|
||||
filter.append(";;");
|
||||
supportedModules++;
|
||||
}
|
||||
|
||||
QString svFilePath = QFileDialog::getSaveFileName(
|
||||
NULL,
|
||||
tr("Export Data"),
|
||||
default_name,
|
||||
filter,
|
||||
&filter);
|
||||
|
||||
if (!svFilePath.isEmpty()) {
|
||||
QFileInfo f(_file_name);
|
||||
QStringList list = filter.split('.').last().split(')');
|
||||
_suffix = list.first();
|
||||
if(f.suffix().compare(_suffix))
|
||||
svFilePath += tr(".") + _suffix;
|
||||
|
||||
_file_name = svFilePath;
|
||||
svFilePath = GetDirectoryName(svFilePath);
|
||||
|
||||
if (svFilePath != app._userHistory.exportDir ){
|
||||
app._userHistory.exportDir = svFilePath;
|
||||
app.SaveHistory();
|
||||
}
|
||||
|
||||
const struct sr_output_module** supportedModules = sr_output_list();
|
||||
while(*supportedModules){
|
||||
if(*supportedModules == NULL)
|
||||
break;
|
||||
if(!strcmp((*supportedModules)->id, _suffix.toUtf8().data())){
|
||||
_outModule = *supportedModules;
|
||||
break;
|
||||
}
|
||||
supportedModules++;
|
||||
}
|
||||
|
||||
if(_outModule == NULL) {
|
||||
_error = tr("Invalid export format.");
|
||||
} else {
|
||||
_thread = boost::thread(&StoreSession::export_proc, this, snapshot);
|
||||
return !_has_error;
|
||||
}
|
||||
if (_outModule == NULL)
|
||||
{
|
||||
_error = tr("Invalid export format.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_thread = boost::thread(&StoreSession::export_proc, this, snapshot);
|
||||
return !_has_error;
|
||||
}
|
||||
|
||||
_error.clear();
|
||||
@@ -1192,5 +1123,166 @@ double StoreSession::get_integer(GVariant *var)
|
||||
return val;
|
||||
}
|
||||
|
||||
QString StoreSession::MakeSaveFile(bool bDlg)
|
||||
{
|
||||
QString default_name;
|
||||
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
if (app._userHistory.saveDir != "")
|
||||
{
|
||||
default_name = app._userHistory.saveDir + "/" + _session.get_device()->name() + "-";
|
||||
}
|
||||
else{
|
||||
QDir _dir;
|
||||
QString _root = _dir.home().path();
|
||||
default_name = _root + "/" + _session.get_device()->name() + "-";
|
||||
}
|
||||
|
||||
for (const GSList *l = _session.get_device()->get_dev_mode_list();
|
||||
l; l = l->next) {
|
||||
const sr_dev_mode *mode = (const sr_dev_mode *)l->data;
|
||||
if (_session.get_device()->dev_inst()->mode == mode->mode) {
|
||||
default_name += mode->acronym;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
default_name += _session.get_session_time().toString("-yyMMdd-hhmmss");
|
||||
|
||||
// Show the dialog
|
||||
if (bDlg)
|
||||
{
|
||||
default_name = QFileDialog::getSaveFileName(
|
||||
NULL,
|
||||
tr("Save File"),
|
||||
default_name,
|
||||
tr("DSView Data (*.dsl)"));
|
||||
|
||||
if (default_name.isEmpty())
|
||||
{
|
||||
return ""; //no select file
|
||||
}
|
||||
|
||||
QString _dir_path = GetDirectoryName(default_name);
|
||||
|
||||
if (_dir_path != app._userHistory.saveDir)
|
||||
{
|
||||
app._userHistory.saveDir = _dir_path;
|
||||
app.SaveHistory();
|
||||
}
|
||||
}
|
||||
|
||||
QFileInfo f(default_name);
|
||||
if (f.suffix().compare("dsl"))
|
||||
{
|
||||
default_name.append(tr(".dsl"));
|
||||
}
|
||||
_file_name = default_name;
|
||||
return default_name;
|
||||
}
|
||||
|
||||
QString StoreSession::MakeExportFile(bool bDlg)
|
||||
{
|
||||
QString default_name;
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
|
||||
if (app._userHistory.exportDir != "")
|
||||
{
|
||||
default_name = app._userHistory.exportDir + "/" + _session.get_device()->name() + "-";
|
||||
}
|
||||
else{
|
||||
QDir _dir;
|
||||
QString _root = _dir.home().path();
|
||||
default_name = _root + "/" + _session.get_device()->name() + "-";
|
||||
}
|
||||
|
||||
for (const GSList *l = _session.get_device()->get_dev_mode_list();
|
||||
l; l = l->next) {
|
||||
const sr_dev_mode *mode = (const sr_dev_mode *)l->data;
|
||||
if (_session.get_device()->dev_inst()->mode == mode->mode) {
|
||||
default_name += mode->acronym;
|
||||
break;
|
||||
}
|
||||
}
|
||||
default_name += _session.get_session_time().toString("-yyMMdd-hhmmss");
|
||||
|
||||
//ext name
|
||||
QList<QString> supportedFormats = getSuportedExportFormats();
|
||||
QString filter;
|
||||
for(int i = 0; i < supportedFormats.count();i++){
|
||||
filter.append(supportedFormats[i]);
|
||||
if(i < supportedFormats.count() - 1)
|
||||
filter.append(";;");
|
||||
}
|
||||
|
||||
QString selfilter;
|
||||
if (app._userHistory.exportFormat != ""){
|
||||
selfilter.append(app._userHistory.exportFormat);
|
||||
}
|
||||
|
||||
if (bDlg)
|
||||
{
|
||||
default_name = QFileDialog::getSaveFileName(
|
||||
NULL,
|
||||
tr("Export Data"),
|
||||
default_name,
|
||||
filter,
|
||||
&selfilter);
|
||||
|
||||
if (default_name == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
bool bChange = false;
|
||||
QString _dir_path = GetDirectoryName(default_name);
|
||||
if (_dir_path != app._userHistory.exportDir)
|
||||
{
|
||||
app._userHistory.exportDir = _dir_path;
|
||||
bChange = true;
|
||||
}
|
||||
if (selfilter != app._userHistory.exportFormat){
|
||||
app._userHistory.exportFormat = selfilter;
|
||||
bChange = true;
|
||||
}
|
||||
|
||||
if (bChange){
|
||||
app.SaveHistory();
|
||||
}
|
||||
}
|
||||
|
||||
QString extName = selfilter;
|
||||
if (extName == ""){
|
||||
extName = filter;
|
||||
}
|
||||
|
||||
QStringList list = extName.split('.').last().split(')');
|
||||
_suffix = list.first();
|
||||
|
||||
QFileInfo f(default_name);
|
||||
if(f.suffix().compare(_suffix)){
|
||||
default_name += tr(".") + _suffix;
|
||||
}
|
||||
|
||||
_file_name = default_name;
|
||||
return default_name;
|
||||
}
|
||||
|
||||
bool StoreSession::IsLogicDataType()
|
||||
{
|
||||
std::set<int> type_set;
|
||||
BOOST_FOREACH(const boost::shared_ptr<view::Signal> sig, _session.get_signals()) {
|
||||
assert(sig);
|
||||
type_set.insert(sig->get_type());
|
||||
}
|
||||
|
||||
if (type_set.size()){
|
||||
int type = *(type_set.begin());
|
||||
return type == SR_CHANNEL_LOGIC;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // pv
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
|
||||
const QString& error() const;
|
||||
|
||||
bool save_start(QString session_file);
|
||||
bool save_start();
|
||||
|
||||
bool export_start();
|
||||
|
||||
@@ -79,10 +79,16 @@ private:
|
||||
QString decoders_gen();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
QJsonArray json_decoders();
|
||||
void load_decoders(dock::ProtocolDock *widget, QJsonArray dec_array);
|
||||
QString MakeSaveFile(bool bDlg);
|
||||
QString MakeExportFile(bool bDlg);
|
||||
|
||||
inline QString GetFileName()
|
||||
{ return _file_name;}
|
||||
|
||||
bool IsLogicDataType();
|
||||
|
||||
|
||||
private:
|
||||
@@ -92,22 +98,24 @@ private:
|
||||
signals:
|
||||
void progress_updated();
|
||||
|
||||
private:
|
||||
QString _file_name;
|
||||
QString _suffix;
|
||||
SigSession &_session;
|
||||
public:
|
||||
QString _sessionFile;
|
||||
|
||||
boost::thread _thread;
|
||||
private:
|
||||
QString _file_name;
|
||||
QString _suffix;
|
||||
SigSession &_session;
|
||||
|
||||
boost::thread _thread;
|
||||
|
||||
const struct sr_output_module* _outModule;
|
||||
|
||||
//mutable boost::mutex _mutex;
|
||||
uint64_t _units_stored;
|
||||
uint64_t _unit_count;
|
||||
bool _has_error;
|
||||
QString _error;
|
||||
bool _canceled;
|
||||
ZipMaker m_zipDoc;
|
||||
|
||||
uint64_t _units_stored;
|
||||
uint64_t _unit_count;
|
||||
bool _has_error;
|
||||
QString _error;
|
||||
bool _canceled;
|
||||
ZipMaker m_zipDoc;
|
||||
};
|
||||
|
||||
} // pv
|
||||
|
||||
@@ -176,6 +176,7 @@ enum {
|
||||
#define SR_PRIV
|
||||
#endif
|
||||
|
||||
|
||||
/** Data types used by sr_config_info(). */
|
||||
enum {
|
||||
SR_T_UINT64 = 10000,
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "config.h" /* Needed for PACKAGE_STRING and others. */
|
||||
|
||||
#define LOG_PREFIX "output/csv"
|
||||
|
||||
|
||||
struct context {
|
||||
unsigned int num_enabled_channels;
|
||||
@@ -234,10 +235,16 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
||||
*out = g_string_sized_new(512);
|
||||
}
|
||||
|
||||
int bflag = sr_get_export_original_flag();
|
||||
|
||||
for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) {
|
||||
ctx->index++;
|
||||
if (ctx->index > 1 && (*(uint64_t *)(logic->data + i) & ctx->mask) == ctx->pre_data)
|
||||
continue;
|
||||
|
||||
if (bflag == 0){
|
||||
if (ctx->index > 1 && (*(uint64_t *)(logic->data + i) & ctx->mask) == ctx->pre_data)
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_printf(*out, "%0.10g", (ctx->index-1)*1.0/ctx->samplerate);
|
||||
for (j = 0; j < ctx->num_enabled_channels; j++) {
|
||||
//idx = ctx->channel_index[j];
|
||||
@@ -331,3 +338,4 @@ SR_PRIV struct sr_output_module output_csv = {
|
||||
.receive = receive,
|
||||
.cleanup = cleanup,
|
||||
};
|
||||
|
||||
|
||||
@@ -179,4 +179,12 @@ SR_PRIV uint16_t ds_trigger_get_edge0(uint16_t stage, uint16_t msc, uint16_t lsc
|
||||
SR_PRIV uint16_t ds_trigger_get_mask1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
|
||||
SR_PRIV uint16_t ds_trigger_get_value1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
|
||||
SR_PRIV uint16_t ds_trigger_get_edge1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
|
||||
|
||||
/*--------------------session.c----------------*/
|
||||
|
||||
SR_API void sr_set_export_original_data(int flag);
|
||||
|
||||
SR_API int sr_get_export_original_flag();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
|
||||
#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
|
||||
|
||||
int bExportOriginalData = 0; //able export all data
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
@@ -813,4 +815,14 @@ SR_API int sr_session_source_remove_channel(GIOChannel *channel)
|
||||
return _sr_session_source_remove((gintptr)channel);
|
||||
}
|
||||
|
||||
SR_API void sr_set_export_original_data(int flag)
|
||||
{
|
||||
bExportOriginalData = flag;
|
||||
}
|
||||
|
||||
SR_API int sr_get_export_original_flag()
|
||||
{
|
||||
return bExportOriginalData;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
Reference in New Issue
Block a user