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"));
229 add_decoder_button_->setShortcut(QKeySequence(Qt::Key_D));
231 connect(add_decoder_button_, SIGNAL(clicked()),
232 this, SLOT(on_add_decoder_clicked()));
235 connect(&sample_count_, SIGNAL(value_changed()),
236 this, SLOT(on_sample_count_changed()));
237 connect(&sample_rate_, SIGNAL(value_changed()),
238 this, SLOT(on_sample_rate_changed()));
240 sample_count_.show_min_max_step(0, UINT64_MAX, 1);
242 set_capture_state(pv::Session::Stopped);
244 configure_button_.setToolTip(tr("Configure Device"));
245 configure_button_.setIcon(QIcon::fromTheme("preferences-system",
246 QIcon(":/icons/preferences-system.png")));
248 channels_button_.setToolTip(tr("Configure Channels"));
249 channels_button_.setIcon(QIcon(":/icons/channels.svg"));
251 add_toolbar_widgets();
253 sample_count_.installEventFilter(this);
254 sample_rate_.installEventFilter(this);
256 // Setup session_ events
257 connect(&session_, SIGNAL(capture_state_changed(int)),
258 this, SLOT(on_capture_state_changed(int)));
259 connect(&session, SIGNAL(device_changed()),
260 this, SLOT(on_device_changed()));
262 update_device_list();
265 void MainBar::update_device_list()
267 DeviceManager &mgr = session_.device_manager();
268 shared_ptr<devices::Device> selected_device = session_.device();
269 list< shared_ptr<devices::Device> > devs;
271 copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs));
273 if (std::find(devs.begin(), devs.end(), selected_device) == devs.end())
274 devs.push_back(selected_device);
276 device_selector_.set_device_list(devs, selected_device);
277 update_device_config_widgets();
280 void MainBar::set_capture_state(pv::Session::capture_state state)
282 bool ui_enabled = (state == pv::Session::Stopped) ? true : false;
284 device_selector_.setEnabled(ui_enabled);
285 configure_button_.setEnabled(ui_enabled);
286 channels_button_.setEnabled(ui_enabled);
287 sample_count_.setEnabled(ui_enabled);
288 sample_rate_.setEnabled(ui_enabled);
291 void MainBar::reset_device_selector()
293 device_selector_.reset();
296 QAction* MainBar::action_open() const
301 QAction* MainBar::action_save_as() const
303 return action_save_as_;
306 QAction* MainBar::action_save_selection_as() const
308 return action_save_selection_as_;
311 QAction* MainBar::action_connect() const
313 return action_connect_;
316 void MainBar::update_sample_rate_selector()
318 Glib::VariantContainerBase gvar_dict;
320 const uint64_t *elements = nullptr;
322 map< const ConfigKey*, set<Capability> > keys;
324 if (updating_sample_rate_) {
325 sample_rate_.show_none();
329 const shared_ptr<devices::Device> device = device_selector_.selected_device();
333 assert(!updating_sample_rate_);
334 updating_sample_rate_ = true;
336 const shared_ptr<sigrok::Device> sr_dev = device->device();
338 sample_rate_.allow_user_entered_values(false);
339 if (sr_dev->config_check(ConfigKey::EXTERNAL_CLOCK, Capability::GET)) {
341 auto gvar = sr_dev->config_get(ConfigKey::EXTERNAL_CLOCK);
343 bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
345 sample_rate_.allow_user_entered_values(value);
347 } catch (Error& error) {
353 if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
355 gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
356 } catch (Error& error) {
357 qDebug() << tr("Failed to get sample rate list:") << error.what();
360 sample_rate_.show_none();
361 updating_sample_rate_ = false;
365 if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
366 "samplerate-steps", G_VARIANT_TYPE("at")))) {
367 elements = (const uint64_t *)g_variant_get_fixed_array(
368 gvar_list, &num_elements, sizeof(uint64_t));
370 const uint64_t min = elements[0];
371 const uint64_t max = elements[1];
372 const uint64_t step = elements[2];
374 g_variant_unref(gvar_list);
382 sample_rate_.show_125_list(min, max);
384 // When the step is not 1, we cam't make a 1-2-5-10
385 // list of sample rates, because we may not be able to
386 // make round numbers. Therefore in this case, show a
388 sample_rate_.show_min_max_step(min, max, step);
390 } else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
391 "samplerates", G_VARIANT_TYPE("at")))) {
392 elements = (const uint64_t *)g_variant_get_fixed_array(
393 gvar_list, &num_elements, sizeof(uint64_t));
394 sample_rate_.show_list(elements, num_elements);
395 g_variant_unref(gvar_list);
397 updating_sample_rate_ = false;
399 update_sample_rate_selector_value();
402 void MainBar::update_sample_rate_selector_value()
404 if (updating_sample_rate_)
407 const shared_ptr<devices::Device> device = device_selector_.selected_device();
412 auto gvar = device->device()->config_get(ConfigKey::SAMPLERATE);
413 uint64_t samplerate =
414 Glib::VariantBase::cast_dynamic<Glib::Variant<guint64>>(gvar).get();
415 assert(!updating_sample_rate_);
416 updating_sample_rate_ = true;
417 sample_rate_.set_value(samplerate);
418 updating_sample_rate_ = false;
419 } catch (Error& error) {
420 qDebug() << tr("Failed to get sample rate:") << error.what();
424 void MainBar::update_sample_count_selector()
426 if (updating_sample_count_)
429 const shared_ptr<devices::Device> device = device_selector_.selected_device();
433 const shared_ptr<sigrok::Device> sr_dev = device->device();
435 assert(!updating_sample_count_);
436 updating_sample_count_ = true;
438 if (!sample_count_supported_) {
439 sample_count_.show_none();
440 updating_sample_count_ = false;
444 uint64_t sample_count = sample_count_.value();
445 uint64_t min_sample_count = 0;
446 uint64_t max_sample_count = MaxSampleCount;
447 bool default_count_set = false;
449 if (sample_count == 0) {
450 sample_count = DefaultSampleCount;
451 default_count_set = true;
454 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::LIST)) {
456 auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
458 g_variant_get(gvar.gobj(), "(tt)",
459 &min_sample_count, &max_sample_count);
460 } catch (Error& error) {
461 qDebug() << tr("Failed to get sample limit list:") << error.what();
465 min_sample_count = min(max(min_sample_count, MinSampleCount),
468 sample_count_.show_125_list(min_sample_count, max_sample_count);
470 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::GET)) {
471 auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES);
472 sample_count = g_variant_get_uint64(gvar.gobj());
473 if (sample_count == 0) {
474 sample_count = DefaultSampleCount;
475 default_count_set = true;
477 sample_count = min(max(sample_count, MinSampleCount),
481 sample_count_.set_value(sample_count);
483 updating_sample_count_ = false;
485 // If we show the default rate then make sure the device uses the same
486 if (default_count_set)
487 commit_sample_count();
490 void MainBar::update_device_config_widgets()
492 using namespace pv::popups;
494 const shared_ptr<devices::Device> device = device_selector_.selected_device();
496 // Hide the widgets if no device is selected
497 channels_button_action_->setVisible(!!device);
499 configure_button_action_->setVisible(false);
500 sample_count_.show_none();
501 sample_rate_.show_none();
505 const shared_ptr<sigrok::Device> sr_dev = device->device();
509 // Update the configure popup
510 DeviceOptions *const opts = new DeviceOptions(sr_dev, this);
511 configure_button_action_->setVisible(!opts->binding().properties().empty());
512 configure_button_.set_popup(opts);
514 // Update the channels popup
515 Channels *const channels = new Channels(session_, this);
516 channels_button_.set_popup(channels);
518 // Update supported options.
519 sample_count_supported_ = false;
521 if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::SET))
522 sample_count_supported_ = true;
524 // Add notification of reconfigure events
525 disconnect(this, SLOT(on_config_changed()));
526 connect(&opts->binding(), SIGNAL(config_changed()),
527 this, SLOT(on_config_changed()));
529 // Update sweep timing widgets.
530 update_sample_count_selector();
531 update_sample_rate_selector();
534 void MainBar::commit_sample_rate()
536 uint64_t sample_rate = 0;
538 const shared_ptr<devices::Device> device = device_selector_.selected_device();
542 const shared_ptr<sigrok::Device> sr_dev = device->device();
544 sample_rate = sample_rate_.value();
547 sr_dev->config_set(ConfigKey::SAMPLERATE,
548 Glib::Variant<guint64>::create(sample_rate));
549 update_sample_rate_selector();
550 } catch (Error& error) {
551 qDebug() << tr("Failed to configure samplerate:") << error.what();
555 // Devices with built-in memory might impose limits on certain
556 // configurations, so let's check what sample count the driver
558 update_sample_count_selector();
561 void MainBar::commit_sample_count()
563 uint64_t sample_count = 0;
565 const shared_ptr<devices::Device> device = device_selector_.selected_device();
569 const shared_ptr<sigrok::Device> sr_dev = device->device();
571 sample_count = sample_count_.value();
572 if (sample_count_supported_) {
574 sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
575 Glib::Variant<guint64>::create(sample_count));
576 update_sample_count_selector();
577 } catch (Error& error) {
578 qDebug() << tr("Failed to configure sample count:") << error.what();
583 // Devices with built-in memory might impose limits on certain
584 // configurations, so let's check what sample rate the driver
586 update_sample_rate_selector();
589 void MainBar::show_session_error(const QString text, const QString info_text)
591 QMessageBox msg(this);
592 msg.setText(text + "\n\n" + info_text);
593 msg.setStandardButtons(QMessageBox::Ok);
594 msg.setIcon(QMessageBox::Warning);
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(QAction* action)
776 new_view(&session_, action->data().toInt());
778 // When the icon of the button is clicked, we create a trace view
779 new_view(&session_, views::ViewTypeTrace);
782 void MainBar::on_actionOpen_triggered()
785 const QString dir = settings.value(SettingOpenDirectory).toString();
788 const QString file_name = QFileDialog::getOpenFileName(
789 this, tr("Open File"), dir, tr(
790 "sigrok Sessions (*.sr);;"
793 if (!file_name.isEmpty()) {
794 session_.load_file(file_name);
796 const QString abs_path = QFileInfo(file_name).absolutePath();
797 settings.setValue(SettingOpenDirectory, abs_path);
801 void MainBar::on_actionSaveAs_triggered()
803 export_file(session_.device_manager().context()->output_formats()["srzip"]);
806 void MainBar::on_actionSaveSelectionAs_triggered()
808 export_file(session_.device_manager().context()->output_formats()["srzip"], true);
811 void MainBar::on_actionSaveSetup_triggered()
814 const QString dir = settings.value(SettingSaveDirectory).toString();
816 const QString file_name = QFileDialog::getSaveFileName(
817 this, tr("Save File"), dir, tr(
818 "PulseView Session Setups (*.pvs);;"
821 if (file_name.isEmpty())
824 QSettings settings_storage(file_name, QSettings::IniFormat);
825 session_.save_setup(settings_storage);
828 void MainBar::on_actionRestoreSetup_triggered()
831 const QString dir = settings.value(SettingSaveDirectory).toString();
833 const QString file_name = QFileDialog::getOpenFileName(
834 this, tr("Open File"), dir, tr(
835 "PulseView Session Setups (*.pvs);;"
838 if (file_name.isEmpty())
841 QSettings settings_storage(file_name, QSettings::IniFormat);
842 session_.restore_setup(settings_storage);
845 void MainBar::on_actionConnect_triggered()
847 // Stop any currently running capture session
848 session_.stop_capture();
850 dialogs::Connect dlg(this, session_.device_manager());
852 // If the user selected a device, select it in the device list. Select the
853 // current device otherwise.
855 session_.select_device(dlg.get_selected_device());
857 update_device_list();
860 void MainBar::on_add_decoder_clicked()
862 show_decoder_selector(&session_);
865 void MainBar::add_toolbar_widgets()
867 addWidget(new_view_button_);
869 addWidget(open_button_);
870 addWidget(save_button_);
873 StandardBar::add_toolbar_widgets();
875 addWidget(&device_selector_);
876 configure_button_action_ = addWidget(&configure_button_);
877 channels_button_action_ = addWidget(&channels_button_);
878 addWidget(&sample_count_);
879 addWidget(&sample_rate_);
882 addWidget(add_decoder_button_);
886 bool MainBar::eventFilter(QObject *watched, QEvent *event)
888 if (sample_count_supported_ && (watched == &sample_count_ ||
889 watched == &sample_rate_) &&
890 (event->type() == QEvent::ToolTip)) {
892 auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value();
893 QHelpEvent *help_event = static_cast<QHelpEvent*>(event);
895 QString str = tr("Total sampling time: %1").arg(
896 pv::util::format_time_si(sec, pv::util::SIPrefix::unspecified, 0, "s", false));
897 QToolTip::showText(help_event->globalPos(), str);
905 } // namespace toolbars