MainBar: Disable custom samplerate by default
[pulseview.git] / pv / toolbars / mainbar.cpp
index b96bfbe78837325bed9c52b4eb86f35f23411a29..d78a153f160d0f14e45969572cfe671269ba07f0 100644 (file)
@@ -302,10 +302,25 @@ void MainBar::update_sample_rate_selector()
 
        const shared_ptr<sigrok::Device> sr_dev = device->device();
 
 
        const shared_ptr<sigrok::Device> 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<Glib::Variant<bool>>(
+                                       gvar).get();
+                               sample_rate_.allow_user_entered_values(value);
+                       }
+               } catch (Error& error) {
+                       // Do nothing
+               }
+       }
+
+
        if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
                try {
                        gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
        if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
                try {
                        gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
-               } catch (Error error) {
+               } catch (Error& error) {
                        qDebug() << tr("Failed to get sample rate list:") << error.what();
                }
        } else {
                        qDebug() << tr("Failed to get sample rate list:") << error.what();
                }
        } else {
@@ -368,7 +383,7 @@ void MainBar::update_sample_rate_selector_value()
                updating_sample_rate_ = true;
                sample_rate_.set_value(samplerate);
                updating_sample_rate_ = false;
                updating_sample_rate_ = true;
                sample_rate_.set_value(samplerate);
                updating_sample_rate_ = false;
-       } catch (Error error) {
+       } catch (Error& error) {
                qDebug() << tr("Failed to get value of sample rate:") << error.what();
        }
 }
                qDebug() << tr("Failed to get value of sample rate:") << error.what();
        }
 }
@@ -409,7 +424,7 @@ void MainBar::update_sample_count_selector()
                        if (gvar.gobj())
                                g_variant_get(gvar.gobj(), "(tt)",
                                        &min_sample_count, &max_sample_count);
                        if (gvar.gobj())
                                g_variant_get(gvar.gobj(), "(tt)",
                                        &min_sample_count, &max_sample_count);
-               } catch (Error error) {
+               } catch (Error& error) {
                        qDebug() << tr("Failed to get sample limit list:") << error.what();
                }
        }
                        qDebug() << tr("Failed to get sample limit list:") << error.what();
                }
        }
@@ -501,7 +516,7 @@ void MainBar::commit_sample_rate()
                sr_dev->config_set(ConfigKey::SAMPLERATE,
                        Glib::Variant<guint64>::create(sample_rate));
                update_sample_rate_selector();
                sr_dev->config_set(ConfigKey::SAMPLERATE,
                        Glib::Variant<guint64>::create(sample_rate));
                update_sample_rate_selector();
-       } catch (Error error) {
+       } catch (Error& error) {
                qDebug() << tr("Failed to configure samplerate:") << error.what();
                return;
        }
                qDebug() << tr("Failed to configure samplerate:") << error.what();
                return;
        }
@@ -528,7 +543,7 @@ void MainBar::commit_sample_count()
                        sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
                                Glib::Variant<guint64>::create(sample_count));
                        update_sample_count_selector();
                        sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
                                Glib::Variant<guint64>::create(sample_count));
                        update_sample_count_selector();
-               } catch (Error error) {
+               } catch (Error& error) {
                        qDebug() << tr("Failed to configure sample count:") << error.what();
                        return;
                }
                        qDebug() << tr("Failed to configure sample count:") << error.what();
                        return;
                }
@@ -540,13 +555,6 @@ void MainBar::commit_sample_count()
        update_sample_rate_selector();
 }
 
        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);
 void MainBar::show_session_error(const QString text, const QString info_text)
 {
        QMessageBox msg(this);
@@ -736,6 +744,10 @@ void MainBar::on_sample_rate_changed()
 
 void MainBar::on_config_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_count();
        commit_sample_rate();
 }