2 * This file is part of the PulseView project.
4 * Copyright (C) 2012-2015 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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/>.
27 #include <QFileDialog>
30 #include <QMessageBox>
34 #include "mainbar.hpp"
36 #include <boost/algorithm/string/join.hpp>
38 #include <pv/devicemanager.hpp>
39 #include <pv/devices/hardwaredevice.hpp>
40 #include <pv/devices/inputfile.hpp>
41 #include <pv/devices/sessionfile.hpp>
42 #include <pv/dialogs/connect.hpp>
43 #include <pv/dialogs/inputoutputoptions.hpp>
44 #include <pv/dialogs/storeprogress.hpp>
45 #include <pv/mainwindow.hpp>
46 #include <pv/popups/channels.hpp>
47 #include <pv/popups/deviceoptions.hpp>
48 #include <pv/util.hpp>
49 #include <pv/views/trace/view.hpp>
50 #include <pv/widgets/exportmenu.hpp>
51 #include <pv/widgets/importmenu.hpp>
53 #include <pv/widgets/decodermenu.hpp>
54 #include <pv/data/decodesignal.hpp>
57 #include <libsigrokcxx/libsigrokcxx.hpp>
59 using std::back_inserter;
68 using std::shared_ptr;
72 using sigrok::Capability;
73 using sigrok::ConfigKey;
75 using sigrok::InputFormat;
76 using sigrok::OutputFormat;
78 using boost::algorithm::join;
83 const uint64_t MainBar::MinSampleCount = 100ULL;
84 const uint64_t MainBar::MaxSampleCount = 1000000000000ULL;
85 const uint64_t MainBar::DefaultSampleCount = 1000000;
87 const char *MainBar::SettingOpenDirectory = "MainWindow/OpenDirectory";
88 const char *MainBar::SettingSaveDirectory = "MainWindow/SaveDirectory";
90 MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view) :
91 StandardBar(session, parent, view, false),
92 action_new_view_(new QAction(this)),
93 action_open_(new QAction(this)),
94 action_save_as_(new QAction(this)),
95 action_save_selection_as_(new QAction(this)),
96 action_restore_setup_(new QAction(this)),
97 action_save_setup_(new QAction(this)),
98 action_connect_(new QAction(this)),
99 open_button_(new QToolButton()),
100 save_button_(new QToolButton()),
101 device_selector_(parent, session.device_manager(), action_connect_),
102 configure_button_(this),
103 configure_button_action_(nullptr),
104 channels_button_(this),
105 channels_button_action_(nullptr),
106 sample_count_(" samples", this),
107 sample_rate_("Hz", this),
108 updating_sample_rate_(false),
109 updating_sample_count_(false),
110 sample_count_supported_(false)
112 , add_decoder_button_(new QToolButton()),
113 menu_decoders_add_(new pv::widgets::DecoderMenu(this, true))
116 setObjectName(QString::fromUtf8("MainBar"));
118 setContextMenuPolicy(Qt::PreventContextMenu);
121 action_new_view_->setText(tr("New &View"));
122 action_new_view_->setIcon(QIcon::fromTheme("window-new",
123 QIcon(":/icons/window-new.png")));
124 connect(action_new_view_, SIGNAL(triggered(bool)),
125 this, SLOT(on_actionNewView_triggered()));
127 action_open_->setText(tr("&Open..."));
128 action_open_->setIcon(QIcon::fromTheme("document-open",
129 QIcon(":/icons/document-open.png")));
130 action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
131 connect(action_open_, SIGNAL(triggered(bool)),
132 this, SLOT(on_actionOpen_triggered()));
134 action_restore_setup_->setText(tr("Restore Session Setu&p..."));
135 connect(action_restore_setup_, SIGNAL(triggered(bool)),
136 this, SLOT(on_actionRestoreSetup_triggered()));
138 action_save_as_->setText(tr("&Save As..."));
139 action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
140 QIcon(":/icons/document-save-as.png")));
141 action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
142 connect(action_save_as_, SIGNAL(triggered(bool)),
143 this, SLOT(on_actionSaveAs_triggered()));
145 action_save_selection_as_->setText(tr("Save Selected &Range As..."));
146 action_save_selection_as_->setIcon(QIcon::fromTheme("document-save-as",
147 QIcon(":/icons/document-save-as.png")));
148 action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
149 connect(action_save_selection_as_, SIGNAL(triggered(bool)),
150 this, SLOT(on_actionSaveSelectionAs_triggered()));
152 action_save_setup_->setText(tr("Save Session Setu&p..."));
153 connect(action_save_setup_, SIGNAL(triggered(bool)),
154 this, SLOT(on_actionSaveSetup_triggered()));
156 widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
157 session.device_manager().context());
158 menu_file_export->setTitle(tr("&Export"));
159 connect(menu_file_export, SIGNAL(format_selected(shared_ptr<sigrok::OutputFormat>)),
160 this, SLOT(export_file(shared_ptr<sigrok::OutputFormat>)));
162 widgets::ImportMenu *menu_file_import = new widgets::ImportMenu(this,
163 session.device_manager().context());
164 menu_file_import->setTitle(tr("&Import"));
165 connect(menu_file_import, SIGNAL(format_selected(shared_ptr<sigrok::InputFormat>)),
166 this, SLOT(import_file(shared_ptr<sigrok::InputFormat>)));
168 action_connect_->setText(tr("&Connect to Device..."));
169 connect(action_connect_, SIGNAL(triggered(bool)),
170 this, SLOT(on_actionConnect_triggered()));
173 vector<QAction*> open_actions;
174 open_actions.push_back(action_open_);
175 QAction* separator_o = new QAction(this);
176 separator_o->setSeparator(true);
177 open_actions.push_back(separator_o);
178 open_actions.push_back(action_restore_setup_);
180 widgets::ImportMenu *import_menu = new widgets::ImportMenu(this,
181 session.device_manager().context(), open_actions);
182 connect(import_menu, SIGNAL(format_selected(shared_ptr<sigrok::InputFormat>)),
183 this, SLOT(import_file(shared_ptr<sigrok::InputFormat>)));
185 open_button_->setMenu(import_menu);
186 open_button_->setDefaultAction(action_open_);
187 open_button_->setPopupMode(QToolButton::MenuButtonPopup);
190 vector<QAction*> save_actions;
191 save_actions.push_back(action_save_as_);
192 save_actions.push_back(action_save_selection_as_);
193 QAction* separator_s = new QAction(this);
194 separator_s->setSeparator(true);
195 save_actions.push_back(separator_s);
196 save_actions.push_back(action_save_setup_);
198 widgets::ExportMenu *export_menu = new widgets::ExportMenu(this,
199 session.device_manager().context(), save_actions);
200 connect(export_menu, SIGNAL(format_selected(shared_ptr<sigrok::OutputFormat>)),
201 this, SLOT(export_file(shared_ptr<sigrok::OutputFormat>)));
203 save_button_->setMenu(export_menu);
204 save_button_->setDefaultAction(action_save_as_);
205 save_button_->setPopupMode(QToolButton::MenuButtonPopup);
207 // Device selector menu
208 connect(&device_selector_, SIGNAL(device_selected()),
209 this, SLOT(on_device_selected()));
211 // Setup the decoder button
213 menu_decoders_add_->setTitle(tr("&Add"));
214 connect(menu_decoders_add_, SIGNAL(decoder_selected(srd_decoder*)),
215 this, SLOT(add_decoder(srd_decoder*)));
217 add_decoder_button_->setIcon(QIcon(":/icons/add-decoder.svg"));
218 add_decoder_button_->setPopupMode(QToolButton::InstantPopup);
219 add_decoder_button_->setMenu(menu_decoders_add_);
220 add_decoder_button_->setToolTip(tr("Add low-level, non-stacked protocol decoder"));
223 connect(&sample_count_, SIGNAL(value_changed()),
224 this, SLOT(on_sample_count_changed()));
225 connect(&sample_rate_, SIGNAL(value_changed()),
226 this, SLOT(on_sample_rate_changed()));
228 sample_count_.show_min_max_step(0, UINT64_MAX, 1);
230 set_capture_state(pv::Session::Stopped);
232 configure_button_.setToolTip(tr("Configure Device"));
233 configure_button_.setIcon(QIcon::fromTheme("preferences-system",
234 QIcon(":/icons/preferences-system.png")));
236 channels_button_.setToolTip(tr("Configure Channels"));
237 channels_button_.setIcon(QIcon(":/icons/channels.svg"));
239 add_toolbar_widgets();
241 sample_count_.installEventFilter(this);
242 sample_rate_.installEventFilter(this);
244 // Setup session_ events
245 connect(&session_, SIGNAL(capture_state_changed(int)),
246 this, SLOT(on_capture_state_changed(int)));
247 connect(&session, SIGNAL(device_changed()),
248 this, SLOT(on_device_changed()));
250 update_device_list();
253 void MainBar::update_device_list()
255 DeviceManager &mgr = session_.device_manager();
256 shared_ptr<devices::Device> selected_device = session_.device();
257 list< shared_ptr<devices::Device> > devs;
259 copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs));
261 if (std::find(devs.begin(), devs.end(), selected_device) == devs.end())
262 devs.push_back(selected_device);
264 device_selector_.set_device_list(devs, selected_device);
265 update_device_config_widgets();
268 void MainBar::set_capture_state(pv::Session::capture_state state)
270 bool ui_enabled = (state == pv::Session::Stopped) ? true : false;
272 device_selector_.setEnabled(ui_enabled);
273 configure_button_.setEnabled(ui_enabled);
274 channels_button_.setEnabled(ui_enabled);
275 sample_count_.setEnabled(ui_enabled);
276 sample_rate_.setEnabled(ui_enabled);
279 void MainBar::reset_device_selector()
281 device_selector_.reset();
284 QAction* MainBar::action_open() const
289 QAction* MainBar::action_save_as() const
291 return action_save_as_;
294 QAction* MainBar::action_save_selection_as() const
296 return action_save_selection_as_;
299 QAction* MainBar::action_connect() const
301 return action_connect_;
304 void MainBar::update_sample_rate_selector()
306 Glib::VariantContainerBase gvar_dict;
308 const uint64_t *elements = nullptr;
310 map< const ConfigKey*, set<Capability> > keys;
312 if (updating_sample_rate_) {
313 sample_rate_.show_none();
317 const shared_ptr<devices::Device> device = device_selector_.selected_device();
321 assert(!updating_sample_rate_);
322 updating_sample_rate_ = true;
324 const shared_ptr<sigrok::Device> sr_dev = device->device();
326 sample_rate_.allow_user_entered_values(false);
327 if (sr_dev->config_check(ConfigKey::EXTERNAL_CLOCK, Capability::GET)) {
329 auto gvar = sr_dev->config_get(ConfigKey::EXTERNAL_CLOCK);
331 bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
333 sample_rate_.allow_user_entered_values(value);
335 } catch (Error& error) {
341 if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
343 gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
344 } catch (Error& error) {
345 qDebug() << tr("Failed to get sample rate list:") << error.what();
348 sample_rate_.show_none();
349 updating_sample_rate_ = false;
353 if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
354 "samplerate-steps", G_VARIANT_TYPE("at")))) {
355 elements = (const uint64_t *)g_variant_get_fixed_array(
356 gvar_list, &num_elements, sizeof(uint64_t));
358 const uint64_t min = elements[0];
359 const uint64_t max = elements[1];
360 const uint64_t step = elements[2];
362 g_variant_unref(gvar_list);
370 sample_rate_.show_125_list(min, max);
372 // When the step is not 1, we cam't make a 1-2-5-10
373 // list of sample rates, because we may not be able to
374 // make round numbers. Therefore in this case, show a
376 sample_rate_.show_min_max_step(min, max, step);
378 } else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
379 "samplerates", G_VARIANT_TYPE("at")))) {
380 elements = (const uint64_t *)g_variant_get_fixed_array(
381 gvar_list, &num_elements, sizeof(uint64_t));
382 sample_rate_.show_list(elements, num_elements);
383 g_variant_unref(gvar_list);
385 updating_sample_rate_ = false;
387 update_sample_rate_selector_value();
390 void MainBar::update_sample_rate_selector_value()
392 if (updating_sample_rate_)
395 const shared_ptr<devices::Device> device = device_selector_.selected_device();
400 auto gvar = device->device()->config_get(ConfigKey::SAMPLERATE);
401 uint64_t samplerate =
402 Glib::VariantBase::cast_dynamic<Glib::Variant<guint64>>(gvar).get();
403 assert(!updating_sample_rate_);
404 updating_sample_rate_ = true;
405 sample_rate_.set_value(samplerate);
406 updating_sample_rate_ = false;
407 } catch (Error& error) {
408 qDebug() << tr("Failed to get sample rate:") << error.what();
412 void MainBar::update_sample_count_selector()
414 if (updating_sample_count_)
417 const shared_ptr<devices::Device> device = device_selector_.selected_device();
421 const shared_ptr<sigrok::Device> sr_dev = device->device();
423 assert(!updating_sample_count_);
424 updating_sample_count_ = true;
426 if (!sample_count_supported_) {
427 sample_count_.show_none();
428 updating_sample_count_ = false;
432 uint64_t sample_count = sample_count_.value();
433 uint64_t min_sample_count = 0;
434 uint64_t max_sample_count = MaxSampleCount;
435 bool default_count_set = false;
437 if (sample_count == 0) {
438 sample_count = DefaultSampleCount;
439 default_count_set = true;
442 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::LIST)) {
444 auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
446 g_variant_get(gvar.gobj(), "(tt)",
447 &min_sample_count, &max_sample_count);
448 } catch (Error& error) {
449 qDebug() << tr("Failed to get sample limit list:") << error.what();
453 min_sample_count = min(max(min_sample_count, MinSampleCount),
456 sample_count_.show_125_list(min_sample_count, max_sample_count);
458 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::GET)) {
459 auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES);
460 sample_count = g_variant_get_uint64(gvar.gobj());
461 if (sample_count == 0) {
462 sample_count = DefaultSampleCount;
463 default_count_set = true;
465 sample_count = min(max(sample_count, MinSampleCount),
469 sample_count_.set_value(sample_count);
471 updating_sample_count_ = false;
473 // If we show the default rate then make sure the device uses the same
474 if (default_count_set)
475 commit_sample_count();
478 void MainBar::update_device_config_widgets()
480 using namespace pv::popups;
482 const shared_ptr<devices::Device> device = device_selector_.selected_device();
484 // Hide the widgets if no device is selected
485 channels_button_action_->setVisible(!!device);
487 configure_button_action_->setVisible(false);
488 sample_count_.show_none();
489 sample_rate_.show_none();
493 const shared_ptr<sigrok::Device> sr_dev = device->device();
497 // Update the configure popup
498 DeviceOptions *const opts = new DeviceOptions(sr_dev, this);
499 configure_button_action_->setVisible(!opts->binding().properties().empty());
500 configure_button_.set_popup(opts);
502 // Update the channels popup
503 Channels *const channels = new Channels(session_, this);
504 channels_button_.set_popup(channels);
506 // Update supported options.
507 sample_count_supported_ = false;
509 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::SET))
510 sample_count_supported_ = true;
512 // Add notification of reconfigure events
513 disconnect(this, SLOT(on_config_changed()));
514 connect(&opts->binding(), SIGNAL(config_changed()),
515 this, SLOT(on_config_changed()));
517 // Update sweep timing widgets.
518 update_sample_count_selector();
519 update_sample_rate_selector();
522 void MainBar::commit_sample_rate()
524 uint64_t sample_rate = 0;
526 const shared_ptr<devices::Device> device = device_selector_.selected_device();
530 const shared_ptr<sigrok::Device> sr_dev = device->device();
532 sample_rate = sample_rate_.value();
535 sr_dev->config_set(ConfigKey::SAMPLERATE,
536 Glib::Variant<guint64>::create(sample_rate));
537 update_sample_rate_selector();
538 } catch (Error& error) {
539 qDebug() << tr("Failed to configure samplerate:") << error.what();
543 // Devices with built-in memory might impose limits on certain
544 // configurations, so let's check what sample count the driver
546 update_sample_count_selector();
549 void MainBar::commit_sample_count()
551 uint64_t sample_count = 0;
553 const shared_ptr<devices::Device> device = device_selector_.selected_device();
557 const shared_ptr<sigrok::Device> sr_dev = device->device();
559 sample_count = sample_count_.value();
560 if (sample_count_supported_) {
562 sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
563 Glib::Variant<guint64>::create(sample_count));
564 update_sample_count_selector();
565 } catch (Error& error) {
566 qDebug() << tr("Failed to configure sample count:") << error.what();
571 // Devices with built-in memory might impose limits on certain
572 // configurations, so let's check what sample rate the driver
574 update_sample_rate_selector();
577 void MainBar::show_session_error(const QString text, const QString info_text)
579 QMessageBox msg(this);
580 msg.setText(text + "\n\n" + info_text);
581 msg.setStandardButtons(QMessageBox::Ok);
582 msg.setIcon(QMessageBox::Warning);
586 void MainBar::add_decoder(srd_decoder *decoder)
590 shared_ptr<data::DecodeSignal> signal = session_.add_decode_signal();
592 signal->stack_decoder(decoder);
598 void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
600 using pv::dialogs::StoreProgress;
602 // Stop any currently running capture session
603 session_.stop_capture();
606 const QString dir = settings.value(SettingSaveDirectory).toString();
608 pair<uint64_t, uint64_t> sample_range;
610 // Selection only? Verify that the cursors are active and fetch their values
611 if (selection_only) {
612 views::trace::View *trace_view =
613 qobject_cast<views::trace::View*>(session_.main_view().get());
615 if (!trace_view->cursors()->enabled()) {
616 show_session_error(tr("Missing Cursors"), tr("You need to set the " \
617 "cursors before you can save the data enclosed by them " \
618 "to a session file (e.g. using the Show Cursors button)."));
622 const double samplerate = session_.get_samplerate();
624 const pv::util::Timestamp& start_time = trace_view->cursors()->first()->time();
625 const pv::util::Timestamp& end_time = trace_view->cursors()->second()->time();
627 const uint64_t start_sample = (uint64_t)max(
628 0.0, start_time.convert_to<double>() * samplerate);
629 const uint64_t end_sample = (uint64_t)max(
630 0.0, end_time.convert_to<double>() * samplerate);
632 if ((start_sample == 0) && (end_sample == 0)) {
633 // Both cursors are negative and were clamped to 0
634 show_session_error(tr("Invalid Range"), tr("The cursors don't " \
635 "define a valid range of samples."));
639 sample_range = make_pair(start_sample, end_sample);
641 sample_range = make_pair(0, 0);
644 // Construct the filter
645 const vector<string> exts = format->extensions();
646 QString filter = tr("%1 files ").arg(
647 QString::fromStdString(format->description()));
652 filter += QString("(*.%1);;%2 (*)").arg(
653 QString::fromStdString(join(exts, ", *.")),
656 // Show the file dialog
657 const QString file_name = QFileDialog::getSaveFileName(
658 this, tr("Save File"), dir, filter);
660 if (file_name.isEmpty())
663 const QString abs_path = QFileInfo(file_name).absolutePath();
664 settings.setValue(SettingSaveDirectory, abs_path);
666 // Show the options dialog
667 map<string, Glib::VariantBase> options;
668 if (!format->options().empty()) {
669 dialogs::InputOutputOptions dlg(
670 tr("Export %1").arg(QString::fromStdString(
671 format->description())),
672 format->options(), this);
675 options = dlg.options();
679 session_.set_name(QFileInfo(file_name).fileName());
681 StoreProgress *dlg = new StoreProgress(file_name, format, options,
682 sample_range, session_, this);
686 void MainBar::import_file(shared_ptr<InputFormat> format)
691 const QString dir = settings.value(SettingOpenDirectory).toString();
693 // Construct the filter
694 const vector<string> exts = format->extensions();
695 const QString filter_exts = exts.empty() ? "" : QString::fromStdString("%1 (%2)").arg(
696 tr("%1 files").arg(QString::fromStdString(format->description())),
697 QString::fromStdString("*.%1").arg(QString::fromStdString(join(exts, " *."))));
698 const QString filter_all = QString::fromStdString("%1 (%2)").arg(
699 tr("All Files"), QString::fromStdString("*"));
700 const QString filter = QString::fromStdString("%1%2%3").arg(
701 exts.empty() ? "" : filter_exts,
702 exts.empty() ? "" : ";;",
705 // Show the file dialog
706 const QString file_name = QFileDialog::getOpenFileName(
707 this, tr("Import File"), dir, filter);
709 if (file_name.isEmpty())
712 // Show the options dialog
713 map<string, Glib::VariantBase> options;
714 if (!format->options().empty()) {
715 dialogs::InputOutputOptions dlg(
716 tr("Import %1").arg(QString::fromStdString(
717 format->description())),
718 format->options(), this);
721 options = dlg.options();
724 session_.load_file(file_name, format, options);
726 const QString abs_path = QFileInfo(file_name).absolutePath();
727 settings.setValue(SettingOpenDirectory, abs_path);
730 void MainBar::on_device_selected()
732 shared_ptr<devices::Device> device = device_selector_.selected_device();
735 session_.select_device(device);
737 reset_device_selector();
740 void MainBar::on_device_changed()
742 update_device_list();
743 update_device_config_widgets();
746 void MainBar::on_capture_state_changed(int state)
748 set_capture_state((pv::Session::capture_state)state);
751 void MainBar::on_sample_count_changed()
753 if (!updating_sample_count_)
754 commit_sample_count();
757 void MainBar::on_sample_rate_changed()
759 if (!updating_sample_rate_)
760 commit_sample_rate();
763 void MainBar::on_config_changed()
765 // We want to also call update_sample_rate_selector() here in case
766 // the user changed the SR_CONF_EXTERNAL_CLOCK option. However,
767 // commit_sample_rate() does this already, so we don't call it here
769 commit_sample_count();
770 commit_sample_rate();
773 void MainBar::on_actionNewView_triggered()
778 void MainBar::on_actionOpen_triggered()
781 const QString dir = settings.value(SettingOpenDirectory).toString();
784 const QString file_name = QFileDialog::getOpenFileName(
785 this, tr("Open File"), dir, tr(
786 "sigrok Sessions (*.sr);;"
789 if (!file_name.isEmpty()) {
790 session_.load_file(file_name);
792 const QString abs_path = QFileInfo(file_name).absolutePath();
793 settings.setValue(SettingOpenDirectory, abs_path);
797 void MainBar::on_actionSaveAs_triggered()
799 export_file(session_.device_manager().context()->output_formats()["srzip"]);
802 void MainBar::on_actionSaveSelectionAs_triggered()
804 export_file(session_.device_manager().context()->output_formats()["srzip"], true);
807 void MainBar::on_actionSaveSetup_triggered()
810 const QString dir = settings.value(SettingSaveDirectory).toString();
812 const QString file_name = QFileDialog::getSaveFileName(
813 this, tr("Save File"), dir, tr(
814 "PulseView Session Setups (*.pvs);;"
817 if (file_name.isEmpty())
820 QSettings settings_storage(file_name, QSettings::IniFormat);
821 session_.save_setup(settings_storage);
824 void MainBar::on_actionRestoreSetup_triggered()
827 const QString dir = settings.value(SettingSaveDirectory).toString();
829 const QString file_name = QFileDialog::getOpenFileName(
830 this, tr("Open File"), dir, tr(
831 "PulseView Session Setups (*.pvs);;"
834 if (file_name.isEmpty())
837 QSettings settings_storage(file_name, QSettings::IniFormat);
838 session_.restore_setup(settings_storage);
841 void MainBar::on_actionConnect_triggered()
843 // Stop any currently running capture session
844 session_.stop_capture();
846 dialogs::Connect dlg(this, session_.device_manager());
848 // If the user selected a device, select it in the device list. Select the
849 // current device otherwise.
851 session_.select_device(dlg.get_selected_device());
853 update_device_list();
856 void MainBar::add_toolbar_widgets()
858 addAction(action_new_view_);
860 addWidget(open_button_);
861 addWidget(save_button_);
864 StandardBar::add_toolbar_widgets();
866 addWidget(&device_selector_);
867 configure_button_action_ = addWidget(&configure_button_);
868 channels_button_action_ = addWidget(&channels_button_);
869 addWidget(&sample_count_);
870 addWidget(&sample_rate_);
873 addWidget(add_decoder_button_);
877 bool MainBar::eventFilter(QObject *watched, QEvent *event)
879 if (sample_count_supported_ && (watched == &sample_count_ ||
880 watched == &sample_rate_) &&
881 (event->type() == QEvent::ToolTip)) {
883 auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value();
884 QHelpEvent *help_event = static_cast<QHelpEvent*>(event);
886 QString str = tr("Total sampling time: %1").arg(
887 pv::util::format_time_si(sec, pv::util::SIPrefix::unspecified, 0, "s", false));
888 QToolTip::showText(help_event->globalPos(), str);
896 } // namespace toolbars