Bug Summary

File:builds/wireshark/wireshark/ui/qt/widgets/additional_toolbar.cpp
Warning:line 416, column 13
Potential leak of memory pointed to by 'listvalue'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name additional_toolbar.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-18/lib/clang/18 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/build/ui/qt -isystem /builds/wireshark/wireshark/ui/qt -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore5Compat -isystem /usr/include/x86_64-linux-gnu/qt6/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt6/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt6/QtMultimedia -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D QT_CONCURRENT_LIB -D QT_CORE5COMPAT_LIB -D QT_CORE_LIB -D QT_DBUS_LIB -D QT_GUI_LIB -D QT_MULTIMEDIA_LIB -D QT_NETWORK_LIB -D QT_PRINTSUPPORT_LIB -D QT_WIDGETS_LIB -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build/ui/qt/qtui_autogen/include -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-truncation -Wno-format-nonliteral -std=c++17 -fdeprecated-macro -ferror-limit 19 -fwrapv -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -analyzer-output=html -dwarf-debug-flags /usr/lib/llvm-18/bin/clang --driver-mode=g++ -### --analyze -x c++ -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D QT_CONCURRENT_LIB -D QT_CORE5COMPAT_LIB -D QT_CORE_LIB -D QT_DBUS_LIB -D QT_GUI_LIB -D QT_MULTIMEDIA_LIB -D QT_NETWORK_LIB -D QT_PRINTSUPPORT_LIB -D QT_WIDGETS_LIB -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build/ui/qt/qtui_autogen/include -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/build/ui/qt -isystem /builds/wireshark/wireshark/ui/qt -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore5Compat -isystem /usr/include/x86_64-linux-gnu/qt6/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt6/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt6/QtMultimedia -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -fexcess-precision=fast -fstrict-flex-arrays=3 -fstack-clash-protection -fcf-protection=full -D _GLIBCXX_ASSERTIONS -fstack-protector-strong -fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -fexceptions -Wno-format-truncation -Wno-format-nonliteral -fdiagnostics-color=always -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -std=c++17 -fPIC -fPIC /builds/wireshark/wireshark/ui/qt/widgets/additional_toolbar.cpp -o /builds/wireshark/wireshark/sbout/2024-12-03-100307-3935-1 -Xclang -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2024-12-03-100307-3935-1 -x c++ /builds/wireshark/wireshark/ui/qt/widgets/additional_toolbar.cpp
1/* additional_toolbar.cpp
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <[email protected]>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#include <config.h>
11
12#include <ui/qt/widgets/additional_toolbar.h>
13#include <ui/qt/widgets/apply_line_edit.h>
14#include <ui/qt/utils/qt_ui_utils.h>
15#include <ui/qt/utils/variant_pointer.h>
16#include <ui/qt/main_application.h>
17
18#include <QLabel>
19#include <QLineEdit>
20#include <QHBoxLayout>
21#include <QComboBox>
22#include <QWidget>
23#include <QCheckBox>
24#include <QPushButton>
25#include <QStandardItem>
26#include <QStandardItemModel>
27#include <QLayoutItem>
28
29const char * AdditionalToolbarWidgetAction::propertyName = "additional_toolbar_item";
30
31AdditionalToolBar::AdditionalToolBar(ext_toolbar_t * exttoolbar, QWidget * parent)
32: QToolBar(parent),
33 toolbar(exttoolbar)
34{ }
35
36AdditionalToolBar::~AdditionalToolBar()
37{ }
38
39AdditionalToolBar * AdditionalToolBar::create(QWidget * parent, ext_toolbar_t * toolbar)
40{
41 if (g_list_length(toolbar->children) == 0)
42 return NULL__null;
43
44 AdditionalToolBar * result = new AdditionalToolBar(toolbar, parent);
45 result->setMovable(false);
46 result->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
47 result->layout()->setContentsMargins(0, 0, 0, 0);
48 result->layout()->setSpacing(4);
49
50 GList * walker = toolbar->children;
51 bool spacerNeeded = true;
52
53 while (walker && walker->data)
54 {
55 ext_toolbar_t * item = gxx_list_data(ext_toolbar_t *, walker)((walker) ? ((reinterpret_cast<ext_toolbar_t *>(walker->
data))) : nullptr)
;
56 if (item->type == EXT_TOOLBAR_ITEM)
57 {
58 if (item->item_type == EXT_TOOLBAR_STRING)
59 spacerNeeded = false;
60
61 QAction * newAction = new AdditionalToolbarWidgetAction(item, result);
62 if (newAction)
63 {
64 result->addAction(newAction);
65 /* Necessary, because enable state is reset upon adding the action */
66 result->actions()[result->actions().count() - 1]->setEnabled(!item->capture_only);
67 }
68 }
69
70 walker = gxx_list_next (walker)((walker) ? ((reinterpret_cast<GList *>(walker))->next
) : nullptr)
;
71 }
72
73 if (result->children().count() == 0)
74 return Q_NULLPTRnullptr;
75
76 if (spacerNeeded)
77 {
78 QWidget * empty = new QWidget();
79 empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
80 result->addWidget(empty);
81
82 }
83
84 return result;
85}
86
87QString AdditionalToolBar::menuName()
88{
89 return (toolbar && toolbar->name) ? QString(toolbar->name) : QString();
90}
91
92AdditionalToolbarWidgetAction::AdditionalToolbarWidgetAction(QObject * parent)
93: QWidgetAction(parent),
94 toolbar_item(0)
95{ }
96
97AdditionalToolbarWidgetAction::AdditionalToolbarWidgetAction(ext_toolbar_t * item, QObject * parent)
98: QWidgetAction(parent),
99 toolbar_item(item)
100{
101 connect(mainApp, &MainApplication::captureActive, this, &AdditionalToolbarWidgetAction::captureActive);
102}
103
104AdditionalToolbarWidgetAction::AdditionalToolbarWidgetAction(const AdditionalToolbarWidgetAction & copy_object)
105: QWidgetAction(copy_object.parent()),
106 toolbar_item(copy_object.toolbar_item)
107{
108 connect(mainApp, &MainApplication::captureActive, this, &AdditionalToolbarWidgetAction::captureActive);
109}
110
111
112void AdditionalToolbarWidgetAction::captureActive(int activeCaptures)
113{
114 if (toolbar_item && toolbar_item->capture_only)
115 {
116 setEnabled(activeCaptures != 0);
117 }
118}
119
120/* Exists, so a default deconstructor does not call delete on toolbar_item */
121AdditionalToolbarWidgetAction::~AdditionalToolbarWidgetAction() { }
122
123QWidget * AdditionalToolbarWidgetAction::createWidget(QWidget * parent)
124{
125 QWidget * barItem = 0;
126
127 if (toolbar_item->type != EXT_TOOLBAR_ITEM)
128 return barItem;
129
130 switch (toolbar_item->item_type)
131 {
132 case EXT_TOOLBAR_BUTTON:
133 barItem = createButton(toolbar_item, parent);
134 break;
135 case EXT_TOOLBAR_BOOLEAN:
136 barItem = createBoolean(toolbar_item, parent);
137 break;
138 case EXT_TOOLBAR_STRING:
139 barItem = createTextEditor(toolbar_item, parent);
140 break;
141 case EXT_TOOLBAR_SELECTOR:
142 barItem = createSelector(toolbar_item, parent);
143 break;
144 }
145
146 if (! barItem)
147 return 0;
148
149 barItem->setToolTip(toolbar_item->tooltip);
150 barItem->setProperty(propertyName, VariantPointer<ext_toolbar_t>::asQVariant(toolbar_item));
151
152#ifdef Q_OS_MAC
153 barItem->setAttribute(Qt::WA_MacSmallSize, true);
154#endif
155
156 return barItem;
157}
158
159static void
160toolbar_button_cb(void *item, void *item_data, void *user_data)
161{
162 if (! item || ! item_data || ! user_data)
163 return;
164
165 QPushButton * widget = (QPushButton *)(item_data);
166 ext_toolbar_update_t * update_entry = (ext_toolbar_update_t *)user_data;
167
168 if (widget)
169 {
170 if (update_entry->type == EXT_TOOLBAR_UPDATE_VALUE)
171 widget->setText((char *)update_entry->user_data);
172 else if (update_entry->type == EXT_TOOLBAR_SET_ACTIVE)
173 {
174 bool enableState = GPOINTER_TO_INT(update_entry->user_data)((gint) (glong) (update_entry->user_data)) == 1;
175 widget->setEnabled(enableState);
176 }
177
178 }
179}
180
181QWidget * AdditionalToolbarWidgetAction::createButton(ext_toolbar_t * item, QWidget * parent)
182{
183 if (! item || item->type != EXT_TOOLBAR_ITEM || item->item_type != EXT_TOOLBAR_BUTTON)
184 return 0;
185
186 QPushButton * button = new QPushButton(item->name, parent);
187 button->setText(item->name);
188 connect(button, &QPushButton::clicked, this, &AdditionalToolbarWidgetAction::onButtonClicked);
189
190 ext_toolbar_register_update_cb(item, (ext_toolbar_action_cb)&toolbar_button_cb, (void *)button);
191
192 return button;
193}
194
195static void
196toolbar_boolean_cb(void *item, void *item_data, void *user_data)
197{
198 if (! item || ! item_data || ! user_data)
199 return;
200
201 QCheckBox * widget = (QCheckBox *)(item_data);
202
203 ext_toolbar_update_t * update_entry = (ext_toolbar_update_t *)user_data;
204
205 if (update_entry->type == EXT_TOOLBAR_UPDATE_VALUE)
206 {
207 bool oldState = false;
208 if (update_entry->silent)
209 oldState = widget->blockSignals(true);
210
211 widget->setCheckState(GPOINTER_TO_INT(update_entry->user_data)((gint) (glong) (update_entry->user_data)) == 1 ? Qt::Checked : Qt::Unchecked);
212
213 if (update_entry->silent)
214 widget->blockSignals(oldState);
215 }
216 else if (update_entry->type == EXT_TOOLBAR_SET_ACTIVE)
217 {
218 bool enableState = GPOINTER_TO_INT(update_entry->user_data)((gint) (glong) (update_entry->user_data)) == 1;
219 widget->setEnabled(enableState);
220 }
221}
222
223QWidget * AdditionalToolbarWidgetAction::createBoolean(ext_toolbar_t * item, QWidget * parent)
224{
225 if (! item || item->type != EXT_TOOLBAR_ITEM || item->item_type != EXT_TOOLBAR_BOOLEAN)
226 return 0;
227
228 QString defValue = toolbar_item->defvalue;
229
230 QCheckBox * checkbox = new QCheckBox(item->name, parent);
231 checkbox->setText(item->name);
232 setCheckable(true);
233 checkbox->setCheckState(defValue.compare("true", Qt::CaseInsensitive) == 0 ? Qt::Checked : Qt::Unchecked);
234#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 7, 0)((6<<16)|(7<<8)|(0))
235 connect(checkbox, &QCheckBox::checkStateChanged, this, &AdditionalToolbarWidgetAction::onCheckBoxChecked);
236#else
237 connect(checkbox, &QCheckBox::stateChanged, this, &AdditionalToolbarWidgetAction::onCheckBoxChecked);
238#endif
239
240 ext_toolbar_register_update_cb(item, (ext_toolbar_action_cb)&toolbar_boolean_cb, (void *)checkbox);
241
242 return checkbox;
243}
244
245QWidget * AdditionalToolbarWidgetAction::createLabelFrame(ext_toolbar_t * item, QWidget * parent)
246{
247 if (! item)
248 return new QWidget();
249
250 QWidget * frame = new QWidget(parent);
251
252 QHBoxLayout * frameLayout = new QHBoxLayout(frame);
253 frameLayout->setContentsMargins(0, 0, 0, 0);
254 frameLayout->setSpacing(0);
255
256 QLabel * strLabel = new QLabel(item->name, frame);
257 strLabel->setToolTip(item->tooltip);
258
259#ifdef Q_OS_MAC
260 frame->setAttribute(Qt::WA_MacSmallSize, true);
261 strLabel->setAttribute(Qt::WA_MacSmallSize, true);
262#endif
263
264 frameLayout->addWidget(strLabel);
265
266 frame->setLayout(frameLayout);
267
268 return frame;
269}
270
271static void
272toolbar_string_cb(void *item, void *item_data, void *user_data)
273{
274 if (! item || ! item_data || ! user_data)
275 return;
276
277 ApplyLineEdit * edit = (ApplyLineEdit *)(item_data);
278
279 ext_toolbar_update_t * update_entry = (ext_toolbar_update_t *)user_data;
280
281 if (update_entry->type == EXT_TOOLBAR_UPDATE_VALUE)
282 {
283 bool oldState = false;
284 if (update_entry->silent)
285 oldState = edit->blockSignals(true);
286
287 edit->setText((char *)update_entry->user_data);
288
289 if (update_entry->silent)
290 edit->blockSignals(oldState);
291 }
292 else if (update_entry->type == EXT_TOOLBAR_SET_ACTIVE)
293 {
294 bool enableState = GPOINTER_TO_INT(update_entry->user_data)((gint) (glong) (update_entry->user_data)) == 1;
295 edit->setEnabled(enableState);
296 }
297}
298
299QWidget * AdditionalToolbarWidgetAction::createTextEditor(ext_toolbar_t * item, QWidget * parent)
300{
301 if (! item || item->type != EXT_TOOLBAR_ITEM || item->item_type != EXT_TOOLBAR_STRING)
302 return 0;
303
304 QWidget * frame = createLabelFrame(toolbar_item, parent);
305
306 ApplyLineEdit * strEdit = new ApplyLineEdit(toolbar_item->defvalue, frame);
307 strEdit->setToolTip(toolbar_item->tooltip);
308 strEdit->setRegEx(toolbar_item->regex);
309 strEdit->setEmptyAllowed(toolbar_item->is_required);
310 strEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
311
312#ifdef Q_OS_MAC
313 strEdit->setAttribute(Qt::WA_MacSmallSize, true);
314#endif
315
316 frame->layout()->addWidget(strEdit);
317
318 connect(strEdit, &ApplyLineEdit::textApplied, this, &AdditionalToolbarWidgetAction::sendTextToCallback);
319
320 ext_toolbar_register_update_cb(item, (ext_toolbar_action_cb)&toolbar_string_cb, (void *)strEdit);
321
322 return frame;
323}
324
325static void
326toolbar_selector_cb(void *item, void *item_data, void *user_data)
327{
328 if (! item || ! item_data || ! user_data)
1
Assuming 'item' is non-null
2
Assuming 'item_data' is non-null
3
Assuming 'user_data' is non-null
4
Taking false branch
329 return;
330
331 QComboBox * comboBox = (QComboBox *)(item_data);
332 ext_toolbar_update_t * update_entry = (ext_toolbar_update_t *)user_data;
333
334 bool oldState = false;
335
336 if (update_entry->silent)
5
Assuming field 'silent' is false
6
Taking false branch
337 oldState = comboBox->blockSignals(true);
338
339 QStandardItemModel * sourceModel = (QStandardItemModel *)comboBox->model();
340
341 if (update_entry->type == EXT_TOOLBAR_SET_ACTIVE)
7
Assuming field 'type' is not equal to EXT_TOOLBAR_SET_ACTIVE
342 {
343 bool enableState = GPOINTER_TO_INT(update_entry->user_data)((gint) (glong) (update_entry->user_data)) == 1;
344 comboBox->setEnabled(enableState);
345 }
346 else if (update_entry->type != EXT_TOOLBAR_UPDATE_DATA_REMOVE && ! update_entry->user_data)
8
Assuming field 'type' is not equal to EXT_TOOLBAR_UPDATE_DATA_REMOVE
9
Assuming field 'user_data' is non-null
10
Taking false branch
347 return;
348
349 if (update_entry->type == EXT_TOOLBAR_UPDATE_VALUE)
11
Assuming field 'type' is not equal to EXT_TOOLBAR_UPDATE_VALUE
12
Taking false branch
350 {
351 QString data = QString((char *)update_entry->user_data);
352
353 for (int i = 0; i < sourceModel->rowCount(); i++)
354 {
355 QStandardItem * dataValue = ((QStandardItemModel *)sourceModel)->item(i, 0);
356 ext_toolbar_value_t * tbValue = VariantPointer<ext_toolbar_value_t>::asPtr(dataValue->data(Qt::UserRole));
357 if (tbValue && data.compare(QString(tbValue->value)) == 0)
358 {
359 comboBox->setCurrentIndex(i);
360 break;
361 }
362 }
363 }
364 else if (update_entry->type == EXT_TOOLBAR_UPDATE_DATA)
13
Assuming field 'type' is not equal to EXT_TOOLBAR_UPDATE_DATA
365 {
366 GList * walker = (GList *)update_entry->user_data;
367 if (g_list_length(walker) == 0)
368 return;
369
370 sourceModel->clear();
371
372 while (walker && walker->data)
373 {
374 ext_toolbar_value_t * listvalue = gxx_list_data(ext_toolbar_value_t *, walker)((walker) ? ((reinterpret_cast<ext_toolbar_value_t *>(walker
->data))) : nullptr)
;
375
376 QStandardItem * si = new QStandardItem(listvalue->display);
377 si->setData(VariantPointer<ext_toolbar_value_t>::asQVariant(listvalue), Qt::UserRole);
378 sourceModel->appendRow(si);
379
380 walker = gxx_list_next(walker)((walker) ? ((reinterpret_cast<GList *>(walker))->next
) : nullptr)
;
381 }
382 }
383 else if (update_entry->type == EXT_TOOLBAR_UPDATE_DATABYINDEX ||
14
Assuming field 'type' is not equal to EXT_TOOLBAR_UPDATE_DATABYINDEX
384 update_entry->type == EXT_TOOLBAR_UPDATE_DATA_ADD ||
15
Assuming field 'type' is equal to EXT_TOOLBAR_UPDATE_DATA_ADD
385 update_entry->type == EXT_TOOLBAR_UPDATE_DATA_REMOVE)
386 {
387 if (! update_entry->data_index)
16
Assuming field 'data_index' is non-null
17
Taking false branch
388 return;
389
390 char * idx = (char *)update_entry->data_index;
391 char * display = (char *)update_entry->user_data;
392
393 if (update_entry->type
17.1
Field 'type' is not equal to EXT_TOOLBAR_UPDATE_DATABYINDEX
== EXT_TOOLBAR_UPDATE_DATABYINDEX)
18
Taking false branch
394 {
395 for (int i = 0; i < sourceModel->rowCount(); i++)
396 {
397 QStandardItem * dataValue = sourceModel->item(i, 0);
398 ext_toolbar_value_t * entry = VariantPointer<ext_toolbar_value_t>::asPtr(dataValue->data(Qt::UserRole));
399 if (entry && g_strcmp0(entry->value, idx) == 0)
400 {
401 g_free(entry->display);
402 entry->display = g_strdup(display)g_strdup_inline (display);
403 dataValue->setData(VariantPointer<ext_toolbar_value_t>::asQVariant(entry), Qt::UserRole);
404 dataValue->setText(display);
405 break;
406 }
407 }
408 }
409 else if (update_entry->type
18.1
Field 'type' is equal to EXT_TOOLBAR_UPDATE_DATA_ADD
== EXT_TOOLBAR_UPDATE_DATA_ADD)
19
Taking true branch
410 {
411 ext_toolbar_value_t * listvalue = g_new0(ext_toolbar_value_t, 1)((ext_toolbar_value_t *) g_malloc0_n ((1), sizeof (ext_toolbar_value_t
)))
;
20
Memory is allocated
412 listvalue->display = g_strdup(display)g_strdup_inline (display);
413 listvalue->value = g_strdup(idx)g_strdup_inline (idx);
414
415 QStandardItem * si = new QStandardItem(listvalue->display);
416 si->setData(VariantPointer<ext_toolbar_value_t>::asQVariant(listvalue), Qt::UserRole);
21
Potential leak of memory pointed to by 'listvalue'
417 sourceModel->appendRow(si);
418 }
419 else if (update_entry->type == EXT_TOOLBAR_UPDATE_DATA_REMOVE)
420 {
421 QList<QStandardItem *> entryList = sourceModel->findItems(display);
422 /* Search for index if display did not find anything */
423 if (entryList.size() == 0)
424 entryList = sourceModel->findItems(idx);
425
426 foreach(QStandardItem *entry, entryList)for (auto _container_426 = QtPrivate::qMakeForeachContainer(entryList
); _container_426.i != _container_426.e; ++_container_426.i) if
(QStandardItem *entry = *_container_426.i; false) {} else
427 {
428 QModelIndex index = sourceModel->indexFromItem(entry);
429 if (index.isValid())
430 sourceModel->removeRow(index.row());
431 }
432 }
433 }
434
435 if (update_entry->silent)
436 comboBox->blockSignals(oldState);
437
438}
439
440QWidget * AdditionalToolbarWidgetAction::createSelector(ext_toolbar_t * item, QWidget * parent)
441{
442 if (! item || item->type != EXT_TOOLBAR_ITEM || item->item_type != EXT_TOOLBAR_SELECTOR)
443 return 0;
444
445 if (g_list_length(item->values) == 0)
446 return 0;
447
448 QWidget * frame = createLabelFrame(item, parent);
449
450 QComboBox * myBox = new QComboBox(parent);
451 myBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
452
453 QStandardItemModel * sourceModel = new QStandardItemModel();
454
455 GList * walker = item->values;
456 int selIndex = 0;
457 while (walker && walker->data)
458 {
459 ext_toolbar_value_t * listvalue = gxx_list_data(ext_toolbar_value_t *, walker)((walker) ? ((reinterpret_cast<ext_toolbar_value_t *>(walker
->data))) : nullptr)
;
460
461 QStandardItem * si = new QStandardItem(listvalue->display);
462 si->setData(VariantPointer<ext_toolbar_value_t>::asQVariant(listvalue), Qt::UserRole);
463 sourceModel->appendRow(si);
464
465 if (listvalue->is_default)
466 selIndex = sourceModel->rowCount();
467
468 walker = gxx_list_next(walker)((walker) ? ((reinterpret_cast<GList *>(walker))->next
) : nullptr)
;
469 }
470
471 myBox->setModel(sourceModel);
472 myBox->setCurrentIndex(selIndex);
473
474#ifdef Q_OS_MAC
475 myBox->setAttribute(Qt::WA_MacSmallSize, true);
476#endif
477
478 frame->layout()->addWidget(myBox);
479
480 connect(myBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
481 this, &AdditionalToolbarWidgetAction::onSelectionInWidgetChanged);
482
483 ext_toolbar_register_update_cb(item, (ext_toolbar_action_cb)&toolbar_selector_cb, (void *)myBox);
484
485 return frame;
486}
487
488ext_toolbar_t * AdditionalToolbarWidgetAction::extractToolbarItemFromObject(QObject * object)
489{
490 QWidget * widget = dynamic_cast<QWidget *>(object);
491 if (! widget)
492 return 0;
493
494 QVariant propValue = widget->property(propertyName);
495
496 /* If property is invalid, look if our parent has this property */
497 if (! propValue.isValid())
498 {
499 QWidget * frame = dynamic_cast<QWidget *>(widget->parent());
500 if (! frame)
501 return 0;
502
503 propValue = frame->property(propertyName);
504 }
505
506 if (! propValue.isValid())
507 return 0;
508
509 return VariantPointer<ext_toolbar_t>::asPtr(propValue);
510}
511
512void AdditionalToolbarWidgetAction::onButtonClicked()
513{
514 ext_toolbar_t * item = extractToolbarItemFromObject(sender());
515 if (! item)
516 return;
517
518 item->callback(item, 0, item->user_data);
519}
520
521#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 7, 0)((6<<16)|(7<<8)|(0))
522void AdditionalToolbarWidgetAction::onCheckBoxChecked(Qt::CheckState checkState)
523#else
524void AdditionalToolbarWidgetAction::onCheckBoxChecked(int checkState)
525#endif
526{
527 ext_toolbar_t * item = extractToolbarItemFromObject(sender());
528 if (! item)
529 return;
530
531 // Qt::PartiallyChecked is not a possibility?
532 bool value = checkState == Qt::Checked ? true : false;
533
534 item->callback(item, &value, item->user_data);
535}
536
537void AdditionalToolbarWidgetAction::sendTextToCallback()
538{
539 ext_toolbar_t * item = extractToolbarItemFromObject(sender());
540 if (! item)
541 return;
542
543 if (item->item_type != EXT_TOOLBAR_STRING)
544 return;
545
546 ApplyLineEdit * editor = dynamic_cast<ApplyLineEdit *>(sender());
547 if (! editor)
548 {
549 /* Called from button, searching for accompanying line edit */
550 QWidget * parent = dynamic_cast<QWidget *>(sender()->parent());
551 if (parent)
552 {
553 QList<ApplyLineEdit *> children = parent->findChildren<ApplyLineEdit *>();
554 if (children.count() >= 0)
555 editor = children.at(0);
556 }
557 }
558
559 if (editor)
560 item->callback(item, qstring_strdup(editor->text()), item->user_data);
561}
562
563void AdditionalToolbarWidgetAction::onSelectionInWidgetChanged(int idx)
564{
565 QComboBox * editor = dynamic_cast<QComboBox *>(sender());
566 ext_toolbar_t * item = extractToolbarItemFromObject(editor);
567 if (! item || item->item_type != EXT_TOOLBAR_SELECTOR)
568 return;
569
570 QStandardItemModel * sourceModel = (QStandardItemModel *) editor->model();
571 if (sourceModel->rowCount() <= idx)
572 return;
573
574 QModelIndex mdIdx = sourceModel->index(idx, 0);
575 QVariant dataSet = sourceModel->data(mdIdx, Qt::UserRole);
576 if (dataSet.isValid())
577 {
578 ext_toolbar_value_t * value_entry = VariantPointer<ext_toolbar_value_t>::asPtr(dataSet);
579 item->callback(item, value_entry, item->user_data);
580 }
581}