From dd3fd4df34d129c83f7f5d80ff1e8b998beca63d Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 28 Mar 2015 13:25:41 +0000 Subject: [PATCH 1/1] MainWindow: Added format parameters to load_file --- pv/devices/inputfile.cpp | 2 +- pv/devices/inputfile.hpp | 5 ++--- pv/mainwindow.cpp | 21 ++++++++++++++++----- pv/mainwindow.hpp | 9 ++++++++- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/pv/devices/inputfile.cpp b/pv/devices/inputfile.cpp index 41187747..e92bf208 100644 --- a/pv/devices/inputfile.cpp +++ b/pv/devices/inputfile.cpp @@ -34,9 +34,9 @@ InputFile::InputFile(const std::shared_ptr &context, const std::string &file_name, std::shared_ptr format, const std::map &options) : + File(file_name), context_(context), input_(format->create_input(options)), - file_name_(file_name), interrupt_(false) { if (!input_) throw QString("Failed to create input"); diff --git a/pv/devices/inputfile.hpp b/pv/devices/inputfile.hpp index 55688fd4..588ccdf2 100644 --- a/pv/devices/inputfile.hpp +++ b/pv/devices/inputfile.hpp @@ -25,12 +25,12 @@ #include -#include "device.hpp" +#include "file.hpp" namespace pv { namespace devices { -class InputFile final : public Device +class InputFile final : public File { private: static const std::streamsize BufferSize; @@ -52,7 +52,6 @@ public: private: const std::shared_ptr context_; const std::shared_ptr input_; - const std::string file_name_; std::atomic interrupt_; }; diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index ac5372a6..a339b19a 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -46,6 +46,7 @@ #include "devicemanager.hpp" #include "devices/hardwaredevice.hpp" +#include "devices/inputfile.hpp" #include "devices/sessionfile.hpp" #include "dialogs/about.hpp" #include "dialogs/connect.hpp" @@ -76,6 +77,7 @@ using boost::algorithm::join; using sigrok::Error; using sigrok::OutputFormat; +using sigrok::InputFormat; namespace pv { @@ -525,17 +527,26 @@ void MainWindow::keyReleaseEvent(QKeyEvent *event) QMainWindow::keyReleaseEvent(event); } -void MainWindow::load_file(QString file_name) +void MainWindow::load_file(QString file_name, + std::shared_ptr format, + const std::map &options) { const QString errorMessage( QString("Failed to load file %1").arg(file_name)); const QString infoMessage; try { - session_.set_device( - shared_ptr(new devices::SessionFile( - device_manager_.context(), - file_name.toStdString()))); + if (format) + session_.set_device(shared_ptr( + new devices::InputFile( + device_manager_.context(), + file_name.toStdString(), + format, options))); + else + session_.set_device(shared_ptr( + new devices::SessionFile( + device_manager_.context(), + file_name.toStdString()))); } catch(Error e) { show_session_error(tr("Failed to load ") + file_name, e.what()); session_.set_default_device(); diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 1779712f..35ccf065 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -22,8 +22,11 @@ #define PULSEVIEW_PV_MAINWINDOW_HPP #include +#include #include +#include + #include #include "session.hpp" @@ -33,6 +36,7 @@ struct srd_decoder; class QVBoxLayout; namespace sigrok { +class InputFormat; class OutputFormat; } @@ -119,7 +123,10 @@ private: void keyReleaseEvent(QKeyEvent *event); private Q_SLOTS: - void load_file(QString file_name); + void load_file(QString file_name, + std::shared_ptr format = nullptr, + const std::map &options = + std::map()); void show_session_error( const QString text, const QString info_text); -- 2.30.2