Skip to content

Commit

Permalink
Qt: Get the debounce timer value from the prefs structure.
Browse files Browse the repository at this point in the history
We do so in ui/qt/widgets/capture_filter_edit.cpp; we might as well do
so in the other files that use it.

That simplifies the process of fetching it, and lets us get rid of the
no-longer-used prefs_get_uint_value().  That lets us name the routine to
fetch unsigned integer preference values similarly to the routines to
fetch most other preference values, by removing the _real from the name.
  • Loading branch information
guyharris committed Nov 22, 2024
1 parent 54dee6e commit 336123f
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 47 deletions.
2 changes: 1 addition & 1 deletion epan/prefs-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ WS_DLL_PUBLIC void prefs_invert_bool_value(pref_t *pref, pref_source_t source);

WS_DLL_PUBLIC unsigned int prefs_set_uint_value(pref_t *pref, unsigned value, pref_source_t source);
WS_DLL_PUBLIC unsigned prefs_get_uint_base(pref_t *pref);
WS_DLL_PUBLIC unsigned prefs_get_uint_value_real(pref_t *pref, pref_source_t source);
WS_DLL_PUBLIC unsigned prefs_get_uint_value(pref_t *pref, pref_source_t source);


WS_DLL_PUBLIC unsigned int prefs_set_enum_value(pref_t *pref, int value, pref_source_t source);
Expand Down
20 changes: 1 addition & 19 deletions epan/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5132,7 +5132,7 @@ prefs_set_pref(char *prefarg, char **errmsg)
return ret;
}

unsigned prefs_get_uint_value_real(pref_t *pref, pref_source_t source)
unsigned prefs_get_uint_value(pref_t *pref, pref_source_t source)
{
switch (source)
{
Expand All @@ -5150,24 +5150,6 @@ unsigned prefs_get_uint_value_real(pref_t *pref, pref_source_t source)
return 0;
}

unsigned prefs_get_uint_value(const char *module_name, const char* pref_name)
{
pref_t *pref = prefs_find_preference(prefs_find_module(module_name), pref_name);
if (pref == NULL) {
ws_warning("Unknown preference requested: %s.%s", module_name, pref_name);
return 0;
}
switch (pref->type) {
case PREF_UINT:
return prefs_get_uint_value_real(pref, pref_current);
case PREF_BOOL:
return prefs_get_bool_value(pref, pref_current);
default:
ws_warning("Non-numeric preference requested: %s.%s", module_name, pref_name);
return 0;
}
}

char* prefs_get_password_value(pref_t *pref, pref_source_t source)
{
return prefs_get_string_value(pref, source);
Expand Down
11 changes: 0 additions & 11 deletions epan/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1020,17 +1020,6 @@ bool prefs_get_preference_obsolete(pref_t *pref);
*/
prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);

/**
* Get current preference uint or bool value. This allows the preference
* structure to remain hidden from those that don't really need it.
*
* @param module_name the preference module name. Usually the same as the protocol
* name, e.g. "tcp".
* @param pref_name the preference name, e.g. "desegment".
* @return the preference's value
*/
WS_DLL_PUBLIC unsigned prefs_get_uint_value(const char *module_name, const char* pref_name);

/**
* Get the current range preference value (maintained by pref, so it doesn't need to be freed). This allows the
* preference structure to remain hidden from those that doesn't really need it.
Expand Down
2 changes: 1 addition & 1 deletion epan/wslua/wslua_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ WSLUA_FUNCTION wslua_get_preference(lua_State *L) {
switch (prefs_get_type(pref)) {
case PREF_UINT:
{
unsigned uint_value = prefs_get_uint_value_real(pref, pref_current);
unsigned uint_value = prefs_get_uint_value(pref, pref_current);
lua_pushinteger(L, uint_value);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion sharkd_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -5327,7 +5327,7 @@ sharkd_session_process_dumpconf_cb(pref_t *pref, void *d)
switch (prefs_get_type(pref))
{
case PREF_UINT:
sharkd_json_value_anyf("u", "%u", prefs_get_uint_value_real(pref, pref_current));
sharkd_json_value_anyf("u", "%u", prefs_get_uint_value(pref, pref_current));
if (prefs_get_uint_base(pref) != 10)
sharkd_json_value_anyf("ub", "%u", prefs_get_uint_base(pref));
break;
Expand Down
8 changes: 4 additions & 4 deletions ui/qt/capture_preferences_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ void CapturePreferencesFrame::updateWidgets()
ui->captureMonitorModeCheckBox->setChecked(prefs_get_bool_value(pref_monitor_mode_, pref_stashed));
ui->capturePcapNgCheckBox->setChecked(prefs_get_bool_value(pref_pcap_ng_, pref_stashed));
ui->captureRealTimeCheckBox->setChecked(prefs_get_bool_value(pref_real_time_, pref_stashed));
ui->captureUpdateIntervalLineEdit->setText(QString::number(prefs_get_uint_value_real(pref_update_interval_, pref_stashed)));
ui->captureUpdateIntervalLineEdit->setPlaceholderText(QString::number(prefs_get_uint_value_real(pref_update_interval_, pref_default)));
ui->captureUpdateIntervalLineEdit->setText(QString::number(prefs_get_uint_value(pref_update_interval_, pref_stashed)));
ui->captureUpdateIntervalLineEdit->setPlaceholderText(QString::number(prefs_get_uint_value(pref_update_interval_, pref_default)));
ui->captureUpdateIntervalLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
#endif // HAVE_LIBPCAP
ui->captureNoInterfaceLoad->setChecked(prefs_get_bool_value(pref_no_interface_load_, pref_stashed));
Expand Down Expand Up @@ -163,7 +163,7 @@ void CapturePreferencesFrame::on_captureUpdateIntervalLineEdit_textChanged(const
{
uint new_uint;
if (new_str.isEmpty()) {
new_uint = prefs_get_uint_value_real(pref_update_interval_, pref_default);
new_uint = prefs_get_uint_value(pref_update_interval_, pref_default);
prefs_set_uint_value(pref_update_interval_, new_uint, pref_stashed);
ui->captureUpdateIntervalLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
return;
Expand All @@ -174,7 +174,7 @@ void CapturePreferencesFrame::on_captureUpdateIntervalLineEdit_textChanged(const
if (ok) {
ui->captureUpdateIntervalLineEdit->setSyntaxState(SyntaxLineEdit::Valid);
} else {
new_uint = prefs_get_uint_value_real(pref_update_interval_, pref_current);
new_uint = prefs_get_uint_value(pref_update_interval_, pref_current);
ui->captureUpdateIntervalLineEdit->setSyntaxState(SyntaxLineEdit::Invalid);
}
prefs_set_uint_value(pref_update_interval_, new_uint, pref_stashed);
Expand Down
4 changes: 2 additions & 2 deletions ui/qt/layout_preferences_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void LayoutPreferencesFrame::showEvent(QShowEvent *)

void LayoutPreferencesFrame::updateWidgets()
{
switch (prefs_get_uint_value_real(pref_layout_type_, pref_stashed)) {
switch (prefs_get_uint_value(pref_layout_type_, pref_stashed)) {
case layout_type_5:
ui->layout5ToolButton->setChecked(true);
break;
Expand Down Expand Up @@ -161,7 +161,7 @@ void LayoutPreferencesFrame::updateWidgets()
break;
}

ui->packetListCachedRowsLineEdit->setText(QString::number(prefs_get_uint_value_real(pref_packet_list_cached_rows_max_, pref_stashed)));
ui->packetListCachedRowsLineEdit->setText(QString::number(prefs_get_uint_value(pref_packet_list_cached_rows_max_, pref_stashed)));
}

void LayoutPreferencesFrame::on_layout5ToolButton_toggled(bool checked)
Expand Down
4 changes: 2 additions & 2 deletions ui/qt/main_window_preferences_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ void MainWindowPreferencesFrame::updateWidgets()

ui->foStyleSpecifiedLineEdit->setText(prefs_get_string_value(pref_fileopen_dir_, pref_stashed));

ui->maxFilterLineEdit->setText(QString::number(prefs_get_uint_value_real(pref_recent_df_entries_max_, pref_stashed)));
ui->maxRecentLineEdit->setText(QString::number(prefs_get_uint_value_real(pref_recent_files_count_max_, pref_stashed)));
ui->maxFilterLineEdit->setText(QString::number(prefs_get_uint_value(pref_recent_df_entries_max_, pref_stashed)));
ui->maxRecentLineEdit->setText(QString::number(prefs_get_uint_value(pref_recent_files_count_max_, pref_stashed)));

ui->confirmUnsavedCheckBox->setChecked(prefs_get_bool_value(pref_ask_unsaved_, pref_stashed));
ui->displayAutoCompleteCheckBox->setChecked(prefs_get_bool_value(pref_autocomplete_filter_, pref_stashed));
Expand Down
4 changes: 2 additions & 2 deletions ui/qt/preference_editor_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module
void PreferenceEditorFrame::uintLineEditTextEdited(const QString &new_str)
{
if (new_str.isEmpty()) {
new_uint_ = prefs_get_uint_value_real(pref_, pref_stashed);
new_uint_ = prefs_get_uint_value(pref_, pref_stashed);
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
return;
Expand All @@ -148,7 +148,7 @@ void PreferenceEditorFrame::uintLineEditTextEdited(const QString &new_str)
new_uint_ = new_uint;
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Valid);
} else {
new_uint_ = prefs_get_uint_value_real(pref_, pref_stashed);
new_uint_ = prefs_get_uint_value(pref_, pref_stashed);
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Invalid);
}
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
Expand Down
3 changes: 1 addition & 2 deletions ui/qt/preferences_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ void PreferencesDialog::on_advancedSearchLineEdit_textEdited(const QString &text
* the countdown.
*/
searchLineEditText = text;
unsigned gui_debounce_timer = prefs_get_uint_value("gui", "debounce.timer");
searchLineEditTimer->start(gui_debounce_timer);
searchLineEditTimer->start(prefs.gui_debounce_timer);
}

void PreferencesDialog::on_showChangedValuesCheckBox_toggled(bool checked)
Expand Down
3 changes: 1 addition & 2 deletions ui/qt/supported_protocols_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,5 @@ void SupportedProtocolsDialog::on_searchLineEdit_textChanged(const QString &sear
* the countdown.
*/
searchLineEditText = search_re;
unsigned gui_debounce_timer = prefs_get_uint_value("gui", "debounce.timer");
searchLineEditTimer->start(gui_debounce_timer);
searchLineEditTimer->start(prefs.gui_debounce_timer);
}

0 comments on commit 336123f

Please sign in to comment.