From: Joel Holdsworth Date: Mon, 3 Dec 2012 23:25:59 +0000 (+0000) Subject: Keep Run/Stop button state updated X-Git-Tag: pulseview-0.1.0~203 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6ac96c2e0ef986da9c9ebea50906cb717aa382ba;p=pulseview.git Keep Run/Stop button state updated --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index f1493667..3f338a12 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -150,6 +150,11 @@ void MainWindow::setup_ui() _menu_file->setTitle(QApplication::translate("MainWindow", "&File", 0, QApplication::UnicodeUTF8)); _menu_view->setTitle(QApplication::translate("MainWindow", "&View", 0, QApplication::UnicodeUTF8)); _menu_help->setTitle(QApplication::translate("MainWindow", "&Help", 0, QApplication::UnicodeUTF8)); + + // Setup _session events + connect(&_session, SIGNAL(capture_state_changed(int)), this, + SLOT(capture_state_changed(int))); + } void MainWindow::on_actionOpen_triggered() @@ -198,4 +203,9 @@ void MainWindow::run_stop() } } +void MainWindow::capture_state_changed(int state) +{ + _sampling_bar->set_sampling(state != SigSession::Stopped); +} + } // namespace pv diff --git a/pv/mainwindow.h b/pv/mainwindow.h index df7d86f5..07a54a0f 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -87,6 +87,8 @@ private slots: void on_actionAbout_triggered(); void run_stop(); + + void capture_state_changed(int state); }; } // namespace pv diff --git a/pv/samplingbar.cpp b/pv/samplingbar.cpp index 31047439..02e4e71d 100644 --- a/pv/samplingbar.cpp +++ b/pv/samplingbar.cpp @@ -68,7 +68,7 @@ SamplingBar::SamplingBar(QWidget *parent) : g_free(text); } - _run_stop_button.setText("Run"); + set_sampling(false); addWidget(&_device_selector); addWidget(&_record_length_selector); @@ -118,6 +118,11 @@ uint64_t SamplingBar::get_sample_rate() const return 0; } +void SamplingBar::set_sampling(bool sampling) +{ + _run_stop_button.setText(sampling ? "Stop" : "Run"); +} + void SamplingBar::update_device_selector() { GSList *devices = NULL; diff --git a/pv/samplingbar.h b/pv/samplingbar.h index e6204dfa..8c6511a8 100644 --- a/pv/samplingbar.h +++ b/pv/samplingbar.h @@ -46,6 +46,8 @@ public: uint64_t get_record_length() const; uint64_t get_sample_rate() const; + void set_sampling(bool sampling); + signals: void run_stop(); diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 580b6796..e4a58a61 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -94,8 +94,6 @@ void SigSession::stop_capture() if(_sampling_thread.get()) _sampling_thread->join(); _sampling_thread.reset(); - - _capture_state = Stopped; } vector< shared_ptr > SigSession::get_signals() @@ -109,6 +107,13 @@ boost::shared_ptr SigSession::get_data() return _logic_data; } +void SigSession::set_capture_state(capture_state state) +{ + lock_guard lock(_state_mutex); + _capture_state = state; + capture_state_changed(state); +} + void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, uint64_t record_length, uint64_t sample_rate) { @@ -140,13 +145,12 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, return; } - { - lock_guard lock(_state_mutex); - _capture_state = Running; - } + set_capture_state(Running); sr_session_run(); sr_session_destroy(); + + set_capture_state(Stopped); } void SigSession::data_feed_in(const struct sr_dev_inst *sdi, diff --git a/pv/sigsession.h b/pv/sigsession.h index 8da89d09..b4f07db4 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -72,6 +72,9 @@ public: boost::shared_ptr get_data(); +private: + void set_capture_state(capture_state state); + private: void sample_thread_proc(struct sr_dev_inst *sdi, uint64_t record_length, uint64_t sample_rate); @@ -96,6 +99,8 @@ private: std::auto_ptr _sampling_thread; signals: + void capture_state_changed(int state); + void signals_changed(); void data_updated();