summaryrefslogtreecommitdiff
path: root/ui/qt
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2013-02-08 01:16:46 +0000
committerGerald Combs <gerald@wireshark.org>2013-02-08 01:16:46 +0000
commit24d67b60ab2f21aea2e4cf8be734d374a9db66ab (patch)
tree4b6b924ec2f3f255d4311130b0490e6cb279a55f /ui/qt
parent4bbe78cbdf46c027504095305bb952c9e9315659 (diff)
downloadwireshark-24d67b60ab2f21aea2e4cf8be734d374a9db66ab.tar.gz
Add a ModulePreferencesScrollArea widget which builds a scrollable frame
for a preferences module. Use it to fill in the remaining preferences. Don't show the printing preferences since they're not used here. Change the titles and tooltips for some of the name resolution preferences. Disable the capture preferences if we can't capture. This is different from the GTK+ version which hides it completely. Thus concludes the preferences dialog (for the time being). svn path=/trunk/; revision=47545
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/QtShark.pro5
-rw-r--r--ui/qt/module_preferences_scroll_area.cpp414
-rw-r--r--ui/qt/module_preferences_scroll_area.h70
-rw-r--r--ui/qt/module_preferences_scroll_area.ui42
-rw-r--r--ui/qt/preferences_dialog.cpp142
-rw-r--r--ui/qt/preferences_dialog.ui30
6 files changed, 664 insertions, 39 deletions
diff --git a/ui/qt/QtShark.pro b/ui/qt/QtShark.pro
index 2a891bbf71..b8b6bf5341 100644
--- a/ui/qt/QtShark.pro
+++ b/ui/qt/QtShark.pro
@@ -196,6 +196,7 @@ FORMS += \
main_welcome.ui \
main_window.ui \
main_window_preferences_frame.ui \
+ module_preferences_scroll_area.ui \
packet_comment_dialog.ui \
packet_format_group_box.ui \
packet_range_group_box.ui \
@@ -238,6 +239,7 @@ HEADERS += $$HEADERS_WS_C \
font_color_preferences_frame.h \
layout_preferences_frame.h \
main_window_preferences_frame.h \
+ module_preferences_scroll_area.h \
packet_comment_dialog.h \
packet_format_group_box.h \
preferences_dialog.h \
@@ -453,6 +455,7 @@ SOURCES += \
main_window.cpp \
main_window_preferences_frame.cpp \
main_window_slots.cpp \
+ module_preferences_scroll_area.cpp \
packet_comment_dialog.cpp \
packet_format_group_box.cpp \
packet_list.cpp \
@@ -472,4 +475,4 @@ SOURCES += \
splash_overlay.cpp \
syntax_line_edit.cpp \
time_shift_dialog.cpp \
- wireshark_application.cpp
+ wireshark_application.cpp \
diff --git a/ui/qt/module_preferences_scroll_area.cpp b/ui/qt/module_preferences_scroll_area.cpp
new file mode 100644
index 0000000000..ada6e557d2
--- /dev/null
+++ b/ui/qt/module_preferences_scroll_area.cpp
@@ -0,0 +1,414 @@
+/* module_preferences_scroll_area.cpp
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "module_preferences_scroll_area.h"
+#include "ui_module_preferences_scroll_area.h"
+#include "syntax_line_edit.h"
+#include "qt_ui_utils.h"
+
+#include <epan/prefs-int.h>
+
+#include <QAbstractButton>
+#include <QButtonGroup>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QScrollBar>
+#include <QSpacerItem>
+
+#include <QDebug>
+
+Q_DECLARE_METATYPE(pref_t *)
+
+const char *pref_prop_ = "pref_ptr";
+
+extern "C" {
+// Callbacks prefs routines
+
+/* show a single preference on the GtkGrid of a preference page */
+static guint
+pref_show(pref_t *pref, gpointer layout_ptr)
+{
+ QVBoxLayout *vb = static_cast<QVBoxLayout *>(layout_ptr);
+
+ if (!pref || !vb) return 0;
+
+ switch (pref->type) {
+ case PREF_UINT:
+ {
+ QHBoxLayout *hb = new QHBoxLayout();
+ hb->addWidget(new QLabel(pref->title));
+ QLineEdit *uint_le = new QLineEdit();
+ uint_le->setProperty(pref_prop_, qVariantFromValue(pref));
+ uint_le->setMinimumWidth(uint_le->fontMetrics().height() * 8);
+ hb->addWidget(uint_le);
+ hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
+ vb->addLayout(hb);
+ break;
+ }
+ case PREF_BOOL:
+ {
+ QCheckBox *bool_cb = new QCheckBox(pref->title);
+ bool_cb->setProperty(pref_prop_, qVariantFromValue(pref));
+ vb->addWidget(bool_cb);
+ break;
+ }
+ case PREF_ENUM:
+ {
+ const enum_val_t *ev;
+ if (!pref->info.enum_info.enumvals) return 0;
+
+ if (pref->info.enum_info.radio_buttons) {
+ vb->addWidget(new QLabel(pref->title));
+ QButtonGroup *enum_bg = new QButtonGroup();
+ for (ev = pref->info.enum_info.enumvals; ev && ev->description; ev++) {
+ QRadioButton *enum_rb = new QRadioButton(ev->description);
+ QStyleOption style_opt;
+ enum_rb->setProperty(pref_prop_, qVariantFromValue(pref));
+ enum_rb->setStyleSheet(QString(
+ "QRadioButton {"
+ " margin-left: %1px;"
+ "}"
+ )
+ .arg(enum_rb->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
+ enum_bg->addButton(enum_rb, ev->value);
+ vb->addWidget(enum_rb);
+ }
+ } else {
+ QHBoxLayout *hb = new QHBoxLayout();
+ QComboBox *enum_cb = new QComboBox();
+ enum_cb->setProperty(pref_prop_, qVariantFromValue(pref));
+ for (ev = pref->info.enum_info.enumvals; ev && ev->description; ev++) {
+ enum_cb->addItem(ev->description, QVariant(ev->value));
+ }
+ hb->addWidget(new QLabel(pref->title));
+ hb->addWidget(enum_cb);
+ hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
+ vb->addLayout(hb);
+ }
+ break;
+ }
+ case PREF_STRING:
+ {
+ QHBoxLayout *hb = new QHBoxLayout();
+ hb->addWidget(new QLabel(pref->title));
+ QLineEdit *string_le = new QLineEdit();
+ string_le->setProperty(pref_prop_, qVariantFromValue(pref));
+ string_le->setMinimumWidth(string_le->fontMetrics().height() * 20);
+ hb->addWidget(string_le);
+ hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
+ vb->addLayout(hb);
+ break;
+ }
+ case PREF_RANGE:
+ {
+ QHBoxLayout *hb = new QHBoxLayout();
+ hb->addWidget(new QLabel(pref->title));
+ SyntaxLineEdit *range_se = new SyntaxLineEdit();
+ range_se->setProperty(pref_prop_, qVariantFromValue(pref));
+ range_se->setMinimumWidth(range_se->fontMetrics().height() * 20);
+ hb->addWidget(range_se);
+ hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
+ vb->addLayout(hb);
+ break;
+ }
+ case PREF_STATIC_TEXT:
+ {
+ vb->addWidget(new QLabel(pref->title));
+ break;
+ }
+ case PREF_UAT:
+ {
+ QHBoxLayout *hb = new QHBoxLayout();
+ hb->addWidget(new QLabel(pref->title));
+ QPushButton *uat_pb = new QPushButton("Edit...");
+ uat_pb->setProperty(pref_prop_, qVariantFromValue(pref));
+ hb->addWidget(uat_pb);
+ hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
+ vb->addLayout(hb);
+ break;
+ }
+ case PREF_COLOR:
+ {
+ // XXX - Not needed yet. When it is needed we can add a label + QFrame which pops up a
+ // color picker similar to the Font and Colors prefs.
+ break;
+ }
+ default:
+ break;
+ }
+ return 0;
+}
+
+} // extern "C"
+
+ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidget *parent) :
+ QScrollArea(parent),
+ ui(new Ui::ModulePreferencesScrollArea),
+ module_(module)
+{
+ ui->setupUi(this);
+
+ if (!module) return;
+
+ /* Add items for each of the preferences */
+ prefs_pref_foreach(module, pref_show, (gpointer) ui->verticalLayout);
+
+ foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
+ pref_t *pref = le->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ if (pref->type == PREF_UINT) {
+ connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString)));
+ } else if (pref->type == PREF_STRING) {
+ connect(le, SIGNAL(textEdited(QString)), this, SLOT(stringLineEditTextEdited(QString)));
+ } else if (pref->type == PREF_RANGE) {
+ connect(le, SIGNAL(textEdited(QString)), this, SLOT(rangeSyntaxLineEditTextEdited(QString)));
+ }
+ }
+
+ foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
+ pref_t *pref = cb->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ if (pref->type == PREF_BOOL) {
+ connect(cb, SIGNAL(toggled(bool)), this, SLOT(boolCheckBoxToggled(bool)));
+ }
+ }
+
+ foreach (QRadioButton *enum_rb, findChildren<QRadioButton *>()) {
+ pref_t *pref = enum_rb->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ if (pref->type == PREF_ENUM && pref->info.enum_info.radio_buttons) {
+ connect(enum_rb, SIGNAL(toggled(bool)), this, SLOT(enumRadioButtonToggled(bool)));
+ }
+ }
+
+ foreach (QComboBox *enum_cb, findChildren<QComboBox *>()) {
+ pref_t *pref = enum_cb->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ if (pref->type == PREF_ENUM && !pref->info.enum_info.radio_buttons) {
+ connect(enum_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(enumComboBoxCurrentIndexChanged(int)));
+ }
+ }
+
+ foreach (QPushButton *uat_pb, findChildren<QPushButton *>()) {
+ pref_t *pref = uat_pb->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ if (pref->type == PREF_UAT) {
+ connect(uat_pb, SIGNAL(pressed()), this, SLOT(uatPushButtonPressed()));
+ }
+ }
+
+ ui->verticalLayout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
+}
+
+ModulePreferencesScrollArea::~ModulePreferencesScrollArea()
+{
+ delete ui;
+}
+
+void ModulePreferencesScrollArea::showEvent(QShowEvent *evt)
+{
+ Q_UNUSED(evt)
+ updateWidgets();
+}
+
+void ModulePreferencesScrollArea::resizeEvent(QResizeEvent *evt)
+{
+ QScrollArea::resizeEvent(evt);
+
+ if (verticalScrollBar()->isVisible()) {
+ setFrameStyle(QFrame::StyledPanel);
+ } else {
+ setFrameStyle(QFrame::NoFrame);
+ }
+}
+
+void ModulePreferencesScrollArea::updateWidgets()
+{
+ foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
+ pref_t *pref = le->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ le->setText(gchar_free_to_qstring(prefs_pref_to_str(pref, pref_stashed)).remove(QRegExp("\n\t")));
+ }
+
+ foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
+ pref_t *pref = cb->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ if (pref->type == PREF_BOOL) {
+ cb->setChecked(pref->stashed_val.boolval);
+ }
+ }
+
+ foreach (QRadioButton *enum_rb, findChildren<QRadioButton *>()) {
+ pref_t *pref = enum_rb->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ QButtonGroup *enum_bg = enum_rb->group();
+ if (!enum_bg) continue;
+
+ if (pref->type == PREF_ENUM && pref->info.enum_info.radio_buttons) {
+ if (pref->stashed_val.enumval == enum_bg->id(enum_rb)) {
+ enum_rb->setChecked(true);
+ }
+ }
+ }
+
+ foreach (QComboBox *enum_cb, findChildren<QComboBox *>()) {
+ pref_t *pref = enum_cb->property(pref_prop_).value<pref_t *>();
+ if (!pref) continue;
+
+ if (pref->type == PREF_ENUM && !pref->info.enum_info.radio_buttons) {
+ for (int i = 0; i < enum_cb->count(); i++) {
+ if (pref->stashed_val.enumval == enum_cb->itemData(i).toInt()) {
+ enum_cb->setCurrentIndex(i);
+ }
+ }
+ }
+ }
+}
+
+void ModulePreferencesScrollArea::uintLineEditTextEdited(const QString &new_str)
+{
+ QLineEdit *uint_le = qobject_cast<QLineEdit*>(sender());
+ if (!uint_le) return;
+
+ pref_t *pref = uint_le->property(pref_prop_).value<pref_t *>();
+ if (!pref) return;
+
+ bool ok;
+ uint new_uint = new_str.toUInt(&ok);
+ if (ok) {
+ pref->stashed_val.uint = new_uint;
+ }
+}
+
+void ModulePreferencesScrollArea::boolCheckBoxToggled(bool checked)
+{
+ QCheckBox *bool_cb = qobject_cast<QCheckBox*>(sender());
+ if (!bool_cb) return;
+
+ pref_t *pref = bool_cb->property(pref_prop_).value<pref_t *>();
+ if (!pref) return;
+
+ pref->stashed_val.boolval = checked;
+}
+
+void ModulePreferencesScrollArea::enumRadioButtonToggled(bool checked)
+{
+ if (!checked) return;
+ QRadioButton *enum_rb = qobject_cast<QRadioButton*>(sender());
+ if (!enum_rb) return;
+
+ QButtonGroup *enum_bg = enum_rb->group();
+ if (!enum_bg) return;
+
+ pref_t *pref = enum_rb->property(pref_prop_).value<pref_t *>();
+ if (!pref) return;
+
+ if (enum_bg->checkedId() >= 0) {
+ pref->stashed_val.enumval = enum_bg->checkedId();
+ }
+}
+
+void ModulePreferencesScrollArea::enumComboBoxCurrentIndexChanged(int index)
+{
+ QComboBox *enum_cb = qobject_cast<QComboBox*>(sender());
+ if (!enum_cb) return;
+
+ pref_t *pref = enum_cb->property(pref_prop_).value<pref_t *>();
+ if (!pref) return;
+
+ pref->stashed_val.enumval = enum_cb->itemData(index).toInt();
+}
+
+void ModulePreferencesScrollArea::stringLineEditTextEdited(const QString &new_str)
+{
+ QLineEdit *string_le = qobject_cast<QLineEdit*>(sender());
+ if (!string_le) return;
+
+ pref_t *pref = string_le->property(pref_prop_).value<pref_t *>();
+ if (!pref) return;
+
+ g_free((void *)pref->stashed_val.string);
+ pref->stashed_val.string = qstring_strdup(new_str);
+}
+
+void ModulePreferencesScrollArea::rangeSyntaxLineEditTextEdited(const QString &new_str)
+{
+ SyntaxLineEdit *range_se = qobject_cast<SyntaxLineEdit*>(sender());
+ if (!range_se) return;
+
+ pref_t *pref = range_se->property(pref_prop_).value<pref_t *>();
+ if (!pref) return;
+
+ range_t *newrange;
+ convert_ret_t ret = range_convert_str(&newrange, new_str.toUtf8().constData(), pref->info.max_value);
+
+ if (ret == CVT_NO_ERROR) {
+ g_free(pref->stashed_val.range);
+ pref->stashed_val.range = newrange;
+
+ if (new_str.isEmpty()) {
+ range_se->setSyntaxState(SyntaxLineEdit::Empty);
+ } else {
+ range_se->setSyntaxState(SyntaxLineEdit::Valid);
+ }
+ } else {
+ range_se->setSyntaxState(SyntaxLineEdit::Invalid);
+ }
+}
+
+void ModulePreferencesScrollArea::uatPushButtonPressed()
+{
+ QPushButton *uat_pb = qobject_cast<QPushButton*>(sender());
+ if (!uat_pb) return;
+
+ pref_t *pref = uat_pb->property(pref_prop_).value<pref_t *>();
+ if (!pref) return;
+
+ qDebug() << "FIX Implement UATs:" << pref->title;
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/qt/module_preferences_scroll_area.h b/ui/qt/module_preferences_scroll_area.h
new file mode 100644
index 0000000000..8a297ef86c
--- /dev/null
+++ b/ui/qt/module_preferences_scroll_area.h
@@ -0,0 +1,70 @@
+/* module_preferences_scroll_area.h
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MODULE_PREFERENCES_SCROLL_AREA_H
+#define MODULE_PREFERENCES_SCROLL_AREA_H
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "color.h"
+#include "packet-range.h"
+
+#include <epan/prefs.h>
+
+#include <QScrollArea>
+
+namespace Ui {
+class ModulePreferencesScrollArea;
+}
+
+class ModulePreferencesScrollArea : public QScrollArea
+{
+ Q_OBJECT
+
+public:
+ explicit ModulePreferencesScrollArea(module_t *module, QWidget *parent = 0);
+ ~ModulePreferencesScrollArea();
+
+protected:
+ void showEvent(QShowEvent *evt);
+ void resizeEvent(QResizeEvent *evt);
+
+private:
+ Ui::ModulePreferencesScrollArea *ui;
+
+ module_t *module_;
+ void updateWidgets();
+
+private slots:
+ void uintLineEditTextEdited(const QString &new_str);
+ void boolCheckBoxToggled(bool checked);
+ void enumRadioButtonToggled(bool checked);
+ void enumComboBoxCurrentIndexChanged(int index);
+ void stringLineEditTextEdited(const QString &new_str);
+ void rangeSyntaxLineEditTextEdited(const QString &new_str);
+ void uatPushButtonPressed();
+};
+
+#endif // MODULE_PREFERENCES_SCROLL_AREA_H
diff --git a/ui/qt/module_preferences_scroll_area.ui b/ui/qt/module_preferences_scroll_area.ui
new file mode 100644
index 0000000000..af3809d86a
--- /dev/null
+++ b/ui/qt/module_preferences_scroll_area.ui
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ModulePreferencesScrollArea</class>
+ <widget class="QScrollArea" name="ModulePreferencesScrollArea">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>ScrollArea</string>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout"/>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/ui/qt/preferences_dialog.cpp b/ui/qt/preferences_dialog.cpp
index 588d015e55..4c2da2c703 100644
--- a/ui/qt/preferences_dialog.cpp
+++ b/ui/qt/preferences_dialog.cpp
@@ -23,28 +23,39 @@
#include "preferences_dialog.h"
#include "ui_preferences_dialog.h"
+
+#include "module_preferences_scroll_area.h"
#include "wireshark_application.h"
+#ifdef HAVE_LIBPCAP
+#ifdef _WIN32
+#include "capture-wpcap.h"
+#endif /* _WIN32 */
+#endif /* HAVE_LIBPCAP */
+
#include <epan/prefs-int.h>
#include <ui/preference_utils.h>
+#include "module_preferences_scroll_area.h"
#include "syntax_line_edit.h"
#include "qt_ui_utils.h"
-#include <QTreeWidgetItemIterator>
+#include <QColorDialog>
+#include <QFileDialog>
#include <QFrame>
#include <QHBoxLayout>
-#include <QSpacerItem>
+#include <QKeyEvent>
#include <QLineEdit>
-#include <QFileDialog>
-#include <QColorDialog>
#include <QMessageBox>
#include <QPushButton>
-#include <QKeyEvent>
+#include <QSpacerItem>
+#include <QTreeWidgetItemIterator>
+
#include <QDebug>
Q_DECLARE_METATYPE(pref_t *)
+Q_DECLARE_METATYPE(QStackedWidget *)
// XXX Should we move this to ui/preference_utils?
static QHash<void *, pref_t *> pref_ptr_to_pref_;
@@ -57,6 +68,91 @@ extern "C" {
// Callbacks prefs routines
static guint
+pref_exists(pref_t *pref, gpointer user_data)
+{
+ Q_UNUSED(pref)
+ Q_UNUSED(user_data)
+ return 1;
+}
+
+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;
+}
+
+static guint
fill_advanced_prefs(module_t *module, gpointer root_ptr)
{
QTreeWidgetItem *root_item = static_cast<QTreeWidgetItem *>(root_ptr);
@@ -160,9 +256,7 @@ module_prefs_clean_stash(module_t *module, gpointer unused)
// Preference tree items
const int appearance_item_ = 0;
-const int protocols_item_ = 4;
-const int statistics_item_ = 5;
-const int advanced_item_ = 6;
+const int capture_item_ = 1;
// We store the saved and current preference values in the "Advanced" tree columns
const int pref_ptr_col_ = 0;
@@ -194,6 +288,19 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) :
pd_ui_->prefsTree->invisibleRootItem()->child(appearance_item_)->setExpanded(true);
pd_ui_->prefsTree->setCurrentItem(pd_ui_->prefsTree->invisibleRootItem()->child(appearance_item_));
+ bool disable_capture = true;
+#ifdef HAVE_LIBPCAP
+#ifdef _WIN32
+ /* Is WPcap loaded? */
+ if (has_wpcap) {
+#endif /* _WIN32 */
+ disable_capture = false;
+#ifdef _WIN32
+ }
+#endif /* _WIN32 */
+#endif /* HAVE_LIBPCAP */
+ pd_ui_->prefsTree->invisibleRootItem()->child(capture_item_)->setDisabled(disable_capture);
+
// This assumes that the prefs tree and stacked widget contents exactly
// correspond to each other.
QTreeWidgetItem *item = pd_ui_->prefsTree->itemAt(0,0);
@@ -203,6 +310,19 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) :
item->setData(0, Qt::UserRole, qVariantFromValue(pd_ui_->stackedWidget->widget(i)));
item = pd_ui_->prefsTree->itemBelow(item);
}
+
+ // Printing prefs don't apply here.
+ module_t *print_module = prefs_find_module("print");
+ if (print_module) print_module->use_gui = FALSE;
+
+ // We called takeChildren above so this shouldn't be necessary.
+ while (tmp_item.childCount() > 0) {
+ tmp_item.removeChild(tmp_item.child(0));
+ }
+ tmp_item.setData(0, Qt::UserRole, qVariantFromValue(pd_ui_->stackedWidget));
+ prefs_modules_foreach_submodules(NULL, module_prefs_show, (gpointer) &tmp_item);
+ pd_ui_->prefsTree->invisibleRootItem()->insertChildren(
+ pd_ui_->prefsTree->invisibleRootItem()->childCount() - 1, tmp_item.takeChildren());
}
PreferencesDialog::~PreferencesDialog()
@@ -483,7 +603,7 @@ void PreferencesDialog::on_advancedTree_itemActivated(QTreeWidgetItem *item, int
pref->stashed_val.string);
if (!filename.isEmpty()) {
g_free((void *)pref->stashed_val.string);
- pref->stashed_val.string = g_strdup(filename.toUtf8().constData());
+ pref->stashed_val.string = qstring_strdup(filename);
updateItem(*item);
}
break;
@@ -588,7 +708,7 @@ void PreferencesDialog::enumPrefCurrentIndexChanged(int index)
pref_t *pref = item->data(pref_ptr_col_, Qt::UserRole).value<pref_t *>();
if (!pref) return;
- pref->stashed_val.enumval = cur_combo_box_->itemData(index, Qt::UserRole).toInt();
+ pref->stashed_val.enumval = cur_combo_box_->itemData(index).toInt();
updateItem(*item);
}
@@ -601,7 +721,7 @@ void PreferencesDialog::stringPrefEditingFinished()
if (!pref) return;
g_free((void *)pref->stashed_val.string);
- pref->stashed_val.string = g_strdup(cur_line_edit_->text().toUtf8().constData());
+ pref->stashed_val.string = qstring_strdup(cur_line_edit_->text());
pd_ui_->advancedTree->removeItemWidget(item, 3);
updateItem(*item);
}
diff --git a/ui/qt/preferences_dialog.ui b/ui/qt/preferences_dialog.ui
index 32b359a95f..cc9b0c7d92 100644
--- a/ui/qt/preferences_dialog.ui
+++ b/ui/qt/preferences_dialog.ui
@@ -69,30 +69,6 @@
</item>
<item>
<property name="text">
- <string>Name Resolution</string>
- </property>
- <property name="flags">
- <set>ItemIsDragEnabled|ItemIsUserCheckable</set>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Protocols</string>
- </property>
- <property name="flags">
- <set>ItemIsDragEnabled|ItemIsUserCheckable</set>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Statistics</string>
- </property>
- <property name="flags">
- <set>ItemIsDragEnabled|ItemIsUserCheckable</set>
- </property>
- </item>
- <item>
- <property name="text">
<string>Advanced</string>
</property>
</item>
@@ -104,15 +80,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
<widget class="MainWindowPreferencesFrame" name="appearanceFrame"/>
<widget class="LayoutPreferencesFrame" name="layoutFrame"/>
<widget class="ColumnPreferencesFrame" name="columnFrame"/>
<widget class="FontColorPreferencesFrame" name="fontandcolorFrame"/>
<widget class="CapturePreferencesFrame" name="captureFrame"/>
<widget class="FilterExpressionsPreferencesFrame" name="filterExpressonsFrame"/>
- <widget class="QFrame" name="nameresolutionFrame"/>
- <widget class="QFrame" name="protocolsFrame"/>
- <widget class="QFrame" name="statisticsFrame"/>
<widget class="QFrame" name="advancedFrame">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>