Skip to content

Commit 44d9045

Browse files
Fix crash when updating of combo row
Use value from the option string list, not from the combo row to find the index to select. The combo row strings are the user-facing names for the values.
1 parent b229632 commit 44d9045

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

src/DeviceOptionsState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ void Gorfector::DeviceOptionsState::Updater::ApplyPreset(const nlohmann::json &j
595595
FindRequestMismatches(indicesToApply, mismatchIndices);
596596
if (!mismatchIndices.empty())
597597
{
598-
g_warning("Failed to set all requested values on the device after %d iterations.", 20 - maxRepeatCount);
598+
g_print("Failed to set all requested values on the device after %d iterations.", 20 - maxRepeatCount);
599599
}
600600
}
601601

src/DeviceOptionsState.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ namespace Gorfector
2424

2525
union WidgetIndex
2626
{
27-
const uint32_t OptionValueIndices[2];
27+
const uint32_t OptionValueIndices[2]; /*
28+
* First index is the option index,
29+
* second index is the value index within the option.
30+
*/
2831
const uint64_t CompositeIndex;
2932
};
3033

src/DeviceSelectorState.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ namespace Gorfector
3333
*
3434
* This method clears the current device list, reinitializes the SANE library, and fetches the latest
3535
* list of devices. It also ensures that the previously selected device is reselected if it is still available.
36-
*
37-
* \throws std::runtime_error If the SANE library fails to initialize.
3836
*/
3937
void GetDevicesFromSANE()
4038
{

src/OptionRewriter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace Gorfector
140140
}
141141

142142
/**
143-
* \brief Retrieves a rewritten string list for an option.
143+
* \brief Retrieves a rewritten, translated string list for an option.
144144
* \param optionIndex The index of the option.
145145
* \param defaultList The default string list to use if no custom list is found.
146146
* \param rewrittenStringList The output parameter to store the rewritten string list.

src/ScanOptionsPanel.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,15 @@ void Gorfector::ScanOptionsPanel::Update(const std::vector<uint64_t> &lastSeenVe
11471147
{
11481148
for (auto changedIndex: changeset->GetChangedIndices())
11491149
{
1150+
auto widget = m_Widgets[changedIndex.CompositeIndex];
1151+
1152+
if (widget == nullptr)
1153+
{
1154+
continue;
1155+
}
1156+
11501157
auto option = m_DeviceOptions->GetOption(changedIndex.OptionValueIndices[0]);
11511158
auto settingValueType = option->GetValueType();
1152-
auto widget = m_Widgets[changedIndex.CompositeIndex];
11531159

11541160
switch (settingValueType)
11551161
{
@@ -1209,20 +1215,27 @@ void Gorfector::ScanOptionsPanel::Update(const std::vector<uint64_t> &lastSeenVe
12091215

12101216
if (ADW_IS_COMBO_ROW(widget))
12111217
{
1212-
auto items = adw_combo_row_get_model(ADW_COMBO_ROW(widget));
1213-
uint32_t valuePosition = 0;
1214-
for (uint32_t i = 0; i < g_list_model_get_n_items(items); i++)
1218+
auto stringList = option->GetStringList();
1219+
auto valuePosition = 0;
1220+
while (stringList[valuePosition] != nullptr)
12151221
{
1216-
auto *item = G_OBJECT(g_list_model_get_item(items, i));
1217-
auto itemName = gtk_string_object_get_string(GTK_STRING_OBJECT(item));
1218-
if (strcmp(itemName, value.c_str()) == 0)
1222+
auto optionValue = stringList[valuePosition];
1223+
1224+
if (strcmp(optionValue, value.c_str()) == 0)
12191225
{
1220-
valuePosition = i;
12211226
break;
12221227
}
1228+
valuePosition++;
12231229
}
12241230

1225-
adw_combo_row_set_selected(ADW_COMBO_ROW(widget), valuePosition);
1231+
if (stringList[valuePosition] == nullptr)
1232+
{
1233+
g_print("Value %s not found in combo row %s\n", value.c_str(), G_OBJECT_TYPE_NAME(widget));
1234+
}
1235+
else
1236+
{
1237+
adw_combo_row_set_selected(ADW_COMBO_ROW(widget), valuePosition);
1238+
}
12261239
}
12271240
else if (ADW_IS_ENTRY_ROW(widget))
12281241
{

0 commit comments

Comments
 (0)