X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=e6beb2b3ba704e198c8aff0076787a9d96798fe9;hb=0adee2d93430b5fb879388e66f3bd44fd11b3b22;hp=65db28b72dd8e509725a644818839ea6d57a9f99;hpb=5f66b56eb6616c9c626d6f48abf1da0d8a652444;p=pulseview.git
diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp
index 65db28b..e6beb2b 100644
--- a/pv/toolbars/mainbar.cpp
+++ b/pv/toolbars/mainbar.cpp
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
#include
@@ -36,6 +35,7 @@
#include
+#include
#include
#include
#include
@@ -44,10 +44,10 @@
#include
#include
#include
-#include
#include
+#include
#include
-#include
+#include
#include
#include
#ifdef ENABLE_DECODE
@@ -57,13 +57,14 @@
#include
using std::back_inserter;
-using std::cerr;
using std::copy;
-using std::endl;
using std::list;
+using std::make_pair;
using std::map;
using std::max;
using std::min;
+using std::pair;
+using std::set;
using std::shared_ptr;
using std::string;
using std::vector;
@@ -86,8 +87,7 @@ const uint64_t MainBar::DefaultSampleCount = 1000000;
const char *MainBar::SettingOpenDirectory = "MainWindow/OpenDirectory";
const char *MainBar::SettingSaveDirectory = "MainWindow/SaveDirectory";
-MainBar::MainBar(Session &session, QWidget *parent,
- pv::views::TraceView::View *view) :
+MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view) :
StandardBar(session, parent, view, false),
action_new_view_(new QAction(this)),
action_open_(new QAction(this)),
@@ -96,8 +96,7 @@ MainBar::MainBar(Session &session, QWidget *parent,
action_connect_(new QAction(this)),
open_button_(new QToolButton()),
save_button_(new QToolButton()),
- device_selector_(parent, session.device_manager(),
- action_connect_),
+ device_selector_(parent, session.device_manager(), action_connect_),
configure_button_(this),
configure_button_action_(nullptr),
channels_button_(this),
@@ -114,6 +113,8 @@ MainBar::MainBar(Session &session, QWidget *parent,
{
setObjectName(QString::fromUtf8("MainBar"));
+ setContextMenuPolicy(Qt::PreventContextMenu);
+
// Actions
action_new_view_->setText(tr("New &View"));
action_new_view_->setIcon(QIcon::fromTheme("window-new",
@@ -145,16 +146,14 @@ MainBar::MainBar(Session &session, QWidget *parent,
widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
session.device_manager().context());
menu_file_export->setTitle(tr("&Export"));
- connect(menu_file_export,
- SIGNAL(format_selected(std::shared_ptr)),
- this, SLOT(export_file(std::shared_ptr)));
+ connect(menu_file_export, SIGNAL(format_selected(shared_ptr)),
+ this, SLOT(export_file(shared_ptr)));
widgets::ImportMenu *menu_file_import = new widgets::ImportMenu(this,
session.device_manager().context());
menu_file_import->setTitle(tr("&Import"));
- connect(menu_file_import,
- SIGNAL(format_selected(std::shared_ptr)),
- this, SLOT(import_file(std::shared_ptr)));
+ connect(menu_file_import, SIGNAL(format_selected(shared_ptr)),
+ this, SLOT(import_file(shared_ptr)));
action_connect_->setText(tr("&Connect to Device..."));
connect(action_connect_, SIGNAL(triggered(bool)),
@@ -163,27 +162,22 @@ MainBar::MainBar(Session &session, QWidget *parent,
// Open button
widgets::ImportMenu *import_menu = new widgets::ImportMenu(this,
session.device_manager().context(), action_open_);
- connect(import_menu,
- SIGNAL(format_selected(std::shared_ptr)),
- this,
- SLOT(import_file(std::shared_ptr)));
+ connect(import_menu, SIGNAL(format_selected(shared_ptr)),
+ this, SLOT(import_file(shared_ptr)));
open_button_->setMenu(import_menu);
open_button_->setDefaultAction(action_open_);
open_button_->setPopupMode(QToolButton::MenuButtonPopup);
// Save button
- vector open_actions;
+ vector open_actions;
open_actions.push_back(action_save_as_);
open_actions.push_back(action_save_selection_as_);
widgets::ExportMenu *export_menu = new widgets::ExportMenu(this,
- session.device_manager().context(),
- open_actions);
- connect(export_menu,
- SIGNAL(format_selected(std::shared_ptr)),
- this,
- SLOT(export_file(std::shared_ptr)));
+ session.device_manager().context(), open_actions);
+ connect(export_menu, SIGNAL(format_selected(shared_ptr)),
+ this, SLOT(export_file(shared_ptr)));
save_button_->setMenu(export_menu);
save_button_->setDefaultAction(action_save_as_);
@@ -199,10 +193,10 @@ MainBar::MainBar(Session &session, QWidget *parent,
connect(menu_decoders_add_, SIGNAL(decoder_selected(srd_decoder*)),
this, SLOT(add_decoder(srd_decoder*)));
- add_decoder_button_->setIcon(QIcon::fromTheme("add-decoder",
- QIcon(":/icons/add-decoder.svg")));
+ add_decoder_button_->setIcon(QIcon(":/icons/add-decoder.svg"));
add_decoder_button_->setPopupMode(QToolButton::InstantPopup);
add_decoder_button_->setMenu(menu_decoders_add_);
+ add_decoder_button_->setToolTip(tr("Add low-level, non-stacked protocol decoder"));
#endif
connect(&sample_count_, SIGNAL(value_changed()),
@@ -215,12 +209,11 @@ MainBar::MainBar(Session &session, QWidget *parent,
set_capture_state(pv::Session::Stopped);
configure_button_.setToolTip(tr("Configure Device"));
- configure_button_.setIcon(QIcon::fromTheme("configure",
- QIcon(":/icons/configure.png")));
+ configure_button_.setIcon(QIcon::fromTheme("preferences-system",
+ QIcon(":/icons/preferences-system.png")));
channels_button_.setToolTip(tr("Configure Channels"));
- channels_button_.setIcon(QIcon::fromTheme("channels",
- QIcon(":/icons/channels.svg")));
+ channels_button_.setIcon(QIcon(":/icons/channels.svg"));
add_toolbar_widgets();
@@ -251,7 +244,6 @@ void MainBar::update_device_list()
update_device_config_widgets();
}
-
void MainBar::set_capture_state(pv::Session::capture_state state)
{
bool ui_enabled = (state == pv::Session::Stopped) ? true : false;
@@ -294,15 +286,14 @@ void MainBar::update_sample_rate_selector()
GVariant *gvar_list;
const uint64_t *elements = nullptr;
gsize num_elements;
- map< const ConfigKey*, std::set > keys;
+ map< const ConfigKey*, set > keys;
if (updating_sample_rate_) {
sample_rate_.show_none();
return;
}
- const shared_ptr device =
- device_selector_.selected_device();
+ const shared_ptr device = device_selector_.selected_device();
if (!device)
return;
@@ -311,8 +302,27 @@ void MainBar::update_sample_rate_selector()
const shared_ptr sr_dev = device->device();
+ sample_rate_.allow_user_entered_values(false);
+ if (sr_dev->config_check(ConfigKey::EXTERNAL_CLOCK, Capability::GET)) {
+ try {
+ auto gvar = sr_dev->config_get(ConfigKey::EXTERNAL_CLOCK);
+ if (gvar.gobj()) {
+ bool value = Glib::VariantBase::cast_dynamic>(
+ gvar).get();
+ sample_rate_.allow_user_entered_values(value);
+ }
+ } catch (Error& error) {
+ // Do nothing
+ }
+ }
+
+
if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
- gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
+ try {
+ gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
+ } catch (Error& error) {
+ qDebug() << tr("Failed to get sample rate list:") << error.what();
+ }
} else {
sample_rate_.show_none();
updating_sample_rate_ = false;
@@ -322,7 +332,7 @@ void MainBar::update_sample_rate_selector()
if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
"samplerate-steps", G_VARIANT_TYPE("at")))) {
elements = (const uint64_t *)g_variant_get_fixed_array(
- gvar_list, &num_elements, sizeof(uint64_t));
+ gvar_list, &num_elements, sizeof(uint64_t));
const uint64_t min = elements[0];
const uint64_t max = elements[1];
@@ -347,7 +357,7 @@ void MainBar::update_sample_rate_selector()
} else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(),
"samplerates", G_VARIANT_TYPE("at")))) {
elements = (const uint64_t *)g_variant_get_fixed_array(
- gvar_list, &num_elements, sizeof(uint64_t));
+ gvar_list, &num_elements, sizeof(uint64_t));
sample_rate_.show_list(elements, num_elements);
g_variant_unref(gvar_list);
}
@@ -361,8 +371,7 @@ void MainBar::update_sample_rate_selector_value()
if (updating_sample_rate_)
return;
- const shared_ptr device =
- device_selector_.selected_device();
+ const shared_ptr device = device_selector_.selected_device();
if (!device)
return;
@@ -374,9 +383,8 @@ void MainBar::update_sample_rate_selector_value()
updating_sample_rate_ = true;
sample_rate_.set_value(samplerate);
updating_sample_rate_ = false;
- } catch (Error error) {
- qDebug() << "WARNING: Failed to get value of sample rate";
- return;
+ } catch (Error& error) {
+ qDebug() << tr("Failed to get sample rate:") << error.what();
}
}
@@ -385,8 +393,7 @@ void MainBar::update_sample_count_selector()
if (updating_sample_count_)
return;
- const shared_ptr device =
- device_selector_.selected_device();
+ const shared_ptr device = device_selector_.selected_device();
if (!device)
return;
@@ -404,28 +411,36 @@ void MainBar::update_sample_count_selector()
uint64_t sample_count = sample_count_.value();
uint64_t min_sample_count = 0;
uint64_t max_sample_count = MaxSampleCount;
+ bool default_count_set = false;
- if (sample_count == 0)
+ if (sample_count == 0) {
sample_count = DefaultSampleCount;
+ default_count_set = true;
+ }
if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::LIST)) {
- auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
- if (gvar.gobj())
- g_variant_get(gvar.gobj(), "(tt)",
- &min_sample_count, &max_sample_count);
+ try {
+ auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
+ if (gvar.gobj())
+ g_variant_get(gvar.gobj(), "(tt)",
+ &min_sample_count, &max_sample_count);
+ } catch (Error& error) {
+ qDebug() << tr("Failed to get sample limit list:") << error.what();
+ }
}
min_sample_count = min(max(min_sample_count, MinSampleCount),
max_sample_count);
- sample_count_.show_125_list(
- min_sample_count, max_sample_count);
+ sample_count_.show_125_list(min_sample_count, max_sample_count);
if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::GET)) {
auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES);
sample_count = g_variant_get_uint64(gvar.gobj());
- if (sample_count == 0)
+ if (sample_count == 0) {
sample_count = DefaultSampleCount;
+ default_count_set = true;
+ }
sample_count = min(max(sample_count, MinSampleCount),
max_sample_count);
}
@@ -433,14 +448,17 @@ void MainBar::update_sample_count_selector()
sample_count_.set_value(sample_count);
updating_sample_count_ = false;
+
+ // If we show the default rate then make sure the device uses the same
+ if (default_count_set)
+ commit_sample_count();
}
void MainBar::update_device_config_widgets()
{
using namespace pv::popups;
- const shared_ptr device =
- device_selector_.selected_device();
+ const shared_ptr device = device_selector_.selected_device();
// Hide the widgets if no device is selected
channels_button_action_->setVisible(!!device);
@@ -457,8 +475,7 @@ void MainBar::update_device_config_widgets()
// Update the configure popup
DeviceOptions *const opts = new DeviceOptions(sr_dev, this);
- configure_button_action_->setVisible(
- !opts->binding().properties().empty());
+ configure_button_action_->setVisible(!opts->binding().properties().empty());
configure_button_.set_popup(opts);
// Update the channels popup
@@ -471,12 +488,6 @@ void MainBar::update_device_config_widgets()
if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::SET))
sample_count_supported_ = true;
- if (sr_dev->config_check(ConfigKey::LIMIT_FRAMES, Capability::SET)) {
- sr_dev->config_set(ConfigKey::LIMIT_FRAMES,
- Glib::Variant::create(1));
- on_config_changed();
- }
-
// Add notification of reconfigure events
disconnect(this, SLOT(on_config_changed()));
connect(&opts->binding(), SIGNAL(config_changed()),
@@ -491,23 +502,20 @@ void MainBar::commit_sample_rate()
{
uint64_t sample_rate = 0;
- const shared_ptr device =
- device_selector_.selected_device();
+ const shared_ptr device = device_selector_.selected_device();
if (!device)
return;
const shared_ptr sr_dev = device->device();
sample_rate = sample_rate_.value();
- if (sample_rate == 0)
- return;
try {
sr_dev->config_set(ConfigKey::SAMPLERATE,
Glib::Variant::create(sample_rate));
update_sample_rate_selector();
- } catch (Error error) {
- qDebug() << "Failed to configure samplerate.";
+ } catch (Error& error) {
+ qDebug() << tr("Failed to configure samplerate:") << error.what();
return;
}
@@ -521,8 +529,7 @@ void MainBar::commit_sample_count()
{
uint64_t sample_count = 0;
- const shared_ptr device =
- device_selector_.selected_device();
+ const shared_ptr device = device_selector_.selected_device();
if (!device)
return;
@@ -534,8 +541,8 @@ void MainBar::commit_sample_count()
sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
Glib::Variant::create(sample_count));
update_sample_count_selector();
- } catch (Error error) {
- qDebug() << "Failed to configure sample count.";
+ } catch (Error& error) {
+ qDebug() << tr("Failed to configure sample count:") << error.what();
return;
}
}
@@ -546,13 +553,6 @@ void MainBar::commit_sample_count()
update_sample_rate_selector();
}
-void MainBar::session_error(const QString text, const QString info_text)
-{
- QMetaObject::invokeMethod(this, "show_session_error",
- Qt::QueuedConnection, Q_ARG(QString, text),
- Q_ARG(QString, info_text));
-}
-
void MainBar::show_session_error(const QString text, const QString info_text)
{
QMessageBox msg(this);
@@ -567,14 +567,15 @@ void MainBar::add_decoder(srd_decoder *decoder)
{
#ifdef ENABLE_DECODE
assert(decoder);
- session_.add_decoder(decoder);
+ shared_ptr signal = session_.add_decode_signal();
+ if (signal)
+ signal->stack_decoder(decoder);
#else
(void)decoder;
#endif
}
-void MainBar::export_file(shared_ptr format,
- bool selection_only)
+void MainBar::export_file(shared_ptr format, bool selection_only)
{
using pv::dialogs::StoreProgress;
@@ -584,17 +585,17 @@ void MainBar::export_file(shared_ptr format,
QSettings settings;
const QString dir = settings.value(SettingSaveDirectory).toString();
- std::pair sample_range;
+ pair sample_range;
// Selection only? Verify that the cursors are active and fetch their values
if (selection_only) {
- views::TraceView::View *trace_view =
- qobject_cast(session_.main_view().get());
+ views::trace::View *trace_view =
+ qobject_cast(session_.main_view().get());
if (!trace_view->cursors()->enabled()) {
show_session_error(tr("Missing Cursors"), tr("You need to set the " \
- "cursors before you can save the data enclosed by them " \
- "to a session file (e.g. using ALT-V - Show Cursors)."));
+ "cursors before you can save the data enclosed by them " \
+ "to a session file (e.g. using the Show Cursors button)."));
return;
}
@@ -603,13 +604,21 @@ void MainBar::export_file(shared_ptr format,
const pv::util::Timestamp& start_time = trace_view->cursors()->first()->time();
const pv::util::Timestamp& end_time = trace_view->cursors()->second()->time();
- const uint64_t start_sample =
- std::max((double)0, start_time.convert_to() * samplerate);
- const uint64_t end_sample = end_time.convert_to() * samplerate;
+ const uint64_t start_sample = (uint64_t)max(
+ 0.0, start_time.convert_to() * samplerate);
+ const uint64_t end_sample = (uint64_t)max(
+ 0.0, end_time.convert_to() * samplerate);
+
+ if ((start_sample == 0) && (end_sample == 0)) {
+ // Both cursors are negative and were clamped to 0
+ show_session_error(tr("Invalid Range"), tr("The cursors don't " \
+ "define a valid range of samples."));
+ return;
+ }
- sample_range = std::make_pair(start_sample, end_sample);
+ sample_range = make_pair(start_sample, end_sample);
} else {
- sample_range = std::make_pair(0, 0);
+ sample_range = make_pair(0, 0);
}
// Construct the filter
@@ -618,9 +627,9 @@ void MainBar::export_file(shared_ptr format,
QString::fromStdString(format->description()));
if (exts.empty())
- filter += "(*.*)";
+ filter += "(*)";
else
- filter += QString("(*.%1);;%2 (*.*)").arg(
+ filter += QString("(*.%1);;%2 (*)").arg(
QString::fromStdString(join(exts, ", *.")),
tr("All Files"));
@@ -663,16 +672,19 @@ void MainBar::import_file(shared_ptr format)
// Construct the filter
const vector exts = format->extensions();
- const QString filter = exts.empty() ? "" :
- tr("%1 files (*.%2)").arg(
- QString::fromStdString(format->description()),
- QString::fromStdString(join(exts, ", *.")));
+ const QString filter_exts = exts.empty() ? "" : QString::fromStdString("%1 (%2)").arg(
+ tr("%1 files").arg(QString::fromStdString(format->description())),
+ QString::fromStdString("*.%1").arg(QString::fromStdString(join(exts, " *."))));
+ const QString filter_all = QString::fromStdString("%1 (%2)").arg(
+ tr("All Files"), QString::fromStdString("*"));
+ const QString filter = QString::fromStdString("%1%2%3").arg(
+ exts.empty() ? "" : filter_exts,
+ exts.empty() ? "" : ";;",
+ filter_all);
// Show the file dialog
const QString file_name = QFileDialog::getOpenFileName(
- this, tr("Import File"), dir, tr(
- "%1 files (*.*);;All Files (*.*)").arg(
- QString::fromStdString(format->description())));
+ this, tr("Import File"), dir, filter);
if (file_name.isEmpty())
return;
@@ -698,12 +710,11 @@ void MainBar::import_file(shared_ptr format)
void MainBar::on_device_selected()
{
shared_ptr device = device_selector_.selected_device();
- if (!device) {
- reset_device_selector();
- return;
- }
- session_.select_device(device);
+ if (device)
+ session_.select_device(device);
+ else
+ reset_device_selector();
}
void MainBar::on_device_changed()
@@ -731,8 +742,12 @@ void MainBar::on_sample_rate_changed()
void MainBar::on_config_changed()
{
+ // We want to also call update_sample_rate_selector() here in case
+ // the user changed the SR_CONF_EXTERNAL_CLOCK option. However,
+ // commit_sample_rate() does this already, so we don't call it here
+
commit_sample_count();
- commit_sample_rate();
+ commit_sample_rate();
}
void MainBar::on_actionNewView_triggered()
@@ -748,8 +763,8 @@ void MainBar::on_actionOpen_triggered()
// Show the dialog
const QString file_name = QFileDialog::getOpenFileName(
this, tr("Open File"), dir, tr(
- "Sigrok Sessions (*.sr);;"
- "All Files (*.*)"));
+ "sigrok Sessions (*.sr);;"
+ "All Files (*)"));
if (!file_name.isEmpty()) {
session_.load_file(file_name);
@@ -808,8 +823,9 @@ void MainBar::add_toolbar_widgets()
bool MainBar::eventFilter(QObject *watched, QEvent *event)
{
if (sample_count_supported_ && (watched == &sample_count_ ||
- watched == &sample_rate_) &&
- (event->type() == QEvent::ToolTip)) {
+ watched == &sample_rate_) &&
+ (event->type() == QEvent::ToolTip)) {
+
auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value();
QHelpEvent *help_event = static_cast(event);