static guint module_prefs_unstash(module_t *module, gpointer data) { gboolean *must_redissect_p = (gboolean *)data; module->prefs_changed = FALSE; /* assume none of them changed */ for (GList *pref_l = module->prefs; pref_l && pref_l->data; pref_l = g_list_next(pref_l)) { pref_t *pref = (pref_t *) pref_l->data; if (pref->type == PREF_OBSOLETE || pref->type == PREF_STATIC_TEXT) continue; pref_unstash(pref, &module->prefs_changed); } /* If any of them changed, indicate that we must redissect and refilter the current capture (if we have one), as the preference change could cause packets to be dissected differently. */ if (module->prefs_changed) *must_redissect_p = TRUE; if(prefs_module_has_submodules(module)) return prefs_modules_foreach_submodules(module, module_prefs_unstash, data); return 0; /* Keep unstashing. */ }
PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent), pd_ui_(new Ui::PreferencesDialog), cur_line_edit_(NULL), cur_combo_box_(NULL) { QTreeWidgetItem tmp_item; // Adding pre-populated top-level items is much faster prefs_modules_foreach_submodules(NULL, fill_advanced_prefs, (gpointer) &tmp_item); // Some classes depend on pref_ptr_to_pref_ so this MUST be called after // fill_advanced_prefs. pd_ui_->setupUi(this); pd_ui_->advancedTree->invisibleRootItem()->addChildren(tmp_item.takeChildren()); QTreeWidgetItemIterator pref_it(pd_ui_->advancedTree, QTreeWidgetItemIterator::NoChildren); while (*pref_it) { updateItem(*(*pref_it)); ++pref_it; } qDebug() << "FIX: Open UAT dialogs from prefs dialog."; qDebug() << "FIX: Auto-size each preference pane."; pd_ui_->splitter->setStretchFactor(0, 1); pd_ui_->splitter->setStretchFactor(1, 5); pd_ui_->prefsTree->invisibleRootItem()->child(appearance_item_)->setExpanded(true); pd_ui_->prefsTree->setCurrentItem(pd_ui_->prefsTree->invisibleRootItem()->child(appearance_item_)); // This assumes that the prefs tree and stacked widget contents exactly // correspond to each other. QTreeWidgetItem *item = pd_ui_->prefsTree->itemAt(0,0); for (int i = 0; i < pd_ui_->stackedWidget->count() && item; i++) { item->setData(0, Qt::UserRole, qVariantFromValue(pd_ui_->stackedWidget->widget(i))); item = pd_ui_->prefsTree->itemBelow(item); } }
guint fill_advanced_prefs(module_t *module, gpointer root_ptr) { QTreeWidgetItem *root_item = static_cast<QTreeWidgetItem *>(root_ptr); if (!module || !root_item) return 1; if (module->numprefs < 1 && !prefs_module_has_submodules(module)) return 0; QString module_title = module->title; QTreeWidgetItem *tl_item = new QTreeWidgetItem(root_item); tl_item->setText(0, module_title); tl_item->setToolTip(0, QString("<span>%1</span>").arg(module->description)); tl_item->setFirstColumnSpanned(true); QList<QTreeWidgetItem *>tl_children; for (GList *pref_l = module->prefs; pref_l && pref_l->data; pref_l = g_list_next(pref_l)) { pref_t *pref = (pref_t *) pref_l->data; if (pref->type == PREF_OBSOLETE || pref->type == PREF_STATIC_TEXT) continue; const char *type_name = prefs_pref_type_name(pref); if (!type_name) continue; pref_stash(pref, NULL); QTreeWidgetItem *item = new QTreeWidgetItem(); QString full_name = QString(module->name ? module->name : module->parent->name) + "." + pref->name; QString type_desc = gchar_free_to_qstring(prefs_pref_type_description(pref)); QString default_value = gchar_free_to_qstring(prefs_pref_to_str(pref, pref_stashed)); item->setData(0, Qt::UserRole, qVariantFromValue(pref)); item->setText(0, full_name); item->setToolTip(0, QString("<span>%1</span>").arg(pref->description)); item->setToolTip(1, QObject::tr("Has this preference been changed?")); item->setText(2, type_name); item->setToolTip(2, QString("<span>%1</span>").arg(type_desc)); item->setToolTip(3, QString("<span>%1</span>").arg( default_value.isEmpty() ? default_value : QObject::tr("Default value is empty"))); tl_children << item; // .uat is a void * so it wins the "useful key value" prize. if (pref->varp.uat) { pref_ptr_to_pref_[pref->varp.uat] = pref; } } tl_item->addChildren(tl_children); if(prefs_module_has_submodules(module)) return prefs_modules_foreach_submodules(module, fill_advanced_prefs, tl_item); return 0; }
static guint module_prefs_clean_stash(module_t *module, gpointer) { for (GList *pref_l = module->prefs; pref_l && pref_l->data; pref_l = g_list_next(pref_l)) { pref_t *pref = (pref_t *) pref_l->data; if (prefs_get_type(pref) == PREF_OBSOLETE || prefs_get_type(pref) == PREF_STATIC_TEXT) continue; pref_clean_stash(pref, NULL); } if(prefs_module_has_submodules(module)) return prefs_modules_foreach_submodules(module, module_prefs_clean_stash, NULL); return 0; /* Keep cleaning modules */ }
static guint module_prefs_show(module_t *module, gpointer ti_ptr) { QTreeWidgetItem *item = static_cast<QTreeWidgetItem *>(ti_ptr); if (!item) return 0; QStackedWidget *stacked_widget = item->data(0, Qt::UserRole).value<QStackedWidget *>(); if (!stacked_widget) return 0; if (!module->use_gui) { /* This module uses its own GUI interface to modify its * preferences, so ignore it */ return 0; } /* * Is this module an interior node, with modules underneath it? */ if (!prefs_module_has_submodules(module)) { /* * No. * Does it have any preferences (other than possibly obsolete ones)? */ if (prefs_pref_foreach(module, pref_exists, NULL) == 0) { /* * No. Don't put the module into the preferences window, * as there's nothing to show. * * XXX - we should do the same for interior ndes; if the module * has no non-obsolete preferences *and* nothing under it has * non-obsolete preferences, don't put it into the window. */ return 0; } } /* * Add this module to the tree. */ QTreeWidgetItem *new_item = new QTreeWidgetItem(item); new_item->setText(0, module->title); new_item->setData(0, Qt::UserRole, item->data(0, Qt::UserRole)); /* * Is this an interior node? */ if (prefs_module_has_submodules(module)) { /* * Yes. Walk the subtree and attach stuff to it. */ prefs_modules_foreach_submodules(module, module_prefs_show, (gpointer) new_item); } /* * We create pages for interior nodes even if they don't have * preferences, so that we at least have something to show * if the user clicks on them, even if it's empty. */ /* Scrolled window */ ModulePreferencesScrollArea *mpsa = new ModulePreferencesScrollArea(module); // /* Associate this module with the page's frame. */ // g_object_set_data(G_OBJECT(frame), E_PAGE_MODULE_KEY, module); /* Add the page to the notebook */ stacked_widget->addWidget(mpsa); /* Attach the page to the tree item */ new_item->setData(0, Qt::UserRole, qVariantFromValue(qobject_cast<QWidget *>(mpsa))); return 0; }
PreferencesDialog::~PreferencesDialog() { delete pd_ui_; prefs_modules_foreach_submodules(NULL, module_prefs_clean_stash, NULL); }
void PreferencesDialog::on_buttonBox_accepted() { gchar* err = NULL; unsigned int redissect_flags = 0; // XXX - We should validate preferences as the user changes them, not here. // XXX - We're also too enthusiastic about setting must_redissect. prefs_modules_foreach_submodules(NULL, module_prefs_unstash, (gpointer)&redissect_flags); if (redissect_flags & PREF_EFFECT_GUI_LAYOUT) { // Layout type changed, reset sizes recent.gui_geometry_main_upper_pane = 0; recent.gui_geometry_main_lower_pane = 0; } pd_ui_->columnFrame->unstash(); pd_ui_->filterExpressonsFrame->acceptChanges(); pd_ui_->expertFrame->acceptChanges(); //Filter expressions don't affect dissection, so there is no need to //send any events to that effect. However, the app needs to know //about any button changes. wsApp->emitAppSignal(WiresharkApplication::FilterExpressionsChanged); prefs_main_write(); if (save_decode_as_entries(&err) < 0) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err); g_free(err); } write_language_prefs(); wsApp->loadLanguage(QString(language)); #ifdef HAVE_AIRPCAP /* * Load the Wireshark decryption keys (just set) and save * the changes to the adapters' registry */ //airpcap_load_decryption_keys(airpcap_if_list); #endif // gtk/prefs_dlg.c:prefs_main_apply_all /* * Apply the protocol preferences first - "gui_prefs_apply()" could * cause redissection, and we have to make sure the protocol * preference changes have been fully applied. */ prefs_apply_all(); /* Fill in capture options with values from the preferences */ prefs_to_capture_opts(); #ifdef HAVE_AIRPCAP // prefs_airpcap_update(); #endif wsApp->setMonospaceFont(prefs.gui_qt_font_name); if (redissect_flags & PREF_EFFECT_DISSECTION) { /* Redissect all the packets, and re-evaluate the display filter. */ wsApp->queueAppSignal(WiresharkApplication::PacketDissectionChanged); } wsApp->queueAppSignal(WiresharkApplication::PreferencesChanged); if (redissect_flags & PREF_EFFECT_GUI_LAYOUT) { wsApp->queueAppSignal(WiresharkApplication::RecentPreferencesRead); } if (prefs.capture_no_extcap != saved_capture_no_extcap_) wsApp->refreshLocalInterfaces(); }