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/data/decodesignal.hpp>
56 #include <libsigrokcxx/libsigrokcxx.hpp>
58 using std::back_inserter;
67 using std::shared_ptr;
71 using sigrok::Capability;
72 using sigrok::ConfigKey;
74 using sigrok::InputFormat;
75 using sigrok::OutputFormat;
77 using boost::algorithm::join;
82 const uint64_t MainBar::MinSampleCount = 100ULL;
83 const uint64_t MainBar::MaxSampleCount = 1000000000000ULL;
84 const uint64_t MainBar::DefaultSampleCount = 1000000;
86 const char *MainBar::SettingOpenDirectory = "MainWindow/OpenDirectory";
87 const char *MainBar::SettingSaveDirectory = "MainWindow/SaveDirectory";
89 MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view) :
90 StandardBar(session, parent, view, false),
91 action_new_view_(new QAction(this)),
92 action_open_(new QAction(this)),
93 action_save_as_(new QAction(this)),
94 action_save_selection_as_(new QAction(this)),
95 action_restore_setup_(new QAction(this)),
96 action_save_setup_(new QAction(this)),
97 action_connect_(new QAction(this)),
98 new_view_button_(new QToolButton()),
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())
115 setObjectName(QString::fromUtf8("MainBar"));
117 setContextMenuPolicy(Qt::PreventContextMenu);
120 action_new_view_->setText(tr("New &View"));
121 action_new_view_->setIcon(QIcon::fromTheme("window-new",
122 QIcon(":/icons/window-new.png")));
123 connect(action_new_view_, SIGNAL(triggered(bool)),
124 this, SLOT(on_actionNewView_triggered()));
126 action_open_->setText(tr("&Open..."));
127 action_open_->setIcon(QIcon::fromTheme("document-open",
128 QIcon(":/icons/document-open.png")));
129 action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
130 connect(action_open_, SIGNAL(triggered(bool)),
131 this, SLOT(on_actionOpen_triggered()));
133 action_restore_setup_->setText(tr("Restore Session Setu&p..."));
134 connect(action_restore_setup_, SIGNAL(triggered(bool)),
135 this, SLOT(on_actionRestoreSetup_triggered()));
137 action_save_as_->setText(tr("&Save As..."));
138 action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
139 QIcon(":/icons/document-save-as.png")));
140 action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
141 connect(action_save_as_, SIGNAL(triggered(bool)),
142 this, SLOT(on_actionSaveAs_triggered()));
144 action_save_selection_as_->setText(tr("Save Selected &Range As..."));
145 action_save_selection_as_->setIcon(QIcon::fromTheme("document-save-as",
146 QIcon(":/icons/document-save-as.png")));
147 action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
148 connect(action_save_selection_as_, SIGNAL(triggered(bool)),
149 this, SLOT(on_actionSaveSelectionAs_triggered()));
151 action_save_setup_->setText(tr("Save Session Setu&p..."));
152 connect(action_save_setup_, SIGNAL(triggered(bool)),
153 this, SLOT(on_actionSaveSetup_triggered()));
155 widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
156 session.device_manager().context());
157 menu_file_export->setTitle(tr("&Export"));
158 connect(menu_file_export, SIGNAL(format_selected(shared_ptr<sigrok::OutputFormat>)),
159 this, SLOT(export_file(shared_ptr<sigrok::OutputFormat>)));
161 widgets::ImportMenu *menu_file_import = new widgets::ImportMenu(this,
162 session.device_manager().context());
163 menu_file_import->setTitle(tr("&Import"));
164 connect(menu_file_import, SIGNAL(format_selected(shared_ptr<sigrok::InputFormat>)),
165 this, SLOT(import_file(shared_ptr<sigrok::InputFormat>)));
167 action_connect_->setText(tr("&Connect to Device..."));
168 connect(action_connect_, SIGNAL(triggered(bool)),
169 this, SLOT(on_actionConnect_triggered()));
172 QMenu *menu_new_view = new QMenu();
173 connect(menu_new_view, SIGNAL(triggered(QAction*)),
174 this, SLOT(on_actionNewView_triggered(QAction*)));
176 for (int i = 0; i < views::ViewTypeCount; i++) {
177 QAction *const action = menu_new_view->addAction(tr(views::ViewTypeNames[i]));
178 action->setData(qVariantFromValue(i));
181 new_view_button_->setMenu(menu_new_view);
182 new_view_button_->setDefaultAction(action_new_view_);
183 new_view_button_->setPopupMode(QToolButton::MenuButtonPopup);
186 vector<QAction*> open_actions;
187 open_actions.push_back(action_open_);
188 QAction* separator_o = new QAction(this);
189 separator_o->setSeparator(true);
190 open_actions.push_back(separator_o);
191 open_actions.push_back(action_restore_setup_);
193 widgets::ImportMenu *import_menu = new widgets::ImportMenu(this,
194 session.device_manager().context(), open_actions);
195 connect(import_menu, SIGNAL(format_selected(shared_ptr<sigrok::InputFormat>)),
196 this, SLOT(import_file(shared_ptr<sigrok::InputFormat>)));
198 open_button_->setMenu(import_menu);
199 open_button_->setDefaultAction(action_open_);
200 open_button_->setPopupMode(QToolButton::MenuButtonPopup);
203 vector<QAction*> save_actions;
204 save_actions.push_back(action_save_as_);
205 save_actions.push_back(action_save_selection_as_);
206 QAction* separator_s = new QAction(this);
207 separator_s->setSeparator(true);
208 save_actions.push_back(separator_s);
209 save_actions.push_back(action_save_setup_);
211 widgets::ExportMenu *export_menu = new widgets::ExportMenu(this,
212 session.device_manager().context(), save_actions);
213 connect(export_menu, SIGNAL(format_selected(shared_ptr<sigrok::OutputFormat>)),
214 this, SLOT(export_file(shared_ptr<sigrok::OutputFormat>)));
216 save_button_->setMenu(export_menu);
217 save_button_->setDefaultAction(action_save_as_);
218 save_button_->setPopupMode(QToolButton::MenuButtonPopup);
220 // Device selector menu
221 connect(&device_selector_, SIGNAL(device_selected()),
222 this, SLOT(on_device_selected()));
224 // Setup the decoder button
226 add_decoder_button_->setIcon(QIcon(":/icons/add-decoder.svg"));
227 add_decoder_button_->setPopupMode(QToolButton::InstantPopup);
228 add_decoder_button_->setToolTip(tr("Add protocol decoder"));
230 connect(add_decoder_button_, SIGNAL(clicked()),
231 this, SLOT(on_add_decoder_clicked()));
234 connect(&sample_count_, SIGNAL(value_changed()),
235 this, SLOT(on_sample_count_changed()));
236 connect(&sample_rate_, SIGNAL(value_changed()),
237 this, SLOT(on_sample_rate_changed()));
239 sample_count_.show_min_max_step(0, UINT64_MAX, 1);
241 set_capture_state(pv::Session::Stopped);
243 configure_button_.setToolTip(tr("Configure Device"));
244 configure_button_.setIcon(QIcon::fromTheme("preferences-system",
245 QIcon(":/icons/preferences-system.png")));
247 channels_button_.setToolTip(tr("Configure Channels"));
248 channels_button_.setIcon(QIcon(":/icons/channels.svg"));
250 add_toolbar_widgets();
252 sample_count_.installEventFilter(this);
253 sample_rate_.installEventFilter(this);
255 // Setup session_ events
256 connect(&session_, SIGNAL(capture_state_changed(int)),
257 this, SLOT(on_capture_state_changed(int)));
258 connect(&session, SIGNAL(device_changed()),
259 this, SLOT(on_device_changed()));
261 update_device_list();
264 void MainBar::update_device_list()
266 DeviceManager &mgr = session_.device_manager();
267 shared_ptr<devices::Device> selected_device = session_.device();
268 list< shared_ptr<devices::Device> > devs;
270 copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs));
272 if (std::find(devs.begin(), devs.end(), selected_device) == devs.end())
273 devs.push_back(selected_device);
275 device_selector_.set_device_list(devs, selected_device);
276 update_device_config_widgets();
279 void MainBar::set_capture_state(pv::Session::capture_state state)
281 bool ui_enabled = (state == pv::Session::Stopped) ? true : false;
283 device_selector_.setEnabled(ui_enabled);
284 configure_button_.setEnabled(ui_enabled);
285 channels_button_.setEnabled(ui_enabled);
286 sample_count_.setEnabled(ui_enabled);
287 sample_rate_.setEnabled(ui_enabled);
290 void MainBar::reset_device_selector()
292 device_selector_.reset();
295 QAction* MainBar::action_open() const
300 QAction* MainBar::action_save_as() const
302 return action_save_as_;
305 QAction* MainBar::action_save_selection_as() const
307 return action_save_selection_as_;
310 QAction* MainBar::action_connect() const
312 return action_connect_;
315 void MainBar::update_sample_rate_selector()
317 Glib::VariantContainerBase gvar_dict;
319 const uint64_t *elements = nullptr;
321 map< const ConfigKey*, set<Capability> > keys;
323 if (updating_sample_rate_) {
324 sample_rate_.show_none();
328 const shared_ptr<devices::Device> device = device_selector_.selected_device();
332 assert(!updating_sample_rate_);
333 updating_sample_rate_ = true;
335 const shared_ptr<sigrok::Device> sr_dev = device->device();
337 sample_rate_.allow_user_entered_values(false);
338 if (sr_dev->config_check(ConfigKey::EXTERNAL_CLOCK, Capability::GET)) {
340 auto gvar = sr_dev->config_get(ConfigKey::EXTERNAL_CLOCK);
342 bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
344 sample_rate_.allow_user_entered_values(value);
346 } catch (Error& error) {
352 if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
354 gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
355 } catch (Error& error) {
356 qDebug() << tr("Failed to get sample rate list:") << error.what();
359 sample_rate_.show_none();
360 updating_sample_rate_ = false;
364 if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
365 "samplerate-steps", G_VARIANT_TYPE("at")))) {
366 elements = (const uint64_t *)g_variant_get_fixed_array(
367 gvar_list, &num_elements, sizeof(uint64_t));
369 const uint64_t min = elements[0];
370 const uint64_t max = elements[1];
371 const uint64_t step = elements[2];
373 g_variant_unref(gvar_list);
381 sample_rate_.show_125_list(min, max);
383 // When the step is not 1, we cam't make a 1-2-5-10
384 // list of sample rates, because we may not be able to
385 // make round numbers. Therefore in this case, show a
387 sample_rate_.show_min_max_step(min, max, step);
389 } else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
390 "samplerates", G_VARIANT_TYPE("at")))) {
391 elements = (const uint64_t *)g_variant_get_fixed_array(
392 gvar_list, &num_elements, sizeof(uint64_t));
393 sample_rate_.show_list(elements, num_elements);
394 g_variant_unref(gvar_list);
396 updating_sample_rate_ = false;
398 update_sample_rate_selector_value();
401 void MainBar::update_sample_rate_selector_value()
403 if (updating_sample_rate_)
406 const shared_ptr<devices::Device> device = device_selector_.selected_device();
411 auto gvar = device->device()->config_get(ConfigKey::SAMPLERATE);
412 uint64_t samplerate =
413 Glib::VariantBase::cast_dynamic<Glib::Variant<guint64>>(gvar).get();
414 assert(!updating_sample_rate_);
415 updating_sample_rate_ = true;
416 sample_rate_.set_value(samplerate);
417 updating_sample_rate_ = false;
418 } catch (Error& error) {
419 qDebug() << tr("Failed to get sample rate:") << error.what();
423 void MainBar::update_sample_count_selector()
425 if (updating_sample_count_)
428 const shared_ptr<devices::Device> device = device_selector_.selected_device();
432 const shared_ptr<sigrok::Device> sr_dev = device->device();
434 assert(!updating_sample_count_);
435 updating_sample_count_ = true;
437 if (!sample_count_supported_) {
438 sample_count_.show_none();
439 updating_sample_count_ = false;
443 uint64_t sample_count = sample_count_.value();
444 uint64_t min_sample_count = 0;
445 uint64_t max_sample_count = MaxSampleCount;
446 bool default_count_set = false;
448 if (sample_count == 0) {
449 sample_count = DefaultSampleCount;
450 default_count_set = true;
453 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::LIST)) {
455 auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
457 g_variant_get(gvar.gobj(), "(tt)",
458 &min_sample_count, &max_sample_count);
459 } catch (Error& error) {
460 qDebug() << tr("Failed to get sample limit list:") << error.what();
464 min_sample_count = min(max(min_sample_count, MinSampleCount),
467 sample_count_.show_125_list(min_sample_count, max_sample_count);
469 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::GET)) {
470 auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES);
471 sample_count = g_variant_get_uint64(gvar.gobj());
472 if (sample_count == 0) {
473 sample_count = DefaultSampleCount;
474 default_count_set = true;
476 sample_count = min(max(sample_count, MinSampleCount),
480 sample_count_.set_value(sample_count);
482 updating_sample_count_ = false;
484 // If we show the default rate then make sure the device uses the same
485 if (default_count_set)
486 commit_sample_count();
489 void MainBar::update_device_config_widgets()
491 using namespace pv::popups;
493 const shared_ptr<devices::Device> device = device_selector_.selected_device();
495 // Hide the widgets if no device is selected
496 channels_button_action_->setVisible(!!device);
498 configure_button_action_->setVisible(false);
499 sample_count_.show_none();
500 sample_rate_.show_none();
504 const shared_ptr<sigrok::Device> sr_dev = device->device();
508 // Update the configure popup
509 DeviceOptions *const opts = new DeviceOptions(sr_dev, this);
510 configure_button_action_->setVisible(!opts->binding().properties().empty());
511 configure_button_.set_popup(opts);
513 // Update the channels popup
514 Channels *const channels = new Channels(session_, this);
515 channels_button_.set_popup(channels);
517 // Update supported options.
518 sample_count_supported_ = false;
520 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::SET))
521 sample_count_supported_ = true;
523 // Add notification of reconfigure events
524 disconnect(this, SLOT(on_config_changed()));
525 connect(&opts->binding(), SIGNAL(config_changed()),
526 this, SLOT(on_config_changed()));
528 // Update sweep timing widgets.
529 update_sample_count_selector();
530 update_sample_rate_selector();
533 void MainBar::commit_sample_rate()
535 uint64_t sample_rate = 0;
537 const shared_ptr<devices::Device> device = device_selector_.selected_device();
541 const shared_ptr<sigrok::Device> sr_dev = device->device();
543 sample_rate = sample_rate_.value();
546 sr_dev->config_set(ConfigKey::SAMPLERATE,
547 Glib::Variant<guint64>::create(sample_rate));
548 update_sample_rate_selector();
549 } catch (Error& error) {
550 qDebug() << tr("Failed to configure samplerate:") << error.what();
554 // Devices with built-in memory might impose limits on certain
555 // configurations, so let's check what sample count the driver
557 update_sample_count_selector();
560 void MainBar::commit_sample_count()
562 uint64_t sample_count = 0;
564 const shared_ptr<devices::Device> device = device_selector_.selected_device();
568 const shared_ptr<sigrok::Device> sr_dev = device->device();
570 sample_count = sample_count_.value();
571 if (sample_count_supported_) {
573 sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
574 Glib::Variant<guint64>::create(sample_count));
575 update_sample_count_selector();
576 } catch (Error& error) {
577 qDebug() << tr("Failed to configure sample count:") << error.what();
582 // Devices with built-in memory might impose limits on certain
583 // configurations, so let's check what sample rate the driver
585 update_sample_rate_selector();
588 void MainBar::show_session_error(const QString text, const QString info_text)
590 QMessageBox msg(this);
591 msg.setText(text + "\n\n" + info_text);
592 msg.setStandardButtons(QMessageBox::Ok);
593 msg.setIcon(QMessageBox::Warning);
597 void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
599 using pv::dialogs::StoreProgress;
601 // Stop any currently running capture session
602 session_.stop_capture();
605 const QString dir = settings.value(SettingSaveDirectory).toString();
607 pair<uint64_t, uint64_t> sample_range;
609 // Selection only? Verify that the cursors are active and fetch their values
610 if (selection_only) {
611 views::trace::View *trace_view =
612 qobject_cast<views::trace::View*>(session_.main_view().get());
614 if (!trace_view->cursors()->enabled()) {
615 show_session_error(tr("Missing Cursors"), tr("You need to set the " \
616 "cursors before you can save the data enclosed by them " \
617 "to a session file (e.g. using the Show Cursors button)."));
621 const double samplerate = session_.get_samplerate();
623 const pv::util::Timestamp& start_time = trace_view->cursors()->first()->time();
624 const pv::util::Timestamp& end_time = trace_view->cursors()->second()->time();
626 const uint64_t start_sample = (uint64_t)max(
627 0.0, start_time.convert_to<double>() * samplerate);
628 const uint64_t end_sample = (uint64_t)max(
629 0.0, end_time.convert_to<double>() * samplerate);
631 if ((start_sample == 0) && (end_sample == 0)) {
632 // Both cursors are negative and were clamped to 0
633 show_session_error(tr("Invalid Range"), tr("The cursors don't " \
634 "define a valid range of samples."));
638 sample_range = make_pair(start_sample, end_sample);
640 sample_range = make_pair(0, 0);
643 // Construct the filter
644 const vector<string> exts = format->extensions();
645 QString filter = tr("%1 files ").arg(
646 QString::fromStdString(format->description()));
651 filter += QString("(*.%1);;%2 (*)").arg(
652 QString::fromStdString(join(exts, ", *.")),
655 // Show the file dialog
656 const QString file_name = QFileDialog::getSaveFileName(
657 this, tr("Save File"), dir, filter);
659 if (file_name.isEmpty())
662 const QString abs_path = QFileInfo(file_name).absolutePath();
663 settings.setValue(SettingSaveDirectory, abs_path);
665 // Show the options dialog
666 map<string, Glib::VariantBase> options;
667 if (!format->options().empty()) {
668 dialogs::InputOutputOptions dlg(
669 tr("Export %1").arg(QString::fromStdString(
670 format->description())),
671 format->options(), this);
674 options = dlg.options();
678 session_.set_name(QFileInfo(file_name).fileName());
680 StoreProgress *dlg = new StoreProgress(file_name, format, options,
681 sample_range, session_, this);
685 void MainBar::import_file(shared_ptr<InputFormat> format)
690 const QString dir = settings.value(SettingOpenDirectory).toString();
692 // Construct the filter
693 const vector<string> exts = format->extensions();
694 const QString filter_exts = exts.empty() ? "" : QString::fromStdString("%1 (%2)").arg(
695 tr("%1 files").arg(QString::fromStdString(format->description())),
696 QString::fromStdString("*.%1").arg(QString::fromStdString(join(exts, " *."))));
697 const QString filter_all = QString::fromStdString("%1 (%2)").arg(
698 tr("All Files"), QString::fromStdString("*"));
699 const QString filter = QString::fromStdString("%1%2%3").arg(
700 exts.empty() ? "" : filter_exts,
701 exts.empty() ? "" : ";;",
704 // Show the file dialog
705 const QString file_name = QFileDialog::getOpenFileName(
706 this, tr("Import File"), dir, filter);
708 if (file_name.isEmpty())
711 // Show the options dialog
712 map<string, Glib::VariantBase> options;
713 if (!format->options().empty()) {
714 dialogs::InputOutputOptions dlg(
715 tr("Import %1").arg(QString::fromStdString(
716 format->description())),
717 format->options(), this);
720 options = dlg.options();
723 session_.load_file(file_name, "", format, options);
725 const QString abs_path = QFileInfo(file_name).absolutePath();
726 settings.setValue(SettingOpenDirectory, abs_path);
729 void MainBar::on_device_selected()
731 shared_ptr<devices::Device> device = device_selector_.selected_device();
734 session_.select_device(device);
736 reset_device_selector();
739 void MainBar::on_device_changed()
741 update_device_list();
742 update_device_config_widgets();
745 void MainBar::on_capture_state_changed(int state)
747 set_capture_state((pv::Session::capture_state)state);
750 void MainBar::on_sample_count_changed()
752 if (!updating_sample_count_)
753 commit_sample_count();
756 void MainBar::on_sample_rate_changed()
758 if (!updating_sample_rate_)
759 commit_sample_rate();
762 void MainBar::on_config_changed()
764 // We want to also call update_sample_rate_selector() here in case
765 // the user changed the SR_CONF_EXTERNAL_CLOCK option. However,
766 // commit_sample_rate() does this already, so we don't call it here
768 commit_sample_count();
769 commit_sample_rate();
772 void MainBar::on_actionNewView_triggered(QAction* action)
775 new_view(&session_, action->data().toInt());
777 // When the icon of the button is clicked, we create a trace view
778 new_view(&session_, views::ViewTypeTrace);
781 void MainBar::on_actionOpen_triggered()
784 const QString dir = settings.value(SettingOpenDirectory).toString();
787 const QString file_name = QFileDialog::getOpenFileName(
788 this, tr("Open File"), dir, tr(
789 "sigrok Sessions (*.sr);;"
792 if (!file_name.isEmpty()) {
793 session_.load_file(file_name);
795 const QString abs_path = QFileInfo(file_name).absolutePath();
796 settings.setValue(SettingOpenDirectory, abs_path);
800 void MainBar::on_actionSaveAs_triggered()
802 export_file(session_.device_manager().context()->output_formats()["srzip"]);
805 void MainBar::on_actionSaveSelectionAs_triggered()
807 export_file(session_.device_manager().context()->output_formats()["srzip"], true);
810 void MainBar::on_actionSaveSetup_triggered()
813 const QString dir = settings.value(SettingSaveDirectory).toString();
815 const QString file_name = QFileDialog::getSaveFileName(
816 this, tr("Save File"), dir, tr(
817 "PulseView Session Setups (*.pvs);;"
820 if (file_name.isEmpty())
823 QSettings settings_storage(file_name, QSettings::IniFormat);
824 session_.save_setup(settings_storage);
827 void MainBar::on_actionRestoreSetup_triggered()
830 const QString dir = settings.value(SettingSaveDirectory).toString();
832 const QString file_name = QFileDialog::getOpenFileName(
833 this, tr("Open File"), dir, tr(
834 "PulseView Session Setups (*.pvs);;"
837 if (file_name.isEmpty())
840 QSettings settings_storage(file_name, QSettings::IniFormat);
841 session_.restore_setup(settings_storage);
844 void MainBar::on_actionConnect_triggered()
846 // Stop any currently running capture session
847 session_.stop_capture();
849 dialogs::Connect dlg(this, session_.device_manager());
851 // If the user selected a device, select it in the device list. Select the
852 // current device otherwise.
854 session_.select_device(dlg.get_selected_device());
856 update_device_list();
859 void MainBar::on_add_decoder_clicked()
861 show_decoder_selector(&session_);
864 void MainBar::add_toolbar_widgets()
866 addWidget(new_view_button_);
868 addWidget(open_button_);
869 addWidget(save_button_);
872 StandardBar::add_toolbar_widgets();
874 addWidget(&device_selector_);
875 configure_button_action_ = addWidget(&configure_button_);
876 channels_button_action_ = addWidget(&channels_button_);
877 addWidget(&sample_count_);
878 addWidget(&sample_rate_);
881 addWidget(add_decoder_button_);
885 bool MainBar::eventFilter(QObject *watched, QEvent *event)
887 if (sample_count_supported_ && (watched == &sample_count_ ||
888 watched == &sample_rate_) &&
889 (event->type() == QEvent::ToolTip)) {
891 auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value();
892 QHelpEvent *help_event = static_cast<QHelpEvent*>(event);
894 QString str = tr("Total sampling time: %1").arg(
895 pv::util::format_time_si(sec, pv::util::SIPrefix::unspecified, 0, "s", false));
896 QToolTip::showText(help_event->globalPos(), str);
904 } // namespace toolbars